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