| 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 "main.h" |
| 25 | #include "gp2x.h" |
| 26 | #include "minimal.h" |
| 27 | #include "fonts.h" |
| 28 | #include "asmutils.h" |
| 29 | |
| 30 | static char fps_str[32]; |
| 31 | static int framesEmulated, framesRendered; |
| 32 | |
| 33 | int gp2x_palette[256]; |
| 34 | unsigned short gp2x_palette16[256]; |
| 35 | |
| 36 | int paletterefresh; |
| 37 | |
| 38 | #define FPS_COLOR 1 |
| 39 | |
| 40 | |
| 41 | static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color, int flip) |
| 42 | { |
| 43 | int i,l,slen; |
| 44 | slen=strlen(text); |
| 45 | |
| 46 | screen=screen+x+y*320; |
| 47 | |
| 48 | for (i=0;i<slen;i++) |
| 49 | { |
| 50 | for (l=0;l<8;l++) |
| 51 | { |
| 52 | |
| 53 | screen[l*320+0]=(fontdata8x8[((text[i])*8)+l]&0x80)?color:screen[l*320+0]; |
| 54 | screen[l*320+1]=(fontdata8x8[((text[i])*8)+l]&0x40)?color:screen[l*320+1]; |
| 55 | screen[l*320+2]=(fontdata8x8[((text[i])*8)+l]&0x20)?color:screen[l*320+2]; |
| 56 | screen[l*320+3]=(fontdata8x8[((text[i])*8)+l]&0x10)?color:screen[l*320+3]; |
| 57 | screen[l*320+4]=(fontdata8x8[((text[i])*8)+l]&0x08)?color:screen[l*320+4]; |
| 58 | screen[l*320+5]=(fontdata8x8[((text[i])*8)+l]&0x04)?color:screen[l*320+5]; |
| 59 | screen[l*320+6]=(fontdata8x8[((text[i])*8)+l]&0x02)?color:screen[l*320+6]; |
| 60 | screen[l*320+7]=(fontdata8x8[((text[i])*8)+l]&0x01)?color:screen[l*320+7]; |
| 61 | |
| 62 | } |
| 63 | screen+=8; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void CleanSurface(void) |
| 69 | { |
| 70 | int c=4; |
| 71 | while (c--) |
| 72 | { |
| 73 | memset(gp2x_screen, 0, 320*240); |
| 74 | gp2x_video_flip(); |
| 75 | } |
| 76 | XBuf = gp2x_screen; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void KillVideo(void) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | |
| 85 | int InitVideo(void) |
| 86 | { |
| 87 | fps_str[0]=0; |
| 88 | |
| 89 | CleanSurface(); |
| 90 | |
| 91 | puts("Initialized GP2X VIDEO via minimal"); |
| 92 | |
| 93 | srendline=0; |
| 94 | erendline=239; |
| 95 | XBuf = gp2x_screen; |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | void ToggleFS(void) |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | |
| 105 | // 16: rrrr rggg gggb bbbb |
| 106 | void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) |
| 107 | { |
| 108 | gp2x_palette[index] = (r << 16) | (g << 8) | b; |
| 109 | gp2x_palette16[index] = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); |
| 110 | gp2x_video_setpalette(gp2x_palette, index + 1); |
| 111 | |
| 112 | paletterefresh = 1; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b) |
| 117 | { |
| 118 | int pix = gp2x_palette[index]; |
| 119 | *r = (uint8) (pix >> 16); |
| 120 | *g = (uint8) (pix >> 8); |
| 121 | *b = (uint8) pix; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | static INLINE void printFps(uint8 *screen) |
| 126 | { |
| 127 | struct timeval tv_now; |
| 128 | static int prevsec, needfpsflip = 0; |
| 129 | |
| 130 | gettimeofday(&tv_now, 0); |
| 131 | if (prevsec != tv_now.tv_sec) |
| 132 | { |
| 133 | sprintf(fps_str, "%2i/%2i", framesRendered, framesEmulated); |
| 134 | framesEmulated = framesRendered = 0; |
| 135 | needfpsflip = 4; |
| 136 | prevsec = tv_now.tv_sec; |
| 137 | } |
| 138 | |
| 139 | if (Settings.scaling == 0) |
| 140 | { |
| 141 | if (needfpsflip) |
| 142 | { |
| 143 | int y, *destt = (int *) screen; |
| 144 | for (y = 20/*240*/; y; y--) |
| 145 | { |
| 146 | *destt++ = 0; *destt++ = 0; *destt++ = 0; *destt++ = 0; |
| 147 | *destt++ = 0; *destt++ = 0; *destt++ = 0; *destt++ = 0; |
| 148 | destt += 64+8; |
| 149 | |
| 150 | //*destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
| 151 | //*destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; *destt++ = 0x3F3F3F3F; |
| 152 | } |
| 153 | if (Settings.showfps) |
| 154 | { |
| 155 | int sep; |
| 156 | for (sep=1; sep < 5; sep++) |
| 157 | if (fps_str[sep] == '/' || fps_str[sep] == 0) break; |
| 158 | fps_str[sep] = 0; |
| 159 | gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); |
| 160 | gp2x_text(screen, 0, 10, fps_str+sep+1, FPS_COLOR, 0); |
| 161 | } |
| 162 | needfpsflip--; |
| 163 | } |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | if (Settings.showfps) |
| 168 | { |
| 169 | gp2x_text(screen+32, 0, 0, fps_str, FPS_COLOR, 0); // TODO: firstline |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | |
| 175 | void BlitScreen(uint8 *buf) |
| 176 | { |
| 177 | framesEmulated++; |
| 178 | |
| 179 | if (!buf) return; |
| 180 | |
| 181 | framesRendered++; |
| 182 | |
| 183 | printFps(gp2x_screen); |
| 184 | |
| 185 | if (Settings.scaling == 3) |
| 186 | soft_scale((char *)gp2x_screen + 32, gp2x_palette16, 0, 240); |
| 187 | |
| 188 | gp2x_video_flip(); |
| 189 | XBuf = gp2x_screen; |
| 190 | } |
| 191 | |
| 192 | |