1 |
cebix |
1.1 |
/* |
2 |
|
|
* emul_op.cpp - 68k opcodes for ROM patches |
3 |
|
|
* |
4 |
cebix |
1.23 |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
cebix |
1.1 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include <string.h> |
22 |
|
|
#include <stdio.h> |
23 |
|
|
|
24 |
|
|
#include "sysdeps.h" |
25 |
|
|
#include "cpu_emulation.h" |
26 |
|
|
#include "main.h" |
27 |
|
|
#include "macos_util.h" |
28 |
|
|
#include "rom_patches.h" |
29 |
|
|
#include "rsrc_patches.h" |
30 |
|
|
#include "xpram.h" |
31 |
|
|
#include "adb.h" |
32 |
|
|
#include "timer.h" |
33 |
|
|
#include "clip.h" |
34 |
|
|
#include "serial.h" |
35 |
|
|
#include "sony.h" |
36 |
|
|
#include "disk.h" |
37 |
|
|
#include "cdrom.h" |
38 |
|
|
#include "scsi.h" |
39 |
|
|
#include "video.h" |
40 |
|
|
#include "audio.h" |
41 |
|
|
#include "ether.h" |
42 |
cebix |
1.4 |
#include "extfs.h" |
43 |
cebix |
1.1 |
#include "emul_op.h" |
44 |
|
|
|
45 |
cebix |
1.16 |
#ifdef ENABLE_MON |
46 |
cebix |
1.8 |
#include "mon.h" |
47 |
|
|
#endif |
48 |
|
|
|
49 |
cebix |
1.1 |
#define DEBUG 0 |
50 |
|
|
#include "debug.h" |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
/* |
54 |
|
|
* Execute EMUL_OP opcode (called by 68k emulator or Illegal Instruction trap handler) |
55 |
|
|
*/ |
56 |
|
|
|
57 |
|
|
void EmulOp(uint16 opcode, M68kRegisters *r) |
58 |
|
|
{ |
59 |
|
|
D(bug("EmulOp %04x\n", opcode)); |
60 |
|
|
switch (opcode) { |
61 |
|
|
case M68K_EMUL_BREAK: { // Breakpoint |
62 |
|
|
printf("*** Breakpoint\n"); |
63 |
jlachmann |
1.19 |
printf("d0 %08lx d1 %08lx d2 %08lx d3 %08lx\n" |
64 |
|
|
"d4 %08lx d5 %08lx d6 %08lx d7 %08lx\n" |
65 |
|
|
"a0 %08lx a1 %08lx a2 %08lx a3 %08lx\n" |
66 |
|
|
"a4 %08lx a5 %08lx a6 %08lx a7 %08lx\n" |
67 |
cebix |
1.1 |
"sr %04x\n", |
68 |
|
|
r->d[0], r->d[1], r->d[2], r->d[3], r->d[4], r->d[5], r->d[6], r->d[7], |
69 |
|
|
r->a[0], r->a[1], r->a[2], r->a[3], r->a[4], r->a[5], r->a[6], r->a[7], |
70 |
|
|
r->sr); |
71 |
cebix |
1.25 |
VideoQuitFullScreen(); |
72 |
cebix |
1.16 |
#ifdef ENABLE_MON |
73 |
cebix |
1.20 |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
74 |
|
|
mon(3, arg); |
75 |
cebix |
1.8 |
#endif |
76 |
cebix |
1.1 |
QuitEmulator(); |
77 |
|
|
break; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
case M68K_EMUL_OP_SHUTDOWN: // Quit emulator |
81 |
|
|
QuitEmulator(); |
82 |
|
|
break; |
83 |
|
|
|
84 |
|
|
case M68K_EMUL_OP_RESET: { // MacOS reset |
85 |
|
|
D(bug("*** RESET ***\n")); |
86 |
|
|
TimerReset(); |
87 |
|
|
EtherReset(); |
88 |
cebix |
1.14 |
AudioReset(); |
89 |
cebix |
1.1 |
|
90 |
|
|
// Create BootGlobs at top of memory |
91 |
cebix |
1.12 |
Mac_memset(RAMBaseMac + RAMSize - 4096, 0, 4096); |
92 |
cebix |
1.1 |
uint32 boot_globs = RAMBaseMac + RAMSize - 0x1c; |
93 |
|
|
WriteMacInt32(boot_globs + 0x00, RAMBaseMac); // First RAM bank |
94 |
|
|
WriteMacInt32(boot_globs + 0x04, RAMSize); |
95 |
|
|
WriteMacInt32(boot_globs + 0x08, 0xffffffff); // End of bank table |
96 |
|
|
WriteMacInt32(boot_globs + 0x0c, 0); |
97 |
|
|
|
98 |
|
|
// Setup registers for boot routine |
99 |
|
|
r->d[0] = ReadMacInt32(ROMBaseMac + UniversalInfo + 0x18); // AddrMapFlags |
100 |
|
|
r->d[1] = ReadMacInt32(ROMBaseMac + UniversalInfo + 0x1c); // UnivROMFlags |
101 |
|
|
r->d[2] = ReadMacInt32(ROMBaseMac + UniversalInfo + 0x10); // HWCfgFlags/IDs |
102 |
|
|
if (FPUType) |
103 |
|
|
r->d[2] |= 0x10000000; // Set FPU flag if FPU present |
104 |
|
|
else |
105 |
|
|
r->d[2] &= 0xefffffff; // Clear FPU flag if no FPU present |
106 |
|
|
r->a[0] = ROMBaseMac + UniversalInfo + ReadMacInt32(ROMBaseMac + UniversalInfo);// AddrMap |
107 |
|
|
r->a[1] = ROMBaseMac + UniversalInfo; // UniversalInfo |
108 |
|
|
r->a[6] = boot_globs; // BootGlobs |
109 |
|
|
r->a[7] = RAMBaseMac + 0x10000; // Boot stack |
110 |
|
|
break; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
case M68K_EMUL_OP_CLKNOMEM: { // Clock/PRAM operations |
114 |
|
|
bool is_read = r->d[1] & 0x80; |
115 |
|
|
if ((r->d[1] & 0x78) == 0x38) { |
116 |
|
|
// XPRAM |
117 |
|
|
uint8 reg = (r->d[1] << 5) & 0xe0 | (r->d[1] >> 10) & 0x1f; |
118 |
|
|
if (is_read) { |
119 |
|
|
r->d[2] = XPRAM[reg]; |
120 |
|
|
bool localtalk = !(XPRAM[0xe0] || XPRAM[0xe1]); // LocalTalk enabled? |
121 |
|
|
switch (reg) { |
122 |
|
|
case 0x08: |
123 |
|
|
if (ROMVersion != ROM_VERSION_32) |
124 |
|
|
r->d[2] &= 0xf8; |
125 |
|
|
break; |
126 |
|
|
case 0x8a: |
127 |
|
|
r->d[2] |= 0x05; // 32bit mode is always enabled |
128 |
|
|
break; |
129 |
|
|
case 0xe0: // Disable LocalTalk (use EtherTalk instead) |
130 |
|
|
if (localtalk) |
131 |
|
|
r->d[2] = 0x00; |
132 |
|
|
break; |
133 |
|
|
case 0xe1: |
134 |
|
|
if (localtalk) |
135 |
|
|
r->d[2] = 0xf1; |
136 |
|
|
break; |
137 |
|
|
case 0xe2: |
138 |
|
|
if (localtalk) |
139 |
|
|
r->d[2] = 0x00; |
140 |
|
|
break; |
141 |
|
|
case 0xe3: |
142 |
|
|
if (localtalk) |
143 |
|
|
r->d[2] = 0x0a; |
144 |
|
|
break; |
145 |
|
|
} |
146 |
|
|
D(bug("Read XPRAM %02x->%02lx\n", reg, r->d[2])); |
147 |
|
|
} else { |
148 |
|
|
D(bug("Write XPRAM %02x<-%02lx\n", reg, r->d[2] & 0xff)); |
149 |
|
|
if (reg == 0x8a && !TwentyFourBitAddressing) |
150 |
|
|
r->d[2] |= 0x05; // 32bit mode is always enabled if possible |
151 |
|
|
XPRAM[reg] = r->d[2]; |
152 |
|
|
} |
153 |
|
|
} else { |
154 |
|
|
// PRAM, RTC and other clock registers |
155 |
|
|
uint8 reg = (r->d[1] >> 2) & 0x1f; |
156 |
|
|
if (reg >= 0x10 || (reg >= 0x08 && reg < 0x0c)) { |
157 |
|
|
if (is_read) { |
158 |
|
|
r->d[2] = XPRAM[reg]; |
159 |
|
|
D(bug("Read XPRAM %02x->%02x\n", reg, XPRAM[reg])); |
160 |
|
|
} else { |
161 |
|
|
D(bug("Write PRAM %02x<-%02lx\n", reg, r->d[2])); |
162 |
|
|
XPRAM[reg] = r->d[2]; |
163 |
|
|
} |
164 |
|
|
} else if (reg < 0x08 && is_read) { |
165 |
|
|
uint32 t = TimerDateTime(); |
166 |
cebix |
1.2 |
uint8 b = t; |
167 |
cebix |
1.1 |
switch (reg & 3) { |
168 |
|
|
case 1: b = t >> 8; break; |
169 |
|
|
case 2: b = t >> 16; break; |
170 |
|
|
case 3: b = t >> 24; break; |
171 |
|
|
} |
172 |
|
|
r->d[2] = b; |
173 |
|
|
} else |
174 |
|
|
D(bug("RTC %s op %d, d1 %08lx d2 %08lx\n", is_read ? "read" : "write", reg, r->d[1], r->d[2])); |
175 |
|
|
} |
176 |
|
|
r->d[0] = 0; |
177 |
|
|
r->d[1] = r->d[2]; |
178 |
|
|
break; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
case M68K_EMUL_OP_READ_XPRAM: // Read from XPRAM (ROM10/11) |
182 |
|
|
D(bug("Read XPRAM %02lx\n", r->d[1])); |
183 |
|
|
r->d[1] = XPRAM[r->d[1] & 0xff]; |
184 |
|
|
break; |
185 |
|
|
|
186 |
|
|
case M68K_EMUL_OP_READ_XPRAM2: // Read from XPRAM (ROM15) |
187 |
|
|
D(bug("Read XPRAM %02lx\n", r->d[0])); |
188 |
|
|
r->d[0] = XPRAM[r->d[0] & 0xff]; |
189 |
|
|
break; |
190 |
|
|
|
191 |
|
|
case M68K_EMUL_OP_PATCH_BOOT_GLOBS: // Patch BootGlobs at startup |
192 |
|
|
D(bug("Patch BootGlobs\n")); |
193 |
|
|
WriteMacInt32(r->a[4] - 20, RAMBaseMac + RAMSize); // MemTop |
194 |
|
|
WriteMacInt8(r->a[4] - 26, 0); // No MMU |
195 |
|
|
WriteMacInt8(r->a[4] - 25, ReadMacInt8(r->a[4] - 25) | 1); // No MMU |
196 |
|
|
r->a[6] = RAMBaseMac + RAMSize; |
197 |
|
|
break; |
198 |
|
|
|
199 |
|
|
case M68K_EMUL_OP_FIX_BOOTSTACK: // Set boot stack to 3/4 of RAM (7.5) |
200 |
|
|
r->a[1] = RAMBaseMac + RAMSize * 3 / 4; |
201 |
cebix |
1.16 |
D(bug("Fix boot stack %08x\n", r->a[1])); |
202 |
cebix |
1.1 |
break; |
203 |
|
|
|
204 |
|
|
case M68K_EMUL_OP_FIX_MEMSIZE: { // Set correct logical and physical memory size |
205 |
|
|
D(bug("Fix MemSize\n")); |
206 |
|
|
uint32 diff = ReadMacInt32(0x1ef8) - ReadMacInt32(0x1ef4); // Difference between logical and physical size |
207 |
|
|
WriteMacInt32(0x1ef8, RAMSize); // Physical RAM size |
208 |
|
|
WriteMacInt32(0x1ef4, RAMSize - diff); // Logical RAM size |
209 |
|
|
break; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
case M68K_EMUL_OP_ADBOP: // ADBOp() replacement |
213 |
|
|
ADBOp(r->d[0], Mac2HostAddr(ReadMacInt32(r->a[0]))); |
214 |
|
|
break; |
215 |
|
|
|
216 |
|
|
case M68K_EMUL_OP_INSTIME: // InsTime() replacement |
217 |
|
|
r->d[0] = InsTime(r->a[0], r->d[1]); |
218 |
|
|
break; |
219 |
|
|
|
220 |
|
|
case M68K_EMUL_OP_RMVTIME: // RmvTime() replacement |
221 |
|
|
r->d[0] = RmvTime(r->a[0]); |
222 |
|
|
break; |
223 |
|
|
|
224 |
|
|
case M68K_EMUL_OP_PRIMETIME: // PrimeTime() replacement |
225 |
|
|
r->d[0] = PrimeTime(r->a[0], r->d[0]); |
226 |
|
|
break; |
227 |
|
|
|
228 |
|
|
case M68K_EMUL_OP_MICROSECONDS: // Microseconds() replacement |
229 |
|
|
Microseconds(r->a[0], r->d[0]); |
230 |
|
|
break; |
231 |
|
|
|
232 |
|
|
case M68K_EMUL_OP_INSTALL_DRIVERS: {// Patch to install our own drivers during startup |
233 |
|
|
// Install drivers |
234 |
|
|
D(bug("InstallDrivers\n")); |
235 |
|
|
InstallDrivers(r->a[0]); |
236 |
|
|
|
237 |
|
|
// Install PutScrap() patch |
238 |
|
|
M68kRegisters r; |
239 |
|
|
r.d[0] = 0xa9fe; |
240 |
|
|
r.a[0] = PutScrapPatch; |
241 |
|
|
Execute68kTrap(0xa647, &r); // SetToolTrap() |
242 |
|
|
|
243 |
|
|
// Setup fake ASC registers |
244 |
|
|
if (ROMVersion == ROM_VERSION_32) { |
245 |
|
|
r.d[0] = 0x1000; |
246 |
|
|
Execute68kTrap(0xa71e, &r); // NewPtrSysClear() |
247 |
|
|
uint32 asc_regs = r.a[0]; |
248 |
|
|
D(bug("ASC registers at %08lx\n", asc_regs)); |
249 |
|
|
WriteMacInt8(asc_regs + 0x800, 0x0f); // Set ASC version number |
250 |
|
|
WriteMacInt32(0xcc0, asc_regs); // Set ASCBase |
251 |
|
|
} |
252 |
|
|
break; |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
case M68K_EMUL_OP_SERD: // Install serial drivers |
256 |
|
|
D(bug("InstallSERD\n")); |
257 |
|
|
InstallSERD(); |
258 |
|
|
break; |
259 |
|
|
|
260 |
|
|
case M68K_EMUL_OP_SONY_OPEN: // Floppy driver functions |
261 |
|
|
r->d[0] = SonyOpen(r->a[0], r->a[1]); |
262 |
|
|
break; |
263 |
|
|
|
264 |
|
|
case M68K_EMUL_OP_SONY_PRIME: |
265 |
|
|
r->d[0] = SonyPrime(r->a[0], r->a[1]); |
266 |
|
|
break; |
267 |
|
|
|
268 |
|
|
case M68K_EMUL_OP_SONY_CONTROL: |
269 |
|
|
r->d[0] = SonyControl(r->a[0], r->a[1]); |
270 |
|
|
break; |
271 |
|
|
|
272 |
|
|
case M68K_EMUL_OP_SONY_STATUS: |
273 |
|
|
r->d[0] = SonyStatus(r->a[0], r->a[1]); |
274 |
|
|
break; |
275 |
|
|
|
276 |
|
|
case M68K_EMUL_OP_DISK_OPEN: // Disk driver functions |
277 |
|
|
r->d[0] = DiskOpen(r->a[0], r->a[1]); |
278 |
|
|
break; |
279 |
|
|
|
280 |
|
|
case M68K_EMUL_OP_DISK_PRIME: |
281 |
|
|
r->d[0] = DiskPrime(r->a[0], r->a[1]); |
282 |
|
|
break; |
283 |
|
|
|
284 |
|
|
case M68K_EMUL_OP_DISK_CONTROL: |
285 |
|
|
r->d[0] = DiskControl(r->a[0], r->a[1]); |
286 |
|
|
break; |
287 |
|
|
|
288 |
|
|
case M68K_EMUL_OP_DISK_STATUS: |
289 |
|
|
r->d[0] = DiskStatus(r->a[0], r->a[1]); |
290 |
|
|
break; |
291 |
|
|
|
292 |
|
|
case M68K_EMUL_OP_CDROM_OPEN: // CD-ROM driver functions |
293 |
|
|
r->d[0] = CDROMOpen(r->a[0], r->a[1]); |
294 |
|
|
break; |
295 |
|
|
|
296 |
|
|
case M68K_EMUL_OP_CDROM_PRIME: |
297 |
|
|
r->d[0] = CDROMPrime(r->a[0], r->a[1]); |
298 |
|
|
break; |
299 |
|
|
|
300 |
|
|
case M68K_EMUL_OP_CDROM_CONTROL: |
301 |
|
|
r->d[0] = CDROMControl(r->a[0], r->a[1]); |
302 |
|
|
break; |
303 |
|
|
|
304 |
|
|
case M68K_EMUL_OP_CDROM_STATUS: |
305 |
|
|
r->d[0] = CDROMStatus(r->a[0], r->a[1]); |
306 |
|
|
break; |
307 |
|
|
|
308 |
|
|
case M68K_EMUL_OP_VIDEO_OPEN: // Video driver functions |
309 |
cebix |
1.5 |
r->d[0] = VideoDriverOpen(r->a[0], r->a[1]); |
310 |
cebix |
1.1 |
break; |
311 |
|
|
|
312 |
|
|
case M68K_EMUL_OP_VIDEO_CONTROL: |
313 |
cebix |
1.5 |
r->d[0] = VideoDriverControl(r->a[0], r->a[1]); |
314 |
cebix |
1.1 |
break; |
315 |
|
|
|
316 |
|
|
case M68K_EMUL_OP_VIDEO_STATUS: |
317 |
cebix |
1.5 |
r->d[0] = VideoDriverStatus(r->a[0], r->a[1]); |
318 |
cebix |
1.1 |
break; |
319 |
|
|
|
320 |
|
|
case M68K_EMUL_OP_SERIAL_OPEN: // Serial driver functions |
321 |
|
|
r->d[0] = SerialOpen(r->a[0], r->a[1], r->d[0]); |
322 |
|
|
break; |
323 |
|
|
|
324 |
|
|
case M68K_EMUL_OP_SERIAL_PRIME: |
325 |
|
|
r->d[0] = SerialPrime(r->a[0], r->a[1], r->d[0]); |
326 |
|
|
break; |
327 |
|
|
|
328 |
|
|
case M68K_EMUL_OP_SERIAL_CONTROL: |
329 |
|
|
r->d[0] = SerialControl(r->a[0], r->a[1], r->d[0]); |
330 |
|
|
break; |
331 |
|
|
|
332 |
|
|
case M68K_EMUL_OP_SERIAL_STATUS: |
333 |
|
|
r->d[0] = SerialStatus(r->a[0], r->a[1], r->d[0]); |
334 |
|
|
break; |
335 |
|
|
|
336 |
|
|
case M68K_EMUL_OP_SERIAL_CLOSE: |
337 |
|
|
r->d[0] = SerialClose(r->a[0], r->a[1], r->d[0]); |
338 |
|
|
break; |
339 |
|
|
|
340 |
|
|
case M68K_EMUL_OP_ETHER_OPEN: // Ethernet driver functions |
341 |
|
|
r->d[0] = EtherOpen(r->a[0], r->a[1]); |
342 |
|
|
break; |
343 |
|
|
|
344 |
|
|
case M68K_EMUL_OP_ETHER_CONTROL: |
345 |
|
|
r->d[0] = EtherControl(r->a[0], r->a[1]); |
346 |
|
|
break; |
347 |
|
|
|
348 |
|
|
case M68K_EMUL_OP_ETHER_READ_PACKET: |
349 |
|
|
EtherReadPacket((uint8 **)&r->a[0], r->a[3], r->d[3], r->d[1]); |
350 |
|
|
break; |
351 |
|
|
|
352 |
cebix |
1.18 |
case M68K_EMUL_OP_SOUNDIN_OPEN: // Sound input driver functions |
353 |
|
|
r->d[0] = SoundInOpen(r->a[0], r->a[1]); |
354 |
|
|
break; |
355 |
|
|
|
356 |
|
|
case M68K_EMUL_OP_SOUNDIN_PRIME: |
357 |
|
|
r->d[0] = SoundInPrime(r->a[0], r->a[1]); |
358 |
|
|
break; |
359 |
|
|
|
360 |
|
|
case M68K_EMUL_OP_SOUNDIN_CONTROL: |
361 |
|
|
r->d[0] = SoundInControl(r->a[0], r->a[1]); |
362 |
|
|
break; |
363 |
|
|
|
364 |
|
|
case M68K_EMUL_OP_SOUNDIN_STATUS: |
365 |
|
|
r->d[0] = SoundInStatus(r->a[0], r->a[1]); |
366 |
|
|
break; |
367 |
|
|
|
368 |
|
|
case M68K_EMUL_OP_SOUNDIN_CLOSE: |
369 |
|
|
r->d[0] = SoundInClose(r->a[0], r->a[1]); |
370 |
|
|
break; |
371 |
|
|
|
372 |
cebix |
1.1 |
case M68K_EMUL_OP_SCSI_DISPATCH: { // SCSIDispatch() replacement |
373 |
|
|
uint32 ret = ReadMacInt32(r->a[7]); // Get return address |
374 |
|
|
uint16 sel = ReadMacInt16(r->a[7] + 4); // Get selector |
375 |
|
|
r->a[7] += 6; |
376 |
|
|
int stack = 0; |
377 |
|
|
switch (sel) { |
378 |
|
|
case 0: // SCSIReset |
379 |
|
|
WriteMacInt16(r->a[7], SCSIReset()); |
380 |
|
|
stack = 0; |
381 |
|
|
break; |
382 |
|
|
case 1: // SCSIGet |
383 |
|
|
WriteMacInt16(r->a[7], SCSIGet()); |
384 |
|
|
stack = 0; |
385 |
|
|
break; |
386 |
|
|
case 2: // SCSISelect |
387 |
|
|
case 11: // SCSISelAtn |
388 |
|
|
WriteMacInt16(r->a[7] + 2, SCSISelect(ReadMacInt16(r->a[7]) & 0xff)); |
389 |
|
|
stack = 2; |
390 |
|
|
break; |
391 |
|
|
case 3: // SCSICmd |
392 |
|
|
WriteMacInt16(r->a[7] + 6, SCSICmd(ReadMacInt16(r->a[7]), Mac2HostAddr(ReadMacInt32(r->a[7] + 2)))); |
393 |
|
|
stack = 6; |
394 |
|
|
break; |
395 |
|
|
case 4: // SCSIComplete |
396 |
|
|
WriteMacInt16(r->a[7] + 12, SCSIComplete(ReadMacInt32(r->a[7]), ReadMacInt32(r->a[7] + 4), ReadMacInt32(r->a[7] + 8))); |
397 |
|
|
stack = 12; |
398 |
|
|
break; |
399 |
|
|
case 5: // SCSIRead |
400 |
|
|
case 8: // SCSIRBlind |
401 |
|
|
WriteMacInt16(r->a[7] + 4, SCSIRead(ReadMacInt32(r->a[7]))); |
402 |
|
|
stack = 4; |
403 |
|
|
break; |
404 |
|
|
case 6: // SCSIWrite |
405 |
|
|
case 9: // SCSIWBlind |
406 |
|
|
WriteMacInt16(r->a[7] + 4, SCSIWrite(ReadMacInt32(r->a[7]))); |
407 |
|
|
stack = 4; |
408 |
|
|
break; |
409 |
|
|
case 10: // SCSIStat |
410 |
|
|
WriteMacInt16(r->a[7], SCSIStat()); |
411 |
|
|
stack = 0; |
412 |
|
|
break; |
413 |
|
|
case 12: // SCSIMsgIn |
414 |
|
|
WriteMacInt16(r->a[7] + 4, 0); |
415 |
|
|
stack = 4; |
416 |
|
|
break; |
417 |
|
|
case 13: // SCSIMsgOut |
418 |
|
|
WriteMacInt16(r->a[7] + 2, 0); |
419 |
|
|
stack = 2; |
420 |
|
|
break; |
421 |
|
|
case 14: // SCSIMgrBusy |
422 |
|
|
WriteMacInt16(r->a[7], SCSIMgrBusy()); |
423 |
|
|
stack = 0; |
424 |
|
|
break; |
425 |
|
|
default: |
426 |
|
|
printf("FATAL: SCSIDispatch(%d): illegal selector\n", sel); |
427 |
|
|
QuitEmulator(); |
428 |
|
|
break; |
429 |
|
|
} |
430 |
|
|
r->a[0] = ret; // "rtd" emulation, a0 = return address, a1 = new stack pointer |
431 |
|
|
r->a[1] = r->a[7] + stack; |
432 |
|
|
break; |
433 |
|
|
} |
434 |
|
|
|
435 |
|
|
case M68K_EMUL_OP_IRQ: // Level 1 interrupt |
436 |
|
|
r->d[0] = 0; |
437 |
cebix |
1.15 |
|
438 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_60HZ) { |
439 |
|
|
ClearInterruptFlag(INTFLAG_60HZ); |
440 |
|
|
if (HasMacStarted()) { |
441 |
|
|
|
442 |
cebix |
1.3 |
// Mac has started, execute all 60Hz interrupt functions |
443 |
cebix |
1.1 |
TimerInterrupt(); |
444 |
|
|
VideoInterrupt(); |
445 |
|
|
|
446 |
|
|
// Call DoVBLTask(0) |
447 |
|
|
if (ROMVersion == ROM_VERSION_32) { |
448 |
|
|
M68kRegisters r2; |
449 |
|
|
r2.d[0] = 0; |
450 |
|
|
Execute68kTrap(0xa072, &r2); |
451 |
|
|
} |
452 |
|
|
|
453 |
|
|
r->d[0] = 1; // Flag: 68k interrupt routine executes VBLTasks etc. |
454 |
|
|
} |
455 |
|
|
} |
456 |
cebix |
1.15 |
|
457 |
|
|
if (InterruptFlags & INTFLAG_1HZ) { |
458 |
|
|
ClearInterruptFlag(INTFLAG_1HZ); |
459 |
|
|
if (HasMacStarted()) { |
460 |
|
|
SonyInterrupt(); |
461 |
|
|
DiskInterrupt(); |
462 |
|
|
CDROMInterrupt(); |
463 |
|
|
} |
464 |
|
|
} |
465 |
|
|
|
466 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_SERIAL) { |
467 |
|
|
ClearInterruptFlag(INTFLAG_SERIAL); |
468 |
|
|
SerialInterrupt(); |
469 |
|
|
} |
470 |
cebix |
1.15 |
|
471 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_ETHER) { |
472 |
|
|
ClearInterruptFlag(INTFLAG_ETHER); |
473 |
|
|
EtherInterrupt(); |
474 |
|
|
} |
475 |
cebix |
1.15 |
|
476 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_AUDIO) { |
477 |
|
|
ClearInterruptFlag(INTFLAG_AUDIO); |
478 |
|
|
AudioInterrupt(); |
479 |
|
|
} |
480 |
jlachmann |
1.19 |
|
481 |
cebix |
1.26 |
if (InterruptFlags & INTFLAG_ADB) { |
482 |
|
|
ClearInterruptFlag(INTFLAG_ADB); |
483 |
|
|
if (HasMacStarted()) |
484 |
|
|
ADBInterrupt(); |
485 |
|
|
} |
486 |
|
|
|
487 |
jlachmann |
1.19 |
if (InterruptFlags & INTFLAG_NMI) { |
488 |
|
|
ClearInterruptFlag(INTFLAG_NMI); |
489 |
cebix |
1.26 |
if (HasMacStarted()) |
490 |
jlachmann |
1.19 |
TriggerNMI(); |
491 |
|
|
} |
492 |
cebix |
1.1 |
break; |
493 |
|
|
|
494 |
|
|
case M68K_EMUL_OP_PUT_SCRAP: { // PutScrap() patch |
495 |
|
|
void *scrap = Mac2HostAddr(ReadMacInt32(r->a[7] + 4)); |
496 |
|
|
uint32 type = ReadMacInt32(r->a[7] + 8); |
497 |
|
|
int32 length = ReadMacInt32(r->a[7] + 12); |
498 |
|
|
PutScrap(type, scrap, length); |
499 |
|
|
break; |
500 |
|
|
} |
501 |
|
|
|
502 |
|
|
case M68K_EMUL_OP_CHECKLOAD: { // vCheckLoad() patch (resource loader) |
503 |
|
|
uint32 type = r->d[1]; |
504 |
|
|
int16 id = ReadMacInt16(r->a[2]); |
505 |
|
|
if (r->a[0] == 0) |
506 |
|
|
break; |
507 |
|
|
uint32 adr = ReadMacInt32(r->a[0]); |
508 |
|
|
if (adr == 0) |
509 |
|
|
break; |
510 |
|
|
uint8 *p = Mac2HostAddr(adr); |
511 |
|
|
uint32 size = ReadMacInt32(adr - 8) & 0xffffff; |
512 |
|
|
CheckLoad(type, id, p, size); |
513 |
|
|
break; |
514 |
|
|
} |
515 |
|
|
|
516 |
|
|
case M68K_EMUL_OP_AUDIO: // Audio component dispatch function |
517 |
|
|
r->d[0] = AudioDispatch(r->a[3], r->a[4]); |
518 |
cebix |
1.4 |
break; |
519 |
|
|
|
520 |
cebix |
1.6 |
#if SUPPORTS_EXTFS |
521 |
cebix |
1.4 |
case M68K_EMUL_OP_EXTFS_COMM: // External file system routines |
522 |
|
|
WriteMacInt16(r->a[7] + 14, ExtFSComm(ReadMacInt16(r->a[7] + 12), ReadMacInt32(r->a[7] + 8), ReadMacInt32(r->a[7] + 4))); |
523 |
|
|
break; |
524 |
|
|
|
525 |
|
|
case M68K_EMUL_OP_EXTFS_HFS: |
526 |
|
|
WriteMacInt16(r->a[7] + 20, ExtFSHFS(ReadMacInt32(r->a[7] + 16), ReadMacInt16(r->a[7] + 14), ReadMacInt32(r->a[7] + 10), ReadMacInt32(r->a[7] + 6), ReadMacInt16(r->a[7] + 4))); |
527 |
cebix |
1.1 |
break; |
528 |
cebix |
1.6 |
#endif |
529 |
cebix |
1.1 |
|
530 |
cebix |
1.21 |
case M68K_EMUL_OP_BLOCK_MOVE: // BlockMove() cache flushing |
531 |
|
|
FlushCodeCache(Mac2HostAddr(r->a[0]), r->a[1]); |
532 |
cebix |
1.7 |
break; |
533 |
|
|
|
534 |
jlachmann |
1.19 |
case M68K_EMUL_OP_DEBUGUTIL: |
535 |
|
|
// printf("DebugUtil d0=%08lx a5=%08lx\n", r->d[0], r->a[5]); |
536 |
|
|
r->d[0] = DebugUtil(r->d[0]); |
537 |
|
|
break; |
538 |
|
|
|
539 |
cebix |
1.1 |
default: |
540 |
jlachmann |
1.19 |
printf("FATAL: EMUL_OP called with bogus opcode %08x\n", opcode); |
541 |
|
|
printf("d0 %08lx d1 %08lx d2 %08lx d3 %08lx\n" |
542 |
|
|
"d4 %08lx d5 %08lx d6 %08lx d7 %08lx\n" |
543 |
|
|
"a0 %08lx a1 %08lx a2 %08lx a3 %08lx\n" |
544 |
|
|
"a4 %08lx a5 %08lx a6 %08lx a7 %08lx\n" |
545 |
cebix |
1.1 |
"sr %04x\n", |
546 |
|
|
r->d[0], r->d[1], r->d[2], r->d[3], r->d[4], r->d[5], r->d[6], r->d[7], |
547 |
|
|
r->a[0], r->a[1], r->a[2], r->a[3], r->a[4], r->a[5], r->a[6], r->a[7], |
548 |
|
|
r->sr); |
549 |
cebix |
1.16 |
#ifdef ENABLE_MON |
550 |
cebix |
1.20 |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
551 |
|
|
mon(3, arg); |
552 |
cebix |
1.9 |
#endif |
553 |
cebix |
1.1 |
QuitEmulator(); |
554 |
|
|
break; |
555 |
|
|
} |
556 |
|
|
} |