c62d2810 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * Copyright notice for this file: |
4 | * Copyright (C) 2002 Ben Parnell |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ |
20 | |
21 | #include <stdio.h> |
22 | #include <string.h> |
23 | #include <stdlib.h> |
5232c20c |
24 | #include <sys/time.h> |
25 | #include <pthread.h> |
c62d2810 |
26 | |
27 | #include "sdl.h" |
28 | #include "../common/vidblit.h" |
29 | |
5232c20c |
30 | |
31 | #ifdef GP2X |
32 | #include "minimal.h" |
33 | |
34 | char* fps_str=NULL; |
35 | #endif |
36 | extern int showfps; |
37 | |
38 | int stretch_offset=32; |
39 | |
40 | unsigned long framesRendered; |
41 | unsigned long fps; |
42 | unsigned long fps_samplecount=0; |
43 | unsigned long total_fps=-1; |
44 | unsigned long ticks; |
45 | |
46 | pthread_t gp2x_video_thread=0; |
47 | uint8 * XBufHelper=NULL; |
48 | |
49 | |
c62d2810 |
50 | #define _sline srendline |
51 | #define _eline erendline |
52 | |
5232c20c |
53 | #ifndef GP2X |
c62d2810 |
54 | SDL_Surface *screen; |
5232c20c |
55 | #endif |
c62d2810 |
56 | |
57 | static int tlines; |
58 | static int inited=0; |
59 | |
60 | static int exs,eys,eefx; |
61 | #define NWIDTH (256-((eoptions&EO_CLIPSIDES)?16:0)) |
62 | #define NOFFSET (eoptions&EO_CLIPSIDES?8:0) |
63 | |
5232c20c |
64 | |
65 | |
66 | int paletterefresh; |
67 | #ifdef GP2X |
68 | static int screenSizeInBytes = 320 * 240; |
69 | #endif |
70 | #define FPS_COLOR 61 |
71 | |
72 | |
73 | |
74 | |
75 | static unsigned char fontdata8x8[] = |
76 | { |
77 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
78 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
79 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
80 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
81 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
82 | 0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C, |
83 | 0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00, |
84 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, |
85 | 0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00, |
86 | 0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00, |
87 | 0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, |
88 | 0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40, |
89 | 0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00, |
90 | 0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00, |
91 | 0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00, |
92 | 0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00, |
93 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00, |
94 | 0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00, |
95 | 0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00, |
96 | 0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00, |
97 | 0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00, |
98 | 0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00, |
99 | 0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00, |
100 | 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00, |
101 | 0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00, |
102 | 0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00, |
103 | 0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00, |
104 | 0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00, |
105 | 0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00, |
106 | 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30, |
107 | 0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00, |
108 | 0x70,0x38,0x1C,0x0E,0x1C,0x38,0x70,0x00,0x7C,0xC6,0xC6,0x1C,0x18,0x00,0x18,0x00, |
109 | 0x3C,0x42,0x99,0xA1,0xA5,0x99,0x42,0x3C,0x38,0x6C,0xC6,0xC6,0xFE,0xC6,0xC6,0x00, |
110 | 0xFC,0xC6,0xC6,0xFC,0xC6,0xC6,0xFC,0x00,0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00, |
111 | 0xF8,0xCC,0xC6,0xC6,0xC6,0xCC,0xF8,0x00,0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xFE,0x00, |
112 | 0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xC0,0x00,0x3E,0x60,0xC0,0xCE,0xC6,0x66,0x3E,0x00, |
113 | 0xC6,0xC6,0xC6,0xFE,0xC6,0xC6,0xC6,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x7E,0x00, |
114 | 0x06,0x06,0x06,0x06,0xC6,0xC6,0x7C,0x00,0xC6,0xCC,0xD8,0xF0,0xF8,0xDC,0xCE,0x00, |
115 | 0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00, |
116 | 0xC6,0xE6,0xF6,0xFE,0xDE,0xCE,0xC6,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00, |
117 | 0xFC,0xC6,0xC6,0xC6,0xFC,0xC0,0xC0,0x00,0x7C,0xC6,0xC6,0xC6,0xDE,0xCC,0x7A,0x00, |
118 | 0xFC,0xC6,0xC6,0xCE,0xF8,0xDC,0xCE,0x00,0x78,0xCC,0xC0,0x7C,0x06,0xC6,0x7C,0x00, |
119 | 0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00, |
120 | 0xC6,0xC6,0xC6,0xEE,0x7C,0x38,0x10,0x00,0xC6,0xC6,0xD6,0xFE,0xFE,0xEE,0xC6,0x00, |
121 | 0xC6,0xEE,0x3C,0x38,0x7C,0xEE,0xC6,0x00,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00, |
122 | 0xFE,0x0E,0x1C,0x38,0x70,0xE0,0xFE,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, |
123 | 0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, |
124 | 0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, |
125 | 0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00, |
126 | 0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00, |
127 | 0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00, |
128 | 0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C, |
129 | 0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00, |
130 | 0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00, |
131 | 0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00, |
132 | 0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00, |
133 | 0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06, |
134 | 0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00, |
135 | 0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00, |
136 | 0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00, |
137 | 0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C, |
138 | 0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00, |
139 | 0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00, |
140 | 0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00, |
141 | }; |
142 | |
143 | static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color, int flip) |
144 | { |
145 | int i,l,slen; |
146 | slen=strlen(text); |
147 | |
148 | screen=screen+x+y*320; |
149 | |
150 | for (i=0;i<slen;i++) |
151 | { |
152 | for (l=0;l<8;l++) |
153 | { |
154 | |
155 | screen[l*320+0]=(fontdata8x8[((text[i])*8)+l]&0x80)?color:screen[l*320+0]; |
156 | screen[l*320+1]=(fontdata8x8[((text[i])*8)+l]&0x40)?color:screen[l*320+1]; |
157 | screen[l*320+2]=(fontdata8x8[((text[i])*8)+l]&0x20)?color:screen[l*320+2]; |
158 | screen[l*320+3]=(fontdata8x8[((text[i])*8)+l]&0x10)?color:screen[l*320+3]; |
159 | screen[l*320+4]=(fontdata8x8[((text[i])*8)+l]&0x08)?color:screen[l*320+4]; |
160 | screen[l*320+5]=(fontdata8x8[((text[i])*8)+l]&0x04)?color:screen[l*320+5]; |
161 | screen[l*320+6]=(fontdata8x8[((text[i])*8)+l]&0x02)?color:screen[l*320+6]; |
162 | screen[l*320+7]=(fontdata8x8[((text[i])*8)+l]&0x01)?color:screen[l*320+7]; |
163 | |
164 | } |
165 | screen+=8; |
166 | } |
167 | } |
168 | |
169 | |
170 | |
171 | |
172 | void CleanSurface(void) |
173 | { |
174 | #ifdef GP2X |
175 | int c=4; |
176 | while (c--) |
c62d2810 |
177 | { |
5232c20c |
178 | memset (gp2x_screen8, 0x80, screenSizeInBytes); |
179 | gp2x_video_flip(); |
180 | } |
181 | |
182 | #else |
c62d2810 |
183 | uint32 x; |
184 | |
185 | x=screen->pitch*screen->h; |
186 | |
187 | if(SDL_MUSTLOCK(screen)) |
188 | SDL_LockSurface(screen); |
189 | |
5232c20c |
190 | memset((uint8*)screen->pixels, 0x3F, x); |
c62d2810 |
191 | |
192 | if(SDL_MUSTLOCK(screen)) |
193 | SDL_UnlockSurface(screen); |
194 | |
195 | SDL_UpdateRect(screen, 0, 0, 0, 0); |
5232c20c |
196 | #endif |
c62d2810 |
197 | } |
198 | |
5232c20c |
199 | |
c62d2810 |
200 | |
201 | void KillVideo(void) |
202 | { |
5232c20c |
203 | #ifdef GP2X |
204 | if (fps_str) |
205 | free(fps_str); |
206 | inited&=~1; |
207 | |
208 | |
209 | #else |
c62d2810 |
210 | if(inited&1) |
211 | { |
212 | SDL_QuitSubSystem(SDL_INIT_VIDEO); |
213 | } |
214 | inited=0; |
5232c20c |
215 | #endif |
c62d2810 |
216 | } |
217 | |
218 | int InitVideo(void) |
219 | { |
5232c20c |
220 | #ifdef GP2X |
221 | |
222 | |
223 | fps_str=malloc(3); |
224 | fps_str[0]='5'; fps_str[1]='0'; fps_str[2]=0; |
225 | |
226 | CleanSurface(); |
227 | |
228 | |
229 | inited|=1; |
230 | |
231 | puts("Initialized GP2X VIDEO via minimal"); |
232 | |
233 | srendline=0; |
234 | erendline=239; |
235 | return 1; |
236 | |
237 | |
238 | #else |
c62d2810 |
239 | const SDL_VideoInfo *vinf; |
240 | int flags=0; |
241 | |
242 | #ifdef BROKEN |
243 | if(_fullscreen && _fshack) |
244 | setenv("SDL_VIDEODRIVER",_fshack,1); |
245 | else |
246 | { |
247 | if(!_fshacksave) |
248 | unsetenv("SDL_VIDEODRIVER"); |
249 | else |
250 | setenv("SDL_VIDEODRIVER",_fshacksave,1); |
251 | } |
252 | #endif |
253 | if(SDL_InitSubSystem(SDL_INIT_VIDEO)==-1) |
254 | { |
255 | puts(SDL_GetError()); |
256 | return(0); |
257 | } |
258 | inited|=1; |
259 | |
260 | SDL_ShowCursor(0); |
261 | tlines=_eline-_sline+1; |
262 | |
263 | vinf=SDL_GetVideoInfo(); |
264 | |
265 | if(vinf->hw_available) |
266 | flags|=SDL_HWSURFACE; |
267 | |
268 | if(_fullscreen) |
269 | flags|=SDL_FULLSCREEN; |
270 | flags|=SDL_HWPALETTE; |
271 | |
272 | if(_fullscreen) |
273 | { |
274 | exs=_xscalefs; |
275 | eys=_yscalefs; |
276 | eefx=_efxfs; |
277 | if(_xres<NWIDTH*exs || _yres<tlines*eys) |
278 | { |
279 | puts("xscale and/or yscale out of bounds."); |
280 | KillVideo(); |
281 | return(0); |
282 | } |
283 | screen = SDL_SetVideoMode(_xres, _yres, 8, flags); |
284 | } |
285 | else |
286 | { |
287 | exs=_xscale; |
288 | eys=_yscale; |
289 | eefx=_efx; |
290 | screen = SDL_SetVideoMode(NWIDTH*exs, tlines*eys, 8, flags); |
291 | } |
292 | if(!screen) |
293 | { |
294 | puts(SDL_GetError()); |
295 | KillVideo(); |
296 | return(0); |
297 | } |
298 | inited=1; |
299 | CleanSurface(); |
300 | |
301 | SDL_WM_SetCaption("FCE Ultra","FCE Ultra"); |
302 | paletterefresh=1; |
5232c20c |
303 | printf("srendline %d, erendline %d\n", srendline, erendline); |
c62d2810 |
304 | return 1; |
5232c20c |
305 | #endif |
c62d2810 |
306 | } |
307 | |
308 | void ToggleFS(void) |
309 | { |
5232c20c |
310 | #ifndef GP2X |
c62d2810 |
311 | KillVideo(); |
312 | _fullscreen=!_fullscreen; |
313 | |
314 | if(!InitVideo()) |
315 | { |
316 | _fullscreen=!_fullscreen; |
317 | if(!InitVideo()) |
318 | { |
319 | puts("Gah, bailing out."); |
320 | exit(1); |
321 | } |
322 | } |
5232c20c |
323 | #endif |
c62d2810 |
324 | } |
5232c20c |
325 | |
326 | |
327 | #ifndef GP2X |
c62d2810 |
328 | static SDL_Color psdl[256]; |
329 | |
330 | void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) |
331 | { |
332 | |
333 | psdl[index].r=r; |
334 | psdl[index].g=g; |
335 | psdl[index].b=b; |
336 | |
337 | paletterefresh=1; |
338 | } |
339 | |
340 | void FCEUD_GetPalette(uint8 index, uint8 *r, uint8 *g, uint8 *b) |
341 | { |
342 | *r=psdl[index].r; |
343 | *g=psdl[index].g; |
344 | *b=psdl[index].b; |
345 | } |
346 | |
347 | static void RedoPalette(void) |
348 | { |
349 | SDL_SetPalette(screen,SDL_PHYSPAL,psdl,0,256); |
350 | } |
5232c20c |
351 | #else |
352 | |
353 | |
354 | |
355 | void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) |
356 | { |
357 | gp2x_video_color8(index, r, g, b); |
358 | gp2x_video_setpalette(); |
359 | |
360 | |
361 | paletterefresh = 1; |
362 | } |
363 | void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b) |
364 | { |
365 | *r = (uint8) gp2x_palette[(index << 1) + 1]; |
366 | *g = (uint8) (gp2x_palette[(index << 1) + 0] >> 8); |
367 | *b = (uint8) gp2x_palette[(index << 1) + 0]; |
368 | } |
369 | |
370 | static void RedoPalette(void) |
371 | { |
372 | } |
373 | |
374 | |
375 | |
376 | unsigned int gp2x_ticks_per_ms=7372800; |
377 | int needfpsflip=1; |
378 | #ifdef FRAMESKIP |
379 | int skipval=16; |
380 | int framecount=0; |
381 | int numrepeats=0; |
382 | int doskipping=0; |
383 | #endif |
384 | |
385 | |
386 | INLINE void printFps(uint8 *screen) |
387 | { |
388 | int y; |
389 | int* destt; |
390 | |
391 | if (needfpsflip) |
392 | { |
393 | if (stretch_offset > 0) |
394 | { |
395 | y=240; |
396 | while (y--) |
397 | { |
398 | |
399 | int* dest=(int *) (screen+((y << 8) + (y << 6))+stretch_offset); |
400 | |
401 | destt=dest - 8; |
402 | destt[0]=0x3F3F3F3F; destt[1]=0x3F3F3F3F; destt[2]=0x3F3F3F3F; destt[3]=0x3F3F3F3F; |
403 | destt[4]=0x3F3F3F3F; destt[5]=0x3F3F3F3F; destt[6]=0x3F3F3F3F; destt[7]=0x3F3F3F3F; |
404 | |
405 | destt=dest + 64; |
406 | destt[0]=0x3F3F3F3F; destt[1]=0x3F3F3F3F; destt[2]=0x3F3F3F3F; destt[3]=0x3F3F3F3F; |
407 | destt[4]=0x3F3F3F3F; destt[5]=0x3F3F3F3F; destt[6]=0x3F3F3F3F; destt[7]=0x3F3F3F3F; |
408 | } |
409 | if (showfps) |
410 | { |
411 | gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); |
412 | } |
413 | } |
414 | |
415 | if (needfpsflip <= 3) |
416 | { |
417 | if (showfps) |
418 | { |
419 | gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); |
420 | } |
421 | needfpsflip++; |
422 | } |
423 | else |
424 | { |
425 | needfpsflip=0; |
426 | } |
427 | } |
428 | #ifdef FRAMESKIP |
429 | if ((fps < 59) && doskipping && ((framesRendered % skipval) == (skipval-1))) |
430 | { |
431 | FCEUI_FrameSkip(1); |
432 | } |
433 | #endif |
434 | if ((framesRendered & 0x3F) != 0x3F) |
435 | { |
436 | return; |
437 | } |
438 | |
439 | unsigned long currTime=gp2x_timer_read_ms(); |
440 | fps= (unsigned long)( framesRendered * 7372800 / (currTime - ticks)); |
441 | if (fps > 90) |
442 | fps=90; |
443 | |
444 | if (fps > 30) |
445 | { |
446 | fps_samplecount++; |
447 | total_fps+=fps; |
448 | } |
449 | if (stretch_offset && showfps) |
450 | { |
451 | sprintf(fps_str, "%d", (int)fps); |
452 | needfpsflip=1; |
453 | fps_str[2]=0; |
454 | gp2x_text(screen, 0, 0, fps_str, stretch_offset, 0); |
455 | } |
456 | |
457 | #ifdef FRAMESKIP |
458 | if (fps < 59) |
459 | { |
460 | numrepeats++; |
461 | if (numrepeats >= 4) |
462 | { |
463 | if (skipval > 4) |
464 | { |
465 | skipval-=2; |
466 | } |
467 | doskipping=1; |
468 | printf("skipping every %dth frame, currfps=%d\n", skipval, fps); |
469 | numrepeats=0; |
470 | } |
471 | } |
472 | else |
473 | { |
474 | numrepeats=0; |
475 | } |
476 | #endif |
477 | ticks = currTime; |
478 | framesRendered = 0; |
479 | } |
480 | #endif |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
c62d2810 |
491 | |
492 | void LockConsole(){} |
493 | void UnlockConsole(){} |
5232c20c |
494 | |
495 | |
496 | #ifdef GP2X |
497 | |
498 | void BlitScreen(uint8 * XBuf) |
499 | { |
500 | |
501 | int x, y, yinc; |
502 | if (!XBuf) return; |
503 | XBufHelper=XBuf; |
504 | framesRendered++; |
505 | XBuf = XBuf ; |
506 | |
507 | y=240; |
508 | yinc=272*(y-1); |
509 | while (y--) |
510 | { |
511 | int* dest=(int *) (gp2x_screen8+((y << 8) + (y << 6))+stretch_offset); |
512 | |
513 | int* src=(int *) (XBuf+yinc); |
514 | x=64; |
515 | while (x--) |
516 | { |
517 | dest[x]=src[x]; |
518 | } |
519 | yinc-=272; |
520 | } |
521 | |
522 | if (paletterefresh) |
523 | { |
524 | gp2x_video_setpalette(); |
525 | paletterefresh = 0; |
526 | } |
527 | |
528 | printFps(gp2x_screen8); |
529 | gp2x_video_flip(); |
530 | } |
531 | |
532 | |
533 | |
534 | |
535 | #else |
536 | extern void SpeedThrottle(); |
c62d2810 |
537 | void BlitScreen(uint8 *XBuf) |
538 | { |
539 | uint8 *dest; |
540 | int xo=0,yo=0; |
541 | |
5232c20c |
542 | SpeedThrottle(); |
543 | |
c62d2810 |
544 | if(paletterefresh) |
545 | { |
546 | RedoPalette(); |
547 | paletterefresh=0; |
548 | } |
549 | |
550 | XBuf+=_sline*272; |
551 | |
552 | if(SDL_MUSTLOCK(screen)) |
553 | SDL_LockSurface(screen); |
554 | |
555 | dest=screen->pixels; |
556 | |
557 | if(_fullscreen) |
558 | { |
559 | xo=(((screen->w-NWIDTH*exs))>>1); |
560 | dest+=xo; |
561 | if(screen->h>(tlines*eys)) |
562 | { |
563 | yo=((screen->h-tlines*eys)>>1); |
564 | dest+=yo*screen->pitch; |
565 | } |
566 | } |
567 | |
568 | Blit8To8(XBuf+NOFFSET,dest, NWIDTH, tlines, screen->pitch,exs,eys,eefx); |
569 | |
570 | if(SDL_MUSTLOCK(screen)) |
571 | SDL_UnlockSurface(screen); |
572 | |
573 | SDL_UpdateRect(screen, xo, yo, NWIDTH*exs, tlines*eys); |
5232c20c |
574 | |
575 | if (0) |
576 | { |
577 | gp2x_text(NULL, 0, 0, NULL, 0, 0); |
578 | } |
c62d2810 |
579 | } |
580 | |
581 | uint32 PtoV(uint16 x, uint16 y) |
582 | { |
583 | if(_fullscreen) |
584 | { |
585 | |
586 | } |
587 | else |
588 | { |
589 | if(eoptions&EO_CLIPSIDES) |
590 | x+=8; |
591 | y+=srendline; |
592 | } |
593 | return(x|(y<<16)); |
594 | } |
5232c20c |
595 | #endif |