X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fsek.c;h=517652878e74b1f55aac7b3d0c4f3cd47a6de7fc;hb=8f80007bcc94faae7c369d4ed8a07a9d35c31c72;hp=39168a9a22c82ce6eed3f1afd960a9a415ac0d78;hpb=d4d626658a7a999f48009f408b4a22d280ab80ea;p=picodrive.git diff --git a/pico/sek.c b/pico/sek.c index 39168a9..5176528 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 } @@ -219,7 +226,9 @@ PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub) cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0; #endif - *(unsigned int *)(cpu+0x40)=pc; + *(unsigned int *)(cpu+0x40) = pc; + *(unsigned int *)(cpu+0x50) = + is_sub ? SekCycleCntS68k : SekCycleCnt; } PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub) @@ -256,6 +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 + if (is_sub) + SekCycleCntS68k = *(unsigned int *)(cpu+0x50); + else + SekCycleCnt = *(unsigned int *)(cpu+0x50); } @@ -266,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 @@ -289,7 +302,8 @@ void SekRegisterIdleHit(unsigned int pc) void SekInitIdleDet(void) { - unsigned short **tmp = realloc(idledet_ptrs, 0x200*4); + unsigned short **tmp; + tmp = realloc(idledet_ptrs, 0x200 * sizeof(tmp[0])); if (tmp == NULL) { free(idledet_ptrs); idledet_ptrs = NULL; @@ -306,10 +320,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); @@ -320,11 +339,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: @@ -346,7 +370,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; @@ -370,6 +396,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); @@ -384,7 +411,8 @@ int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop, void *ctx) } if (idledet_count >= 0x200 && (idledet_count & 0x1ff) == 0) { - unsigned short **tmp = realloc(idledet_ptrs, (idledet_count+0x200)*4); + unsigned short **tmp; + tmp = realloc(idledet_ptrs, (idledet_count+0x200) * sizeof(tmp[0])); if (tmp == NULL) return 1; idledet_ptrs = tmp; @@ -397,11 +425,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) { @@ -415,9 +445,127 @@ void SekFinishIdleDet(void) else elprintf(EL_STATUS|EL_IDLE, "idle: don't know how to restore %04x", *op); } + idledet_count = -1; } +#if defined(CPU_CMP_R) || defined(CPU_CMP_W) +#include "debug.h" + +struct ref_68k { + u32 dar[16]; + u32 pc; + u32 sr; + u32 cycles; + u32 pc_prev; +}; +struct ref_68k ref_68ks[2]; +static int current_68k; + +void SekTrace(int is_s68k) +{ + struct ref_68k *x68k = &ref_68ks[is_s68k]; + u32 pc = is_s68k ? SekPcS68k : SekPc; + u32 sr = is_s68k ? SekSrS68k : SekSr; + u32 cycles = is_s68k ? SekCycleCntS68k : SekCycleCnt; + u32 r; + u8 cmd; +#ifdef CPU_CMP_W + int i; + + if (is_s68k != current_68k) { + current_68k = is_s68k; + cmd = CTL_68K_SLAVE | current_68k; + tl_write(&cmd, sizeof(cmd)); + } + if (pc != x68k->pc) { + x68k->pc = pc; + tl_write_uint(CTL_68K_PC, x68k->pc); + } + if (sr != x68k->sr) { + x68k->sr = sr; + tl_write_uint(CTL_68K_SR, x68k->sr); + } + for (i = 0; i < 16; i++) { + r = is_s68k ? SekDarS68k(i) : SekDar(i); + if (r != x68k->dar[i]) { + x68k->dar[i] = r; + tl_write_uint(CTL_68K_R + i, r); + } + } + tl_write_uint(CTL_68K_CYCLES, cycles); +#else + int i, bad = 0; + + while (1) + { + int ret = tl_read(&cmd, sizeof(cmd)); + if (ret == 0) { + elprintf(EL_STATUS, "EOF"); + exit(1); + } + switch (cmd) { + case CTL_68K_SLAVE: + case CTL_68K_SLAVE + 1: + current_68k = cmd & 1; + break; + case CTL_68K_PC: + tl_read_uint(&x68k->pc); + break; + case CTL_68K_SR: + tl_read_uint(&x68k->sr); + break; + case CTL_68K_CYCLES: + tl_read_uint(&x68k->cycles); + goto breakloop; + default: + if (CTL_68K_R <= cmd && cmd < CTL_68K_R + 0x10) + tl_read_uint(&x68k->dar[cmd - CTL_68K_R]); + else + elprintf(EL_STATUS, "invalid cmd: %02x", cmd); + } + } + +breakloop: + if (is_s68k != current_68k) { + printf("bad 68k: %d %d\n", is_s68k, current_68k); + bad = 1; + } + if (cycles != x68k->cycles) { + printf("bad cycles: %u %u\n", cycles, x68k->cycles); + bad = 1; + } + if ((pc ^ x68k->pc) & 0xffffff) { + printf("bad PC: %08x %08x\n", pc, x68k->pc); + bad = 1; + } + if (sr != x68k->sr) { + printf("bad SR: %03x %03x\n", sr, x68k->sr); + bad = 1; + } + for (i = 0; i < 16; i++) { + r = is_s68k ? SekDarS68k(i) : SekDar(i); + if (r != x68k->dar[i]) { + printf("bad %c%d: %08x %08x\n", i < 8 ? 'D' : 'A', i & 7, + r, x68k->dar[i]); + bad = 1; + } + } + if (bad) { + for (i = 0; i < 8; i++) + 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); + } + x68k->pc_prev = x68k->pc; +#endif +} +#endif // CPU_CMP_* + #if defined(EMU_M68K) && M68K_INSTRUCTION_HOOK == OPT_SPECIFY_HANDLER static unsigned char op_flags[0x400000/2] = { 0, }; static int atexit_set = 0; @@ -445,3 +593,5 @@ void instruction_hook(void) op_flags[REG_PC/2] = 1; } #endif + +// vim:shiftwidth=2:ts=2:expandtab