1.45a Pico win32, code move
[picodrive.git] / platform / win32 / GenaDrive / Loop.cpp
index 2781a91..8aa0561 100644 (file)
@@ -1,11 +1,7 @@
 #include "app.h"\r
 //#include "FileMenu.h"\r
 \r
-extern char *romname;\r
-int fastForward=0;\r
-int frameStep=0;\r
-\r
-char LoopQuit=0;\r
+char LoopQuit=0,LoopWait=0,LoopWaiting=0;\r
 static FILE *DebugFile=NULL;\r
 int LoopMode=0;\r
 static void UpdateSound(int len);\r
@@ -17,22 +13,21 @@ int LoopInit()
   // bits LSb->MSb:\r
   // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound;\r
   // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites\r
-  PicoOpt=0x1f;\r
+  PicoOpt=0xbccf;\r
   PsndRate=44100;\r
-  //PsndLen=PsndRate/60;   // calculated later by pico itself\r
 \r
   // Init Direct3D:\r
-  ret=DirectInit(); if (ret) { error("Direct3D init failed"); return 1; }\r
+  ret=DirectInit(); if (ret) { error("DirectX video init failed"); return 1; }\r
   InputInit();\r
 \r
   // Init DirectSound:\r
   //DSoundInit();\r
 \r
   ret=EmuInit(); if (ret) return 1;\r
-  //FileMenu.init();\r
 \r
   LoopMode=8;\r
   PicoWriteSound = UpdateSound;\r
+  PicoAutoRgnOrder = 0x184;\r
 \r
   return 0;\r
 }\r
@@ -43,9 +38,7 @@ void LoopExit()
 {\r
   dprintf(debugString());\r
 \r
-  //FileMenu.exit();\r
   EmuExit();\r
-  DSoundExit(); PsndLen=0;\r
   InputExit();\r
   DirectExit();\r
 \r
@@ -55,98 +48,29 @@ void LoopExit()
 \r
 // ----------------------------------------------------------------\r
 \r
-int emu_frame = 0;\r
-\r
-static int DoGame()\r
+static void UpdateSound(int len)\r
 {\r
-  if(fastForward) { PicoSkipFrame+=1; PicoSkipFrame&=7; }\r
-  else PicoSkipFrame=0;\r
-\r
-  if(frameStep==1)      return 0;\r
-  else if(frameStep==3) frameStep=1;\r
-\r
-  EmuFrame();\r
-  emu_frame++;\r
-\r
-  if (Inp.held[7]==1) LoopMode=2; // Right thumb = Toggle Menu\r
-\r
-  return 0;\r
+  while (DSoundUpdate() > 0) { Sleep(1); }\r
+  //while (DSoundUpdate()== 0) { }\r
 }\r
-// ----------------------------------------------------------------\r
 \r
-/*\r
-static int MenuUpdate()\r
+static void PostProcess()\r
 {\r
-  int delta=0;\r
-\r
-  if (Inp.repeat[0]) delta-=0x100;\r
-  if (Inp.repeat[1]) delta+=0x100;\r
-\r
-  if (Inp.button[14]>30) delta-=Inp.button[14]-30;\r
-  if (Inp.button[15]>30) delta+=Inp.button[15]-30;\r
-\r
-  if (delta) FileMenu.scroll(delta);\r
-\r
-  if (Inp.held[8]==1 || Inp.held[10]==1 || Inp.held[4]==1) // A, X or Start\r
+  static int lock_to_1_1_prev = 0, is_40_prev = -1;\r
+  int is_40;\r
+  PicoGetInternal(PI_IS40_CELL, (pint_ret_t *)&is_40);\r
+  if (lock_to_1_1)\r
   {\r
-    //RomFree();\r
-    //FileMenu.getFilePath(RomName);\r
-    //RomLoad();\r
-    //LoopMode=8; // Go to game\r
+    if (is_40 != is_40_prev || !lock_to_1_1_prev)\r
+      PostMessage(FrameWnd, WM_COMMAND, 0x20000 | (is_40 ? 1100 : 1101), 0);\r
   }\r
-\r
-  if (Inp.held[7]==1) LoopMode=8; // Right thumb = Toggle Menu\r
-\r
-  return 0;\r
-}\r
-\r
-static int MenuRender()\r
-{\r
-  WCHAR text[80]={0};\r
-  wsprintfW(text,L"%.40S v%x.%.3x",AppName,PicoVer>>12,PicoVer&0xfff);\r
-  FontSetColour(0x60c0ff);\r
-  FontText(text,64,48);\r
-\r
-  FileMenu.render();\r
-\r
-  return 0;\r
-}\r
-*/\r
-\r
-// ----------------------------------------------------------------\r
-\r
-static int ModeUpdate()\r
-{\r
-  if (Inp.held[14] && Inp.held[15] && Inp.held[12]==1) LoopQuit=1; // L+R+black to quit:\r
-  if (Inp.button[4]>30 && Inp.button[5]>30) LoopQuit=1; // Start and back to quit\r
-\r
-  if (LoopMode==8) { DoGame(); return 0; }\r
-\r
-  if (DSoundNext) memset(DSoundNext,0,PsndLen<<2);\r
-\r
-//  if (LoopMode==2) { FileMenu.scan(); LoopMode++; return 0; }\r
-//  if (LoopMode==3) { MenuUpdate(); return 0; }\r
-//  if (LoopMode==4) { LightCalUpdate(); return 0; }\r
-\r
-  LoopMode=2; // Unknown mode, go to rom menu\r
-  return 0;\r
-}\r
-\r
-\r
-static int ModeRender()\r
-{\r
-  DirectScreen();\r
-//  if (LoopMode==3) MenuRender();\r
-//  if (LoopMode==4) LightCalRender();\r
-\r
-  return 0;\r
-}\r
-\r
-static void UpdateSound(int len)\r
-{\r
-  if(fastForward) return;\r
-  while (DSoundUpdate()) { Sleep(1); }\r
-  while (DSoundUpdate()==0) { }\r
+  if (is_40 != is_40_prev)\r
+  {\r
+    EmuScreenRect.left  = is_40 ?   0 :  32;\r
+    EmuScreenRect.right = is_40 ? 320 : 256+32;\r
+  }\r
+  lock_to_1_1_prev = lock_to_1_1;\r
+  is_40_prev = is_40;\r
 }\r
 \r
 int LoopCode()\r
@@ -155,14 +79,23 @@ int LoopCode()
   // Main loop:\r
   while (!LoopQuit)\r
   {\r
+    if (LoopWait)\r
+    {\r
+      DSoundExit();\r
+      while (!LoopQuit && LoopWait) { LoopWaiting=1; Sleep(100); }\r
+      if (LoopQuit) break;\r
+      DSoundInit();\r
+    }\r
     InputUpdate();\r
 \r
     DirectClear(0);\r
-    ModeUpdate();\r
-    ModeRender();\r
+    EmuFrame();\r
+    PostProcess();\r
+    DirectScreen();\r
     DirectPresent();\r
 //      UpdateSound();\r
   }\r
+  DSoundExit();\r
 \r
   return 0;\r
 }\r
@@ -195,7 +128,7 @@ extern "C" int dprintf(char *format, ...)
 }\r
 #endif\r
 \r
-extern "C" int dprintf2(char *format, ...)\r
+extern "C" int lprintf(char *format, ...)\r
 {\r
   char str[512];\r
   va_list val=NULL;\r