work on 'vblank on line start' problem, var changes, mask defines
[picodrive.git] / Pico / Pico.c
index 7978fed..2edc8ee 100644 (file)
 \r
 int PicoVer=0x0133;\r
 struct Pico Pico;\r
-int PicoOpt=0; // disable everything by default\r
-int PicoSkipFrame=0; // skip rendering frame?\r
+int PicoOpt = 0;\r
+int PicoSkipFrame = 0; // skip rendering frame?\r
+int emustatus = 0;     // rapid_ym2612, multi_ym_updates\r
+int PicoPad[2];        // Joypads, format is SACB RLDU\r
+int PicoAHW = 0;       // active addon hardware: scd_active, 32x_active, svp_active\r
 int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
 int PicoAutoRgnOrder = 0;\r
-int emustatus = 0; // rapid_ym2612, multi_ym_updates\r
+int z80startCycle, z80stopCycle; // in 68k cycles\r
+struct PicoSRAM SRam = {0,};\r
+\r
 void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware\r
 void (*PicoResetHook)(void) = NULL;\r
 void (*PicoLineHook)(int count) = NULL;\r
 \r
-struct PicoSRAM SRam = {0,};\r
-int z80startCycle, z80stopCycle; // in 68k cycles\r
-int PicoPad[2];  // Joypads, format is SACB RLDU\r
-int PicoMCD = 0; // mega CD status: scd_started\r
-\r
 // to be called once on emu init\r
 int PicoInit(void)\r
 {\r
@@ -48,7 +48,7 @@ int PicoInit(void)
 // to be called once on emu exit\r
 void PicoExit(void)\r
 {\r
-  if (PicoMCD&1)\r
+  if (PicoAHW & PAHW_MCD)\r
     PicoExitMCD();\r
   z80_exit();\r
 \r
@@ -71,7 +71,7 @@ void PicoPower(void)
   Pico.video.reg[0xc] = 0x81;\r
   Pico.video.reg[0xf] = 0x02;\r
 \r
-  if (PicoMCD & 1)\r
+  if (PicoAHW & PAHW_MCD)\r
     PicoPowerMCD();\r
 \r
   PicoReset();\r
@@ -92,10 +92,10 @@ int PicoReset(void)
   PicoMemReset();\r
   SekReset();\r
   // s68k doesn't have the TAS quirk, so we just globally set normal TAS handler in MCD mode (used by Batman games).\r
-  SekSetRealTAS(PicoMCD & 1);\r
+  SekSetRealTAS(PicoAHW & PAHW_MCD);\r
   SekCycleCntT=0;\r
 \r
-  if (PicoMCD & 1)\r
+  if (PicoAHW & PAHW_MCD)\r
     // needed for MCD to reset properly, probably some bug hides behind this..\r
     memset(Pico.ioports,0,sizeof(Pico.ioports));\r
   emustatus = 0;\r
@@ -155,10 +155,10 @@ int PicoReset(void)
   PsndReset(); // pal must be known here\r
 \r
   // create an empty "dma" to cause 68k exec start at random frame location\r
-  if (Pico.m.dma_xfers == 0 && !(PicoOpt&0x10000))\r
+  if (Pico.m.dma_xfers == 0 && !(PicoOpt&POPT_DIS_VDP_FIFO))\r
     Pico.m.dma_xfers = rand() & 0x1fff;\r
 \r
-  if (PicoMCD & 1) {\r
+  if (PicoAHW & PAHW_MCD) {\r
     PicoResetMCD();\r
     return 0;\r
   }\r
@@ -306,7 +306,7 @@ static void PicoRunZ80Simple(int line_from, int line_to)
   int line_from_r=line_from, line_to_r=line_to, line=0;\r
   int line_sample = Pico.m.pal ? 68 : 93;\r
 \r
-  if (!(PicoOpt&4) || Pico.m.z80Run == 0) line_to_r = 0;\r
+  if (!(PicoOpt&POPT_EN_Z80) || Pico.m.z80Run == 0) line_to_r = 0;\r
   else {\r
     extern const unsigned short vcounts[];\r
     if (z80startCycle) {\r
@@ -317,7 +317,7 @@ static void PicoRunZ80Simple(int line_from, int line_to)
     z80startCycle = SekCyclesDone();\r
   }\r
 \r
-  if (PicoOpt&1) {\r
+  if (PicoOpt&POPT_EN_FM) {\r
     // we have ym2612 enabled, so we have to run Z80 in lines, so we could update DAC and timers\r
     for (line = line_from; line < line_to; line++) {\r
       Psnd_timers_and_dac(line);\r
@@ -358,7 +358,7 @@ static int PicoFrameSimple(void)
   }\r
 \r
   // a hack for VR, to get it running in fast mode\r
-  if (PicoRead16Hook == PicoSVPRead16)\r
+  if (PicoAHW & PAHW_SVP)\r
     Pico.ram[0xd864^1] = 0x1a;\r
 \r
   // we don't emulate DMA timing in this mode\r
@@ -409,7 +409,7 @@ static int PicoFrameSimple(void)
   }\r
 \r
   // another hack for VR (it needs hints to work)\r
-  if (PicoRead16Hook == PicoSVPRead16) {\r
+  if (PicoAHW & PAHW_SVP) {\r
     Pico.ram[0xd864^1] = 1;\r
     pv->pending_ints|=0x10;\r
     if (pv->reg[0]&0x10) SekInterrupt(4);\r
@@ -419,7 +419,7 @@ static int PicoFrameSimple(void)
   // render screen\r
   if (!PicoSkipFrame)\r
   {\r
-    if (!(PicoOpt&0x10))\r
+    if (!(PicoOpt&POPT_ALT_RENDERER))\r
     {\r
       // Draw the screen\r
 #if CAN_HANDLE_240_LINES\r
@@ -439,7 +439,7 @@ static int PicoFrameSimple(void)
   }\r
 \r
   // here we render sound if ym2612 is disabled\r
-  if (!(PicoOpt&1) && PsndOut) {\r
+  if (!(PicoOpt&POPT_EN_FM) && PsndOut) {\r
     int len = PsndRender(0, PsndLen);\r
     if (PicoWriteSound) PicoWriteSound(len);\r
     // clear sound buffer\r
@@ -470,10 +470,11 @@ static int PicoFrameSimple(void)
   }\r
 \r
   if (pv->reg[1]&0x20) SekInterrupt(6); // Set IRQ\r
-  if (Pico.m.z80Run && (PicoOpt&4))\r
+  if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))\r
     z80_int();\r
 \r
-  while (sects) {\r
+  while (sects)\r
+  {\r
     lines += lines_step;\r
 \r
     SekRunM68k(cycles_68k_vblock);\r
@@ -502,23 +503,23 @@ int PicoFrame(void)
 \r
   Pico.m.frame_count++;\r
 \r
-  if (PicoMCD & 1) {\r
+  if (PicoAHW & PAHW_MCD) {\r
     PicoFrameMCD();\r
     return 0;\r
   }\r
 \r
   // be accurate if we are asked for this\r
-  if(PicoOpt&0x40) acc=1;\r
+  if (PicoOpt&POPT_ACC_TIMING) acc=1;\r
   // don't be accurate in alternative render mode, as hint effects will not be rendered anyway\r
-  else if(PicoOpt&0x10) acc = 0;\r
+  else if (PicoOpt&POPT_ALT_RENDERER) acc = 0;\r
   else acc=Pico.video.reg[0]&0x10; // be accurate if hints are used\r
 \r
   //if(Pico.video.reg[12]&0x2) Pico.video.status ^= 0x10; // change odd bit in interlace mode\r
 \r
-  if(!(PicoOpt&0x10))\r
+  if (!(PicoOpt&POPT_ALT_RENDERER))\r
     PicoFrameStart();\r
 \r
-  if(acc)\r
+  if (acc)\r
        PicoFrameHints();\r
   else PicoFrameSimple();\r
 \r