\r
extern M68K_CONTEXT *g_m68kcontext;\r
\r
+typedef enum\r
+{\r
+ fm68k_reason_emulate = 0,\r
+ fm68k_reason_init,\r
+ fm68k_reason_idle_install,\r
+ fm68k_reason_idle_remove,\r
+} fm68k_call_reason;\r
+\r
/************************/\r
/* Function definition */\r
/************************/\r
\r
/* General purpose functions */\r
void fm68k_init(void);\r
-int fm68k_reset(void);\r
-int fm68k_emulate(int n, int idle_mode);\r
-int fm68k_would_interrupt(void); // to be called from fm68k_emulate()\r
+int fm68k_reset(M68K_CONTEXT *ctx);\r
+int fm68k_emulate(M68K_CONTEXT *ctx, int n, fm68k_call_reason reason);\r
+int fm68k_would_interrupt(M68K_CONTEXT *ctx); // to be called from fm68k_emulate()\r
\r
-unsigned fm68k_get_pc(M68K_CONTEXT *context);\r
+unsigned fm68k_get_pc(M68K_CONTEXT *ctx);\r
\r
+// PICODRIVE_HACK\r
+int fm68k_idle_install(void);\r
+int fm68k_idle_remove(void);\r
\r
#ifdef __cplusplus\r
}\r
static u32 initialised = 0;\r
\r
#ifdef PICODRIVE_HACK\r
-extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k;\r
+extern M68K_CONTEXT PicoCpuFS68k;\r
#endif\r
\r
/* Custom function handler */\r
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\r
};\r
\r
+static int init_jump_table(void);\r
\r
/***********************/\r
/* core main functions */\r
puts("Initializing FAME...");\r
#endif\r
\r
- if (!initialised)\r
- fm68k_emulate(0, 0);\r
+ if (!initialised)\r
+ init_jump_table();\r
\r
#ifdef FAMEC_DEBUG\r
puts("FAME initialized.");\r
/* M68K_NO_SUP_ADDR_SPACE (2): No se puede resetear porque no hay mapa */\r
/* de memoria supervisor de extraccion de opcodes */\r
/******************************************************************************/\r
-int fm68k_reset(void)\r
+int fm68k_reset(M68K_CONTEXT *ctx)\r
{\r
if (!initialised)\r
- fm68k_emulate(0, 0);\r
+ init_jump_table();\r
+\r
+ g_m68kcontext = ctx;\r
\r
// Si la CPU esta en ejecucion, salir con M68K_RUNNING\r
if (m68kcontext.execinfo & M68K_RUNNING)\r
return 0;\r
}\r
\r
-int fm68k_would_interrupt(void)\r
+int fm68k_would_interrupt(M68K_CONTEXT *ctx)\r
{\r
return interrupt_chk__();\r
}\r
// main exec function\r
//////////////////////\r
\r
-int fm68k_emulate(s32 cycles, int idle_mode)\r
+int fm68k_emulate(M68K_CONTEXT *ctx, s32 cycles, fm68k_call_reason reason)\r
{\r
#ifndef FAMEC_NO_GOTOS\r
u32 Opcode;\r
u32 flag_NotZ;\r
u32 flag_N;\r
u32 flag_X;\r
-#endif\r
\r
- if (!initialised)\r
+ switch (reason)\r
{\r
+ case fm68k_reason_init:\r
goto init_jump_table;\r
- }\r
-\r
#ifdef PICODRIVE_HACK\r
- if (idle_mode == 1) goto idle_install;\r
- else if (idle_mode == 2) goto idle_remove;\r
+ case fm68k_reason_idle_install:\r
+ goto idle_install;\r
+ case fm68k_reason_idle_remove:\r
+ goto idle_remove;\r
#endif\r
+ case fm68k_reason_emulate:\r
+ break;\r
+ }\r
+#endif // FAMEC_NO_GOTOS\r
+\r
+ g_m68kcontext = ctx;\r
\r
// won't emulate double fault\r
// if (m68kcontext.execinfo & M68K_FAULTED) return -1;\r
\r
return cycles - m68kcontext.io_cycle_counter;\r
\r
+#ifndef FAMEC_NO_GOTOS\r
init_jump_table:\r
+#else\r
+}\r
+\r
+static int init_jump_table(void)\r
+#endif\r
{\r
u32 i, j;\r
\r
JumpTable[fake_op_base] = JumpTable[fake_op_base|0x0200] = CAST_OP(0x4AFC); \\r
JumpTable[real_op] = CAST_OP(normal_handler)\r
\r
+#ifndef FAMEC_NO_GOTOS\r
idle_install:\r
+#else\r
+int fm68k_idle_install(void)\r
+#endif\r
+{\r
// printf("install..\n");\r
INSTALL_IDLE(0x71fa, 0x66fa, idle_detector_bcc8, 0x6601_idle, 0x6601);\r
INSTALL_IDLE(0x71f8, 0x66f8, idle_detector_bcc8, 0x6601_idle, 0x6601);\r
INSTALL_IDLE(0x7dfe, 0x60fe, idle_detector_bcc8, 0x6001_idle, 0x6001);\r
INSTALL_IDLE(0x7dfc, 0x60fc, idle_detector_bcc8, 0x6001_idle, 0x6001);\r
return 0;\r
+}\r
\r
+#ifndef FAMEC_NO_GOTOS\r
idle_remove:\r
+#else\r
+int fm68k_idle_remove(void)\r
+#endif\r
+{\r
// printf("remove..\n");\r
UNDO_IDLE(0x71fa, 0x66fa, 0x6601);\r
UNDO_IDLE(0x71f8, 0x66f8, 0x6601);\r
UNDO_IDLE(0x7dfe, 0x60fe, 0x6001);\r
UNDO_IDLE(0x7dfc, 0x60fc, 0x6001);\r
return 0;\r
+}\r
+#endif // PICODRIVE_HACK\r
\r
-#endif\r
+#ifndef FAMEC_NO_GOTOS\r
}\r
\r
-void *get_jumptab(void) { return JumpTable; }\r
+static int init_jump_table(void)\r
+{\r
+ return fm68k_emulate(NULL, 0, fm68k_reason_init);\r
+}\r
+\r
+#ifdef PICODRIVE_HACK\r
+int fm68k_idle_install(void)\r
+{\r
+ return fm68k_emulate(NULL, 0, fm68k_reason_idle_install);\r
+}\r
\r
+int fm68k_idle_remove(void)\r
+{\r
+ return fm68k_emulate(NULL, 0, fm68k_reason_idle_remove);\r
+}\r
+#endif\r
+#endif // FAMEC_NO_GOTOS\r