ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/AmigaOS/main_amiga.cpp
Revision: 1.11
Committed: 2000-09-22T17:22:40Z (24 years, 2 months ago) by gbeauche
Branch: MAIN
Changes since 1.10: +2 -2 lines
Log Message:
- changed type of ScratchMem from uint32 to uint8 *

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * main_amiga.cpp - Startup code for AmigaOS
3     *
4 cebix 1.5 * Basilisk II (C) 1997-2000 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 <exec/types.h>
22     #include <exec/execbase.h>
23     #include <exec/memory.h>
24     #include <exec/tasks.h>
25     #include <dos/dostags.h>
26     #include <intuition/intuition.h>
27     #include <devices/timer.h>
28     #include <devices/ahi.h>
29     #include <proto/exec.h>
30     #include <proto/dos.h>
31     #include <proto/intuition.h>
32    
33     #include "sysdeps.h"
34     #include "cpu_emulation.h"
35     #include "main.h"
36     #include "xpram.h"
37     #include "timer.h"
38     #include "sony.h"
39     #include "disk.h"
40     #include "cdrom.h"
41     #include "scsi.h"
42     #include "audio.h"
43     #include "video.h"
44     #include "serial.h"
45     #include "ether.h"
46     #include "clip.h"
47     #include "emul_op.h"
48     #include "rom_patches.h"
49     #include "prefs.h"
50     #include "prefs_editor.h"
51     #include "sys.h"
52     #include "user_strings.h"
53     #include "version.h"
54    
55     #define DEBUG 0
56     #include "debug.h"
57    
58    
59 cebix 1.4 // Options for libnix
60     unsigned long __stack = 0x4000; // Stack requirement
61     int __nocommandline = 1; // Disable command line parsing
62 cebix 1.3
63    
64 cebix 1.1 // Constants
65     static const char ROM_FILE_NAME[] = "ROM";
66 cebix 1.3 static const char __ver[] = "$VER: " VERSION_STRING " " __DATE__;
67 cebix 1.1 static const int SCRATCH_MEM_SIZE = 65536;
68    
69    
70     // RAM and ROM pointers
71     uint32 RAMBaseMac; // RAM base (Mac address space)
72     uint8 *RAMBaseHost; // RAM base (host address space)
73     uint32 RAMSize; // Size of RAM
74     uint32 ROMBaseMac; // ROM base (Mac address space)
75     uint8 *ROMBaseHost; // ROM base (host address space)
76     uint32 ROMSize; // Size of ROM
77    
78    
79     // CPU and FPU type, addressing mode
80     int CPUType;
81     bool CPUIs68060;
82     int FPUType;
83     bool TwentyFourBitAddressing;
84    
85    
86     // Global variables
87     extern ExecBase *SysBase;
88 cebix 1.3 struct Library *GfxBase = NULL;
89     struct IntuitionBase *IntuitionBase = NULL;
90 cebix 1.1 struct Library *GadToolsBase = NULL;
91 cebix 1.3 struct Library *IFFParseBase = NULL;
92 cebix 1.1 struct Library *AslBase = NULL;
93     struct Library *P96Base = NULL;
94 cebix 1.6 struct Library *CyberGfxBase = NULL;
95 cebix 1.1 struct Library *TimerBase = NULL;
96     struct Library *AHIBase = NULL;
97     struct Library *DiskBase = NULL;
98    
99     struct Task *MainTask; // Our task
100 gbeauche 1.11 uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes
101 cebix 1.1 APTR OldTrapHandler = NULL; // Old trap handler
102     APTR OldExceptionHandler = NULL; // Old exception handler
103     BYTE IRQSig = -1; // "Interrupt" signal number
104     ULONG IRQSigMask = 0; // "Interrupt" signal mask
105    
106     static struct timerequest *timereq = NULL; // IORequest for timer
107    
108     static struct MsgPort *ahi_port = NULL; // Port for AHI
109     static struct AHIRequest *ahi_io = NULL; // IORequest for AHI
110    
111     static struct Process *tick_proc = NULL; // 60Hz process
112     static volatile bool tick_proc_active = true; // Flag for quitting the 60Hz process
113    
114     static bool stack_swapped = false; // Stack swapping
115     static StackSwapStruct stack_swap;
116    
117    
118     // Assembly functions
119     struct trap_regs;
120     extern "C" void AtomicAnd(uint32 *p, uint32 val);
121     extern "C" void AtomicOr(uint32 *p, uint32 val);
122     extern "C" void MoveVBR(void);
123     extern "C" void TrapHandlerAsm(void);
124     extern "C" void ExceptionHandlerAsm(void);
125     extern "C" void IllInstrHandler(trap_regs *regs);
126     extern "C" void PrivViolHandler(trap_regs *regs);
127 cebix 1.3 extern "C" void quit_emulator(void);
128 cebix 1.1 uint16 EmulatedSR; // Emulated SR (supervisor bit and interrupt mask)
129    
130    
131 cebix 1.3 // Prototypes
132     static void jump_to_rom(void);
133     static void tick_func(void);
134    
135    
136 cebix 1.1 /*
137     * Main program
138     */
139    
140     int main(void)
141     {
142     // Initialize variables
143     RAMBaseHost = NULL;
144     ROMBaseHost = NULL;
145     MainTask = FindTask(NULL);
146     struct DateStamp ds;
147     DateStamp(&ds);
148     srand(ds.ds_Tick);
149    
150     // Print some info
151     printf(GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR);
152     printf(" %s\n", GetString(STR_ABOUT_TEXT2));
153    
154     // Open libraries
155 cebix 1.3 GfxBase = OpenLibrary((UBYTE *)"graphics.library", 39);
156     if (GfxBase == NULL) {
157     printf("Cannot open graphics.library V39.\n");
158     exit(1);
159     }
160     IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library", 39);
161     if (IntuitionBase == NULL) {
162     printf("Cannot open intuition.library V39.\n");
163     CloseLibrary(GfxBase);
164     exit(1);
165     }
166 cebix 1.1 DiskBase = (struct Library *)OpenResource((UBYTE *)"disk.resource");
167     if (DiskBase == NULL)
168     QuitEmulator();
169     GadToolsBase = OpenLibrary((UBYTE *)"gadtools.library", 39);
170     if (GadToolsBase == NULL) {
171     ErrorAlert(GetString(STR_NO_GADTOOLS_LIB_ERR));
172     QuitEmulator();
173     }
174 cebix 1.3 IFFParseBase = OpenLibrary((UBYTE *)"iffparse.library", 39);
175     if (IFFParseBase == NULL) {
176     ErrorAlert(GetString(STR_NO_IFFPARSE_LIB_ERR));
177     QuitEmulator();
178     }
179 cebix 1.1 AslBase = OpenLibrary((UBYTE *)"asl.library", 36);
180     if (AslBase == NULL) {
181     ErrorAlert(GetString(STR_NO_ASL_LIB_ERR));
182     QuitEmulator();
183     }
184 cebix 1.6
185     // These two can fail (the respective gfx support won't be available, then)
186 cebix 1.1 P96Base = OpenLibrary((UBYTE *)"Picasso96API.library", 2);
187 cebix 1.6 CyberGfxBase = OpenLibrary((UBYTE *)"cybergraphics.library", 2);
188 cebix 1.1
189 cebix 1.3 // Read preferences
190     PrefsInit();
191    
192 cebix 1.1 // Open AHI
193     ahi_port = CreateMsgPort();
194     if (ahi_port) {
195     ahi_io = (struct AHIRequest *)CreateIORequest(ahi_port, sizeof(struct AHIRequest));
196     if (ahi_io) {
197     ahi_io->ahir_Version = 2;
198     if (OpenDevice((UBYTE *)AHINAME, AHI_NO_UNIT, (struct IORequest *)ahi_io, 0) == 0) {
199     AHIBase = (struct Library *)ahi_io->ahir_Std.io_Device;
200     }
201     }
202     }
203    
204     // Init system routines
205     SysInit();
206    
207     // Show preferences editor
208     if (!PrefsFindBool("nogui"))
209     if (!PrefsEditor())
210     QuitEmulator();
211    
212     // Check start of Chip memory (because we need access to 0x0000..0x2000)
213     if ((uint32)FindName(&SysBase->MemList, (UBYTE *)"chip memory") < 0x2000) {
214     ErrorAlert(GetString(STR_NO_PREPARE_EMUL_ERR));
215     QuitEmulator();
216     }
217    
218     // Open timer.device
219     timereq = (struct timerequest *)AllocVec(sizeof(timerequest), MEMF_PUBLIC | MEMF_CLEAR);
220     if (timereq == NULL) {
221     ErrorAlert(GetString(STR_NO_MEM_ERR));
222     QuitEmulator();
223     }
224     if (OpenDevice((UBYTE *)TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timereq, 0)) {
225     ErrorAlert(GetString(STR_NO_TIMER_DEV_ERR));
226     QuitEmulator();
227     }
228     TimerBase = (struct Library *)timereq->tr_node.io_Device;
229    
230     // Allocate scratch memory
231 gbeauche 1.11 ScratchMem = (uint8 *)AllocMem(SCRATCH_MEM_SIZE, MEMF_PUBLIC);
232 cebix 1.1 if (ScratchMem == NULL) {
233     ErrorAlert(GetString(STR_NO_MEM_ERR));
234     QuitEmulator();
235     }
236     ScratchMem += SCRATCH_MEM_SIZE/2; // ScratchMem points to middle of block
237    
238     // Create area for Mac RAM and ROM (ROM must be higher in memory,
239     // so we allocate one big chunk and put the ROM at the top of it)
240     RAMSize = PrefsFindInt32("ramsize") & 0xfff00000; // Round down to 1MB boundary
241     if (RAMSize < 1024*1024) {
242     WarningAlert(GetString(STR_SMALL_RAM_WARN));
243     RAMSize = 1024*1024;
244     }
245 jlachmann 1.9 RAMBaseHost = (uint8 *)AllocVec(RAMSize + 0x100000, MEMF_PUBLIC);
246 cebix 1.10 if (RAMBaseHost == NULL) {
247 jlachmann 1.9 uint32 newRAMSize = AvailMem(MEMF_LARGEST) - 0x100000;
248     char xText[120];
249    
250     sprintf(xText, GetString(STR_NOT_ENOUGH_MEM_WARN), RAMSize, newRAMSize);
251    
252 cebix 1.10 if (ChoiceAlert(xText, "Use", "Quit") != 1)
253 jlachmann 1.9 QuitEmulator();
254    
255     RAMSize = newRAMSize;
256     RAMBaseHost = (uint8 *)AllocVec(RAMSize + 0x100000, MEMF_PUBLIC);
257     if (RAMBaseHost == NULL) {
258     ErrorAlert(GetString(STR_NO_MEM_ERR));
259     QuitEmulator();
260     }
261 cebix 1.10 }
262 cebix 1.1 RAMBaseMac = (uint32)RAMBaseHost;
263     D(bug("Mac RAM starts at %08lx\n", RAMBaseHost));
264     ROMBaseHost = RAMBaseHost + RAMSize;
265     ROMBaseMac = (uint32)ROMBaseHost;
266     D(bug("Mac ROM starts at %08lx\n", ROMBaseHost));
267    
268     // Get rom file path from preferences
269     const char *rom_path = PrefsFindString("rom");
270    
271     // Load Mac ROM
272 cebix 1.3 BPTR rom_fh = Open(rom_path ? (char *)rom_path : (char *)ROM_FILE_NAME, MODE_OLDFILE);
273 cebix 1.1 if (rom_fh == NULL) {
274     ErrorAlert(GetString(STR_NO_ROM_FILE_ERR));
275     QuitEmulator();
276     }
277     printf(GetString(STR_READING_ROM_FILE));
278     Seek(rom_fh, 0, OFFSET_END);
279     ROMSize = Seek(rom_fh, 0, OFFSET_CURRENT);
280     if (ROMSize != 512*1024 && ROMSize != 1024*1024) {
281     ErrorAlert(GetString(STR_ROM_SIZE_ERR));
282     Close(rom_fh);
283     QuitEmulator();
284     }
285     Seek(rom_fh, 0, OFFSET_BEGINNING);
286     if (Read(rom_fh, ROMBaseHost, ROMSize) != ROMSize) {
287     ErrorAlert(GetString(STR_ROM_FILE_READ_ERR));
288     Close(rom_fh);
289     QuitEmulator();
290     }
291    
292     // Set CPU and FPU type
293     UWORD attn = SysBase->AttnFlags;
294     CPUType = attn & AFF_68040 ? 4 : (attn & AFF_68030 ? 3 : 2);
295     CPUIs68060 = attn & AFF_68060;
296     FPUType = attn & AFF_68881 ? 1 : 0;
297    
298 cebix 1.2 // Initialize everything
299     if (!InitAll())
300 cebix 1.1 QuitEmulator();
301    
302     // Move VBR away from 0 if neccessary
303     MoveVBR();
304    
305     // Install trap handler
306     EmulatedSR = 0x2700;
307     OldTrapHandler = MainTask->tc_TrapCode;
308     MainTask->tc_TrapCode = (APTR)TrapHandlerAsm;
309    
310     // Allocate signal for interrupt emulation and install exception handler
311     IRQSig = AllocSignal(-1);
312     IRQSigMask = 1 << IRQSig;
313     OldExceptionHandler = MainTask->tc_ExceptCode;
314     MainTask->tc_ExceptCode = (APTR)ExceptionHandlerAsm;
315     SetExcept(SIGBREAKF_CTRL_C | IRQSigMask, SIGBREAKF_CTRL_C | IRQSigMask);
316    
317     // Start 60Hz process
318     tick_proc = CreateNewProcTags(
319 cebix 1.3 NP_Entry, (ULONG)tick_func,
320     NP_Name, (ULONG)"Basilisk II 60Hz",
321 cebix 1.1 NP_Priority, 5,
322     TAG_END
323     );
324    
325     // Set task priority to -1 so we don't use all processing time
326     SetTaskPri(MainTask, -1);
327    
328 cebix 1.10 WriteMacInt32(0xbff, 0); // MacsBugFlags
329 jlachmann 1.9
330 cebix 1.1 // Swap stack to Mac RAM area
331     stack_swap.stk_Lower = RAMBaseHost;
332     stack_swap.stk_Upper = (ULONG)RAMBaseHost + RAMSize;
333     stack_swap.stk_Pointer = RAMBaseHost + 0x8000;
334     StackSwap(&stack_swap);
335     stack_swapped = true;
336    
337     // Jump to ROM boot routine
338     Start680x0();
339    
340     QuitEmulator();
341     return 0;
342     }
343    
344     void Start680x0(void)
345     {
346     typedef void (*rom_func)(void);
347     rom_func fp = (rom_func)(ROMBaseHost + 0x2a);
348     fp();
349     }
350    
351    
352     /*
353     * Quit emulator (__saveds because it might be called from an exception)
354     */
355    
356 cebix 1.3 // Assembly entry point
357     void __saveds quit_emulator(void)
358     {
359     QuitEmulator();
360     }
361    
362     void QuitEmulator(void)
363 cebix 1.1 {
364 cebix 1.7 // Stop 60Hz thread
365     if (tick_proc) {
366     SetSignal(0, SIGF_SINGLE);
367     tick_proc_active = false;
368     Wait(SIGF_SINGLE);
369     }
370    
371 cebix 1.1 // Restore stack
372     if (stack_swapped) {
373     stack_swapped = false;
374     StackSwap(&stack_swap);
375     }
376    
377     // Remove exception handler
378     if (IRQSig >= 0) {
379     SetExcept(0, SIGBREAKF_CTRL_C | IRQSigMask);
380     MainTask->tc_ExceptCode = OldExceptionHandler;
381     FreeSignal(IRQSig);
382     }
383    
384     // Remove trap handler
385     MainTask->tc_TrapCode = OldTrapHandler;
386    
387 cebix 1.2 // Deinitialize everything
388     ExitAll();
389 cebix 1.1
390     // Delete RAM/ROM area
391     if (RAMBaseHost)
392 jlachmann 1.9 FreeVec(RAMBaseHost);
393 cebix 1.1
394     // Delete scratch memory area
395     if (ScratchMem)
396     FreeMem((void *)(ScratchMem - SCRATCH_MEM_SIZE/2), SCRATCH_MEM_SIZE);
397    
398     // Close timer.device
399     if (TimerBase)
400     CloseDevice((struct IORequest *)timereq);
401     if (timereq)
402     FreeVec(timereq);
403    
404     // Exit system routines
405     SysExit();
406    
407     // Close AHI
408     if (AHIBase)
409     CloseDevice((struct IORequest *)ahi_io);
410     if (ahi_io)
411     DeleteIORequest((struct IORequest *)ahi_io);
412     if (ahi_port)
413     DeleteMsgPort(ahi_port);
414    
415     // Exit preferences
416     PrefsExit();
417    
418     // Close libraries
419 cebix 1.6 if (CyberGfxBase)
420     CloseLibrary(CyberGfxBase);
421 cebix 1.1 if (P96Base)
422     CloseLibrary(P96Base);
423     if (AslBase)
424     CloseLibrary(AslBase);
425 cebix 1.3 if (IFFParseBase)
426     CloseLibrary(IFFParseBase);
427 cebix 1.1 if (GadToolsBase)
428     CloseLibrary(GadToolsBase);
429 cebix 1.3 if (IntuitionBase)
430     CloseLibrary((struct Library *)IntuitionBase);
431     if (GfxBase)
432     CloseLibrary(GfxBase);
433 cebix 1.1
434     exit(0);
435     }
436    
437    
438     /*
439     * Code was patched, flush caches if neccessary (i.e. when using a real 680x0
440     * or a dynamically recompiling emulator)
441     */
442    
443     void FlushCodeCache(void *start, uint32 size)
444     {
445     CacheClearE(start, size, CACRF_ClearI | CACRF_ClearD);
446     }
447    
448    
449     /*
450     * Interrupt flags (must be handled atomically!)
451     */
452    
453     uint32 InterruptFlags;
454    
455     void SetInterruptFlag(uint32 flag)
456     {
457     AtomicOr(&InterruptFlags, flag);
458     }
459    
460     void ClearInterruptFlag(uint32 flag)
461     {
462     AtomicAnd(&InterruptFlags, ~flag);
463     }
464    
465     void TriggerInterrupt(void)
466     {
467     Signal(MainTask, IRQSigMask);
468 jlachmann 1.9 }
469    
470     void TriggerNMI(void)
471     {
472     AsmTriggerNMI();
473 cebix 1.1 }
474    
475    
476     /*
477     * 60Hz thread
478     */
479    
480     static __saveds void tick_func(void)
481     {
482     int tick_counter = 0;
483     struct MsgPort *timer_port = NULL;
484     struct timerequest *timer_io = NULL;
485     ULONG timer_mask = 0;
486    
487     // Start 60Hz timer
488     timer_port = CreateMsgPort();
489     if (timer_port) {
490     timer_io = (struct timerequest *)CreateIORequest(timer_port, sizeof(struct timerequest));
491     if (timer_io) {
492     if (!OpenDevice((UBYTE *)TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timer_io, 0)) {
493     timer_mask = 1 << timer_port->mp_SigBit;
494     timer_io->tr_node.io_Command = TR_ADDREQUEST;
495     timer_io->tr_time.tv_secs = 0;
496     timer_io->tr_time.tv_micro = 16625;
497     SendIO((struct IORequest *)timer_io);
498     }
499     }
500     }
501    
502     while (tick_proc_active) {
503    
504     // Wait for timer tick
505     Wait(timer_mask);
506    
507     // Restart timer
508     timer_io->tr_node.io_Command = TR_ADDREQUEST;
509     timer_io->tr_time.tv_secs = 0;
510     timer_io->tr_time.tv_micro = 16625;
511     SendIO((struct IORequest *)timer_io);
512    
513     // Pseudo Mac 1Hz interrupt, update local time
514     if (++tick_counter > 60) {
515     tick_counter = 0;
516     WriteMacInt32(0x20c, TimerDateTime());
517 cebix 1.7 SetInterruptFlag(INTFLAG_1HZ);
518     TriggerInterrupt();
519 cebix 1.1 }
520    
521     // Trigger 60Hz interrupt
522     SetInterruptFlag(INTFLAG_60HZ);
523     TriggerInterrupt();
524     }
525    
526     // Stop timer
527     if (timer_io) {
528     if (!CheckIO((struct IORequest *)timer_io))
529     AbortIO((struct IORequest *)timer_io);
530     WaitIO((struct IORequest *)timer_io);
531     CloseDevice((struct IORequest *)timer_io);
532     DeleteIORequest(timer_io);
533     }
534     if (timer_port)
535     DeleteMsgPort(timer_port);
536    
537     // Main task asked for termination, send signal
538     Forbid();
539     Signal(MainTask, SIGF_SINGLE);
540     }
541    
542    
543     /*
544     * Display error alert
545     */
546    
547     void ErrorAlert(const char *text)
548     {
549     if (PrefsFindBool("nogui")) {
550     printf(GetString(STR_SHELL_ERROR_PREFIX), text);
551     return;
552     }
553     EasyStruct req;
554     req.es_StructSize = sizeof(EasyStruct);
555     req.es_Flags = 0;
556     req.es_Title = (UBYTE *)GetString(STR_ERROR_ALERT_TITLE);
557     req.es_TextFormat = (UBYTE *)GetString(STR_GUI_ERROR_PREFIX);
558     req.es_GadgetFormat = (UBYTE *)GetString(STR_QUIT_BUTTON);
559 cebix 1.3 EasyRequest(NULL, &req, NULL, (ULONG)text);
560 cebix 1.1 }
561    
562    
563     /*
564     * Display warning alert
565     */
566    
567     void WarningAlert(const char *text)
568     {
569     if (PrefsFindBool("nogui")) {
570     printf(GetString(STR_SHELL_WARNING_PREFIX), text);
571     return;
572     }
573     EasyStruct req;
574     req.es_StructSize = sizeof(EasyStruct);
575     req.es_Flags = 0;
576     req.es_Title = (UBYTE *)GetString(STR_WARNING_ALERT_TITLE);
577     req.es_TextFormat = (UBYTE *)GetString(STR_GUI_WARNING_PREFIX);
578     req.es_GadgetFormat = (UBYTE *)GetString(STR_OK_BUTTON);
579 cebix 1.3 EasyRequest(NULL, &req, NULL, (ULONG)text);
580 cebix 1.1 }
581    
582    
583     /*
584     * Display choice alert
585     */
586    
587     bool ChoiceAlert(const char *text, const char *pos, const char *neg)
588     {
589     char str[256];
590     sprintf(str, "%s|%s", pos, neg);
591     EasyStruct req;
592     req.es_StructSize = sizeof(EasyStruct);
593     req.es_Flags = 0;
594     req.es_Title = (UBYTE *)GetString(STR_WARNING_ALERT_TITLE);
595     req.es_TextFormat = (UBYTE *)GetString(STR_GUI_WARNING_PREFIX);
596     req.es_GadgetFormat = (UBYTE *)str;
597 cebix 1.3 return EasyRequest(NULL, &req, NULL, (ULONG)text);
598 cebix 1.1 }
599    
600    
601     /*
602     * Illegal Instruction and Privilege Violation trap handlers
603     */
604    
605     struct trap_regs { // This must match the layout of M68kRegisters
606     uint32 d[8];
607     uint32 a[8];
608     uint16 sr;
609     uint32 pc;
610     };
611    
612     void __saveds IllInstrHandler(trap_regs *r)
613     {
614     uint16 opcode = *(uint16 *)(r->pc);
615     if ((opcode & 0xff00) != 0x7100) {
616     printf("Illegal Instruction %04x at %08lx\n", *(uint16 *)(r->pc), r->pc);
617     printf("d0 %08lx d1 %08lx d2 %08lx d3 %08lx\n"
618     "d4 %08lx d5 %08lx d6 %08lx d7 %08lx\n"
619     "a0 %08lx a1 %08lx a2 %08lx a3 %08lx\n"
620     "a4 %08lx a5 %08lx a6 %08lx a7 %08lx\n"
621     "sr %04x\n",
622     r->d[0], r->d[1], r->d[2], r->d[3], r->d[4], r->d[5], r->d[6], r->d[7],
623     r->a[0], r->a[1], r->a[2], r->a[3], r->a[4], r->a[5], r->a[6], r->a[7],
624     r->sr);
625     QuitEmulator();
626     } else {
627     // Disable interrupts
628     uint16 sr = EmulatedSR;
629     EmulatedSR |= 0x0700;
630    
631     // Call opcode routine
632 cebix 1.8 EmulOp(opcode, (M68kRegisters *)r);
633 cebix 1.1 r->pc += 2;
634    
635     // Restore interrupts
636     EmulatedSR = sr;
637     if ((EmulatedSR & 0x0700) == 0 && InterruptFlags)
638     Signal(MainTask, IRQSigMask);
639     }
640     }
641    
642     void __saveds PrivViolHandler(trap_regs *r)
643     {
644     printf("Privileged instruction %04x %04x at %08lx\n", *(uint16 *)(r->pc), *(uint16 *)(r->pc + 2), r->pc);
645     printf("d0 %08lx d1 %08lx d2 %08lx d3 %08lx\n"
646     "d4 %08lx d5 %08lx d6 %08lx d7 %08lx\n"
647     "a0 %08lx a1 %08lx a2 %08lx a3 %08lx\n"
648     "a4 %08lx a5 %08lx a6 %08lx a7 %08lx\n"
649     "sr %04x\n",
650     r->d[0], r->d[1], r->d[2], r->d[3], r->d[4], r->d[5], r->d[6], r->d[7],
651     r->a[0], r->a[1], r->a[2], r->a[3], r->a[4], r->a[5], r->a[6], r->a[7],
652     r->sr);
653     QuitEmulator();
654     }