X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fwin32%2FGenaDrive%2FMain.cpp;h=f5f41cc3c66c7750a04459050148f1a7122ddab1;hb=03a265e5ebabff7adbb4f97387f81e9b0428dbee;hp=edab4305343ae632697de8f0e7787d1dae4a2383;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/platform/win32/GenaDrive/Main.cpp b/platform/win32/GenaDrive/Main.cpp index edab430..f5f41cc 100644 --- a/platform/win32/GenaDrive/Main.cpp +++ b/platform/win32/GenaDrive/Main.cpp @@ -1,54 +1,25 @@ - #include "app.h" +#include "version.h" #include #include char *romname; HWND FrameWnd=NULL; +RECT FrameRectMy; int MainWidth=720,MainHeight=480; -char AppName[]="GenaDrive"; - -#ifdef STARSCREAM - extern "C" int SekReset(); -#endif - -// ------------------------------------ XBox Main ------------------------------------------ -#ifdef _XBOX - -static int MainCode() -{ - int ret=0; - - ret=LoopInit(); if (ret) { LoopExit(); return 1; } - - LoopQuit=0; LoopCode(); - LoopExit(); - - return 0; -} - -int __cdecl main() -{ - LD_LAUNCH_DASHBOARD launch; - - MainCode(); - - // Go back to dashboard: - memset(&launch,0,sizeof(launch)); - launch.dwReason=XLD_LAUNCH_DASHBOARD_MAIN_MENU; - XLaunchNewImage(NULL,(LAUNCH_DATA *)&launch); -} -#endif - -// ----------------------------------- Windows Main ---------------------------------------- -#ifndef _XBOX // Window proc for the frame window: static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { - if (msg==WM_CLOSE) { PostQuitMessage(0); return 0; } - if (msg==WM_DESTROY) FrameWnd=NULL; // Blank handle + switch (msg) + { + case WM_CLOSE: PostQuitMessage(0); return 0; + case WM_DESTROY: FrameWnd=NULL; break; // Blank handle + case WM_SIZE: + case WM_MOVE: + case WM_SIZING: GetWindowRect(hwnd, &FrameRectMy); break; + } return DefWindowProc(hwnd,msg,wparam,lparam); } @@ -88,9 +59,13 @@ static int FrameInit() top-=height; top>>=1; // Create the window: - FrameWnd=CreateWindow(wc.lpszClassName,AppName,style|WS_VISIBLE, + FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE, left,top,width,height,NULL,NULL,NULL,NULL); + ShowWindow(FrameWnd, SW_NORMAL); + UpdateWindow(FrameWnd); + GetWindowRect(FrameWnd, &FrameRectMy); + return 0; } @@ -102,51 +77,51 @@ static DWORD WINAPI ThreadCode(void *) return 0; } -// starscream needs this -unsigned char *rom_data = 0; -unsigned int rom_size = 0; - int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) { MSG msg; int ret=0; DWORD tid=0; HANDLE thread=NULL; + unsigned char *rom_data = 0; + unsigned int rom_size = 0; + + static char rompath[MAX_PATH] = { 0, }; + pm_file *rom = NULL; + + FrameInit(); + ret=LoopInit(); if (ret) goto end0; // notaz: load rom - static char rompath[MAX_PATH]; rompath[0] = 0; strcpy(rompath, cmdline + (cmdline[0] == '\"' ? 1 : 0)); if(rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0; - FILE *rom = 0; - if(strlen(rompath) > 4) rom = fopen(rompath, "rb"); + if(strlen(rompath) > 4) rom = pm_open(rompath); if(!rom) { OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); - of.lStructSize = sizeof(OPENFILENAME); - of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0"; - of.lpstrFile = rompath; rompath[0] = 0; - of.nMaxFile = MAX_PATH; - of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; - if(!GetOpenFileName(&of)) return 1; - rom = fopen(rompath, "rb"); - if(!rom) return 1; + of.lStructSize = sizeof(OPENFILENAME); + of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen;*.zip\0"; + of.lpstrFile = rompath; rompath[0] = 0; + of.nMaxFile = MAX_PATH; + of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; + if(!GetOpenFileName(&of)) goto end0; + rom = pm_open(rompath); + if(!rom) goto end0; } romname = rompath; - if(PicoCartLoad(rom, &rom_data, &rom_size)) { - //RDebug::Print(_L("PicoCartLoad() failed.")); - //goto cleanup; + ret=PicoCartLoad(rom, &rom_data, &rom_size); + pm_close(rom); + if (ret) { + error("failed to load ROM"); + goto end0; } - FrameInit(); - ret=LoopInit(); if (ret) { LoopExit(); return 1; } - PicoCartInsert(rom_data, rom_size); // only now we got the mode (pal/ntsc), so init sound now - DSoundInit(); - - preLoopInit(); + ret=DSoundInit(); + if (ret) error("Failed to init DirectSound"); // warning // Make another thread to run LoopCode(): LoopQuit=0; @@ -166,6 +141,7 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) LoopQuit=1; WaitForSingleObject(thread,5000); CloseHandle(thread); thread=NULL; +end0: LoopExit(); DestroyWindow(FrameWnd); @@ -174,5 +150,9 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) _CrtDumpMemoryLeaks(); return 0; } -#endif + +extern void error(char *text) +{ + MessageBox(FrameWnd, text, "Error", 0); +}