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