X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pandora%2Femu.c;h=a9556b17dad6689f7f024c0520f0a40931fd0c8b;hb=f6eaae4f09c6abab99692900a31c1df2a06b99af;hp=4a628c7638d5d5283dd8227ac37897092da58b88;hpb=d2f29611d1379a249c8f3f955ed16a336f9290cd;p=libpicofe.git diff --git a/pandora/emu.c b/pandora/emu.c index 4a628c7..a9556b1 100644 --- a/pandora/emu.c +++ b/pandora/emu.c @@ -4,35 +4,57 @@ // For commercial use, separate licencing terms must be obtained. #include +#include #include "../common/emu.h" #include "../common/menu.h" #include "../common/plat.h" #include "../common/arm_utils.h" #include "../linux/sndout_oss.h" +#include "../linux/fbdev.h" #include "asm_utils.h" #include "version.h" #include -#define USE_320_SCREEN 1 - static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; static unsigned char temp_frame[g_screen_width * g_screen_height * 2]; unsigned char *PicoDraw2FB = temp_frame; -static int osd_fps_x; -char cpu_clk_name[] = "unused"; +const char *renderer_names[] = { NULL }; +const char *renderer_names32x[] = { NULL }; +char cpu_clk_name[] = "Max CPU clock"; + +enum { + SCALE_1x1, + SCALE_2x2_3x2, + SCALE_2x2_2x2, +}; +static int get_cpu_clock(void) +{ + FILE *f; + int ret = 0; + f = fopen("/proc/pandora/cpu_mhz_max", "r"); + if (f) { + fscanf(f, "%d", &ret); + fclose(f); + } + return ret; +} void pemu_prep_defconfig(void) { // XXX: move elsewhere g_menubg_ptr = temp_frame; + + defaultConfig.EmuOpt |= EOPT_VSYNC; + defaultConfig.scaling = SCALE_2x2_3x2; } void pemu_validate_config(void) { + currentConfig.CPUclock = get_cpu_clock(); } // FIXME: cleanup @@ -40,7 +62,7 @@ static void osd_text(int x, int y, const char *text) { int len = strlen(text)*8; - if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + if (0) { int *p, i, h; x &= ~3; // align x len = (len+3) >> 2; @@ -68,7 +90,7 @@ static void draw_cd_leds(void) // if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change // mmu hack problems? old_reg = Pico_mcd->s68k_regs[0]; - if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + if (0) { // 8-bit modes unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; @@ -89,9 +111,7 @@ static void draw_cd_leds(void) } } -#ifdef USE_320_SCREEN - -static int EmuScanBegin16(unsigned int num) +static int emuscan_1x1(unsigned int num) { DrawLineDest = (unsigned short *)g_screen_ptr + num*800 + 800/2 - 320/2; //int w = (Pico.video.reg[12]&1) ? 320 : 256; @@ -100,65 +120,75 @@ static int EmuScanBegin16(unsigned int num) return 0; } -#else // USE_320_SCREEN - -static int EmuScanEnd16(unsigned int num) -{ - unsigned char *ps=HighCol+8; - unsigned short *pd; - unsigned short *pal=HighPal; - int sh = Pico.video.reg[0xC]&8; - int len, mask = 0xff; - - pd=(unsigned short *)g_screen_ptr + num*800*2 + 800/2 - 320*2/2; - - if (Pico.m.dirtyPal) - PicoDoHighPal555(sh); - - if (Pico.video.reg[12]&1) { - len = 320; - } else { - pd += 32*2; - len = 256; - } +#define MAKE_EMUSCAN(name_, clut_name_, offs_, len_) \ +static int name_(unsigned int num) \ +{ \ + unsigned char *ps = HighCol+8; \ + unsigned short *pd, *pal = HighPal; \ + int sh = Pico.video.reg[0xC] & 8; \ + int mask = 0xff; \ + \ + pd = (unsigned short *)g_screen_ptr + num*800*2 + offs_;\ + \ + if (Pico.m.dirtyPal) \ + PicoDoHighPal555(sh); \ + \ + if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) \ + mask = 0x3f; /* upper bits are priority stuff */\ + \ + clut_line##clut_name_(pd, ps, pal, (mask<<16) | len_); \ + \ + return 0; \ +} - if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) - mask=0x3f; // messed sprites, upper bits are priority stuff +MAKE_EMUSCAN(emuscan_2x2_40, 2x2, 800/2 - 320*2/2, 320) +MAKE_EMUSCAN(emuscan_2x2_32, 2x2, 800/2 - 256*2/2, 256) +MAKE_EMUSCAN(emuscan_3x2_32, 3x2, 800/2 - 256*3/2, 256) -#if 1 - clut_line(pd, ps, pal, (mask<<16) | len); -#else - for (; len > 0; len--) - { - unsigned int p = pal[*ps++ & mask]; +#if 0 /* FIXME */ +static int EmuScanEnd16_32x(unsigned int num) +{ + unsigned int *ps; + unsigned int *pd; + int len; + + ps = (unsigned int *)temp_frame; + pd = (unsigned int *)g_screen_ptr + (num*800*2 + 800/2 - 320*2/2) / 2; + + for (len = 320/2; len > 0; len--, ps++) { + unsigned int p, p1; + p1 = *ps; + p = p1 << 16; + p |= p >> 16; + *pd = pd[800/2] = p; + pd++; + + p = p1 >> 16; p |= p << 16; - *(unsigned int *)pd = p; - *(unsigned int *)(&pd[800]) = p; - pd += 2; + *pd = pd[800/2] = p; + pd++; } -#endif return 0; } +#endif -#endif // USE_320_SCREEN - -void pemu_update_display(const char *fps, const char *notice) +void pemu_finalize_frame(const char *fps, const char *notice) { if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) { if (notice) - osd_text(4, 460, notice); + osd_text(4, 464, notice); if (currentConfig.EmuOpt & EOPT_SHOW_FPS) - osd_text(osd_fps_x, 460, fps); + osd_text(640, 464, fps); } if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) draw_cd_leds(); } -void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu) +void plat_video_toggle_renderer(int change, int is_menu) { // this will auto-select SMS/32X renderers - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 1); } void plat_video_menu_enter(int is_rom_loaded) @@ -172,19 +202,24 @@ void plat_video_menu_begin(void) void plat_video_menu_end(void) { + plat_video_flip(); } void plat_status_msg_clear(void) { - unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_width * g_screen_height; - int l = g_screen_width * 8; - memset32((int *)(d - l), 0, l * 2 / 4); + int s = g_screen_width * g_screen_height * 2; + int l = g_screen_width * 16 * 2; + int i; + + for (i = 0; i < fbdev_buffer_count; i++) + memset32((int *)((char *)fbdev_buffers[i] + s - l), 0, l / 4); } void plat_status_msg_busy_next(const char *msg) { plat_status_msg_clear(); - pemu_update_display("", msg); + pemu_finalize_frame("", msg); + plat_video_flip(); emu_status_msg(""); reset_timing = 1; } @@ -218,70 +253,71 @@ void plat_update_volume(int has_changed, int is_up) void pemu_forced_frame(int opts) { int po_old = PicoOpt; - int eo_old = currentConfig.EmuOpt; PicoOpt &= ~0x10; PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites - currentConfig.EmuOpt |= 0x80; - -#ifdef USE_320_SCREEN - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; -#else - PicoDrawSetColorFormat(-1); - PicoScanEnd = EmuScanEnd16; -#endif + Pico.m.dirtyPal = 1; PicoFrameDrawOnly(); PicoOpt = po_old; - currentConfig.EmuOpt = eo_old; } static void updateSound(int len) { + unsigned int t; + len <<= 1; if (PicoOpt & POPT_EN_STEREO) len <<= 1; + // sndout_oss_can_write() not reliable.. if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len)) return; /* avoid writing audio when lagging behind to prevent audio lag */ - if (PicoSkipFrame != 2) - sndout_oss_write(PsndOut, len); + if (PicoSkipFrame == 2) + return; + + t = plat_get_ticks_ms(); + sndout_oss_write(PsndOut, len); + t = plat_get_ticks_ms() - t; + if (t > 1) + printf("audio lag %u\n", t); } void pemu_sound_start(void) { - static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; int target_fps = Pico.m.pal ? 50 : 60; PsndOut = NULL; - if (currentConfig.EmuOpt & 4) + if (currentConfig.EmuOpt & EOPT_EN_SOUND) { - int snd_excess_add; - if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old) - PsndRerate(Pico.m.frame_count ? 1 : 0); + int snd_excess_add, frame_samples; + int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0; + + PsndRerate(Pico.m.frame_count ? 1 : 0); + + frame_samples = PsndLen; + snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps; + if (snd_excess_add != 0) + frame_samples++; - snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps; printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", - PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); - sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3); - sndout_oss_setvol(currentConfig.volume, currentConfig.volume); + PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal); + sndout_oss_start(PsndRate, frame_samples * 2, is_stereo); + //sndout_oss_setvol(currentConfig.volume, currentConfig.volume); PicoWriteSound = updateSound; plat_update_volume(0, 0); memset(sndBuffer, 0, sizeof(sndBuffer)); PsndOut = sndBuffer; - PsndRate_old = PsndRate; - PicoOpt_old = PicoOpt; - pal_old = Pico.m.pal; } } void pemu_sound_stop(void) { + sndout_oss_stop(); } void pemu_sound_wait(void) @@ -295,21 +331,52 @@ void plat_debug_cat(char *str) void emu_video_mode_change(int start_line, int line_count, int is_32cols) { - osd_fps_x = 260; + int i; // clear whole screen in all buffers - memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4); + for (i = 0; i < fbdev_buffer_count; i++) + memset32(fbdev_buffers[i], 0, g_screen_width * g_screen_height * 2 / 4); + + PicoScanBegin = NULL; + PicoScanEnd = NULL; + +#if 0 + if (PicoAHW & PAHW_32X) { + /* FIXME */ + DrawLineDest = (unsigned short *)temp_frame; + PicoDrawSetOutFormat(PDF_RGB555, 1); + PicoScanEnd = EmuScanEnd16_32x; + } else +#endif + { + switch (currentConfig.scaling) { + case SCALE_1x1: + PicoDrawSetOutFormat(PDF_RGB555, 1); + PicoScanBegin = emuscan_1x1; + break; + case SCALE_2x2_3x2: + PicoDrawSetOutFormat(PDF_NONE, 0); + PicoScanEnd = is_32cols ? emuscan_3x2_32 : emuscan_2x2_40; + break; + case SCALE_2x2_2x2: + PicoDrawSetOutFormat(PDF_NONE, 0); + PicoScanEnd = is_32cols ? emuscan_2x2_32 : emuscan_2x2_40; + break; + } + } } void pemu_loop_prep(void) { -#ifdef USE_320_SCREEN - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; -#else - PicoDrawSetColorFormat(-1); - PicoScanEnd = EmuScanEnd16; -#endif + emu_video_mode_change(0, 0, 0); + + if (currentConfig.CPUclock != get_cpu_clock()) { + FILE *f = fopen("/proc/pandora/cpu_mhz_max", "w"); + if (f != NULL) { + fprintf(f, "%d\n", currentConfig.CPUclock); + fclose(f); + } + } pemu_sound_start(); } @@ -327,7 +394,7 @@ void pemu_loop_end(void) PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; currentConfig.EmuOpt |= EOPT_16BPP; - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 1); Pico.m.dirtyPal = 1; PicoFrame(); @@ -335,39 +402,39 @@ void pemu_loop_end(void) currentConfig.EmuOpt = eo_old; } -/* XXX: avoid busy wait somehow? */ void plat_wait_till_us(unsigned int us_to) { unsigned int now; + signed int diff; - spend_cycles(1024); now = plat_get_ticks_us(); - while ((signed int)(us_to - now) > 512) - { + // XXX: need to check NOHZ + diff = (signed int)(us_to - now); + if (diff > 10000) { + //printf("sleep %d\n", us_to - now); + usleep(diff * 15 / 16); + now = plat_get_ticks_us(); + //printf(" wake %d\n", (signed)(us_to - now)); + } +/* + while ((signed int)(us_to - now) > 512) { spend_cycles(1024); now = plat_get_ticks_us(); } -} - -void plat_video_wait_vsync(void) -{ +*/ } const char *plat_get_credits(void) { - return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n" + return "PicoDrive v" VERSION " (c) notaz, 2006-2010\n\n\n" "Credits:\n" "fDave: Cyclone 68000 core,\n" " base code of PicoDrive\n" "Reesy & FluBBa: DrZ80 core\n" "MAME devs: YM2612 and SN76496 cores\n" - "rlyeh and others: minimal SDK\n" - "Squidge: mmuhack\n" - "Dzz: ARM940 sample\n" - "GnoStiC / Puck2099: USB joy code\n" - "craigix: GP2X hardware\n" - "ketchupgun: skin design\n" + "Pandora team: Pandora\n" + "Inder: menu bg\n" "\n" "special thanks (for docs, ideas):\n" " Charles MacDonald, Haze,\n"