c62d2810 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * Copyright notice for this file: |
22f08d95 |
4 | * Copyright (C) 1998 BERO |
c62d2810 |
5 | * Copyright (C) 2002 Ben Parnell |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | */ |
21 | |
22 | /* SVGA High Level Routines |
23 | FCE / FCE Ultra |
24 | */ |
25 | #include <stdio.h> |
26 | #include <stdlib.h> |
27 | #include <math.h> |
28 | #include <string.h> |
29 | |
30 | #include <stdarg.h> |
31 | |
32 | |
33 | #ifndef M_PI |
34 | #define M_PI 3.14159265358979323846 |
35 | #endif |
36 | |
37 | #include "types.h" |
22f08d95 |
38 | #include "svga.h" |
c62d2810 |
39 | #include "fce.h" |
40 | #include "general.h" |
41 | #include "video.h" |
42 | #include "sound.h" |
43 | #include "version.h" |
44 | #include "nsf.h" |
45 | #include "palette.h" |
46 | #include "fds.h" |
47 | #include "netplay.h" |
48 | #include "state.h" |
49 | #include "cart.h" |
50 | #include "input.h" |
51 | |
92764e62 |
52 | #include "vsuni.h" |
53 | |
c62d2810 |
54 | FCEUS FSettings; |
55 | |
56 | static int howlong; |
57 | static char errmsg[65]; |
58 | |
59 | void FCEU_PrintError(char *format, ...) |
60 | { |
61 | char temp[2048]; |
62 | |
63 | va_list ap; |
64 | |
65 | va_start(ap,format); |
66 | vsprintf(temp,format,ap); |
67 | FCEUD_PrintError(temp); |
68 | |
69 | va_end(ap); |
70 | } |
71 | |
72 | void FCEU_DispMessage(char *format, ...) |
73 | { |
74 | va_list ap; |
75 | |
76 | va_start(ap,format); |
77 | vsprintf(errmsg,format,ap); |
78 | va_end(ap); |
79 | |
80 | howlong=180; |
989672f4 |
81 | if (errmsg[0] != '|') |
82 | printf("%s\n", errmsg); |
c62d2810 |
83 | } |
84 | |
85 | void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) |
86 | { |
87 | FSettings.UsrFirstSLine[0]=ntscf; |
88 | FSettings.UsrLastSLine[0]=ntscl; |
89 | FSettings.UsrFirstSLine[1]=palf; |
90 | FSettings.UsrLastSLine[1]=pall; |
91 | if(PAL) |
92 | { |
93 | FSettings.FirstSLine=FSettings.UsrFirstSLine[1]; |
94 | FSettings.LastSLine=FSettings.UsrLastSLine[1]; |
95 | } |
96 | else |
97 | { |
98 | FSettings.FirstSLine=FSettings.UsrFirstSLine[0]; |
99 | FSettings.LastSLine=FSettings.UsrLastSLine[0]; |
100 | } |
101 | |
102 | } |
103 | |
104 | void FCEUI_SetVidSystem(int a) |
105 | { |
106 | FSettings.PAL=a?1:0; |
107 | FCEU_ResetVidSys(); |
108 | FCEU_ResetPalette(); |
109 | } |
110 | |
111 | int FCEUI_GetCurrentVidSystem(int *slstart, int *slend) |
112 | { |
113 | if(slstart) |
114 | *slstart=FSettings.FirstSLine; |
115 | if(slend) |
116 | *slend=FSettings.LastSLine; |
117 | return(PAL); |
118 | } |
119 | |
120 | #ifdef NETWORK |
121 | void FCEUI_SetNetworkPlay(int type) |
122 | { |
123 | FSettings.NetworkPlay=type; |
124 | } |
125 | #endif |
126 | |
127 | void FCEUI_SetGameGenie(int a) |
128 | { |
129 | FSettings.GameGenie=a?1:0; |
130 | } |
131 | |
c62d2810 |
132 | #ifndef NETWORK |
133 | #define netplay 0 |
134 | #endif |
135 | |
c62d2810 |
136 | uint8 Exit=0; |
137 | |
138 | uint8 DIPS=0; |
c62d2810 |
139 | |
c62d2810 |
140 | uint8 CommandQueue=0; |
141 | |
c62d2810 |
142 | |
143 | void FCEUI_SetSnapName(int a) |
144 | { |
145 | FSettings.SnapName=a; |
146 | } |
147 | |
148 | void FCEUI_SaveExtraDataUnderBase(int a) |
149 | { |
150 | FSettings.SUnderBase=a; |
151 | } |
152 | |
c62d2810 |
153 | |
154 | void FCEUI_SelectState(int w) |
155 | { |
971a1d07 |
156 | // if(netplay!=2 && FCEUGameInfo.type!=GIT_NSF) |
157 | // CommandQueue=42+w; |
c62d2810 |
158 | } |
159 | |
160 | void FCEUI_SaveState(void) |
161 | { |
971a1d07 |
162 | // if(netplay!=2 && FCEUGameInfo.type!=GIT_NSF) |
163 | // CommandQueue=40; |
164 | |
165 | //CheckStates(); |
166 | SaveState(); |
c62d2810 |
167 | } |
168 | |
169 | void FCEUI_LoadState(void) |
170 | { |
971a1d07 |
171 | // if(netplay!=2 && FCEUGameInfo.type!=GIT_NSF) |
172 | // CommandQueue=41; |
173 | //CheckStates(); |
174 | LoadState(); |
c62d2810 |
175 | } |
176 | |
177 | int32 FCEUI_GetDesiredFPS(void) |
178 | { |
179 | if(PAL) |
180 | return(838977920); // ~50.007 |
181 | else |
182 | return(1008307711); // ~60.1 |
183 | } |
184 | |
185 | static int dosnapsave=0; |
186 | void FCEUI_SaveSnapshot(void) |
187 | { |
188 | dosnapsave=1; |
189 | } |
190 | |
191 | /* I like the sounds of breaking necks. */ |
192 | static void ReallySnap(void) |
193 | { |
194 | int x=SaveSnapshot(); |
195 | if(!x) |
196 | FCEU_DispMessage("Error saving screen snapshot."); |
197 | else |
198 | FCEU_DispMessage("Screen snapshot %d saved.",x-1); |
199 | } |
200 | |
201 | void DriverInterface(int w, void *d) |
202 | { |
203 | switch(w) |
204 | { |
c62d2810 |
205 | case DES_RESET:if(netplay!=2) CommandQueue=30;break; |
206 | case DES_POWER:if(netplay!=2) CommandQueue=31;break; |
21afaa36 |
207 | |
c62d2810 |
208 | case DES_VSUNIDIPSET:CommandQueue=10+(int)d;break; |
209 | case DES_VSUNITOGGLEDIPVIEW:CommandQueue=10;break; |
210 | case DES_VSUNICOIN:CommandQueue=19;break; |
92764e62 |
211 | #if 0 |
c62d2810 |
212 | case DES_NTSCDEC: |
213 | if(ntsccol && FCEUGameInfo.type!=GIT_VSUNI && !PAL && FCEUGameInfo.type!=GIT_NSF) |
214 | { |
215 | char which; |
216 | if(controlselect) |
217 | { |
218 | if(controllength) |
219 | { |
220 | which=controlselect==1?ntschue:ntsctint; |
221 | which--; |
222 | if(which<0) which=0; |
22f08d95 |
223 | if(controlselect==1) |
224 | ntschue=which; |
225 | else ntsctint=which; |
c62d2810 |
226 | CalculatePalette(); |
227 | } |
228 | controllength=360; |
229 | } |
230 | } |
231 | break; |
22f08d95 |
232 | case DES_NTSCINC: |
c62d2810 |
233 | if(ntsccol && FCEUGameInfo.type!=GIT_VSUNI && !PAL && FCEUGameInfo.type!=GIT_NSF) |
234 | if(controlselect) |
235 | { |
236 | if(controllength) |
237 | { |
238 | switch(controlselect) |
239 | { |
240 | case 1:ntschue++; |
241 | if(ntschue>128) ntschue=128; |
242 | CalculatePalette(); |
243 | break; |
244 | case 2:ntsctint++; |
245 | if(ntsctint>128) ntsctint=128; |
246 | CalculatePalette(); |
247 | break; |
248 | } |
249 | } |
250 | controllength=360; |
251 | } |
252 | break; |
92764e62 |
253 | #endif |
c62d2810 |
254 | } |
255 | } |
256 | |
c62d2810 |
257 | |
258 | #include "drawing.h" |
259 | #ifdef FRAMESKIP |
260 | void FCEU_PutImageDummy(void) |
261 | { |
c62d2810 |
262 | if(howlong) howlong--; /* DrawMessage() */ |
263 | #ifdef FPS |
264 | { |
265 | extern uint64 frcount; |
266 | frcount++; |
267 | } |
268 | #endif |
269 | |
270 | } |
271 | #endif |
272 | |
273 | void FCEU_PutImage(void) |
274 | { |
275 | if(FCEUGameInfo.type==GIT_NSF) |
276 | { |
277 | DrawNSF(XBuf); |
278 | /* Save snapshot after NSF screen is drawn. Why would we want to |
279 | do it before? |
280 | */ |
281 | if(dosnapsave) |
282 | { |
283 | ReallySnap(); |
284 | dosnapsave=0; |
285 | } |
286 | } |
287 | else |
22f08d95 |
288 | { |
c62d2810 |
289 | /* Save snapshot before overlay stuff is written. */ |
290 | if(dosnapsave) |
291 | { |
292 | ReallySnap(); |
293 | dosnapsave=0; |
294 | } |
92764e62 |
295 | if(FCEUGameInfo.type==GIT_VSUNI) |
296 | FCEU_VSUniDraw(XBuf); |
92764e62 |
297 | |
298 | //FCEU_DrawSaveStates(XBuf); |
299 | //FCEU_DrawMovies(XBuf); |
300 | //FCEU_DrawNTSCControlBars(XBuf); |
301 | //FCEU_DrawRecordingStatus(XBuf); |
302 | |
303 | //if(controllength) {controllength--;DrawBars();} |
c62d2810 |
304 | } |
305 | DrawMessage(); |
306 | #ifdef FPS |
307 | { |
308 | extern uint64 frcount; |
309 | frcount++; |
310 | } |
311 | #endif |
312 | DrawInput(XBuf+8); |
313 | } |
314 | |
92764e62 |
315 | #if 0 |
c62d2810 |
316 | void DoCommand(uint8 c) |
317 | { |
318 | switch(c) |
319 | { |
320 | case 1:FDSControl(FDS_SELECT);break; |
321 | case 2:FDSControl(FDS_IDISK);break; |
322 | case 3:FDSControl(FDS_EJECT);break; |
323 | |
324 | case 10:DIPS^=2;break; |
325 | case 11:vsdip^=1;DIPS|=2;break; |
326 | case 12:vsdip^=2;DIPS|=2;break; |
327 | case 13:vsdip^=4;DIPS|=2;break; |
328 | case 14:vsdip^=8;DIPS|=2;break; |
329 | case 15:vsdip^=0x10;DIPS|=2;break; |
330 | case 16:vsdip^=0x20;DIPS|=2;break; |
331 | case 17:vsdip^=0x40;DIPS|=2;break; |
332 | case 18:vsdip^=0x80;DIPS|=2;break; |
333 | case 19:coinon=6;break; |
334 | case 30:ResetNES();break; |
335 | case 31:PowerNES();break; |
336 | case 40:CheckStates();StateShow=0;SaveState();break; |
337 | case 41:CheckStates();StateShow=0;LoadState();break; |
338 | case 42: case 43: case 44: case 45: case 46: case 47: case 48: case 49: |
339 | case 50: case 51:StateShow=180;CurrentState=c-42;CheckStates();break; |
340 | } |
341 | } |
d97315ac |
342 | #endif |
343 | |