1 // (c) Copyright 2006-2009 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
9 #include "plat_gp2x.h"
\r
11 #include "../common/plat.h"
\r
12 #include "../common/menu.h"
\r
13 #include "../common/arm_utils.h"
\r
14 #include "../common/fonts.h"
\r
15 #include "../common/emu.h"
\r
16 #include "../common/config.h"
\r
17 #include "../linux/sndout_oss.h"
\r
18 #include "version.h"
\r
20 #include <pico/pico_int.h>
\r
21 #include <pico/patch.h>
\r
22 #include <pico/sound/mix.h>
\r
23 #include <zlib/zlib.h>
\r
28 #define OSD_FPS_X 220
\r
30 #define OSD_FPS_X 260
\r
34 extern int crashed_940;
\r
36 static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50];
\r
37 static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)];
\r
38 unsigned char *PicoDraw2FB = PicoDraw2FB_;
\r
39 static int osd_fps_x, osd_y;
\r
41 extern void *gp2x_screens[4];
\r
43 int plat_get_root_dir(char *dst, int len)
\r
45 extern char **g_argv;
\r
48 strncpy(dst, g_argv[0], len);
\r
49 len -= 32; // reserve
\r
50 if (len < 0) len = 0;
\r
52 for (j = strlen(dst); j > 0; j--)
\r
53 if (dst[j] == '/') { dst[j+1] = 0; break; }
\r
59 static void scaling_update(void)
\r
61 PicoOpt &= ~(POPT_DIS_32C_BORDER|POPT_EN_SOFTSCALE);
\r
62 switch (currentConfig.scaling) {
\r
64 case EOPT_SCALE_HW_H:
\r
65 case EOPT_SCALE_HW_HV:
\r
66 PicoOpt |= POPT_DIS_32C_BORDER;
\r
68 case EOPT_SCALE_SW_H:
\r
69 PicoOpt |= POPT_EN_SOFTSCALE;
\r
75 void pemu_prep_defconfig(void)
\r
79 memset(&defaultConfig, 0, sizeof(defaultConfig));
\r
80 defaultConfig.EmuOpt = 0x9d | EOPT_RAM_TIMINGS|EOPT_CONFIRM_SAVE|EOPT_EN_CD_LEDS;
\r
81 defaultConfig.s_PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 |
\r
82 POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC|POPT_ACC_SPRITES |
\r
83 POPT_EN_32X|POPT_EN_PWM;
\r
84 defaultConfig.s_PsndRate = 44100;
\r
85 defaultConfig.s_PicoRegion = 0; // auto
\r
86 defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP
\r
87 defaultConfig.s_PicoCDBuffers = 0;
\r
88 defaultConfig.Frameskip = -1; // auto
\r
89 defaultConfig.CPUclock = default_cpu_clock;
\r
90 defaultConfig.volume = 50;
\r
91 defaultConfig.gamma = 100;
\r
92 defaultConfig.scaling = 0;
\r
93 defaultConfig.turbo_rate = 15;
\r
96 if (soc == SOCID_MMSP2)
\r
97 defaultConfig.s_PicoOpt |= POPT_EXT_FM;
\r
98 else if (soc == SOCID_POLLUX)
\r
99 defaultConfig.EmuOpt |= EOPT_WIZ_TEAR_FIX|EOPT_SHOW_RTC;
\r
102 static void (*osd_text)(int x, int y, const char *text);
\r
104 static void osd_text8(int x, int y, const char *text)
\r
106 int len = strlen(text)*8;
\r
107 int *p, i, h, offs;
\r
109 len = (len+3) >> 2;
\r
110 for (h = 0; h < 8; h++) {
\r
111 offs = (x + g_screen_width * (y+h)) & ~3;
\r
112 p = (int *) ((char *)g_screen_ptr + offs);
\r
113 for (i = len; i; i--, p++)
\r
116 emu_text_out8(x, y, text);
\r
119 static void osd_text16(int x, int y, const char *text)
\r
121 int len = strlen(text)*8;
\r
122 int *p, i, h, offs;
\r
124 len = (len+1) >> 1;
\r
125 for (h = 0; h < 8; h++) {
\r
126 offs = (x + g_screen_width * (y+h)) & ~1;
\r
127 p = (int *) ((short *)g_screen_ptr + offs);
\r
128 for (i = len; i; i--, p++)
\r
129 *p = (*p >> 2) & 0x39e7;
\r
131 emu_text_out16(x, y, text);
\r
134 static void osd_text8_rot(int x, int y, const char *text)
\r
136 int len = strlen(text) * 8;
\r
137 char *p = (char *)g_screen_ptr + 240*(320-x) + y;
\r
140 memset(p, 0xe0, 8);
\r
144 emu_text_out8_rot(x, y, text);
\r
147 static void osd_text16_rot(int x, int y, const char *text)
\r
149 int len = strlen(text) * 8;
\r
150 short *p = (short *)g_screen_ptr + 240*(320-x) + y;
\r
157 emu_text_out16_rot(x, y, text);
\r
160 static void draw_cd_leds(void)
\r
162 int led_reg, pitch, scr_offs, led_offs;
\r
163 led_reg = Pico_mcd->s68k_regs[0];
\r
165 if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
\r
167 led_offs = -pitch * 6;
\r
168 scr_offs = pitch * (320 - 4);
\r
172 scr_offs = pitch * 2 + 4;
\r
175 if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) {
\r
176 #define p(x) px[(x) >> 2]
\r
178 unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);
\r
179 unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
\r
180 unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
\r
181 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
182 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
185 #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]
\r
187 unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);
\r
188 unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;
\r
189 unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;
\r
190 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
191 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
196 static void draw_pico_ptr(void)
\r
198 unsigned short *p = (unsigned short *)g_screen_ptr;
\r
199 int x, y, pitch = 320;
\r
201 // only if pen enabled and for 16bit modes
\r
202 if (pico_inp_mode == 0 || (PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP))
\r
205 x = pico_pen_x + PICO_PEN_ADJUST_X;
\r
206 y = pico_pen_y + PICO_PEN_ADJUST_Y;
\r
207 if (!(Pico.video.reg[12]&1) && !(PicoOpt & POPT_DIS_32C_BORDER))
\r
210 if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
\r
212 p += (319 - x) * pitch + y;
\r
214 p += x + y * pitch;
\r
217 p[pitch-1] ^= 0xffff;
\r
218 p[pitch] ^= 0xffff;
\r
219 p[pitch+1] ^= 0xffff;
\r
220 p[pitch*2] ^= 0xffff;
\r
223 static int EmuScanBegin16(unsigned int num)
\r
225 DrawLineDest = (unsigned short *) g_screen_ptr + g_screen_width * num;
\r
230 static int EmuScanBegin8(unsigned int num)
\r
232 DrawLineDest = (unsigned char *) g_screen_ptr + g_screen_width * num;
\r
237 /* rot thing for Wiz */
\r
238 static unsigned char __attribute__((aligned(4))) rot_buff[320*4*2];
\r
240 static int EmuScanBegin16_rot(unsigned int num)
\r
242 DrawLineDest = rot_buff + (num & 3) * 320 * 2;
\r
246 static int EmuScanEnd16_rot(unsigned int num)
\r
248 if ((num & 3) != 3)
\r
250 rotated_blit16(g_screen_ptr, rot_buff, num + 1,
\r
251 !(Pico.video.reg[12] & 1) && !(PicoOpt & POPT_EN_SOFTSCALE));
\r
255 static int EmuScanBegin8_rot(unsigned int num)
\r
257 DrawLineDest = rot_buff + (num & 3) * 320;
\r
261 static int EmuScanEnd8_rot(unsigned int num)
\r
263 if ((num & 3) != 3)
\r
265 rotated_blit8(g_screen_ptr, rot_buff, num + 1,
\r
266 !(Pico.video.reg[12] & 1));
\r
270 static int localPal[0x100];
\r
271 static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border);
\r
272 static int (*make_local_pal)(int fast_mode);
\r
274 static int make_local_pal_md(int fast_mode)
\r
278 bgr444_to_rgb32(localPal, Pico.cram);
\r
282 if (Pico.video.reg[0xC] & 8) { // shadow/hilight mode
\r
283 bgr444_to_rgb32_sh(localPal, Pico.cram);
\r
284 localPal[0xc0] = 0x0000c000;
\r
285 localPal[0xd0] = 0x00c00000;
\r
286 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
287 localPal[0xf0] = 0x00ffffff;
\r
290 else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes
\r
291 bgr444_to_rgb32(localPal+0x40, HighPal);
\r
292 bgr444_to_rgb32(localPal+0x80, HighPal+0x40);
\r
295 memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess
\r
300 static int make_local_pal_sms(int fast_mode)
\r
302 unsigned short *spal = Pico.cram;
\r
303 unsigned int *dpal = (void *)localPal;
\r
306 for (i = 0x40; i > 0; i--) {
\r
308 t = ((t & 0x0003) << 22) | ((t & 0x000c) << 12) | ((t & 0x0030) << 2);
\r
317 void pemu_update_display(const char *fps, const char *notice)
\r
319 int emu_opt = currentConfig.EmuOpt;
\r
322 if (PicoOpt & POPT_ALT_RENDERER)
\r
324 // 8bit fast renderer
\r
325 if (Pico.m.dirtyPal) {
\r
326 Pico.m.dirtyPal = 0;
\r
327 ret = make_local_pal(1);
\r
328 // feed new palette to our device
\r
329 gp2x_video_setpalette(localPal, ret);
\r
332 if (PicoAHW & PAHW_SVP)
\r
333 memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);
\r
335 vidcpyM2(g_screen_ptr, PicoDraw2FB+328*8,
\r
336 !(Pico.video.reg[12] & 1), !(PicoOpt & POPT_DIS_32C_BORDER));
\r
338 else if (!(emu_opt & EOPT_16BPP))
\r
340 // 8bit accurate renderer
\r
341 if (Pico.m.dirtyPal)
\r
343 Pico.m.dirtyPal = 0;
\r
344 ret = make_local_pal(0);
\r
345 gp2x_video_setpalette(localPal, ret);
\r
349 if (notice || (emu_opt & 2)) {
\r
351 osd_text(4, osd_y, notice);
\r
353 osd_text(osd_fps_x, osd_y, fps);
\r
355 if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))
\r
357 if (PicoAHW & PAHW_PICO)
\r
365 unsigned int plat_get_ticks_ms(void)
\r
367 return gp2x_get_ticks_ms();
\r
370 unsigned int plat_get_ticks_us(void)
\r
372 return gp2x_get_ticks_us();
\r
376 void plat_wait_till_us(unsigned int us_to)
\r
380 spend_cycles(1024);
\r
381 now = plat_get_ticks_us();
\r
383 while ((signed int)(us_to - now) > 512)
\r
385 spend_cycles(1024);
\r
386 now = plat_get_ticks_us();
\r
390 void plat_video_wait_vsync(void)
\r
392 gp2x_video_wait_vsync();
\r
395 void plat_status_msg_clear(void)
\r
397 int is_8bit = (PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP);
\r
398 if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
\r
402 for (i = 0; i < 4; i++) {
\r
403 p = (int *)gp2x_screens[i] + (240-8) / 4;
\r
404 for (u = 320; u > 0; u--, p += 240/4)
\r
405 p[0] = p[1] = 0xe0e0e0e0;
\r
408 for (i = 0; i < 4; i++) {
\r
409 p = (int *)gp2x_screens[i] + (240-8)*2 / 4;
\r
410 for (u = 320; u > 0; u--, p += 240*2/4)
\r
411 p[0] = p[1] = p[2] = p[3] = 0;
\r
418 gp2x_memset_all_buffers(320*232, 0xe0, 320*8);
\r
420 gp2x_memset_all_buffers(320*232*2, 0, 320*8*2);
\r
423 void plat_status_msg_busy_next(const char *msg)
\r
425 plat_status_msg_clear();
\r
426 pemu_update_display("", msg);
\r
427 emu_status_msg("");
\r
429 /* assumption: msg_busy_next gets called only when
\r
430 * something slow is about to happen */
\r
434 void plat_status_msg_busy_first(const char *msg)
\r
436 gp2x_memcpy_all_buffers(g_screen_ptr, 0, 320*240*2);
\r
437 plat_status_msg_busy_next(msg);
\r
440 static void vidResetMode(void)
\r
442 PicoScanEnd = NULL;
\r
444 if (PicoOpt & POPT_ALT_RENDERER) {
\r
445 if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
\r
446 gp2x_video_changemode(-8);
\r
447 vidcpyM2 = vidcpy_m2_rot;
\r
448 osd_text = osd_text8_rot;
\r
450 gp2x_video_changemode(8);
\r
451 vidcpyM2 = vidcpy_m2;
\r
452 osd_text = osd_text8;
\r
455 else if (currentConfig.EmuOpt & EOPT_16BPP) {
\r
456 PicoDrawSetColorFormat(1);
\r
457 if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
\r
458 gp2x_video_changemode(-16);
\r
459 PicoScanBegin = EmuScanBegin16_rot;
\r
460 PicoScanEnd = EmuScanEnd16_rot;
\r
461 osd_text = osd_text16_rot;
\r
463 gp2x_video_changemode(16);
\r
464 PicoScanBegin = EmuScanBegin16;
\r
465 osd_text = osd_text16;
\r
469 PicoDrawSetColorFormat(2);
\r
470 if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
\r
471 gp2x_video_changemode(-8);
\r
472 PicoScanBegin = EmuScanBegin8_rot;
\r
473 PicoScanEnd = EmuScanEnd8_rot;
\r
474 osd_text = osd_text8_rot;
\r
476 gp2x_video_changemode(8);
\r
477 PicoScanBegin = EmuScanBegin8;
\r
478 osd_text = osd_text8;
\r
482 if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) {
\r
483 // setup pal for 8-bit modes
\r
484 localPal[0xc0] = 0x0000c000; // MCD LEDs
\r
485 localPal[0xd0] = 0x00c00000;
\r
486 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
487 localPal[0xf0] = 0x00ffffff;
\r
488 gp2x_video_setpalette(localPal, 0x100);
\r
489 gp2x_memset_all_buffers(0, 0xe0, 320*240);
\r
492 Pico.m.dirtyPal = 1;
\r
495 if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8))
\r
496 gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224);
\r
497 else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);
\r
499 // palette converters for 8bit modes
\r
500 make_local_pal = (PicoAHW & PAHW_SMS) ? make_local_pal_sms : make_local_pal_md;
\r
503 void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu)
\r
506 PicoOpt &= ~POPT_ALT_RENDERER;
\r
507 currentConfig.EmuOpt |= EOPT_16BPP;
\r
509 /* alt, 16bpp, 8bpp */
\r
510 else if (PicoOpt & POPT_ALT_RENDERER) {
\r
511 PicoOpt &= ~POPT_ALT_RENDERER;
\r
513 currentConfig.EmuOpt |= EOPT_16BPP;
\r
514 } else if (!(currentConfig.EmuOpt & EOPT_16BPP)) {
\r
516 PicoOpt |= POPT_ALT_RENDERER;
\r
518 currentConfig.EmuOpt |= EOPT_16BPP;
\r
520 currentConfig.EmuOpt &= ~EOPT_16BPP;
\r
522 PicoOpt |= POPT_ALT_RENDERER;
\r
529 rendstatus_old = -1;
\r
531 if (PicoOpt & POPT_ALT_RENDERER) {
\r
532 emu_status_msg(" 8bit fast renderer");
\r
533 } else if (currentConfig.EmuOpt & EOPT_16BPP) {
\r
534 emu_status_msg("16bit accurate renderer");
\r
536 emu_status_msg(" 8bit accurate renderer");
\r
541 static void RunEventsPico(unsigned int events)
\r
543 int ret, px, py, lim_x;
\r
544 static int pdown_frames = 0;
\r
547 ret = gp2x_touchpad_read(&px, &py);
\r
552 if (pdown_frames++ > 5)
\r
553 PicoPad[0] |= 0x20;
\r
557 if (!(Pico.video.reg[12]&1)) {
\r
559 if (pico_pen_x < 0) pico_pen_x = 0;
\r
560 if (pico_pen_x > 248) pico_pen_x = 248;
\r
562 if (pico_pen_y > 224) pico_pen_y = 224;
\r
568 // PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;
\r
573 void plat_update_volume(int has_changed, int is_up)
\r
575 static int prev_frame = 0, wait_frames = 0;
\r
576 int vol = currentConfig.volume;
\r
577 int need_low_volume = 0;
\r
580 soc = soc_detect();
\r
581 if ((PicoOpt & POPT_EN_STEREO) && soc == SOCID_MMSP2)
\r
582 need_low_volume = 1;
\r
586 if (need_low_volume && vol < 5 && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)
\r
590 if (vol < 99) vol++;
\r
592 if (vol > 0) vol--;
\r
595 sndout_oss_setvol(vol, vol);
\r
596 currentConfig.volume = vol;
\r
598 emu_status_msg("VOL: %02i", vol);
\r
599 prev_frame = Pico.m.frame_count;
\r
602 if (!need_low_volume)
\r
605 /* set the right mixer func */
\r
607 PsndMix_32_to_16l = mix_32_to_16l_stereo;
\r
609 mix_32_to_16l_level = 5 - vol;
\r
610 PsndMix_32_to_16l = mix_32_to_16l_stereo_lvl;
\r
614 static void updateSound(int len)
\r
617 if (PicoOpt & POPT_EN_STEREO)
\r
620 if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))
\r
623 /* avoid writing audio when lagging behind to prevent audio lag */
\r
624 if (PicoSkipFrame != 2)
\r
625 sndout_oss_write(PsndOut, len);
\r
628 void pemu_sound_start(void)
\r
630 static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
\r
634 // prepare sound stuff
\r
635 if (currentConfig.EmuOpt & EOPT_EN_SOUND)
\r
637 int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;
\r
638 int target_fps = Pico.m.pal ? 50 : 60;
\r
639 int frame_samples, snd_excess_add;
\r
640 int snd_rate_oss = PsndRate;
\r
643 soc = soc_detect();
\r
644 if (soc == SOCID_POLLUX) {
\r
645 /* POLLUX pain: DPLL1 / mclk_div / bitclk_div / 4 */
\r
646 switch (PsndRate) {
\r
647 case 44100: PsndRate = 44171; break; // 44170.673077
\r
648 case 22050: PsndRate = 22086; break; // 22085.336538
\r
649 case 11025: PsndRate = 11043; break; // 11042.668269
\r
654 #define SOUND_RERATE_FLAGS (POPT_EN_FM|POPT_EN_PSG|POPT_EN_STEREO|POPT_EXT_FM|POPT_EN_MCD_CDDA)
\r
655 if (PsndRate != PsndRate_old || Pico.m.pal != pal_old || ((PicoOpt & POPT_EXT_FM) && crashed_940) ||
\r
656 ((PicoOpt ^ PicoOpt_old) & SOUND_RERATE_FLAGS)) {
\r
657 PsndRerate(Pico.m.frame_count ? 1 : 0);
\r
660 memset(sndBuffer, 0, sizeof(sndBuffer));
\r
661 PsndOut = sndBuffer;
\r
662 PicoWriteSound = updateSound;
\r
663 PsndRate_old = PsndRate;
\r
664 PicoOpt_old = PicoOpt;
\r
665 pal_old = Pico.m.pal;
\r
666 plat_update_volume(0, 0);
\r
668 frame_samples = PsndLen;
\r
669 snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps;
\r
670 if (snd_excess_add != 0)
\r
672 if (soc == SOCID_POLLUX)
\r
673 frame_samples *= 2; /* force larger buffer */
\r
675 printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
\r
676 PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);
\r
677 sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
\r
678 sndout_oss_start(snd_rate_oss, frame_samples, is_stereo);
\r
680 /* Wiz's sound hardware needs more prebuffer */
\r
681 if (soc == SOCID_POLLUX)
\r
682 updateSound(frame_samples);
\r
686 void pemu_sound_stop(void)
\r
688 /* get back from Wiz pain */
\r
689 switch (PsndRate) {
\r
690 case 44171: PsndRate = 44100; break;
\r
691 case 22086: PsndRate = 22050; break;
\r
692 case 11043: PsndRate = 11025; break;
\r
697 void pemu_sound_wait(void)
\r
699 // don't need to do anything, writes will block by themselves
\r
703 void pemu_forced_frame(int opts)
\r
705 int po_old = PicoOpt;
\r
706 int eo_old = currentConfig.EmuOpt;
\r
708 PicoOpt &= ~POPT_ALT_RENDERER;
\r
709 PicoOpt |= opts|POPT_ACC_SPRITES;
\r
710 currentConfig.EmuOpt |= EOPT_16BPP;
\r
712 PicoDrawSetColorFormat(1);
\r
713 PicoScanBegin = EmuScanBegin16;
\r
714 PicoScanEnd = NULL;
\r
715 Pico.m.dirtyPal = 1;
\r
716 PicoFrameDrawOnly();
\r
719 currentConfig.EmuOpt = eo_old;
\r
722 void plat_debug_cat(char *str)
\r
726 void emu_video_mode_change(int start_line, int line_count, int is_32cols)
\r
729 osd_fps_x = OSD_FPS_X;
\r
731 if (is_32cols && (PicoOpt & POPT_DIS_32C_BORDER)) {
\r
733 osd_fps_x = OSD_FPS_X - 64;
\r
736 /* want vertical scaling and game is not in 240 line mode */
\r
737 if (currentConfig.scaling == EOPT_SCALE_HW_HV) {
\r
738 gp2x_video_RGB_setscaling(start_line, scalex, line_count);
\r
739 osd_y = start_line + line_count - 8;
\r
741 gp2x_video_RGB_setscaling(0, scalex, 240);
\r
743 // clear whole screen in all buffers
\r
744 if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP))
\r
745 gp2x_memset_all_buffers(0, 0xe0, 320*240);
\r
747 gp2x_memset_all_buffers(0, 0, 320*240*2);
\r
751 static void tga_dump(void)
\r
753 #define BYTE unsigned char
\r
754 #define WORD unsigned short
\r
757 BYTE IDLength; /* 00h Size of Image ID field */
\r
758 BYTE ColorMapType; /* 01h Color map type */
\r
759 BYTE ImageType; /* 02h Image type code */
\r
760 WORD CMapStart; /* 03h Color map origin */
\r
761 WORD CMapLength; /* 05h Color map length */
\r
762 BYTE CMapDepth; /* 07h Depth of color map entries */
\r
763 WORD XOffset; /* 08h X origin of image */
\r
764 WORD YOffset; /* 0Ah Y origin of image */
\r
765 WORD Width; /* 0Ch Width of image */
\r
766 WORD Height; /* 0Eh Height of image */
\r
767 BYTE PixelDepth; /* 10h Image pixel size */
\r
768 BYTE ImageDescriptor; /* 11h Image descriptor byte */
\r
769 } __attribute__((packed)) TGAHEAD;
\r
770 static unsigned short oldscr[320*240];
\r
771 FILE *f; char name[128]; int i;
\r
773 memset(&TGAHEAD, 0, sizeof(TGAHEAD));
\r
774 TGAHEAD.ImageType = 2;
\r
775 TGAHEAD.Width = 320;
\r
776 TGAHEAD.Height = 240;
\r
777 TGAHEAD.PixelDepth = 16;
\r
778 TGAHEAD.ImageDescriptor = 2<<4; // image starts at top-left
\r
780 #define CONV(X) (((X>>1)&0x7fe0)|(X&0x1f)) // 555?
\r
782 for (i = 0; i < 320*240; i++)
\r
783 if(oldscr[i] != CONV(((unsigned short *)g_screen_ptr)[i])) break;
\r
786 for (i = 0; i < 320*240; i++)
\r
787 oldscr[i] = CONV(((unsigned short *)g_screen_ptr)[i]);
\r
788 sprintf(name, "%05i.tga", Pico.m.frame_count);
\r
789 f = fopen(name, "wb");
\r
790 if (!f) { printf("!f\n"); exit(1); }
\r
791 fwrite(&TGAHEAD, 1, sizeof(TGAHEAD), f);
\r
792 fwrite(oldscr, 1, 320*240*2, f);
\r
798 void pemu_loop_prep(void)
\r
800 static int gp2x_old_clock = -1, EmuOpt_old = 0, pal_old = 0;
\r
801 static int gp2x_old_gamma = 100;
\r
804 soc = soc_detect();
\r
806 if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_RAM_TIMINGS) {
\r
807 if (currentConfig.EmuOpt & EOPT_RAM_TIMINGS)
\r
810 unset_ram_timings();
\r
813 if (gp2x_old_clock < 0)
\r
814 gp2x_old_clock = default_cpu_clock;
\r
815 if (gp2x_old_clock != currentConfig.CPUclock) {
\r
816 printf("changing clock to %i...", currentConfig.CPUclock); fflush(stdout);
\r
817 gp2x_set_cpuclk(currentConfig.CPUclock);
\r
818 gp2x_old_clock = currentConfig.CPUclock;
\r
822 if (gp2x_old_gamma != currentConfig.gamma || ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_A_SN_GAMMA)) {
\r
823 set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt & EOPT_A_SN_GAMMA));
\r
824 gp2x_old_gamma = currentConfig.gamma;
\r
825 printf("updated gamma to %i, A_SN's curve: %i\n", currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000));
\r
828 if (((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_VSYNC) || Pico.m.pal != pal_old) {
\r
829 if ((currentConfig.EmuOpt & EOPT_VSYNC) || soc == SOCID_POLLUX)
\r
830 set_lcd_custom_rate(Pico.m.pal);
\r
831 else if (EmuOpt_old & EOPT_VSYNC)
\r
832 unset_lcd_custom_rate();
\r
835 if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_MMUHACK)
\r
836 gp2x_make_fb_bufferable(currentConfig.EmuOpt & EOPT_MMUHACK);
\r
838 EmuOpt_old = currentConfig.EmuOpt;
\r
839 pal_old = Pico.m.pal;
\r
841 // make sure we are in correct mode
\r
845 pemu_sound_start();
\r
848 void pemu_loop_end(void)
\r
850 int po_old = PicoOpt;
\r
851 int eo_old = currentConfig.EmuOpt;
\r
854 memset32(g_screen_ptr, 0, 320*240*2/4);
\r
856 /* do one more frame for menu bg */
\r
857 PicoOpt &= ~POPT_ALT_RENDERER;
\r
858 PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES;
\r
859 currentConfig.EmuOpt |= EOPT_16BPP;
\r
861 PicoScanBegin = EmuScanBegin16;
\r
862 PicoScanEnd = NULL;
\r
863 PicoDrawSetColorFormat(1);
\r
864 Pico.m.dirtyPal = 1;
\r
868 currentConfig.EmuOpt = eo_old;
\r
871 const char *plat_get_credits(void)
\r
873 return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n"
\r
875 "fDave: Cyclone 68000 core,\n"
\r
876 " base code of PicoDrive\n"
\r
877 "Reesy & FluBBa: DrZ80 core\n"
\r
878 "MAME devs: YM2612 and SN76496 cores\n"
\r
879 "rlyeh and others: minimal SDK\n"
\r
880 "Squidge: mmuhack\n"
\r
881 "Dzz: ARM940 sample\n"
\r
882 "GnoStiC / Puck2099: USB joy code\n"
\r
883 "craigix: GP2X hardware\n"
\r
884 "ketchupgun: skin design\n"
\r
886 "special thanks (for docs, ideas):\n"
\r
887 " Charles MacDonald, Haze,\n"
\r
888 " Stephane Dallongeville,\n"
\r
889 " Lordus, Exophase, Rokas,\n"
\r
890 " Nemesis, Tasco Deluxe";
\r