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 |
1b0ac8ad |
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 |
cc68a136 |
62 | {\r |
1b0ac8ad |
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 |
cc68a136 |
65 | }\r |
1b0ac8ad |
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 |
cc68a136 |
73 | }\r |
74 | \r |
75 | int LoopCode()\r |
76 | {\r |
77 | \r |
78 | // Main loop:\r |
79 | while (!LoopQuit)\r |
80 | {\r |
1b0ac8ad |
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 |
cc68a136 |
88 | InputUpdate();\r |
89 | \r |
90 | DirectClear(0);\r |
1b0ac8ad |
91 | EmuFrame();\r |
92 | PostProcess();\r |
93 | DirectScreen();\r |
cc68a136 |
94 | DirectPresent();\r |
95 | // UpdateSound();\r |
96 | }\r |
1b0ac8ad |
97 | DSoundExit();\r |
cc68a136 |
98 | \r |
99 | return 0;\r |
100 | }\r |
101 | \r |
102 | // -------------------------------------------------------------------------------------\r |
103 | \r |
4b2b67eb |
104 | #if 0\r |
cc68a136 |
105 | extern "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 |
4b2b67eb |
128 | #endif\r |
cc68a136 |
129 | \r |
130 | extern "C" int dprintf2(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 |
4b2b67eb |
142 | \r |