|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Events
1.1.1.4 root 5: * These are best for low-frequency events. Having too many of them,
6: * or using them for events that occur too frequently, can cause massive
7: * slowdown.
1.1.1.3 root 8: *
1.1.1.4 root 9: * Copyright 1995-1998 Bernd Schmidt
1.1 root 10: */
11:
1.1.1.4 root 12: #include "machdep/rpt.h"
1.1.1.9 root 13:
1.1.1.4 root 14: extern frame_time_t vsynctime, vsyncmintime;
15: extern void reset_frame_rate_hack (void);
16: extern int rpt_available;
17:
1.1.1.9 root 18: extern unsigned long currcycle, nextevent, is_lastline;
19: extern unsigned long sample_evtime;
1.1 root 20: typedef void (*evfunc)(void);
21:
22: struct ev
23: {
24: int active;
25: unsigned long int evtime, oldcycles;
26: evfunc handler;
27: };
28:
1.1.1.3 root 29: enum {
1.1.1.9 root 30: ev_hsync, ev_copper, ev_audio, ev_cia, ev_blitter, ev_disk,
1.1 root 31: ev_max
32: };
33:
34: extern struct ev eventtab[ev_max];
35:
1.1.1.5 root 36: STATIC_INLINE void events_schedule (void)
1.1 root 37: {
38: int i;
1.1.1.3 root 39:
1.1 root 40: unsigned long int mintime = ~0L;
1.1.1.9 root 41: for (i = 0; i < ev_max; i++) {
1.1.1.3 root 42: if (eventtab[i].active) {
1.1.1.9 root 43: unsigned long int eventtime = eventtab[i].evtime - currcycle;
1.1 root 44: if (eventtime < mintime)
1.1.1.3 root 45: mintime = eventtime;
1.1 root 46: }
47: }
1.1.1.9 root 48: nextevent = currcycle + mintime;
1.1 root 49: }
50:
1.1.1.5 root 51: STATIC_INLINE void do_cycles_slow (unsigned long cycles_to_add)
1.1 root 52: {
1.1.1.9 root 53: if (is_lastline && eventtab[ev_hsync].evtime - currcycle <= cycles_to_add
1.1.1.3 root 54: && (long int)(read_processor_time () - vsyncmintime) < 0)
55: return;
1.1.1.4 root 56:
1.1.1.9 root 57: while ((nextevent - currcycle) <= cycles_to_add) {
58: int i;
59: cycles_to_add -= (nextevent - currcycle);
60: currcycle = nextevent;
61:
62: for (i = 0; i < ev_max; i++) {
63: if (eventtab[i].active && eventtab[i].evtime == currcycle) {
64: (*eventtab[i].handler)();
1.1 root 65: }
66: }
1.1.1.9 root 67: events_schedule();
1.1 root 68: }
1.1.1.9 root 69: currcycle += cycles_to_add;
1.1 root 70: }
71:
1.1.1.5 root 72: STATIC_INLINE void do_cycles_fast (void)
1.1 root 73: {
1.1.1.9 root 74: if (is_lastline && eventtab[ev_hsync].evtime - currcycle <= 1
1.1.1.3 root 75: && (long int)(read_processor_time () - vsyncmintime) < 0)
76: return;
1.1.1.4 root 77:
1.1.1.9 root 78: currcycle++;
79: if (nextevent == currcycle) {
1.1 root 80: int i;
1.1.1.3 root 81:
1.1.1.4 root 82: for (i = 0; i < ev_max; i++) {
1.1.1.9 root 83: if (eventtab[i].active && eventtab[i].evtime == currcycle) {
1.1.1.4 root 84: (*eventtab[i].handler) ();
1.1 root 85: }
86: }
87: events_schedule();
88: }
89:
90: }
91:
1.1.1.10! root 92: /* This is a special-case function. Normally, all events should lie in the
! 93: future; they should only ever be active at the current cycle during
! 94: do_cycles. However, a snapshot is saved during do_cycles, and so when
! 95: restoring it, we may have other events pending. */
! 96: STATIC_INLINE void handle_active_events (void)
! 97: {
! 98: int i;
! 99: for (i = 0; i < ev_max; i++) {
! 100: if (eventtab[i].active && eventtab[i].evtime == currcycle) {
! 101: (*eventtab[i].handler)();
! 102: }
! 103: }
! 104: }
! 105:
1.1.1.9 root 106: STATIC_INLINE unsigned long get_cycles (void)
107: {
108: return currcycle;
109: }
110:
1.1.1.10! root 111: extern void init_eventtab (void);
! 112:
1.1.1.3 root 113: #if /* M68K_SPEED == 1 */ 0
1.1 root 114: #define do_cycles do_cycles_fast
115: #else
116: #define do_cycles do_cycles_slow
117: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.