5a681086 |
1 | /*\r |
2 | * (c) Copyright 2006-2010 notaz, All rights reserved.\r |
7bf552b5 |
3 | * (c) Copyright 2019-2024 irixxxx\r |
5a681086 |
4 | *\r |
5 | * For performance reasons 3 renderers are exported for both MD and 32x modes:\r |
6 | * - 16bpp line renderer\r |
7 | * - 8bpp line renderer (slightly faster)\r |
8 | * - 8bpp tile renderer\r |
9 | * In 32x mode:\r |
10 | * - 32x layer is overlayed on top of 16bpp one\r |
98a27142 |
11 | * - line internal one done on .Draw2FB, then mixed with 32x\r |
12 | * - tile internal one done on .Draw2FB, then mixed with 32x\r |
5a681086 |
13 | */\r |
cc68a136 |
14 | \r |
15 | #include <stdio.h>\r |
16 | #include <stdlib.h>\r |
c7eb229a |
17 | #include <unistd.h>\r |
cc68a136 |
18 | \r |
75a30842 |
19 | #include "../libpicofe/gp2x/plat_gp2x.h"\r |
20 | #include "../libpicofe/gp2x/soc.h"\r |
21 | #include "../libpicofe/input.h"\r |
22 | #include "../libpicofe/plat.h"\r |
23 | #include "../libpicofe/gp2x/soc_pollux.h"\r |
24 | #include "../common/menu_pico.h"\r |
e5f426aa |
25 | #include "../common/arm_utils.h"\r |
ea8c405f |
26 | #include "../common/emu.h"\r |
bac44b18 |
27 | #include "../common/keyboard.h"\r |
75a30842 |
28 | #include "../common/config_file.h"\r |
29 | #include "../common/version.h"\r |
30 | #include "plat.h"\r |
cc68a136 |
31 | \r |
efcba75f |
32 | #include <pico/pico_int.h>\r |
33 | #include <pico/patch.h>\r |
34 | #include <pico/sound/mix.h>\r |
325ee167 |
35 | #include <zlib.h>\r |
cc68a136 |
36 | \r |
cc68a136 |
37 | #ifdef BENCHMARK\r |
38 | #define OSD_FPS_X 220\r |
39 | #else\r |
40 | #define OSD_FPS_X 260\r |
41 | #endif\r |
42 | \r |
cc68a136 |
43 | \r |
75a30842 |
44 | //extern int crashed_940;\r |
cc68a136 |
45 | \r |
f4750ee0 |
46 | static int osd_fps_x, osd_y, doing_bg_frame;\r |
fcdefcf6 |
47 | const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };\r |
48 | const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };\r |
5a681086 |
49 | enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };\r |
cc68a136 |
50 | \r |
dca20eff |
51 | static int is_1stblanked;\r |
52 | static int firstline, linecount;\r |
53 | static int firstcol, colcount;\r |
54 | \r |
f4750ee0 |
55 | static int (*emu_scan_begin)(unsigned int num) = NULL;\r |
56 | static int (*emu_scan_end)(unsigned int num) = NULL;\r |
cc68a136 |
57 | \r |
2433f409 |
58 | \r |
f2cf8472 |
59 | void pemu_prep_defconfig(void)\r |
58c86d00 |
60 | {\r |
ee2a3bdf |
61 | gp2x_soc_t soc;\r |
62 | \r |
ee2a3bdf |
63 | defaultConfig.CPUclock = default_cpu_clock;\r |
9090dc0f |
64 | defaultConfig.renderer32x = RT_8BIT_ACC;\r |
45285368 |
65 | defaultConfig.analog_deadzone = 50;\r |
ee2a3bdf |
66 | \r |
67 | soc = soc_detect();\r |
68 | if (soc == SOCID_MMSP2)\r |
69 | defaultConfig.s_PicoOpt |= POPT_EXT_FM;\r |
8340e7c9 |
70 | else if (soc == SOCID_POLLUX) {\r |
61753a67 |
71 | defaultConfig.EmuOpt |= EOPT_WIZ_TEAR_FIX|EOPT_SHOW_RTC;\r |
8340e7c9 |
72 | defaultConfig.s_PicoOpt |= POPT_EN_MCD_GFX;\r |
73 | }\r |
58c86d00 |
74 | }\r |
75 | \r |
697746df |
76 | void pemu_validate_config(void)\r |
77 | {\r |
f4750ee0 |
78 | if (gp2x_dev_id != GP2X_DEV_GP2X)\r |
93f9619e |
79 | PicoIn.opt &= ~POPT_EXT_FM;\r |
f4750ee0 |
80 | if (gp2x_dev_id != GP2X_DEV_WIZ)\r |
697746df |
81 | currentConfig.EmuOpt &= ~EOPT_WIZ_TEAR_FIX;\r |
82 | \r |
83 | if (currentConfig.gamma < 10 || currentConfig.gamma > 300)\r |
84 | currentConfig.gamma = 100;\r |
85 | \r |
86 | if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 1024)\r |
87 | currentConfig.CPUclock = default_cpu_clock;\r |
88 | }\r |
89 | \r |
5a681086 |
90 | static int get_renderer(void)\r |
91 | {\r |
9b2d466a |
92 | if (doing_bg_frame)\r |
93 | return RT_16BIT;\r |
93f9619e |
94 | if (PicoIn.AHW & PAHW_32X)\r |
5a681086 |
95 | return currentConfig.renderer32x;\r |
96 | else\r |
97 | return currentConfig.renderer;\r |
98 | }\r |
99 | \r |
100 | static void change_renderer(int diff)\r |
101 | {\r |
102 | int *r;\r |
93f9619e |
103 | if (PicoIn.AHW & PAHW_32X)\r |
5a681086 |
104 | r = ¤tConfig.renderer32x;\r |
105 | else\r |
106 | r = ¤tConfig.renderer;\r |
107 | *r += diff;\r |
f4750ee0 |
108 | \r |
5a681086 |
109 | if (*r >= RT_COUNT)\r |
110 | *r = 0;\r |
111 | else if (*r < 0)\r |
112 | *r = RT_COUNT - 1;\r |
113 | }\r |
114 | \r |
115 | #define is_16bit_mode() \\r |
466fa079 |
116 | (currentConfig.renderer == RT_16BIT || (PicoIn.AHW & PAHW_32X) || doing_bg_frame)\r |
5a681086 |
117 | \r |
cc41eb4f |
118 | static void (*osd_text)(int x, int y, const char *text);\r |
119 | \r |
120 | static void osd_text8(int x, int y, const char *text)\r |
cc68a136 |
121 | {\r |
122 | int len = strlen(text)*8;\r |
e2de9939 |
123 | int *p, i, h, offs;\r |
cc68a136 |
124 | \r |
cc41eb4f |
125 | len = (len+3) >> 2;\r |
126 | for (h = 0; h < 8; h++) {\r |
127 | offs = (x + g_screen_width * (y+h)) & ~3;\r |
128 | p = (int *) ((char *)g_screen_ptr + offs);\r |
129 | for (i = len; i; i--, p++)\r |
130 | *p = 0xe0e0e0e0;\r |
131 | }\r |
132 | emu_text_out8(x, y, text);\r |
133 | }\r |
134 | \r |
cc41eb4f |
135 | static void osd_text8_rot(int x, int y, const char *text)\r |
136 | {\r |
137 | int len = strlen(text) * 8;\r |
138 | char *p = (char *)g_screen_ptr + 240*(320-x) + y;\r |
139 | \r |
140 | while (len--) {\r |
141 | memset(p, 0xe0, 8);\r |
142 | p -= 240;\r |
cc68a136 |
143 | }\r |
cc41eb4f |
144 | \r |
145 | emu_text_out8_rot(x, y, text);\r |
146 | }\r |
147 | \r |
148 | static void osd_text16_rot(int x, int y, const char *text)\r |
149 | {\r |
150 | int len = strlen(text) * 8;\r |
151 | short *p = (short *)g_screen_ptr + 240*(320-x) + y;\r |
152 | \r |
153 | while (len--) {\r |
154 | memset(p, 0, 8*2);\r |
155 | p -= 240;\r |
156 | }\r |
157 | \r |
158 | emu_text_out16_rot(x, y, text);\r |
cc68a136 |
159 | }\r |
160 | \r |
213c16ad |
161 | static void draw_cd_leds(void)\r |
bf098bc5 |
162 | {\r |
cc41eb4f |
163 | int led_reg, pitch, scr_offs, led_offs;\r |
164 | led_reg = Pico_mcd->s68k_regs[0];\r |
165 | \r |
166 | if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r |
167 | pitch = 240;\r |
168 | led_offs = -pitch * 6;\r |
169 | scr_offs = pitch * (320 - 4);\r |
170 | } else {\r |
171 | pitch = 320;\r |
172 | led_offs = 4;\r |
173 | scr_offs = pitch * 2 + 4;\r |
174 | }\r |
bf098bc5 |
175 | \r |
5a681086 |
176 | if (!is_16bit_mode()) {\r |
cc41eb4f |
177 | #define p(x) px[(x) >> 2]\r |
bf098bc5 |
178 | // 8-bit modes\r |
cc41eb4f |
179 | unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);\r |
180 | unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r |
181 | unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r |
182 | p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;\r |
183 | p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;\r |
184 | #undef p\r |
bf098bc5 |
185 | } else {\r |
cc41eb4f |
186 | #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]\r |
bf098bc5 |
187 | // 16-bit modes\r |
cc41eb4f |
188 | unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);\r |
189 | unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;\r |
190 | unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;\r |
191 | p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;\r |
192 | p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;\r |
193 | #undef p\r |
bf098bc5 |
194 | }\r |
195 | }\r |
196 | \r |
213c16ad |
197 | static void draw_pico_ptr(void)\r |
198 | {\r |
c87e36d7 |
199 | int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;\r |
dca20eff |
200 | int x, y, pitch = 320, offs;\r |
15cc45c0 |
201 | // storyware pages are actually squished, 2:1\r |
202 | int h = (pico_inp_mode == 1 ? 160 : linecount);\r |
203 | if (h < 224) y++;\r |
213c16ad |
204 | \r |
c87e36d7 |
205 | x = ((pico_pen_x * colcount * ((1ULL<<32)/320 + 1)) >> 32) + firstcol;\r |
15cc45c0 |
206 | y = ((pico_pen_y * h * ((1ULL<<32)/224 + 1)) >> 32) + firstline;\r |
213c16ad |
207 | \r |
02da059d |
208 | if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r |
cc41eb4f |
209 | pitch = 240;\r |
dca20eff |
210 | offs = (319 - x) * pitch + y;\r |
cc41eb4f |
211 | } else\r |
dca20eff |
212 | offs = x + y * pitch;\r |
213 | \r |
214 | if (is_16bit_mode()) {\r |
215 | unsigned short *p = (unsigned short *)g_screen_ptr + offs;\r |
c87e36d7 |
216 | int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000);\r |
cc41eb4f |
217 | \r |
15cc45c0 |
218 | p[-pitch-1] ^= o; p[-pitch] ^= _; p[-pitch+1] ^= _; p[-pitch+2] ^= o;\r |
219 | p[-1] ^= _; p[0] ^= o; p[1] ^= o; p[2] ^= _;\r |
220 | p[pitch-1] ^= _; p[pitch] ^= o; p[pitch+1] ^= o; p[pitch+2] ^= _;\r |
221 | p[2*pitch-1]^= o; p[2*pitch]^= _; p[2*pitch+1]^= _; p[2*pitch+2]^= o;\r |
dca20eff |
222 | } else {\r |
223 | unsigned char *p = (unsigned char *)g_screen_ptr + offs;\r |
c87e36d7 |
224 | int o = (up ? 0xe0 : 0xf0), _ = (up ? 0xf0 : 0xe0);\r |
dca20eff |
225 | \r |
15cc45c0 |
226 | p[-pitch-1] = o; p[-pitch] = _; p[-pitch+1] = _; p[-pitch+2] = o;\r |
227 | p[-1] = _; p[0] = o; p[1] = o; p[2] = _;\r |
228 | p[pitch-1] = _; p[pitch] = o; p[pitch+1] = o; p[pitch+2] = _;\r |
229 | p[2*pitch-1]= o; p[2*pitch]= _; p[2*pitch+1]= _; p[2*pitch+2]= o;\r |
dca20eff |
230 | }\r |
213c16ad |
231 | }\r |
232 | \r |
96948bdf |
233 | static void clear_1st_column(int firstcol, int firstline, int linecount)\r |
234 | {\r |
235 | int size = is_16bit_mode() ? 2 : 1;\r |
236 | int black = is_16bit_mode() ? 0 : 0xe0;\r |
237 | int i;\r |
238 | \r |
239 | // SMS 1st column blanked, replace with black\r |
240 | if ((currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) && !doing_bg_frame) {\r |
241 | int pitch = 240*size;\r |
242 | char *p = (char *)g_screen_ptr + (319-(firstcol-8))*pitch;\r |
243 | for (i = 0; i < 8; i++, p -= pitch)\r |
244 | memset(p+(firstline)*size, black, linecount*size);\r |
245 | } else {\r |
246 | int pitch = 320*size;\r |
247 | char *p = (char *)g_screen_ptr + (firstline)*pitch;\r |
248 | for (i = 0; i < linecount; i++, p += pitch)\r |
249 | memset(p+(firstcol-8)*size, black, 8*size);\r |
250 | }\r |
251 | }\r |
252 | \r |
cc41eb4f |
253 | /* rot thing for Wiz */\r |
254 | static unsigned char __attribute__((aligned(4))) rot_buff[320*4*2];\r |
255 | \r |
256 | static int EmuScanBegin16_rot(unsigned int num)\r |
257 | {\r |
99bdfd31 |
258 | Pico.est.DrawLineDest = rot_buff + (num & 3) * 320 * 2;\r |
cc41eb4f |
259 | return 0;\r |
260 | }\r |
261 | \r |
262 | static int EmuScanEnd16_rot(unsigned int num)\r |
263 | {\r |
264 | if ((num & 3) != 3)\r |
265 | return 0;\r |
cc41eb4f |
266 | rotated_blit16(g_screen_ptr, rot_buff, num + 1,\r |
93f9619e |
267 | !(Pico.video.reg[12] & 1) && !(PicoIn.opt & POPT_EN_SOFTSCALE));\r |
cc41eb4f |
268 | return 0;\r |
269 | }\r |
270 | \r |
271 | static int EmuScanBegin8_rot(unsigned int num)\r |
272 | {\r |
99bdfd31 |
273 | Pico.est.DrawLineDest = rot_buff + (num & 3) * 320;\r |
cc41eb4f |
274 | return 0;\r |
275 | }\r |
276 | \r |
277 | static int EmuScanEnd8_rot(unsigned int num)\r |
278 | {\r |
279 | if ((num & 3) != 3)\r |
280 | return 0;\r |
cc41eb4f |
281 | rotated_blit8(g_screen_ptr, rot_buff, num + 1,\r |
96948bdf |
282 | !(Pico.video.reg[12] & 1) && !(PicoIn.opt & POPT_EN_SOFTSCALE));\r |
cc41eb4f |
283 | return 0;\r |
284 | }\r |
285 | \r |
f4750ee0 |
286 | /* line doublers */\r |
287 | static unsigned int ld_counter;\r |
466fa079 |
288 | static int ld_left, ld_lines; // numbers in Q1 format\r |
f4750ee0 |
289 | \r |
290 | static int EmuScanBegin16_ld(unsigned int num)\r |
291 | {\r |
495fe1fd |
292 | if ((signed int)(ld_counter - num) > 100) {\r |
293 | // vsync, offset so that the upscaled image is centered\r |
294 | ld_counter = 120 - (120-num) * (ld_lines+2)/ld_lines;\r |
295 | ld_left = ld_lines;\r |
296 | }\r |
f4750ee0 |
297 | \r |
298 | if (emu_scan_begin)\r |
299 | return emu_scan_begin(ld_counter);\r |
300 | else\r |
99bdfd31 |
301 | Pico.est.DrawLineDest = (char *)g_screen_ptr + 320 * ld_counter * gp2x_current_bpp / 8;\r |
f4750ee0 |
302 | \r |
303 | return 0;\r |
304 | }\r |
305 | \r |
306 | static int EmuScanEnd16_ld(unsigned int num)\r |
307 | {\r |
99bdfd31 |
308 | void *oldline = Pico.est.DrawLineDest;\r |
f4750ee0 |
309 | \r |
310 | if (emu_scan_end)\r |
311 | emu_scan_end(ld_counter);\r |
312 | \r |
313 | ld_counter++;\r |
466fa079 |
314 | ld_left -= 2;\r |
f4750ee0 |
315 | if (ld_left <= 0) {\r |
466fa079 |
316 | ld_left += ld_lines;\r |
f4750ee0 |
317 | \r |
318 | EmuScanBegin16_ld(num);\r |
fdcfd323 |
319 | memcpy(Pico.est.DrawLineDest, oldline, 320 * gp2x_current_bpp / 8);\r |
f4750ee0 |
320 | if (emu_scan_end)\r |
321 | emu_scan_end(ld_counter);\r |
322 | \r |
323 | ld_counter++;\r |
324 | }\r |
325 | \r |
326 | return 0;\r |
327 | }\r |
328 | \r |
19954be1 |
329 | static int localPal[0x100];\r |
b1a047c9 |
330 | static int localPalSize;\r |
331 | \r |
96948bdf |
332 | static void (*vidcpy8bit)(void *dest, void *src, int x_y, int w_h);\r |
19954be1 |
333 | static int (*make_local_pal)(int fast_mode);\r |
334 | \r |
335 | static int make_local_pal_md(int fast_mode)\r |
336 | {\r |
b1a047c9 |
337 | int pallen = 0x100;\r |
19954be1 |
338 | \r |
b1a047c9 |
339 | if (fast_mode) {\r |
ace18401 |
340 | bgr444_to_rgb32(localPal, PicoMem.cram, 64);\r |
b1a047c9 |
341 | pallen = 0x40;\r |
342 | Pico.m.dirtyPal = 0;\r |
19954be1 |
343 | }\r |
ea38612f |
344 | else if (Pico.est.rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r |
b1a047c9 |
345 | switch (Pico.est.SonicPalCount) {\r |
ace18401 |
346 | case 3: bgr444_to_rgb32(localPal+0xc0, Pico.est.SonicPal+0xc0, 64);\r |
347 | case 2: bgr444_to_rgb32(localPal+0x80, Pico.est.SonicPal+0x80, 64);\r |
348 | case 1: bgr444_to_rgb32(localPal+0x40, Pico.est.SonicPal+0x40, 64);\r |
349 | default:bgr444_to_rgb32(localPal, Pico.est.SonicPal, 64);\r |
b1a047c9 |
350 | }\r |
351 | pallen = (Pico.est.SonicPalCount+1)*0x40;\r |
19954be1 |
352 | }\r |
b1a047c9 |
353 | else if (Pico.video.reg[0xC] & 8) { // shadow/hilight mode\r |
ace18401 |
354 | bgr444_to_rgb32(localPal, Pico.est.SonicPal, 64);\r |
b1a047c9 |
355 | bgr444_to_rgb32_sh(localPal, Pico.est.SonicPal);\r |
466fa079 |
356 | memcpy(localPal+0xc0, localPal, 0x40*4); // for spr prio mess\r |
b1a047c9 |
357 | }\r |
358 | else {\r |
ace18401 |
359 | bgr444_to_rgb32(localPal, Pico.est.SonicPal, 64);\r |
b1a047c9 |
360 | memcpy(localPal+0x40, localPal, 0x40*4); // for spr prio mess\r |
361 | memcpy(localPal+0x80, localPal, 0x80*4); // for spr prio mess\r |
362 | }\r |
363 | localPal[0xc0] = 0x0000c000;\r |
364 | localPal[0xd0] = 0x00c00000;\r |
365 | localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r |
366 | localPal[0xf0] = 0x00ffffff;\r |
19954be1 |
367 | \r |
08626dab |
368 | if (Pico.m.dirtyPal == 2)\r |
b1a047c9 |
369 | Pico.m.dirtyPal = 0;\r |
19954be1 |
370 | return pallen;\r |
371 | }\r |
372 | \r |
373 | static int make_local_pal_sms(int fast_mode)\r |
374 | {\r |
ace18401 |
375 | static u16 tmspal[32] = {\r |
376 | // SMS palette for TMS modes\r |
377 | 0x0000, 0x0000, 0x00a0, 0x00f0, 0x0500, 0x0f00, 0x0005, 0x0ff0,\r |
378 | 0x000a, 0x000f, 0x0055, 0x00ff, 0x0050, 0x0f0f, 0x0555, 0x0fff,\r |
e5a1d4c5 |
379 | // TMS palette\r |
380 | 0x0000, 0x0000, 0x04c2, 0x07d6, 0x0e55, 0x0f77, 0x055c, 0x0ee4,\r |
381 | 0x055f, 0x077f, 0x05bc, 0x08ce, 0x03a2, 0x0b5c, 0x0ccc, 0x0fff,\r |
ace18401 |
382 | };\r |
383 | int i;\r |
384 | \r |
385 | if (!(Pico.video.reg[0] & 0x4)) {\r |
386 | for (i = Pico.est.SonicPalCount; i >= 0; i--) {\r |
e5a1d4c5 |
387 | int sg = !!(PicoIn.AHW & (PAHW_SG|PAHW_SC));\r |
388 | bgr444_to_rgb32(localPal+i*0x40, tmspal+sg*0x10, 32);\r |
ace18401 |
389 | memcpy(localPal+i*0x40+0x20, localPal+i*0x40, 0x20*4);\r |
390 | }\r |
96948bdf |
391 | } else if (fast_mode) {\r |
392 | for (i = 0;i >= 0; i--) {\r |
393 | bgr444_to_rgb32(localPal+i*0x40, PicoMem.cram+i*0x40, 32);\r |
394 | memcpy(localPal+i*0x40+0x20, localPal+i*0x40, 0x20*4);\r |
395 | }\r |
ace18401 |
396 | } else {\r |
397 | for (i = Pico.est.SonicPalCount; i >= 0; i--) {\r |
398 | bgr444_to_rgb32(localPal+i*0x40, Pico.est.SonicPal+i*0x40, 32);\r |
399 | memcpy(localPal+i*0x40+0x20, localPal+i*0x40, 0x20*4);\r |
400 | }\r |
401 | }\r |
402 | if (Pico.m.dirtyPal == 2)\r |
403 | Pico.m.dirtyPal = 0;\r |
404 | return (Pico.est.SonicPalCount+1)*0x40;\r |
19954be1 |
405 | }\r |
cc68a136 |
406 | \r |
d08e7326 |
407 | void pemu_finalize_frame(const char *fps, const char *notice)\r |
cc68a136 |
408 | {\r |
bf098bc5 |
409 | int emu_opt = currentConfig.EmuOpt;\r |
c05ec65e |
410 | int direct_rendered = 1;\r |
bf098bc5 |
411 | \r |
96948bdf |
412 | if (is_16bit_mode())\r |
b1a047c9 |
413 | localPalSize = 0; // nothing to do\r |
5a681086 |
414 | else if (get_renderer() == RT_8BIT_FAST)\r |
fad24893 |
415 | {\r |
cc68a136 |
416 | // 8bit fast renderer\r |
b1a047c9 |
417 | if (Pico.m.dirtyPal)\r |
418 | localPalSize = make_local_pal(1);\r |
fad24893 |
419 | // a hack for VR\r |
93f9619e |
420 | if (PicoIn.AHW & PAHW_SVP)\r |
35247900 |
421 | memset32((int *)(Pico.est.Draw2FB+328*8+328*223), 0xe0e0e0e0, 328/4);\r |
fad24893 |
422 | // do actual copy\r |
96948bdf |
423 | vidcpy8bit(g_screen_ptr, Pico.est.Draw2FB,\r |
424 | (firstcol << 16) | firstline, (colcount << 16) | linecount);\r |
c05ec65e |
425 | direct_rendered = 0;\r |
fad24893 |
426 | }\r |
5a681086 |
427 | else if (get_renderer() == RT_8BIT_ACC)\r |
fad24893 |
428 | {\r |
cc68a136 |
429 | // 8bit accurate renderer\r |
602133e1 |
430 | if (Pico.m.dirtyPal)\r |
b1a047c9 |
431 | localPalSize = make_local_pal(0);\r |
cc68a136 |
432 | }\r |
96948bdf |
433 | \r |
c05ec65e |
434 | // blank 1st column, only needed in modes directly rendering to screen\r |
435 | if (is_1stblanked && direct_rendered)\r |
96948bdf |
436 | clear_1st_column(firstcol, firstline, linecount);\r |
cc68a136 |
437 | \r |
f4750ee0 |
438 | if (notice)\r |
439 | osd_text(4, osd_y, notice);\r |
440 | if (emu_opt & EOPT_SHOW_FPS)\r |
441 | osd_text(osd_fps_x, osd_y, fps);\r |
93f9619e |
442 | if ((PicoIn.AHW & PAHW_MCD) && (emu_opt & EOPT_EN_CD_LEDS))\r |
213c16ad |
443 | draw_cd_leds();\r |
15cc45c0 |
444 | if (PicoIn.AHW & PAHW_PICO) {\r |
445 | int h = linecount, w = colcount;\r |
446 | u16 *pd = g_screen_ptr + firstline*g_screen_ppitch + firstcol;\r |
447 | \r |
448 | if (pico_inp_mode && is_16bit_mode())\r |
449 | emu_pico_overlay(pd, w, h, g_screen_ppitch);\r |
450 | if (pico_inp_mode /*== 2 || overlay*/)\r |
451 | draw_pico_ptr();\r |
452 | }\r |
bac44b18 |
453 | // draw virtual keyboard on display\r |
4814d19e |
454 | if (kbd_mode && currentConfig.keyboard == 1 && vkbd)\r |
bac44b18 |
455 | vkbd_draw(vkbd);\r |
d08e7326 |
456 | }\r |
cc68a136 |
457 | \r |
d08e7326 |
458 | void plat_video_flip(void)\r |
459 | {\r |
5a681086 |
460 | int stride = g_screen_width;\r |
cc68a136 |
461 | gp2x_video_flip();\r |
b1a047c9 |
462 | // switching the palette takes immediate effect, whilst flipping only\r |
463 | // takes effect with the next vsync; unavoidable flicker may occur!\r |
464 | if (localPalSize)\r |
465 | gp2x_video_setpalette(localPal, localPalSize);\r |
5a681086 |
466 | \r |
467 | if (is_16bit_mode())\r |
468 | stride *= 2;\r |
bdf7761e |
469 | // the fast renderer has overlap areas and can't directly render to\r |
470 | // screen buffers. Its output is copied to screen in finalize_frame\r |
9b2d466a |
471 | if (get_renderer() != RT_8BIT_FAST || (PicoIn.AHW & PAHW_32X))\r |
bdf7761e |
472 | PicoDrawSetOutBuf(g_screen_ptr, stride);\r |
cc68a136 |
473 | }\r |
474 | \r |
b24e0f6c |
475 | /* XXX */\r |
b24e0f6c |
476 | unsigned int plat_get_ticks_ms(void)\r |
477 | {\r |
478 | return gp2x_get_ticks_ms();\r |
479 | }\r |
480 | \r |
481 | unsigned int plat_get_ticks_us(void)\r |
482 | {\r |
483 | return gp2x_get_ticks_us();\r |
484 | }\r |
b24e0f6c |
485 | \r |
486 | void plat_wait_till_us(unsigned int us_to)\r |
487 | {\r |
488 | unsigned int now;\r |
489 | \r |
490 | spend_cycles(1024);\r |
491 | now = plat_get_ticks_us();\r |
492 | \r |
493 | while ((signed int)(us_to - now) > 512)\r |
494 | {\r |
495 | spend_cycles(1024);\r |
496 | now = plat_get_ticks_us();\r |
497 | }\r |
498 | }\r |
499 | \r |
500 | void plat_video_wait_vsync(void)\r |
501 | {\r |
502 | gp2x_video_wait_vsync();\r |
503 | }\r |
504 | \r |
505 | void plat_status_msg_clear(void)\r |
cc68a136 |
506 | {\r |
69b7b264 |
507 | int i, is_8bit = !is_16bit_mode();\r |
508 | \r |
509 | for (i = 0; i < 4; i++) {\r |
510 | if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r |
511 | /* ugh.. */\r |
512 | int u, *p;\r |
513 | if (is_8bit) {\r |
514 | p = (int *)gp2x_screens[i] + (240-8) / 4;\r |
515 | for (u = 320; u > 0; u--, p += 240/4)\r |
516 | p[0] = p[1] = 0xe0e0e0e0;\r |
517 | } else {\r |
518 | p = (int *)gp2x_screens[i] + (240-8)*2 / 4;\r |
519 | for (u = 320; u > 0; u--, p += 240*2/4)\r |
520 | p[0] = p[1] = p[2] = p[3] = 0;\r |
521 | }\r |
758abbeb |
522 | } else {\r |
69b7b264 |
523 | if (is_8bit) {\r |
524 | char *d = (char *)gp2x_screens[i] + 320 * (240-8);\r |
bdf7761e |
525 | memset32((int *)d, 0xe0e0e0e0, 320 * 8 / 4);\r |
69b7b264 |
526 | } else {\r |
527 | char *d = (char *)gp2x_screens[i] + 320*2 * (240-8);\r |
528 | memset32((int *)d, 0, 2*320 * 8 / 4);\r |
529 | }\r |
758abbeb |
530 | }\r |
cc41eb4f |
531 | }\r |
cc68a136 |
532 | }\r |
533 | \r |
d34a42f9 |
534 | void plat_status_msg_busy_next(const char *msg)\r |
535 | {\r |
b24e0f6c |
536 | plat_status_msg_clear();\r |
d08e7326 |
537 | pemu_finalize_frame("", msg);\r |
538 | plat_video_flip();\r |
7c34867a |
539 | emu_status_msg("");\r |
d34a42f9 |
540 | \r |
541 | /* assumption: msg_busy_next gets called only when\r |
542 | * something slow is about to happen */\r |
543 | reset_timing = 1;\r |
544 | }\r |
545 | \r |
546 | void plat_status_msg_busy_first(const char *msg)\r |
547 | {\r |
d34a42f9 |
548 | plat_status_msg_busy_next(msg);\r |
549 | }\r |
cc68a136 |
550 | \r |
95b08943 |
551 | void plat_status_msg_busy_done(void)\r |
552 | {\r |
553 | }\r |
554 | \r |
f4750ee0 |
555 | static void vid_reset_mode(void)\r |
cc68a136 |
556 | {\r |
5a681086 |
557 | int gp2x_mode = 16;\r |
558 | int renderer = get_renderer();\r |
559 | \r |
1bbe9abf |
560 | PicoIn.opt &= ~(POPT_ALT_RENDERER|POPT_DIS_32C_BORDER|POPT_EN_SOFTSCALE);\r |
561 | if (currentConfig.scaling == EOPT_SCALE_SW) {\r |
562 | PicoIn.opt |= POPT_EN_SOFTSCALE;\r |
563 | PicoIn.filter = EOPT_FILTER_BILINEAR2;\r |
564 | } else if (currentConfig.scaling == EOPT_SCALE_HW)\r |
565 | // hw scaling, render without any padding\r |
566 | PicoIn.opt |= POPT_DIS_32C_BORDER;\r |
cc41eb4f |
567 | \r |
5a681086 |
568 | switch (renderer) {\r |
569 | case RT_16BIT:\r |
5a681086 |
570 | PicoDrawSetOutFormat(PDF_RGB555, 0);\r |
571 | PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);\r |
5a681086 |
572 | break;\r |
573 | case RT_8BIT_ACC:\r |
5a681086 |
574 | PicoDrawSetOutFormat(PDF_8BIT, 0);\r |
575 | PicoDrawSetOutBuf(g_screen_ptr, g_screen_width);\r |
5a681086 |
576 | gp2x_mode = 8;\r |
577 | break;\r |
578 | case RT_8BIT_FAST:\r |
93f9619e |
579 | PicoIn.opt |= POPT_ALT_RENDERER;\r |
5a681086 |
580 | PicoDrawSetOutFormat(PDF_NONE, 0);\r |
96948bdf |
581 | vidcpy8bit = vidcpy_8bit;\r |
5a681086 |
582 | gp2x_mode = 8;\r |
583 | break;\r |
f4750ee0 |
584 | default:\r |
585 | printf("bad renderer\n");\r |
586 | break;\r |
bf098bc5 |
587 | }\r |
cc41eb4f |
588 | \r |
93f9619e |
589 | if (PicoIn.AHW & PAHW_32X) {\r |
5a681086 |
590 | // Wiz 16bit is an exception, uses line rendering due to rotation mess\r |
591 | if (renderer == RT_16BIT && (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX)) {\r |
592 | PicoDrawSetOutFormat(PDF_RGB555, 1);\r |
5a681086 |
593 | }\r |
5a681086 |
594 | PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);\r |
45285368 |
595 | gp2x_mode = 16;\r |
5a681086 |
596 | }\r |
597 | \r |
1bbe9abf |
598 | emu_scan_begin = NULL;\r |
599 | emu_scan_end = NULL;\r |
600 | \r |
f4750ee0 |
601 | if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r |
93f9619e |
602 | if ((PicoIn.AHW & PAHW_32X) || renderer == RT_16BIT) {\r |
f4750ee0 |
603 | emu_scan_begin = EmuScanBegin16_rot;\r |
604 | emu_scan_end = EmuScanEnd16_rot;\r |
96948bdf |
605 | memset(rot_buff, 0, 320*4*2);\r |
f4750ee0 |
606 | }\r |
607 | else if (renderer == RT_8BIT_ACC) {\r |
608 | emu_scan_begin = EmuScanBegin8_rot;\r |
609 | emu_scan_end = EmuScanEnd8_rot;\r |
96948bdf |
610 | memset(rot_buff, 0xe0, 320*4);\r |
f4750ee0 |
611 | }\r |
612 | else if (renderer == RT_8BIT_FAST)\r |
96948bdf |
613 | vidcpy8bit = vidcpy_8bit_rot;\r |
f4750ee0 |
614 | }\r |
615 | \r |
616 | PicoDrawSetCallbacks(emu_scan_begin, emu_scan_end);\r |
617 | \r |
618 | if (is_16bit_mode())\r |
f7e40c9b |
619 | osd_text = (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) ? osd_text16_rot : emu_osd_text16;\r |
f4750ee0 |
620 | else\r |
621 | osd_text = (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) ? osd_text8_rot : osd_text8;\r |
622 | \r |
f4750ee0 |
623 | gp2x_video_wait_vsync();\r |
5a681086 |
624 | if (!is_16bit_mode()) {\r |
bf098bc5 |
625 | // setup pal for 8-bit modes\r |
626 | localPal[0xc0] = 0x0000c000; // MCD LEDs\r |
627 | localPal[0xd0] = 0x00c00000;\r |
cc68a136 |
628 | localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r |
629 | localPal[0xf0] = 0x00ffffff;\r |
cc68a136 |
630 | gp2x_video_setpalette(localPal, 0x100);\r |
cc68a136 |
631 | }\r |
f4750ee0 |
632 | \r |
45285368 |
633 | if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX)\r |
634 | gp2x_mode = -gp2x_mode;\r |
635 | \r |
31f944ea |
636 | gp2x_video_changemode(gp2x_mode, Pico.m.pal);\r |
45285368 |
637 | \r |
ebd9c86a |
638 | // clear whole screen in all buffers\r |
639 | if (!is_16bit_mode())\r |
640 | gp2x_memset_all_buffers(0, 0xe0, 320*240);\r |
641 | else\r |
642 | gp2x_memset_all_buffers(0, 0, 320*240*2);\r |
643 | \r |
cc68a136 |
644 | Pico.m.dirtyPal = 1;\r |
cc41eb4f |
645 | \r |
19954be1 |
646 | // palette converters for 8bit modes\r |
93f9619e |
647 | make_local_pal = (PicoIn.AHW & PAHW_SMS) ? make_local_pal_sms : make_local_pal_md;\r |
cc68a136 |
648 | }\r |
649 | \r |
d5d17782 |
650 | void emu_video_mode_change(int start_line, int line_count, int start_col, int col_count)\r |
f4750ee0 |
651 | {\r |
652 | int scalex = 320, scaley = 240;\r |
653 | int ln_offs = 0;\r |
654 | \r |
96948bdf |
655 | if (currentConfig.vscaling != EOPT_SCALE_NONE &&\r |
656 | (is_16bit_mode() || get_renderer() != RT_8BIT_FAST)) {\r |
657 | /* NTSC always has 224 visible lines, anything smaller has bars */\r |
658 | if (line_count < 224 && line_count > 144) {\r |
659 | start_line -= (224-line_count) /2;\r |
660 | line_count = 224;\r |
661 | }\r |
495fe1fd |
662 | \r |
96948bdf |
663 | /* line doubling for swscaling, also needed for bg frames */\r |
664 | if (currentConfig.vscaling == EOPT_SCALE_SW && line_count < 240) {\r |
665 | ld_lines = ld_left = 2*line_count / (240 - line_count);\r |
666 | PicoDrawSetCallbacks(EmuScanBegin16_ld,EmuScanEnd16_ld);\r |
667 | }\r |
466fa079 |
668 | }\r |
669 | \r |
96948bdf |
670 | /* blanking for SMS with 1st tile blanked */\r |
671 | is_1stblanked = (col_count == 248);\r |
672 | firstline = start_line; linecount = line_count;\r |
673 | firstcol = start_col; colcount = col_count;\r |
674 | \r |
f4750ee0 |
675 | if (doing_bg_frame)\r |
676 | return;\r |
677 | \r |
678 | osd_fps_x = OSD_FPS_X;\r |
679 | osd_y = 232;\r |
680 | \r |
681 | /* set up hwscaling here */\r |
d5d17782 |
682 | if (col_count < 320 && currentConfig.scaling == EOPT_SCALE_HW) {\r |
683 | scalex = col_count;\r |
d5d17782 |
684 | osd_fps_x = col_count - (320-OSD_FPS_X);\r |
f4750ee0 |
685 | }\r |
686 | \r |
687 | if (currentConfig.vscaling == EOPT_SCALE_HW) {\r |
688 | ln_offs = start_line;\r |
689 | scaley = line_count;\r |
690 | osd_y = start_line + line_count - 8;\r |
691 | }\r |
692 | \r |
693 | gp2x_video_RGB_setscaling(ln_offs, scalex, scaley);\r |
694 | \r |
f4750ee0 |
695 | // clear whole screen in all buffers\r |
696 | if (!is_16bit_mode())\r |
697 | gp2x_memset_all_buffers(0, 0xe0, 320*240);\r |
698 | else\r |
699 | gp2x_memset_all_buffers(0, 0, 320*240*2);\r |
700 | }\r |
701 | \r |
bac44b18 |
702 | void plat_video_clear_buffers(void)\r |
703 | {\r |
704 | if (!is_16bit_mode())\r |
705 | gp2x_memset_all_buffers(0, 0xe0, 320*240);\r |
706 | else\r |
707 | gp2x_memset_all_buffers(0, 0, 320*240*2);\r |
708 | }\r |
709 | \r |
5a681086 |
710 | void plat_video_toggle_renderer(int change, int is_menu_call)\r |
66fdc0f0 |
711 | {\r |
5a681086 |
712 | change_renderer(change);\r |
d90f5bd7 |
713 | \r |
5a681086 |
714 | if (is_menu_call)\r |
d90f5bd7 |
715 | return;\r |
7a1f6e45 |
716 | \r |
f4750ee0 |
717 | vid_reset_mode();\r |
19954be1 |
718 | rendstatus_old = -1;\r |
66fdc0f0 |
719 | \r |
93f9619e |
720 | if (PicoIn.AHW & PAHW_32X)\r |
5a681086 |
721 | emu_status_msg(renderer_names32x[get_renderer()]);\r |
722 | else\r |
723 | emu_status_msg(renderer_names[get_renderer()]);\r |
fa1e5e29 |
724 | }\r |
725 | \r |
f2cf8472 |
726 | #if 0 // TODO\r |
991473ad |
727 | static void RunEventsPico(unsigned int events)\r |
406c96c5 |
728 | {\r |
f0f0d2df |
729 | int ret, px, py, lim_x;\r |
85a4b5a4 |
730 | static int pdown_frames = 0;\r |
731 | \r |
85a4b5a4 |
732 | // for F200\r |
733 | ret = gp2x_touchpad_read(&px, &py);\r |
f0f0d2df |
734 | if (ret >= 0)\r |
735 | {\r |
736 | if (ret > 35000)\r |
737 | {\r |
85a4b5a4 |
738 | if (pdown_frames++ > 5)\r |
93f9619e |
739 | PicoIn.pad[0] |= 0x20;\r |
85a4b5a4 |
740 | \r |
741 | pico_pen_x = px;\r |
742 | pico_pen_y = py;\r |
743 | if (!(Pico.video.reg[12]&1)) {\r |
744 | pico_pen_x -= 32;\r |
745 | if (pico_pen_x < 0) pico_pen_x = 0;\r |
746 | if (pico_pen_x > 248) pico_pen_x = 248;\r |
747 | }\r |
748 | if (pico_pen_y > 224) pico_pen_y = 224;\r |
749 | }\r |
750 | else\r |
f0f0d2df |
751 | pdown_frames = 0;\r |
85a4b5a4 |
752 | \r |
753 | //if (ret == 0)\r |
754 | // PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r |
755 | }\r |
406c96c5 |
756 | }\r |
f2cf8472 |
757 | #endif\r |
406c96c5 |
758 | \r |
d34a42f9 |
759 | void plat_update_volume(int has_changed, int is_up)\r |
4a32f01f |
760 | {\r |
761 | static int prev_frame = 0, wait_frames = 0;\r |
d34a42f9 |
762 | int need_low_volume = 0;\r |
75a30842 |
763 | int vol = currentConfig.volume;\r |
d34a42f9 |
764 | gp2x_soc_t soc;\r |
765 | \r |
766 | soc = soc_detect();\r |
93f9619e |
767 | if ((PicoIn.opt & POPT_EN_STEREO) && soc == SOCID_MMSP2)\r |
d34a42f9 |
768 | need_low_volume = 1;\r |
4a32f01f |
769 | \r |
770 | if (has_changed)\r |
771 | {\r |
d34a42f9 |
772 | if (need_low_volume && vol < 5 && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)\r |
4a32f01f |
773 | wait_frames++;\r |
774 | else {\r |
4a32f01f |
775 | wait_frames = 0;\r |
75a30842 |
776 | plat_target_step_volume(¤tConfig.volume, is_up ? 1 : -1);\r |
777 | vol = currentConfig.volume;\r |
4a32f01f |
778 | }\r |
b24e0f6c |
779 | emu_status_msg("VOL: %02i", vol);\r |
4a32f01f |
780 | prev_frame = Pico.m.frame_count;\r |
781 | }\r |
782 | \r |
54646a39 |
783 | if (!need_low_volume)\r |
d34a42f9 |
784 | return;\r |
785 | \r |
786 | /* set the right mixer func */\r |
4a32f01f |
787 | if (vol >= 5)\r |
70efc52d |
788 | PsndMix_32_to_16 = mix_32_to_16_stereo;\r |
4a32f01f |
789 | else {\r |
70efc52d |
790 | mix_32_to_16_level = 5 - vol;\r |
791 | PsndMix_32_to_16 = mix_32_to_16_stereo_lvl;\r |
4a32f01f |
792 | }\r |
793 | }\r |
794 | \r |
75a30842 |
795 | void pemu_sound_start(void)\r |
cc68a136 |
796 | {\r |
31f944ea |
797 | gp2x_soc_t soc;\r |
7b3f44c6 |
798 | \r |
31f944ea |
799 | emu_sound_start();\r |
7b3f44c6 |
800 | \r |
7c34867a |
801 | if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r |
7b3f44c6 |
802 | {\r |
b08ccf71 |
803 | soc = soc_detect();\r |
31f944ea |
804 | if (soc == SOCID_POLLUX) {\r |
6311a3ba |
805 | PicoIn.sndRate = pollux_get_real_snd_rate(PicoIn.sndRate);\r |
7b3f44c6 |
806 | PsndRerate(Pico.m.frame_count ? 1 : 0);\r |
807 | }\r |
b08ccf71 |
808 | \r |
31f944ea |
809 | plat_target_step_volume(¤tConfig.volume, 0);\r |
7b3f44c6 |
810 | }\r |
811 | }\r |
812 | \r |
089f516d |
813 | static const int sound_rates[] = { 52000, 44100, 32000, 22050, 16000, 11025, 8000 };\r |
9f6a4e90 |
814 | \r |
f2cf8472 |
815 | void pemu_sound_stop(void)\r |
7b3f44c6 |
816 | {\r |
9f6a4e90 |
817 | int i;\r |
818 | \r |
819 | /* get back from Pollux pain */\r |
6311a3ba |
820 | PicoIn.sndRate += 1000;\r |
9f6a4e90 |
821 | for (i = 0; i < ARRAY_SIZE(sound_rates); i++) {\r |
6311a3ba |
822 | if (PicoIn.sndRate >= sound_rates[i]) {\r |
823 | PicoIn.sndRate = sound_rates[i];\r |
9f6a4e90 |
824 | break;\r |
825 | }\r |
02da059d |
826 | }\r |
7b3f44c6 |
827 | }\r |
828 | \r |
45285368 |
829 | void pemu_forced_frame(int no_scale, int do_emu)\r |
860c6322 |
830 | {\r |
a4edca53 |
831 | doing_bg_frame = 1;\r |
f4750ee0 |
832 | PicoDrawSetCallbacks(NULL, NULL);\r |
a12e0116 |
833 | Pico.m.dirtyPal = 1;\r |
466fa079 |
834 | PicoIn.opt &= ~POPT_DIS_32C_BORDER;\r |
835 | gp2x_current_bpp = 16;\r |
96948bdf |
836 | // always render in screen 3 since menu uses 0-2\r |
837 | g_screen_ptr = gp2x_screens[3];\r |
860c6322 |
838 | \r |
b1a047c9 |
839 | if (!no_scale)\r |
840 | no_scale = currentConfig.scaling == EOPT_SCALE_NONE;\r |
832faed3 |
841 | emu_cmn_forced_frame(no_scale, do_emu, g_screen_ptr);\r |
f4750ee0 |
842 | \r |
96948bdf |
843 | if (is_1stblanked)\r |
844 | clear_1st_column(firstcol, firstline, linecount);\r |
845 | \r |
45285368 |
846 | g_menubg_src_ptr = g_screen_ptr;\r |
a4edca53 |
847 | doing_bg_frame = 0;\r |
860c6322 |
848 | }\r |
849 | \r |
f2cf8472 |
850 | void plat_debug_cat(char *str)\r |
fcf94fcc |
851 | {\r |
fcf94fcc |
852 | }\r |
853 | \r |
75a30842 |
854 | void plat_video_loop_prepare(void) \r |
da310283 |
855 | {\r |
75a30842 |
856 | // make sure we are in correct mode\r |
857 | change_renderer(0);\r |
858 | vid_reset_mode();\r |
466fa079 |
859 | rendstatus_old = -1;\r |
da310283 |
860 | }\r |
da310283 |
861 | \r |
b24e0f6c |
862 | void pemu_loop_prep(void)\r |
cc68a136 |
863 | {\r |
45285368 |
864 | if (gp2x_dev_id == GP2X_DEV_CAANOO)\r |
75a30842 |
865 | in_set_config_int(in_name_to_id("evdev:pollux-analog"),\r |
866 | IN_CFG_ABS_DEAD_ZONE,\r |
867 | currentConfig.analog_deadzone);\r |
cc68a136 |
868 | \r |
c7eb229a |
869 | // dirty buffers better go now than during gameplay\r |
870 | sync();\r |
871 | sleep(0);\r |
b24e0f6c |
872 | }\r |
cc68a136 |
873 | \r |
b24e0f6c |
874 | void pemu_loop_end(void)\r |
875 | {\r |
02da059d |
876 | pemu_sound_stop();\r |
877 | \r |
96948bdf |
878 | if (g_screen_ptr == gp2x_screens[0]) {\r |
879 | /* currently on screen 3, which is needed for forced_frame */\r |
880 | int size = gp2x_current_bpp / 8;\r |
881 | gp2x_memcpy_all_buffers(g_screen_ptr, 0, 320*240 * size);\r |
882 | gp2x_video_flip();\r |
883 | }\r |
730259b7 |
884 | /* do one more frame for menu bg */\r |
45285368 |
885 | pemu_forced_frame(0, 1);\r |
cc68a136 |
886 | }\r |
887 | \r |