920659849dff9cf26f3bf79b231ee371aee41fc8
[cyclone68000.git] / PicoDrive / WinMain.cpp
1 \r
2 // This file is part of the PicoDrive Megadrive Emulator\r
3 \r
4 // This code is licensed under the GNU General Public License version 2.0 and the MAME License.\r
5 // You can choose the license that has the most advantages for you.\r
6 \r
7 // SVN repository can be found at http://code.google.com/p/cyclone68000/\r
8 \r
9 #include "stdafx.h"\r
10 #include <stdarg.h>\r
11 \r
12 static FILE *DebugFile=NULL;\r
13 int Main3800=0;\r
14 int WINAPI WinMain(HINSTANCE,HINSTANCE,LPTSTR,int)\r
15 {\r
16   MSG msg; int ret=0;\r
17   TCHAR device[260];\r
18 \r
19   memset(&msg,0,sizeof(msg));\r
20   memset(device,0,sizeof(device));\r
21 \r
22   // Check if this program is running already:\r
23   FrameWnd=FindWindow(APP_TITLE,NULL);\r
24   if (FrameWnd!=NULL) { SetForegroundWindow(FrameWnd); return 0; }\r
25 \r
26   DeleteFile(L"zout.txt");\r
27 \r
28   SystemParametersInfo(SPI_GETOEMINFO,sizeof(device)>>1,device,0);\r
29   if (_wcsicmp(device,L"compaq ipaq h3800")==0) Main3800=1;\r
30 \r
31   FrameInit();\r
32 \r
33   ConfigInit();\r
34   ConfigLoad();\r
35 \r
36   WaveRate=44100; WaveLen=735;\r
37   WaveInit();\r
38 \r
39   for(;;)\r
40   {\r
41     ret=PeekMessage(&msg,NULL,0,0,PM_REMOVE);\r
42     if (ret)\r
43     {\r
44       if (msg.message==WM_QUIT) break;\r
45       TranslateMessage(&msg);\r
46       DispatchMessage(&msg);\r
47     }\r
48     else\r
49     {\r
50       EmulateFrame();\r
51       //WaveUpdate();\r
52       Sleep(1);\r
53     }\r
54   }\r
55 \r
56   WaveExit();\r
57   EmulateExit();\r
58 \r
59   ConfigSave();\r
60 \r
61   DestroyWindow(FrameWnd);\r
62 \r
63   if (DebugFile) fclose(DebugFile);\r
64   DebugFile=NULL;\r
65   return 0;\r
66 }\r
67 \r
68 extern "C" int dprintf(char *Format, ...)\r
69 {\r
70   va_list VaList=NULL;\r
71   va_start(VaList,Format);\r
72 \r
73   if (DebugFile==NULL) DebugFile=fopen("zout.txt","wt");\r
74   if (DebugFile) vfprintf(DebugFile,Format,VaList);\r
75 \r
76   va_end(VaList);\r
77   return 0;\r
78 }\r