|
|
1.1 root 1: /*
1.1.1.5 root 2: Hatari - m68000.h
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
1.1 root 6: */
7:
1.1.1.10! root 8: /* 2007/11/10 [NP] Add pairing for lsr / dbcc (and all variants */
! 9: /* working on register, not on memory). */
! 10: /* 2008/01/07 [NP] Use PairingArray to store all valid pairing */
! 11: /* combinations (in m68000.c) */
! 12:
1.1.1.5 root 13: #ifndef HATARI_M68000_H
14: #define HATARI_M68000_H
15:
1.1.1.9 root 16: #include "cycles.h" /* for nCyclesMainCounter */
1.1.1.6 root 17: #include "sysdeps.h"
18: #include "memory.h"
1.1.1.9 root 19: #include "newcpu.h" /* for regs */
1.1.1.10! root 20: #include "int.h"
! 21: #include "trace.h"
! 22:
! 23:
! 24: /* Ugly hacks to adapt the main code to the different CPU cores: */
! 25:
! 26: #define Regs regs.regs
! 27:
! 28: #if defined(UAE_NEWCPU_H)
! 29:
! 30: # define M68000_GetPC() m68k_getpc()
! 31: # define M68000_SetPC(val) m68k_setpc(val)
! 32:
! 33: static inline Uint16 M68000_GetSR(void)
! 34: {
! 35: MakeSR();
! 36: return regs.sr;
! 37: }
! 38: static inline void M68000_SetSR(Uint16 v)
! 39: {
! 40: regs.sr = v;
! 41: MakeFromSR();
! 42: }
! 43:
! 44: # define M68000_SetSpecial(flags) set_special(flags)
! 45: # define M68000_UnsetSpecial(flags) unset_special(flags)
! 46:
! 47: #else /* following code is for WinUAE CPU: */
! 48:
! 49: # define M68000_GetPC() m68k_getpc(®s)
! 50: # define M68000_SetPC(val) m68k_setpc(®s,val)
1.1.1.6 root 51:
1.1.1.10! root 52: static inline Uint16 M68000_GetSR(void)
! 53: {
! 54: MakeSR(®s);
! 55: return regs.sr;
! 56: }
! 57: static inline void M68000_SetSR(Uint16 v)
! 58: {
! 59: regs.sr = v;
! 60: MakeFromSR(®s);
! 61: }
! 62:
! 63: # define M68000_SetSpecial(flags) set_special(®s,flags)
! 64: # define M68000_UnsetSpecial(flags) unset_special(®s,flags)
! 65:
! 66: #endif /* defined(UAE_NEWCPU_H) */
! 67:
! 68:
! 69: #define FIND_IPL ((regs.intmask)&0x7)
1.1.1.6 root 70:
71:
1.1.1.9 root 72: /* bus error mode */
73: #define BUS_ERROR_WRITE 0
74: #define BUS_ERROR_READ 1
75:
1.1.1.10! root 76:
! 77: /* interrupt type used in M68000_Exception() */
! 78: #define M68000_INT_MFP 1 /* exception is an MFP interrupt */
! 79: #define M68000_INT_VIDEO 2 /* exception is a video interrupt */
1.1.1.6 root 80:
1.1.1.7 root 81: extern Uint32 BusErrorAddress;
1.1.1.5 root 82: extern Uint32 BusErrorPC;
1.1.1.6 root 83: extern BOOL bBusErrorReadWrite;
1.1.1.7 root 84: extern int nCpuFreqShift;
1.1.1.9 root 85: extern int nWaitStateCycles;
1.1.1.6 root 86:
1.1.1.10! root 87: extern int LastOpcodeFamily;
! 88: extern int LastInstrCycles;
! 89: extern int Pairing;
! 90: extern char PairingArray[ MAX_OPCODE_FAMILY ][ MAX_OPCODE_FAMILY ];
! 91: extern const char *OpcodeName[];
! 92:
1.1.1.6 root 93:
94: /*-----------------------------------------------------------------------*/
1.1.1.10! root 95: /**
! 96: * Add CPU cycles.
! 97: * NOTE: All times are rounded up to nearest 4 cycles.
! 98: */
1.1.1.6 root 99: static inline void M68000_AddCycles(int cycles)
100: {
1.1.1.10! root 101: cycles = (cycles + 3) & ~3;
! 102: cycles = cycles >> nCpuFreqShift;
! 103:
! 104: PendingInterruptCount -= INT_CONVERT_TO_INTERNAL(cycles, INT_CPU_CYCLE);
1.1.1.9 root 105: nCyclesMainCounter += cycles;
1.1.1.6 root 106: }
1.1.1.5 root 107:
1.1.1.10! root 108:
! 109: /*-----------------------------------------------------------------------*/
! 110: /**
! 111: * Add CPU cycles, take cycles pairing into account.
! 112: * NOTE: All times are rounded up to nearest 4 cycles.
! 113: */
! 114: static inline void M68000_AddCyclesWithPairing(int cycles)
! 115: {
! 116: Pairing = 0;
! 117: /* Check if number of cycles for current instr and for */
! 118: /* the previous one is of the form 4+2n */
! 119: /* If so, a pairing could be possible depending on the opcode */
! 120: if ( ( PairingArray[ LastOpcodeFamily ][ OpcodeFamily ] == 1 )
! 121: && ( ( cycles & 3 ) == 2 ) && ( ( LastInstrCycles & 3 ) == 2 ) )
! 122: {
! 123: Pairing = 1;
! 124: HATARI_TRACE( HATARI_TRACE_CPU_PAIRING ,
! 125: "pairing detected pc=%x family %s/%s cycles %d/%d\n" ,
! 126: m68k_getpc(), OpcodeName[LastOpcodeFamily] ,
! 127: OpcodeName[OpcodeFamily], LastInstrCycles, cycles );
! 128: }
! 129:
! 130: /* Store current instr (not rounded) to check next time */
! 131: LastInstrCycles = cycles;
! 132: LastOpcodeFamily = OpcodeFamily;
! 133:
! 134: /* If pairing is true, we need to substract 2 cycles for the */
! 135: /* previous instr which was rounded to 4 cycles while it wasn't */
! 136: /* needed (and we don't round the current one) */
! 137: /* -> both instr will take 4 cycles less on the ST than if ran */
! 138: /* separately. */
! 139: if (Pairing == 1)
! 140: cycles -= 2;
! 141: else
! 142: cycles = (cycles + 3) & ~3; /* no pairing, round current instr to 4 cycles */
! 143:
! 144: cycles = cycles >> nCpuFreqShift;
! 145:
! 146: PendingInterruptCount -= INT_CONVERT_TO_INTERNAL ( cycles , INT_CPU_CYCLE );
! 147:
! 148: nCyclesMainCounter += cycles;
! 149: }
! 150:
! 151:
! 152: extern void M68000_InitPairing(void);
1.1 root 153: extern void M68000_Reset(BOOL bCold);
1.1.1.10! root 154: extern void M68000_Start(void);
! 155: extern void M68000_CheckCpuLevel(void);
1.1 root 156: extern void M68000_MemorySnapShot_Capture(BOOL bSave);
1.1.1.8 root 157: extern void M68000_BusError(Uint32 addr, BOOL bReadWrite);
1.1.1.10! root 158: extern void M68000_Exception(Uint32 ExceptionVector , int InterruptType);
1.1.1.9 root 159: extern void M68000_WaitState(int nCycles);
1.1.1.5 root 160:
161: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.