1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Let's see whether hiding this away somewhere where the compiler can't
see it will cure it of its silly urge to mis-optimize the comparison */
//extern long int diff32(frame_time_t x, frame_time_t y);
extern int pissoff_value;
STATIC_INLINE void events_schedule (void)
{
int i;
unsigned long int mintime = ~0L;
for (i = 0; i < ev_max; i++) {
if (eventtab[i].active) {
unsigned long int eventtime = eventtab[i].evtime - currcycle;
#ifdef EVENT_DEBUG
if (eventtime == 0) {
write_log ("event %d bug\n",i);
}
#endif
if (eventtime < mintime)
mintime = eventtime;
}
}
nextevent = currcycle + mintime;
}
extern signed long pissoff;
STATIC_INLINE void cycles_do_special (void)
{
#ifdef JIT
if (currprefs.cachesize) {
if (pissoff >= 0)
pissoff = -1;
} else
#endif
{
pissoff = 0;
}
}
STATIC_INLINE void do_extra_cycles (unsigned long cycles_to_add)
{
pissoff -= cycles_to_add;
}
STATIC_INLINE unsigned long int get_cycles (void)
{
return currcycle;
}
STATIC_INLINE void set_cycles (unsigned long int x)
{
currcycle = x;
eventtab[ev_hsync].oldcycles = x;
#ifdef EVT_DEBUG
if (currcycle & (CYCLE_UNIT - 1))
write_log ("%x\n", currcycle);
#endif
}
STATIC_INLINE void do_cycles_slow (unsigned long cycles_to_add)
{
if ((pissoff -= cycles_to_add) >= 0)
return;
cycles_to_add = -pissoff;
pissoff = 0;
if (is_lastline && eventtab[ev_hsync].evtime - currcycle <= cycles_to_add) {
int rpt = uae_gethrtime ();
int v = rpt - vsyncmintime;
if (v > (int)syncbase || v < -((int)syncbase))
vsyncmintime = rpt;
if (v < 0) {
pissoff = pissoff_value * CYCLE_UNIT;
return;
}
}
while ((nextevent - currcycle) <= cycles_to_add) {
int i;
cycles_to_add -= (nextevent - currcycle);
currcycle = nextevent;
for (i = 0; i < ev_max; i++) {
if (eventtab[i].active && eventtab[i].evtime == currcycle) {
(*eventtab[i].handler)();
}
}
events_schedule ();
}
currcycle += cycles_to_add;
#ifdef EVT_DEBUG
if (currcycle & (CYCLE_UNIT - 1))
write_log ("%x\n", currcycle);
#endif
}
#define do_cycles do_cycles_slow
#define countdown pissoff