32x: more wip
[picodrive.git] / pico / 32x / 32x.c
1 #include "../pico_int.h"
2 #include "../sound/ym2612.h"
3
4 struct Pico32x Pico32x;
5
6 void Pico32xStartup(void)
7 {
8   elprintf(EL_STATUS|EL_32X, "32X startup");
9
10   PicoAHW |= PAHW_32X;
11   PicoMemSetup32x();
12
13   if (!Pico.m.pal)
14     Pico32x.vdp_regs[0] |= P32XV_nPAL;
15
16   emu_32x_startup();
17 }
18
19 void Pico32xInit(void)
20 {
21 }
22
23 void PicoPower32x(void)
24 {
25   memset(&Pico32x, 0, sizeof(Pico32x));
26
27   Pico32x.regs[0] = 0x0082; // SH2 reset?
28   Pico32x.vdp_regs[0x0a/2] = P32XV_VBLK|P32XV_HBLK|P32XV_PEN;
29 }
30
31 void PicoUnload32x(void)
32 {
33   if (Pico32xMem != NULL)
34     free(Pico32xMem);
35   Pico32xMem = NULL;
36
37   PicoAHW &= ~PAHW_32X;
38 }
39
40 void PicoReset32x(void)
41 {
42   extern int p32x_csum_faked;
43   p32x_csum_faked = 0; // tmp
44 }
45
46 static void p32x_start_blank(void)
47 {
48   // enter vblank
49   Pico32x.vdp_regs[0x0a/2] |= P32XV_VBLK|P32XV_PEN;
50
51   // swap waits until vblank
52   if ((Pico32x.vdp_regs[0x0a/2] ^ Pico32x.pending_fb) & P32XV_FS) {
53     Pico32x.vdp_regs[0x0a/2] &= ~P32XV_FS;
54     Pico32x.vdp_regs[0x0a/2] |= Pico32x.pending_fb;
55     Pico32xSwapDRAM(Pico32x.pending_fb ^ 1);
56   }
57 }
58
59 // FIXME..
60 static __inline void SekRunM68k(int cyc)
61 {
62   int cyc_do;
63   SekCycleAim+=cyc;
64   if ((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;
65 #if defined(EMU_CORE_DEBUG)
66   // this means we do run-compare
67   SekCycleCnt+=CM_compareRun(cyc_do, 0);
68 #elif defined(EMU_C68K)
69   PicoCpuCM68k.cycles=cyc_do;
70   CycloneRun(&PicoCpuCM68k);
71   SekCycleCnt+=cyc_do-PicoCpuCM68k.cycles;
72 #elif defined(EMU_M68K)
73   SekCycleCnt+=m68k_execute(cyc_do);
74 #elif defined(EMU_F68K)
75   SekCycleCnt+=fm68k_emulate(cyc_do+1, 0, 0);
76 #endif
77 }
78
79 #define PICO_32X
80 #include "../pico_cmn.c"
81
82 void PicoFrame32x(void)
83 {
84   if ((Pico32x.vdp_regs[0] & 3 ) != 0) // no forced blanking
85     Pico32x.vdp_regs[0x0a/2] &= ~(P32XV_VBLK|P32XV_PEN); // get out of vblank
86
87   PicoFrameStart();
88   PicoFrameHints();
89 }