-
Notifications
You must be signed in to change notification settings - Fork 4
/
mainloop.cpp
181 lines (160 loc) · 3.98 KB
/
mainloop.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "std.h"
#include "emul.h"
#include "vars.h"
#include "sound.h"
#include "draw.h"
#include "dx.h"
#include "dxr_rsm.h"
#include "leds.h"
#include "memory.h"
#include "snapshot.h"
#include "emulkeys.h"
#include "vs1001.h"
#include "z80.h"
#include "util.h"
void spectrum_frame()
{
if (!temp.inputblock || input.keymode != K_INPUT::KM_DEFAULT)
input.make_matrix();
init_snd_frame();
init_frame();
if(cpu.dbgchk)
{
cpu.SetDbgMemIf();
z80dbg::z80loop();
}
else
{
cpu.SetFastMemIf();
z80fast::z80loop();
}
if (modem.open_port)
modem.io();
flush_snd_frame();
flush_frame();
showleds();
if (!cpu.iff1 || // int disabled in CPU
((conf.mem_model == MM_ATM710 || conf.mem_model == MM_ATM3) && !(comp.pFF77 & 0x20))) // int disabled by ATM hardware
{
unsigned char *mp = am_r(cpu.pc);
if (cpu.halted)
{
strcpy(statusline, "CPU HALTED");
statcnt = 10;
}
if (*(unsigned short*)mp == WORD2(0x18,0xFE) ||
((*mp == 0xC3) && *(unsigned short*)(mp+1) == (unsigned short)cpu.pc))
{
strcpy(statusline, "CPU STOPPED");
statcnt = 10;
}
}
comp.t_states += conf.frame;
cpu.t -= conf.frame;
cpu.eipos -= conf.frame;
comp.frame_counter++;
}
void do_idle()
{
static volatile unsigned long long last_cpu = rdtsc();
for (;;)
{
asm_pause();
volatile unsigned long long cpu = rdtsc();
if ((cpu-last_cpu) >= temp.ticks_frame)
break;
if(conf.sleepidle)
{
ULONG Delay = ULONG(((temp.ticks_frame - (cpu-last_cpu)) * 1000ULL) / temp.cpufq);
if(Delay != 0)
{
Sleep(Delay);
// printf("sleep: %lu\n", Delay);
break;
}
}
}
last_cpu = rdtsc();
}
// version before frame resampler
//uncommented by Alone Coder
/*
void mainloop()
{
unsigned char skipped = 0;
for (;;)
{
if (skipped < temp.frameskip)
{
skipped++;
temp.vidblock = 1;
}
else
skipped = temp.vidblock = 0;
temp.sndblock = !conf.sound.enabled;
temp.inputblock = 0; //temp.vidblock; //Alone Coder
spectrum_frame();
// message handling before flip (they paint to rbuf)
if (!temp.inputblock)
dispatch(conf.atm.xt_kbd ? ac_main_xt : ac_main);
if (!temp.vidblock)
flip();
if (!temp.sndblock)
{
do_sound();
Vs1001.Play();
// if(conf.sound.do_sound != do_sound_ds)
do_idle();
}
}
}
*/
void mainloop(const bool &Exit)
{
unsigned char skipped = 0;
for (;!Exit;)
{
if (skipped < temp.frameskip)
{
skipped++;
temp.vidblock = 1;
}
else
skipped = temp.vidblock = 0;
if (!temp.vidblock)
flip();
for (unsigned f = rsm.needframes[rsm.frame]; f; f--)
{
temp.sndblock = !conf.sound.enabled;
temp.inputblock = temp.vidblock && conf.sound.enabled;
spectrum_frame();
VideoSaver();
// message handling before flip (they paint to rbuf)
if (!temp.inputblock)
{
dispatch(conf.atm.xt_kbd ? ac_main_xt : ac_main);
}
if (!temp.sndblock)
{
do_sound();
Vs1001.Play();
}
if (rsm.mix_frames > 1)
{
memcpy(rbuf_s + rsm.rbuf_dst * rb2_offs, rbuf, temp.scx * temp.scy / 4);
if (++rsm.rbuf_dst == rsm.mix_frames)
rsm.rbuf_dst = 0;
}
if (!temp.sndblock)
{
/*
if(conf.sound.do_sound == do_sound_none)
do_idle();
*/
}
}
if (++rsm.frame == rsm.period)
rsm.frame = 0;
}
correct_exit();
}