|
|
1.1.1.6 root 1: /*
2: Hatari - hatari-glue.c
3:
1.1.1.18 root 4: This file is distributed under the GNU General Public License, version 2
5: or at your option any later version. Read the file gpl.txt for details.
1.1.1.6 root 6:
7: This file contains some code to glue the UAE CPU core to the rest of the
8: emulator and Hatari's "illegal" opcodes.
9: */
1.1.1.13 root 10: const char HatariGlue_fileid[] = "Hatari hatari-glue.c : " __DATE__ " " __TIME__;
1.1.1.6 root 11:
1.1 root 12:
13: #include <stdio.h>
14:
1.1.1.15 root 15: #include "main.h"
16: #include "configuration.h"
17: #include "cycInt.h"
18: #include "tos.h"
19: #include "gemdos.h"
1.1.1.18 root 20: #include "natfeats.h"
1.1.1.15 root 21: #include "cart.h"
22: #include "vdi.h"
23: #include "stMemory.h"
24: #include "ikbd.h"
1.1.1.16 root 25: #include "screen.h"
1.1.1.15 root 26: #include "video.h"
1.1.1.17 root 27: #include "psg.h"
1.1.1.18 root 28: #include "mfp.h"
29: #include "fdc.h"
1.1 root 30:
1.1.1.3 root 31: #include "sysdeps.h"
32: #include "maccess.h"
1.1.1.5 root 33: #include "memory.h"
1.1.1.17 root 34: #include "m68000.h"
1.1.1.3 root 35: #include "newcpu.h"
1.1.1.8 root 36: #include "hatari-glue.h"
1.1 root 37:
38:
1.1.1.11 root 39: struct uae_prefs currprefs, changed_prefs;
1.1 root 40:
1.1.1.8 root 41: int pendingInterrupts = 0;
1.1.1.6 root 42:
1.1 root 43:
1.1.1.14 root 44: /**
45: * Reset custom chips
1.1.1.18 root 46: * In case the RESET instruction is called, we must reset all the peripherals
47: * connected to the CPU's reset pin.
1.1.1.14 root 48: */
1.1 root 49: void customreset(void)
50: {
1.1.1.14 root 51: pendingInterrupts = 0;
1.1.1.12 root 52:
1.1.1.18 root 53: /* Reset the IKBD */
54: IKBD_Reset ( false );
1.1.1.13 root 55:
1.1.1.14 root 56: /* Reseting the GLUE video chip should also set freq/res register to 0 */
57: Video_Reset_Glue ();
1.1.1.17 root 58:
59: /* Reset the YM2149 (stop any sound) */
60: PSG_Reset ();
1.1.1.18 root 61:
62: /* Reset the MFP */
63: MFP_Reset ();
64:
65: /* Reset the FDC */
1.1.1.19 root 66: FDC_Reset ( false );
1.1.1.6 root 67: }
68:
69:
1.1.1.14 root 70: /**
71: * Return interrupt number (1 - 7), -1 means no interrupt.
1.1.1.8 root 72: * Note that the interrupt stays pending if it can't be executed yet
1.1.1.14 root 73: * due to the interrupt level field in the SR.
74: */
1.1.1.6 root 75: int intlev(void)
76: {
1.1.1.14 root 77: /* There are only VBL and HBL autovector interrupts in the ST... */
78: assert((pendingInterrupts & ~((1<<4)|(1<<2))) == 0);
1.1.1.8 root 79:
1.1.1.18 root 80: #if 0
1.1.1.14 root 81: if (pendingInterrupts & (1 << 4)) /* VBL interrupt? */
82: {
83: if (regs.intmask < 4)
84: pendingInterrupts &= ~(1 << 4);
85: return 4;
86: }
87: else if (pendingInterrupts & (1 << 2)) /* HBL interrupt? */
88: {
89: if (regs.intmask < 2)
90: pendingInterrupts &= ~(1 << 2);
91: return 2;
92: }
1.1.1.18 root 93: #else
94: if ( pendingInterrupts & (1 << 4) ) /* VBL interrupt ? */
95: return 4;
96: else if ( pendingInterrupts & (1 << 2) ) /* HBL interrupt ? */
97: return 2;
98: #endif
1.1.1.14 root 99:
100: return -1;
1.1 root 101: }
102:
103:
1.1.1.14 root 104: /**
105: * Initialize 680x0 emulation
106: */
1.1 root 107: int Init680x0(void)
108: {
1.1.1.14 root 109: currprefs.cpu_level = changed_prefs.cpu_level = ConfigureParams.System.nCpuLevel;
110: currprefs.cpu_compatible = changed_prefs.cpu_compatible = ConfigureParams.System.bCompatibleCpu;
111: currprefs.address_space_24 = changed_prefs.address_space_24 = true;
1.1 root 112:
1.1.1.14 root 113: init_m68k();
1.1.1.22! root 114: Cart_PatchCpuTables();
1.1.1.14 root 115:
116: return true;
1.1 root 117: }
118:
119:
1.1.1.14 root 120: /**
121: * Deinitialize 680x0 emulation
122: */
1.1 root 123: void Exit680x0(void)
124: {
1.1.1.14 root 125: memory_uninit();
1.1.1.8 root 126:
1.1.1.14 root 127: free(table68k);
128: table68k = NULL;
1.1 root 129: }
130:
131:
1.1.1.14 root 132: /**
1.1.1.20 root 133: * Execute a 'NOP' opcode (increment PC by 2 bytes and take care
134: * of prefetch at the CPU level depending on the current CPU mode)
135: * This is used to return from Gemdos / Natfeats interception, by ignoring
136: * the intercepted opcode and executing a NOP instead once the work has been done.
137: */
138: static void CpuDoNOP ( void )
139: {
140: (*cpufunctbl[0X4E71])(0x4E71);
141: }
142:
143:
144: /**
1.1.1.14 root 145: * Check if the CPU type has been changed
146: */
1.1.1.11 root 147: void check_prefs_changed_cpu(void)
1.1.1.4 root 148: {
1.1.1.14 root 149: if (currprefs.cpu_level != changed_prefs.cpu_level
150: || currprefs.cpu_compatible != changed_prefs.cpu_compatible)
151: {
152: currprefs.cpu_level = changed_prefs.cpu_level;
153: currprefs.cpu_compatible = changed_prefs.cpu_compatible;
154: set_special(SPCFLAG_MODE_CHANGE);
155: build_cpufunctbl ();
1.1.1.22! root 156: Cart_PatchCpuTables();
1.1.1.14 root 157: }
1.1 root 158: }
159:
160:
1.1.1.14 root 161: /**
1.1.1.21 root 162: * Check whether PC is currently in ROM cartridge space - used
163: * to test whether our "illegal" Hatari opcodes should be handled
164: * or whether they are just "normal" illegal opcodes.
165: */
166: static bool is_cart_pc(void)
167: {
168: Uint32 pc = M68000_GetPC() & 0x00ffffff;
169: return pc >= 0xfa0000 && pc < 0xfc0000;
170: }
171:
172:
173: /**
1.1.1.14 root 174: * This function will be called at system init by the cartridge routine
175: * (after gemdos init, before booting floppies).
176: * The GEMDOS vector (#$84) is setup and we also initialize the connected
177: * drive mask and Line-A variables (for an extended VDI resolution) from here.
178: */
1.1.1.7 root 179: unsigned long OpCode_SysInit(uae_u32 opcode)
1.1 root 180: {
1.1.1.21 root 181: if (is_cart_pc())
1.1.1.14 root 182: {
1.1.1.21 root 183: /* Add any drives mapped by TOS in the interim */
184: ConnectedDriveMask |= STMemory_ReadLong(0x4c2);
185: /* Initialize the connected drive mask */
186: STMemory_WriteLong(0x4c2, ConnectedDriveMask);
187:
1.1.1.14 root 188: /* Init on boot - see cart.c */
189: GemDOS_Boot();
190:
191: /* Update LineA for extended VDI res
192: * D0: LineA base, A1: Font base
193: */
194: VDI_LineA(regs.regs[0], regs.regs[9]);
1.1.1.21 root 195:
196: CpuDoNOP ();
197: }
1.1.1.22! root 198: else if (!bUseTos)
! 199: {
! 200: GemDOS_Boot();
! 201: CpuDoNOP();
! 202: }
1.1.1.21 root 203: else
204: {
205: LOG_TRACE(TRACE_OS_GEMDOS | TRACE_OS_BASE | TRACE_OS_VDI | TRACE_OS_AES,
206: "SYSINIT opcode invoked outside of cartridge space\n");
207: /* illegal instruction */
208: op_illg(opcode);
209: fill_prefetch_0();
1.1.1.14 root 210: }
211:
212: return 4;
1.1.1.3 root 213: }
214:
1.1.1.5 root 215:
1.1.1.14 root 216: /**
217: * Intercept GEMDOS calls.
218: * Used for GEMDOS HD emulation (see gemdos.c).
219: */
1.1.1.3 root 220: unsigned long OpCode_GemDos(uae_u32 opcode)
221: {
1.1.1.21 root 222: if (is_cart_pc())
223: {
224: GemDOS_OpCode(); /* handler code in gemdos.c */
225: CpuDoNOP();
226: }
227: else
228: {
229: LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS opcode invoked outside of cartridge space\n");
230: /* illegal instruction */
231: op_illg(opcode);
232: fill_prefetch_0();
233: }
1.1.1.3 root 234:
1.1.1.14 root 235: return 4;
1.1 root 236: }
237:
1.1.1.5 root 238:
1.1.1.14 root 239: /**
240: * This is called after completion of each VDI call
241: */
1.1.1.5 root 242: unsigned long OpCode_VDI(uae_u32 opcode)
243: {
1.1.1.17 root 244: /* this is valid only after VDI trap, called from cartridge code */
1.1.1.21 root 245: if (VDI_OldPC && is_cart_pc())
1.1.1.17 root 246: {
247: VDI_Complete();
1.1.1.5 root 248:
1.1.1.17 root 249: /* Set PC back to where originated from to continue instruction decoding */
250: m68k_setpc(VDI_OldPC);
251: VDI_OldPC = 0;
252: }
253: else
254: {
1.1.1.21 root 255: LOG_TRACE(TRACE_OS_VDI, "VDI opcode invoked outside of cartridge space\n");
1.1.1.17 root 256: /* illegal instruction */
257: op_illg(opcode);
258: }
1.1.1.14 root 259: fill_prefetch_0();
260: return 4;
1.1 root 261: }
1.1.1.18 root 262:
263:
264: /**
265: * Emulator Native Features ID opcode interception.
266: */
267: unsigned long OpCode_NatFeat_ID(uae_u32 opcode)
268: {
269: Uint32 stack = Regs[REG_A7] + SIZE_LONG; /* skip return address */
270:
271: if (NatFeat_ID(stack, &(Regs[REG_D0]))) {
1.1.1.20 root 272: CpuDoNOP ();
1.1.1.18 root 273: }
274: return 4;
275: }
276:
277: /**
278: * Emulator Native Features call opcode interception.
279: */
280: unsigned long OpCode_NatFeat_Call(uae_u32 opcode)
281: {
282: Uint32 stack = Regs[REG_A7] + SIZE_LONG; /* skip return address */
283: Uint16 SR = M68000_GetSR();
284: bool super;
285:
286: super = ((SR & SR_SUPERMODE) == SR_SUPERMODE);
287: if (NatFeat_Call(stack, super, &(Regs[REG_D0]))) {
1.1.1.20 root 288: CpuDoNOP ();
1.1.1.18 root 289: }
290: return 4;
291: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.