ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/AmigaOS/main_amiga.cpp
(Generate patch)

Comparing BasiliskII/src/AmigaOS/main_amiga.cpp (file contents):
Revision 1.9 by jlachmann, 2000-08-20T14:08:41Z vs.
Revision 1.20 by jlachmann, 2001-10-16T17:27:52Z

# Line 1 | Line 1
1   /*
2   *  main_amiga.cpp - Startup code for AmigaOS
3   *
4 < *  Basilisk II (C) 1997-2000 Christian Bauer
4 > *  Basilisk II (C) 1997-2001 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
# Line 75 | Line 75 | uint32 ROMBaseMac;             // ROM base (Mac add
75   uint8 *ROMBaseHost;             // ROM base (host address space)
76   uint32 ROMSize;                 // Size of ROM
77  
78 uint32 MacsBugFlags = 0xbff;
79
78  
79   // CPU and FPU type, addressing mode
80   int CPUType;
# Line 99 | Line 97 | struct Library *AHIBase = NULL;
97   struct Library *DiskBase = NULL;
98  
99   struct Task *MainTask;                                                  // Our task
100 < uint32 ScratchMem = NULL;                                               // Scratch memory for Mac ROM writes
100 > uint8 *ScratchMem = NULL;                                               // Scratch memory for Mac ROM writes
101   APTR OldTrapHandler = NULL;                                             // Old trap handler
102   APTR OldExceptionHandler = NULL;                                // Old exception handler
103   BYTE IRQSig = -1;                                                               // "Interrupt" signal number
# Line 110 | Line 108 | static struct timerequest *timereq = NUL
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 *xpram_proc = NULL;               // XPRAM watchdog
112 + static volatile bool xpram_proc_active = true;  // Flag for quitting the XPRAM watchdog
113 +
114   static struct Process *tick_proc = NULL;                // 60Hz process
115   static volatile bool tick_proc_active = true;   // Flag for quitting the 60Hz process
116  
# Line 122 | Line 123 | struct trap_regs;
123   extern "C" void AtomicAnd(uint32 *p, uint32 val);
124   extern "C" void AtomicOr(uint32 *p, uint32 val);
125   extern "C" void MoveVBR(void);
126 + extern "C" void DisableSuperBypass(void);
127   extern "C" void TrapHandlerAsm(void);
128   extern "C" void ExceptionHandlerAsm(void);
129   extern "C" void IllInstrHandler(trap_regs *regs);
130   extern "C" void PrivViolHandler(trap_regs *regs);
131   extern "C" void quit_emulator(void);
132 + extern "C" void AsmTriggerNMI(void);
133   uint16 EmulatedSR;                                      // Emulated SR (supervisor bit and interrupt mask)
134  
135  
136   // Prototypes
137   static void jump_to_rom(void);
138 + static void xpram_func(void);
139   static void tick_func(void);
140  
141  
# Line 139 | Line 143 | static void tick_func(void);
143   *  Main program
144   */
145  
146 < int main(void)
146 > int main(int argc, char **argv)
147   {
148          // Initialize variables
149          RAMBaseHost = NULL;
# Line 170 | Line 174 | int main(void)
174                  QuitEmulator();
175          GadToolsBase = OpenLibrary((UBYTE *)"gadtools.library", 39);
176          if (GadToolsBase == NULL) {
177 <                ErrorAlert(GetString(STR_NO_GADTOOLS_LIB_ERR));
177 >                ErrorAlert(STR_NO_GADTOOLS_LIB_ERR);
178                  QuitEmulator();
179          }
180          IFFParseBase = OpenLibrary((UBYTE *)"iffparse.library", 39);
181          if (IFFParseBase == NULL) {
182 <                ErrorAlert(GetString(STR_NO_IFFPARSE_LIB_ERR));
182 >                ErrorAlert(STR_NO_IFFPARSE_LIB_ERR);
183                  QuitEmulator();
184          }
185          AslBase = OpenLibrary((UBYTE *)"asl.library", 36);
186          if (AslBase == NULL) {
187 <                ErrorAlert(GetString(STR_NO_ASL_LIB_ERR));
187 >                ErrorAlert(STR_NO_ASL_LIB_ERR);
188                  QuitEmulator();
189          }
190  
191 +        if (FindTask((UBYTE *) "« Enforcer »"))
192 +                {
193 +                ErrorAlert(STR_ENFORCER_RUNNING_ERR);
194 +                QuitEmulator();
195 +                }
196 +
197          // These two can fail (the respective gfx support won't be available, then)
198          P96Base = OpenLibrary((UBYTE *)"Picasso96API.library", 2);
199          CyberGfxBase = OpenLibrary((UBYTE *)"cybergraphics.library", 2);
200  
201          // Read preferences
202 <        PrefsInit();
202 >        PrefsInit(argc, argv);
203  
204          // Open AHI
205          ahi_port = CreateMsgPort();
# Line 213 | Line 223 | int main(void)
223  
224          // Check start of Chip memory (because we need access to 0x0000..0x2000)
225          if ((uint32)FindName(&SysBase->MemList, (UBYTE *)"chip memory") < 0x2000) {
226 <                ErrorAlert(GetString(STR_NO_PREPARE_EMUL_ERR));
226 >                ErrorAlert(STR_NO_PREPARE_EMUL_ERR);
227                  QuitEmulator();
228          }
229  
230          // Open timer.device
231          timereq = (struct timerequest *)AllocVec(sizeof(timerequest), MEMF_PUBLIC | MEMF_CLEAR);
232          if (timereq == NULL) {
233 <                ErrorAlert(GetString(STR_NO_MEM_ERR));
233 >                ErrorAlert(STR_NO_MEM_ERR);
234                  QuitEmulator();
235          }
236          if (OpenDevice((UBYTE *)TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timereq, 0)) {
237 <                ErrorAlert(GetString(STR_NO_TIMER_DEV_ERR));
237 >                ErrorAlert(STR_NO_TIMER_DEV_ERR);
238                  QuitEmulator();
239          }
240          TimerBase = (struct Library *)timereq->tr_node.io_Device;
241  
242          // Allocate scratch memory
243 <        ScratchMem = (uint32)AllocMem(SCRATCH_MEM_SIZE, MEMF_PUBLIC);
243 >        ScratchMem = (uint8 *)AllocMem(SCRATCH_MEM_SIZE, MEMF_PUBLIC);
244          if (ScratchMem == NULL) {
245 <                ErrorAlert(GetString(STR_NO_MEM_ERR));
245 >                ErrorAlert(STR_NO_MEM_ERR);
246                  QuitEmulator();
247          }
248          ScratchMem += SCRATCH_MEM_SIZE/2;       // ScratchMem points to middle of block
# Line 245 | Line 255 | int main(void)
255                  RAMSize = 1024*1024;
256          }
257          RAMBaseHost = (uint8 *)AllocVec(RAMSize + 0x100000, MEMF_PUBLIC);
258 < //      if (RAMBaseHost == NULL) {
249 < //              ErrorAlert(GetString(STR_NO_MEM_ERR));
250 < //              QuitEmulator();
251 < //      }
252 <        if (RAMBaseHost == NULL)
253 <                {
258 >        if (RAMBaseHost == NULL) {
259                  uint32 newRAMSize = AvailMem(MEMF_LARGEST) - 0x100000;
260                  char xText[120];
261  
262                  sprintf(xText, GetString(STR_NOT_ENOUGH_MEM_WARN), RAMSize, newRAMSize);
263  
264 <                if (1 != ChoiceAlert(xText, "Use", "Quit"))
264 >                if (ChoiceAlert(xText, "Use", "Quit") != 1)
265                          QuitEmulator();
266  
267                  RAMSize = newRAMSize;
268                  RAMBaseHost = (uint8 *)AllocVec(RAMSize + 0x100000, MEMF_PUBLIC);
269                  if (RAMBaseHost == NULL) {
270 <                        ErrorAlert(GetString(STR_NO_MEM_ERR));
270 >                        ErrorAlert(STR_NO_MEM_ERR);
271                          QuitEmulator();
272                  }
273 <                }
273 >        }
274          RAMBaseMac = (uint32)RAMBaseHost;
275          D(bug("Mac RAM starts at %08lx\n", RAMBaseHost));
276          ROMBaseHost = RAMBaseHost + RAMSize;
# Line 277 | Line 282 | int main(void)
282  
283          // Load Mac ROM
284          BPTR rom_fh = Open(rom_path ? (char *)rom_path : (char *)ROM_FILE_NAME, MODE_OLDFILE);
285 <        if (rom_fh == NULL) {
286 <                ErrorAlert(GetString(STR_NO_ROM_FILE_ERR));
285 >        if (rom_fh == 0) {
286 >                ErrorAlert(STR_NO_ROM_FILE_ERR);
287                  QuitEmulator();
288          }
289          printf(GetString(STR_READING_ROM_FILE));
290          Seek(rom_fh, 0, OFFSET_END);
291          ROMSize = Seek(rom_fh, 0, OFFSET_CURRENT);
292          if (ROMSize != 512*1024 && ROMSize != 1024*1024) {
293 <                ErrorAlert(GetString(STR_ROM_SIZE_ERR));
293 >                ErrorAlert(STR_ROM_SIZE_ERR);
294                  Close(rom_fh);
295                  QuitEmulator();
296          }
297          Seek(rom_fh, 0, OFFSET_BEGINNING);
298          if (Read(rom_fh, ROMBaseHost, ROMSize) != ROMSize) {
299 <                ErrorAlert(GetString(STR_ROM_FILE_READ_ERR));
299 >                ErrorAlert(STR_ROM_FILE_READ_ERR);
300                  Close(rom_fh);
301                  QuitEmulator();
302          }
# Line 309 | Line 314 | int main(void)
314          // Move VBR away from 0 if neccessary
315          MoveVBR();
316  
317 +        // On 68060, disable Super Bypass mode because of a CPU bug that is triggered by MacOS 8
318 +        if (CPUIs68060)
319 +                DisableSuperBypass();
320 +
321          // Install trap handler
322          EmulatedSR = 0x2700;
323          OldTrapHandler = MainTask->tc_TrapCode;
# Line 321 | Line 330 | int main(void)
330          MainTask->tc_ExceptCode = (APTR)ExceptionHandlerAsm;
331          SetExcept(SIGBREAKF_CTRL_C | IRQSigMask, SIGBREAKF_CTRL_C | IRQSigMask);
332  
333 +        // Start XPRAM watchdog process
334 +        xpram_proc = CreateNewProcTags(
335 +                NP_Entry, (ULONG)xpram_func,
336 +                NP_Name, (ULONG)"Basilisk II XPRAM Watchdog",
337 +                NP_Priority, 0,
338 +                TAG_END
339 +        );
340 +
341          // Start 60Hz process
342          tick_proc = CreateNewProcTags(
343                  NP_Entry, (ULONG)tick_func,
# Line 332 | Line 349 | int main(void)
349          // Set task priority to -1 so we don't use all processing time
350          SetTaskPri(MainTask, -1);
351  
352 <        WriteMacInt32(MacsBugFlags, 0);
352 >        WriteMacInt32(0xbff, 0);        // MacsBugFlags
353  
354          // Swap stack to Mac RAM area
355          stack_swap.stk_Lower = RAMBaseHost;
# Line 368 | Line 385 | void __saveds quit_emulator(void)
385  
386   void QuitEmulator(void)
387   {
388 <        // Stop 60Hz thread
388 >        // Stop 60Hz process
389          if (tick_proc) {
390                  SetSignal(0, SIGF_SINGLE);
391                  tick_proc_active = false;
392                  Wait(SIGF_SINGLE);
393          }
394  
395 +        // Stop XPRAM watchdog process
396 +        if (xpram_proc) {
397 +                SetSignal(0, SIGF_SINGLE);
398 +                xpram_proc_active = false;
399 +                Wait(SIGF_SINGLE);
400 +        }
401 +
402          // Restore stack
403          if (stack_swapped) {
404                  stack_swapped = false;
# Line 454 | Line 478 | void FlushCodeCache(void *start, uint32
478  
479  
480   /*
481 + *  Mutexes
482 + */
483 +
484 + struct B2_mutex {
485 +        int dummy;      //!!
486 + };
487 +
488 + B2_mutex *B2_create_mutex(void)
489 + {
490 +        return new B2_mutex;
491 + }
492 +
493 + void B2_lock_mutex(B2_mutex *mutex)
494 + {
495 + }
496 +
497 + void B2_unlock_mutex(B2_mutex *mutex)
498 + {
499 + }
500 +
501 + void B2_delete_mutex(B2_mutex *mutex)
502 + {
503 +        delete mutex;
504 + }
505 +
506 +
507 + /*
508   *  Interrupt flags (must be handled atomically!)
509   */
510  
# Line 481 | Line 532 | void TriggerNMI(void)
532  
533  
534   /*
535 < *  60Hz thread
535 > *  60Hz thread (really 60.15Hz)
536   */
537  
538   static __saveds void tick_func(void)
# Line 543 | Line 594 | static __saveds void tick_func(void)
594  
595          // Main task asked for termination, send signal
596          Forbid();
597 +        Signal(MainTask, SIGF_SINGLE);
598 + }
599 +
600 +
601 + /*
602 + *  XPRAM watchdog thread (saves XPRAM every minute)
603 + */
604 +
605 + static __saveds void xpram_func(void)
606 + {
607 +        uint8 last_xpram[XPRAM_SIZE];
608 +        memcpy(last_xpram, XPRAM, XPRAM_SIZE);
609 +
610 +        while (xpram_proc_active) {
611 +                for (int i=0; i<60 && xpram_proc_active; i++)
612 +                        Delay(50);              // Only wait 1 second so we quit promptly when xpram_proc_active becomes false
613 +                if (memcmp(last_xpram, XPRAM, XPRAM_SIZE)) {
614 +                        memcpy(last_xpram, XPRAM, XPRAM_SIZE);
615 +                        SaveXPRAM();
616 +                }
617 +        }
618 +
619 +        // Main task asked for termination, send signal
620 +        Forbid();
621          Signal(MainTask, SIGF_SINGLE);
622   }
623  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines