Category Archives: Control Panels

Marathon fixed & INITs revisited; Fun with Control Panel (cdevs & After Dark)

Marathon color fix

As predicted in the previous post, the culprit for the messed up colors in Marathon was actually just the unfinished implementation of UpdateGWorld. What caused problems in this case was, that the color table in the backbuffer GWorld, which the game uses for off-screen drawing, was created during loading when the intro color table was active, and thus it “inherited” that active color table from the GDevice. However, UpdateGWorld was expected to update new colors from the GDevice when entering the game, and as it was not implemented, that left the old color table intact and messed up the colors. The current implementation of UpdateGWorld handles most of the cases, but does not do the existing pixel data conversion cases, which some applications might required (TODO-assertions were added there though, to signal when we encounter such case).

One handy source (literally!) for debugging Marathon’s backbuffer behaviour was the Marathon source code, which Bungie published quite some time ago at: http://infinitysource.bungie.org/

Also, we noticed that Marathon has pretty decent support for mouselook, so we enabled the relative mouse mode for test JSON config, and it feels pretty playable with it.

Here are some screenshots of the first level of Marathon running (finally) with proper colors:

Here are also a couple screenshots of one of the demo levels played by the game after staying idle in the main menu:

The first level seems to be completely playable until the end, except that the terminals on the level do not work yet (they require the Styled TextEdit implementation, which still remains on the TODO list – however with quite higher priority now, as so many applications seem to need it already). This is especially tricky as the teleport used at end of the level requires that feature also to pass the level 🙂

INITs revisited

Some time ago, we played around a bit with the INIT loading during startup, and used it to load After Dark screen saver. However, the handling of memory during startup was not optimal; basically BufPtr, which is the top of memory usable for application zone, and 68k stack pointer, were colliding, which caused random crashing.

As the color support is already quite nice for most basic cases (in indexed color modes), we wanted to see how After Dark would work in the color mode, so we did some quick fixing for this. Basically we moved the stack to near middle of the memory range, in a area which was very unlikely to hit the top of system zone, and way below the BufPtr limit, which After Dark wants to lower. This seems to fix that problem for now.

Control Panels

Another important thing we wanted was to allow the After Dark control panel to be usable, so that the screensaver modules could be configured. As we don’t have yet our own control panel to support running cdev resources (the control panels), we temporarily tried out what happens if we run the actual, real Control Panel desk accessory from System 6 – seems that there almost no issues getting this to work, as seen below:

System 6’s “General” Control Panel (cdev) running in the System 6’s Control Panel Desk Accessory (DRVR) running on M.A.C.E.

Surprisingly, bunch of the functionality in “General” control panel was directly working; The desktop pattern editor was almost completely functional, but required implementation of the SetDeskCPat trap, which it uses to apply modified pattern on the desktop. Menu blinking and caret flash controls work directly (as TextEdit and Menu Manager were built to use those low memory globals), and speaker volume control works when run in the “classic” (monochrome Mac Plus style) mode – color version still has the unfinished Sound Manager implementation. The date & time controls show placeholder value as the International Utilities routines are still unfinished, and RAM cache does nothing 🙂

System 6’s “CloseView” Control Panel (cdev) running in the System 6’s Control Panel Desk Accessory (DRVR) running on M.A.C.E.

Even more interestingly, the CloseView control panel (above) also work almost without any fixes; The Key1Trans and Key2Trans low memory procedure pointers were needed to allow shortcut keys to not crash. The zoom controls and zooming work neatly and follow mouse properly, as the cdev does some clever patching of a number of QuickDraw routines, so all the native C drawing is directed to a secondary buffer, which the CloseView cdev draws actually on the screen – when active, it seems to replace WMgrPort and WMgrCPort with the backbuffer, and even modifies ScreenBase to make CopyBits work properly! However, there is still some issue with the algorithm it uses to track “dirty” area, when magnification is off but closeview is active, as it leaves some artifacts on the screen when for example moving windows.

After Dark Control Panel (cdev) running in the System 6’s Control Panel Desk Accessory (DRVR) running on M.A.C.E.

But most importantly, After Dark is now also working. There were a couple fixes needed to make the control panel itself, and some modules, work – such as blend and subpin transfer modes for rectangle blitter, and a number of System 7-type temporary memory handle allocation functions (which for now just directly map to regular handle allocations in the application zone).

But most importantly, the rather complex and deep mix of native C, 68k DRVR, INIT and cdev code with patched traps included, surfaced a rare register trashing condition in the invocation of 68k code from native code – this was only present as a crash when using “Demo” feature of After Dark control panel! The problem was, that as certain 68k procedure calls needed arguments to be passed in registers, they were not saved before the call – and as native C part of the toolbox does not use the 68k registers, and thus does not internally save them, certain 68k -> native -> 68k call combinations resulted with registers being trashed. After adding the fix by implementing proper register save/restore, After Dark is much more stable, and looks great! Here are screenshots of some of the modules which work now (you can click image for larger view):

There are still a number of things to fix though; for example, MultiModule does not work yet (cannot configure modules for some reason), and other modules have unique cases which need to be handled separately (such as “Down the Drain” requiring GetCPixel), and some modules occasionally spitting “Not enough memory” error, but this is good as it provides a lot of test cases for the future!

Also some of the other desk accessories were kind of working and not; some such as “Mouse” control panel won’t have any affect (mouse is right now completely controlled by host operating system), “Monitors” requires proper Slot Manager implementation for handling the graphic devices to not crash, “Color” (probably) needs to have support for modifying the labels in System file, and “Sound” does not do much without Sound Manager. We will in future also try out other cdevs to see what happens 🙂

Full list of changes since last post

2020-10-30 04:38:37 +0200 • Rename SMSlotInterruptGlobals for clarity
2020-10-30 04:36:28 +0200 • Iterate INIT resources in LoadNamedINITFile
2020-10-30 04:33:32 +0200 • Enable relative mouse mode for marathon cmake JSON
2020-10-30 04:33:05 +0200 • Add control panel files to TeachText cmake json
2020-10-29 23:57:28 +0200 • Implement CloseCPort trap
2020-10-29 23:53:50 +0200 • Also add subPin mode to pattern rectangle blitter
2020-10-29 23:26:20 +0200 • Arithmetic blend mode in pattern rectangle blitter
2020-10-29 23:24:53 +0200 • Save & restore ALL 68k register on C->68k calls
2020-10-29 17:40:16 +0200 • Fix byteswap bug in UPP routineCount
2020-10-28 03:55:16 +0200 • First part of Key(1/2)Trans lowmem proc support
2020-10-27 07:09:52 +0200 • Add dummy TempFreeMem/NewHandle/HLock/DisposHandle
2020-10-27 05:52:11 +0200 • Add ShutDown Mgr (+ dummy ShutDwnInstall selector)
2020-10-27 05:30:12 +0200 • Make SystemTask more compatible with DAs
2020-10-27 03:05:01 +0200 • Implement SetDeskCPat trap handler
2020-10-27 02:49:46 +0200 • Implement PixPatChanged selector for QDExtensions
2020-10-27 02:43:19 +0200 • Also fix the hack in boot-time temp memory size
2020-10-27 02:42:05 +0200 • Temporarily move SP out of below BufPtr at startup
2020-10-27 02:41:05 +0200 • Fix a really stupid DRVR call bug (HLock missing)
2020-10-13 01:03:50 +0300 • Set RAMBase during startup
2020-10-06 01:17:40 +0300 • Dummy placeholder for WriteParam trap handler
2020-10-06 01:16:12 +0300 • Fix directory ID for indexed non-HFS GetFileInfo
2020-10-06 01:14:03 +0300 • Implement (kind of) TempTopMem OSDispatch selector
2020-10-03 17:27:12 +0300 • Add SlotManager dispatcher (and SVersion selector)
2020-10-03 03:33:17 +0300 • Fix memory leak in ClosePort
2020-10-03 03:30:57 +0300 • Add rest of UpdateGWorld (except pixmap data copy)
2020-10-03 02:33:45 +0300 • Handle _MapRgn wideOpen case; Fixes Marathon map
2020-10-03 01:34:23 +0300 • Clear MemErr in Lock/UnlockHandle on success
2020-10-02 16:30:08 +0300 • Fix warning in LayerDispatch from missing #include
2020-10-02 05:07:00 +0300 • Pass right pixelDepth to NewGWorld in UpdateGWorld
2020-10-02 04:57:55 +0300 • Some progress on UpdateGWorld implementation