--- hatari/src/includes/m68000.h 2019/04/09 08:48:40 1.1.1.14 +++ hatari/src/includes/m68000.h 2019/04/09 08:53:11 1.1.1.16 @@ -1,8 +1,8 @@ /* Hatari - m68000.h - 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. + This file is distributed under the GNU General Public License, version 2 + or at your option any later version. Read the file gpl.txt for details. */ /* 2007/11/10 [NP] Add pairing for lsr / dbcc (and all variants */ @@ -44,7 +44,7 @@ enum { REG_A4, REG_A5, REG_A6, - REG_A7, /* ..A7 (also SP) */ + REG_A7 /* ..A7 (also SP) */ }; /* 68000 Condition code's */ @@ -99,13 +99,17 @@ enum { #define SYSINIT_OPCODE 10 /* Free op-code to initialize system (connected drives etc.) */ #define VDI_OPCODE 12 /* Free op-code to call VDI handlers AFTER Trap#2 */ +/* Illegal opcodes used for Native Features emulation: + * http://wiki.aranym.org/natfeats/proposal#special_opcodes + */ +#define NATFEAT_ID_OPCODE 0x7300 +#define NATFEAT_CALL_OPCODE 0x7301 /* Ugly hacks to adapt the main code to the different CPU cores: */ #define Regs regs.regs -#if defined(UAE_NEWCPU_H) # define M68000_GetPC() m68k_getpc() # define M68000_SetPC(val) m68k_setpc(val) @@ -124,44 +128,49 @@ static inline void M68000_SetSR(Uint16 v # define M68000_SetSpecial(flags) set_special(flags) # define M68000_UnsetSpecial(flags) unset_special(flags) -#else /* following code is for WinUAE CPU: */ - -# define M68000_GetPC() m68k_getpc(®s) -# define M68000_SetPC(val) m68k_setpc(®s,val) - -static inline Uint16 M68000_GetSR(void) -{ - MakeSR(®s); - return regs.sr; -} -static inline void M68000_SetSR(Uint16 v) -{ - regs.sr = v; - MakeFromSR(®s); -} - -# define M68000_SetSpecial(flags) set_special(®s,flags) -# define M68000_UnsetSpecial(flags) unset_special(®s,flags) - -#endif /* defined(UAE_NEWCPU_H) */ - /* bus error mode */ #define BUS_ERROR_WRITE 0 #define BUS_ERROR_READ 1 -/* bus acces mode */ +/* bus access mode */ #define BUS_MODE_CPU 0 /* bus is owned by the cpu */ #define BUS_MODE_BLITTER 1 /* bus is owned by the blitter */ +/* Notes on IACK : + * When an interrupt happens, it's possible a similar interrupt happens again + * between the start of the exception and the IACK sequence. In that case, we + * might have to set pending bit twice and change the interrupt vector. + * From the 68000's doc, IACK start after 12 cycles. Then in an Atari STF, it takes + * 12 extra cycles to fetch the vector number. + * This means we have at max 24 cycles at the start of the exception where some + * changes can happen. The values we use were not measured on real hardware, they + * were adjusted to get the correct behaviour in some games/demos relying on this. + */ +#define CPU_IACK_CYCLES_MFP 12 /* vector sent by the MFP */ +#define CPU_IACK_CYCLES_VIDEO 20 /* auto vectored */ + + +/* information about current CPU instruction */ +typedef struct { + /* these are provided only by WinUAE CPU core */ + int iCacheMisses; + int iSave_instr_tail; + + /* TODO: move other instruction specific Hatari variables here */ +} cpu_instruction_t; + +extern cpu_instruction_t CpuInstruction; + extern Uint32 BusErrorAddress; extern Uint32 BusErrorPC; extern bool bBusErrorReadWrite; extern int nCpuFreqShift; extern int nWaitStateCycles; extern int BusMode; +extern bool CPU_IACK; extern int LastOpcodeFamily; extern int LastInstrCycles; @@ -182,6 +191,7 @@ static inline void M68000_AddCycles(int PendingInterruptCount -= INT_CONVERT_TO_INTERNAL(cycles, INT_CPU_CYCLE); nCyclesMainCounter += cycles; + CyclesGlobalClockCounter += cycles; } @@ -249,7 +259,7 @@ static inline void M68000_AddCyclesWithP LastInstrCycles = cycles + BusCyclePenalty; LastOpcodeFamily = OpcodeFamily; - /* If pairing is true, we need to substract 2 cycles for the */ + /* If pairing is true, we need to subtract 2 cycles for the */ /* previous instr which was rounded to 4 cycles while it wasn't */ /* needed (and we don't round the current one) */ /* -> both instr will take 4 cycles less on the ST than if ran */ @@ -275,6 +285,7 @@ static inline void M68000_AddCyclesWithP PendingInterruptCount -= INT_CONVERT_TO_INTERNAL ( cycles , INT_CPU_CYCLE ); nCyclesMainCounter += cycles; + CyclesGlobalClockCounter += cycles; BusCyclePenalty = 0; } @@ -282,10 +293,11 @@ static inline void M68000_AddCyclesWithP extern void M68000_Init(void); extern void M68000_Reset(bool bCold); extern void M68000_Start(void); -extern void M68000_CheckCpuLevel(void); +extern void M68000_CheckCpuSettings(void); extern void M68000_MemorySnapShot_Capture(bool bSave); extern void M68000_BusError(Uint32 addr, bool bReadWrite); extern void M68000_Exception(Uint32 ExceptionVector , int ExceptionSource); extern void M68000_WaitState(int nCycles); +extern int M68000_WaitEClock ( void ); #endif