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 |
228 |
|
TimerBase = (struct Library *)timereq->tr_node.io_Device; |
229 |
|
|
230 |
|
// Allocate scratch memory |
231 |
< |
ScratchMem = (uint32)AllocMem(SCRATCH_MEM_SIZE, MEMF_PUBLIC); |
231 |
> |
ScratchMem = (uint8 *)AllocMem(SCRATCH_MEM_SIZE, MEMF_PUBLIC); |
232 |
|
if (ScratchMem == NULL) { |
233 |
|
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
234 |
|
QuitEmulator(); |
242 |
|
WarningAlert(GetString(STR_SMALL_RAM_WARN)); |
243 |
|
RAMSize = 1024*1024; |
244 |
|
} |
245 |
< |
RAMBaseHost = (uint8 *)AllocMem(RAMSize + 0x100000, MEMF_PUBLIC); |
245 |
> |
RAMBaseHost = (uint8 *)AllocVec(RAMSize + 0x100000, MEMF_PUBLIC); |
246 |
|
if (RAMBaseHost == NULL) { |
247 |
< |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
248 |
< |
QuitEmulator(); |
247 |
> |
uint32 newRAMSize = AvailMem(MEMF_LARGEST) - 0x100000; |
248 |
> |
char xText[120]; |
249 |
> |
|
250 |
> |
sprintf(xText, GetString(STR_NOT_ENOUGH_MEM_WARN), RAMSize, newRAMSize); |
251 |
> |
|
252 |
> |
if (ChoiceAlert(xText, "Use", "Quit") != 1) |
253 |
> |
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 |
|
} |
262 |
|
RAMBaseMac = (uint32)RAMBaseHost; |
263 |
|
D(bug("Mac RAM starts at %08lx\n", RAMBaseHost)); |
325 |
|
// Set task priority to -1 so we don't use all processing time |
326 |
|
SetTaskPri(MainTask, -1); |
327 |
|
|
328 |
+ |
WriteMacInt32(0xbff, 0); // MacsBugFlags |
329 |
+ |
|
330 |
|
// Swap stack to Mac RAM area |
331 |
|
stack_swap.stk_Lower = RAMBaseHost; |
332 |
|
stack_swap.stk_Upper = (ULONG)RAMBaseHost + RAMSize; |
361 |
|
|
362 |
|
void QuitEmulator(void) |
363 |
|
{ |
364 |
+ |
// Stop 60Hz thread |
365 |
+ |
if (tick_proc) { |
366 |
+ |
SetSignal(0, SIGF_SINGLE); |
367 |
+ |
tick_proc_active = false; |
368 |
+ |
Wait(SIGF_SINGLE); |
369 |
+ |
} |
370 |
+ |
|
371 |
|
// Restore stack |
372 |
|
if (stack_swapped) { |
373 |
|
stack_swapped = false; |
381 |
|
FreeSignal(IRQSig); |
382 |
|
} |
383 |
|
|
363 |
– |
// Stop 60Hz thread |
364 |
– |
if (tick_proc) { |
365 |
– |
SetSignal(0, SIGF_SINGLE); |
366 |
– |
tick_proc_active = false; |
367 |
– |
Wait(SIGF_SINGLE); |
368 |
– |
} |
369 |
– |
|
384 |
|
// Remove trap handler |
385 |
|
MainTask->tc_TrapCode = OldTrapHandler; |
386 |
|
|
389 |
|
|
390 |
|
// Delete RAM/ROM area |
391 |
|
if (RAMBaseHost) |
392 |
< |
FreeMem(RAMBaseHost, RAMSize + 0x100000); |
392 |
> |
FreeVec(RAMBaseHost); |
393 |
|
|
394 |
|
// Delete scratch memory area |
395 |
|
if (ScratchMem) |
467 |
|
Signal(MainTask, IRQSigMask); |
468 |
|
} |
469 |
|
|
470 |
+ |
void TriggerNMI(void) |
471 |
+ |
{ |
472 |
+ |
AsmTriggerNMI(); |
473 |
+ |
} |
474 |
+ |
|
475 |
|
|
476 |
|
/* |
477 |
|
* 60Hz thread |
514 |
|
if (++tick_counter > 60) { |
515 |
|
tick_counter = 0; |
516 |
|
WriteMacInt32(0x20c, TimerDateTime()); |
517 |
+ |
SetInterruptFlag(INTFLAG_1HZ); |
518 |
+ |
TriggerInterrupt(); |
519 |
|
} |
520 |
|
|
521 |
|
// Trigger 60Hz interrupt |
629 |
|
EmulatedSR |= 0x0700; |
630 |
|
|
631 |
|
// Call opcode routine |
632 |
< |
EmulOp(*(uint16 *)(r->pc), (M68kRegisters *)r); |
632 |
> |
EmulOp(opcode, (M68kRegisters *)r); |
633 |
|
r->pc += 2; |
634 |
|
|
635 |
|
// Restore interrupts |