minor adjustments
[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 = 0;\r
60 int is_40 = PicoGetStat(PS_40_CELL);\r
61 if (lock_to_1_1)\r
62 {\r
63 if (is_40 != is_40_prev || !lock_to_1_1_prev)\r
64 PostMessage(FrameWnd, WM_COMMAND, 0x20000 | (is_40 ? 1100 : 1101), 0);\r
65 }\r
66 if (is_40 != is_40_prev)\r
67 {\r
68 EmuScreenRect.left = is_40 ? 0 : 32;\r
69 EmuScreenRect.right = is_40 ? 320 : 256+32;\r
70 }\r
71 lock_to_1_1_prev = lock_to_1_1;\r
72 is_40_prev = is_40;\r
73}\r
74\r
75int LoopCode()\r
76{\r
77\r
78 // Main loop:\r
79 while (!LoopQuit)\r
80 {\r
81 if (LoopWait)\r
82 {\r
83 DSoundExit();\r
84 while (!LoopQuit && LoopWait) { LoopWaiting=1; Sleep(100); }\r
85 if (LoopQuit) break;\r
86 DSoundInit();\r
87 }\r
88 InputUpdate();\r
89\r
90 DirectClear(0);\r
91 EmuFrame();\r
92 PostProcess();\r
93 DirectScreen();\r
94 DirectPresent();\r
95// UpdateSound();\r
96 }\r
97 DSoundExit();\r
98\r
99 return 0;\r
100}\r
101\r
102// -------------------------------------------------------------------------------------\r
103\r
104#if 0\r
105extern "C" int dprintf(char *format, ...)\r
106{\r
107 char *name=NULL;\r
108 va_list val=NULL;\r
109\r
110#ifdef _XBOX\r
111 name="d:\\zout.txt";\r
112#else\r
113 name="zout.txt";\r
114#endif\r
115\r
116 if (DebugFile==NULL) DebugFile=fopen(name,"wt");\r
117 if (DebugFile==NULL) return 1;\r
118\r
119 fprintf(DebugFile, "%05i: ", emu_frame);\r
120 va_start(val,format);\r
121 vfprintf(DebugFile,format,val);\r
122 fprintf(DebugFile, "\n");\r
123 fflush(DebugFile);\r
124\r
125 va_end(val);\r
126 return 0;\r
127}\r
128#endif\r
129\r
130extern "C" int lprintf(char *format, ...)\r
131{\r
132 char str[512];\r
133 va_list val=NULL;\r
134\r
135 va_start(val,format);\r
136 vsprintf(str,format,val);\r
137 va_end(val);\r
138 OutputDebugString(str);\r
139\r
140 return 0;\r
141}\r
142\r