tweaking win32 port
[picodrive.git] / platform / win32 / GenaDrive / Main.cpp
index a8e3362..acc8fcd 100644 (file)
@@ -1,5 +1,5 @@
-\r
 #include "app.h"\r
+#include "version.h"\r
 #include <crtdbg.h>\r
 #include <commdlg.h>\r
 \r
@@ -8,42 +8,6 @@ HWND FrameWnd=NULL;
 \r
 int MainWidth=720,MainHeight=480;\r
 \r
-char AppName[]="GenaDrive";\r
-\r
-#ifdef STARSCREAM\r
-  extern "C" int SekReset();\r
-#endif\r
-\r
-// ------------------------------------ XBox Main ------------------------------------------\r
-#ifdef _XBOX\r
-\r
-static int MainCode()\r
-{\r
-  int ret=0;\r
-\r
-  ret=LoopInit(); if (ret) { LoopExit(); return 1; }\r
-\r
-  LoopQuit=0; LoopCode();\r
-  LoopExit();\r
-\r
-  return 0;\r
-}\r
-\r
-int __cdecl main()\r
-{\r
-  LD_LAUNCH_DASHBOARD launch;\r
-\r
-  MainCode();\r
-\r
-  // Go back to dashboard:\r
-  memset(&launch,0,sizeof(launch));\r
-  launch.dwReason=XLD_LAUNCH_DASHBOARD_MAIN_MENU;\r
-  XLaunchNewImage(NULL,(LAUNCH_DATA *)&launch);\r
-}\r
-#endif\r
-\r
-// ----------------------------------- Windows Main ----------------------------------------\r
-#ifndef _XBOX\r
 // Window proc for the frame window:\r
 static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
 {\r
@@ -88,7 +52,7 @@ static int FrameInit()
   top-=height; top>>=1;\r
 \r
   // Create the window:\r
-  FrameWnd=CreateWindow(wc.lpszClassName,AppName,style|WS_VISIBLE,\r
+  FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE,\r
     left,top,width,height,NULL,NULL,NULL,NULL);\r
 \r
   return 0;\r
@@ -102,19 +66,17 @@ static DWORD WINAPI ThreadCode(void *)
   return 0;\r
 }\r
 \r
-// starscream needs this\r
-unsigned char *rom_data = 0;\r
-unsigned int rom_size = 0;\r
-\r
 int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int)\r
 {\r
   MSG msg;\r
   int ret=0;\r
   DWORD tid=0;\r
   HANDLE thread=NULL;\r
+  unsigned char *rom_data = 0;\r
+  unsigned int rom_size = 0;\r
 \r
   FrameInit();\r
-  ret=LoopInit(); if (ret) { LoopExit(); return 1; }\r
+  ret=LoopInit(); if (ret) goto end0;\r
 \r
   // notaz: load rom\r
   static char rompath[MAX_PATH]; rompath[0] = 0;\r
@@ -125,27 +87,29 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int)
   if(strlen(rompath) > 4) rom = pm_open(rompath);\r
   if(!rom) {\r
     OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME));\r
-       of.lStructSize = sizeof(OPENFILENAME);\r
-       of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0";\r
-       of.lpstrFile = rompath; rompath[0] = 0;\r
-       of.nMaxFile = MAX_PATH;\r
-       of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;\r
-       if(!GetOpenFileName(&of)) return 1;\r
-       rom = pm_open(rompath);\r
-       if(!rom) return 1;\r
+    of.lStructSize = sizeof(OPENFILENAME);\r
+    of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen;*.zip\0";\r
+    of.lpstrFile = rompath; rompath[0] = 0;\r
+    of.nMaxFile = MAX_PATH;\r
+    of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;\r
+    if(!GetOpenFileName(&of)) goto end0;\r
+    rom = pm_open(rompath);\r
+    if(!rom) goto end0;\r
   }\r
   romname = rompath;\r
 \r
-  if(PicoCartLoad(rom, &rom_data, &rom_size)) {\r
-       //RDebug::Print(_L("PicoCartLoad() failed."));\r
-       //goto cleanup;\r
-  }\r
+  ret=PicoCartLoad(rom, &rom_data, &rom_size);\r
   pm_close(rom);\r
+  if (ret) {\r
+    error("failed to load ROM");\r
+    goto end0;\r
+  }\r
 \r
   PicoCartInsert(rom_data, rom_size);\r
 \r
   // only now we got the mode (pal/ntsc), so init sound now\r
-  DSoundInit();\r
+  ret=DSoundInit();\r
+  if (ret) error("Failed to init DirectSound"); // warning\r
 \r
   // Make another thread to run LoopCode():\r
   LoopQuit=0;\r
@@ -165,6 +129,7 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int)
   LoopQuit=1; WaitForSingleObject(thread,5000);\r
   CloseHandle(thread); thread=NULL;\r
 \r
+end0:\r
   LoopExit();\r
   DestroyWindow(FrameWnd);\r
 \r
@@ -178,5 +143,4 @@ extern void error(char *text)
 {\r
   MessageBox(FrameWnd, text, "Error", 0);\r
 }\r
-#endif\r
 \r