--- hatari/src/uae-cpu/newcpu.c 2019/04/01 07:09:30 1.1.1.2 +++ hatari/src/uae-cpu/newcpu.c 2019/04/01 07:11:55 1.1.1.9 @@ -7,25 +7,29 @@ * * Adaptation to Hatari by Thomas Huth * + * This file is distributed under the GNU Public License, version 2 or at + * your option any later version. Read the file gpl.txt for details. */ +char NewCpu_rcsid[] = "Hatari $Id: newcpu.c,v 1.1.1.9 2019/04/01 07:11:55 root Exp $"; #include "sysdeps.h" #include "hatari-glue.h" #include "maccess.h" #include "memory.h" #include "newcpu.h" -#include "compiler.h" -#include "events.h" +#include "../includes/main.h" +#include "../includes/m68000.h" +#include "../includes/mfp.h" #include "../includes/tos.h" +#include "../includes/vdi.h" +#include "../includes/cart.h" +#include "../includes/debugui.h" +#include "../includes/bios.h" +#include "../includes/xbios.h" -/*int crashtrace=0;*/ -int quit_program = 0; -int debugging = 0; struct flag_struct regflags; -int lastInstructionCycles; /* how many cycles last instruction took to execute */ - /* Opcode of faulting instruction */ uae_u16 last_op_for_exception_3; /* PC at fault time */ @@ -46,6 +50,7 @@ int fpp_movem_next[256]; cpuop_func *cpufunctbl[65536]; + #define COUNT_INSTRS 0 #if COUNT_INSTRS @@ -98,26 +103,17 @@ void dump_counts (void) } #endif -int broken_in; - -static __inline__ unsigned int cft_map (unsigned int f) -{ -#ifndef HAVE_GET_WORD_UNSWAPPED - return f; -#else - return ((f >> 8) & 255) | ((f & 255) << 8); -#endif -} static unsigned long op_illg_1 (uae_u32 opcode) REGPARAM; static unsigned long REGPARAM2 op_illg_1 (uae_u32 opcode) { - op_illg (cft_map (opcode)); + op_illg (opcode); return 4; } -static void build_cpufunctbl (void) + +void build_cpufunctbl(void) { int i; unsigned long opcode; @@ -132,10 +128,10 @@ static void build_cpufunctbl (void) cpu_level, cpu_compatible, address_space_24); for (opcode = 0; opcode < 65536; opcode++) - cpufunctbl[cft_map(opcode)] = op_illg_1; + cpufunctbl[opcode] = op_illg_1; for (i = 0; tbl[i].handler != NULL; i++) { if (! tbl[i].specific) - cpufunctbl[cft_map (tbl[i].opcode)] = tbl[i].handler; + cpufunctbl[tbl[i].opcode] = tbl[i].handler; } for (opcode = 0; opcode < 65536; opcode++) { cpuop_func *f; @@ -144,41 +140,25 @@ static void build_cpufunctbl (void) continue; if (table68k[opcode].handler != -1) { - f = cpufunctbl[cft_map (table68k[opcode].handler)]; + f = cpufunctbl[table68k[opcode].handler]; if (f == op_illg_1) abort(); - cpufunctbl[cft_map(opcode)] = f; + cpufunctbl[opcode] = f; } } for (i = 0; tbl[i].handler != NULL; i++) { if (tbl[i].specific) - cpufunctbl[cft_map(tbl[i].opcode)] = tbl[i].handler; + cpufunctbl[tbl[i].opcode] = tbl[i].handler; } - /* Hataris illegal opcodes: */ - cpufunctbl[cft_map(CONDRV_OPCODE)] = OpCode_ConnectedDrive; - cpufunctbl[cft_map(TIMERD_OPCODE)] = OpCode_TimerD; + /* Hatari's illegal opcodes: */ + cpufunctbl[GEMDOS_OPCODE] = OpCode_GemDos; + cpufunctbl[SYSINIT_OPCODE] = OpCode_SysInit; + cpufunctbl[VDI_OPCODE] = OpCode_VDI; } -/* -void check_prefs_changed_cpu (void) -{ - if (currprefs.cpu_level != changed_prefs.cpu_level - || currprefs.cpu_compatible != changed_prefs.cpu_compatible) { - currprefs.cpu_level = changed_prefs.cpu_level; - currprefs.cpu_compatible = changed_prefs.cpu_compatible; - build_cpufunctbl (); - } - if (currprefs.m68k_speed != changed_prefs.m68k_speed) { - currprefs.m68k_speed = changed_prefs.m68k_speed; - reset_frame_rate_hack (); - update_68k_cycles (); - } -} -*/ - void init_m68k (void) { int i; @@ -241,7 +221,7 @@ void init_m68k (void) if (cpu_compatible) write_log (" (compatible mode)"); write_log ("\n"); - + read_table68k (); do_merges (); @@ -250,9 +230,12 @@ void init_m68k (void) build_cpufunctbl (); } + struct regstruct regs, lastint_regs; +/* not used ATM: static struct regstruct regs_backup[16]; static int backup_pointer = 0; +*/ static long int m68kpc_offset; int lastint_no; @@ -323,8 +306,7 @@ uae_s32 ShowEA (FILE *f, int reg, amodes sprintf (buffer,"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', 1 << ((dp >> 9) & 3), - disp,outer, - (unsigned long)addr); + (long)disp, (long)outer, (unsigned long)addr); } else { addr = m68k_areg(regs,reg) + (uae_s32)((uae_s8)disp8) + dispreg; sprintf (buffer,"(A%d, %c%d.%c*%d, $%02x) == $%08lx", reg, @@ -370,8 +352,7 @@ uae_s32 ShowEA (FILE *f, int reg, amodes sprintf (buffer,"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', 1 << ((dp >> 9) & 3), - disp,outer, - (unsigned long)addr); + (long)disp, (long)outer, (unsigned long)addr); } else { addr += (uae_s32)((uae_s8)disp8) + dispreg; sprintf (buffer,"(PC, %c%d.%c*%d, $%02x) == $%08lx", dp & 0x8000 ? 'A' : 'D', @@ -434,9 +415,11 @@ uae_s32 ShowEA (FILE *f, int reg, amodes return offset; } + /* The plan is that this will take over the job of exception 3 handling - * the CPU emulation functions will just do a longjmp to m68k_go whenever * they hit an odd address. */ +#if 0 static int verify_ea (int reg, amodes mode, wordsizes size, uae_u32 *val) { uae_u16 dp; @@ -445,7 +428,7 @@ static int verify_ea (int reg, amodes mo int r; uae_u32 dispreg; uaecptr addr; - uae_s32 offset = 0; + /*uae_s32 offset = 0;*/ switch (mode){ case Dreg: @@ -557,6 +540,8 @@ static int verify_ea (int reg, amodes mo last_fault_for_exception_3 = addr; return 0; } +#endif + uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp) { @@ -610,6 +595,8 @@ uae_u32 get_disp_ea_000 (uae_u32 base, u #endif } + +/* Create the Status Register from the flags */ void MakeSR (void) { #if 0 @@ -629,6 +616,8 @@ void MakeSR (void) | GET_CFLG); } + +/* Set up the flags from Status Register */ void MakeFromSR (void) { int oldm = regs.m; @@ -677,22 +666,53 @@ void MakeFromSR (void) } } - set_special (SPCFLAG_INT); + /* Pending interrupts can occur again after a write to the SR: */ + set_special (SPCFLAG_DOINT); if (regs.t1 || regs.t0) set_special (SPCFLAG_TRACE); else - unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE); + /* Keep SPCFLAG_DOTRACE, we still want a trace exception for + SR-modifying instructions (including STOP). */ + unset_special (SPCFLAG_TRACE); } + void Exception(int nr, uaecptr oldpc) { uae_u32 currpc = m68k_getpc (); /*if( nr>=2 && nr<10 ) fprintf(stderr,"Exception (-> %i bombs)!\n",nr);*/ - compiler_flush_jsr_stack(); + /* Intercept VDI exception (Trap #2 with D0 = 0x73) */ + if(bUseVDIRes && nr == 0x22 && regs.regs[0] == 0x73) + { + if(!VDI()) + { + /* Set 'PC' as address of 'VDI_OPCODE' illegal instruction + * This will call OpCode_VDI after completion of Trap call! + * Use to modify return structure from VDI */ + VDI_OldPC = currpc; + currpc = CART_VDI_OPCODE_ADDR; + } + } + +#if 0 + /* Intercept BIOS or XBIOS trap (Trap #13 or #14) */ + if (nr == 0x2d) + { + /* Intercept BIOS calls */ + if (Bios()) return; + } + else if (nr == 0x2e) + { + /* Intercept XBIOS calls */ + if (XBios()) return; + } +#endif + MakeSR(); + /* Change to supervisor mode if necessary */ if (!regs.s) { regs.usp = m68k_areg(regs, 7); if (cpu_level >= 2) @@ -701,6 +721,8 @@ void Exception(int nr, uaecptr oldpc) m68k_areg(regs, 7) = regs.isp; regs.s = 1; } + + /* Build additional exception stack frame for 68010 and higher */ if (cpu_level > 0) { if (nr == 2 || nr == 3) { int i; @@ -732,32 +754,97 @@ void Exception(int nr, uaecptr oldpc) m68k_areg(regs, 7) -= 2; put_word (m68k_areg(regs, 7), nr * 4); } - } else { - if (nr == 2 || nr == 3) { - /*crashtrace=4;*/ - /*sleep(1);*/ - m68k_areg(regs, 7) -= 12; - /* ??????? */ - if (nr == 3) { - put_long (m68k_areg(regs, 7), last_fault_for_exception_3); - put_word (m68k_areg(regs, 7)+4, last_op_for_exception_3); - put_long (m68k_areg(regs, 7)+8, last_addr_for_exception_3); - } - /*write_log ("UAE CPU Exception.\n");*/ - goto kludge_me_do; - } } + + /* Push PC on stack: */ m68k_areg(regs, 7) -= 4; put_long (m68k_areg(regs, 7), currpc); -kludge_me_do: + /* Push SR on stack: */ m68k_areg(regs, 7) -= 2; put_word (m68k_areg(regs, 7), regs.sr); + + /* 68000 bus/address errors: */ + if (cpu_level==0 && (nr==2 || nr==3)) { + uae_u16 specialstatus = 0x2001; + /* Special status word emulation isn't perfect yet... :-( */ + if (regs.sr & 0x2000) + specialstatus |= 0x4; + m68k_areg(regs, 7) -= 8; + if (nr == 3) { /* Address error */ + put_word (m68k_areg(regs, 7), specialstatus); + put_long (m68k_areg(regs, 7)+2, last_fault_for_exception_3); + put_word (m68k_areg(regs, 7)+6, last_op_for_exception_3); + put_long (m68k_areg(regs, 7)+10, last_addr_for_exception_3); + if (bEnableDebug) { + fprintf(stderr,"Address Error at address $%x, PC=$%x\n",last_fault_for_exception_3,currpc); + DebugUI(); + } + } + else { /* Bus error */ + if (bBusErrorReadWrite) + specialstatus |= 0x10; + put_word (m68k_areg(regs, 7), specialstatus); + put_long (m68k_areg(regs, 7)+2, BusAddressLocation); + put_word (m68k_areg(regs, 7)+6, get_word(BusErrorPC)); /* Opcode */ + /* Check for double bus errors: */ + if (regs.spcflags & SPCFLAG_BUSERROR) { + fprintf(stderr, "Detected double bus error at address $%x, PC=$%lx => CPU halted!\n", + BusAddressLocation, (long)currpc); + unset_special(SPCFLAG_BUSERROR); + if (bEnableDebug) + DebugUI(); + regs.intmask = 7; + m68k_setstopped(TRUE); + return; + } + if (bEnableDebug && BusAddressLocation!=0xff8a00) { + fprintf(stderr,"Bus Error at address $%x, PC=$%lx\n",BusAddressLocation,(long)currpc); + DebugUI(); + } + } + } + + /* Set PC and flags */ + if (bEnableDebug && get_long (regs.vbr + 4*nr) == 0) { + write_log("Uninitialized exception handler #%i!\n", nr); + } m68k_setpc (get_long (regs.vbr + 4*nr)); fill_prefetch_0 (); regs.t1 = regs.t0 = regs.m = 0; unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE); + + /* Handle exception cycles: */ + if(nr >= 24 && nr <= 31) + { + M68000_AddCycles(44+4); /* Interrupt */ + } + else if(nr >= 32 && nr <= 47) + { + M68000_AddCycles(34); /* Trap */ + } + else switch(nr) + { + case 2: M68000_AddCycles(50); break; /* Bus error */ + case 3: M68000_AddCycles(50); break; /* Address error */ + case 4: M68000_AddCycles(34); break; /* Illegal instruction */ + case 5: M68000_AddCycles(38); break; /* Div by zero */ + case 6: M68000_AddCycles(40); break; /* CHK */ + case 7: M68000_AddCycles(34); break; /* TRAPV */ + case 8: M68000_AddCycles(34); break; /* Privilege violation */ + case 9: M68000_AddCycles(34); break; /* Trace */ + case 10: M68000_AddCycles(34); break; /* Line-A - probably wrong */ + case 11: M68000_AddCycles(34); break; /* Line-F - probably wrong */ + default: + /* FIXME: Add right cycles value for MFP interrupts and copro exceptions ... */ + if(nr < 64) + M68000_AddCycles(4); /* Coprocessor and unassigned exceptions (???) */ + else + M68000_AddCycles(24); /* Must be a MFP interrupt */ + break; + } } + static void Interrupt(int nr) { assert(nr < 8 && nr >= 0); @@ -769,7 +856,10 @@ static void Interrupt(int nr) set_special (SPCFLAG_INT); } -static uae_u32 caar, cacr, itt0, itt1, dtt0, dtt1, tc, mmusr; + +uae_u32 reg_caar, reg_cacr; +static uae_u32 itt0, itt1, dtt0, dtt1, tc, mmusr, urp, srp; + int m68k_move2c (int regno, uae_u32 *regp) { @@ -783,19 +873,22 @@ int m68k_move2c (int regno, uae_u32 *reg switch (regno) { case 0: regs.sfc = *regp & 7; break; case 1: regs.dfc = *regp & 7; break; - case 2: cacr = *regp & (cpu_level < 4 ? 0x3 : 0x80008000); break; + case 2: reg_cacr = *regp & (cpu_level < 4 ? 0x3 : 0x80008000); break; case 3: tc = *regp & 0xc000; break; /* Mask out fields that should be zero. */ case 4: itt0 = *regp & 0xffffe364; break; case 5: itt1 = *regp & 0xffffe364; break; case 6: dtt0 = *regp & 0xffffe364; break; case 7: dtt1 = *regp & 0xffffe364; break; - + case 0x800: regs.usp = *regp; break; case 0x801: regs.vbr = *regp; break; - case 0x802: caar = *regp & 0xfc; break; + case 0x802: reg_caar = *regp & 0xfc; break; case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg(regs, 7) = regs.msp; break; case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg(regs, 7) = regs.isp; break; + case 0x805: mmusr = *regp; break; + case 0x806: urp = *regp; break; + case 0x807: srp = *regp; break; default: op_illg (0x4E7B); return 0; @@ -816,7 +909,7 @@ int m68k_movec2 (int regno, uae_u32 *reg switch (regno) { case 0: *regp = regs.sfc; break; case 1: *regp = regs.dfc; break; - case 2: *regp = cacr; break; + case 2: *regp = reg_cacr; break; case 3: *regp = tc; break; case 4: *regp = itt0; break; case 5: *regp = itt1; break; @@ -824,10 +917,12 @@ int m68k_movec2 (int regno, uae_u32 *reg case 7: *regp = dtt1; break; case 0x800: *regp = regs.usp; break; case 0x801: *regp = regs.vbr; break; - case 0x802: *regp = caar; break; + case 0x802: *regp = reg_caar; break; case 0x803: *regp = regs.m == 1 ? m68k_areg(regs, 7) : regs.msp; break; case 0x804: *regp = regs.m == 0 ? m68k_areg(regs, 7) : regs.isp; break; case 0x805: *regp = mmusr; break; + case 0x806: *regp = urp; break; + case 0x807: *regp = srp; break; default: op_illg (0x4E7A); return 0; @@ -1087,15 +1182,10 @@ void m68k_mull (uae_u32 opcode, uae_u32 } #endif } -static char* ccnames[] = -{ "T ","F ","HI","LS","CC","CS","NE","EQ", - "VC","VS","PL","MI","GE","LT","GT","LE" }; + void m68k_reset (void) { - m68k_areg (regs, 7) = get_long (ROMmem_start); - m68k_setpc (get_long (ROMmem_start+4)); - fill_prefetch_0 (); regs.s = 1; regs.m = 0; regs.stopped = 0; @@ -1106,80 +1196,38 @@ void m68k_reset (void) SET_CFLG (0); SET_VFLG (0); SET_NFLG (0); - regs.spcflags = 0; + regs.spcflags &= SPCFLAG_MODE_CHANGE; /* Clear specialflags except mode-change */ regs.intmask = 7; regs.vbr = regs.sfc = regs.dfc = 0; regs.fpcr = regs.fpsr = regs.fpiar = 0; + + m68k_areg(regs, 7) = get_long(0); + m68k_setpc(get_long(4)); + refill_prefetch (m68k_getpc(), 0); } + unsigned long REGPARAM2 op_illg (uae_u32 opcode) { +#if 0 uaecptr pc = m68k_getpc (); -/* - if (cloanto_rom && (opcode & 0xF100) == 0x7100) { - m68k_dreg (regs, (opcode >> 9) & 7) = (uae_s8)(opcode & 0xFF); - m68k_incpc (2); - fill_prefetch_0 (); - return 4; - } -*/ - compiler_flush_jsr_stack (); - if (opcode == 0x4E7B && get_long (0x10) == 0 ) - { - write_log ("This program requires a 68020 CPU!\n"); - broken_in = 1; - set_special (SPCFLAG_BRK); - quit_program = 1; - } -/* - if (opcode == 0xFF0D) { - if ((pc & 0xF80000) == 0xF80000) { - // This is from the dummy Kickstart replacement - uae_u16 arg = get_iword (2); - m68k_incpc (4); - ersatz_perform (arg); - fill_prefetch_0 (); - return 4; - } else if ((pc & 0xF80000) == 0xF00000) { - // User-mode STOP replacement - m68k_setstopped (1); - return 4; - } - } -*/ -/* - if ((opcode & 0xF000) == 0xA000 && (pc & 0xF80000) == 0xF00000) { - // Calltrap. - m68k_incpc(2); - call_calltrap (opcode & 0xFFF); - fill_prefetch_0 (); - return 4; - } -*/ - if ((opcode & 0xF000) == 0xF000) - { +#endif + if ((opcode & 0xF000) == 0xF000) { Exception(0xB,0); return 4; - } - if ((opcode & 0xF000) == 0xA000) - { -/* - if ((pc & 0xF80000) == 0xF00000) { - // Calltrap. - call_calltrap (opcode & 0xFFF); - } -*/ + } + if ((opcode & 0xF000) == 0xA000) { Exception(0xA,0); return 4; - } - -#if 1 - write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); + } +#if 0 + write_log ("Illegal instruction: %04x at %08lx\n", opcode, (long)pc); #endif Exception (4,0); return 4; } + void mmu_op(uae_u32 opcode, uae_u16 extra) { if ((opcode & 0xFE0) == 0x0500) { @@ -1232,17 +1280,43 @@ static void do_trace (void) } +/* + * Handle special flags + */ static int do_specialties (void) { - run_compiled_code(); + if(regs.spcflags & SPCFLAG_BUSERROR) { + /* We can not execute bus errors directly in the memory handler + * functions since the PC should point to the address of the next + * instruction, so we're executing the bus errors here: */ + unset_special(SPCFLAG_BUSERROR); + Exception(2,0); + } + + if(regs.spcflags & SPCFLAG_EXTRA_CYCLES) { + /* Add some extra cycles to simulate a wait state */ + unset_special(SPCFLAG_EXTRA_CYCLES); + M68000_AddCycles(4); + } + if (regs.spcflags & SPCFLAG_DOTRACE) { Exception (9,last_trace_ad); } + while (regs.spcflags & SPCFLAG_STOP) { - do_cycles (4); - /*if (regs.spcflags & SPCFLAG_COPPER) - do_copper ();*/ - if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)){ + if (regs.intmask > 5) { + /* We still have to care about events when IPL==7 ! */ + Main_EventHandler(); + if (regs.spcflags & SPCFLAG_BRK) return 1; + } + M68000_AddCycles(4); + if (PendingInterruptCount<=0 && PendingInterruptFunction) { + CALL_VAR(PendingInterruptFunction); + } + if (regs.spcflags & SPCFLAG_MFP) { + MFP_CheckPendingInterrupts(); + } + if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { int intr = intlev (); unset_special (SPCFLAG_INT | SPCFLAG_DOINT); if (intr != -1 && intr > regs.intmask) { @@ -1252,11 +1326,13 @@ static int do_specialties (void) } } } + if (regs.spcflags & SPCFLAG_TRACE) do_trace (); if (regs.spcflags & SPCFLAG_DOINT) { int intr = intlev (); + /* SPCFLAG_DOINT will be enabled again in MakeFromSR to handle pending interrupts! */ unset_special (SPCFLAG_DOINT); if (intr != -1 && intr > regs.intmask) { Interrupt (intr); @@ -1267,13 +1343,20 @@ static int do_specialties (void) unset_special (SPCFLAG_INT); set_special (SPCFLAG_DOINT); } + + if (regs.spcflags & SPCFLAG_MFP) { /* Check for MFP interrupts */ + MFP_CheckPendingInterrupts(); + } + if (regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)) { - unset_special (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); + unset_special(SPCFLAG_MODE_CHANGE); return 1; } + return 0; } + /* It's really sad to have two almost identical functions for this, but we do it all for performance... :( */ static void m68k_run_1 (void) @@ -1282,9 +1365,11 @@ static void m68k_run_1 (void) uae_u8 saved_bytes[20]; uae_u16 *oldpcp; #endif - while(!quit_program) { + + for (;;) { int cycles; uae_u32 opcode = get_iword_prefetch (0); + #ifdef DEBUG_PREFETCH if (get_ilong (0) != do_get_mem_long (®s.prefetch)) { fprintf (stderr, "Prefetch differs from memory.\n"); @@ -1296,8 +1381,7 @@ static void m68k_run_1 (void) #endif /*m68k_dumpstate(stderr, NULL);*/ - m68k_disasm(stderr, m68k_getpc (), NULL, 1); - /*if( opcode == 0 ) sleep(1);*/ + /*m68k_disasm(stderr, m68k_getpc (), NULL, 1);*/ /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1308,7 +1392,7 @@ static void m68k_run_1 (void) instrcount[opcode]++; #endif - cycles = (*cpufunctbl[cft_map(opcode)])(opcode); + cycles = (*cpufunctbl[opcode])(opcode); #ifdef DEBUG_PREFETCH if (memcmp (saved_bytes, oldpcp, 20) != 0) { @@ -1318,7 +1402,10 @@ static void m68k_run_1 (void) } #endif - do_cycles (cycles); + M68000_AddCycles(cycles); + if (PendingInterruptCount<=0 && PendingInterruptFunction) + CALL_VAR(PendingInterruptFunction); + if (regs.spcflags) { if (do_specialties ()) return; @@ -1326,23 +1413,16 @@ static void m68k_run_1 (void) } } -#define DEBUG_PREFETCH /* Same thing, but don't use prefetch to get opcode. */ static void m68k_run_2 (void) { - while(!quit_program) { + for (;;) { int cycles; -#ifdef HAVE_GET_WORD_UNSWAPPED - uae_u32 opcode = do_get_mem_word_unswapped (regs.pc_p); -#else uae_u32 opcode = get_iword (0); -#endif /*m68k_dumpstate(stderr, NULL);*/ - /*if(crashtrace) - { --crashtrace ; m68k_disasm(stderr, m68k_getpc (), NULL, 1); }*/ - /*if( opcode == 0 ) sleep(1); */ + /*m68k_disasm(stderr, m68k_getpc (), NULL, 1);*/ /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1353,9 +1433,12 @@ static void m68k_run_2 (void) instrcount[opcode]++; #endif - cycles = (*cpufunctbl[cft_map(opcode)])(opcode); + cycles = (*cpufunctbl[opcode])(opcode); + + M68000_AddCycles(cycles); + if (PendingInterruptCount<=0 && PendingInterruptFunction) + CALL_VAR(PendingInterruptFunction); - do_cycles (cycles); if (regs.spcflags) { if (do_specialties ()) return; @@ -1364,39 +1447,28 @@ static void m68k_run_2 (void) } -int in_m68k_go = 0; - void m68k_go (int may_quit) { + static int in_m68k_go = 0; + if (in_m68k_go || !may_quit) { write_log ("Bug! m68k_go is not reentrant.\n"); abort (); } in_m68k_go++; - while(!quit_program) { -/* - if (quit_program > 0) { - if (quit_program == 1) - break; - quit_program = 0; - m68k_reset (); - //reset_all_systems (); - customreset (); - } -*/ -/* - if (debugging) - debug (); -*/ + while (!(regs.spcflags & SPCFLAG_BRK)) { if(cpu_compatible) m68k_run_1(); else m68k_run_2(); } + unset_special(SPCFLAG_BRK); in_m68k_go--; } + +/* static void m68k_verify (uaecptr addr, uaecptr *nextpc) { uae_u32 opcode, val; @@ -1406,7 +1478,7 @@ static void m68k_verify (uaecptr addr, u last_op_for_exception_3 = opcode; m68kpc_offset = 2; - if (cpufunctbl[cft_map(opcode)] == op_illg_1) { + if (cpufunctbl[opcode] == op_illg_1) { opcode = 0x4AFC; } dp = table68k + opcode; @@ -1424,9 +1496,15 @@ static void m68k_verify (uaecptr addr, u } } } +*/ + void m68k_disasm (FILE *f, uaecptr addr, uaecptr *nextpc, int cnt) { + static const char* ccnames[] = + { "T ","F ","HI","LS","CC","CS","NE","EQ", + "VC","VS","PL","MI","GE","LT","GT","LE" }; + uaecptr newpc = 0; m68kpc_offset = addr - m68k_getpc (); while (cnt-- > 0) { @@ -1441,7 +1519,7 @@ void m68k_disasm (FILE *f, uaecptr addr, } opcode = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - if (cpufunctbl[cft_map(opcode)] == op_illg_1) { + if (cpufunctbl[opcode] == op_illg_1) { opcode = 0x4AFC; } dp = table68k + opcode; @@ -1473,11 +1551,11 @@ void m68k_disasm (FILE *f, uaecptr addr, } if (ccpt != 0) { if (cctrue(dp->cc)) - fprintf (f, " == %08lx (TRUE)", newpc); + fprintf (f, " == %08lx (TRUE)", (long)newpc); else - fprintf (f, " == %08lx (FALSE)", newpc); + fprintf (f, " == %08lx (FALSE)", (long)newpc); } else if ((opcode & 0xff00) == 0x6100) /* BSR */ - fprintf (f, " == %08lx", newpc); + fprintf (f, " == %08lx", (long)newpc); fprintf (f, "\n"); } if (nextpc) @@ -1488,18 +1566,18 @@ void m68k_dumpstate (FILE *f, uaecptr *n { int i; for (i = 0; i < 8; i++){ - fprintf (f, "D%d: %08lx ", i, m68k_dreg(regs, i)); + fprintf (f, "D%d: %08lx ", i, (long)m68k_dreg(regs, i)); if ((i & 3) == 3) fprintf (f, "\n"); } for (i = 0; i < 8; i++){ - fprintf (f, "A%d: %08lx ", i, m68k_areg(regs, i)); + fprintf (f, "A%d: %08lx ", i, (long)m68k_areg(regs, i)); if ((i & 3) == 3) fprintf (f, "\n"); } if (regs.s == 0) regs.usp = m68k_areg(regs, 7); if (regs.s && regs.m) regs.msp = m68k_areg(regs, 7); if (regs.s && regs.m == 0) regs.isp = m68k_areg(regs, 7); fprintf (f, "USP=%08lx ISP=%08lx MSP=%08lx VBR=%08lx\n", - regs.usp,regs.isp,regs.msp,regs.vbr); + (long)regs.usp,(long)regs.isp,(long)regs.msp,(long)regs.vbr); fprintf (f, "T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d\n", regs.t1, regs.t0, regs.s, regs.m, GET_XFLG, GET_NFLG, GET_ZFLG, GET_VFLG, GET_CFLG, regs.intmask); @@ -1517,5 +1595,5 @@ void m68k_dumpstate (FILE *f, uaecptr *n m68k_disasm (f, m68k_getpc (), nextpc, 1); if (nextpc) - fprintf (f, "next PC: %08lx\n", *nextpc); + fprintf (f, "next PC: %08lx\n", (long)*nextpc); }