1 |
cebix |
1.1 |
/* |
2 |
|
|
* emul_op.cpp - 68k opcodes for ROM patches |
3 |
|
|
* |
4 |
|
|
* Basilisk II (C) 1997-1999 Christian Bauer |
5 |
|
|
* |
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 |
|
|
#include "emul_op.h" |
43 |
|
|
|
44 |
|
|
#define DEBUG 0 |
45 |
|
|
#include "debug.h" |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
/* |
49 |
|
|
* Execute EMUL_OP opcode (called by 68k emulator or Illegal Instruction trap handler) |
50 |
|
|
*/ |
51 |
|
|
|
52 |
|
|
void EmulOp(uint16 opcode, M68kRegisters *r) |
53 |
|
|
{ |
54 |
|
|
D(bug("EmulOp %04x\n", opcode)); |
55 |
|
|
switch (opcode) { |
56 |
|
|
case M68K_EMUL_BREAK: { // Breakpoint |
57 |
|
|
printf("*** Breakpoint\n"); |
58 |
|
|
printf("d0 %08lx d1 %08lx d2 %08lx d3 %08lx\n" |
59 |
|
|
"d4 %08lx d5 %08lx d6 %08lx d7 %08lx\n" |
60 |
|
|
"a0 %08lx a1 %08lx a2 %08lx a3 %08lx\n" |
61 |
|
|
"a4 %08lx a5 %08lx a6 %08lx a7 %08lx\n" |
62 |
|
|
"sr %04x\n", |
63 |
|
|
r->d[0], r->d[1], r->d[2], r->d[3], r->d[4], r->d[5], r->d[6], r->d[7], |
64 |
|
|
r->a[0], r->a[1], r->a[2], r->a[3], r->a[4], r->a[5], r->a[6], r->a[7], |
65 |
|
|
r->sr); |
66 |
|
|
QuitEmulator(); |
67 |
|
|
break; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
case M68K_EMUL_OP_SHUTDOWN: // Quit emulator |
71 |
|
|
QuitEmulator(); |
72 |
|
|
break; |
73 |
|
|
|
74 |
|
|
case M68K_EMUL_OP_RESET: { // MacOS reset |
75 |
|
|
D(bug("*** RESET ***\n")); |
76 |
|
|
TimerReset(); |
77 |
|
|
EtherReset(); |
78 |
|
|
|
79 |
|
|
// Create BootGlobs at top of memory |
80 |
|
|
memset((void *)(RAMBaseHost + RAMSize - 4096), 0, 4096); |
81 |
|
|
uint32 boot_globs = RAMBaseMac + RAMSize - 0x1c; |
82 |
|
|
WriteMacInt32(boot_globs + 0x00, RAMBaseMac); // First RAM bank |
83 |
|
|
WriteMacInt32(boot_globs + 0x04, RAMSize); |
84 |
|
|
WriteMacInt32(boot_globs + 0x08, 0xffffffff); // End of bank table |
85 |
|
|
WriteMacInt32(boot_globs + 0x0c, 0); |
86 |
|
|
|
87 |
|
|
// Setup registers for boot routine |
88 |
|
|
r->d[0] = ReadMacInt32(ROMBaseMac + UniversalInfo + 0x18); // AddrMapFlags |
89 |
|
|
r->d[1] = ReadMacInt32(ROMBaseMac + UniversalInfo + 0x1c); // UnivROMFlags |
90 |
|
|
r->d[2] = ReadMacInt32(ROMBaseMac + UniversalInfo + 0x10); // HWCfgFlags/IDs |
91 |
|
|
if (FPUType) |
92 |
|
|
r->d[2] |= 0x10000000; // Set FPU flag if FPU present |
93 |
|
|
else |
94 |
|
|
r->d[2] &= 0xefffffff; // Clear FPU flag if no FPU present |
95 |
|
|
r->a[0] = ROMBaseMac + UniversalInfo + ReadMacInt32(ROMBaseMac + UniversalInfo);// AddrMap |
96 |
|
|
r->a[1] = ROMBaseMac + UniversalInfo; // UniversalInfo |
97 |
|
|
r->a[6] = boot_globs; // BootGlobs |
98 |
|
|
r->a[7] = RAMBaseMac + 0x10000; // Boot stack |
99 |
|
|
break; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
case M68K_EMUL_OP_CLKNOMEM: { // Clock/PRAM operations |
103 |
|
|
bool is_read = r->d[1] & 0x80; |
104 |
|
|
if ((r->d[1] & 0x78) == 0x38) { |
105 |
|
|
// XPRAM |
106 |
|
|
uint8 reg = (r->d[1] << 5) & 0xe0 | (r->d[1] >> 10) & 0x1f; |
107 |
|
|
if (is_read) { |
108 |
|
|
r->d[2] = XPRAM[reg]; |
109 |
|
|
bool localtalk = !(XPRAM[0xe0] || XPRAM[0xe1]); // LocalTalk enabled? |
110 |
|
|
switch (reg) { |
111 |
|
|
case 0x08: |
112 |
|
|
if (ROMVersion != ROM_VERSION_32) |
113 |
|
|
r->d[2] &= 0xf8; |
114 |
|
|
break; |
115 |
|
|
case 0x8a: |
116 |
|
|
r->d[2] |= 0x05; // 32bit mode is always enabled |
117 |
|
|
break; |
118 |
|
|
case 0xe0: // Disable LocalTalk (use EtherTalk instead) |
119 |
|
|
if (localtalk) |
120 |
|
|
r->d[2] = 0x00; |
121 |
|
|
break; |
122 |
|
|
case 0xe1: |
123 |
|
|
if (localtalk) |
124 |
|
|
r->d[2] = 0xf1; |
125 |
|
|
break; |
126 |
|
|
case 0xe2: |
127 |
|
|
if (localtalk) |
128 |
|
|
r->d[2] = 0x00; |
129 |
|
|
break; |
130 |
|
|
case 0xe3: |
131 |
|
|
if (localtalk) |
132 |
|
|
r->d[2] = 0x0a; |
133 |
|
|
break; |
134 |
|
|
} |
135 |
|
|
D(bug("Read XPRAM %02x->%02lx\n", reg, r->d[2])); |
136 |
|
|
} else { |
137 |
|
|
D(bug("Write XPRAM %02x<-%02lx\n", reg, r->d[2] & 0xff)); |
138 |
|
|
if (reg == 0x8a && !TwentyFourBitAddressing) |
139 |
|
|
r->d[2] |= 0x05; // 32bit mode is always enabled if possible |
140 |
|
|
XPRAM[reg] = r->d[2]; |
141 |
|
|
} |
142 |
|
|
} else { |
143 |
|
|
// PRAM, RTC and other clock registers |
144 |
|
|
uint8 reg = (r->d[1] >> 2) & 0x1f; |
145 |
|
|
if (reg >= 0x10 || (reg >= 0x08 && reg < 0x0c)) { |
146 |
|
|
if (is_read) { |
147 |
|
|
r->d[2] = XPRAM[reg]; |
148 |
|
|
D(bug("Read XPRAM %02x->%02x\n", reg, XPRAM[reg])); |
149 |
|
|
} else { |
150 |
|
|
D(bug("Write PRAM %02x<-%02lx\n", reg, r->d[2])); |
151 |
|
|
XPRAM[reg] = r->d[2]; |
152 |
|
|
} |
153 |
|
|
} else if (reg < 0x08 && is_read) { |
154 |
|
|
uint32 t = TimerDateTime(); |
155 |
cebix |
1.2 |
uint8 b = t; |
156 |
cebix |
1.1 |
switch (reg & 3) { |
157 |
|
|
case 1: b = t >> 8; break; |
158 |
|
|
case 2: b = t >> 16; break; |
159 |
|
|
case 3: b = t >> 24; break; |
160 |
|
|
} |
161 |
|
|
r->d[2] = b; |
162 |
|
|
} else |
163 |
|
|
D(bug("RTC %s op %d, d1 %08lx d2 %08lx\n", is_read ? "read" : "write", reg, r->d[1], r->d[2])); |
164 |
|
|
} |
165 |
|
|
r->d[0] = 0; |
166 |
|
|
r->d[1] = r->d[2]; |
167 |
|
|
break; |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
case M68K_EMUL_OP_READ_XPRAM: // Read from XPRAM (ROM10/11) |
171 |
|
|
D(bug("Read XPRAM %02lx\n", r->d[1])); |
172 |
|
|
r->d[1] = XPRAM[r->d[1] & 0xff]; |
173 |
|
|
break; |
174 |
|
|
|
175 |
|
|
case M68K_EMUL_OP_READ_XPRAM2: // Read from XPRAM (ROM15) |
176 |
|
|
D(bug("Read XPRAM %02lx\n", r->d[0])); |
177 |
|
|
r->d[0] = XPRAM[r->d[0] & 0xff]; |
178 |
|
|
break; |
179 |
|
|
|
180 |
|
|
case M68K_EMUL_OP_PATCH_BOOT_GLOBS: // Patch BootGlobs at startup |
181 |
|
|
D(bug("Patch BootGlobs\n")); |
182 |
|
|
WriteMacInt32(r->a[4] - 20, RAMBaseMac + RAMSize); // MemTop |
183 |
|
|
WriteMacInt8(r->a[4] - 26, 0); // No MMU |
184 |
|
|
WriteMacInt8(r->a[4] - 25, ReadMacInt8(r->a[4] - 25) | 1); // No MMU |
185 |
|
|
r->a[6] = RAMBaseMac + RAMSize; |
186 |
|
|
break; |
187 |
|
|
|
188 |
|
|
case M68K_EMUL_OP_FIX_BOOTSTACK: // Set boot stack to 3/4 of RAM (7.5) |
189 |
|
|
D(bug("Fix boot stack\n")); |
190 |
|
|
r->a[1] = RAMBaseMac + RAMSize * 3 / 4; |
191 |
|
|
break; |
192 |
|
|
|
193 |
|
|
case M68K_EMUL_OP_FIX_MEMSIZE: { // Set correct logical and physical memory size |
194 |
|
|
D(bug("Fix MemSize\n")); |
195 |
|
|
uint32 diff = ReadMacInt32(0x1ef8) - ReadMacInt32(0x1ef4); // Difference between logical and physical size |
196 |
|
|
WriteMacInt32(0x1ef8, RAMSize); // Physical RAM size |
197 |
|
|
WriteMacInt32(0x1ef4, RAMSize - diff); // Logical RAM size |
198 |
|
|
break; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
case M68K_EMUL_OP_ADBOP: // ADBOp() replacement |
202 |
|
|
ADBOp(r->d[0], Mac2HostAddr(ReadMacInt32(r->a[0]))); |
203 |
|
|
break; |
204 |
|
|
|
205 |
|
|
case M68K_EMUL_OP_INSTIME: // InsTime() replacement |
206 |
|
|
r->d[0] = InsTime(r->a[0], r->d[1]); |
207 |
|
|
break; |
208 |
|
|
|
209 |
|
|
case M68K_EMUL_OP_RMVTIME: // RmvTime() replacement |
210 |
|
|
r->d[0] = RmvTime(r->a[0]); |
211 |
|
|
break; |
212 |
|
|
|
213 |
|
|
case M68K_EMUL_OP_PRIMETIME: // PrimeTime() replacement |
214 |
|
|
r->d[0] = PrimeTime(r->a[0], r->d[0]); |
215 |
|
|
break; |
216 |
|
|
|
217 |
|
|
case M68K_EMUL_OP_MICROSECONDS: // Microseconds() replacement |
218 |
|
|
Microseconds(r->a[0], r->d[0]); |
219 |
|
|
break; |
220 |
|
|
|
221 |
|
|
case M68K_EMUL_OP_INSTALL_DRIVERS: {// Patch to install our own drivers during startup |
222 |
|
|
// Install drivers |
223 |
|
|
D(bug("InstallDrivers\n")); |
224 |
|
|
InstallDrivers(r->a[0]); |
225 |
|
|
|
226 |
|
|
// Install PutScrap() patch |
227 |
|
|
M68kRegisters r; |
228 |
|
|
r.d[0] = 0xa9fe; |
229 |
|
|
r.a[0] = PutScrapPatch; |
230 |
|
|
Execute68kTrap(0xa647, &r); // SetToolTrap() |
231 |
|
|
|
232 |
|
|
// Setup fake ASC registers |
233 |
|
|
if (ROMVersion == ROM_VERSION_32) { |
234 |
|
|
r.d[0] = 0x1000; |
235 |
|
|
Execute68kTrap(0xa71e, &r); // NewPtrSysClear() |
236 |
|
|
uint32 asc_regs = r.a[0]; |
237 |
|
|
D(bug("ASC registers at %08lx\n", asc_regs)); |
238 |
|
|
WriteMacInt8(asc_regs + 0x800, 0x0f); // Set ASC version number |
239 |
|
|
WriteMacInt32(0xcc0, asc_regs); // Set ASCBase |
240 |
|
|
} |
241 |
|
|
break; |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
case M68K_EMUL_OP_SERD: // Install serial drivers |
245 |
|
|
D(bug("InstallSERD\n")); |
246 |
|
|
InstallSERD(); |
247 |
|
|
break; |
248 |
|
|
|
249 |
|
|
case M68K_EMUL_OP_SONY_OPEN: // Floppy driver functions |
250 |
|
|
r->d[0] = SonyOpen(r->a[0], r->a[1]); |
251 |
|
|
break; |
252 |
|
|
|
253 |
|
|
case M68K_EMUL_OP_SONY_PRIME: |
254 |
|
|
r->d[0] = SonyPrime(r->a[0], r->a[1]); |
255 |
|
|
break; |
256 |
|
|
|
257 |
|
|
case M68K_EMUL_OP_SONY_CONTROL: |
258 |
|
|
r->d[0] = SonyControl(r->a[0], r->a[1]); |
259 |
|
|
break; |
260 |
|
|
|
261 |
|
|
case M68K_EMUL_OP_SONY_STATUS: |
262 |
|
|
r->d[0] = SonyStatus(r->a[0], r->a[1]); |
263 |
|
|
break; |
264 |
|
|
|
265 |
|
|
case M68K_EMUL_OP_DISK_OPEN: // Disk driver functions |
266 |
|
|
r->d[0] = DiskOpen(r->a[0], r->a[1]); |
267 |
|
|
break; |
268 |
|
|
|
269 |
|
|
case M68K_EMUL_OP_DISK_PRIME: |
270 |
|
|
r->d[0] = DiskPrime(r->a[0], r->a[1]); |
271 |
|
|
break; |
272 |
|
|
|
273 |
|
|
case M68K_EMUL_OP_DISK_CONTROL: |
274 |
|
|
r->d[0] = DiskControl(r->a[0], r->a[1]); |
275 |
|
|
break; |
276 |
|
|
|
277 |
|
|
case M68K_EMUL_OP_DISK_STATUS: |
278 |
|
|
r->d[0] = DiskStatus(r->a[0], r->a[1]); |
279 |
|
|
break; |
280 |
|
|
|
281 |
|
|
case M68K_EMUL_OP_CDROM_OPEN: // CD-ROM driver functions |
282 |
|
|
r->d[0] = CDROMOpen(r->a[0], r->a[1]); |
283 |
|
|
break; |
284 |
|
|
|
285 |
|
|
case M68K_EMUL_OP_CDROM_PRIME: |
286 |
|
|
r->d[0] = CDROMPrime(r->a[0], r->a[1]); |
287 |
|
|
break; |
288 |
|
|
|
289 |
|
|
case M68K_EMUL_OP_CDROM_CONTROL: |
290 |
|
|
r->d[0] = CDROMControl(r->a[0], r->a[1]); |
291 |
|
|
break; |
292 |
|
|
|
293 |
|
|
case M68K_EMUL_OP_CDROM_STATUS: |
294 |
|
|
r->d[0] = CDROMStatus(r->a[0], r->a[1]); |
295 |
|
|
break; |
296 |
|
|
|
297 |
|
|
case M68K_EMUL_OP_VIDEO_OPEN: // Video driver functions |
298 |
|
|
r->d[0] = VideoOpen(r->a[0], r->a[1]); |
299 |
|
|
break; |
300 |
|
|
|
301 |
|
|
case M68K_EMUL_OP_VIDEO_CONTROL: |
302 |
|
|
r->d[0] = VideoControl(r->a[0], r->a[1]); |
303 |
|
|
break; |
304 |
|
|
|
305 |
|
|
case M68K_EMUL_OP_VIDEO_STATUS: |
306 |
|
|
r->d[0] = VideoStatus(r->a[0], r->a[1]); |
307 |
|
|
break; |
308 |
|
|
|
309 |
|
|
case M68K_EMUL_OP_SERIAL_OPEN: // Serial driver functions |
310 |
|
|
r->d[0] = SerialOpen(r->a[0], r->a[1], r->d[0]); |
311 |
|
|
break; |
312 |
|
|
|
313 |
|
|
case M68K_EMUL_OP_SERIAL_PRIME: |
314 |
|
|
r->d[0] = SerialPrime(r->a[0], r->a[1], r->d[0]); |
315 |
|
|
break; |
316 |
|
|
|
317 |
|
|
case M68K_EMUL_OP_SERIAL_CONTROL: |
318 |
|
|
r->d[0] = SerialControl(r->a[0], r->a[1], r->d[0]); |
319 |
|
|
break; |
320 |
|
|
|
321 |
|
|
case M68K_EMUL_OP_SERIAL_STATUS: |
322 |
|
|
r->d[0] = SerialStatus(r->a[0], r->a[1], r->d[0]); |
323 |
|
|
break; |
324 |
|
|
|
325 |
|
|
case M68K_EMUL_OP_SERIAL_CLOSE: |
326 |
|
|
r->d[0] = SerialClose(r->a[0], r->a[1], r->d[0]); |
327 |
|
|
break; |
328 |
|
|
|
329 |
|
|
case M68K_EMUL_OP_ETHER_OPEN: // Ethernet driver functions |
330 |
|
|
r->d[0] = EtherOpen(r->a[0], r->a[1]); |
331 |
|
|
break; |
332 |
|
|
|
333 |
|
|
case M68K_EMUL_OP_ETHER_CONTROL: |
334 |
|
|
r->d[0] = EtherControl(r->a[0], r->a[1]); |
335 |
|
|
break; |
336 |
|
|
|
337 |
|
|
case M68K_EMUL_OP_ETHER_READ_PACKET: |
338 |
|
|
EtherReadPacket((uint8 **)&r->a[0], r->a[3], r->d[3], r->d[1]); |
339 |
|
|
break; |
340 |
|
|
|
341 |
|
|
case M68K_EMUL_OP_SCSI_DISPATCH: { // SCSIDispatch() replacement |
342 |
|
|
uint32 ret = ReadMacInt32(r->a[7]); // Get return address |
343 |
|
|
uint16 sel = ReadMacInt16(r->a[7] + 4); // Get selector |
344 |
|
|
r->a[7] += 6; |
345 |
|
|
int stack = 0; |
346 |
|
|
switch (sel) { |
347 |
|
|
case 0: // SCSIReset |
348 |
|
|
WriteMacInt16(r->a[7], SCSIReset()); |
349 |
|
|
stack = 0; |
350 |
|
|
break; |
351 |
|
|
case 1: // SCSIGet |
352 |
|
|
WriteMacInt16(r->a[7], SCSIGet()); |
353 |
|
|
stack = 0; |
354 |
|
|
break; |
355 |
|
|
case 2: // SCSISelect |
356 |
|
|
case 11: // SCSISelAtn |
357 |
|
|
WriteMacInt16(r->a[7] + 2, SCSISelect(ReadMacInt16(r->a[7]) & 0xff)); |
358 |
|
|
stack = 2; |
359 |
|
|
break; |
360 |
|
|
case 3: // SCSICmd |
361 |
|
|
WriteMacInt16(r->a[7] + 6, SCSICmd(ReadMacInt16(r->a[7]), Mac2HostAddr(ReadMacInt32(r->a[7] + 2)))); |
362 |
|
|
stack = 6; |
363 |
|
|
break; |
364 |
|
|
case 4: // SCSIComplete |
365 |
|
|
WriteMacInt16(r->a[7] + 12, SCSIComplete(ReadMacInt32(r->a[7]), ReadMacInt32(r->a[7] + 4), ReadMacInt32(r->a[7] + 8))); |
366 |
|
|
stack = 12; |
367 |
|
|
break; |
368 |
|
|
case 5: // SCSIRead |
369 |
|
|
case 8: // SCSIRBlind |
370 |
|
|
WriteMacInt16(r->a[7] + 4, SCSIRead(ReadMacInt32(r->a[7]))); |
371 |
|
|
stack = 4; |
372 |
|
|
break; |
373 |
|
|
case 6: // SCSIWrite |
374 |
|
|
case 9: // SCSIWBlind |
375 |
|
|
WriteMacInt16(r->a[7] + 4, SCSIWrite(ReadMacInt32(r->a[7]))); |
376 |
|
|
stack = 4; |
377 |
|
|
break; |
378 |
|
|
case 10: // SCSIStat |
379 |
|
|
WriteMacInt16(r->a[7], SCSIStat()); |
380 |
|
|
stack = 0; |
381 |
|
|
break; |
382 |
|
|
case 12: // SCSIMsgIn |
383 |
|
|
WriteMacInt16(r->a[7] + 4, 0); |
384 |
|
|
stack = 4; |
385 |
|
|
break; |
386 |
|
|
case 13: // SCSIMsgOut |
387 |
|
|
WriteMacInt16(r->a[7] + 2, 0); |
388 |
|
|
stack = 2; |
389 |
|
|
break; |
390 |
|
|
case 14: // SCSIMgrBusy |
391 |
|
|
WriteMacInt16(r->a[7], SCSIMgrBusy()); |
392 |
|
|
stack = 0; |
393 |
|
|
break; |
394 |
|
|
default: |
395 |
|
|
printf("FATAL: SCSIDispatch(%d): illegal selector\n", sel); |
396 |
|
|
QuitEmulator(); |
397 |
|
|
break; |
398 |
|
|
} |
399 |
|
|
r->a[0] = ret; // "rtd" emulation, a0 = return address, a1 = new stack pointer |
400 |
|
|
r->a[1] = r->a[7] + stack; |
401 |
|
|
break; |
402 |
|
|
} |
403 |
|
|
|
404 |
|
|
case M68K_EMUL_OP_MEMORY_DISPATCH: { // MemoryDispatch() replacement routine |
405 |
|
|
int16 sel = r->d[0]; |
406 |
|
|
D(bug("MemoryDispatch(%d)\n", sel)); |
407 |
|
|
switch (sel) { |
408 |
|
|
case -6: // GetLogicalRAMSize |
409 |
|
|
r->d[0] = RAMSize; |
410 |
|
|
break; |
411 |
|
|
case -3: |
412 |
|
|
r->d[0] = 0x1000; |
413 |
|
|
break; |
414 |
|
|
case 0: // HoldMemory |
415 |
|
|
case 1: // UnholdMemory |
416 |
|
|
case 2: // LockMemory |
417 |
|
|
case 3: // UnlockMemory |
418 |
|
|
case 4: // LockMemoryContiguous |
419 |
|
|
case 6: // ProtectMemory |
420 |
|
|
case 7: // UnprotectMemory |
421 |
|
|
r->d[0] = 0; |
422 |
|
|
break; |
423 |
|
|
default: |
424 |
|
|
printf("FATAL: MemoryDispatch(%d): illegal selector\n", sel); |
425 |
|
|
r->d[0] = (uint32)-502; |
426 |
|
|
break; |
427 |
|
|
} |
428 |
|
|
break; |
429 |
|
|
} |
430 |
|
|
|
431 |
|
|
case M68K_EMUL_OP_IRQ: // Level 1 interrupt |
432 |
|
|
r->d[0] = 0; |
433 |
|
|
if (InterruptFlags & INTFLAG_60HZ) { |
434 |
|
|
ClearInterruptFlag(INTFLAG_60HZ); |
435 |
|
|
if (HasMacStarted()) { |
436 |
|
|
|
437 |
|
|
// Mac has started, execute video, ADB and Time Manager interrupt functions |
438 |
|
|
ADBInterrupt(); |
439 |
|
|
TimerInterrupt(); |
440 |
|
|
VideoInterrupt(); |
441 |
|
|
|
442 |
|
|
// Call DoVBLTask(0) |
443 |
|
|
if (ROMVersion == ROM_VERSION_32) { |
444 |
|
|
M68kRegisters r2; |
445 |
|
|
r2.d[0] = 0; |
446 |
|
|
Execute68kTrap(0xa072, &r2); |
447 |
|
|
} |
448 |
|
|
|
449 |
|
|
r->d[0] = 1; // Flag: 68k interrupt routine executes VBLTasks etc. |
450 |
|
|
} |
451 |
|
|
} |
452 |
|
|
if (InterruptFlags & INTFLAG_SERIAL) { |
453 |
|
|
ClearInterruptFlag(INTFLAG_SERIAL); |
454 |
|
|
SerialInterrupt(); |
455 |
|
|
} |
456 |
|
|
if (InterruptFlags & INTFLAG_ETHER) { |
457 |
|
|
ClearInterruptFlag(INTFLAG_ETHER); |
458 |
|
|
EtherInterrupt(); |
459 |
|
|
} |
460 |
|
|
if (InterruptFlags & INTFLAG_AUDIO) { |
461 |
|
|
ClearInterruptFlag(INTFLAG_AUDIO); |
462 |
|
|
AudioInterrupt(); |
463 |
|
|
} |
464 |
|
|
break; |
465 |
|
|
|
466 |
|
|
case M68K_EMUL_OP_PUT_SCRAP: { // PutScrap() patch |
467 |
|
|
void *scrap = Mac2HostAddr(ReadMacInt32(r->a[7] + 4)); |
468 |
|
|
uint32 type = ReadMacInt32(r->a[7] + 8); |
469 |
|
|
int32 length = ReadMacInt32(r->a[7] + 12); |
470 |
|
|
PutScrap(type, scrap, length); |
471 |
|
|
break; |
472 |
|
|
} |
473 |
|
|
|
474 |
|
|
case M68K_EMUL_OP_CHECKLOAD: { // vCheckLoad() patch (resource loader) |
475 |
|
|
uint32 type = r->d[1]; |
476 |
|
|
int16 id = ReadMacInt16(r->a[2]); |
477 |
|
|
if (r->a[0] == 0) |
478 |
|
|
break; |
479 |
|
|
uint32 adr = ReadMacInt32(r->a[0]); |
480 |
|
|
if (adr == 0) |
481 |
|
|
break; |
482 |
|
|
uint8 *p = Mac2HostAddr(adr); |
483 |
|
|
uint32 size = ReadMacInt32(adr - 8) & 0xffffff; |
484 |
|
|
CheckLoad(type, id, p, size); |
485 |
|
|
break; |
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
case M68K_EMUL_OP_AUDIO: // Audio component dispatch function |
489 |
|
|
r->d[0] = AudioDispatch(r->a[3], r->a[4]); |
490 |
|
|
break; |
491 |
|
|
|
492 |
|
|
default: |
493 |
|
|
printf("FATAL: EMUL_OP called with bogus opcode %08x\n", opcode); |
494 |
|
|
printf("d0 %08lx d1 %08lx d2 %08lx d3 %08lx\n" |
495 |
|
|
"d4 %08lx d5 %08lx d6 %08lx d7 %08lx\n" |
496 |
|
|
"a0 %08lx a1 %08lx a2 %08lx a3 %08lx\n" |
497 |
|
|
"a4 %08lx a5 %08lx a6 %08lx a7 %08lx\n" |
498 |
|
|
"sr %04x\n", |
499 |
|
|
r->d[0], r->d[1], r->d[2], r->d[3], r->d[4], r->d[5], r->d[6], r->d[7], |
500 |
|
|
r->a[0], r->a[1], r->a[2], r->a[3], r->a[4], r->a[5], r->a[6], r->a[7], |
501 |
|
|
r->sr); |
502 |
|
|
QuitEmulator(); |
503 |
|
|
break; |
504 |
|
|
} |
505 |
|
|
} |