From: notaz Date: Sat, 14 Oct 2017 21:45:55 +0000 (+0300) Subject: famec: split fm68k_emulate X-Git-Tag: v1.93~38 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12f23dac6f91eb707f985ef00a5d48e9e5ef8838;p=picodrive.git famec: split fm68k_emulate in FAMEC_NO_GOTOS mode at least --- diff --git a/cpu/fame/fame.h b/cpu/fame/fame.h index 2f9d8508..93172c87 100644 --- a/cpu/fame/fame.h +++ b/cpu/fame/fame.h @@ -145,18 +145,29 @@ typedef struct extern M68K_CONTEXT *g_m68kcontext; +typedef enum +{ + fm68k_reason_emulate = 0, + fm68k_reason_init, + fm68k_reason_idle_install, + fm68k_reason_idle_remove, +} fm68k_call_reason; + /************************/ /* Function definition */ /************************/ /* General purpose functions */ void fm68k_init(void); -int fm68k_reset(void); -int fm68k_emulate(int n, int idle_mode); -int fm68k_would_interrupt(void); // to be called from fm68k_emulate() +int fm68k_reset(M68K_CONTEXT *ctx); +int fm68k_emulate(M68K_CONTEXT *ctx, int n, fm68k_call_reason reason); +int fm68k_would_interrupt(M68K_CONTEXT *ctx); // to be called from fm68k_emulate() -unsigned fm68k_get_pc(M68K_CONTEXT *context); +unsigned fm68k_get_pc(M68K_CONTEXT *ctx); +// PICODRIVE_HACK +int fm68k_idle_install(void); +int fm68k_idle_remove(void); #ifdef __cplusplus } diff --git a/cpu/fame/famec.c b/cpu/fame/famec.c index db4eae69..508a12f7 100644 --- a/cpu/fame/famec.c +++ b/cpu/fame/famec.c @@ -556,7 +556,7 @@ M68K_CONTEXT *g_m68kcontext; static u32 initialised = 0; #ifdef PICODRIVE_HACK -extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k; +extern M68K_CONTEXT PicoCpuFS68k; #endif /* Custom function handler */ @@ -640,6 +640,7 @@ static const s32 exception_cycle_table[256] = 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 }; +static int init_jump_table(void); /***********************/ /* core main functions */ @@ -656,8 +657,8 @@ void fm68k_init(void) puts("Initializing FAME..."); #endif - if (!initialised) - fm68k_emulate(0, 0); + if (!initialised) + init_jump_table(); #ifdef FAMEC_DEBUG puts("FAME initialized."); @@ -673,10 +674,12 @@ void fm68k_init(void) /* M68K_NO_SUP_ADDR_SPACE (2): No se puede resetear porque no hay mapa */ /* de memoria supervisor de extraccion de opcodes */ /******************************************************************************/ -int fm68k_reset(void) +int fm68k_reset(M68K_CONTEXT *ctx) { if (!initialised) - fm68k_emulate(0, 0); + init_jump_table(); + + g_m68kcontext = ctx; // Si la CPU esta en ejecucion, salir con M68K_RUNNING if (m68kcontext.execinfo & M68K_RUNNING) @@ -731,7 +734,7 @@ static FAMEC_EXTRA_INLINE s32 interrupt_chk__(void) return 0; } -int fm68k_would_interrupt(void) +int fm68k_would_interrupt(M68K_CONTEXT *ctx) { return interrupt_chk__(); } @@ -808,7 +811,7 @@ static FAMEC_EXTRA_INLINE u32 execute_exception_group_0(s32 vect, s32 addr, u16 // main exec function ////////////////////// -int fm68k_emulate(s32 cycles, int idle_mode) +int fm68k_emulate(M68K_CONTEXT *ctx, s32 cycles, fm68k_call_reason reason) { #ifndef FAMEC_NO_GOTOS u32 Opcode; @@ -820,17 +823,23 @@ int fm68k_emulate(s32 cycles, int idle_mode) u32 flag_NotZ; u32 flag_N; u32 flag_X; -#endif - if (!initialised) + switch (reason) { + case fm68k_reason_init: goto init_jump_table; - } - #ifdef PICODRIVE_HACK - if (idle_mode == 1) goto idle_install; - else if (idle_mode == 2) goto idle_remove; + case fm68k_reason_idle_install: + goto idle_install; + case fm68k_reason_idle_remove: + goto idle_remove; #endif + case fm68k_reason_emulate: + break; + } +#endif // FAMEC_NO_GOTOS + + g_m68kcontext = ctx; // won't emulate double fault // if (m68kcontext.execinfo & M68K_FAULTED) return -1; @@ -975,7 +984,13 @@ famec_End: return cycles - m68kcontext.io_cycle_counter; +#ifndef FAMEC_NO_GOTOS init_jump_table: +#else +} + +static int init_jump_table(void) +#endif { u32 i, j; @@ -5005,7 +5020,12 @@ init_jump_table: JumpTable[fake_op_base] = JumpTable[fake_op_base|0x0200] = CAST_OP(0x4AFC); \ JumpTable[real_op] = CAST_OP(normal_handler) +#ifndef FAMEC_NO_GOTOS idle_install: +#else +int fm68k_idle_install(void) +#endif +{ // printf("install..\n"); INSTALL_IDLE(0x71fa, 0x66fa, idle_detector_bcc8, 0x6601_idle, 0x6601); INSTALL_IDLE(0x71f8, 0x66f8, idle_detector_bcc8, 0x6601_idle, 0x6601); @@ -5018,8 +5038,14 @@ idle_install: INSTALL_IDLE(0x7dfe, 0x60fe, idle_detector_bcc8, 0x6001_idle, 0x6001); INSTALL_IDLE(0x7dfc, 0x60fc, idle_detector_bcc8, 0x6001_idle, 0x6001); return 0; +} +#ifndef FAMEC_NO_GOTOS idle_remove: +#else +int fm68k_idle_remove(void) +#endif +{ // printf("remove..\n"); UNDO_IDLE(0x71fa, 0x66fa, 0x6601); UNDO_IDLE(0x71f8, 0x66f8, 0x6601); @@ -5032,9 +5058,26 @@ idle_remove: UNDO_IDLE(0x7dfe, 0x60fe, 0x6001); UNDO_IDLE(0x7dfc, 0x60fc, 0x6001); return 0; +} +#endif // PICODRIVE_HACK -#endif +#ifndef FAMEC_NO_GOTOS } -void *get_jumptab(void) { return JumpTable; } +static int init_jump_table(void) +{ + return fm68k_emulate(NULL, 0, fm68k_reason_init); +} + +#ifdef PICODRIVE_HACK +int fm68k_idle_install(void) +{ + return fm68k_emulate(NULL, 0, fm68k_reason_idle_install); +} +int fm68k_idle_remove(void) +{ + return fm68k_emulate(NULL, 0, fm68k_reason_idle_remove); +} +#endif +#endif // FAMEC_NO_GOTOS diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index af320bd0..929b57f3 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -107,7 +107,7 @@ static void SekRunM68kOnce(void) #elif defined(EMU_M68K) Pico.t.m68c_cnt += m68k_execute(cyc_do) - cyc_do; #elif defined(EMU_F68K) - Pico.t.m68c_cnt += fm68k_emulate(cyc_do, 0) - cyc_do; + Pico.t.m68c_cnt += fm68k_emulate(&PicoCpuFM68k, cyc_do, 0) - cyc_do; #endif } @@ -138,8 +138,7 @@ static void SekRunS68k(unsigned int to) SekCycleCntS68k += m68k_execute(cyc_do) - cyc_do; m68k_set_context(&PicoCpuMM68k); #elif defined(EMU_F68K) - g_m68kcontext = &PicoCpuFS68k; - SekCycleCntS68k += fm68k_emulate(cyc_do, 0) - cyc_do; + SekCycleCntS68k += fm68k_emulate(&PicoCpuFS68k, cyc_do, 0) - cyc_do; g_m68kcontext = &PicoCpuFM68k; #endif } diff --git a/pico/cd/sek.c b/pico/cd/sek.c index 42fea930..6f54801b 100644 --- a/pico/cd/sek.c +++ b/pico/cd/sek.c @@ -151,8 +151,7 @@ PICO_INTERNAL int SekResetS68k(void) #ifdef EMU_F68K { void *oldcontext = g_m68kcontext; - g_m68kcontext = &PicoCpuFS68k; - fm68k_reset(); + fm68k_reset(&PicoCpuFS68k); g_m68kcontext = oldcontext; } #endif diff --git a/pico/debugCPU.c b/pico/debugCPU.c index fd312142..36e71a7c 100644 --- a/pico/debugCPU.c +++ b/pico/debugCPU.c @@ -49,7 +49,7 @@ static int otherRun(void) CycloneRun(currentC68k); return 1-currentC68k->cycles; #elif defined(EMU_F68K) - return fm68k_emulate(1, 0); + return fm68k_emulate(g_m68kcontext, 1, 0); #endif } diff --git a/pico/pico_cmn.c b/pico/pico_cmn.c index 27a66cdf..d2a1d94c 100644 --- a/pico/pico_cmn.c +++ b/pico/pico_cmn.c @@ -38,7 +38,7 @@ static void SekSyncM68k(void) #elif defined(EMU_M68K) Pico.t.m68c_cnt += m68k_execute(cyc_do) - cyc_do; #elif defined(EMU_F68K) - Pico.t.m68c_cnt += fm68k_emulate(cyc_do, 0) - cyc_do; + Pico.t.m68c_cnt += fm68k_emulate(&PicoCpuFM68k, cyc_do, 0) - cyc_do; #endif } diff --git a/pico/pico_int.h b/pico/pico_int.h index e3bf03a8..f356d40d 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -81,7 +81,7 @@ extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k; } #define SekIsStoppedM68k() (PicoCpuFM68k.execinfo&FM68K_HALTED) #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED) -#define SekShouldInterrupt() fm68k_would_interrupt() +#define SekShouldInterrupt() fm68k_would_interrupt(&PicoCpuFM68k) #define SekNotPolling PicoCpuFM68k.not_polling #define SekNotPollingS68k PicoCpuFS68k.not_polling diff --git a/pico/sek.c b/pico/sek.c index 8fece1a3..c76a3e8e 100644 --- a/pico/sek.c +++ b/pico/sek.c @@ -157,10 +157,7 @@ PICO_INTERNAL int SekReset(void) REG_USP = 0; // ? #endif #ifdef EMU_F68K - { - g_m68kcontext = &PicoCpuFM68k; - fm68k_reset(); - } + fm68k_reset(&PicoCpuFM68k); #endif return 0; @@ -178,7 +175,7 @@ void SekStepM68k(void) #elif defined(EMU_M68K) Pico.t.m68c_cnt += m68k_execute(1); #elif defined(EMU_F68K) - Pico.t.m68c_cnt += fm68k_emulate(1, 0); + Pico.t.m68c_cnt += fm68k_emulate(&PicoCpuFM68k, 1, 0); #endif } @@ -320,7 +317,7 @@ void SekInitIdleDet(void) CycloneInitIdle(); #endif #ifdef EMU_F68K - fm68k_emulate(0, 1); + fm68k_idle_install(); #endif } @@ -431,7 +428,7 @@ void SekFinishIdleDet(void) CycloneFinishIdle(); #endif #ifdef EMU_F68K - fm68k_emulate(0, 2); + fm68k_idle_remove(); #endif while (idledet_count > 0) {