--- hatari/src/uae-cpu/newcpu.c 2019/04/01 07:15:37 1.1.1.14 +++ hatari/src/uae-cpu/newcpu.c 2019/04/09 08:47:24 1.1.1.15 @@ -110,9 +110,7 @@ /* 'while' condition (PendingInterruptCount <= 0 is true less often than STOP==0) */ - - -const char NewCpu_rcsid[] = "Hatari $Id: newcpu.c,v 1.1.1.14 2019/04/01 07:15:37 root Exp $"; +const char NewCpu_fileid[] = "Hatari newcpu.c : " __DATE__ " " __TIME__; #include "sysdeps.h" #include "hatari-glue.h" @@ -128,10 +126,12 @@ const char NewCpu_rcsid[] = "Hatari $Id: #include "../includes/vdi.h" #include "../includes/cart.h" #include "../includes/debugui.h" +#include "../includes/dialog.h" #include "../includes/bios.h" #include "../includes/xbios.h" #include "../includes/video.h" #include "../includes/options.h" +#include "../falcon/dsp.h" //#define DEBUG_PREFETCH @@ -929,8 +929,8 @@ 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) ) { @@ -946,7 +946,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(); } @@ -968,13 +968,15 @@ void Exception(int nr, uaecptr oldpc, in 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 reseted.\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(); } @@ -982,7 +984,7 @@ 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(); } @@ -998,7 +1000,13 @@ void Exception(int nr, uaecptr oldpc, in } 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 */ @@ -1500,8 +1508,8 @@ static bool do_specialties_interrupt (in { /* 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 */ + 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) */ @@ -1512,11 +1520,11 @@ static bool do_specialties_interrupt (in 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 true; } } - return FALSE; /* no interrupt was found */ + return false; /* no interrupt was found */ } @@ -1546,7 +1554,7 @@ static int do_specialties (void) 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 */ + if ( do_specialties_interrupt(true) ) { /* test if there's an interrupt and add pending jitter */ regs.stopped = 0; unset_special (SPCFLAG_STOP); } @@ -1558,7 +1566,7 @@ static int do_specialties (void) 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 */ + Interrupt (intr , true); /* process the interrupt and add pending jitter */ regs.stopped = 0; unset_special (SPCFLAG_STOP); } @@ -1581,7 +1589,7 @@ static int do_specialties (void) 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 */ + if ( do_specialties_interrupt(false) ) { /* test if there's an interrupt and add non pending jitter */ regs.stopped = 0; unset_special (SPCFLAG_STOP); break; @@ -1595,7 +1603,7 @@ static int do_specialties (void) 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 */ + Interrupt (intr , false); /* process the interrupt and add non pending jitter */ regs.stopped = 0; unset_special (SPCFLAG_STOP); break; @@ -1613,8 +1621,8 @@ static int do_specialties (void) // 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 */ + + 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) { @@ -1628,7 +1636,7 @@ static int do_specialties (void) // unset_special (SPCFLAG_DOINT); unset_special (SPCFLAG_INT | SPCFLAG_DOINT); if (intr != -1 && intr > regs.intmask) { - Interrupt (intr , FALSE); /* call Interrupt() with Pending=FALSE, not necessarily true but harmless */ + Interrupt (intr , false); /* call Interrupt() with Pending=false, not necessarily true but harmless */ regs.stopped = 0; /* [NP] useless ? */ } } @@ -1642,6 +1650,9 @@ static int do_specialties (void) } #endif + if (regs.spcflags & SPCFLAG_DEBUGGER) + DebugUI_CpuCheck(); + if (regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)) { unset_special(SPCFLAG_MODE_CHANGE); return 1; @@ -1675,13 +1686,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 ); + 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 ); m68k_disasm(stderr, m68k_getpc (), NULL, 1); - } + } /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1717,11 +1730,6 @@ static void m68k_run_1 (void) #if 0 while (PendingInterruptCount <= 0 && PendingInterruptFunction) CALL_VAR(PendingInterruptFunction); - - if (regs.spcflags) { - if (do_specialties ()) - return; - } #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 */ @@ -1731,7 +1739,7 @@ static void m68k_run_1 (void) 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 */ + 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 */ @@ -1739,13 +1747,17 @@ static void m68k_run_1 (void) } #endif } +#endif if (regs.spcflags) { if (do_specialties ()) return; } -#endif + /* Run DSP 56k code if necessary */ + if (bDspEnabled) { + DSP_Run(cycles); + } } } @@ -1758,13 +1770,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 ); + 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 ); m68k_disasm(stderr, m68k_getpc (), NULL, 1); - } + } /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */ /* regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/ @@ -1792,6 +1806,11 @@ static void m68k_run_2 (void) if (do_specialties ()) return; } + + /* Run DSP 56k code if necessary */ + if (bDspEnabled) { + DSP_Run(cycles); + } } }