9 int MainWidth=720,MainHeight=480;
\r
11 // Window proc for the frame window:
\r
12 static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
\r
14 if (msg==WM_CLOSE) { PostQuitMessage(0); return 0; }
\r
15 if (msg==WM_DESTROY) FrameWnd=NULL; // Blank handle
\r
17 return DefWindowProc(hwnd,msg,wparam,lparam);
\r
20 static int FrameInit()
\r
23 RECT rect={0,0,0,0};
\r
25 int left=0,top=0,width=0,height=0;
\r
27 memset(&wc,0,sizeof(wc));
\r
29 // Register the window class:
\r
30 wc.lpfnWndProc=WndProc;
\r
31 wc.hInstance=GetModuleHandle(NULL);
\r
32 wc.hCursor=LoadCursor(NULL,IDC_ARROW);
\r
33 wc.hbrBackground=CreateSolidBrush(0);
\r
34 wc.lpszClassName="MainFrame";
\r
37 rect.right =320;//MainWidth;
\r
38 rect.bottom=224;//MainHeight;
\r
40 // Adjust size of windows based on borders:
\r
41 style=WS_OVERLAPPEDWINDOW;
\r
42 AdjustWindowRect(&rect,style,0);
\r
43 width =rect.right-rect.left;
\r
44 height=rect.bottom-rect.top;
\r
46 // Place window in the centre of the screen:
\r
47 SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
\r
48 left=rect.left+rect.right;
\r
49 top=rect.top+rect.bottom;
\r
51 left-=width; left>>=1;
\r
52 top-=height; top>>=1;
\r
54 // Create the window:
\r
55 FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE,
\r
56 left,top,width,height,NULL,NULL,NULL,NULL);
\r
61 // --------------------
\r
63 static DWORD WINAPI ThreadCode(void *)
\r
69 int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int)
\r
75 unsigned char *rom_data = 0;
\r
76 unsigned int rom_size = 0;
\r
79 ret=LoopInit(); if (ret) goto end0;
\r
82 static char rompath[MAX_PATH]; rompath[0] = 0;
\r
83 strcpy(rompath, cmdline + (cmdline[0] == '\"' ? 1 : 0));
\r
84 if(rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0;
\r
87 if(strlen(rompath) > 4) rom = pm_open(rompath);
\r
89 OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME));
\r
90 of.lStructSize = sizeof(OPENFILENAME);
\r
91 of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen;*.zip\0";
\r
92 of.lpstrFile = rompath; rompath[0] = 0;
\r
93 of.nMaxFile = MAX_PATH;
\r
94 of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
\r
95 if(!GetOpenFileName(&of)) goto end0;
\r
96 rom = pm_open(rompath);
\r
101 ret=PicoCartLoad(rom, &rom_data, &rom_size);
\r
104 error("failed to load ROM");
\r
108 PicoCartInsert(rom_data, rom_size);
\r
110 // only now we got the mode (pal/ntsc), so init sound now
\r
112 if (ret) error("Failed to init DirectSound"); // warning
\r
114 // Make another thread to run LoopCode():
\r
116 thread=CreateThread(NULL,0,ThreadCode,NULL,0,&tid);
\r
118 // Main window loop:
\r
121 GetMessage(&msg,NULL,0,0);
\r
122 if (msg.message==WM_QUIT) break;
\r
124 TranslateMessage(&msg);
\r
125 DispatchMessage(&msg);
\r
128 // Signal thread to quit and wait for it to exit:
\r
129 LoopQuit=1; WaitForSingleObject(thread,5000);
\r
130 CloseHandle(thread); thread=NULL;
\r
134 DestroyWindow(FrameWnd);
\r
138 _CrtDumpMemoryLeaks();
\r
142 extern void error(char *text)
\r
144 MessageBox(FrameWnd, text, "Error", 0);
\r