X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fsek.c;h=8bf0341b492a9b82e57c4308ce8f466a18a5d18e;hb=40d22a8e7610b2fdde5cfe6178605262ef0d61d7;hp=2fe77cbb7496d17674c2b99fe07147001917a2ad;hpb=12da51c27a8d1c1205d8f0f01bbc4814c46e79ce;p=picodrive.git diff --git a/pico/sek.c b/pico/sek.c index 2fe77cb..8bf0341 100644 --- a/pico/sek.c +++ b/pico/sek.c @@ -11,9 +11,8 @@ #include "memory.h" -int SekCycleCnt=0; // cycles done in this frame -int SekCycleAim=0; // cycle aim -unsigned int SekCycleCntT=0; +unsigned int SekCycleCnt; +unsigned int SekCycleAim; /* context */ @@ -61,6 +60,8 @@ static int SekUnrecognizedOpcode() PicoCpuCM68k.state_flags |= 1; return 1; } + // happened once - may happen again + SekFinishIdleDet(); #ifdef EMU_M68K // debugging cyclone { extern int have_illegal; @@ -91,8 +92,14 @@ static int SekTasCallback(void) #ifdef EMU_F68K static void SekIntAckF68K(unsigned level) { - if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); } - else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); } + if (level == 4) { + Pico.video.pending_ints = 0; + elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCyclesDone()); + } + else if(level == 6) { + Pico.video.pending_ints &= ~0x20; + elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCyclesDone()); + } PicoCpuFM68k.interrupts[0] = 0; } #endif @@ -171,7 +178,7 @@ void SekStepM68k(void) #elif defined(EMU_M68K) SekCycleCnt+=m68k_execute(1); #elif defined(EMU_F68K) - SekCycleCnt+=fm68k_emulate(1, 0, 0); + SekCycleCnt+=fm68k_emulate(1, 0); #endif } @@ -220,7 +227,8 @@ PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub) #endif *(unsigned int *)(cpu+0x40) = pc; - *(unsigned int *)(cpu+0x50) = SekCycleCntT; + *(unsigned int *)(cpu+0x50) = + is_sub ? SekCycleCntS68k : SekCycleCnt; } PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) @@ -257,7 +265,10 @@ PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) context->execinfo &= ~FM68K_HALTED; if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED; #endif - SekCycleCntT = *(unsigned int *)(cpu+0x50); + if (is_sub) + SekCycleCntS68k = *(unsigned int *)(cpu+0x50); + else + SekCycleCnt = *(unsigned int *)(cpu+0x50); } @@ -268,7 +279,7 @@ PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) static unsigned short **idledet_ptrs = NULL; static int idledet_count = 0, idledet_bads = 0; -int idledet_start_frame = 0; +static int idledet_start_frame = 0; #if 0 #define IDLE_STATS 1 @@ -308,10 +319,15 @@ void SekInitIdleDet(void) CycloneInitIdle(); #endif #ifdef EMU_F68K - fm68k_emulate(0, 0, 1); + fm68k_emulate(0, 1); #endif } +int SekIsIdleReady(void) +{ + return (Pico.m.frame_count >= idledet_start_frame); +} + int SekIsIdleCode(unsigned short *dst, int bytes) { // printf("SekIsIdleCode %04x %i\n", *dst, bytes); @@ -322,11 +338,16 @@ int SekIsIdleCode(unsigned short *dst, int bytes) 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 - (*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 + if ( (*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; + if (PicoAHW & (PAHW_MCD|PAHW_32X)) + break; + // with no addons, there should be no need to wait + // for byte change anywhere + if ( (*dst & 0xfff8) == 0x4a10 || // tst.b ($aX) + (*dst & 0xfff8) == 0x4a28) // tst.b ($xxxx,a0) return 1; break; case 6: @@ -348,7 +369,9 @@ int SekIsIdleCode(unsigned short *dst, int bytes) return 1; break; case 12: - if ((*dst & 0xf1f8) == 0x3010 && // move.w (aX), dX + if (PicoAHW & (PAHW_MCD|PAHW_32X)) + break; + if ( (*dst & 0xf1f8) == 0x3010 && // move.w (aX), dX (dst[1]&0xf100) == 0x0000 && // arithmetic (dst[3]&0xf100) == 0x0000) // arithmetic return 1; @@ -372,6 +395,7 @@ int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx) is_main68k = ctx == &PicoCpuFM68k; #endif pc &= ~0xff000000; + if (!(newop&0x200)) elprintf(EL_IDLE, "idle: patch %06x %04x %04x %c %c #%i", pc, oldop, newop, (newop&0x200)?'n':'y', is_main68k?'m':'s', idledet_count); @@ -399,11 +423,13 @@ int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx) void SekFinishIdleDet(void) { + if (idledet_count < 0) + return; #ifdef EMU_C68K CycloneFinishIdle(); #endif #ifdef EMU_F68K - fm68k_emulate(0, 0, 2); + fm68k_emulate(0, 2); #endif while (idledet_count > 0) { @@ -417,6 +443,7 @@ void SekFinishIdleDet(void) else elprintf(EL_STATUS|EL_IDLE, "idle: don't know how to restore %04x", *op); } + idledet_count = -1; } @@ -527,6 +554,7 @@ breakloop: printf("D%d: %08x A%d: %08x\n", i, x68k->dar[i], i, x68k->dar[i + 8]); printf("PC: %08x, %08x\n", x68k->pc, x68k->pc_prev); + printf("SR: %04x\n", x68k->sr); PDebugDumpMem(); exit(1);