X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fwin32%2FGenaDrive%2FMain.cpp;h=93db3cd9e6d6e5eeb86fc1e5829c0c1b60a812a9;hb=c9e1affca5438353fdb156fb07a747af83251e14;hp=edab4305343ae632697de8f0e7787d1dae4a2383;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/platform/win32/GenaDrive/Main.cpp b/platform/win32/GenaDrive/Main.cpp index edab430..93db3cd 100644 --- a/platform/win32/GenaDrive/Main.cpp +++ b/platform/win32/GenaDrive/Main.cpp @@ -1,54 +1,134 @@ - #include "app.h" +#include "version.h" #include #include -char *romname; +char *romname=NULL; HWND FrameWnd=NULL; +RECT FrameRectMy; +int lock_to_1_1 = 1; int MainWidth=720,MainHeight=480; -char AppName[]="GenaDrive"; - -#ifdef STARSCREAM - extern "C" int SekReset(); -#endif - -// ------------------------------------ XBox Main ------------------------------------------ -#ifdef _XBOX +static HMENU mdisplay = 0; +static int rom_loaded = 0; -static int MainCode() +static void UpdateRect() { - int ret=0; + WINDOWINFO wi; + memset(&wi, 0, sizeof(wi)); + wi.cbSize = sizeof(wi); + GetWindowInfo(FrameWnd, &wi); + FrameRectMy = wi.rcClient; +} - ret=LoopInit(); if (ret) { LoopExit(); return 1; } +static void LoadROM(const char *cmdpath) +{ + static char rompath[MAX_PATH] = { 0, }; + unsigned char *rom_data_new = NULL; + unsigned int rom_size = 0; + pm_file *rom = NULL; + int oldwait=LoopWait; + int i, ret; + + if (cmdpath) { + strcpy(rompath, cmdpath + (cmdpath[0] == '\"' ? 1 : 0)); + if (rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0; + if (strlen(rompath) > 4) rom = pm_open(rompath); + } - LoopQuit=0; LoopCode(); - LoopExit(); + if (!rom) { + OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); + 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; + of.hwndOwner = FrameWnd; + if (!GetOpenFileName(&of)) return; + rom = pm_open(rompath); + if (!rom) { error("failed to open ROM"); return; } + } - return 0; -} + ret=PicoCartLoad(rom, &rom_data_new, &rom_size); + pm_close(rom); + if (ret) { + error("failed to load ROM"); + return; + } -int __cdecl main() -{ - LD_LAUNCH_DASHBOARD launch; + // halt the work thread.. + // just a hack, should've used proper sync. primitives here, but who will use this emu anyway.. + LoopWaiting=0; + LoopWait=1; + for (i = 0; LoopWaiting == 0 && i < 10; i++) Sleep(100); - MainCode(); + PicoUnloadCart(); + PicoCartInsert(rom_data_new, rom_size); - // Go back to dashboard: - memset(&launch,0,sizeof(launch)); - launch.dwReason=XLD_LAUNCH_DASHBOARD_MAIN_MENU; - XLaunchNewImage(NULL,(LAUNCH_DATA *)&launch); + rom_loaded = 1; + romname = rompath; + LoopWait=0; } -#endif -// ----------------------------------- Windows Main ---------------------------------------- -#ifndef _XBOX +static int rect_widths[4] = { 320, 256, 640, 512 }; +static int rect_heights[4] = { 224, 224, 448, 448 }; + // 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 + int i; + 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: UpdateRect(); break; + case WM_COMMAND: + switch (LOWORD(wparam)) + { + case 1000: LoadROM(NULL); break; + case 1001: PostQuitMessage(0); return 0; + case 1100: + case 1101: + case 1102: + case 1103: + LoopWait=1; // another sync hack + for (i = 0; !LoopWaiting && i < 10; i++) Sleep(10); + FrameRectMy.right = FrameRectMy.left + rect_widths[wparam&3]; + FrameRectMy.bottom = FrameRectMy.top + rect_heights[wparam&3]; + AdjustWindowRect(&FrameRectMy, WS_OVERLAPPEDWINDOW, 1); + MoveWindow(hwnd, FrameRectMy.left, FrameRectMy.top, + FrameRectMy.right-FrameRectMy.left, FrameRectMy.bottom-FrameRectMy.top, 1); + UpdateRect(); + if (HIWORD(wparam) == 0) { // locally sent + lock_to_1_1=0; + CheckMenuItem(mdisplay, 1104, MF_UNCHECKED); + } + if (rom_loaded) LoopWait=0; + return 0; + case 1104: + lock_to_1_1=!lock_to_1_1; + CheckMenuItem(mdisplay, 1104, lock_to_1_1 ? MF_CHECKED : MF_UNCHECKED); + return 0; + case 1200: break; + case 1300: + MessageBox(FrameWnd, "PicoDrive v" VERSION " (c) notaz, 2006-2008\n" + "SVP demo edition\n\n" + "Credits:\n" + "fDave: base code of PicoDrive, GenaDrive (the frontend)\n" + "Chui: Fame/C\n" + "NJ: CZ80\n" + "MAME devs: YM2612 and SN76496 cores\n" + "Stéphane Dallongeville: Gens code, base of Fame/C (C68K), CZ80\n" + "Tasco Deluxe: SVP RE work\n" + "Pierpaolo Prazzoli: info about SSP16 chips\n", + "About", 0); + return 0; + } + break; + } return DefWindowProc(hwnd,msg,wparam,lparam); } @@ -57,6 +137,7 @@ static int FrameInit() { WNDCLASS wc; RECT rect={0,0,0,0}; + HMENU mmain, mfile; int style=0; int left=0,top=0,width=0,height=0; @@ -75,7 +156,7 @@ static int FrameInit() // Adjust size of windows based on borders: style=WS_OVERLAPPEDWINDOW; - AdjustWindowRect(&rect,style,0); + AdjustWindowRect(&rect,style,1); width =rect.right-rect.left; height=rect.bottom-rect.top; @@ -87,9 +168,30 @@ static int FrameInit() left-=width; left>>=1; top-=height; top>>=1; + // Create menu: + mfile = CreateMenu(); + InsertMenu(mfile, -1, MF_BYPOSITION|MF_STRING, 1000, "&Load ROM"); + InsertMenu(mfile, -1, MF_BYPOSITION|MF_STRING, 1001, "E&xit"); + mdisplay = CreateMenu(); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1100, "320x224"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1101, "256x224"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1102, "640x448"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1103, "512x448"); + InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1104, "Lock to 1:1"); + mmain = CreateMenu(); + InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR) mfile, "&File"); + InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR) mdisplay, "&Display"); +// InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, 1200, "&Config"); + InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING, 1300, "&About"); + // Create the window: - FrameWnd=CreateWindow(wc.lpszClassName,AppName,style|WS_VISIBLE, - left,top,width,height,NULL,NULL,NULL,NULL); + FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE, + left,top,width,height,NULL,mmain,NULL,NULL); + + CheckMenuItem(mdisplay, 1104, lock_to_1_1 ? MF_CHECKED : MF_UNCHECKED); + ShowWindow(FrameWnd, SW_NORMAL); + UpdateWindow(FrameWnd); + UpdateRect(); return 0; } @@ -102,10 +204,6 @@ 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; @@ -113,45 +211,16 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) DWORD tid=0; HANDLE thread=NULL; - // 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(!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; - } - romname = rompath; - - if(PicoCartLoad(rom, &rom_data, &rom_size)) { - //RDebug::Print(_L("PicoCartLoad() failed.")); - //goto cleanup; - } - 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=LoopInit(); if (ret) goto end0; // Make another thread to run LoopCode(): LoopQuit=0; + LoopWait=1; // wait for ROM to be loaded thread=CreateThread(NULL,0,ThreadCode,NULL,0,&tid); + LoadROM(cmdline); + // Main window loop: for (;;) { @@ -166,13 +235,16 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) LoopQuit=1; WaitForSingleObject(thread,5000); CloseHandle(thread); thread=NULL; +end0: LoopExit(); DestroyWindow(FrameWnd); - free(rom_data); - _CrtDumpMemoryLeaks(); return 0; } -#endif + +extern void error(char *text) +{ + MessageBox(FrameWnd, text, "Error", 0); +}