X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Femu.c;h=46dc3aa052e1c9764d944c50c864d4cb53ec6a24;hb=0fc3250a875c96efc4e43873cfa319eb4b25a95a;hp=003f1737d8685268ce26efa71b80de7661ec5002;hpb=2c60056042e94007286e3e0e1789f4c9a78b7731;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index 003f173..46dc3aa 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -1,4 +1,4 @@ -// (c) Copyright 2006-2007 notaz, All rights reserved. +// (c) Copyright 2006-2009 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. @@ -8,22 +8,18 @@ #include #include #include -#include -#include -#include - #include -#include "emu.h" -#include "gp2x.h" -#include "menu.h" +#include "plat_gp2x.h" +#include "soc.h" +#include "../common/plat.h" +#include "../common/menu.h" #include "../common/arm_utils.h" #include "../common/fonts.h" #include "../common/emu.h" #include "../common/config.h" #include "../common/input.h" #include "../linux/sndout_oss.h" -#include "cpuctrl.h" #include "version.h" #include @@ -40,8 +36,6 @@ #endif -int select_exits = 0; - extern int crashed_940; static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; @@ -103,12 +97,16 @@ void emu_Init(void) static void scaling_update(void) { - PicoOpt &= ~0x4100; + PicoOpt &= ~(POPT_DIS_32C_BORDER|POPT_EN_SOFTSCALE); switch (currentConfig.scaling) { - default: break; // off - case 1: // hw hor - case 2: PicoOpt |= 0x0100; break; // hw hor+vert - case 3: PicoOpt |= 0x4000; break; // sw hor + default:break; + case EOPT_SCALE_HW_H: + case EOPT_SCALE_HW_HV: + PicoOpt |= POPT_DIS_32C_BORDER; + break; + case EOPT_SCALE_SW_H: + PicoOpt |= POPT_EN_SOFTSCALE; + break; } } @@ -130,40 +128,33 @@ void emu_Deinit(void) // restore gamma if (gp2x_old_gamma != 100) - set_gamma(100, 0); + set_lcd_gamma(100, 0); } void emu_prepareDefaultConfig(void) { + gp2x_soc_t soc; + memset(&defaultConfig, 0, sizeof(defaultConfig)); - defaultConfig.EmuOpt = 0x9d | 0x00700; // | <- ram_tmng, confirm_save, cd_leds - defaultConfig.s_PicoOpt = 0x0f | POPT_EXT_FM|POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC|POPT_ACC_SPRITES; + defaultConfig.EmuOpt = 0x9d | EOPT_RAM_TIMINGS | 0x600; // | <- confirm_save, cd_leds + defaultConfig.s_PicoOpt = 0x0f | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC|POPT_ACC_SPRITES; defaultConfig.s_PsndRate = 44100; defaultConfig.s_PicoRegion = 0; // auto defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP defaultConfig.s_PicoCDBuffers = 0; defaultConfig.Frameskip = -1; // auto - defaultConfig.CPUclock = 200; + defaultConfig.CPUclock = default_cpu_clock; defaultConfig.volume = 50; - defaultConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU - defaultConfig.KeyBinds[ 4] = 1<<1; - defaultConfig.KeyBinds[ 2] = 1<<2; - defaultConfig.KeyBinds[ 6] = 1<<3; - defaultConfig.KeyBinds[14] = 1<<4; - defaultConfig.KeyBinds[13] = 1<<5; - defaultConfig.KeyBinds[12] = 1<<6; - defaultConfig.KeyBinds[ 8] = 1<<7; - defaultConfig.KeyBinds[15] = 1<<26; // switch rend - defaultConfig.KeyBinds[10] = 1<<27; // save state - defaultConfig.KeyBinds[11] = 1<<28; // load state - defaultConfig.KeyBinds[23] = 1<<29; // vol up - defaultConfig.KeyBinds[22] = 1<<30; // vol down defaultConfig.gamma = 100; defaultConfig.scaling = 0; defaultConfig.turbo_rate = 15; + + soc = soc_detect(); + if (soc == SOCID_MMSP2) + defaultConfig.s_PicoOpt |= POPT_EXT_FM; } -void osd_text(int x, int y, const char *text) +static void osd_text(int x, int y, const char *text) { int len = strlen(text)*8; int *p, i, h, offs; @@ -310,8 +301,10 @@ static void blit(const char *fps, const char *notice) if (notice || (emu_opt & 2)) { int h = 232; - if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) h -= 8; - if (notice) osd_text(4, h, notice); + if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8)) + h -= 8; + if (notice) + osd_text(4, h, notice); if (emu_opt & 2) osd_text(osd_fps_x, h, fps); } @@ -377,7 +370,7 @@ static void vidResetMode(void) } Pico.m.dirtyPal = 1; // reset scaling - if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) + if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8)) gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224); else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240); } @@ -415,7 +408,7 @@ static void emu_msg_tray_open(void) gettimeofday(¬iceMsgTime, 0); } -static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) +static void RunEventsPico(unsigned int events) { int ret, px, py, lim_x; static int pdown_frames = 0; @@ -449,11 +442,11 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) // PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000; } + if (PicoPad[0] & 1) pico_pen_y--; + if (PicoPad[0] & 2) pico_pen_y++; + if (PicoPad[0] & 4) pico_pen_x--; + if (PicoPad[0] & 8) pico_pen_x++; PicoPad[0] &= ~0x0f; // release UDLR - if (gp2x_keys & GP2X_UP) pico_pen_y--; - if (gp2x_keys & GP2X_DOWN) pico_pen_y++; - if (gp2x_keys & GP2X_LEFT) pico_pen_x--; - if (gp2x_keys & GP2X_RIGHT) pico_pen_x++; lim_x = (Pico.video.reg[12]&1) ? 319 : 255; if (pico_pen_y < 8) pico_pen_y = 8; @@ -507,15 +500,31 @@ static void RunEvents(unsigned int which) { int do_it = 1; if ( emu_checkSaveFile(state_slot) && - (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load - (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save - unsigned long keys; - blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)"); - while ( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) - usleep(50*1024); - if (keys & GP2X_X) do_it = 0; - while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release - usleep(50*1024); + (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load + (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) // save + { + const char *nm; + char tmp[64]; + int keys, len; + + strcpy(tmp, (which & 0x1000) ? "LOAD STATE? " : "OVERWRITE SAVE? "); + len = strlen(tmp); + nm = in_get_key_name(-1, -PBTN_MA3); + snprintf(tmp + len, sizeof(tmp) - len, "(%s=yes, ", nm); + len = strlen(tmp); + nm = in_get_key_name(-1, -PBTN_MBACK); + snprintf(tmp + len, sizeof(tmp) - len, "%s=no)", nm); + + blit("", tmp); + + in_set_blocking(1); + while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK)); // wait for release + while ( !((keys = in_menu_wait_any(50)) & (PBTN_MA3|PBTN_MBACK)) ); // .. press + if (keys & PBTN_MBACK) + do_it = 0; + while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK)); // .. release + in_set_blocking(0); + clearArea(0); } if (do_it) { @@ -544,7 +553,7 @@ static void RunEvents(unsigned int which) strcpy(noticeMsg, " 8bit accurate renderer"); } - gettimeofday(¬iceMsgTime, 0); + emu_noticeMsgUpdated(); } if (which & 0x0300) { @@ -556,7 +565,7 @@ static void RunEvents(unsigned int which) if(state_slot > 9) state_slot = 0; } sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE"); - gettimeofday(¬iceMsgTime, 0); + emu_noticeMsgUpdated(); } if (which & 0x0080) { engineState = PGS_Menu; @@ -565,16 +574,9 @@ static void RunEvents(unsigned int which) static void updateKeys(void) { - unsigned int keys, keys2, allActions[2] = { 0, 0 }, events; + unsigned int allActions[2] = { 0, 0 }, events; static unsigned int prevEvents = 0; - keys = gp2x_joystick_read(0); - if (keys & GP2X_SELECT) - engineState = select_exits ? PGS_Quit : PGS_Menu; - - keys &= CONFIGURABLE_KEYS; - keys2 = keys; - /* FIXME: player2 */ allActions[0] = in_update(); @@ -599,7 +601,7 @@ static void updateKeys(void) events &= ~prevEvents; if (PicoAHW == PAHW_PICO) - RunEventsPico(events, keys); + RunEventsPico(events); if (events) RunEvents(events); if (movie_data) emu_updateMovie(); @@ -767,7 +769,7 @@ static void tga_dump(void) void emu_Loop(void) { - static int gp2x_old_clock = 200, EmuOpt_old = 0; + static int gp2x_old_clock = -1, EmuOpt_old = 0; char fpsbuff[24]; // fps count c string struct timeval tval; // timing int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync @@ -777,25 +779,38 @@ void emu_Loop(void) printf("entered emu_Loop()\n"); + if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_RAM_TIMINGS) { + if (currentConfig.EmuOpt & EOPT_RAM_TIMINGS) + set_ram_timings(); + else + unset_ram_timings(); + } + + if (gp2x_old_clock < 0) + gp2x_old_clock = default_cpu_clock; if (gp2x_old_clock != currentConfig.CPUclock) { printf("changing clock to %i...", currentConfig.CPUclock); fflush(stdout); - set_FCLK(currentConfig.CPUclock); + gp2x_set_cpuclk(currentConfig.CPUclock); gp2x_old_clock = currentConfig.CPUclock; printf(" done\n"); } if (gp2x_old_gamma != currentConfig.gamma || (EmuOpt_old&0x1000) != (currentConfig.EmuOpt&0x1000)) { - set_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000)); + set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000)); gp2x_old_gamma = currentConfig.gamma; printf("updated gamma to %i, A_SN's curve: %i\n", currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000)); } - if ((EmuOpt_old&0x2000) != (currentConfig.EmuOpt&0x2000)) { - if (currentConfig.EmuOpt&0x2000) - set_LCD_custom_rate(Pico.m.pal ? LCDR_100 : LCDR_120); - else unset_LCD_custom_rate(); + if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_PSYNC) { + if (currentConfig.EmuOpt & EOPT_PSYNC) + set_lcd_custom_rate(Pico.m.pal); + else + unset_lcd_custom_rate(); } + if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_MMUHACK) + gp2x_make_fb_bufferable(currentConfig.EmuOpt & EOPT_MMUHACK); + EmuOpt_old = currentConfig.EmuOpt; fpsbuff[0] = 0; @@ -875,7 +890,8 @@ void emu_Loop(void) vidCpyM2 = vidCpyM2_32col; } } - if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode + /* want vertical scaling and game is not in 240 line mode */ + if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(modes&8)) gp2x_video_RGB_setscaling(8, scalex, 224); else gp2x_video_RGB_setscaling(0, scalex, 240); oldmodes = modes; @@ -1021,7 +1037,7 @@ const char *plat_get_credits(void) "Reesy & FluBBa: DrZ80 core\n" "MAME devs: YM2612 and SN76496 cores\n" "rlyeh and others: minimal SDK\n" - "Squidge: squidgehack\n" + "Squidge: mmuhack\n" "Dzz: ARM940 sample\n" "GnoStiC / Puck2099: USB joy code\n" "craigix: GP2X hardware\n"