X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=Pico%2FSek.c;h=f72da65f9a4d0d00cbce02a6be422b4256562113;hb=6a13ef3f56a80ac698d463f5d00235ea2a090f52;hp=001faeace10e6c9cfd0cbd5be50b586d31b7b209;hpb=053fd9b42f2cf38194f78e37c373363fc9cb9933;p=picodrive.git diff --git a/Pico/Sek.c b/Pico/Sek.c index 001faea..f72da65 100644 --- a/Pico/Sek.c +++ b/Pico/Sek.c @@ -96,7 +96,7 @@ static void SekIntAckF68K(unsigned level) #endif -PICO_INTERNAL int SekInit() +PICO_INTERNAL void SekInit(void) { #ifdef EMU_C68K CycloneInit(); @@ -129,13 +129,11 @@ PICO_INTERNAL int SekInit() g_m68kcontext = oldcontext; } #endif - - return 0; } // Reset the 68000: -PICO_INTERNAL int SekReset() +PICO_INTERNAL int SekReset(void) { if (Pico.rom==NULL) return 1; @@ -165,21 +163,19 @@ PICO_INTERNAL int SekReset() return 0; } - -// data must be word aligned -PICO_INTERNAL void SekState(int *data) +void SekStepM68k(void) { -#ifdef EMU_C68K - memcpy32(data,(int *)PicoCpuCM68k.d,0x44/4); - data[0x11] = PicoCpuCM68k.flags; + SekCycleAim=SekCycleCnt+1; +#if defined(EMU_CORE_DEBUG) + SekCycleCnt+=CM_compareRun(1, 0); +#elif defined(EMU_C68K) + PicoCpuCM68k.cycles=1; + CycloneRun(&PicoCpuCM68k); + SekCycleCnt+=1-PicoCpuCM68k.cycles; #elif defined(EMU_M68K) - memcpy32(data, (int *)PicoCpuMM68k.dar, 0x40/4); - data[0x10] = PicoCpuMM68k.pc; - data[0x11] = m68k_get_reg(&PicoCpuMM68k, M68K_REG_SR); + SekCycleCnt+=m68k_execute(1); #elif defined(EMU_F68K) - memcpy32(data, (int *)PicoCpuFM68k.dreg, 0x40/4); - data[0x10] = PicoCpuFM68k.pc; - data[0x11] = PicoCpuFM68k.sr; + SekCycleCnt+=fm68k_emulate(1, 0, 0); #endif } @@ -193,6 +189,7 @@ PICO_INTERNAL void SekSetRealTAS(int use_real) #endif } + /* idle loop detection, not to be used in CD mode */ #ifdef EMU_C68K #include "cpu/Cyclone/tools/idle.h" @@ -202,9 +199,24 @@ static int *idledet_addrs = NULL; static int idledet_count = 0, idledet_bads = 0; int idledet_start_frame = 0; -static int jump_verify[0x10000]; -extern int CycloneJumpTab[]; -static unsigned char *rom_verify = NULL; +#if 0 +#define IDLE_STATS 1 +unsigned int idlehit_addrs[128], idlehit_counts[128]; + +void SekRegisterIdleHit(unsigned int pc) +{ + int i; + for (i = 0; i < 127 && idlehit_addrs[i]; i++) { + if (idlehit_addrs[i] == pc) { + idlehit_counts[i]++; + return; + } + } + idlehit_addrs[i] = pc; + idlehit_counts[i] = 1; + idlehit_addrs[i+1] = 0; +} +#endif void SekInitIdleDet(void) { @@ -217,46 +229,57 @@ void SekInitIdleDet(void) idledet_addrs = tmp; idledet_count = idledet_bads = 0; idledet_start_frame = Pico.m.frame_count + 360; +#ifdef IDLE_STATS + idlehit_addrs[0] = 0; +#endif - memcpy(jump_verify, CycloneJumpTab, 0x10000*4); - rom_verify = realloc(rom_verify, Pico.romsize); - memcpy(rom_verify, Pico.rom, Pico.romsize); #ifdef EMU_C68K CycloneInitIdle(); #endif +#ifdef EMU_F68K + fm68k_emulate(0, 0, 1); +#endif } int SekIsIdleCode(unsigned short *dst, int bytes) { - printf("SekIsIdleCode %04x %i\n", *dst, bytes); + // printf("SekIsIdleCode %04x %i\n", *dst, bytes); switch (bytes) { + case 2: + if ((*dst & 0xf000) != 0x6000) // not another branch + return 1; + break; case 4: - if ( (*dst & 0xfff8) == 0x4a10 || // tst.b ($aX) // where should be no need to wait - (*dst & 0xfff8) == 0x4a28 || // tst.b ($xxxx,a0) // for byte change anywhere - (*dst & 0xff3f) == 0x4a38 || // tst.x ($xxxx.w), tas ($xxxx.w) + if ( (*dst & 0xfff8) == 0x4a10 || // tst.b ($aX) // there should be no need to wait + (*dst & 0xfff8) == 0x4a28 || // tst.b ($xxxx,a0) // for byte change anywhere + (*dst & 0xff3f) == 0x4a38 || // tst.x ($xxxx.w); tas ($xxxx.w) (*dst & 0xc1ff) == 0x0038 || // move.x ($xxxx.w), dX (*dst & 0xf13f) == 0xb038) // cmp.x ($xxxx.w), dX return 1; break; case 6: - if ( ((dst[1] & 0xe0) == 0xe0 && ( // RAM - *dst == 0x4a39 || // tst.b ($xxxxxxxx) - *dst == 0x4a79 || // tst.w ($xxxxxxxx) - *dst == 0x4ab9)) || // tst.l ($xxxxxxxx) - *dst == 0x0838) // btst $X, ($xxxx.w) [6 byte op] + if ( ((dst[1] & 0xe0) == 0xe0 && ( // RAM and + *dst == 0x4a39 || // tst.b ($xxxxxxxx) + *dst == 0x4a79 || // tst.w ($xxxxxxxx) + *dst == 0x4ab9 || // tst.l ($xxxxxxxx) + (*dst & 0xc1ff) == 0x0039 || // move.x ($xxxxxxxx), dX + (*dst & 0xf13f) == 0xb039))||// cmp.x ($xxxxxxxx), dX + *dst == 0x0838 || // btst $X, ($xxxx.w) [6 byte op] + (*dst & 0xffbf) == 0x0c38) // cmpi.{b,w} $X, ($xxxx.w) return 1; break; case 8: - if ( (dst[2] & 0xe0) == 0xe0 && ( // RAM - *dst == 0x0839 || // btst $X, ($xxxxxxxx.w) [8 byte op] - (*dst & 0xffbf) == 0x0c39)) // cmpi.{b,w} $X, ($xxxxxxxx) + if ( ((dst[2] & 0xe0) == 0xe0 && ( // RAM and + *dst == 0x0839 || // btst $X, ($xxxxxxxx.w) [8 byte op] + (*dst & 0xffbf) == 0x0c39))||// cmpi.{b,w} $X, ($xxxxxxxx) + *dst == 0x0cb8) // cmpi.l $X, ($xxxx.w) return 1; break; case 12: if ((*dst & 0xf1f8) == 0x3010 && // move.w (aX), dX - (dst[1]&0xf100) == 0x0000 && // arithmetic - (dst[3]&0xf100) == 0x0000) // arithmetic + (dst[1]&0xf100) == 0x0000 && // arithmetic + (dst[3]&0xf100) == 0x0000) // arithmetic return 1; break; } @@ -264,14 +287,21 @@ int SekIsIdleCode(unsigned short *dst, int bytes) return 0; } -int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop) +int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx) { -#ifdef EMU_C68K - pc -= PicoCpuCM68k.membase; + int is_main68k = 1; +#if defined(EMU_C68K) + struct Cyclone *cyc = ctx; + is_main68k = cyc == &PicoCpuCM68k; + pc -= cyc->membase; +#elif defined(EMU_F68K) + is_main68k = ctx == &PicoCpuFM68k; #endif pc &= ~0xff000000; - elprintf(EL_IDLE, "idle: patch %06x %04x %04x #%i", pc, oldop, newop, idledet_count); - if (pc > Pico.romsize) { + elprintf(EL_IDLE, "idle: patch %06x %04x %04x %c %c #%i", pc, oldop, newop, + (newop&0x200)?'n':'y', is_main68k?'m':'s', idledet_count); + + if (pc > Pico.romsize && !(PicoAHW & PAHW_SVP)) { if (++idledet_bads > 128) return 2; // remove detector return 1; // don't patch } @@ -282,15 +312,19 @@ int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop) idledet_addrs = tmp; } - idledet_addrs[idledet_count++] = pc; + if (pc < Pico.romsize) + idledet_addrs[idledet_count++] = pc; + return 0; } void SekFinishIdleDet(void) { - int done_something = idledet_count > 0; #ifdef EMU_C68K CycloneFinishIdle(); +#endif +#ifdef EMU_F68K + fm68k_emulate(0, 0, 2); #endif while (idledet_count > 0) { @@ -304,17 +338,6 @@ void SekFinishIdleDet(void) else elprintf(EL_STATUS|EL_IDLE, "idle: don't know how to restore %04x", *op); } - - if (done_something) - { - int i; - for (i = 0; i < 0x10000; i++) - if (jump_verify[i] != CycloneJumpTab[i]) - printf("jumptab corruption @ %04x!\n", i), exit(1); - for (i = 0; i < Pico.romsize; i++) - if (rom_verify[i] != Pico.rom[i]) - printf("ROM corruption @ %06x!\n", i), exit(1); - } }