X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2Femu.c;h=3096edd95d78408e18f914762d8d8b42d15dd971;hb=1dceadaee482ad3ca6f5ccbef57ea93893f45e82;hp=27e9d13dbffbefcd6b46da2eaa1cf8a1814b55c9;hpb=4e8a534cecffcc60e96c9fefdb821cc1a09a1eba;p=picodrive.git diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 27e9d13..3096edd 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -18,13 +18,15 @@ #include "gp2x.h" #include "usbjoy.h" #include "menu.h" -#include "asmutils.h" +#include "../common/arm_utils.h" +#include "../common/fonts.h" #include "cpuctrl.h" #include #include #include +//#define PFRAMES #ifdef BENCHMARK #define OSD_FPS_X 220 @@ -32,14 +34,6 @@ #define OSD_FPS_X 260 #endif -// PicoPad[] format: SACB RLDU -char *actionNames[] = { - "UP", "DOWN", "LEFT", "RIGHT", "B", "C", "A", "START", - 0, 0, 0, 0, 0, 0, 0, 0, // Z, Y, X, MODE (enabled only when needed), ?, ?, ?, ? - 0, 0, 0, 0, 0, 0, 0, "ENTER MENU", // player2_flag, ?, ?, ?, ?, ?, ?, menu - "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE", - "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE" -}; int engineState; int select_exits = 0; @@ -59,7 +53,7 @@ static int combo_keys = 0, combo_acts = 0; // keys and actions which need button static int gp2x_old_gamma = 100; static unsigned char *movie_data = NULL; static int movie_size = 0; -unsigned char *framebuff = 0; // temporary buffer for alt renderer +unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer int state_slot = 0; int reset_timing = 0; int config_slot = 0, config_slot_current = 0; @@ -285,7 +279,7 @@ int emu_ReloadRom(void) // bios_help() ? return 0; } else { - if (PicoMCD & 1) PicoExitMCD(); + if (PicoMCD & 1) Stop_CD(); PicoMCD &= ~1; } @@ -295,6 +289,8 @@ int emu_ReloadRom(void) return 0; } + menu_romload_prepare(used_rom_name); + if(rom_data) { free(rom_data); rom_data = 0; @@ -305,9 +301,11 @@ int emu_ReloadRom(void) sprintf(menuErrorMsg, "PicoCartLoad() failed."); printf("%s\n", menuErrorMsg); pm_close(rom); + menu_romload_end(); return 0; } pm_close(rom); + menu_romload_end(); // detect wrong files (Pico crashes on very small files), also see if ROM EP is good if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 || @@ -319,9 +317,9 @@ int emu_ReloadRom(void) } // load config for this ROM (do this before insert to get correct region) - ret = emu_ReadConfig(1); + ret = emu_ReadConfig(1, 1); if (!ret) - emu_ReadConfig(0); + emu_ReadConfig(0, 1); printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size); if(PicoCartInsert(rom_data, rom_size)) { @@ -351,11 +349,11 @@ int emu_ReloadRom(void) } // additional movie stuff - if(movie_data) { + if (movie_data) { if(movie_data[0x14] == '6') PicoOpt |= 0x20; // 6 button pad else PicoOpt &= ~0x20; - PicoOpt |= 0x40; // accurate timing + PicoOpt |= 0x10040; // accurate timing, no VDP fifo timing if(movie_data[0xF] >= 'A') { if(movie_data[0x16] & 0x80) { PicoRegionOverride = 8; @@ -370,6 +368,7 @@ int emu_ReloadRom(void) } else { + PicoOpt &= ~0x10000; if(Pico.m.pal) { strcpy(noticeMsg, "PAL SYSTEM / 50 FPS"); } else { @@ -392,10 +391,10 @@ static void emu_msg_tray_open(void); void emu_Init(void) { // make temp buffer for alt renderer - framebuff = malloc((8+320)*(8+240+8)); - if (!framebuff) + PicoDraw2FB = malloc((8+320)*(8+240+8)); + if (!PicoDraw2FB) { - printf("framebuff == 0\n"); + printf("PicoDraw2FB == 0\n"); } // make dirs for saves, cfgs, etc. @@ -472,7 +471,7 @@ void scaling_update(void) } -int emu_ReadConfig(int game) +int emu_ReadConfig(int game, int no_defaults) { FILE *f; char cfg[512], extbuf[16]; @@ -480,33 +479,36 @@ int emu_ReadConfig(int game) if (!game) { - // set default config - memset(¤tConfig, 0, sizeof(currentConfig)); - currentConfig.lastRomFile[0] = 0; - currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds - currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda - currentConfig.PsndRate = 22050; // 44100; - currentConfig.PicoRegion = 0; // auto - currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP - currentConfig.Frameskip = -1; // auto - currentConfig.CPUclock = 200; - currentConfig.volume = 50; - currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU - currentConfig.KeyBinds[ 4] = 1<<1; - currentConfig.KeyBinds[ 2] = 1<<2; - currentConfig.KeyBinds[ 6] = 1<<3; - currentConfig.KeyBinds[14] = 1<<4; - currentConfig.KeyBinds[13] = 1<<5; - currentConfig.KeyBinds[12] = 1<<6; - currentConfig.KeyBinds[ 8] = 1<<7; - currentConfig.KeyBinds[15] = 1<<26; // switch rend - currentConfig.KeyBinds[10] = 1<<27; // save state - currentConfig.KeyBinds[11] = 1<<28; // load state - currentConfig.KeyBinds[23] = 1<<29; // vol up - currentConfig.KeyBinds[22] = 1<<30; // vol down - currentConfig.gamma = 100; - currentConfig.PicoCDBuffers = 64; - currentConfig.scaling = 0; + if (!no_defaults) + { + // set default config + memset(¤tConfig, 0, sizeof(currentConfig)); + currentConfig.lastRomFile[0] = 0; + currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds + currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda + currentConfig.PsndRate = 22050; // 44100; + currentConfig.PicoRegion = 0; // auto + currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP + currentConfig.Frameskip = -1; // auto + currentConfig.CPUclock = 200; + currentConfig.volume = 50; + currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU + currentConfig.KeyBinds[ 4] = 1<<1; + currentConfig.KeyBinds[ 2] = 1<<2; + currentConfig.KeyBinds[ 6] = 1<<3; + currentConfig.KeyBinds[14] = 1<<4; + currentConfig.KeyBinds[13] = 1<<5; + currentConfig.KeyBinds[12] = 1<<6; + currentConfig.KeyBinds[ 8] = 1<<7; + currentConfig.KeyBinds[15] = 1<<26; // switch rend + currentConfig.KeyBinds[10] = 1<<27; // save state + currentConfig.KeyBinds[11] = 1<<28; // load state + currentConfig.KeyBinds[23] = 1<<29; // vol up + currentConfig.KeyBinds[22] = 1<<30; // vol down + currentConfig.gamma = 100; + currentConfig.PicoCDBuffers = 64; + currentConfig.scaling = 0; + } strncpy(cfg, PicoConfigFile, 511); if (config_slot != 0) { @@ -539,10 +541,6 @@ int emu_ReadConfig(int game) PicoRegionOverride = currentConfig.PicoRegion; PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder; PicoCDBuffers = currentConfig.PicoCDBuffers; - if (PicoOpt & 0x20) { - actionNames[ 8] = "Z"; actionNames[ 9] = "Y"; - actionNames[10] = "X"; actionNames[11] = "MODE"; - } scaling_update(); // some sanity checks if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200; @@ -630,7 +628,7 @@ void emu_Deinit(void) } } - free(framebuff); + free(PicoDraw2FB); PicoExit(); @@ -639,6 +637,53 @@ void emu_Deinit(void) set_gamma(100, 0); } +static void text_out8_builtin(int x, int y, const char *text) +{ + int i,l,len=strlen(text); + unsigned char *screen = (unsigned char *)gp2x_screen + x + y*320; + + /* always using built-in font */ + for (i = 0; i < len; i++) + { + for (l=0;l<8;l++) + { + unsigned char fd = fontdata8x8[((text[i])*8)+l]; + if (fd&0x80) screen[l*320+0]=0xf0; + if (fd&0x40) screen[l*320+1]=0xf0; + if (fd&0x20) screen[l*320+2]=0xf0; + if (fd&0x10) screen[l*320+3]=0xf0; + if (fd&0x08) screen[l*320+4]=0xf0; + if (fd&0x04) screen[l*320+5]=0xf0; + if (fd&0x02) screen[l*320+6]=0xf0; + if (fd&0x01) screen[l*320+7]=0xf0; + } + screen += 8; + } +} + +static void text_out16_builtin(int x, int y, const char *text) +{ + int i,l,len=strlen(text); + unsigned short *screen = (unsigned short *)gp2x_screen + x + y*320; + + for (i = 0; i < len; i++) + { + for (l=0;l<8;l++) + { + unsigned char fd = fontdata8x8[((text[i])*8)+l]; + if(fd&0x80) screen[l*320+0]=0xffff; + if(fd&0x40) screen[l*320+1]=0xffff; + if(fd&0x20) screen[l*320+2]=0xffff; + if(fd&0x10) screen[l*320+3]=0xffff; + if(fd&0x08) screen[l*320+4]=0xffff; + if(fd&0x04) screen[l*320+5]=0xffff; + if(fd&0x02) screen[l*320+6]=0xffff; + if(fd&0x01) screen[l*320+7]=0xffff; + } + screen += 8; + } +} + void osd_text(int x, int y, const char *text) { @@ -652,7 +697,7 @@ void osd_text(int x, int y, const char *text) p = (int *) ((unsigned char *) gp2x_screen+x+320*(y+h)); for (i = len; i; i--, p++) *p = 0xe0e0e0e0; } - gp2x_text_out8_2(x, y, text, 0xf0); + text_out8_builtin(x, y, text); } else { int *p, i, h; x &= ~1; // align x @@ -661,7 +706,7 @@ void osd_text(int x, int y, const char *text) p = (int *) ((unsigned short *) gp2x_screen+x+320*(y+h)); for (i = len; i; i--, p++) *p = (*p>>2)&0x39e7; } - gp2x_text_out15(x, y, text); + text_out16_builtin(x, y, text); } } @@ -725,7 +770,7 @@ static void blit(const char *fps, const char *notice) // feed new palette to our device gp2x_video_setpalette(localPal, 0x40); } - vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); + vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); } else if (!(emu_opt&0x80)) { // 8bit accurate renderer if (Pico.m.dirtyPal) { @@ -799,7 +844,7 @@ static void vidResetMode(void) if (PicoOpt&0x10) { gp2x_video_changemode(8); } else if (currentConfig.EmuOpt&0x80) { - gp2x_video_changemode(15); + gp2x_video_changemode(16); PicoDrawSetColorFormat(1); PicoScan = EmuScan16; PicoScan(0, 0); @@ -1050,20 +1095,31 @@ static void SkipFrame(int do_audio) void emu_forced_frame(void) { int po_old = PicoOpt; + int eo_old = currentConfig.EmuOpt; - PicoOpt |= 0x10; - PicoFrameFull(); + PicoOpt &= ~0x0010; + PicoOpt |= 0x4080; // soft_scale | acc_sprites + currentConfig.EmuOpt |= 0x80; + + //vidResetMode(); + PicoDrawSetColorFormat(1); + PicoScan = EmuScan16; + PicoScan(0, 0); + Pico.m.dirtyPal = 1; + PicoFrameDrawOnly(); +/* if (!(Pico.video.reg[12]&1)) { vidCpyM2 = vidCpyM2_32col; clearArea(1); } else vidCpyM2 = vidCpyM2_40col; - vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); + vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); - +*/ PicoOpt = po_old; + currentConfig.EmuOpt = eo_old; } static void simpleWait(int thissec, int lim_time) @@ -1131,17 +1187,18 @@ void emu_Loop(void) // prepare sound stuff if(currentConfig.EmuOpt & 4) { int snd_excess_add; - if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) { + if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || + ((PicoOpt&0x200) && crashed_940)) { /* if 940 is turned off, we need it to be put back to sleep */ if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) { Reset940(1, 2); Pause940(1); } - sound_rerate(1); + sound_rerate(Pico.m.frame_count ? 1 : 0); } - //excess_samples = PsndRate - PsndLen*target_fps; 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); + printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", + PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3); gp2x_sound_volume(currentConfig.volume, currentConfig.volume); PicoWriteSound = updateSound; @@ -1253,6 +1310,9 @@ void emu_Loop(void) if (frames_shown > frames_done) frames_shown = frames_done; } } +#ifdef PFRAMES + sprintf(fpsbuff, "%i", Pico.m.frame_count); +#endif lim_time = (frames_done+1) * target_frametime + vsync_offset; if(currentConfig.Frameskip >= 0) { // frameskip enabled @@ -1380,12 +1440,9 @@ if (Pico.m.frame_count == 31563) { SRam.changed = 0; } - // if in 16bit mode, generate 8it image for menu background - if (!(PicoOpt&0x10) && (currentConfig.EmuOpt&0x80)) + // if in 8bit mode, generate 16bit image for menu background + if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) emu_forced_frame(); - - // for menu bg - gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2); } @@ -1520,7 +1577,7 @@ int emu_SaveLoadGame(int load, int sram) } } else { sram_size = SRam.end-SRam.start+1; - if(SRam.reg_back & 4) sram_size=0x2000; + if(Pico.m.sram_reg & 4) sram_size=0x2000; sram_data = SRam.data; } if (!sram_data) return 0; // SRam forcefully disabled for this game