X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FSek.c;h=f72da65f9a4d0d00cbce02a6be422b4256562113;hb=6a13ef3f56a80ac698d463f5d00235ea2a090f52;hp=659850b7838b481a7044252efa85ed435a4b0b59;hpb=b06778874d140bd5187cb74444ddc40931b9bd1d;p=picodrive.git diff --git a/Pico/Sek.c b/Pico/Sek.c index 659850b..f72da65 100644 --- a/Pico/Sek.c +++ b/Pico/Sek.c @@ -163,6 +163,21 @@ PICO_INTERNAL int SekReset(void) return 0; } +void SekStepM68k(void) +{ + 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) + SekCycleCnt+=m68k_execute(1); +#elif defined(EMU_F68K) + SekCycleCnt+=fm68k_emulate(1, 0, 0); +#endif +} PICO_INTERNAL void SekSetRealTAS(int use_real) { @@ -174,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" @@ -183,7 +199,24 @@ static int *idledet_addrs = NULL; static int idledet_count = 0, idledet_bads = 0; int idledet_start_frame = 0; -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) { @@ -196,19 +229,27 @@ 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 - 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) // there should be no need to wait (*dst & 0xfff8) == 0x4a28 || // tst.b ($xxxx,a0) // for byte change anywhere @@ -246,13 +287,20 @@ 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); + 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 @@ -272,9 +320,11 @@ int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop) 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) { @@ -288,14 +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 < Pico.romsize; i++) - if (rom_verify[i] != Pico.rom[i]) - printf("ROM corruption @ %06x!\n", i), exit(1); - } }