|
|
1.1 root 1: /*
2: Hatari - hatari-glue.c
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.
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: */
10: const char HatariGlue_fileid[] = "Hatari hatari-glue.c : " __DATE__ " " __TIME__;
11:
12:
13: #include <stdio.h>
14:
15: #include "main.h"
16: #include "configuration.h"
17: #include "cycInt.h"
18: #include "tos.h"
19: #include "gemdos.h"
20: #include "cart.h"
21: #include "vdi.h"
22: #include "stMemory.h"
23: #include "ikbd.h"
24: #include "screen.h"
25: #include "video.h"
1.1.1.2 ! root 26: #include "psg.h"
1.1 root 27:
28: #include "sysdeps.h"
29: #include "maccess.h"
30: #include "memory.h"
31: #include "newcpu.h"
32: #include "hatari-glue.h"
33:
34:
35: struct uae_prefs currprefs, changed_prefs;
36:
37: int pendingInterrupts = 0;
38:
39:
40: /**
41: * Reset custom chips
42: */
43: void customreset(void)
44: {
45: pendingInterrupts = 0;
46:
47: /* In case the 6301 was executing a custom program from its RAM */
48: /* we must turn it back to the 'normal' mode. */
49: IKBD_Reset_ExeMode ();
50:
51: /* Reseting the GLUE video chip should also set freq/res register to 0 */
52: Video_Reset_Glue ();
1.1.1.2 ! root 53:
! 54: /* Reset the YM2149 (stop any sound) */
! 55: PSG_Reset ();
1.1 root 56: }
57:
58:
59: /**
60: * Return interrupt number (1 - 7), -1 means no interrupt.
61: * Note that the interrupt stays pending if it can't be executed yet
62: * due to the interrupt level field in the SR.
63: */
64: int intlev(void)
65: {
66: /* There are only VBL and HBL autovector interrupts in the ST... */
67: assert((pendingInterrupts & ~((1<<4)|(1<<2))) == 0);
68:
69: if (pendingInterrupts & (1 << 4)) /* VBL interrupt? */
70: {
71: if (regs.intmask < 4)
72: pendingInterrupts &= ~(1 << 4);
73: return 4;
74: }
75: else if (pendingInterrupts & (1 << 2)) /* HBL interrupt? */
76: {
77: if (regs.intmask < 2)
78: pendingInterrupts &= ~(1 << 2);
79: return 2;
80: }
81:
82: return -1;
83: }
84:
85: /**
86: * Initialize 680x0 emulation
87: */
88: int Init680x0(void)
89: {
90: currprefs.cpu_level = changed_prefs.cpu_level = ConfigureParams.System.nCpuLevel;
91:
92: switch (currprefs.cpu_level) {
93: case 0 : currprefs.cpu_model = 68000; break;
94: case 1 : currprefs.cpu_model = 68010; break;
95: case 2 : currprefs.cpu_model = 68020; break;
96: case 3 : currprefs.cpu_model = 68030; break;
97: case 4 : currprefs.cpu_model = 68040; break;
98: case 5 : currprefs.cpu_model = 68060; break;
99: default: fprintf (stderr, "Init680x0() : Error, cpu_level unknown\n");
100: }
101:
102: currprefs.cpu_compatible = changed_prefs.cpu_compatible = ConfigureParams.System.bCompatibleCpu;
103: currprefs.address_space_24 = changed_prefs.address_space_24 = ConfigureParams.System.bAddressSpace24;
104: currprefs.cpu_cycle_exact = changed_prefs.cpu_cycle_exact = ConfigureParams.System.bCycleExactCpu;
105: currprefs.fpu_model = changed_prefs.fpu_model = ConfigureParams.System.n_FPUType;
106: currprefs.fpu_strict = changed_prefs.fpu_strict = ConfigureParams.System.bCompatibleFPU;
107: currprefs.mmu_model = changed_prefs.mmu_model = ConfigureParams.System.bMMU;
108:
109: init_m68k();
110:
111: return true;
112: }
113:
114:
115: /**
116: * Deinitialize 680x0 emulation
117: */
118: void Exit680x0(void)
119: {
120: memory_uninit();
121:
122: free(table68k);
123: table68k = NULL;
124: }
125:
126: /**
127: * This function will be called at system init by the cartridge routine
128: * (after gemdos init, before booting floppies).
129: * The GEMDOS vector (#$84) is setup and we also initialize the connected
130: * drive mask and Line-A variables (for an extended VDI resolution) from here.
131: */
132: unsigned long OpCode_SysInit(uae_u32 opcode)
133: {
134: /* Add any drives mapped by TOS in the interim */
135: ConnectedDriveMask |= STMemory_ReadLong(0x4c2);
136: /* Initialize the connected drive mask */
137: STMemory_WriteLong(0x4c2, ConnectedDriveMask);
138:
139: if (!bInitGemDOS)
140: {
141: /* Init on boot - see cart.c */
142: GemDOS_Boot();
143:
144: /* Update LineA for extended VDI res
145: * D0: LineA base, A1: Font base
146: */
147: VDI_LineA(regs.regs[0], regs.regs[9]);
148: }
149:
150: m68k_incpc(2);
151: fill_prefetch_0();
152: return 4;
153: }
154:
155:
156: /**
157: * Intercept GEMDOS calls.
158: * Used for GEMDOS HD emulation (see gemdos.c).
159: */
160: unsigned long OpCode_GemDos(uae_u32 opcode)
161: {
162: GemDOS_OpCode(); /* handler code in gemdos.c */
163:
164: m68k_incpc(2);
165: fill_prefetch_0();
166: return 4;
167: }
168:
169:
170: /**
171: * This is called after completion of each VDI call
172: */
173: unsigned long OpCode_VDI(uae_u32 opcode)
174: {
175: VDI_Complete();
176:
177: /* Set PC back to where originated from to continue instruction decoding */
178: m68k_setpc(VDI_OldPC);
179:
180: fill_prefetch_0();
181: return 4;
182: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.