Let's document Sheepshaver's code
Posted: Mon Oct 24, 2016 9:52 pm
Before I begin, Sheepshaver's code is here. Sheepshaver hasn't seen much development since Gwenole left. The most significant patch in memory is a patch that allows some Ambrosia games like Escape Velocity: Nova and Ferazel's Wand to run under Sheepshaver. There's also a monitor/disassembler named cxmon, which was recently put into the macemu tree.
Here are some notable places under macemu/SheepShaver/src/ :
/dummy - Empty files used for whenever a component is not available.
/emul_ppc - The original Sheepshaver core. No longer used and is effectively dummied out by sheepshaver_glue.cpp in the below folder.
/kpx_cpu - The current Sheepshaver core.
emul_op.cpp - Emulating various operations that were 68k code in the original ROM.
gfxaccel.cpp - Quickdraw (2D) acceleration, but it only handles some basic functions.
main.cpp - This is where Sheepshaver initializes everything, poking the XPRAM to values expected by Mac OS.
name_registry.cpp - Set up the names for the devices, such as the processors and the ethernet devices.
prefs_items.cpp - Items referenced by the preferences files.
video.cpp - Video emulation.
rom_patches.cpp - Patches for the ROM. There are patches used for New World ROMs compiled in 1998 and 1999, but mainly focuses the Old World ROMs.
rsrc_patches.cpp - Patches based on the OS's resource forks.
timer.cpp - Time Manager emulation. This is an emulation of the Time Manager, but using the Unix functions.
Of course, several files are shortcuts to files in Basilisk II, reusing the audio, CD, and disk functionality from that.
There are also .i files, which are really binaries. To see these in a hex editor and disassemble them easier...
1)Open the .i file up any word processor
2)Replace 0x and , with blanks.
3)Copy and paste into the editor.
The original code for these driver stubs hasn't been found yet and I don't think it was included.
Patterns I've noticed in the code so far:
D(bug("String\n")); <- Used whenever the debug mode is enabled, noting which function was enabled
ReadMacInt32(), ReadMacInt16() <- Trying to read from the emulated Mac's memory.
FindLibSymbol() <- Not common, but it's supposed to be used any time Sheepshaver is trying to find a library within the Mac OS itself.
As for the video driver stub, there are exactly two functions: TheDriverDescription, and DoDriverIO. It's very primitive, being under 512 bytes. I'll check out the other stubs included.
Inside kpx_cpu, you have four folders:
cpu - The main code for the CPU
mathlib - Used for the floating point operations
test - PowerPC regression testing, but it's largely floating point and integer operations... and some AltiVec/VMX ones.
utils - Processor check, but this is largely for the x86 processors
There's also ppc-dis.c, which is a file straight from GNU, and is now being used as the disassembler.
You can also work with a monitor (using the command mon), but you have to manually enable this command in the code.
I plan on adding/commenting on the code more, so stay tuned on this topic.
Also, some new resources:
Mac Process Manager Document
Here are some notable places under macemu/SheepShaver/src/ :
/dummy - Empty files used for whenever a component is not available.
/emul_ppc - The original Sheepshaver core. No longer used and is effectively dummied out by sheepshaver_glue.cpp in the below folder.
/kpx_cpu - The current Sheepshaver core.
emul_op.cpp - Emulating various operations that were 68k code in the original ROM.
gfxaccel.cpp - Quickdraw (2D) acceleration, but it only handles some basic functions.
main.cpp - This is where Sheepshaver initializes everything, poking the XPRAM to values expected by Mac OS.
name_registry.cpp - Set up the names for the devices, such as the processors and the ethernet devices.
prefs_items.cpp - Items referenced by the preferences files.
video.cpp - Video emulation.
rom_patches.cpp - Patches for the ROM. There are patches used for New World ROMs compiled in 1998 and 1999, but mainly focuses the Old World ROMs.
rsrc_patches.cpp - Patches based on the OS's resource forks.
timer.cpp - Time Manager emulation. This is an emulation of the Time Manager, but using the Unix functions.
Of course, several files are shortcuts to files in Basilisk II, reusing the audio, CD, and disk functionality from that.
There are also .i files, which are really binaries. To see these in a hex editor and disassemble them easier...
1)Open the .i file up any word processor
2)Replace 0x and , with blanks.
3)Copy and paste into the editor.
The original code for these driver stubs hasn't been found yet and I don't think it was included.
Patterns I've noticed in the code so far:
D(bug("String\n")); <- Used whenever the debug mode is enabled, noting which function was enabled
ReadMacInt32(), ReadMacInt16() <- Trying to read from the emulated Mac's memory.
FindLibSymbol() <- Not common, but it's supposed to be used any time Sheepshaver is trying to find a library within the Mac OS itself.
As for the video driver stub, there are exactly two functions: TheDriverDescription, and DoDriverIO. It's very primitive, being under 512 bytes. I'll check out the other stubs included.
Inside kpx_cpu, you have four folders:
cpu - The main code for the CPU
mathlib - Used for the floating point operations
test - PowerPC regression testing, but it's largely floating point and integer operations... and some AltiVec/VMX ones.
utils - Processor check, but this is largely for the x86 processors
There's also ppc-dis.c, which is a file straight from GNU, and is now being used as the disassembler.
You can also work with a monitor (using the command mon), but you have to manually enable this command in the code.
I plan on adding/commenting on the code more, so stay tuned on this topic.
Also, some new resources:
Mac Process Manager Document