famec: split fm68k_emulate

in FAMEC_NO_GOTOS mode at least
This commit is contained in:
notaz 2017-10-15 00:45:55 +03:00
parent fdcfd32374
commit 12f23dac6f
8 changed files with 83 additions and 34 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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

View file

@ -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)
{