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