cc68a136 |
1 | #include "app.h"\r |
4b2b67eb |
2 | //#include "FileMenu.h"\r |
cc68a136 |
3 | \r |
1b0ac8ad |
4 | char LoopQuit=0,LoopWait=0,LoopWaiting=0;\r |
cc68a136 |
5 | static FILE *DebugFile=NULL;\r |
6 | int LoopMode=0;\r |
4b2b67eb |
7 | static void UpdateSound(int len);\r |
cc68a136 |
8 | \r |
9 | int 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 |
e0978fa8 |
16 | PicoOpt=0xbccf;\r |
cc68a136 |
17 | PsndRate=44100;\r |
cc68a136 |
18 | \r |
19 | // Init Direct3D:\r |
03a265e5 |
20 | ret=DirectInit(); if (ret) { error("DirectX video init failed"); return 1; }\r |
cc68a136 |
21 | InputInit();\r |
22 | \r |
23 | // Init DirectSound:\r |
24 | //DSoundInit();\r |
25 | \r |
26 | ret=EmuInit(); if (ret) return 1;\r |
cc68a136 |
27 | \r |
28 | LoopMode=8;\r |
29 | PicoWriteSound = UpdateSound;\r |
1b0ac8ad |
30 | PicoAutoRgnOrder = 0x184;\r |
cc68a136 |
31 | \r |
32 | return 0;\r |
33 | }\r |
34 | \r |
cc68a136 |
35 | extern "C" char *debugString();\r |
36 | \r |
37 | void LoopExit()\r |
38 | {\r |
39 | dprintf(debugString());\r |
40 | \r |
cc68a136 |
41 | EmuExit();\r |
cc68a136 |
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 |
1b0ac8ad |
51 | static void UpdateSound(int len)\r |
cc68a136 |
52 | {\r |
1b0ac8ad |
53 | while (DSoundUpdate() > 0) { Sleep(1); }\r |
54 | //while (DSoundUpdate()== 0) { }\r |
cc68a136 |
55 | }\r |
cc68a136 |
56 | \r |
1b0ac8ad |
57 | static void PostProcess()\r |
cc68a136 |
58 | {\r |
4609d0cd |
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 |
1b0ac8ad |
62 | if (lock_to_1_1)\r |
cc68a136 |
63 | {\r |
1b0ac8ad |
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 |
cc68a136 |
66 | }\r |
1b0ac8ad |
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 |
cc68a136 |
74 | }\r |
75 | \r |
76 | int LoopCode()\r |
77 | {\r |
78 | \r |
79 | // Main loop:\r |
80 | while (!LoopQuit)\r |
81 | {\r |
1b0ac8ad |
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 |
cc68a136 |
89 | InputUpdate();\r |
90 | \r |
91 | DirectClear(0);\r |
1b0ac8ad |
92 | EmuFrame();\r |
93 | PostProcess();\r |
94 | DirectScreen();\r |
cc68a136 |
95 | DirectPresent();\r |
96 | // UpdateSound();\r |
97 | }\r |
1b0ac8ad |
98 | DSoundExit();\r |
cc68a136 |
99 | \r |
100 | return 0;\r |
101 | }\r |
102 | \r |
103 | // -------------------------------------------------------------------------------------\r |
104 | \r |
4b2b67eb |
105 | #if 0\r |
cc68a136 |
106 | extern "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 |
4b2b67eb |
129 | #endif\r |
cc68a136 |
130 | \r |
8f7ed1b8 |
131 | extern "C" int lprintf(char *format, ...)\r |
cc68a136 |
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 |
4b2b67eb |
143 | \r |