| Click here to select a new forum. |
| Software detection of emulator |
Posted by: David Cook on 2024-03-07 09:11:42 Hello everyone,
Does anyone know how to detect if an application is running in SheepShaver, Basilisk II, or Mini vMac? I'm writing a serial transfer utility and thought it would be nice to synchronize the real Macintosh's clock when it is connected to an emulated Mac.
For Basilisk II, I notice that it has a decent identifier in PDS slot #0.

The following code works: (I have a library of common routines that start with 'EL_' that check for nil pointers etc. Substitute for whatever you have.)
bool EL_IsEmulator(void)
{
bool isEmulator = false;
if (EL_IsTrapImplemented(_SlotManager))
{
OSErr errorCheck;
SpBlock slotSearch;
EL_MemoryClear(&slotSearch, sizeof(SpBlock));
slotSearch.spCategory = 1;
errorCheck = SNextTypeSRsrc(&slotSearch);
if (errorCheck == noErr)
{
slotSearch.spID = 2;
errorCheck = SGetCString(&slotSearch);
if (errorCheck == noErr)
{
char* slotNameCStringPtr = (char*) slotSearch.spResult;
if (EL_CStringCompare(slotNameCStringPtr, "Basilisk II Slot ROM", true, false) == 0)
{
isEmulator = true;
}
EL_DisposePtr(&slotNameCStringPtr);
}
}
}
return isEmulator;
}
I assume this is a reliable approach. Does anyone know of a more preferred way?
Does anyone know how to detect SheepShaver or Mini vMac?
Thank you,
David |
Posted by: Nixontheknight on 2024-03-07 10:04:59 sheepshaver's probably similar, try using TattleTech to confirm that. as for MiniVMac, you'd have to figure out if a certain extension is running |
Posted by: rplacd on 2024-03-07 10:22:17 I think mini vMac might have some special traps that are used to implement "secret sauce" file import/export utility apps from within the emulated environment.
(e.g. https://www.gryphel.com/c/minivmac/extras/importfl/index.html) |
Posted by: cheesestraws on 2024-03-07 10:57:27 Yes, look at the top of EXTNSLIB.I in the ImportFl source code: there's a function there (with the usual mini vmac slightly odd coding conventions) that will tell you whether or not the Mini vMac extension mechanism is present. |
Posted by: David Cook on 2024-03-07 16:31:50 Thank you @Nixontheknight @rplacd and @cheesestraws
This code works at least on recent versions of both Mini vMac and Basilisk. Notice that Basilisk sets the Sony pointer to DEADBEEF. Ha.
At some point, maybe I'll check out Sheep Shaver as well.
typedef enum
{
kEmulatorType_Unknown = 0,
kEmulatorType_None,
kEmulatorType_Basilisk,
kEmulatorType_MiniVMac,
kEmulatorType_SheepShaver
} EmulatorType;
EmulatorType el_gEmulatorType = kEmulatorType_None;
#define kEmulatorSonyIsBasilisk 0xDEADBEEF
#define kEmulatorSonyCheckValue 0x841339E2
typedef struct
{
unsigned long shouldBeZero[4];
unsigned long checkValue;
unsigned long pokeAddress;
} EmulatorSonyRecord;
#define LMGetSonyRecordPtr() (*(EmulatorSonyRecord**) 0x0134)
void EL_EmulatorCheckFloppy(void)
{
EmulatorSonyRecord* sonyRecordPtr = LMGetSonyRecordPtr();
if ((unsigned long)sonyRecordPtr == kEmulatorSonyIsBasilisk)
{
el_gEmulatorType = kEmulatorType_Basilisk;
}
else
{
// Cannot be nil or point to an odd address
if ( sonyRecordPtr != nil
&& (((unsigned long)sonyRecordPtr) & 1) == 0)
{
// Must have zeros and the proper check value
if ( sonyRecordPtr->shouldBeZero[0] == 0
&& sonyRecordPtr->shouldBeZero[1] == 0
&& sonyRecordPtr->shouldBeZero[2] == 0
// && sonyRecordPtr->shouldBeZero[3] == 0
&& sonyRecordPtr->checkValue == kEmulatorSonyCheckValue )
{
if (sonyRecordPtr->pokeAddress != nil)
{
el_gEmulatorType = kEmulatorType_MiniVMac;
}
}
}
}
} |
Posted by: cheesestraws on 2024-03-07 16:59:16 Perhaps I am being overly fastidious, but I must admit to rather preferring the slot manager approach for Basilisk II - it feels rather more transparent and sane. |
Posted by: David Cook on 2024-03-07 17:11:59
Perhaps I am being overly fastidious, but I must admit to rather preferring the slot manager approach for Basilisk II - it feels rather more transparent and sane.
I agree. It is definitive, compatible, and fitting.
I'm not sure how an emulated 128/512/Plus could indicate 'added hardware'. But, I imagine there is a way.
In my complete code, I first check the slot manager for Basilisk. If nothing, I then call the floppy routine. |
Posted by: NJRoadfan on 2024-03-07 18:52:35 Most emulators have a detection routine by poking a known memory address and reading back the result. Apple II emulators have a standardized way of doing this. |
Posted by: DBJ314 on 2024-03-12 15:19:49 SheepShaver patches the ROM in quite a few places. Maybe some of them are convenient.
https://github.com/cebix/macemu/blob/master/SheepShaver/src/rom_patches.cpp
https://github.com/cebix/macemu/blob/master/SheepShaver/src/rsrc_patches.cpp |
Posted by: joevt on 2024-03-13 03:20:30 Check the driver list and look for an emulator specific driver? Not helpful unless there's an emulator specific device. DingusPPC doesn't have its own drivers yet but does have its own hard disk drives and CD-ROM drives. |
| 1 |