32x.c 17 KB

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