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 | |
396c448e |
24 | #include "../common/main.h" |
4a2a617a |
25 | #include "../common/settings.h" |
35868d35 |
26 | #include "minimal.h" |
396c448e |
27 | #include "../libpicofe/fonts.h" |
c8c88d89 |
28 | #include "../arm/asmutils.h" |
35868d35 |
29 | |
35868d35 |
30 | static char fps_str[32]; |
31 | static int framesEmulated, framesRendered; |
32 | |
b2b95d2e |
33 | int gp2x_palette[256]; |
989672f4 |
34 | unsigned short gp2x_palette16[256]; |
b2b95d2e |
35 | |
35868d35 |
36 | int paletterefresh; |
37 | |
21afaa36 |
38 | extern int eoptions; |
39 | |
6587f346 |
40 | #define FPS_COLOR 1 |
35868d35 |
41 | |
42 | |
35868d35 |
43 | static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color, int flip) |
44 | { |
45 | int i,l,slen; |
46 | slen=strlen(text); |
47 | |
48 | screen=screen+x+y*320; |
49 | |
50 | for (i=0;i<slen;i++) |
51 | { |
52 | for (l=0;l<8;l++) |
53 | { |
54 | |
21afaa36 |
55 | screen[l*320+0]=(fontdata8x8[((text[i])*8)+l]&0x80)?color:0; |
56 | screen[l*320+1]=(fontdata8x8[((text[i])*8)+l]&0x40)?color:0; |
57 | screen[l*320+2]=(fontdata8x8[((text[i])*8)+l]&0x20)?color:0; |
58 | screen[l*320+3]=(fontdata8x8[((text[i])*8)+l]&0x10)?color:0; |
59 | screen[l*320+4]=(fontdata8x8[((text[i])*8)+l]&0x08)?color:0; |
60 | screen[l*320+5]=(fontdata8x8[((text[i])*8)+l]&0x04)?color:0; |
61 | screen[l*320+6]=(fontdata8x8[((text[i])*8)+l]&0x02)?color:0; |
62 | screen[l*320+7]=(fontdata8x8[((text[i])*8)+l]&0x01)?color:0; |
35868d35 |
63 | |
64 | } |
65 | screen+=8; |
66 | } |
67 | } |
68 | |
69 | |
70 | void CleanSurface(void) |
71 | { |
72 | int c=4; |
73 | while (c--) |
74 | { |
21afaa36 |
75 | memset32(gp2x_screen, 0, 320*240*2/4); |
35868d35 |
76 | gp2x_video_flip(); |
77 | } |
b2b95d2e |
78 | XBuf = gp2x_screen; |
35868d35 |
79 | } |
80 | |
81 | |
82 | void KillVideo(void) |
83 | { |
84 | } |
85 | |
86 | |
87 | int InitVideo(void) |
88 | { |
89 | fps_str[0]=0; |
90 | |
91 | CleanSurface(); |
92 | |
93 | puts("Initialized GP2X VIDEO via minimal"); |
94 | |
95 | srendline=0; |
96 | erendline=239; |
b2b95d2e |
97 | XBuf = gp2x_screen; |
35868d35 |
98 | return 1; |
99 | } |
100 | |
101 | |
0bb3fe12 |
102 | // 16: rrrr rggg gg0b bbbb |
35868d35 |
103 | void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) |
104 | { |
47d0839e |
105 | /* note: menu depends on bit5 being 0 */ |
b2b95d2e |
106 | gp2x_palette[index] = (r << 16) | (g << 8) | b; |
47d0839e |
107 | gp2x_palette16[index] = ((r & 0xf8) << 8) | ((g & 0xf8) << 3) | (b >> 3); |
b2b95d2e |
108 | gp2x_video_setpalette(gp2x_palette, index + 1); |
35868d35 |
109 | |
110 | paletterefresh = 1; |
111 | } |
112 | |
113 | |
114 | void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b) |
115 | { |
b2b95d2e |
116 | int pix = gp2x_palette[index]; |
117 | *r = (uint8) (pix >> 16); |
118 | *g = (uint8) (pix >> 8); |
119 | *b = (uint8) pix; |
35868d35 |
120 | } |
121 | |
122 | |
123 | static INLINE void printFps(uint8 *screen) |
124 | { |
125 | struct timeval tv_now; |
126 | static int prevsec, needfpsflip = 0; |
127 | |
128 | gettimeofday(&tv_now, 0); |
129 | if (prevsec != tv_now.tv_sec) |
130 | { |
22f08d95 |
131 | sprintf(fps_str, "%2i/%2i", framesRendered, framesEmulated); |
35868d35 |
132 | framesEmulated = framesRendered = 0; |
133 | needfpsflip = 4; |
134 | prevsec = tv_now.tv_sec; |
135 | } |
136 | |
21afaa36 |
137 | if (!Settings.showfps || !screen) return; |
138 | |
989672f4 |
139 | if (Settings.scaling == 0) |
35868d35 |
140 | { |
141 | if (needfpsflip) |
142 | { |
21afaa36 |
143 | int sep; |
144 | for (sep=1; sep < 5; sep++) |
145 | if (fps_str[sep] == '/' || fps_str[sep] == 0) break; |
146 | fps_str[sep] = 0; |
147 | gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); |
148 | gp2x_text(screen, 0, 10, fps_str+sep+1, FPS_COLOR, 0); |
35868d35 |
149 | needfpsflip--; |
150 | } |
151 | } |
152 | else |
153 | { |
21afaa36 |
154 | gp2x_text(screen+32, 0, srendline, fps_str, FPS_COLOR, 0); |
35868d35 |
155 | } |
156 | } |
157 | |
158 | |
7b356ee3 |
159 | void BlitPrepare(int skip) |
35868d35 |
160 | { |
35868d35 |
161 | framesEmulated++; |
162 | |
7b356ee3 |
163 | if (skip) { |
21afaa36 |
164 | printFps(0); |
165 | return; |
166 | } |
35868d35 |
167 | |
168 | framesRendered++; |
169 | |
21afaa36 |
170 | if (eoptions & EO_CLIPSIDES) |
171 | { |
172 | int i, *p = (int *) ((char *)gp2x_screen + 32); |
173 | for (i = 240; i; i--, p += 320/4) |
174 | { |
175 | p[0] = p[1] = p[62] = p[63] = 0; |
176 | } |
177 | } |
178 | |
642070a9 |
179 | if (Settings.accurate_mode && Settings.scaling < 2) |
180 | { |
181 | int i, *p = (int *)gp2x_screen + 32/4; |
182 | if (srendline > 0) |
183 | for (i = srendline; i > 0; i--, p += 320/4) |
184 | memset32(p, 0, 256/4); |
185 | if (erendline < 239) |
186 | { |
187 | int *p = (int *)gp2x_screen + erendline*320/4 + 32/4; |
44343b87 |
188 | for (i = 239-erendline; i > 0; i--, p += 320/4) |
642070a9 |
189 | memset32(p, 0, 256/4); |
190 | } |
191 | } |
192 | |
0bb3fe12 |
193 | printFps(gp2x_screen); |
194 | |
989672f4 |
195 | if (Settings.scaling == 3) |
21afaa36 |
196 | { |
197 | soft_scale((char *)gp2x_screen + 32, gp2x_palette16, srendline, erendline-srendline); |
198 | if (srendline) |
199 | memset32((int *)((char *)gp2x_screen + 32), 0, srendline*320*2/4); |
200 | } |
989672f4 |
201 | |
7b356ee3 |
202 | /* at this point we should be done with the frame */ |
203 | gp2x_video_flush_cache(); |
204 | } |
205 | |
206 | |
207 | void BlitScreen(int skip) |
208 | { |
209 | if (!skip) |
210 | { |
211 | gp2x_video_flip(); |
212 | XBuf = gp2x_screen; |
213 | } |
35868d35 |
214 | } |
215 | |
216 | |