Improved stability during reboot

This commit is contained in:
kanjitalk755 2023-12-17 09:32:14 +09:00
parent 1ddb7d3a42
commit 1d8dd979ab
8 changed files with 43 additions and 14 deletions

View File

@ -1268,13 +1268,15 @@ static void one_tick(...)
}
#ifdef USE_PTHREADS_SERVICES
bool tick_inhibit;
static void *tick_func(void *arg)
{
uint64 start = GetTicks_usec();
int64 ticks = 0;
uint64 next = start;
while (!tick_thread_cancel) {
one_tick();
if (!tick_inhibit)
one_tick();
next += 16625;
int64 delay = next - GetTicks_usec();
if (delay > 0)

View File

@ -623,13 +623,15 @@ static void one_tick(...)
}
}
bool tick_inhibit;
static int tick_func(void *arg)
{
uint64 start = GetTicks_usec();
int64 ticks = 0;
uint64 next = GetTicks_usec();
while (!tick_thread_cancel) {
one_tick();
if (!tick_inhibit)
one_tick();
next += 16625;
int64 delay = next - GetTicks_usec();
if (delay > 0)

View File

@ -32,6 +32,7 @@
#include <string.h>
#include <vector>
#include <map>
#ifndef NO_STD_NAMESPACE
using std::vector;
@ -162,6 +163,7 @@ uint32 CDROMIconAddr;
// Flag: Control(accRun) has been called, interrupt routine is now active
static bool acc_run_called = false;
static std::map<int, void *> remount_map;
/*
* Get pointer to drive info or drives.end() if not found
@ -368,6 +370,17 @@ bool CDROMMountVolume(void *fh)
return false;
}
void CDROMRemount() {
for (std::map<int, void *>::iterator i = remount_map.begin(); i != remount_map.end(); ++i)
for (drive_vec::iterator info = drives.begin(); info != drives.end(); ++info)
if (info->num == i->first) {
last_drive_num = i->first;
info->fh = i->second;
break;
}
remount_map.clear();
}
/*
* Mount volumes for which the to_be_mounted flag is set
@ -568,13 +581,16 @@ int16 CDROMControl(uint32 pb, uint32 dce)
case 7: // EjectTheDisc
if (ReadMacInt8(info->status + dsDiskInPlace) > 0) {
SysAllowRemoval(info->fh);
SysEject(info->fh);
WriteMacInt8(info->status + dsDiskInPlace, 0);
info->twok_offset = -1;
info->close_fh();
if (info->drop) {
SysAllowRemoval(info->fh);
SysEject(info->fh);
info->twok_offset = -1;
info->close_fh();
info->drop = false;
}
else remount_map.insert(std::make_pair(ReadMacInt16(pb + ioVRefNum), info->fh));
info->fh = NULL;
info->drop = false;
WriteMacInt8(info->status + dsDiskInPlace, 0);
return noErr;
} else {
return offLinErr;

View File

@ -49,6 +49,8 @@
#define DEBUG 0
#include "debug.h"
extern bool tick_inhibit;
void PlayStartupSound();
/*
@ -57,7 +59,6 @@ void PlayStartupSound();
void EmulOp(uint16 opcode, M68kRegisters *r)
{
static bool bootflag;
D(bug("EmulOp %04x\n", opcode));
switch (opcode) {
case M68K_EMUL_BREAK: { // Breakpoint
@ -84,12 +85,9 @@ void EmulOp(uint16 opcode, M68kRegisters *r)
break;
case M68K_EMUL_OP_RESET: { // MacOS reset
if (bootflag) {
CDROMExit();
CDROMInit();
}
bootflag = true;
D(bug("*** RESET ***\n"));
tick_inhibit = true;
CDROMRemount(); // for System 7.x
TimerReset();
EtherReset();
AudioReset();
@ -116,6 +114,7 @@ void EmulOp(uint16 opcode, M68kRegisters *r)
r->a[1] = ROMBaseMac + UniversalInfo; // UniversalInfo
r->a[6] = boot_globs; // BootGlobs
r->a[7] = RAMBaseMac + 0x10000; // Boot stack
tick_inhibit = false;
break;
}

View File

@ -43,5 +43,6 @@ extern int16 CDROMStatus(uint32 pb, uint32 dce);
extern void CDROMOpenDone(void); // Called by CDROMOpen() once drives have been to the drive queue
void CDROMDrop(const char *path);
void CDROMRemount();
#endif

View File

@ -1438,6 +1438,7 @@ static void *nvram_func(void *arg)
* 60Hz thread (really 60.15Hz)
*/
bool tick_inhibit;
static void *tick_func(void *arg)
{
int tick_counter = 0;
@ -1454,6 +1455,7 @@ static void *tick_func(void *arg)
Delay_usec(delay);
else if (delay < -16625)
next = GetTicks_usec();
if (tick_inhibit) continue;
ticks++;
#if !EMULATED_PPC

View File

@ -638,6 +638,7 @@ static DWORD nvram_func(void *arg)
* 60Hz thread (really 60.15Hz)
*/
bool tick_inhibit;
static DWORD tick_func(void *arg)
{
int tick_counter = 0;
@ -654,6 +655,7 @@ static DWORD tick_func(void *arg)
Delay_usec(delay);
else if (delay < -16625)
next = GetTicks_usec();
if (tick_inhibit) continue;
ticks++;
// Pseudo Mac 1Hz interrupt, update local time

View File

@ -50,6 +50,8 @@
#define DEBUG 0
#include "debug.h"
extern bool tick_inhibit;
void PlayStartupSound();
// TVector of MakeExecutable
@ -283,6 +285,8 @@ void EmulOp(M68kRegisters *r, uint32 pc, int selector)
case OP_RESET: // Early in MacOS reset
D(bug("*** RESET ***\n"));
tick_inhibit = true;
CDROMRemount(); // for System 7.x
TimerReset();
MacOSUtilReset();
AudioReset();
@ -300,6 +304,7 @@ void EmulOp(M68kRegisters *r, uint32 pc, int selector)
memcpy((void *)DR_EMULATOR_BASE, (void *)(ROMBase + 0x370000), DR_EMULATOR_SIZE);
MakeExecutable(0, DR_EMULATOR_BASE, DR_EMULATOR_SIZE);
}
tick_inhibit = false;
break;
case OP_IRQ: // Level 1 interrupt