| 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 | |
| 22 | #include "../../video.h" |
| 23 | |
| 24 | #include "gp2x.h" |
| 25 | #include "minimal.h" |
| 26 | |
| 27 | extern int showfps; |
| 28 | |
| 29 | static char fps_str[32]; |
| 30 | static int framesEmulated, framesRendered; |
| 31 | |
| 32 | int scaled_display=0; |
| 33 | int paletterefresh; |
| 34 | |
| 35 | #define FPS_COLOR 61 |
| 36 | |
| 37 | |
| 38 | static unsigned char fontdata8x8[] = |
| 39 | { |
| 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 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 44 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 45 | 0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C, |
| 46 | 0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00, |
| 47 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, |
| 48 | 0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00, |
| 49 | 0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00, |
| 50 | 0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, |
| 51 | 0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40, |
| 52 | 0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00, |
| 53 | 0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00, |
| 54 | 0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00, |
| 55 | 0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00, |
| 56 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00, |
| 57 | 0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00, |
| 58 | 0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00, |
| 59 | 0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00, |
| 60 | 0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00, |
| 61 | 0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00, |
| 62 | 0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00, |
| 63 | 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00, |
| 64 | 0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00, |
| 65 | 0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00, |
| 66 | 0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00, |
| 67 | 0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00, |
| 68 | 0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00, |
| 69 | 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30, |
| 70 | 0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00, |
| 71 | 0x70,0x38,0x1C,0x0E,0x1C,0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FE,0xFE,0xEE,0xC6,0x00, |
| 84 | 0xC6,0xEE,0x3C,0x38,0x7C,0xEE,0xC6,0x00,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00, |
| 85 | 0xFE,0x0E,0x1C,0x38,0x70,0xE0,0xFE,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, |
| 86 | 0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, |
| 87 | 0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, |
| 88 | 0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00, |
| 89 | 0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00, |
| 90 | 0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00, |
| 91 | 0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C, |
| 92 | 0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00, |
| 93 | 0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00, |
| 94 | 0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00, |
| 95 | 0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00, |
| 96 | 0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06, |
| 97 | 0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00, |
| 98 | 0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00, |
| 99 | 0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00, |
| 100 | 0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C, |
| 101 | 0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00, |
| 102 | 0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00, |
| 103 | 0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00, |
| 104 | }; |
| 105 | |
| 106 | static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color, int flip) |
| 107 | { |
| 108 | int i,l,slen; |
| 109 | slen=strlen(text); |
| 110 | |
| 111 | screen=screen+x+y*320; |
| 112 | |
| 113 | for (i=0;i<slen;i++) |
| 114 | { |
| 115 | for (l=0;l<8;l++) |
| 116 | { |
| 117 | |
| 118 | screen[l*320+0]=(fontdata8x8[((text[i])*8)+l]&0x80)?color:screen[l*320+0]; |
| 119 | screen[l*320+1]=(fontdata8x8[((text[i])*8)+l]&0x40)?color:screen[l*320+1]; |
| 120 | screen[l*320+2]=(fontdata8x8[((text[i])*8)+l]&0x20)?color:screen[l*320+2]; |
| 121 | screen[l*320+3]=(fontdata8x8[((text[i])*8)+l]&0x10)?color:screen[l*320+3]; |
| 122 | screen[l*320+4]=(fontdata8x8[((text[i])*8)+l]&0x08)?color:screen[l*320+4]; |
| 123 | screen[l*320+5]=(fontdata8x8[((text[i])*8)+l]&0x04)?color:screen[l*320+5]; |
| 124 | screen[l*320+6]=(fontdata8x8[((text[i])*8)+l]&0x02)?color:screen[l*320+6]; |
| 125 | screen[l*320+7]=(fontdata8x8[((text[i])*8)+l]&0x01)?color:screen[l*320+7]; |
| 126 | |
| 127 | } |
| 128 | screen+=8; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | |
| 133 | void CleanSurface(void) |
| 134 | { |
| 135 | int c=4; |
| 136 | while (c--) |
| 137 | { |
| 138 | memset (gp2x_screen8, 0x80, 320*240); |
| 139 | gp2x_video_flip(); |
| 140 | } |
| 141 | XBuf = gp2x_screen8; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | void KillVideo(void) |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | |
| 150 | int InitVideo(void) |
| 151 | { |
| 152 | fps_str[0]=0; |
| 153 | |
| 154 | CleanSurface(); |
| 155 | |
| 156 | puts("Initialized GP2X VIDEO via minimal"); |
| 157 | |
| 158 | srendline=0; |
| 159 | erendline=239; |
| 160 | XBuf = gp2x_screen8; // TODO: use mmuhacked upper mem |
| 161 | return 1; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | void ToggleFS(void) |
| 166 | { |
| 167 | } |
| 168 | |
| 169 | |
| 170 | void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) |
| 171 | { |
| 172 | gp2x_video_color8(index, r, g, b); |
| 173 | gp2x_video_setpalette(); |
| 174 | |
| 175 | paletterefresh = 1; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b) |
| 180 | { |
| 181 | *r = (uint8) gp2x_palette[(index << 1) + 1]; |
| 182 | *g = (uint8) (gp2x_palette[(index << 1) + 0] >> 8); |
| 183 | *b = (uint8) gp2x_palette[(index << 1) + 0]; |
| 184 | } |
| 185 | |
| 186 | |
| 187 | static INLINE void printFps(uint8 *screen) |
| 188 | { |
| 189 | struct timeval tv_now; |
| 190 | static int prevsec, needfpsflip = 0; |
| 191 | |
| 192 | gettimeofday(&tv_now, 0); |
| 193 | if (prevsec != tv_now.tv_sec) |
| 194 | { |
| 195 | sprintf(fps_str, "%2i/%2i", framesRendered, framesEmulated); |
| 196 | framesEmulated = framesRendered = 0; |
| 197 | needfpsflip = 4; |
| 198 | prevsec = tv_now.tv_sec; |
| 199 | } |
| 200 | |
| 201 | if (!scaled_display) |
| 202 | { |
| 203 | if (needfpsflip) |
| 204 | { |
| 205 | int y, *destt = (int *) screen; |
| 206 | for (y = 20/*240*/; y; y--) |
| 207 | { |
| 208 | *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
| 209 | *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
| 210 | destt += 64+8; |
| 211 | |
| 212 | //*destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
| 213 | //*destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
| 214 | } |
| 215 | if (showfps) |
| 216 | { |
| 217 | int sep; |
| 218 | for (sep=1; sep < 5; sep++) |
| 219 | if (fps_str[sep] == '/' || fps_str[sep] == 0) break; |
| 220 | fps_str[sep] = 0; |
| 221 | gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); |
| 222 | gp2x_text(screen, 0, 10, fps_str+sep+1, FPS_COLOR, 0); |
| 223 | } |
| 224 | needfpsflip--; |
| 225 | } |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | if (showfps) |
| 230 | { |
| 231 | gp2x_text(screen+32, 0, 0, fps_str, FPS_COLOR, 0); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | |
| 237 | void BlitScreen(uint8 *buf) |
| 238 | { |
| 239 | framesEmulated++; |
| 240 | |
| 241 | if (!buf) return; |
| 242 | |
| 243 | framesRendered++; |
| 244 | |
| 245 | printFps(gp2x_screen8); |
| 246 | gp2x_video_flip(); |
| 247 | XBuf = gp2x_screen8; |
| 248 | } |
| 249 | |
| 250 | |