1 #include "../pico_int.h"
2 #include "../sound/ym2612.h"
4 struct Pico32x Pico32x;
6 static void sh2_irq_cb(int id, int level)
9 elprintf(EL_32X, "%csh2 ack %d @ %08x", id ? 's' : 'm', level, sh2_pc(id));
12 void p32x_update_irls(void)
14 int irqs, mlvl = 0, slvl = 0;
17 irqs = (Pico32x.sh2irqs | Pico32x.sh2irqi[0]) & ((Pico32x.sh2irq_mask[0] << 3) | P32XI_VRES);
23 irqs = (Pico32x.sh2irqs | Pico32x.sh2irqi[1]) & ((Pico32x.sh2irq_mask[1] << 3) | P32XI_VRES);
28 elprintf(EL_32X, "update_irls: m %d, s %d", mlvl, slvl);
29 sh2_irl_irq(&msh2, mlvl);
30 sh2_irl_irq(&ssh2, slvl);
33 p32x_poll_event(mlvl | (slvl << 1), 0);
36 void Pico32xStartup(void)
38 elprintf(EL_STATUS|EL_32X, "32X startup");
44 msh2.irq_callback = sh2_irq_cb;
48 ssh2.irq_callback = sh2_irq_cb;
52 Pico32x.vdp_regs[0] |= P32XV_nPAL;
57 void Pico32xInit(void)
61 void PicoPower32x(void)
63 memset(&Pico32x, 0, sizeof(Pico32x));
65 Pico32x.regs[0] = 0x0082; // SH2 reset?
66 Pico32x.vdp_regs[0x0a/2] = P32XV_VBLK|P32XV_HBLK|P32XV_PEN;
67 Pico32x.sh2_regs[0] = P32XS2_ADEN;
70 void PicoUnload32x(void)
72 if (Pico32xMem != NULL)
79 void PicoReset32x(void)
81 extern int p32x_csum_faked;
82 p32x_csum_faked = 0; // tmp
85 static void p32x_start_blank(void)
88 Pico32x.vdp_regs[0x0a/2] |= P32XV_VBLK|P32XV_PEN;
90 // FB swap waits until vblank
91 if ((Pico32x.vdp_regs[0x0a/2] ^ Pico32x.pending_fb) & P32XV_FS) {
92 Pico32x.vdp_regs[0x0a/2] &= ~P32XV_FS;
93 Pico32x.vdp_regs[0x0a/2] |= Pico32x.pending_fb;
94 Pico32xSwapDRAM(Pico32x.pending_fb ^ 1);
97 Pico32x.sh2irqs |= P32XI_VINT;
99 p32x_poll_event(3, 1);
103 static __inline void SekRunM68k(int cyc)
107 if (Pico32x.emu_flags & P32XF_68KPOLL) {
108 SekCycleCnt = SekCycleAim;
111 if ((cyc_do = SekCycleAim - SekCycleCnt) <= 0)
113 #if defined(EMU_CORE_DEBUG)
114 // this means we do run-compare
115 SekCycleCnt+=CM_compareRun(cyc_do, 0);
116 #elif defined(EMU_C68K)
117 PicoCpuCM68k.cycles=cyc_do;
118 CycloneRun(&PicoCpuCM68k);
119 SekCycleCnt+=cyc_do-PicoCpuCM68k.cycles;
120 #elif defined(EMU_M68K)
121 SekCycleCnt+=m68k_execute(cyc_do);
122 #elif defined(EMU_F68K)
123 SekCycleCnt+=fm68k_emulate(cyc_do+1, 0, 0);
127 // ~1463.8, but due to cache misses and slow mem
128 // it's much lower than that
129 //#define SH2_LINE_CYCLES 735
130 #define CYCLES_M68K2SH2(x) ((x) * 9 / 4)
133 #define RUN_SH2S_SIMPLE(m68k_cycles) \
134 if (!(Pico32x.emu_flags & (P32XF_MSH2POLL|P32XF_MSH2VPOLL))) \
135 sh2_execute(&msh2, CYCLES_M68K2SH2(m68k_cycles)); \
136 if (!(Pico32x.emu_flags & (P32XF_SSH2POLL|P32XF_SSH2VPOLL))) \
137 sh2_execute(&ssh2, CYCLES_M68K2SH2(m68k_cycles))
140 #define RUN_SH2S_LOCKSTEP(m68k_cycles) \
143 for (i = 0; i < CYCLES_M68K2SH2(m68k_cycles); i+= STEP) { \
144 sh2_execute(&msh2, STEP); \
145 sh2_execute(&ssh2, STEP); \
149 #define RUN_SH2S RUN_SH2S_SIMPLE
150 //#define RUN_SH2S RUN_SH2S_LOCKSTEP
152 #include "../pico_cmn.c"
154 void PicoFrame32x(void)
156 pwm_frame_smp_cnt = 0;
158 Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank
159 if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0) // no forced blanking
160 Pico32x.vdp_regs[0x0a/2] &= ~P32XV_PEN; // no palette access
162 p32x_poll_event(3, 1);
166 elprintf(EL_32X, "poll: %02x", Pico32x.emu_flags);