Building Classic Mac OS Apps in OS X
blog.steventroughtonsmith.com
blog.steventroughtonsmith.com
Also, Windows 3.1 can be augmented with Win32s, which offers a subset of the 32-bit Windows API -- so it's possible for a single binary to run on Windows 3.1 all the way through Windows 10 (64-bit Windows does not support 16-bit executables). If you want to try this for yourself, Win32s is rather finicky, so executables produced by modern compilers won't run. I believe I used Borland C++ 5.5, which is now available as a free download.
http://charlespetzold.com/etc/Windows1/CAKE.C
With relatively minor modifications, it'll run on Windows 7/8 and look exactly as it did on Windows 1.0 30 years ago.
The app was actually created for a fun presentation he gave in 2005:
Originally I assumed this is what the classic support would do.
Carbon is a modernization of the classic APIs. If an app was ported to Carbon then it could run in OS X natively without the VM. Older apps that weren't ported to Carbon need a VM running a classic version of Mac OS.
There was a thing called "Desk Accessories", sort of single-window mini apps (think Calculator), that were implemented as a special kind of device driver. But IIRC even these were serviced by periodic calls to SystemTask() which would make sure every running device got some time.
To get around this, we hacked the OS in crazy ways. For example, all of the system APIs were in a big address table. So if you had loaded some code and wanted to get a little slice of execution time to yourself, patching your function's address into the table in place of SystemTask() was a common technique (not forgetting to call to the original SystemTask() address before finishing, of course)! Since everyone did this (including Apple), you can imagine the long sequences of hacks patching on top of each other would lead to a really unstable system. Hence the classic Mac OS reputation.
I once wrote a driver for a custom-built hardware keyboard which plugged in via the serial port. The keyboard driver was basically a Control Panel (CDEV) with an INIT resource that patched something (I'm guessing SystemTask() but my memory is hazy...not sure why I didn't just make it a straight-up device driver) to check for bytes from the keyboard, which it would post into the event queue, and they'd show up in the running application.
Another common technique for getting time slices was to use the interrupt manager, although that was dicey because calling into system APIs at interrupt time wasn't safe.
Caveat: it's been a long time.
You could simulate threads like GUSI did, by passing control on (simulated) UNIX system calls.
He built a compatibility layer that can run a lot of binaries up to about system 6, but without a copy of the OS.
(The closest analogy I can think of is like wine, but also he has a CPU emulator underneath with neat tricks like dynamic recompilation).