--- BasiliskII/src/AmigaOS/main_amiga.cpp 1999/10/19 19:28:15 1.3 +++ BasiliskII/src/AmigaOS/main_amiga.cpp 2000/09/04 16:30:47 1.10 @@ -1,7 +1,7 @@ /* * main_amiga.cpp - Startup code for AmigaOS * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2000 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,8 +56,9 @@ #include "debug.h" -// Our minimum stack requirement -unsigned long __stack = 0x4000; +// Options for libnix +unsigned long __stack = 0x4000; // Stack requirement +int __nocommandline = 1; // Disable command line parsing // Constants @@ -90,6 +91,7 @@ struct Library *GadToolsBase = NULL; struct Library *IFFParseBase = NULL; struct Library *AslBase = NULL; struct Library *P96Base = NULL; +struct Library *CyberGfxBase = NULL; struct Library *TimerBase = NULL; struct Library *AHIBase = NULL; struct Library *DiskBase = NULL; @@ -179,7 +181,10 @@ int main(void) ErrorAlert(GetString(STR_NO_ASL_LIB_ERR)); QuitEmulator(); } + + // These two can fail (the respective gfx support won't be available, then) P96Base = OpenLibrary((UBYTE *)"Picasso96API.library", 2); + CyberGfxBase = OpenLibrary((UBYTE *)"cybergraphics.library", 2); // Read preferences PrefsInit(); @@ -237,10 +242,22 @@ int main(void) WarningAlert(GetString(STR_SMALL_RAM_WARN)); RAMSize = 1024*1024; } - RAMBaseHost = (uint8 *)AllocMem(RAMSize + 0x100000, MEMF_PUBLIC); + RAMBaseHost = (uint8 *)AllocVec(RAMSize + 0x100000, MEMF_PUBLIC); if (RAMBaseHost == NULL) { - ErrorAlert(GetString(STR_NO_MEM_ERR)); - QuitEmulator(); + uint32 newRAMSize = AvailMem(MEMF_LARGEST) - 0x100000; + char xText[120]; + + sprintf(xText, GetString(STR_NOT_ENOUGH_MEM_WARN), RAMSize, newRAMSize); + + if (ChoiceAlert(xText, "Use", "Quit") != 1) + QuitEmulator(); + + RAMSize = newRAMSize; + RAMBaseHost = (uint8 *)AllocVec(RAMSize + 0x100000, MEMF_PUBLIC); + if (RAMBaseHost == NULL) { + ErrorAlert(GetString(STR_NO_MEM_ERR)); + QuitEmulator(); + } } RAMBaseMac = (uint32)RAMBaseHost; D(bug("Mac RAM starts at %08lx\n", RAMBaseHost)); @@ -308,6 +325,8 @@ int main(void) // Set task priority to -1 so we don't use all processing time SetTaskPri(MainTask, -1); + WriteMacInt32(0xbff, 0); // MacsBugFlags + // Swap stack to Mac RAM area stack_swap.stk_Lower = RAMBaseHost; stack_swap.stk_Upper = (ULONG)RAMBaseHost + RAMSize; @@ -342,6 +361,13 @@ void __saveds quit_emulator(void) void QuitEmulator(void) { + // Stop 60Hz thread + if (tick_proc) { + SetSignal(0, SIGF_SINGLE); + tick_proc_active = false; + Wait(SIGF_SINGLE); + } + // Restore stack if (stack_swapped) { stack_swapped = false; @@ -355,13 +381,6 @@ void QuitEmulator(void) FreeSignal(IRQSig); } - // Stop 60Hz thread - if (tick_proc) { - SetSignal(0, SIGF_SINGLE); - tick_proc_active = false; - Wait(SIGF_SINGLE); - } - // Remove trap handler MainTask->tc_TrapCode = OldTrapHandler; @@ -370,7 +389,7 @@ void QuitEmulator(void) // Delete RAM/ROM area if (RAMBaseHost) - FreeMem(RAMBaseHost, RAMSize + 0x100000); + FreeVec(RAMBaseHost); // Delete scratch memory area if (ScratchMem) @@ -397,6 +416,8 @@ void QuitEmulator(void) PrefsExit(); // Close libraries + if (CyberGfxBase) + CloseLibrary(CyberGfxBase); if (P96Base) CloseLibrary(P96Base); if (AslBase) @@ -446,6 +467,11 @@ void TriggerInterrupt(void) Signal(MainTask, IRQSigMask); } +void TriggerNMI(void) +{ + AsmTriggerNMI(); +} + /* * 60Hz thread @@ -488,6 +514,8 @@ static __saveds void tick_func(void) if (++tick_counter > 60) { tick_counter = 0; WriteMacInt32(0x20c, TimerDateTime()); + SetInterruptFlag(INTFLAG_1HZ); + TriggerInterrupt(); } // Trigger 60Hz interrupt @@ -601,7 +629,7 @@ void __saveds IllInstrHandler(trap_regs EmulatedSR |= 0x0700; // Call opcode routine - EmulOp(*(uint16 *)(r->pc), (M68kRegisters *)r); + EmulOp(opcode, (M68kRegisters *)r); r->pc += 2; // Restore interrupts