cc68a136 |
1 | #include "app.h"\r |
4b2b67eb |
2 | //#include "FileMenu.h"\r |
cc68a136 |
3 | \r |
cc68a136 |
4 | extern char *romname;\r |
5 | int fastForward=0;\r |
6 | int frameStep=0;\r |
7 | \r |
8 | char LoopQuit=0;\r |
9 | static FILE *DebugFile=NULL;\r |
10 | int LoopMode=0;\r |
4b2b67eb |
11 | static void UpdateSound(int len);\r |
cc68a136 |
12 | \r |
13 | int LoopInit()\r |
14 | {\r |
15 | int ret=0;\r |
16 | \r |
17 | // bits LSb->MSb:\r |
18 | // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound;\r |
19 | // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites\r |
20 | PicoOpt=0x1f;\r |
21 | PsndRate=44100;\r |
22 | //PsndLen=PsndRate/60; // calculated later by pico itself\r |
23 | \r |
24 | // Init Direct3D:\r |
4b2b67eb |
25 | ret=DirectInit(); if (ret) { error("Direct3D init failed"); return 1; }\r |
cc68a136 |
26 | InputInit();\r |
27 | \r |
28 | // Init DirectSound:\r |
29 | //DSoundInit();\r |
30 | \r |
31 | ret=EmuInit(); if (ret) return 1;\r |
4b2b67eb |
32 | //FileMenu.init();\r |
cc68a136 |
33 | \r |
34 | LoopMode=8;\r |
35 | PicoWriteSound = UpdateSound;\r |
36 | \r |
37 | return 0;\r |
38 | }\r |
39 | \r |
cc68a136 |
40 | extern "C" char *debugString();\r |
41 | \r |
42 | void LoopExit()\r |
43 | {\r |
44 | dprintf(debugString());\r |
45 | \r |
4b2b67eb |
46 | //FileMenu.exit();\r |
cc68a136 |
47 | EmuExit();\r |
48 | DSoundExit(); PsndLen=0;\r |
49 | InputExit();\r |
50 | DirectExit();\r |
51 | \r |
52 | if (DebugFile) fclose(DebugFile);\r |
53 | DebugFile=NULL;\r |
54 | }\r |
55 | \r |
56 | // ----------------------------------------------------------------\r |
57 | \r |
58 | int emu_frame = 0;\r |
59 | \r |
60 | static int DoGame()\r |
61 | {\r |
62 | if(fastForward) { PicoSkipFrame+=1; PicoSkipFrame&=7; }\r |
63 | else PicoSkipFrame=0;\r |
64 | \r |
65 | if(frameStep==1) return 0;\r |
66 | else if(frameStep==3) frameStep=1;\r |
67 | \r |
68 | EmuFrame();\r |
69 | emu_frame++;\r |
70 | \r |
71 | if (Inp.held[7]==1) LoopMode=2; // Right thumb = Toggle Menu\r |
72 | \r |
73 | return 0;\r |
74 | }\r |
75 | // ----------------------------------------------------------------\r |
76 | \r |
4b2b67eb |
77 | /*\r |
cc68a136 |
78 | static int MenuUpdate()\r |
79 | {\r |
80 | int delta=0;\r |
81 | \r |
82 | if (Inp.repeat[0]) delta-=0x100;\r |
83 | if (Inp.repeat[1]) delta+=0x100;\r |
84 | \r |
85 | if (Inp.button[14]>30) delta-=Inp.button[14]-30;\r |
86 | if (Inp.button[15]>30) delta+=Inp.button[15]-30;\r |
87 | \r |
88 | if (delta) FileMenu.scroll(delta);\r |
89 | \r |
90 | if (Inp.held[8]==1 || Inp.held[10]==1 || Inp.held[4]==1) // A, X or Start\r |
91 | {\r |
92 | //RomFree();\r |
93 | //FileMenu.getFilePath(RomName);\r |
94 | //RomLoad();\r |
95 | //LoopMode=8; // Go to game\r |
96 | }\r |
97 | \r |
98 | if (Inp.held[7]==1) LoopMode=8; // Right thumb = Toggle Menu\r |
99 | \r |
100 | return 0;\r |
101 | }\r |
102 | \r |
103 | static int MenuRender()\r |
104 | {\r |
105 | WCHAR text[80]={0};\r |
106 | wsprintfW(text,L"%.40S v%x.%.3x",AppName,PicoVer>>12,PicoVer&0xfff);\r |
107 | FontSetColour(0x60c0ff);\r |
108 | FontText(text,64,48);\r |
109 | \r |
110 | FileMenu.render();\r |
111 | \r |
112 | return 0;\r |
113 | }\r |
4b2b67eb |
114 | */\r |
cc68a136 |
115 | \r |
116 | // ----------------------------------------------------------------\r |
117 | \r |
118 | static int ModeUpdate()\r |
119 | {\r |
120 | if (Inp.held[14] && Inp.held[15] && Inp.held[12]==1) LoopQuit=1; // L+R+black to quit:\r |
121 | if (Inp.button[4]>30 && Inp.button[5]>30) LoopQuit=1; // Start and back to quit\r |
122 | \r |
123 | if (LoopMode==8) { DoGame(); return 0; }\r |
124 | \r |
125 | if (DSoundNext) memset(DSoundNext,0,PsndLen<<2);\r |
126 | \r |
4b2b67eb |
127 | // if (LoopMode==2) { FileMenu.scan(); LoopMode++; return 0; }\r |
128 | // if (LoopMode==3) { MenuUpdate(); return 0; }\r |
129 | // if (LoopMode==4) { LightCalUpdate(); return 0; }\r |
cc68a136 |
130 | \r |
131 | LoopMode=2; // Unknown mode, go to rom menu\r |
132 | return 0;\r |
133 | }\r |
134 | \r |
135 | \r |
136 | static int ModeRender()\r |
137 | {\r |
138 | DirectScreen();\r |
4b2b67eb |
139 | // if (LoopMode==3) MenuRender();\r |
140 | // if (LoopMode==4) LightCalRender();\r |
cc68a136 |
141 | \r |
142 | return 0;\r |
143 | }\r |
144 | \r |
4b2b67eb |
145 | static void UpdateSound(int len)\r |
cc68a136 |
146 | {\r |
147 | if(fastForward) return;\r |
148 | while (DSoundUpdate()) { Sleep(1); }\r |
149 | while (DSoundUpdate()==0) { }\r |
150 | }\r |
151 | \r |
152 | int LoopCode()\r |
153 | {\r |
154 | \r |
155 | // Main loop:\r |
156 | while (!LoopQuit)\r |
157 | {\r |
158 | InputUpdate();\r |
159 | \r |
160 | DirectClear(0);\r |
161 | ModeUpdate();\r |
162 | ModeRender();\r |
163 | DirectPresent();\r |
164 | // UpdateSound();\r |
165 | }\r |
166 | \r |
167 | return 0;\r |
168 | }\r |
169 | \r |
170 | // -------------------------------------------------------------------------------------\r |
171 | \r |
4b2b67eb |
172 | #if 0\r |
cc68a136 |
173 | extern "C" int dprintf(char *format, ...)\r |
174 | {\r |
175 | char *name=NULL;\r |
176 | va_list val=NULL;\r |
177 | \r |
178 | #ifdef _XBOX\r |
179 | name="d:\\zout.txt";\r |
180 | #else\r |
181 | name="zout.txt";\r |
182 | #endif\r |
183 | \r |
184 | if (DebugFile==NULL) DebugFile=fopen(name,"wt");\r |
185 | if (DebugFile==NULL) return 1;\r |
186 | \r |
187 | fprintf(DebugFile, "%05i: ", emu_frame);\r |
188 | va_start(val,format);\r |
189 | vfprintf(DebugFile,format,val);\r |
190 | fprintf(DebugFile, "\n");\r |
191 | fflush(DebugFile);\r |
192 | \r |
193 | va_end(val);\r |
194 | return 0;\r |
195 | }\r |
4b2b67eb |
196 | #endif\r |
cc68a136 |
197 | \r |
198 | extern "C" int dprintf2(char *format, ...)\r |
199 | {\r |
200 | char str[512];\r |
201 | va_list val=NULL;\r |
202 | \r |
203 | va_start(val,format);\r |
204 | vsprintf(str,format,val);\r |
205 | va_end(val);\r |
206 | OutputDebugString(str);\r |
207 | \r |
208 | return 0;\r |
209 | }\r |
4b2b67eb |
210 | \r |