ROM load progress bar
[picodrive.git] / platform / win32 / GenaDrive / Main.cpp
CommitLineData
cc68a136 1\r
2#include "app.h"\r
3#include <crtdbg.h>\r
4#include <commdlg.h>\r
5\r
6char *romname;\r
7HWND FrameWnd=NULL;\r
8\r
9int MainWidth=720,MainHeight=480;\r
10\r
11char AppName[]="GenaDrive";\r
12\r
13#ifdef STARSCREAM\r
14 extern "C" int SekReset();\r
15#endif\r
16\r
17// ------------------------------------ XBox Main ------------------------------------------\r
18#ifdef _XBOX\r
19\r
20static int MainCode()\r
21{\r
22 int ret=0;\r
23\r
24 ret=LoopInit(); if (ret) { LoopExit(); return 1; }\r
25\r
26 LoopQuit=0; LoopCode();\r
27 LoopExit();\r
28\r
29 return 0;\r
30}\r
31\r
32int __cdecl main()\r
33{\r
34 LD_LAUNCH_DASHBOARD launch;\r
35\r
36 MainCode();\r
37\r
38 // Go back to dashboard:\r
39 memset(&launch,0,sizeof(launch));\r
40 launch.dwReason=XLD_LAUNCH_DASHBOARD_MAIN_MENU;\r
41 XLaunchNewImage(NULL,(LAUNCH_DATA *)&launch);\r
42}\r
43#endif\r
44\r
45// ----------------------------------- Windows Main ----------------------------------------\r
46#ifndef _XBOX\r
47// Window proc for the frame window:\r
48static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
49{\r
50 if (msg==WM_CLOSE) { PostQuitMessage(0); return 0; }\r
51 if (msg==WM_DESTROY) FrameWnd=NULL; // Blank handle\r
52\r
53 return DefWindowProc(hwnd,msg,wparam,lparam);\r
54}\r
55\r
56static int FrameInit()\r
57{\r
58 WNDCLASS wc;\r
59 RECT rect={0,0,0,0};\r
60 int style=0;\r
61 int left=0,top=0,width=0,height=0;\r
62\r
63 memset(&wc,0,sizeof(wc));\r
64\r
65 // Register the window class:\r
66 wc.lpfnWndProc=WndProc;\r
67 wc.hInstance=GetModuleHandle(NULL);\r
68 wc.hCursor=LoadCursor(NULL,IDC_ARROW);\r
69 wc.hbrBackground=CreateSolidBrush(0);\r
70 wc.lpszClassName="MainFrame";\r
71 RegisterClass(&wc);\r
72\r
73 rect.right =320;//MainWidth;\r
74 rect.bottom=224;//MainHeight;\r
75\r
76 // Adjust size of windows based on borders:\r
77 style=WS_OVERLAPPEDWINDOW;\r
78 AdjustWindowRect(&rect,style,0);\r
79 width =rect.right-rect.left;\r
80 height=rect.bottom-rect.top;\r
81\r
82 // Place window in the centre of the screen:\r
83 SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);\r
84 left=rect.left+rect.right;\r
85 top=rect.top+rect.bottom;\r
86\r
87 left-=width; left>>=1;\r
88 top-=height; top>>=1;\r
89\r
90 // Create the window:\r
91 FrameWnd=CreateWindow(wc.lpszClassName,AppName,style|WS_VISIBLE,\r
92 left,top,width,height,NULL,NULL,NULL,NULL);\r
93\r
94 return 0;\r
95}\r
96\r
97// --------------------\r
98\r
99static DWORD WINAPI ThreadCode(void *)\r
100{\r
101 LoopCode();\r
102 return 0;\r
103}\r
104\r
105// starscream needs this\r
106unsigned char *rom_data = 0;\r
107unsigned int rom_size = 0;\r
108\r
109int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int)\r
110{\r
111 MSG msg;\r
112 int ret=0;\r
113 DWORD tid=0;\r
114 HANDLE thread=NULL;\r
115\r
116 // notaz: load rom\r
117 static char rompath[MAX_PATH]; rompath[0] = 0;\r
118 strcpy(rompath, cmdline + (cmdline[0] == '\"' ? 1 : 0));\r
119 if(rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0;\r
120\r
121 FILE *rom = 0;\r
122 if(strlen(rompath) > 4) rom = fopen(rompath, "rb");\r
123 if(!rom) {\r
124 OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME));\r
125 of.lStructSize = sizeof(OPENFILENAME);\r
126 of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0";\r
127 of.lpstrFile = rompath; rompath[0] = 0;\r
128 of.nMaxFile = MAX_PATH;\r
129 of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;\r
130 if(!GetOpenFileName(&of)) return 1;\r
131 rom = fopen(rompath, "rb");\r
132 if(!rom) return 1;\r
133 }\r
134 romname = rompath;\r
135\r
136 if(PicoCartLoad(rom, &rom_data, &rom_size)) {\r
137 //RDebug::Print(_L("PicoCartLoad() failed."));\r
138 //goto cleanup;\r
139 }\r
140\r
141 FrameInit();\r
142 ret=LoopInit(); if (ret) { LoopExit(); return 1; }\r
143\r
144 PicoCartInsert(rom_data, rom_size);\r
145\r
146 // only now we got the mode (pal/ntsc), so init sound now\r
147 DSoundInit();\r
148\r
149 preLoopInit();\r
150\r
151 // Make another thread to run LoopCode():\r
152 LoopQuit=0;\r
153 thread=CreateThread(NULL,0,ThreadCode,NULL,0,&tid);\r
154\r
155 // Main window loop:\r
156 for (;;)\r
157 {\r
158 GetMessage(&msg,NULL,0,0);\r
159 if (msg.message==WM_QUIT) break;\r
160\r
161 TranslateMessage(&msg);\r
162 DispatchMessage(&msg);\r
163 }\r
164\r
165 // Signal thread to quit and wait for it to exit:\r
166 LoopQuit=1; WaitForSingleObject(thread,5000);\r
167 CloseHandle(thread); thread=NULL;\r
168\r
169 LoopExit();\r
170 DestroyWindow(FrameWnd);\r
171\r
172 free(rom_data);\r
173\r
174 _CrtDumpMemoryLeaks();\r
175 return 0;\r
176}\r
177#endif\r
178\r