|
|
1.1 root 1: /*
2: Hatari
3:
4: M68000 - CPU. This handles exception handling as well as a few OpCode's such as Line-F and Line-A.
5: */
6:
7: #include "main.h"
8: #include "bios.h"
9: #include "cart.h"
10: #include "debug.h"
11: #include "decode.h"
12: #include "fdc.h"
13: #include "gemdos.h"
14: #include "ikbd.h"
15: #include "int.h"
16: #include "m68000.h"
17: #include "memAlloc.h"
18: #include "memorySnapShot.h"
19: #include "mfp.h"
20: #include "misc.h"
21: #include "psg.h"
22: #include "screen.h"
23: #include "stMemory.h"
24: #include "tos.h"
25: #include "vdi.h"
26: #include "xbios.h"
27:
28:
29: unsigned long ExceptionVector;
30: short int PendingInterruptFlag;
31: void *PendingInterruptFunction;
32: short int PendingInterruptCount;
33: unsigned long BusAddressLocation;
34:
35:
36:
1.1.1.3 root 37: /*-----------------------------------------------------------------------*/
1.1 root 38: /*
39: Reset CPU 68000 variables
40: */
41: void M68000_Reset(BOOL bCold)
42: {
43: int i;
44:
1.1.1.3 root 45: /* Clear registers, set PC, SR and stack pointers */
1.1 root 46: if (bCold) {
47: for(i=0; i<(16+1); i++)
48: Regs[i] = 0;
49: }
50: PC = TOSAddress; /* Start of TOS image, 0xfc0000 or 0xe00000 */
51: SR = 0x2700; /* Starting status register */
1.1.1.3 root 52: MakeFromSR();
1.1.1.2 root 53: PendingInterruptFlag = 0; /* Clear pending flag */
1.1 root 54:
1.1.1.3 root 55: /* Hold display for extended VDI resolutions(under init our VDI) */
1.1 root 56: bHoldScreenDisplay = TRUE;
1.1.1.4 ! root 57:
! 58: /* Now directly reset the UAE CPU core: */
! 59: m68k_reset();
1.1 root 60: }
61:
1.1.1.3 root 62:
63: /*-----------------------------------------------------------------------*/
1.1 root 64: /*
65: Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
66: */
67: void M68000_MemorySnapShot_Capture(BOOL bSave)
68: {
1.1.1.3 root 69: /* Save/Restore details */
1.1.1.4 ! root 70: /*MemorySnapShot_Store(&bDoTraceException,sizeof(bDoTraceException));*/
1.1 root 71: }
72:
1.1.1.3 root 73:
74: /*-----------------------------------------------------------------------*/
1.1 root 75: /*
76: Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
77: This is for 'decode.asm' variables - as cannot use 'decode.c' as will overwrite assembler .obj file!
78: */
79: void M68000_Decode_MemorySnapShot_Capture(BOOL bSave)
80: {
81: int ID;
82:
1.1.1.3 root 83: /* Save/Restore details */
1.1 root 84: MemorySnapShot_Store(Regs,sizeof(Regs));
85: MemorySnapShot_Store(&STRamEnd,sizeof(STRamEnd));
86: MemorySnapShot_Store(&STRamEnd_BusErr,sizeof(STRamEnd_BusErr));
87: MemorySnapShot_Store(&PendingInterruptCount,sizeof(PendingInterruptCount));
88: MemorySnapShot_Store(&PendingInterruptFlag,sizeof(PendingInterruptFlag));
89: if (bSave) {
1.1.1.3 root 90: /* Convert function to ID */
1.1 root 91: ID = Int_HandlerFunctionToID(PendingInterruptFunction);
92: MemorySnapShot_Store(&ID,sizeof(int));
93: }
94: else {
1.1.1.3 root 95: /* Convert ID to function */
1.1 root 96: MemorySnapShot_Store(&ID,sizeof(int));
97: PendingInterruptFunction = Int_IDToHandlerFunction(ID);
98: }
99: MemorySnapShot_Store(&PC,sizeof(PC));
100: MemorySnapShot_Store(&SR,sizeof(SR));
1.1.1.4 ! root 101: /*MemorySnapShot_Store(&bInSuperMode,sizeof(bInSuperMode));*/
1.1.1.2 root 102: /*MemorySnapShot_Store(&Reg_SuperSP,sizeof(Reg_SuperSP));*//*FIXME*/
103: /*MemorySnapShot_Store(&Reg_UserSP,sizeof(Reg_UserSP));*/
1.1.1.4 ! root 104: /*MemorySnapShot_Store(&EmuCCode,sizeof(EmuCCode));*/
1.1 root 105: MemorySnapShot_Store(&ExceptionVector,sizeof(ExceptionVector));
106: }
107:
108:
1.1.1.3 root 109: /*-----------------------------------------------------------------------*/
1.1 root 110: /*
111: BUSERROR - Access outside valid memory range
112: */
113: void M68000_BusError(unsigned long addr)
114: {
1.1.1.3 root 115: /* Reset PC's stack to normal(as may have done many calls) so return to
116: correct level after exception.
117: Enter here with 'ebp' as address we tried to access */
1.1.1.4 ! root 118: fprintf(stderr, "M68000_BusError at address $%lx\n", (long)addr);
1.1.1.3 root 119: BusAddressLocation=addr; /* Store for exception frame */
120: ExceptionVector = EXCEPTION_BUSERROR; /* Handler */
121: M68000_Exception(); /* Cause trap */
1.1 root 122: }
123:
1.1.1.3 root 124:
125: /*-----------------------------------------------------------------------*/
1.1 root 126: /*
127: ADDRESSERROR - Access incorrect memory boundary, eg byte offset for a word access
128: */
129: void M68000_AddressError(unsigned long addr)
130: {
1.1.1.3 root 131: fprintf(stderr, "M68000_AddressError at address $%lx\n", (long)addr);
132: BusAddressLocation=addr; /* Store for exception frame */
133: ExceptionVector=EXCEPTION_ADDRERROR; /* Handler */
134: M68000_Exception(); /* Cause trap */
1.1 root 135: }
136:
1.1.1.3 root 137:
138: /*-----------------------------------------------------------------------*/
1.1 root 139: /*
140: Exception handler
141: */
142: void M68000_Exception(void)
143: {
144: unsigned long Vector,MFPBaseVector;
145: BOOL bRet=FALSE;
146:
1.1.1.2 root 147: /* Was the CPU stopped, i.e. by a STOP instruction? */
148: regs.stopped = 0;
149: unset_special (SPCFLAG_STOP); /* All is go,go,go! */
150:
1.1 root 151: /* At the moment, this functions ist just a wrapper to Exception() of the UAE CPU - Thothy */
152: Exception(ExceptionVector/4, m68k_getpc());
1.1.1.2 root 153:
1.1 root 154: }
155:
1.1.1.3 root 156:
157: /*-----------------------------------------------------------------------*/
1.1 root 158: /*
159: Handle Line-A OpCode exception(Top 4-bit in opcode are 0xA)
160: */
161: /*
1.1.1.3 root 162: void M68000_Line_A_OpCode(void)
1.1 root 163: {
164: PC -= SIZE_WORD; // PC needs to be at address of Line-A instruction
165: ExceptionVector = EXCEPTION_LINE_A;
166: M68000_Exception();
167: }
168: */
169:
1.1.1.3 root 170:
171: /*-----------------------------------------------------------------------*/
1.1 root 172: /*
173: During init do 0xA000, followed by 0xA0FF - we use this to get pointer to Line-A structure details(to fix for extended VDI res)
174: */
175: void M68000_Line_A_Trap(void)
176: {
177: /* FIXME */
178: /*
179:
180: PUSH_ALL
181: __asm {
182: mov edx,DWORD PTR Regs[REG_D0*4]
183: mov [LineABase],edx
184: mov edx,DWORD PTR Regs[REG_A1*4]
185: mov [FontBase],edx
186: call VDI_LineA // Modify Line-A structure
187: }
188: POP_ALL
189: RET
190: */
191: }
192:
1.1.1.3 root 193:
194: /*-----------------------------------------------------------------------*/
1.1 root 195: /*
196: Handle Line-F OpCode exception(Top 4-bit in opcode are 0xF)
197: */
198: /*
1.1.1.3 root 199: void M68000_Line_F_OpCode(void)
1.1 root 200: {
201: PC -= SIZE_WORD; // PC needs to be at address of Line-F instruction
202: ExceptionVector = EXCEPTION_LINE_F;
203: M68000_Exception();
204: }
205: */
206:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.