Monthly Archives: September 2020

Notarized test applications & Other fixes

Most of the past couple weeks have again been a bit quiet due to busy time at the daytime job, but there are a couple improvements which are worthy of creating an update in this development diary:

Notarized macOS downloads

The set of (macOS) app bundles on the downloads page have finally been notarized, after Toni enrolled again in (& paid for) the Apple developer program for one year required to do it. So, there won’t be any longer any trouble with the scary warnings on the recent macOS versions.

The downside is, that the default notarized applications require macOS 10.9, but we’ve left the old, unsigned application bundles for Mac OS X 10.6+ compatibility, for now.

There are not much functional differences between the most recent notarized applications and the previous builds, as most of the recent progress has been on improving color compatibility, and other features in applications not currently part of the set of the downloadable app bundles.

Escape Velocity map “works” now

After a couple days of debugging, the code crashing Escape Velocity when opening the map was isolated. However, curiously it would appear there might be a bug in Escape Velocity causing the issue; in map, the game keeps track of four data structures of 10 bytes each (which I assume may contain coordinates for at least the nebula and asteroid field pictures), but in the map drawing code it accidentally accesses a fifth element in the array, which will contain random data at end of the allocated memory area. I briefly tested this part on a real Mac running Mac OS 9 – and it exhibited the same behaviour, but luckily SectRect intersected the offending corrupted coordinates, before running CopyBits, which would crash on negative source rectangle size; in M.A.C.E. as a workaround the StdBits (which CopyBits uses) was reinforced to ignore negative transfer sizes, which appears to be invalid operation on the QuickDraw on real Macs.

The Escape Velocity map window now works without crashing

There were also a couple other minor fixes:

  • MakeFSSpec did not populate the FSSpec fields correctly for non-existing file, which was required behaviour when using it to create FSSpecs for creating new files with FSpCreate
  • The “search & replace” mode in _Munger trap did not work correctly; The mission list was using this to replace “<DST>” with destination name, but in the case the search string was not found, it would keep appending it in the end of string infinitely
  • StandardGetFile selector in Std File Package was missing typeList pointer, causing the “Open pilot” dialog to not display any files


We recently also tested Thexder on M.A.C.E., which seems to be working quite well in both “classic” monochrome mode (with audio), and in the color mode. The controls are also quite responsive, although having played previously the DOS version it took a short bit of learning to play with the numpad controls, where vertical and horizontal movement keys are combined, as holding down multiple arrow keys is disabled in the Mac version, perhaps to avoid conflicting with the use of space bar as fire button.

This game is quite rare in the sense that it is the only game which we know that uses 2-bit (four-color) mode in the color version; this however works as a perfect test case for the 2-bit display mode testing and debugging. Interestingly, the monochrome version of the game seems to have some bugs (such as enemies not following player horizontally in the same way as in color version, and also some walls destructible by lasers seem to not work correctly). But as these bugs appear also on real Macs and minivmac, it seems that at least the emulation is working as intended.

Palette fix for Loony Labyrinth

As mentioned in the previous post, Loony Labyrinth was having some color corruption problems, which seemed to only affect the playfield. After a quick evening of debugging, it appeared that as the game used custom palette for intro screens, it was trying to reset color table back to default using RestoreDeviceClut selector of PaletteDispatch, which contained some code which was left previously as unimplemented to-do task. With a quick implementation to release the palette links from the GDevice, and doing a reallocation of color entries to restore original palette, the playfield now appears and displays as it should:

Loony Labyrinth playfield now displays correctly

Also, to celebrate this in combination with the physics fixes from earlier this month, here’s a video of how well the game’s own AI is able to play the game in the demo mode:

Loony Labyrinth playing one game of pinball in the auto demo mode

Although this does not fix Marathon’s color table issue, we luckily we have identified the problem with that game, and will be fixing it before next week. More about that in the next update!

Full list of changes since last post

2020-09-29 03:12:46 +0300 • Finalize (mostly) RestoreDeviceClut implementation
2020-09-29 02:13:02 +0300 • Fix PortList allocation & add PortList debug tool
2020-09-27 03:26:40 +0300 • Fix missing typeList in StandardGetFile
2020-09-27 02:56:59 +0300 • Fix "search&replace" mode in _Munger trap
2020-09-27 02:19:43 +0300 • Implement FSpSetFInfo for HighLevelFSDispatch
2020-09-27 02:17:32 +0300 • Add dummy empty NewAlias and NewAliasMinimal
2020-09-27 02:15:44 +0300 • Populate properly fnfErr result case in MakeFSSpec
2020-09-22 11:09:13 +0300 • Merge branch 'master' of
2020-09-22 11:09:08 +0300 • Minor tweak in colorQD detection in CDEF 63
2020-09-22 02:06:41 +0300 • Fix warnings causing errors on the new Xcode
2020-09-21 03:26:21 +0300 • Fix StretchBits crashing on negative srcRect width
2020-09-21 03:24:14 +0300 • Fix ADF filenames starting with % to map correctly
2020-09-21 03:23:00 +0300 • Add OrbQuest test application JSON config to cmake
2020-09-10 13:22:57 +0300 • Fix vfs file dependency command in cmake
2020-09-10 11:57:35 +0300 • Tweak Thexder JSON config
2020-09-10 11:57:03 +0300 • Pixel-doubling support for 4-bit (16-color) mode
2020-09-10 11:56:35 +0300 • Pixel-doubling support for 2-bit (4-color) mode
2020-09-10 04:13:30 +0300 • Fix cmake to allow again unsigned apps in OSX 10.6
2020-09-10 03:19:58 +0300 • Also return success code for decoding opOpColor…
2020-09-10 03:18:11 +0300 • Add Thexder test app to cmake json configs
2020-09-10 03:17:43 +0300 • Implement opOpColor in PICT playback

Many fixes: DIVU.W, Bitfields, Time Manager; Prince of Persia 2…

A lot of has happened past week, perhaps thanks to the summer finally starting to be over, and us having more time for the project again. Here’s a breakdown of most important advances made last week:

Fixed the DIVU.W overflow calculation

A long-time bug in unsigned 16-bit division instruction was finally found, and fixed by Pukka! We accidentally calculated overflow using signed 32767 limit, while it should have been unsigned 65535. This immediately fixed highly noticeable glitches in two of the test applications, Vette! and Test Drive II: The Duel (both ironically of same racing simulation genre):

Before the fix, Test Drive II had noticeable warping and glitching in the road near the bottom, and the polygons in Vette! had sometimes incorrect tangents, causing them to get messy depending on the angle of polygon edge.

This also fixed the “Divide overflow” bug occurring in SoftPC, which was weirdly happening on certain times of day, which does indicate that some calculation related to the computer clock time was failing because of the incorrectly signaled overflow. Now SoftPC works quite reliably.

Bitfield instruction fixes

One recently added test application, Prince of Persia 2, used a lot of the bitfield instructions for the SHAP resource drawing on the screen (apparently RLE/LZ decoding), which originally had a really messy artifacts:

But after fixing the instructions, the levels finally looks as they should:

Time Manager fixes

Besides the bitfield instructions, Prince of Persia 2 also uses Time Manager heavily for timing, and that surfaced a couple nasty bugs in the code, which were fixed.

There are still so oddities to investigate, for example the intro sequence does not advance past second screen yet, and the death and level completion delays do not trigger during the gameplay.

Sadly these fixes do not (yet) fix the one special case in Speedometer, where Dhrystone test does not work properly because of some issues that may be related to Time Manager (it starts the same timer twice, and stops it before test, so it never runs).

Keyboard handling threading bug

There was also a nasty bug in keyboard handling, which had rather surprisingly managed to stay hidden for a quite long time; Basically, the SDL2 key events that were handled by the keyboard code on main thread had chance to accidentally modify data structures and especially the A0 register, while 68K was running in VBL interrupt handler, causing in some rare cases the A0 register value to get corrupted; This caused a lot of crashes in Prince of Persia 2, and is most likely the cause of a very rare crash in Wolfenstein 3D. The offending part code was made thread-safe, which fixed this particular crash completely.

Sound in SoftPC

This was a very minor fix, but still worth mentioning; the reason for why there was no sound in SoftPC was caused by the fact that the application was setting the sound driver volume from the SPVolCtl low memory global, which had been set to zero on startup. By improving the PRAM simulation to populate all low memory PRAM values with sensible default values, the sound works now nicely in SoftPC!

Dark Castle “_Random” bug

As Pukka guessed last Christmas, the reason for buggy behaviour of robots, and some other minor glitches, in Dark Castle was indeed related to calling of the “_Random” trap! Of the last weekend was spent on searching the bug in other places at first, such as robot behaviour code, until we noticed something strange.

In Apple documentation, and all references known to us, the QuickDraw random number generator is defined simply as a Pascal type function with the following signature (in IM: Mathematical and Logical Utilities, 3-51):

pascal short Random (void);

Which means, that the function takes no arguments, and returns a 16-bit signed integer on stack. But, however, the way Dark Castle used was rather odd:

This screenshot of ResEdit showing disassembly of the part of Dark Castle code calling _Random shows, that it actually ignores the result value at offset 000B60 by discarding it off stack! And later looking at the code, it was actually using value in D0 instead…so, a quick look at System 7 _Random trap handler gives some insight to this:

Here actually it is visible, that on real Macs, the trap trashes a number of registers, and has the side-effect of leaving result value in the D0 register (being a toolbox trap, the trap dispatcher does not clean up any of the registers, unlike it does for some of registers after calling OS traps).

So, to fix Dark Castle, we added extra code to set up the D0 register as the game expected it, and everything started to work perfectly.

Some other progress from these changes

A couple other test applications seemed to benefit of these changes too, although they still need a bit of work to make sense: Loony Labyrinth now loads correctly after bitfield instructions were fixed (and physics in it also work correctly after the DIVU.W fix), and Marathon now actually runs and is playable with the Time Manager fixes:

Interestingly both of these games still seem to suffer from having colors completely messed up, but besides this glitch, they appear to be playable and run quite nicely.

Bonus video

And to celebrate getting SoftPC finally to work properly, I recorded this short video of M.A.C.E. running SoftPC running David Murray’s (The 8-bit Guy) Planet X-3:

You can find more information on Planet X-3 here:

Full list of changes since last post

2020-09-09 23:29:07 +0300 • Merge branch 'master' of
2020-09-09 23:28:59 +0300 • Update CMake scripts to support Apple notarization
2020-09-09 21:14:01 +0300 • add missing addressing fixes
2020-09-09 20:32:11 +0300 • memory addressing fixes
2020-09-09 20:26:50 +0300 • Fix compilation error in QDColorStretchBits.c
2020-09-09 20:00:29 +0300 • Fix some warnings in StretchBits color blitters
2020-09-09 19:59:57 +0300 • Fix some warnings in CodeResourceWDEF1
2020-09-09 19:26:58 +0300 • Fix return value in C_PlotCIconHandle
2020-09-09 19:18:10 +0300 • Merge branch 'master' of
2020-09-09 19:16:59 +0300 • fixes for bitfield and divuw instructions
2020-09-07 04:23:28 +0300 • Tweak more Dark Castle CMake JSON configs
2020-09-07 00:04:11 +0300 • Simulate PRAM (SysParam) to make SoftPC sound work
2020-09-06 23:04:58 +0300 • Update MACE version in CMake config
2020-09-06 13:14:44 +0300 • Color pixeldouble & (disabled) CRT simulation
2020-09-06 03:45:52 +0300 • Update trap generator XLS file
2020-09-06 03:44:13 +0300 • Tweak Dark Castle JSON config settings
2020-09-06 01:52:48 +0300 • Hack Random result value in D0 to fix Dark Castle
2020-09-05 03:54:17 +0300 • Get correct tmCount in RmvTime for non-first tasks
2020-09-03 02:16:54 +0300 • Fix the conversion of positive count in PrimeTime
2020-09-02 19:30:04 +0300 • Fix threading issue with keyboard input module
2020-09-02 19:28:30 +0300 • Don't crash on purged handles in GetHandleSize
2020-09-02 19:27:42 +0300 • Fix a lot of Time Manager bugs & clean up the code
2020-09-02 19:23:45 +0300 • Fix typing of region handle to CMDoDrawControls
2020-08-31 23:01:40 +0300 • A simplified MakeFSSpec implementation, for POP2
2020-08-31 04:17:44 +0300 • Add missing EqualRect change in EmuUtils.h
2020-08-31 04:16:59 +0300 • Fix GetCCursor crash when ResLoad was FALSE
2020-08-31 04:16:08 +0300 • Add dummy SCSIDispatch for Loony Labyrinth
2020-08-30 21:32:44 +0300 • Add Prince of Persia 2 to test app JSON configs
2020-08-03 01:45:10 +0300 • Make NewGWorld's rowBytes to work w/ Color VETTE!
2020-08-01 20:08:42 +0300 • Record PICT2 opHiliteColor, opOpColor &opDefHilite
2020-08-01 19:45:53 +0300 • Record HiliteBit as opHiliteMode in PICT2 format