--- hatari/src/uae-cpu/newcpu.c 2019/04/01 07:14:57 1.1.1.13 +++ hatari/src/uae-cpu/newcpu.c 2019/04/09 08:49:41 1.1.1.17 @@ -75,33 +75,68 @@ /* 2008/11/18 [NP] In 'do_specialties()', when the cpu is in the STOP state, we must test all */ /* possible int handlers while PendingInterruptCount <= 0 without increasing the */ /* cpu cycle counter. In the case where both an MFP int and an HBL occur at the */ -/* same time for example, the HBL was delayed by 4 bytes if no MFP exception */ +/* same time for example, the HBL was delayed by 4 cycles if no MFP exception */ /* was triggered, which was wrong (this happened mainly with the TOS timer D that */ /* expires very often). Such precision is required for very recent hardscroll */ /* techniques that use 'stop' to stay in sync with the video shifter. */ +/* 2008/11/23 [NP] In 'do_specialties()', when in STOP state, we must first test for a pending */ +/* interrupt that would exit the STOP state immediatly, without doing a 'while' */ +/* loop until 'SPCFLAG_INT' or 'SPCFLAG_DOINT' are set. */ +/* 2008/11/29 [NP] Call 'InterruptAddJitter()' when a video interrupt happens to precisely emulate */ +/* the jitter happening on the Atari (see video.c for the jitter patterns). */ +/* FIXME : Pattern is not always correct when handling pending interrupt in STOP */ +/* state, but this should be harmless as no program has been found using this. */ +/* 2008/12/05 [NP] On Atari it takes 56 cycles to process an interrupt. During that time, a higher */ +/* level interrupt could happen and we must execute it before the previous int */ +/* (see m68k_run_1()). */ +/* This is the case for the VBL which can interrupt the last HBL of a screen */ +/* (end of line 312) at various point (from 0 to 8 cycles). */ +/* This fixes the fullscreen tunnel in Suretrip 49% by Checkpoint, which uses a */ +/* really buggy vbl/hbl combination, even on a real ST. Also fixes sample sound */ +/* in Swedish New Year's TCB screen. */ +/* 2008/12/11 [NP] Extract interrupt handling from do_specialties() in do_specialties_interrupt() */ +/* and factorize some code. In m68k_run_1 when testing for multiple interrupts at */ +/* the same time, call do_specialties_interrupt() to check only the special flags */ +/* related to interrupts (MFP and video) (else, this caused problem when the TRACE */ +/* flag was set). */ +/* 2008/12/14 [NP] In m68k_run_1(), we should check for simultaneous ints only if the cpu is not */ +/* in the STOP state after the last instruction was executed. Else, the call to */ +/* do_specialties_interrupt() could acknowledge the interrupt and we would never */ +/* exit the STOP state in do_specialties() just after (the problem can happen if */ +/* the TOS timer D expires just at the same time as the STOP instruction). */ +/* Fix regression since 2008/12/11 in the hidden screen from ULM in Oh Crickey... */ +/* 2008/12/20 [NP] In m68k_run_1(), when checking interrupts and STOP mode, we should test */ +/* PendingInterruptCount before regs.spcflags to have a faster evaluation of the */ +/* 'while' condition (PendingInterruptCount <= 0 is true less often than STOP==0) */ +/* 2011/04/29 [NP] In Exception(), check the new PC is not on odd address ; raise an address error */ +/* exception if it's the case. */ - -const char NewCpu_rcsid[] = "Hatari $Id: newcpu.c,v 1.1.1.13 2019/04/01 07:14:57 root Exp $"; +const char NewCpu_fileid[] = "Hatari newcpu.c : " __DATE__ " " __TIME__; #include "sysdeps.h" #include "hatari-glue.h" #include "maccess.h" #include "memory.h" #include "newcpu.h" -#include "../includes/main.h" -#include "../includes/log.h" -#include "../includes/m68000.h" -#include "../includes/int.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" -#include "../includes/video.h" -#include "../includes/options.h" +#include "main.h" +#include "m68000.h" +#include "cycInt.h" +#include "mfp.h" +#include "tos.h" +#include "vdi.h" +#include "cart.h" +#include "dialog.h" +#include "bios.h" +#include "xbios.h" +#include "screen.h" +#include "video.h" +#include "options.h" +#include "dsp.h" +#include "log.h" +#include "debugui.h" +#include "debugcpu.h" +#include "68kDisass.h" //#define DEBUG_PREFETCH @@ -128,6 +163,7 @@ int fpp_movem_next[256]; cpuop_func *cpufunctbl[65536]; int OpcodeFamily; +int BusCyclePenalty = 0; #define COUNT_INSTRS 0 @@ -770,30 +806,62 @@ static void exception_trace (int nr) } +/* + * Compute the number of jitter cycles to add when a video interrupt occurs + * (this is specific to the Atari ST) + */ +static void InterruptAddJitter (int Level , int Pending) +{ + int cycles = 0; + + if ( Level == 2 ) /* HBL */ + { + if ( Pending ) + cycles = HblJitterArrayPending[ HblJitterIndex ]; + else + cycles = HblJitterArray[ HblJitterIndex ]; + } + + else if ( Level == 4 ) /* VBL */ + { + if ( Pending ) + cycles = VblJitterArrayPending[ VblJitterIndex ]; + else + cycles = VblJitterArray[ VblJitterIndex ]; + } + +//fprintf ( stderr , "jitter %d\n" , cycles ); +//cycles=0; + if ( cycles > 0 ) /* no need to call M68000_AddCycles if cycles == 0 */ + M68000_AddCycles ( cycles ); +} + + /* Handle exceptions. We need a special case to handle MFP exceptions */ /* on Atari ST, because it's possible to change the MFP's vector base */ /* and get a conflict with 'normal' cpu exceptions. */ void Exception(int nr, uaecptr oldpc, int ExceptionSource) { - uae_u32 currpc = m68k_getpc (); + uae_u32 currpc = m68k_getpc () , newpc; /*if( nr>=2 && nr<10 ) fprintf(stderr,"Exception (-> %i bombs)!\n",nr);*/ - /* Intercept VDI exception (Trap #2 with D0 = 0x73) */ - if ( ExceptionSource != M68000_EXCEPTION_SRC_INT_MFP ) + if (ExceptionSource == M68000_EXC_SRC_CPU) { - if(bUseVDIRes && nr == 0x22 && regs.regs[0] == 0x73) + if (bVdiAesIntercept && nr == 0x22) { - if(!VDI()) + /* Intercept VDI & AES exceptions (Trap #2) */ + if(VDI_AES_Entry()) { - /* 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 */ + /* Set 'PC' to address of 'VDI_OPCODE' illegal instruction. + * This will call OpCode_VDI() after completion of Trap call! + * This is used to modify specific VDI return vectors contents. + */ VDI_OldPC = currpc; currpc = CART_VDI_OPCODE_ADDR; } } - + if (bBiosIntercept) { /* Intercept BIOS or XBIOS trap (Trap #13 or #14) */ @@ -825,7 +893,8 @@ void Exception(int nr, uaecptr oldpc, in /* Build additional exception stack frame for 68010 and higher */ /* (special case for MFP) */ if (currprefs.cpu_level > 0) { - if (ExceptionSource == M68000_EXCEPTION_SRC_INT_MFP) { + if (ExceptionSource == M68000_EXC_SRC_INT_MFP + || ExceptionSource == M68000_EXC_SRC_INT_DSP) { m68k_areg(regs, 7) -= 2; put_word (m68k_areg(regs, 7), nr * 4); /* MFP interrupt, 'nr' can be in a different range depending on $fffa17 */ } @@ -868,11 +937,11 @@ void Exception(int nr, uaecptr oldpc, in m68k_areg(regs, 7) -= 2; put_word (m68k_areg(regs, 7), regs.sr); - HATARI_TRACE ( HATARI_TRACE_CPU_EXCEPTION , "cpu exception %d currpc %x buspc %x newpc %x fault_e3 %x op_e3 %hx addr_e3 %x\n" , - nr, currpc, BusErrorPC, get_long (regs.vbr + 4*nr), last_fault_for_exception_3, last_op_for_exception_3, last_addr_for_exception_3 ); + LOG_TRACE(TRACE_CPU_EXCEPTION, "cpu exception %d currpc %x buspc %x newpc %x fault_e3 %x op_e3 %hx addr_e3 %x\n", + nr, currpc, BusErrorPC, get_long (regs.vbr + 4*nr), last_fault_for_exception_3, last_op_for_exception_3, last_addr_for_exception_3); /* 68000 bus/address errors: */ - if (currprefs.cpu_level==0 && (nr==2 || nr==3) && (ExceptionSource != M68000_EXCEPTION_SRC_INT_MFP) ) { + if (currprefs.cpu_level==0 && (nr==2 || nr==3) && ExceptionSource == M68000_EXC_SRC_CPU) { uae_u16 specialstatus = 1; /* Special status word emulation isn't perfect yet... :-( */ @@ -885,7 +954,7 @@ void Exception(int nr, uaecptr oldpc, in 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) { + if (bExceptionDebugging) { fprintf(stderr,"Address Error at address $%x, PC=$%x\n",last_fault_for_exception_3,currpc); DebugUI(); } @@ -900,20 +969,22 @@ void Exception(int nr, uaecptr oldpc, in /* [NP] PC stored in the stack frame is not necessarily pointing to the next instruction ! */ /* FIXME : we should have a proper model for this, in the meantime we handle specific cases */ - if ( get_word(BusErrorPC) == 0x21f8 ) /* move.l $0.w,$24.w (Transbeauce 2 loader) */ + if ( get_word(BusErrorPC) == 0x21f8 ) /* move.l $0.w,$24.w (Transbeauce 2 loader) */ put_long (m68k_areg(regs, 7)+10, currpc-2); /* correct PC is 2 bytes less than usual value */ /* Check for double bus errors: */ if (regs.spcflags & SPCFLAG_BUSERROR) { fprintf(stderr, "Detected double bus error at address $%x, PC=$%lx => CPU halted!\n", BusErrorAddress, (long)currpc); unset_special(SPCFLAG_BUSERROR); - if (bEnableDebug) + if (bExceptionDebugging) DebugUI(); + else + DlgAlert_Notice("Detected double bus error => CPU halted!\nEmulation needs to be reset.\n"); regs.intmask = 7; - m68k_setstopped(TRUE); + m68k_setstopped(true); return; } - if (bEnableDebug && BusErrorAddress!=0xff8a00) { + if (bExceptionDebugging && BusErrorAddress!=0xff8a00) { fprintf(stderr,"Bus Error at address $%x, PC=$%lx\n", BusErrorAddress, (long)currpc); DebugUI(); } @@ -921,23 +992,45 @@ void Exception(int nr, uaecptr oldpc, in } /* Set PC and flags */ - if (bEnableDebug && get_long (regs.vbr + 4*nr) == 0) { + if (bExceptionDebugging && get_long (regs.vbr + 4*nr) == 0) { write_log("Uninitialized exception handler #%i!\n", nr); DebugUI(); } + newpc = get_long (regs.vbr + 4*nr); + if ( newpc & 1) /* check new pc is even */ + { + if ( nr==2 || nr==3 ) /* address error during bus/address error -> stop emulation */ + { + fprintf(stderr,"Address Error during exception 2/3, aborting new PC=$%x\n",newpc); + DebugUI(); + } + else + { + fprintf(stderr,"Address Error during exception, new PC=$%x\n",newpc); + Exception ( 3 , m68k_getpc() , M68000_EXC_SRC_CPU ); + } + return; + } + m68k_setpc (get_long (regs.vbr + 4*nr)); fill_prefetch_0 (); /* Handle trace flags depending on current state */ exception_trace (nr); /* Handle exception cycles (special case for MFP) */ - if ( ExceptionSource == M68000_EXCEPTION_SRC_INT_MFP ) + if (ExceptionSource == M68000_EXC_SRC_INT_MFP) { M68000_AddCycles(44+12); /* MFP interrupt, 'nr' can be in a different range depending on $fffa17 */ } else if (nr >= 24 && nr <= 31) { - if ( ( nr == 26 ) || ( nr == 28 ) ) /* HBL or VBL */ + if ( nr == 26 ) /* HBL */ + { + /* store current cycle pos when then interrupt was received (see video.c) */ + LastCycleHblException = Cycles_GetCounter(CYCLES_COUNTER_VIDEO); + M68000_AddCycles(44+12); /* Video Interrupt */ + } + else if ( nr == 28 ) /* VBL */ M68000_AddCycles(44+12); /* Video Interrupt */ else M68000_AddCycles(44+4); /* Other Interrupts */ @@ -963,25 +1056,27 @@ void Exception(int nr, uaecptr oldpc, in if(nr < 64) M68000_AddCycles(4); /* Coprocessor and unassigned exceptions (???) */ else - M68000_AddCycles(44+12); /* Must be a MFP interrupt, should be processed above */ + M68000_AddCycles(44+12); /* Must be a MFP or DSP interrupt */ break; } + } -static void Interrupt(int nr) +static void Interrupt(int nr , int Pending) { assert(nr < 8 && nr >= 0); /*lastint_regs = regs;*/ /*lastint_no = nr;*/ - /* [NP] On Hatari, only video ints are using SPCFLAG_INT (see m68000.c) */ - /* TODO : to be really precise, we should use a global variable to store the last ExceptionSource */ - /* passed to M68000_Exception, instead of hardcoding M68000_EXCEPTION_SRC_INT_VIDEO here */ - Exception(nr+24, 0, M68000_EXCEPTION_SRC_INT_VIDEO); + /* On Hatari, only video ints are using SPCFLAG_INT (see m68000.c) */ + Exception(nr+24, 0, M68000_EXC_SRC_AUTOVEC); regs.intmask = nr; set_special (SPCFLAG_INT); + + /* Handle Atari ST's specific jitter for hbl/vbl */ + InterruptAddJitter ( nr , Pending ); } @@ -1023,7 +1118,17 @@ 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 & (currprefs.cpu_level < 4 ? 0x3 : 0x80008000); break; + case 2: + { + uae_u32 cacr_mask = 0; + if (currprefs.cpu_level == 2) // 68020 + cacr_mask = 0x0000000f; + else if (currprefs.cpu_level == 3) // Fake 68030 + cacr_mask = 0x00003f1f; + else if (currprefs.cpu_level == 4) // 68040 + cacr_mask = 0x80008000; + cacr = *regp & cacr_mask; + } case 3: tc = *regp & 0xc000; break; /* Mask out fields that should be zero. */ case 4: itt0 = *regp & 0xffffe364; break; @@ -1107,7 +1212,7 @@ void m68k_divl (uae_u32 opcode, uae_u32 { #if defined(uae_s64) if (src == 0) { - Exception (5, oldpc,M68000_EXCEPTION_SRC_CPU); + Exception (5, oldpc,M68000_EXC_SRC_CPU); return; } if (extra & 0x800) { @@ -1162,7 +1267,7 @@ void m68k_divl (uae_u32 opcode, uae_u32 } #else if (src == 0) { - Exception (5, oldpc,M68000_EXCEPTION_SRC_CPU); + Exception (5, oldpc,M68000_EXC_SRC_CPU); return; } if (extra & 0x800) { @@ -1343,7 +1448,7 @@ void m68k_reset (void) SET_CFLG (0); SET_VFLG (0); SET_NFLG (0); - regs.spcflags &= SPCFLAG_MODE_CHANGE; /* Clear specialflags except mode-change */ + regs.spcflags &= ( SPCFLAG_MODE_CHANGE | SPCFLAG_DEBUGGER ); /* Clear specialflags except mode-change and debugger */ regs.intmask = 7; regs.vbr = regs.sfc = regs.dfc = 0; regs.fpcr = regs.fpsr = regs.fpiar = 0; @@ -1360,17 +1465,17 @@ unsigned long REGPARAM2 op_illg (uae_u32 uaecptr pc = m68k_getpc (); #endif if ((opcode & 0xF000) == 0xF000) { - Exception(0xB,0,M68000_EXCEPTION_SRC_CPU); + Exception(0xB,0,M68000_EXC_SRC_CPU); return 4; } if ((opcode & 0xF000) == 0xA000) { - Exception(0xA,0,M68000_EXCEPTION_SRC_CPU); + Exception(0xA,0,M68000_EXC_SRC_CPU); return 4; } #if 0 write_log ("Illegal instruction: %04x at %08lx\n", opcode, (long)pc); #endif - Exception (4,0,M68000_EXCEPTION_SRC_CPU); + Exception (4,0,M68000_EXC_SRC_CPU); return 4; } @@ -1430,6 +1535,31 @@ static void do_trace (void) /* * Handle special flags */ + +static bool do_specialties_interrupt (int Pending) +{ + /* Check for MFP ints first (level 6) */ + if (regs.spcflags & SPCFLAG_MFP) { + if (MFP_CheckPendingInterrupts() == true) + return true; /* MFP exception was generated, no higher interrupt can happen */ + } + + /* No MFP int, check for VBL/HBL ints (levels 4/2) */ + if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { + int intr = intlev (); + /* SPCFLAG_DOINT will be enabled again in MakeFromSR to handle pending interrupts! */ +// unset_special (SPCFLAG_DOINT); + unset_special (SPCFLAG_INT | SPCFLAG_DOINT); + if (intr != -1 && intr > regs.intmask) { + Interrupt (intr , Pending); /* process the interrupt and add pending jitter if necessary */ + return true; + } + } + + return false; /* no interrupt was found */ +} + + static int do_specialties (void) { if(regs.spcflags & SPCFLAG_BUSERROR) { @@ -1437,7 +1567,7 @@ static int do_specialties (void) * 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,M68000_EXCEPTION_SRC_CPU); + Exception(2,0,M68000_EXC_SRC_CPU); } if(regs.spcflags & SPCFLAG_EXTRA_CYCLES) { @@ -1448,53 +1578,98 @@ static int do_specialties (void) } if (regs.spcflags & SPCFLAG_DOTRACE) { - Exception (9,last_trace_ad,M68000_EXCEPTION_SRC_CPU); + Exception (9,last_trace_ad,M68000_EXC_SRC_CPU); } - while (regs.spcflags & SPCFLAG_STOP) { - 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); - - /* It is possible one or more ints happen at the same time */ - /* We must process them during the same cpu cycle until the special INT flag is set */ - while (PendingInterruptCount<=0 && PendingInterruptFunction) { - /* 1st, we call the interrupt handler */ - CALL_VAR(PendingInterruptFunction); - /* Then we check if this handler triggered an MFP int to process */ - 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) { - Interrupt (intr); + + /* Handle the STOP instruction */ + if ( regs.spcflags & SPCFLAG_STOP ) { + /* We first test if there's a pending interrupt that would */ + /* allow to immediatly leave the STOP state */ + if ( do_specialties_interrupt(true) ) { /* test if there's an interrupt and add pending jitter */ + regs.stopped = 0; + unset_special (SPCFLAG_STOP); + } +#if 0 + if (regs.spcflags & SPCFLAG_MFP) /* MFP int */ + MFP_CheckPendingInterrupts(); + + if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { /* VBL/HBL ints */ + int intr = intlev (); + unset_special (SPCFLAG_INT | SPCFLAG_DOINT); + if (intr != -1 && intr > regs.intmask) { + Interrupt (intr , true); /* process the interrupt and add pending jitter */ + regs.stopped = 0; + unset_special (SPCFLAG_STOP); + } + } +#endif + + /* No pending int, we have to wait for the next matching int */ + while (regs.spcflags & SPCFLAG_STOP) { + + /* Take care of quit event if needed */ + if (regs.spcflags & SPCFLAG_BRK) + return 1; + + M68000_AddCycles(4); + + /* It is possible one or more ints happen at the same time */ + /* We must process them during the same cpu cycle until the special INT flag is set */ + while (PendingInterruptCount<=0 && PendingInterruptFunction) { + /* 1st, we call the interrupt handler */ + CALL_VAR(PendingInterruptFunction); + + /* Then we check if this handler triggered an interrupt to process */ + if ( do_specialties_interrupt(false) ) { /* test if there's an interrupt and add non pending jitter */ regs.stopped = 0; unset_special (SPCFLAG_STOP); - break; - } + break; + } +#if 0 + /* Then we check if this handler triggered an MFP int to process */ + 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) { + Interrupt (intr , false); /* process the interrupt and add non pending jitter */ + regs.stopped = 0; + unset_special (SPCFLAG_STOP); + break; + } + } +#endif } } } + if (regs.spcflags & SPCFLAG_TRACE) do_trace (); // if (regs.spcflags & SPCFLAG_DOINT) { /* [NP] pending int should be processed now, not after the current instr */ + /* so we check for (SPCFLAG_INT | SPCFLAG_DOINT), not just for SPCFLAG_DOINT */ + + if ( do_specialties_interrupt(false) ) { /* test if there's an interrupt and add non pending jitter */ + regs.stopped = 0; /* [NP] useless ? */ + } + if (regs.spcflags & SPCFLAG_INT) { + unset_special (SPCFLAG_INT); + set_special (SPCFLAG_DOINT); + } +#if 0 if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { int intr = intlev (); /* SPCFLAG_DOINT will be enabled again in MakeFromSR to handle pending interrupts! */ // unset_special (SPCFLAG_DOINT); unset_special (SPCFLAG_INT | SPCFLAG_DOINT); if (intr != -1 && intr > regs.intmask) { - Interrupt (intr); - regs.stopped = 0; + Interrupt (intr , false); /* call Interrupt() with Pending=false, not necessarily true but harmless */ + regs.stopped = 0; /* [NP] useless ? */ } } if (regs.spcflags & SPCFLAG_INT) { @@ -1505,6 +1680,10 @@ static int do_specialties (void) if (regs.spcflags & SPCFLAG_MFP) { /* Check for MFP interrupts */ MFP_CheckPendingInterrupts(); } +#endif + + if (regs.spcflags & SPCFLAG_DEBUGGER) + DebugCpu_Check(); if (regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)) { unset_special(SPCFLAG_MODE_CHANGE); @@ -1539,13 +1718,15 @@ static void m68k_run_1 (void) #endif /*m68k_dumpstate(stderr, NULL);*/ - if ( HATARI_TRACE_LEVEL ( HATARI_TRACE_CPU_DISASM ) ) - { - int nFrameCycles = Cycles_GetCounter(CYCLES_COUNTER_VIDEO);; - int nLineCycles = nFrameCycles % nCyclesPerLine; - HATARI_TRACE_PRINT ( "video_cyc=%6d %3d@%3d : " , nFrameCycles, nLineCycles, nHBL ); - m68k_disasm(stderr, m68k_getpc (), NULL, 1); - } + if (LOG_TRACE_LEVEL(TRACE_CPU_DISASM)) + { + int FrameCycles, HblCounterVideo, LineCycles; + + Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles ); + + LOG_TRACE_PRINT ( "cpu video_cyc=%6d %3d@%3d : " , FrameCycles, LineCycles, HblCounterVideo ); + Disasm(stderr, m68k_getpc (), NULL, 1, DISASM_ENGINE_EXT); + } /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1570,6 +1751,9 @@ static void m68k_run_1 (void) } #endif + if (bDspEnabled) + Cycles_SetCounter(CYCLES_COUNTER_CPU, 0); /* to measure the total number of cycles spent in the cpu */ + M68000_AddCyclesWithPairing(cycles); if (regs.spcflags & SPCFLAG_EXTRA_CYCLES) { /* Add some extra cycles to simulate a wait state */ @@ -1578,13 +1762,37 @@ static void m68k_run_1 (void) nWaitStateCycles = 0; } - while (PendingInterruptCount <= 0 && PendingInterruptFunction) +#if 0 + while (PendingInterruptCount <= 0 && PendingInterruptFunction) CALL_VAR(PendingInterruptFunction); +#else + /* We can have several interrupts at the same time before the next CPU instruction */ + /* We must check for pending interrupt and call do_specialties_interrupt() only */ + /* if the cpu is not in the STOP state. Else, the int could be acknowledged now */ + /* and prevent exiting the STOP state when calling do_specialties() after. */ + /* For performance, we first test PendingInterruptCount, then regs.spcflags */ + while ( ( PendingInterruptCount <= 0 ) && ( PendingInterruptFunction ) && ( ( regs.spcflags & SPCFLAG_STOP ) == 0 ) ) + { + CALL_VAR(PendingInterruptFunction); /* call the interrupt handler */ + do_specialties_interrupt(false); /* test if there's an mfp/video interrupt and add non pending jitter */ +#if 0 + if ( regs.spcflags & ( SPCFLAG_MFP | SPCFLAG_INT ) ) { /* only check mfp/video interrupts */ + if (do_specialties ()) /* check if this latest int has higher priority */ + return; + } +#endif + } +#endif if (regs.spcflags) { if (do_specialties ()) return; } + + /* Run DSP 56k code if necessary */ + if (bDspEnabled) { + DSP_Run( Cycles_GetCounter(CYCLES_COUNTER_CPU) ); + } } } @@ -1597,13 +1805,15 @@ static void m68k_run_2 (void) uae_u32 opcode = get_iword (0); /*m68k_dumpstate(stderr, NULL);*/ - if ( HATARI_TRACE_LEVEL ( HATARI_TRACE_CPU_DISASM ) ) - { - int nFrameCycles = Cycles_GetCounter(CYCLES_COUNTER_VIDEO);; - int nLineCycles = nFrameCycles % nCyclesPerLine; - HATARI_TRACE_PRINT ( "video_cyc=%6d %3d@%3d : " , nFrameCycles, nLineCycles, nHBL ); - m68k_disasm(stderr, m68k_getpc (), NULL, 1); - } + if (LOG_TRACE_LEVEL(TRACE_CPU_DISASM)) + { + int FrameCycles, HblCounterVideo, LineCycles; + + Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles ); + + LOG_TRACE_PRINT ( "cpu video_cyc=%6d %3d@%3d : " , FrameCycles, LineCycles, HblCounterVideo ); + Disasm(stderr, m68k_getpc (), NULL, 1, DISASM_ENGINE_EXT); + } /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1614,8 +1824,15 @@ static void m68k_run_2 (void) instrcount[opcode]++; #endif + /* In case of a Bus Error, we need the PC of the instruction that caused */ + /* the error to build the exception stack frame */ + BusErrorPC = m68k_getpc(); + cycles = (*cpufunctbl[opcode])(opcode); + if (bDspEnabled) + Cycles_SetCounter(CYCLES_COUNTER_CPU, 0); /* to measure the total number of cycles spent in the cpu */ + M68000_AddCycles(cycles); if (regs.spcflags & SPCFLAG_EXTRA_CYCLES) { /* Add some extra cycles to simulate a wait state */ @@ -1631,6 +1848,11 @@ static void m68k_run_2 (void) if (do_specialties ()) return; } + + /* Run DSP 56k code if necessary */ + if (bDspEnabled) { + DSP_Run( Cycles_GetCounter(CYCLES_COUNTER_CPU) ); + } } } @@ -1673,13 +1895,13 @@ static void m68k_verify (uaecptr addr, u if (dp->suse) { if (!verify_ea (dp->sreg, dp->smode, dp->size, &val)) { - Exception (3, 0,M68000_EXCEPTION_SRC_CPU); + Exception (3, 0,M68000_EXC_SRC_CPU); return; } } if (dp->duse) { if (!verify_ea (dp->dreg, dp->dmode, dp->size, &val)) { - Exception (3, 0,M68000_EXCEPTION_SRC_CPU); + Exception (3, 0,M68000_EXC_SRC_CPU); return; } }