1.45a Pico win32, code move
[picodrive.git] / platform / win32 / GenaDrive / Loop.cpp
... / ...
CommitLineData
1#include "app.h"\r
2//#include "FileMenu.h"\r
3\r
4char LoopQuit=0,LoopWait=0,LoopWaiting=0;\r
5static FILE *DebugFile=NULL;\r
6int LoopMode=0;\r
7static void UpdateSound(int len);\r
8\r
9int LoopInit()\r
10{\r
11 int ret=0;\r
12\r
13 // bits LSb->MSb:\r
14 // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound;\r
15 // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites\r
16 PicoOpt=0xbccf;\r
17 PsndRate=44100;\r
18\r
19 // Init Direct3D:\r
20 ret=DirectInit(); if (ret) { error("DirectX video init failed"); return 1; }\r
21 InputInit();\r
22\r
23 // Init DirectSound:\r
24 //DSoundInit();\r
25\r
26 ret=EmuInit(); if (ret) return 1;\r
27\r
28 LoopMode=8;\r
29 PicoWriteSound = UpdateSound;\r
30 PicoAutoRgnOrder = 0x184;\r
31\r
32 return 0;\r
33}\r
34\r
35extern "C" char *debugString();\r
36\r
37void LoopExit()\r
38{\r
39 dprintf(debugString());\r
40\r
41 EmuExit();\r
42 InputExit();\r
43 DirectExit();\r
44\r
45 if (DebugFile) fclose(DebugFile);\r
46 DebugFile=NULL;\r
47}\r
48\r
49// ----------------------------------------------------------------\r
50\r
51static void UpdateSound(int len)\r
52{\r
53 while (DSoundUpdate() > 0) { Sleep(1); }\r
54 //while (DSoundUpdate()== 0) { }\r
55}\r
56\r
57static void PostProcess()\r
58{\r
59 static int lock_to_1_1_prev = 0, is_40_prev = -1;\r
60 int is_40;\r
61 PicoGetInternal(PI_IS40_CELL, (pint_ret_t *)&is_40);\r
62 if (lock_to_1_1)\r
63 {\r
64 if (is_40 != is_40_prev || !lock_to_1_1_prev)\r
65 PostMessage(FrameWnd, WM_COMMAND, 0x20000 | (is_40 ? 1100 : 1101), 0);\r
66 }\r
67 if (is_40 != is_40_prev)\r
68 {\r
69 EmuScreenRect.left = is_40 ? 0 : 32;\r
70 EmuScreenRect.right = is_40 ? 320 : 256+32;\r
71 }\r
72 lock_to_1_1_prev = lock_to_1_1;\r
73 is_40_prev = is_40;\r
74}\r
75\r
76int LoopCode()\r
77{\r
78\r
79 // Main loop:\r
80 while (!LoopQuit)\r
81 {\r
82 if (LoopWait)\r
83 {\r
84 DSoundExit();\r
85 while (!LoopQuit && LoopWait) { LoopWaiting=1; Sleep(100); }\r
86 if (LoopQuit) break;\r
87 DSoundInit();\r
88 }\r
89 InputUpdate();\r
90\r
91 DirectClear(0);\r
92 EmuFrame();\r
93 PostProcess();\r
94 DirectScreen();\r
95 DirectPresent();\r
96// UpdateSound();\r
97 }\r
98 DSoundExit();\r
99\r
100 return 0;\r
101}\r
102\r
103// -------------------------------------------------------------------------------------\r
104\r
105#if 0\r
106extern "C" int dprintf(char *format, ...)\r
107{\r
108 char *name=NULL;\r
109 va_list val=NULL;\r
110\r
111#ifdef _XBOX\r
112 name="d:\\zout.txt";\r
113#else\r
114 name="zout.txt";\r
115#endif\r
116\r
117 if (DebugFile==NULL) DebugFile=fopen(name,"wt");\r
118 if (DebugFile==NULL) return 1;\r
119\r
120 fprintf(DebugFile, "%05i: ", emu_frame);\r
121 va_start(val,format);\r
122 vfprintf(DebugFile,format,val);\r
123 fprintf(DebugFile, "\n");\r
124 fflush(DebugFile);\r
125\r
126 va_end(val);\r
127 return 0;\r
128}\r
129#endif\r
130\r
131extern "C" int lprintf(char *format, ...)\r
132{\r
133 char str[512];\r
134 va_list val=NULL;\r
135\r
136 va_start(val,format);\r
137 vsprintf(str,format,val);\r
138 va_end(val);\r
139 OutputDebugString(str);\r
140\r
141 return 0;\r
142}\r
143\r