initial libretro port
[picodrive.git] / pico / pico.c
index d312386..6a065e6 100644 (file)
@@ -1,11 +1,11 @@
-// PicoDrive\r
-\r
-// (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006-2008 notaz, All rights reserved.\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
-\r
+/*\r
+ * PicoDrive\r
+ * (c) Copyright Dave, 2004\r
+ * (C) notaz, 2006-2010\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
 \r
 #include "pico_int.h"\r
 #include "sound/ym2612.h"\r
@@ -23,6 +23,9 @@ struct PicoSRAM SRam;
 int emustatus;         // rapid_ym2612, multi_ym_updates\r
 int scanlines_total;\r
 \r
+int p32x_msh2_multiplier = MSH2_MULTI_DEFAULT;\r
+int p32x_ssh2_multiplier = SSH2_MULTI_DEFAULT;\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)(void) = NULL;\r
@@ -192,10 +195,8 @@ int PicoReset(void)
   if (!(PicoOpt & POPT_DIS_IDLE_DET))\r
     SekInitIdleDet();\r
 \r
-  if (PicoOpt & POPT_EN_32X) {\r
+  if (PicoOpt & POPT_EN_32X)\r
     PicoReset32x();\r
-    return 0;\r
-  }\r
 \r
   // reset sram state; enable sram access by default if it doesn't overlap with ROM\r
   Pico.m.sram_reg = 0;\r
@@ -209,7 +210,7 @@ int PicoReset(void)
   return 0;\r
 }\r
 \r
-// flush cinfig changes before emu loop starts\r
+// flush config changes before emu loop starts\r
 void PicoLoopPrepare(void)\r
 {\r
   if (PicoRegionOverride)\r
@@ -219,6 +220,9 @@ void PicoLoopPrepare(void)
   // FIXME: PAL has 313 scanlines..\r
   scanlines_total = Pico.m.pal ? 312 : 262;\r
 \r
+  Pico.m.dirtyPal = 1;\r
+  rendstatus_old = -1;\r
+\r
   if (PicoAHW & PAHW_32X)\r
     p32x_timers_recalc();\r
 }\r
@@ -272,6 +276,8 @@ PICO_INTERNAL int CheckDMA(void)
 static __inline void SekRunM68k(int cyc)\r
 {\r
   int cyc_do;\r
+  pprof_start(m68k);\r
+\r
   SekCycleAim+=cyc;\r
   if ((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;\r
 #if defined(EMU_CORE_DEBUG)\r
@@ -286,6 +292,8 @@ static __inline void SekRunM68k(int cyc)
 #elif defined(EMU_F68K)\r
   SekCycleCnt+=fm68k_emulate(cyc_do+1, 0, 0);\r
 #endif\r
+\r
+  pprof_end(m68k);\r
 }\r
 \r
 #include "pico_cmn.c"\r
@@ -303,38 +311,47 @@ PICO_INTERNAL void PicoSyncZ80(int m68k_cycles_done)
   z80_cycle_aim = cycles_68k_to_z80(m68k_cycles_done);\r
   cnt = z80_cycle_aim - z80_cycle_cnt;\r
 \r
+  pprof_start(z80);\r
+\r
   elprintf(EL_BUSREQ, "z80 sync %i (%i|%i -> %i|%i)", cnt, z80_cycle_cnt, z80_cycle_cnt / 228,\r
     z80_cycle_aim, z80_cycle_aim / 228);\r
 \r
   if (cnt > 0)\r
     z80_cycle_cnt += z80_run(cnt);\r
+\r
+  pprof_end(z80);\r
 }\r
 \r
 \r
 void PicoFrame(void)\r
 {\r
+  pprof_start(frame);\r
+\r
   Pico.m.frame_count++;\r
 \r
   if (PicoAHW & PAHW_SMS) {\r
     PicoFrameMS();\r
-    return;\r
+    goto end;\r
   }\r
 \r
   // TODO: MCD+32X\r
   if (PicoAHW & PAHW_MCD) {\r
     PicoFrameMCD();\r
-    return;\r
+    goto end;\r
   }\r
 \r
   if (PicoAHW & PAHW_32X) {\r
     PicoFrame32x();\r
-    return;\r
+    goto end;\r
   }\r
 \r
   //if(Pico.video.reg[12]&0x2) Pico.video.status ^= 0x10; // change odd bit in interlace mode\r
 \r
   PicoFrameStart();\r
   PicoFrameHints();\r
+\r
+end:\r
+  pprof_end(frame);\r
 }\r
 \r
 void PicoFrameDrawOnly(void)\r