35868d35 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
16 | */ |
17 | |
18 | #include <stdio.h> |
19 | #include <string.h> |
20 | #include <sys/time.h> |
21 | |
22f08d95 |
22 | #include "gp2x.h" |
35868d35 |
23 | #include "minimal.h" |
24 | |
25 | extern int showfps; |
26 | |
27 | static char fps_str[32]; |
28 | static int framesEmulated, framesRendered; |
29 | |
30 | int stretch_offset=32; |
31 | int paletterefresh; |
32 | |
33 | #define FPS_COLOR 61 |
34 | |
35 | |
36 | static unsigned char fontdata8x8[] = |
37 | { |
38 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
39 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
40 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
41 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
42 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
43 | 0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C, |
44 | 0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00, |
45 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, |
46 | 0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00, |
47 | 0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00, |
48 | 0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, |
49 | 0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40, |
50 | 0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00, |
51 | 0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00, |
52 | 0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00, |
53 | 0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00, |
54 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00, |
55 | 0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00, |
56 | 0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00, |
57 | 0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00, |
58 | 0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00, |
59 | 0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00, |
60 | 0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00, |
61 | 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00, |
62 | 0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00, |
63 | 0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00, |
64 | 0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00, |
65 | 0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00, |
66 | 0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00, |
67 | 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30, |
68 | 0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00, |
69 | 0x70,0x38,0x1C,0x0E,0x1C,0x38,0x70,0x00,0x7C,0xC6,0xC6,0x1C,0x18,0x00,0x18,0x00, |
70 | 0x3C,0x42,0x99,0xA1,0xA5,0x99,0x42,0x3C,0x38,0x6C,0xC6,0xC6,0xFE,0xC6,0xC6,0x00, |
71 | 0xFC,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,0x30,0x3C,0x00, |
84 | 0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, |
85 | 0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, |
86 | 0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00, |
87 | 0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00, |
88 | 0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00, |
89 | 0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C, |
90 | 0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00, |
91 | 0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00, |
92 | 0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00, |
93 | 0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00, |
94 | 0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06, |
95 | 0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00, |
96 | 0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00, |
97 | 0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00, |
98 | 0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C, |
99 | 0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00, |
100 | 0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00, |
101 | 0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00, |
102 | }; |
103 | |
104 | static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color, int flip) |
105 | { |
106 | int i,l,slen; |
107 | slen=strlen(text); |
108 | |
109 | screen=screen+x+y*320; |
110 | |
111 | for (i=0;i<slen;i++) |
112 | { |
113 | for (l=0;l<8;l++) |
114 | { |
115 | |
116 | screen[l*320+0]=(fontdata8x8[((text[i])*8)+l]&0x80)?color:screen[l*320+0]; |
117 | screen[l*320+1]=(fontdata8x8[((text[i])*8)+l]&0x40)?color:screen[l*320+1]; |
118 | screen[l*320+2]=(fontdata8x8[((text[i])*8)+l]&0x20)?color:screen[l*320+2]; |
119 | screen[l*320+3]=(fontdata8x8[((text[i])*8)+l]&0x10)?color:screen[l*320+3]; |
120 | screen[l*320+4]=(fontdata8x8[((text[i])*8)+l]&0x08)?color:screen[l*320+4]; |
121 | screen[l*320+5]=(fontdata8x8[((text[i])*8)+l]&0x04)?color:screen[l*320+5]; |
122 | screen[l*320+6]=(fontdata8x8[((text[i])*8)+l]&0x02)?color:screen[l*320+6]; |
123 | screen[l*320+7]=(fontdata8x8[((text[i])*8)+l]&0x01)?color:screen[l*320+7]; |
124 | |
125 | } |
126 | screen+=8; |
127 | } |
128 | } |
129 | |
130 | |
131 | void CleanSurface(void) |
132 | { |
133 | int c=4; |
134 | while (c--) |
135 | { |
136 | memset (gp2x_screen8, 0x80, 320*240); |
137 | gp2x_video_flip(); |
138 | } |
139 | } |
140 | |
141 | |
142 | void KillVideo(void) |
143 | { |
144 | } |
145 | |
146 | |
147 | int InitVideo(void) |
148 | { |
149 | fps_str[0]=0; |
150 | |
151 | CleanSurface(); |
152 | |
153 | puts("Initialized GP2X VIDEO via minimal"); |
154 | |
155 | srendline=0; |
156 | erendline=239; |
157 | return 1; |
158 | } |
159 | |
160 | |
161 | void ToggleFS(void) |
162 | { |
163 | } |
164 | |
165 | |
166 | void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) |
167 | { |
168 | gp2x_video_color8(index, r, g, b); |
169 | gp2x_video_setpalette(); |
170 | |
171 | paletterefresh = 1; |
172 | } |
173 | |
174 | |
175 | void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b) |
176 | { |
177 | *r = (uint8) gp2x_palette[(index << 1) + 1]; |
178 | *g = (uint8) (gp2x_palette[(index << 1) + 0] >> 8); |
179 | *b = (uint8) gp2x_palette[(index << 1) + 0]; |
180 | } |
181 | |
182 | |
183 | static INLINE void printFps(uint8 *screen) |
184 | { |
185 | struct timeval tv_now; |
186 | static int prevsec, needfpsflip = 0; |
187 | |
188 | gettimeofday(&tv_now, 0); |
189 | if (prevsec != tv_now.tv_sec) |
190 | { |
22f08d95 |
191 | sprintf(fps_str, "%2i/%2i", framesRendered, framesEmulated); |
35868d35 |
192 | framesEmulated = framesRendered = 0; |
193 | needfpsflip = 4; |
194 | prevsec = tv_now.tv_sec; |
195 | } |
196 | |
197 | if (stretch_offset > 0) |
198 | { |
199 | if (needfpsflip) |
200 | { |
201 | int y, *destt = (int *) screen; |
202 | for (y = 240; y; y--) |
203 | { |
204 | *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
205 | *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
206 | destt += 64; |
207 | |
208 | *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
209 | *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
210 | } |
211 | if (showfps) |
212 | { |
213 | fps_str[2] = 0; |
214 | gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); |
215 | gp2x_text(screen, 0, 10, fps_str+3, FPS_COLOR, 0); |
216 | } |
217 | needfpsflip--; |
218 | } |
219 | } |
220 | else |
221 | { |
222 | if (showfps) |
223 | { |
224 | gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); |
225 | } |
226 | } |
227 | } |
228 | |
229 | |
230 | void BlitScreen(uint8 * XBuf) |
231 | { |
232 | int x, y, yinc; |
233 | |
234 | framesEmulated++; |
235 | |
236 | if (!XBuf) return; |
237 | |
238 | framesRendered++; |
239 | |
240 | #if 1 // 48->54 |
241 | y=240; |
242 | yinc=272*(y-1); |
243 | while (y--) |
244 | { |
245 | int* dest=(int *) (gp2x_screen8+((y << 8) + (y << 6))+stretch_offset); |
246 | |
247 | int* src=(int *) (XBuf+yinc); |
248 | x=64; |
249 | while (x--) |
250 | { |
251 | dest[x]=src[x]; |
252 | } |
253 | yinc-=272; |
254 | } |
255 | |
256 | if (paletterefresh) |
257 | { |
258 | gp2x_video_setpalette(); |
259 | paletterefresh = 0; |
260 | } |
261 | #endif |
262 | printFps(gp2x_screen8); |
263 | gp2x_video_flip(); |
264 | } |
265 | |
266 | |