cff531af |
1 | /* |
2 | * PicoDrive |
6a98f03e |
3 | * (C) notaz, 2009,2010,2013 |
cff531af |
4 | * |
5 | * This work is licensed under the terms of MAME license. |
6 | * See COPYING file in the top-level directory. |
7 | */ |
be2c4208 |
8 | #include "../pico_int.h" |
974fdb5b |
9 | #include "../sound/ym2612.h" |
51d86e55 |
10 | #include "../../cpu/sh2/compiler.h" |
be2c4208 |
11 | |
12 | struct Pico32x Pico32x; |
83ff19ec |
13 | SH2 sh2s[2]; |
be2c4208 |
14 | |
19886062 |
15 | #define SH2_IDLE_STATES (SH2_STATE_CPOLL|SH2_STATE_VPOLL|SH2_STATE_SLEEP) |
16 | |
e05b81fc |
17 | static int REGPARM(2) sh2_irq_cb(SH2 *sh2, int level) |
4ea707e1 |
18 | { |
e05b81fc |
19 | if (sh2->pending_irl > sh2->pending_int_irq) { |
f8675e28 |
20 | elprintf_sh2(sh2, EL_32X, "ack/irl %d @ %08x", |
21 | level, sh2_pc(sh2)); |
e05b81fc |
22 | return 64 + sh2->pending_irl / 2; |
23 | } else { |
f8675e28 |
24 | elprintf_sh2(sh2, EL_32X, "ack/int %d/%d @ %08x", |
25 | level, sh2->pending_int_vector, sh2_pc(sh2)); |
e05b81fc |
26 | sh2->pending_int_irq = 0; // auto-clear |
27 | sh2->pending_level = sh2->pending_irl; |
28 | return sh2->pending_int_vector; |
29 | } |
4ea707e1 |
30 | } |
31 | |
c1931173 |
32 | // MUST specify active_sh2 when called from sh2 memhandlers |
4d5dfee8 |
33 | void p32x_update_irls(SH2 *active_sh2, int m68k_cycles) |
4ea707e1 |
34 | { |
35 | int irqs, mlvl = 0, slvl = 0; |
a8fd6e37 |
36 | int mrun, srun; |
4ea707e1 |
37 | |
19886062 |
38 | if (active_sh2 != NULL) |
39 | m68k_cycles = sh2_cycles_done_m68k(active_sh2); |
40 | |
4ea707e1 |
41 | // msh2 |
42 | irqs = (Pico32x.sh2irqs | Pico32x.sh2irqi[0]) & ((Pico32x.sh2irq_mask[0] << 3) | P32XI_VRES); |
43 | while ((irqs >>= 1)) |
44 | mlvl++; |
45 | mlvl *= 2; |
46 | |
47 | // ssh2 |
48 | irqs = (Pico32x.sh2irqs | Pico32x.sh2irqi[1]) & ((Pico32x.sh2irq_mask[1] << 3) | P32XI_VRES); |
49 | while ((irqs >>= 1)) |
50 | slvl++; |
51 | slvl *= 2; |
52 | |
c1931173 |
53 | mrun = sh2_irl_irq(&msh2, mlvl, active_sh2 == &msh2); |
54 | if (mrun) { |
19886062 |
55 | p32x_sh2_poll_event(&msh2, SH2_IDLE_STATES, m68k_cycles); |
c1931173 |
56 | if (active_sh2 == &msh2) |
57 | sh2_end_run(active_sh2, 1); |
58 | } |
19886062 |
59 | |
c1931173 |
60 | srun = sh2_irl_irq(&ssh2, slvl, active_sh2 == &ssh2); |
61 | if (srun) { |
19886062 |
62 | p32x_sh2_poll_event(&ssh2, SH2_IDLE_STATES, m68k_cycles); |
c1931173 |
63 | if (active_sh2 == &ssh2) |
64 | sh2_end_run(active_sh2, 1); |
65 | } |
19886062 |
66 | |
a8fd6e37 |
67 | elprintf(EL_32X, "update_irls: m %d/%d, s %d/%d", mlvl, mrun, slvl, srun); |
4ea707e1 |
68 | } |
69 | |
be2c4208 |
70 | void Pico32xStartup(void) |
71 | { |
72 | elprintf(EL_STATUS|EL_32X, "32X startup"); |
73 | |
679af8a3 |
74 | // TODO: OOM handling |
be2c4208 |
75 | PicoAHW |= PAHW_32X; |
f81107f5 |
76 | sh2_init(&msh2, 0, &ssh2); |
4ea707e1 |
77 | msh2.irq_callback = sh2_irq_cb; |
f81107f5 |
78 | sh2_init(&ssh2, 1, &msh2); |
4ea707e1 |
79 | ssh2.irq_callback = sh2_irq_cb; |
83ff19ec |
80 | |
81 | PicoMemSetup32x(); |
045a4c52 |
82 | p32x_pwm_ctl_changed(); |
a8fd6e37 |
83 | p32x_timers_recalc(); |
acd35d4c |
84 | |
be2c4208 |
85 | if (!Pico.m.pal) |
974fdb5b |
86 | Pico32x.vdp_regs[0] |= P32XV_nPAL; |
be2c4208 |
87 | |
2446536b |
88 | rendstatus_old = -1; |
89 | |
974fdb5b |
90 | emu_32x_startup(); |
be2c4208 |
91 | } |
92 | |
83ff19ec |
93 | #define HWSWAP(x) (((x) << 16) | ((x) >> 16)) |
94 | void p32x_reset_sh2s(void) |
95 | { |
96 | elprintf(EL_32X, "sh2 reset"); |
97 | |
98 | sh2_reset(&msh2); |
99 | sh2_reset(&ssh2); |
cd0ace28 |
100 | sh2_peripheral_reset(&msh2); |
101 | sh2_peripheral_reset(&ssh2); |
83ff19ec |
102 | |
103 | // if we don't have BIOS set, perform it's work here. |
104 | // MSH2 |
105 | if (p32x_bios_m == NULL) { |
106 | unsigned int idl_src, idl_dst, idl_size; // initial data load |
107 | unsigned int vbr; |
108 | |
109 | // initial data |
110 | idl_src = HWSWAP(*(unsigned int *)(Pico.rom + 0x3d4)) & ~0xf0000000; |
111 | idl_dst = HWSWAP(*(unsigned int *)(Pico.rom + 0x3d8)) & ~0xf0000000; |
112 | idl_size= HWSWAP(*(unsigned int *)(Pico.rom + 0x3dc)); |
113 | if (idl_size > Pico.romsize || idl_src + idl_size > Pico.romsize || |
114 | idl_size > 0x40000 || idl_dst + idl_size > 0x40000 || (idl_src & 3) || (idl_dst & 3)) { |
115 | elprintf(EL_STATUS|EL_ANOMALY, "32x: invalid initial data ptrs: %06x -> %06x, %06x", |
116 | idl_src, idl_dst, idl_size); |
117 | } |
118 | else |
119 | memcpy(Pico32xMem->sdram + idl_dst, Pico.rom + idl_src, idl_size); |
120 | |
121 | // GBR/VBR |
122 | vbr = HWSWAP(*(unsigned int *)(Pico.rom + 0x3e8)); |
123 | sh2_set_gbr(0, 0x20004000); |
124 | sh2_set_vbr(0, vbr); |
125 | |
126 | // checksum and M_OK |
127 | Pico32x.regs[0x28 / 2] = *(unsigned short *)(Pico.rom + 0x18e); |
128 | // program will set M_OK |
129 | } |
130 | |
131 | // SSH2 |
132 | if (p32x_bios_s == NULL) { |
133 | unsigned int vbr; |
134 | |
135 | // GBR/VBR |
136 | vbr = HWSWAP(*(unsigned int *)(Pico.rom + 0x3ec)); |
137 | sh2_set_gbr(1, 0x20004000); |
138 | sh2_set_vbr(1, vbr); |
139 | // program will set S_OK |
140 | } |
ed4402a7 |
141 | |
142 | msh2.m68krcycles_done = ssh2.m68krcycles_done = SekCyclesDoneT(); |
83ff19ec |
143 | } |
144 | |
be2c4208 |
145 | void Pico32xInit(void) |
146 | { |
ed4402a7 |
147 | if (msh2.mult_m68k_to_sh2 == 0 || msh2.mult_sh2_to_m68k == 0) |
148 | Pico32xSetClocks(PICO_MSH2_HZ, 0); |
149 | if (ssh2.mult_m68k_to_sh2 == 0 || ssh2.mult_sh2_to_m68k == 0) |
150 | Pico32xSetClocks(0, PICO_MSH2_HZ); |
974fdb5b |
151 | } |
152 | |
153 | void PicoPower32x(void) |
154 | { |
155 | memset(&Pico32x, 0, sizeof(Pico32x)); |
5e49c3a8 |
156 | |
83ff19ec |
157 | Pico32x.regs[0] = P32XS_REN|P32XS_nRES; // verified |
4a1fb183 |
158 | Pico32x.vdp_regs[0x0a/2] = P32XV_VBLK|P32XV_PEN; |
87accdf7 |
159 | Pico32x.sh2_regs[0] = P32XS2_ADEN; |
be2c4208 |
160 | } |
161 | |
5e49c3a8 |
162 | void PicoUnload32x(void) |
163 | { |
164 | if (Pico32xMem != NULL) |
b081408f |
165 | plat_munmap(Pico32xMem, sizeof(*Pico32xMem)); |
5e49c3a8 |
166 | Pico32xMem = NULL; |
e898de13 |
167 | sh2_finish(&msh2); |
168 | sh2_finish(&ssh2); |
5e49c3a8 |
169 | |
170 | PicoAHW &= ~PAHW_32X; |
171 | } |
172 | |
be2c4208 |
173 | void PicoReset32x(void) |
174 | { |
83ff19ec |
175 | if (PicoAHW & PAHW_32X) { |
61801d5b |
176 | msh2.m68krcycles_done = ssh2.m68krcycles_done = SekCyclesDoneT(); |
83ff19ec |
177 | Pico32x.sh2irqs |= P32XI_VRES; |
4d5dfee8 |
178 | p32x_update_irls(NULL, SekCyclesDoneT2()); |
19886062 |
179 | p32x_sh2_poll_event(&msh2, SH2_IDLE_STATES, 0); |
180 | p32x_sh2_poll_event(&ssh2, SH2_IDLE_STATES, 0); |
045a4c52 |
181 | p32x_pwm_ctl_changed(); |
a8fd6e37 |
182 | p32x_timers_recalc(); |
83ff19ec |
183 | } |
be2c4208 |
184 | } |
185 | |
974fdb5b |
186 | static void p32x_start_blank(void) |
187 | { |
7a961c19 |
188 | if (Pico32xDrawMode != PDM32X_OFF && !PicoSkipFrame) { |
5aec752d |
189 | int offs, lines; |
190 | |
191 | pprof_start(draw); |
192 | |
193 | offs = 8; lines = 224; |
7a961c19 |
194 | if ((Pico.video.reg[1] & 8) && !(PicoOpt & POPT_ALT_RENDERER)) { |
195 | offs = 0; |
196 | lines = 240; |
197 | } |
198 | |
199 | // XXX: no proper handling of 32col mode.. |
5a681086 |
200 | if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0 && // 32x not blanking |
201 | (Pico.video.reg[12] & 1) && // 40col mode |
202 | (PicoDrawMask & PDRAW_32X_ON)) |
203 | { |
204 | int md_bg = Pico.video.reg[7] & 0x3f; |
5a681086 |
205 | |
206 | // we draw full layer (not line-by-line) |
207 | PicoDraw32xLayer(offs, lines, md_bg); |
208 | } |
7a961c19 |
209 | else if (Pico32xDrawMode != PDM32X_32X_ONLY) |
210 | PicoDraw32xLayerMdOnly(offs, lines); |
5aec752d |
211 | |
212 | pprof_end(draw); |
5a681086 |
213 | } |
214 | |
974fdb5b |
215 | // enter vblank |
216 | Pico32x.vdp_regs[0x0a/2] |= P32XV_VBLK|P32XV_PEN; |
217 | |
4ea707e1 |
218 | // FB swap waits until vblank |
974fdb5b |
219 | if ((Pico32x.vdp_regs[0x0a/2] ^ Pico32x.pending_fb) & P32XV_FS) { |
220 | Pico32x.vdp_regs[0x0a/2] &= ~P32XV_FS; |
221 | Pico32x.vdp_regs[0x0a/2] |= Pico32x.pending_fb; |
222 | Pico32xSwapDRAM(Pico32x.pending_fb ^ 1); |
223 | } |
4ea707e1 |
224 | |
97d3f47f |
225 | Pico32x.sh2irqs |= P32XI_VINT; |
4d5dfee8 |
226 | p32x_update_irls(NULL, SekCyclesDoneT2()); |
19886062 |
227 | p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, 0); |
228 | p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, 0); |
974fdb5b |
229 | } |
230 | |
19886062 |
231 | // compare cycles, handling overflows |
232 | // check if a > b |
233 | #define CYCLES_GT(a, b) \ |
234 | ((int)((a) - (b)) > 0) |
235 | // check if a >= b |
236 | #define CYCLES_GE(a, b) \ |
237 | ((int)((a) - (b)) >= 0) |
238 | |
a8fd6e37 |
239 | /* events */ |
a8fd6e37 |
240 | static void fillend_event(unsigned int now) |
241 | { |
242 | Pico32x.vdp_regs[0x0a/2] &= ~P32XV_nFEN; |
19886062 |
243 | p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, now); |
244 | p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, now); |
a8fd6e37 |
245 | } |
246 | |
247 | typedef void (event_cb)(unsigned int now); |
248 | |
6a98f03e |
249 | unsigned int event_times[P32X_EVENT_COUNT]; |
a8fd6e37 |
250 | static unsigned int event_time_next; |
251 | static event_cb *event_cbs[] = { |
df63f1a6 |
252 | [P32X_EVENT_PWM] = p32x_pwm_irq_event, |
a8fd6e37 |
253 | [P32X_EVENT_FILLEND] = fillend_event, |
254 | }; |
255 | |
19886062 |
256 | // schedule event at some time 'after', in m68k clocks |
257 | void p32x_event_schedule(unsigned int now, enum p32x_event event, int after) |
a8fd6e37 |
258 | { |
19886062 |
259 | unsigned int when; |
260 | |
261 | when = (now + after) | 1; |
a8fd6e37 |
262 | |
263 | elprintf(EL_32X, "new event #%u %u->%u", event, now, when); |
264 | event_times[event] = when; |
265 | |
19886062 |
266 | if (event_time_next == 0 || CYCLES_GT(event_time_next, when)) |
a8fd6e37 |
267 | event_time_next = when; |
268 | } |
269 | |
19886062 |
270 | void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after) |
271 | { |
272 | unsigned int now = sh2_cycles_done_m68k(sh2); |
273 | int left_to_next; |
274 | |
275 | p32x_event_schedule(now, event, after); |
276 | |
277 | left_to_next = (event_time_next - now) * 3; |
c1931173 |
278 | sh2_end_run(sh2, left_to_next); |
19886062 |
279 | } |
280 | |
a8fd6e37 |
281 | static void run_events(unsigned int until) |
282 | { |
283 | int oldest, oldest_diff, time; |
284 | int i, diff; |
285 | |
286 | while (1) { |
287 | oldest = -1, oldest_diff = 0x7fffffff; |
288 | |
289 | for (i = 0; i < P32X_EVENT_COUNT; i++) { |
290 | if (event_times[i]) { |
291 | diff = event_times[i] - until; |
292 | if (diff < oldest_diff) { |
293 | oldest_diff = diff; |
294 | oldest = i; |
295 | } |
296 | } |
297 | } |
298 | |
299 | if (oldest_diff <= 0) { |
300 | time = event_times[oldest]; |
301 | event_times[oldest] = 0; |
302 | elprintf(EL_32X, "run event #%d %u", oldest, time); |
303 | event_cbs[oldest](time); |
304 | } |
305 | else if (oldest_diff < 0x7fffffff) { |
306 | event_time_next = event_times[oldest]; |
307 | break; |
308 | } |
309 | else { |
310 | event_time_next = 0; |
311 | break; |
312 | } |
313 | } |
314 | |
315 | if (oldest != -1) |
316 | elprintf(EL_32X, "next event #%d at %u", oldest, event_time_next); |
317 | } |
318 | |
19886062 |
319 | static inline void run_sh2(SH2 *sh2, int m68k_cycles) |
320 | { |
321 | int cycles, done; |
322 | |
323 | pevt_log_sh2_o(sh2, EVT_RUN_START); |
324 | sh2->state |= SH2_STATE_RUN; |
325 | cycles = C_M68K_TO_SH2(*sh2, m68k_cycles); |
f8675e28 |
326 | elprintf_sh2(sh2, EL_32X, "+run %u %d @%08x", |
327 | sh2->m68krcycles_done, cycles, sh2->pc); |
19886062 |
328 | |
329 | done = sh2_execute(sh2, cycles); |
330 | |
331 | sh2->m68krcycles_done += C_SH2_TO_M68K(*sh2, done); |
332 | sh2->state &= ~SH2_STATE_RUN; |
333 | pevt_log_sh2_o(sh2, EVT_RUN_END); |
f8675e28 |
334 | elprintf_sh2(sh2, EL_32X, "-run %u %d", |
335 | sh2->m68krcycles_done, done); |
19886062 |
336 | } |
337 | |
338 | // sync other sh2 to this one |
339 | // note: recursive call |
340 | void p32x_sync_other_sh2(SH2 *sh2, unsigned int m68k_target) |
341 | { |
f81107f5 |
342 | SH2 *osh2 = sh2->other_sh2; |
19886062 |
343 | int left_to_event; |
344 | int m68k_cycles; |
345 | |
346 | if (osh2->state & SH2_STATE_RUN) |
347 | return; |
348 | |
349 | m68k_cycles = m68k_target - osh2->m68krcycles_done; |
350 | if (m68k_cycles < 200) |
351 | return; |
352 | |
353 | if (osh2->state & SH2_IDLE_STATES) { |
354 | osh2->m68krcycles_done = m68k_target; |
355 | return; |
356 | } |
357 | |
f8675e28 |
358 | elprintf_sh2(osh2, EL_32X, "sync to %u %d", |
359 | m68k_target, m68k_cycles); |
19886062 |
360 | |
361 | run_sh2(osh2, m68k_cycles); |
362 | |
363 | // there might be new event to schedule current sh2 to |
364 | if (event_time_next) { |
365 | left_to_event = event_time_next - m68k_target; |
366 | left_to_event *= 3; |
367 | if (sh2_cycles_left(sh2) > left_to_event) { |
368 | if (left_to_event < 1) |
369 | left_to_event = 1; |
370 | sh2_end_run(sh2, left_to_event); |
371 | } |
372 | } |
373 | } |
a8fd6e37 |
374 | |
ed4402a7 |
375 | #define sync_sh2s_normal p32x_sync_sh2s |
376 | //#define sync_sh2s_lockstep p32x_sync_sh2s |
974fdb5b |
377 | |
a8fd6e37 |
378 | /* most timing is in 68k clock */ |
ed4402a7 |
379 | void sync_sh2s_normal(unsigned int m68k_target) |
380 | { |
a8fd6e37 |
381 | unsigned int now, target, timer_cycles; |
19886062 |
382 | int cycles; |
ed4402a7 |
383 | |
a8fd6e37 |
384 | elprintf(EL_32X, "sh2 sync to %u", m68k_target); |
ed4402a7 |
385 | |
27e26273 |
386 | if (!(Pico32x.regs[0] & P32XS_nRES)) { |
387 | msh2.m68krcycles_done = ssh2.m68krcycles_done = m68k_target; |
ed4402a7 |
388 | return; // rare |
27e26273 |
389 | } |
ed4402a7 |
390 | |
a8fd6e37 |
391 | now = msh2.m68krcycles_done; |
392 | if (CYCLES_GT(now, ssh2.m68krcycles_done)) |
393 | now = ssh2.m68krcycles_done; |
394 | timer_cycles = now; |
395 | |
396 | while (CYCLES_GT(m68k_target, now)) |
ed4402a7 |
397 | { |
a8fd6e37 |
398 | if (event_time_next && CYCLES_GE(now, event_time_next)) |
399 | run_events(now); |
ed4402a7 |
400 | |
a8fd6e37 |
401 | target = m68k_target; |
402 | if (event_time_next && CYCLES_GT(target, event_time_next)) |
403 | target = event_time_next; |
404 | |
405 | while (CYCLES_GT(target, now)) |
406 | { |
407 | elprintf(EL_32X, "sh2 exec to %u %d,%d/%d, flags %x", target, |
408 | target - msh2.m68krcycles_done, target - ssh2.m68krcycles_done, |
409 | m68k_target - now, Pico32x.emu_flags); |
ed4402a7 |
410 | |
19886062 |
411 | if (!(ssh2.state & SH2_IDLE_STATES)) { |
a8fd6e37 |
412 | cycles = target - ssh2.m68krcycles_done; |
413 | if (cycles > 0) { |
19886062 |
414 | run_sh2(&ssh2, cycles); |
a8fd6e37 |
415 | |
416 | if (event_time_next && CYCLES_GT(target, event_time_next)) |
417 | target = event_time_next; |
418 | } |
ed4402a7 |
419 | } |
420 | |
19886062 |
421 | if (!(msh2.state & SH2_IDLE_STATES)) { |
a8fd6e37 |
422 | cycles = target - msh2.m68krcycles_done; |
423 | if (cycles > 0) { |
19886062 |
424 | run_sh2(&msh2, cycles); |
a8fd6e37 |
425 | |
426 | if (event_time_next && CYCLES_GT(target, event_time_next)) |
427 | target = event_time_next; |
428 | } |
ed4402a7 |
429 | } |
a8fd6e37 |
430 | |
19886062 |
431 | now = target; |
432 | if (!(msh2.state & SH2_IDLE_STATES)) { |
433 | if (CYCLES_GT(now, msh2.m68krcycles_done)) |
434 | now = msh2.m68krcycles_done; |
435 | } |
436 | if (!(ssh2.state & SH2_IDLE_STATES)) { |
437 | if (CYCLES_GT(now, ssh2.m68krcycles_done)) |
438 | now = ssh2.m68krcycles_done; |
439 | } |
ed4402a7 |
440 | } |
a8fd6e37 |
441 | |
045a4c52 |
442 | p32x_timers_do(now - timer_cycles); |
a8fd6e37 |
443 | timer_cycles = now; |
ed4402a7 |
444 | } |
19886062 |
445 | |
446 | // advance idle CPUs |
447 | if (msh2.state & SH2_IDLE_STATES) { |
448 | if (CYCLES_GT(m68k_target, msh2.m68krcycles_done)) |
449 | msh2.m68krcycles_done = m68k_target; |
450 | } |
451 | if (ssh2.state & SH2_IDLE_STATES) { |
452 | if (CYCLES_GT(m68k_target, ssh2.m68krcycles_done)) |
453 | ssh2.m68krcycles_done = m68k_target; |
454 | } |
236990cf |
455 | } |
acd35d4c |
456 | |
c987bb5c |
457 | #define STEP_68K 24 |
ed4402a7 |
458 | |
459 | void sync_sh2s_lockstep(unsigned int m68k_target) |
460 | { |
461 | unsigned int mcycles; |
462 | |
463 | mcycles = msh2.m68krcycles_done; |
464 | if (ssh2.m68krcycles_done < mcycles) |
465 | mcycles = ssh2.m68krcycles_done; |
466 | |
467 | while (mcycles < m68k_target) { |
468 | mcycles += STEP_68K; |
469 | sync_sh2s_normal(mcycles); |
470 | } |
87accdf7 |
471 | } |
472 | |
ed4402a7 |
473 | #define CPUS_RUN(m68k_cycles,s68k_cycles) do { \ |
474 | SekRunM68k(m68k_cycles); \ |
19886062 |
475 | if (Pico32x.emu_flags & (P32XF_68KCPOLL|P32XF_68KVPOLL)) \ |
476 | p32x_sync_sh2s(SekCyclesDoneT2()); \ |
ed4402a7 |
477 | } while (0) |
87accdf7 |
478 | |
ed4402a7 |
479 | #define PICO_32X |
974fdb5b |
480 | #include "../pico_cmn.c" |
481 | |
482 | void PicoFrame32x(void) |
483 | { |
4ea707e1 |
484 | Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank |
db1d3564 |
485 | if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0) // no forced blanking |
486 | Pico32x.vdp_regs[0x0a/2] &= ~P32XV_PEN; // no palette access |
4ea707e1 |
487 | |
19886062 |
488 | p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, 0); |
489 | p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, 0); |
974fdb5b |
490 | |
491 | PicoFrameStart(); |
492 | PicoFrameHints(); |
51d86e55 |
493 | sh2_drc_frame(); |
494 | |
19886062 |
495 | elprintf(EL_32X, "poll: %02x %02x %02x", |
496 | Pico32x.emu_flags & 3, msh2.state, ssh2.state); |
974fdb5b |
497 | } |
db1d3564 |
498 | |
ed4402a7 |
499 | // calculate multipliers against 68k clock (7670442) |
500 | // normally * 3, but effectively slower due to high latencies everywhere |
501 | // however using something lower breaks MK2 animations |
502 | void Pico32xSetClocks(int msh2_hz, int ssh2_hz) |
503 | { |
504 | float m68k_clk = (float)(OSC_NTSC / 7); |
505 | if (msh2_hz > 0) { |
506 | msh2.mult_m68k_to_sh2 = (int)((float)msh2_hz * (1 << CYCLE_MULT_SHIFT) / m68k_clk); |
507 | msh2.mult_sh2_to_m68k = (int)(m68k_clk * (1 << CYCLE_MULT_SHIFT) / (float)msh2_hz); |
508 | } |
509 | if (ssh2_hz > 0) { |
510 | ssh2.mult_m68k_to_sh2 = (int)((float)ssh2_hz * (1 << CYCLE_MULT_SHIFT) / m68k_clk); |
511 | ssh2.mult_sh2_to_m68k = (int)(m68k_clk * (1 << CYCLE_MULT_SHIFT) / (float)ssh2_hz); |
512 | } |
513 | } |
514 | |
27e26273 |
515 | void Pico32xStateLoaded(int is_early) |
516 | { |
517 | if (is_early) { |
518 | Pico32xMemStateLoaded(); |
519 | return; |
520 | } |
521 | |
19886062 |
522 | SekCycleCnt = 0; |
27e26273 |
523 | sh2s[0].m68krcycles_done = sh2s[1].m68krcycles_done = SekCycleCntT; |
4d5dfee8 |
524 | p32x_update_irls(NULL, SekCycleCntT); |
df63f1a6 |
525 | p32x_pwm_state_loaded(); |
27e26273 |
526 | run_events(SekCycleCntT); |
527 | } |
528 | |
ed4402a7 |
529 | // vim:shiftwidth=2:ts=2:expandtab |