X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2Ffame%2Ffamec.c;h=db4eae692c919ee3590e2ee4ce90a26ae56128ae;hb=c041308933a54fce3b1e98b0228e19f96475ae40;hp=19657fc6e6e81ce62158ceccbb2e0f9a25f02c26;hpb=10d84cb2757db05bf7d66ef33575c52ed4b22053;p=picodrive.git diff --git a/cpu/fame/famec.c b/cpu/fame/famec.c index 19657fc..db4eae6 100644 --- a/cpu/fame/famec.c +++ b/cpu/fame/famec.c @@ -11,6 +11,10 @@ #include #include +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + #include "fame.h" @@ -20,7 +24,7 @@ #define FAMEC_CHECK_BRANCHES #define FAMEC_EXTRA_INLINE // #define FAMEC_DEBUG -#define FAMEC_NO_GOTOS +// #define FAMEC_NO_GOTOS #define FAMEC_ADR_BITS 24 // #define FAMEC_FETCHBITS 8 #define FAMEC_DATABITS 8 @@ -31,7 +35,17 @@ #define PICODRIVE_HACK // Options // - +#ifndef FAMEC_NO_GOTOS +// computed gotos is a GNU extension +#ifndef __GNUC__ +#define FAMEC_NO_GOTOS +#endif +// as of 3.3, clang takes over 3h to compile this in computed goto mode.. +#ifdef __clang__ +#define FAMEC_NO_GOTOS +#endif +#endif + #undef INLINE #ifdef _MSC_VER #define INLINE @@ -70,12 +84,17 @@ #undef s32 #endif +#ifdef uptr +#undef uptr +#endif + #define u8 unsigned char #define s8 signed char #define u16 unsigned short #define s16 signed short #define u32 unsigned int #define s32 signed int +#define uptr unsigned long /* typedef unsigned char u8; @@ -262,6 +281,10 @@ typedef signed int s32; goto famec_Exec; #endif +#define RET0() \ + m68kcontext.io_cycle_counter = -6; \ + goto famec_End; + #else #define NEXT \ @@ -274,12 +297,16 @@ typedef signed int s32; m68kcontext.io_cycle_counter -= (A); \ return; +#define RET0() \ + m68kcontext.io_cycle_counter = -6; \ + return; + #endif #define M68K_PPL (m68kcontext.sr >> 8) & 7 #define GET_PC \ - ((u32)PC - BasePC) + (u32)((uptr)PC - BasePC) #ifdef FAMEC_CHECK_BRANCHES @@ -503,8 +530,6 @@ typedef signed int s32; #endif -static int init_jump_table(void); - // global variable /////////////////// @@ -513,22 +538,20 @@ M68K_CONTEXT *g_m68kcontext; #define m68kcontext (*g_m68kcontext) #ifdef FAMEC_NO_GOTOS -static u32 Opcode; -static s32 cycles_needed; -static u16 *PC; -static u32 BasePC; -static u32 flag_C; -static u32 flag_V; -static u32 flag_NotZ; -static u32 flag_N; -static u32 flag_X; +#define Opcode m68kcontext.Opcode +#define cycles_needed m68kcontext.cycles_needed +#define PC m68kcontext.PC +#define BasePC m68kcontext.BasePC +#define flag_C m68kcontext.flag_C +#define flag_V m68kcontext.flag_V +#define flag_NotZ m68kcontext.flag_NotZ +#define flag_N m68kcontext.flag_N +#define flag_X m68kcontext.flag_X #endif -#ifdef FAMEC_EMULATE_TRACE -static u32 flag_T; -#endif -static u32 flag_S; -static u32 flag_I; +#define flag_T m68kcontext.flag_T +#define flag_S m68kcontext.flag_S +#define flag_I m68kcontext.flag_I static u32 initialised = 0; @@ -691,7 +714,7 @@ int fm68k_reset(void) u32 fm68k_get_pc(M68K_CONTEXT *context) { #ifdef FAMEC_NO_GOTOS - return (context->execinfo & M68K_RUNNING)?(u32)PC-BasePC:context->pc; + return (context->execinfo & M68K_RUNNING)?(uptr)PC-BasePC:context->pc; #else return context->pc; // approximate PC in this mode #endif @@ -719,6 +742,9 @@ static FAMEC_EXTRA_INLINE u32 execute_exception(s32 vect, u32 oldPC, u32 oldSR) //u32 oldSR = GET_SR; m68kcontext.io_cycle_counter -= exception_cycle_table[vect]; +#ifdef FAMEC_EMULATE_TRACE + m68kcontext.execinfo &= ~FM68K_EMULATE_TRACE; +#endif PRE_IO @@ -740,6 +766,7 @@ static FAMEC_EXTRA_INLINE u32 execute_exception(s32 vect, u32 oldPC, u32 oldSR) /* adjust SR */ flag_S = M68K_SR_S; + flag_T = 0; #ifndef FAMEC_32BIT_PC newPC&=M68K_ADR_MASK @@ -770,8 +797,6 @@ static FAMEC_EXTRA_INLINE u32 execute_exception_group_0(s32 vect, s32 addr, u16 } -static void setup_jumptable(void); - #ifdef FAMEC_NO_GOTOS #define OPCODE(N_OP) static void OP_##N_OP(void) @@ -783,13 +808,13 @@ static void setup_jumptable(void); // main exec function ////////////////////// -int fm68k_emulate(s32 cycles, int dualcore) +int fm68k_emulate(s32 cycles, int idle_mode) { #ifndef FAMEC_NO_GOTOS u32 Opcode; s32 cycles_needed; u16 *PC; - u32 BasePC; + uptr BasePC; u32 flag_C; u32 flag_V; u32 flag_NotZ; @@ -799,17 +824,12 @@ int fm68k_emulate(s32 cycles, int dualcore) if (!initialised) { -#ifdef FAMEC_NO_GOTOS - init_jump_table(); - return 0; -#else goto init_jump_table; -#endif } #ifdef PICODRIVE_HACK - if (dualcore) goto dualcore_mode; -famec_restart: + if (idle_mode == 1) goto idle_install; + else if (idle_mode == 2) goto idle_remove; #endif // won't emulate double fault @@ -900,12 +920,11 @@ famec_Exec: #ifdef FAMEC_EMULATE_TRACE if (m68kcontext.execinfo & FM68K_EMULATE_TRACE) { - m68kcontext.io_cycle_counter = cycles_needed; + m68kcontext.io_cycle_counter += cycles_needed; cycles_needed = 0; m68kcontext.execinfo &= ~FM68K_EMULATE_TRACE; m68kcontext.execinfo |= FM68K_DO_TRACE; SET_PC(execute_exception(M68K_TRACE_EX, GET_PC, GET_SR)); - flag_T=0; if (m68kcontext.io_cycle_counter > 0) { //NEXT @@ -917,8 +936,9 @@ famec_Exec: if (cycles_needed != 0) { u32 line; - m68kcontext.io_cycle_counter = cycles_needed; + m68kcontext.io_cycle_counter += cycles_needed; cycles_needed = 0; + //if (m68kcontext.io_cycle_counter <= 0) goto famec_End; line=interrupt_chk__(); if (line>0) { @@ -953,70 +973,10 @@ famec_End: printf("pc: 0x%08x\n",m68kcontext.pc); #endif -#ifdef PICODRIVE_HACK - if (!dualcore) -#endif - return cycles - m68kcontext.io_cycle_counter; + return cycles - m68kcontext.io_cycle_counter; -#ifdef PICODRIVE_HACK -dualcore_mode: - - while (1) - { - extern int SekCycleAim, SekCycleCnt, SekCycleAimS68k, SekCycleCntS68k; - #define PS_STEP_M68K ((488<<16)/20) // ~24 - if (dualcore == 1) - { - dualcore = (488<<16); // ~ cycn in Pico.c - // adjust for first iteration - g_m68kcontext = &PicoCpuFS68k; - cycles = m68kcontext.io_cycle_counter = 0; - } - if (g_m68kcontext == &PicoCpuFS68k) - { - SekCycleCntS68k += cycles - m68kcontext.io_cycle_counter; - // end? - dualcore -= PS_STEP_M68K; - if (dualcore < 0) return 0; - // become main 68k - g_m68kcontext = &PicoCpuFM68k; - if ((cycles = SekCycleAim-SekCycleCnt-(dualcore>>16)) > 0) - { - if ((m68kcontext.execinfo & FM68K_HALTED) && m68kcontext.interrupts[0] <= (M68K_PPL)) - SekCycleCnt += cycles; // halted - else goto famec_restart; - //else { printf("go main %i\n", cycles); goto famec_restart; } - } - cycles = m68kcontext.io_cycle_counter = 0; - } - if (g_m68kcontext == &PicoCpuFM68k) - { - int cycn_s68k = (dualcore + dualcore/2 + dualcore/8) >> 16; - SekCycleCnt += cycles - m68kcontext.io_cycle_counter; - // become sub 68k - g_m68kcontext = &PicoCpuFS68k; - if ((cycles = SekCycleAimS68k-SekCycleCntS68k-cycn_s68k) > 0) - { - if ((m68kcontext.execinfo & FM68K_HALTED) && m68kcontext.interrupts[0] <= (M68K_PPL)) - SekCycleCntS68k += cycles; // halted - else goto famec_restart; - } - cycles = m68kcontext.io_cycle_counter = 0; - } - } -#endif - - - -#ifdef FAMEC_NO_GOTOS -} - -static int init_jump_table(void) -{{ -#else init_jump_table: { -#endif u32 i, j; for(i = 0x0000; i <= 0xFFFF; i += 0x0001) @@ -5032,6 +4992,49 @@ init_jump_table: initialised = 1; return 0; -}} +} + +#ifdef PICODRIVE_HACK + +#define INSTALL_IDLE(fake_op_base,real_op,detector,idle_handler,normal_handler) \ + JumpTable[fake_op_base] = CAST_OP(idle_handler); \ + JumpTable[fake_op_base|0x0200] = CAST_OP(normal_handler); \ + JumpTable[real_op] = CAST_OP(detector) + +#define UNDO_IDLE(fake_op_base,real_op,normal_handler) \ + JumpTable[fake_op_base] = JumpTable[fake_op_base|0x0200] = CAST_OP(0x4AFC); \ + JumpTable[real_op] = CAST_OP(normal_handler) + +idle_install: + // printf("install..\n"); + INSTALL_IDLE(0x71fa, 0x66fa, idle_detector_bcc8, 0x6601_idle, 0x6601); + INSTALL_IDLE(0x71f8, 0x66f8, idle_detector_bcc8, 0x6601_idle, 0x6601); + INSTALL_IDLE(0x71f6, 0x66f6, idle_detector_bcc8, 0x6601_idle, 0x6601); + INSTALL_IDLE(0x71f2, 0x66f2, idle_detector_bcc8, 0x6601_idle, 0x6601); + INSTALL_IDLE(0x75fa, 0x67fa, idle_detector_bcc8, 0x6701_idle, 0x6701); + INSTALL_IDLE(0x75f8, 0x67f8, idle_detector_bcc8, 0x6701_idle, 0x6701); + INSTALL_IDLE(0x75f6, 0x67f6, idle_detector_bcc8, 0x6701_idle, 0x6701); + INSTALL_IDLE(0x75f2, 0x67f2, idle_detector_bcc8, 0x6701_idle, 0x6701); + INSTALL_IDLE(0x7dfe, 0x60fe, idle_detector_bcc8, 0x6001_idle, 0x6001); + INSTALL_IDLE(0x7dfc, 0x60fc, idle_detector_bcc8, 0x6001_idle, 0x6001); + return 0; + +idle_remove: + // printf("remove..\n"); + UNDO_IDLE(0x71fa, 0x66fa, 0x6601); + UNDO_IDLE(0x71f8, 0x66f8, 0x6601); + UNDO_IDLE(0x71f6, 0x66f6, 0x6601); + UNDO_IDLE(0x71f2, 0x66f2, 0x6601); + UNDO_IDLE(0x75fa, 0x67fa, 0x6701); + UNDO_IDLE(0x75f8, 0x67f8, 0x6701); + UNDO_IDLE(0x75f6, 0x67f6, 0x6701); + UNDO_IDLE(0x75f2, 0x67f2, 0x6701); + UNDO_IDLE(0x7dfe, 0x60fe, 0x6001); + UNDO_IDLE(0x7dfc, 0x60fc, 0x6001); + return 0; + +#endif +} +void *get_jumptab(void) { return JumpTable; }