1 |
cebix |
1.1 |
/* |
2 |
|
|
* emul_op.cpp - 68k opcodes for ROM patches |
3 |
|
|
* |
4 |
gbeauche |
1.32 |
* Basilisk II (C) 1997-2005 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 |
cebix |
1.27 |
printf("d0 %08x d1 %08x d2 %08x d3 %08x\n" |
64 |
|
|
"d4 %08x d5 %08x d6 %08x d7 %08x\n" |
65 |
|
|
"a0 %08x a1 %08x a2 %08x a3 %08x\n" |
66 |
|
|
"a4 %08x a5 %08x a6 %08x a7 %08x\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 |
gbeauche |
1.34 |
if (PutScrapPatch) { |
240 |
|
|
r.d[0] = 0xa9fe; |
241 |
|
|
r.a[0] = PutScrapPatch; |
242 |
|
|
Execute68kTrap(0xa647, &r); // SetToolTrap() |
243 |
|
|
} |
244 |
cebix |
1.1 |
|
245 |
gbeauche |
1.31 |
// Install GetScrap() patch |
246 |
|
|
if (GetScrapPatch) { |
247 |
|
|
r.d[0] = 0xa9fd; |
248 |
|
|
r.a[0] = GetScrapPatch; |
249 |
|
|
Execute68kTrap(0xa647, &r); // SetToolTrap() |
250 |
|
|
} |
251 |
|
|
|
252 |
cebix |
1.1 |
// Setup fake ASC registers |
253 |
|
|
if (ROMVersion == ROM_VERSION_32) { |
254 |
|
|
r.d[0] = 0x1000; |
255 |
|
|
Execute68kTrap(0xa71e, &r); // NewPtrSysClear() |
256 |
|
|
uint32 asc_regs = r.a[0]; |
257 |
|
|
D(bug("ASC registers at %08lx\n", asc_regs)); |
258 |
|
|
WriteMacInt8(asc_regs + 0x800, 0x0f); // Set ASC version number |
259 |
|
|
WriteMacInt32(0xcc0, asc_regs); // Set ASCBase |
260 |
|
|
} |
261 |
|
|
break; |
262 |
|
|
} |
263 |
|
|
|
264 |
|
|
case M68K_EMUL_OP_SERD: // Install serial drivers |
265 |
|
|
D(bug("InstallSERD\n")); |
266 |
|
|
InstallSERD(); |
267 |
|
|
break; |
268 |
|
|
|
269 |
|
|
case M68K_EMUL_OP_SONY_OPEN: // Floppy driver functions |
270 |
|
|
r->d[0] = SonyOpen(r->a[0], r->a[1]); |
271 |
|
|
break; |
272 |
|
|
|
273 |
|
|
case M68K_EMUL_OP_SONY_PRIME: |
274 |
|
|
r->d[0] = SonyPrime(r->a[0], r->a[1]); |
275 |
|
|
break; |
276 |
|
|
|
277 |
|
|
case M68K_EMUL_OP_SONY_CONTROL: |
278 |
|
|
r->d[0] = SonyControl(r->a[0], r->a[1]); |
279 |
|
|
break; |
280 |
|
|
|
281 |
|
|
case M68K_EMUL_OP_SONY_STATUS: |
282 |
|
|
r->d[0] = SonyStatus(r->a[0], r->a[1]); |
283 |
|
|
break; |
284 |
|
|
|
285 |
|
|
case M68K_EMUL_OP_DISK_OPEN: // Disk driver functions |
286 |
|
|
r->d[0] = DiskOpen(r->a[0], r->a[1]); |
287 |
|
|
break; |
288 |
|
|
|
289 |
|
|
case M68K_EMUL_OP_DISK_PRIME: |
290 |
|
|
r->d[0] = DiskPrime(r->a[0], r->a[1]); |
291 |
|
|
break; |
292 |
|
|
|
293 |
|
|
case M68K_EMUL_OP_DISK_CONTROL: |
294 |
|
|
r->d[0] = DiskControl(r->a[0], r->a[1]); |
295 |
|
|
break; |
296 |
|
|
|
297 |
|
|
case M68K_EMUL_OP_DISK_STATUS: |
298 |
|
|
r->d[0] = DiskStatus(r->a[0], r->a[1]); |
299 |
|
|
break; |
300 |
|
|
|
301 |
|
|
case M68K_EMUL_OP_CDROM_OPEN: // CD-ROM driver functions |
302 |
|
|
r->d[0] = CDROMOpen(r->a[0], r->a[1]); |
303 |
|
|
break; |
304 |
|
|
|
305 |
|
|
case M68K_EMUL_OP_CDROM_PRIME: |
306 |
|
|
r->d[0] = CDROMPrime(r->a[0], r->a[1]); |
307 |
|
|
break; |
308 |
|
|
|
309 |
|
|
case M68K_EMUL_OP_CDROM_CONTROL: |
310 |
|
|
r->d[0] = CDROMControl(r->a[0], r->a[1]); |
311 |
|
|
break; |
312 |
|
|
|
313 |
|
|
case M68K_EMUL_OP_CDROM_STATUS: |
314 |
|
|
r->d[0] = CDROMStatus(r->a[0], r->a[1]); |
315 |
|
|
break; |
316 |
|
|
|
317 |
|
|
case M68K_EMUL_OP_VIDEO_OPEN: // Video driver functions |
318 |
cebix |
1.5 |
r->d[0] = VideoDriverOpen(r->a[0], r->a[1]); |
319 |
cebix |
1.1 |
break; |
320 |
|
|
|
321 |
|
|
case M68K_EMUL_OP_VIDEO_CONTROL: |
322 |
cebix |
1.5 |
r->d[0] = VideoDriverControl(r->a[0], r->a[1]); |
323 |
cebix |
1.1 |
break; |
324 |
|
|
|
325 |
|
|
case M68K_EMUL_OP_VIDEO_STATUS: |
326 |
cebix |
1.5 |
r->d[0] = VideoDriverStatus(r->a[0], r->a[1]); |
327 |
cebix |
1.1 |
break; |
328 |
|
|
|
329 |
|
|
case M68K_EMUL_OP_SERIAL_OPEN: // Serial driver functions |
330 |
|
|
r->d[0] = SerialOpen(r->a[0], r->a[1], r->d[0]); |
331 |
|
|
break; |
332 |
|
|
|
333 |
|
|
case M68K_EMUL_OP_SERIAL_PRIME: |
334 |
|
|
r->d[0] = SerialPrime(r->a[0], r->a[1], r->d[0]); |
335 |
|
|
break; |
336 |
|
|
|
337 |
|
|
case M68K_EMUL_OP_SERIAL_CONTROL: |
338 |
|
|
r->d[0] = SerialControl(r->a[0], r->a[1], r->d[0]); |
339 |
|
|
break; |
340 |
|
|
|
341 |
|
|
case M68K_EMUL_OP_SERIAL_STATUS: |
342 |
|
|
r->d[0] = SerialStatus(r->a[0], r->a[1], r->d[0]); |
343 |
|
|
break; |
344 |
|
|
|
345 |
|
|
case M68K_EMUL_OP_SERIAL_CLOSE: |
346 |
|
|
r->d[0] = SerialClose(r->a[0], r->a[1], r->d[0]); |
347 |
|
|
break; |
348 |
|
|
|
349 |
|
|
case M68K_EMUL_OP_ETHER_OPEN: // Ethernet driver functions |
350 |
|
|
r->d[0] = EtherOpen(r->a[0], r->a[1]); |
351 |
|
|
break; |
352 |
|
|
|
353 |
|
|
case M68K_EMUL_OP_ETHER_CONTROL: |
354 |
|
|
r->d[0] = EtherControl(r->a[0], r->a[1]); |
355 |
|
|
break; |
356 |
|
|
|
357 |
|
|
case M68K_EMUL_OP_ETHER_READ_PACKET: |
358 |
gbeauche |
1.33 |
EtherReadPacket(r->a[0], r->a[3], r->d[3], r->d[1]); |
359 |
cebix |
1.1 |
break; |
360 |
|
|
|
361 |
cebix |
1.18 |
case M68K_EMUL_OP_SOUNDIN_OPEN: // Sound input driver functions |
362 |
|
|
r->d[0] = SoundInOpen(r->a[0], r->a[1]); |
363 |
|
|
break; |
364 |
|
|
|
365 |
|
|
case M68K_EMUL_OP_SOUNDIN_PRIME: |
366 |
|
|
r->d[0] = SoundInPrime(r->a[0], r->a[1]); |
367 |
|
|
break; |
368 |
|
|
|
369 |
|
|
case M68K_EMUL_OP_SOUNDIN_CONTROL: |
370 |
|
|
r->d[0] = SoundInControl(r->a[0], r->a[1]); |
371 |
|
|
break; |
372 |
|
|
|
373 |
|
|
case M68K_EMUL_OP_SOUNDIN_STATUS: |
374 |
|
|
r->d[0] = SoundInStatus(r->a[0], r->a[1]); |
375 |
|
|
break; |
376 |
|
|
|
377 |
|
|
case M68K_EMUL_OP_SOUNDIN_CLOSE: |
378 |
|
|
r->d[0] = SoundInClose(r->a[0], r->a[1]); |
379 |
|
|
break; |
380 |
|
|
|
381 |
cebix |
1.1 |
case M68K_EMUL_OP_SCSI_DISPATCH: { // SCSIDispatch() replacement |
382 |
|
|
uint32 ret = ReadMacInt32(r->a[7]); // Get return address |
383 |
|
|
uint16 sel = ReadMacInt16(r->a[7] + 4); // Get selector |
384 |
|
|
r->a[7] += 6; |
385 |
|
|
int stack = 0; |
386 |
|
|
switch (sel) { |
387 |
|
|
case 0: // SCSIReset |
388 |
|
|
WriteMacInt16(r->a[7], SCSIReset()); |
389 |
|
|
stack = 0; |
390 |
|
|
break; |
391 |
|
|
case 1: // SCSIGet |
392 |
|
|
WriteMacInt16(r->a[7], SCSIGet()); |
393 |
|
|
stack = 0; |
394 |
|
|
break; |
395 |
|
|
case 2: // SCSISelect |
396 |
|
|
case 11: // SCSISelAtn |
397 |
|
|
WriteMacInt16(r->a[7] + 2, SCSISelect(ReadMacInt16(r->a[7]) & 0xff)); |
398 |
|
|
stack = 2; |
399 |
|
|
break; |
400 |
|
|
case 3: // SCSICmd |
401 |
|
|
WriteMacInt16(r->a[7] + 6, SCSICmd(ReadMacInt16(r->a[7]), Mac2HostAddr(ReadMacInt32(r->a[7] + 2)))); |
402 |
|
|
stack = 6; |
403 |
|
|
break; |
404 |
|
|
case 4: // SCSIComplete |
405 |
|
|
WriteMacInt16(r->a[7] + 12, SCSIComplete(ReadMacInt32(r->a[7]), ReadMacInt32(r->a[7] + 4), ReadMacInt32(r->a[7] + 8))); |
406 |
|
|
stack = 12; |
407 |
|
|
break; |
408 |
|
|
case 5: // SCSIRead |
409 |
|
|
case 8: // SCSIRBlind |
410 |
|
|
WriteMacInt16(r->a[7] + 4, SCSIRead(ReadMacInt32(r->a[7]))); |
411 |
|
|
stack = 4; |
412 |
|
|
break; |
413 |
|
|
case 6: // SCSIWrite |
414 |
|
|
case 9: // SCSIWBlind |
415 |
|
|
WriteMacInt16(r->a[7] + 4, SCSIWrite(ReadMacInt32(r->a[7]))); |
416 |
|
|
stack = 4; |
417 |
|
|
break; |
418 |
|
|
case 10: // SCSIStat |
419 |
|
|
WriteMacInt16(r->a[7], SCSIStat()); |
420 |
|
|
stack = 0; |
421 |
|
|
break; |
422 |
|
|
case 12: // SCSIMsgIn |
423 |
|
|
WriteMacInt16(r->a[7] + 4, 0); |
424 |
|
|
stack = 4; |
425 |
|
|
break; |
426 |
|
|
case 13: // SCSIMsgOut |
427 |
|
|
WriteMacInt16(r->a[7] + 2, 0); |
428 |
|
|
stack = 2; |
429 |
|
|
break; |
430 |
|
|
case 14: // SCSIMgrBusy |
431 |
|
|
WriteMacInt16(r->a[7], SCSIMgrBusy()); |
432 |
|
|
stack = 0; |
433 |
|
|
break; |
434 |
|
|
default: |
435 |
|
|
printf("FATAL: SCSIDispatch(%d): illegal selector\n", sel); |
436 |
|
|
QuitEmulator(); |
437 |
|
|
break; |
438 |
|
|
} |
439 |
|
|
r->a[0] = ret; // "rtd" emulation, a0 = return address, a1 = new stack pointer |
440 |
|
|
r->a[1] = r->a[7] + stack; |
441 |
|
|
break; |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
case M68K_EMUL_OP_IRQ: // Level 1 interrupt |
445 |
|
|
r->d[0] = 0; |
446 |
cebix |
1.15 |
|
447 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_60HZ) { |
448 |
|
|
ClearInterruptFlag(INTFLAG_60HZ); |
449 |
cebix |
1.29 |
|
450 |
|
|
// Increment Ticks variable |
451 |
|
|
WriteMacInt32(0x16a, ReadMacInt32(0x16a) + 1); |
452 |
|
|
|
453 |
cebix |
1.1 |
if (HasMacStarted()) { |
454 |
|
|
|
455 |
cebix |
1.3 |
// Mac has started, execute all 60Hz interrupt functions |
456 |
cebix |
1.1 |
TimerInterrupt(); |
457 |
|
|
VideoInterrupt(); |
458 |
|
|
|
459 |
|
|
// Call DoVBLTask(0) |
460 |
|
|
if (ROMVersion == ROM_VERSION_32) { |
461 |
|
|
M68kRegisters r2; |
462 |
|
|
r2.d[0] = 0; |
463 |
|
|
Execute68kTrap(0xa072, &r2); |
464 |
|
|
} |
465 |
|
|
|
466 |
|
|
r->d[0] = 1; // Flag: 68k interrupt routine executes VBLTasks etc. |
467 |
|
|
} |
468 |
|
|
} |
469 |
cebix |
1.15 |
|
470 |
|
|
if (InterruptFlags & INTFLAG_1HZ) { |
471 |
|
|
ClearInterruptFlag(INTFLAG_1HZ); |
472 |
|
|
if (HasMacStarted()) { |
473 |
|
|
SonyInterrupt(); |
474 |
|
|
DiskInterrupt(); |
475 |
|
|
CDROMInterrupt(); |
476 |
|
|
} |
477 |
|
|
} |
478 |
|
|
|
479 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_SERIAL) { |
480 |
|
|
ClearInterruptFlag(INTFLAG_SERIAL); |
481 |
|
|
SerialInterrupt(); |
482 |
|
|
} |
483 |
cebix |
1.15 |
|
484 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_ETHER) { |
485 |
|
|
ClearInterruptFlag(INTFLAG_ETHER); |
486 |
|
|
EtherInterrupt(); |
487 |
|
|
} |
488 |
cebix |
1.15 |
|
489 |
cebix |
1.1 |
if (InterruptFlags & INTFLAG_AUDIO) { |
490 |
|
|
ClearInterruptFlag(INTFLAG_AUDIO); |
491 |
|
|
AudioInterrupt(); |
492 |
|
|
} |
493 |
jlachmann |
1.19 |
|
494 |
cebix |
1.26 |
if (InterruptFlags & INTFLAG_ADB) { |
495 |
|
|
ClearInterruptFlag(INTFLAG_ADB); |
496 |
|
|
if (HasMacStarted()) |
497 |
|
|
ADBInterrupt(); |
498 |
|
|
} |
499 |
|
|
|
500 |
jlachmann |
1.19 |
if (InterruptFlags & INTFLAG_NMI) { |
501 |
|
|
ClearInterruptFlag(INTFLAG_NMI); |
502 |
cebix |
1.26 |
if (HasMacStarted()) |
503 |
jlachmann |
1.19 |
TriggerNMI(); |
504 |
|
|
} |
505 |
cebix |
1.1 |
break; |
506 |
|
|
|
507 |
|
|
case M68K_EMUL_OP_PUT_SCRAP: { // PutScrap() patch |
508 |
|
|
void *scrap = Mac2HostAddr(ReadMacInt32(r->a[7] + 4)); |
509 |
|
|
uint32 type = ReadMacInt32(r->a[7] + 8); |
510 |
|
|
int32 length = ReadMacInt32(r->a[7] + 12); |
511 |
|
|
PutScrap(type, scrap, length); |
512 |
|
|
break; |
513 |
|
|
} |
514 |
|
|
|
515 |
gbeauche |
1.31 |
case M68K_EMUL_OP_GET_SCRAP: { // GetScrap() patch |
516 |
|
|
void **scrap_handle = (void **)Mac2HostAddr(ReadMacInt32(r->a[7] + 4)); |
517 |
|
|
uint32 type = ReadMacInt32(r->a[7] + 8); |
518 |
|
|
int32 length = ReadMacInt32(r->a[7] + 12); |
519 |
|
|
GetScrap(scrap_handle, type, length); |
520 |
|
|
break; |
521 |
|
|
} |
522 |
|
|
|
523 |
cebix |
1.1 |
case M68K_EMUL_OP_CHECKLOAD: { // vCheckLoad() patch (resource loader) |
524 |
|
|
uint32 type = r->d[1]; |
525 |
|
|
int16 id = ReadMacInt16(r->a[2]); |
526 |
|
|
if (r->a[0] == 0) |
527 |
|
|
break; |
528 |
|
|
uint32 adr = ReadMacInt32(r->a[0]); |
529 |
|
|
if (adr == 0) |
530 |
|
|
break; |
531 |
|
|
uint8 *p = Mac2HostAddr(adr); |
532 |
|
|
uint32 size = ReadMacInt32(adr - 8) & 0xffffff; |
533 |
|
|
CheckLoad(type, id, p, size); |
534 |
|
|
break; |
535 |
|
|
} |
536 |
|
|
|
537 |
|
|
case M68K_EMUL_OP_AUDIO: // Audio component dispatch function |
538 |
|
|
r->d[0] = AudioDispatch(r->a[3], r->a[4]); |
539 |
cebix |
1.4 |
break; |
540 |
|
|
|
541 |
cebix |
1.6 |
#if SUPPORTS_EXTFS |
542 |
cebix |
1.4 |
case M68K_EMUL_OP_EXTFS_COMM: // External file system routines |
543 |
|
|
WriteMacInt16(r->a[7] + 14, ExtFSComm(ReadMacInt16(r->a[7] + 12), ReadMacInt32(r->a[7] + 8), ReadMacInt32(r->a[7] + 4))); |
544 |
|
|
break; |
545 |
|
|
|
546 |
|
|
case M68K_EMUL_OP_EXTFS_HFS: |
547 |
|
|
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))); |
548 |
cebix |
1.1 |
break; |
549 |
cebix |
1.6 |
#endif |
550 |
cebix |
1.1 |
|
551 |
cebix |
1.21 |
case M68K_EMUL_OP_BLOCK_MOVE: // BlockMove() cache flushing |
552 |
|
|
FlushCodeCache(Mac2HostAddr(r->a[0]), r->a[1]); |
553 |
cebix |
1.7 |
break; |
554 |
|
|
|
555 |
jlachmann |
1.19 |
case M68K_EMUL_OP_DEBUGUTIL: |
556 |
|
|
// printf("DebugUtil d0=%08lx a5=%08lx\n", r->d[0], r->a[5]); |
557 |
|
|
r->d[0] = DebugUtil(r->d[0]); |
558 |
|
|
break; |
559 |
|
|
|
560 |
cebix |
1.1 |
default: |
561 |
jlachmann |
1.19 |
printf("FATAL: EMUL_OP called with bogus opcode %08x\n", opcode); |
562 |
cebix |
1.27 |
printf("d0 %08x d1 %08x d2 %08x d3 %08x\n" |
563 |
|
|
"d4 %08x d5 %08x d6 %08x d7 %08x\n" |
564 |
|
|
"a0 %08x a1 %08x a2 %08x a3 %08x\n" |
565 |
|
|
"a4 %08x a5 %08x a6 %08x a7 %08x\n" |
566 |
cebix |
1.1 |
"sr %04x\n", |
567 |
|
|
r->d[0], r->d[1], r->d[2], r->d[3], r->d[4], r->d[5], r->d[6], r->d[7], |
568 |
|
|
r->a[0], r->a[1], r->a[2], r->a[3], r->a[4], r->a[5], r->a[6], r->a[7], |
569 |
|
|
r->sr); |
570 |
cebix |
1.16 |
#ifdef ENABLE_MON |
571 |
cebix |
1.20 |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
572 |
|
|
mon(3, arg); |
573 |
cebix |
1.9 |
#endif |
574 |
cebix |
1.1 |
QuitEmulator(); |
575 |
|
|
break; |
576 |
|
|
} |
577 |
|
|
} |