Category Archives: Graphics

5 year anniversary! And happy new year 2023

It feels crazy to think that today it’s been a whopping 5 years since the project got rebooted to its current iteration! Sorry again for slow progress between late summer and the Christmas holidays, a lot of things going on so we have had to juggle between different things and try to prioritise them. But past couple months have been again quite productive, and we have some nice updates to share:

File system improvements

One important feature that was added to NativeFS has been ability to create directories using DirCreate, something that not only installer applications, but also some apps generally depend on. It’s still not perfect (for example extracting the THINK Pascal installer archives made with SmallerInstaller causes the directories to get a bit haywire), but basic use cases such as creating Desktop & Trash folders seems to work.

Also, some groundwork has been laid to support deletion of files, as the AVL tree routines for node deletion were added – but actual deletion of file system items is still a work-in-progress task, which needs to be done carefully and is not to be rushed considering errors and bugs in this code might cause a bit headache to the end-users.

And also, when doing test runs on some Installer VISE installers, we found out that the NativeFS DRVR’s Control handler had used incorrect csCodes for the logical/physical drive icons (we were using 0x16 and 0x17, while correct ones were 0x15 and 0x16), this tiny mistake caused the whole installer to crash…oops! Another quite important bug fix was adding missing IODone call to the NativeFS DRVR’s Status handler, as that caused basically the entire Device Manager to hang…

List Manager multi-select

Not really a tough feature to implement, but one that has been a TODO for long time, list manager multi-selection has been finally implemented. A very good test case for this has been ResEdit, as it supports multi-selection both in the 2-dimensional icon grid, and in the 1-dimensional list view

List multi-select in action in ResEdit

SeedCFill & CalcCMask

Also as part of filling some missing traps, SeedCFill and CalcCMask were implemented. Like the aforementioned list multi-selection, ResEdit again was a wonderful test case for this, as the color editor PACK 1 in it uses these for the color flood-fill tool:

SeedCFill & CalcCMask in ResEdit’s PACK 1 color pixmap editor

Technically, the SeedCFill and CalcCMask actually call SeedFill and CalcMask, and to do that, they first map the color pixmap passed to the routine to a 1-bit image by using a custom color search proc to a temporary bitmap, which replaces matching colors with 0 and non-matching with 1 (i.e. doing floodfill on certain color gets flooded only to exactly matching pixels, while being bound by any other colors)

Application zone teardown updates & fixes

A bunch of fixes and missing features were added to the InitApplZone & SetApplBase, which makes doing transfer/shell launch to other apps way more reliable:

  • Font caches are flushed in SetApplBase and InitApplZone. Sometimes recently used font might be left cached in the application zone, and doing Launch/Chain to new app might accidentally use the cached (but not obliterated from memory) font, causing random crashes.
  • All color grafports, palettes, and VBL tasks located in application zone are disposed/closed

These are quite important fixes, as the aim is to provide soon the much-promised “generic” MACE runtime, which would contain an application shell (i.e. Finder replacement) to reliably run applications from

Communications Toolbox foundation

Weirdly, the Comm Toolbox has a bunch of very non-related routines included, which some applications seem to depend on. The first one we encountered was some Installer VISE installers using the CountDITL selector to get number of items in dialog item list, which the designers of the toolbox interestingly put as part of the Communications Toolbox. Also, the dispatcher mechanism they use is a very non-standard one (they basically pass parameter block pointer in A0 register, which contains the actual arguments of the routine – which might vary in size and number depending on the API call – and expecting result in D0 register). Although there’s just this one call implemented, the foundation for Comm Toolbox was done so that other routines can be added as needed later.

SoftFPU support

Even though Pekka is working hard on the 6888x FPU support, we did interesting experiment to see how well the SoftFPU control panel would work on MACE. Basically, that utility hooks as the F-line exception handler, using SANE calls to the actual math, and passing those results as emulated FPU instruction results. So, emulation inside emulation, kind of. Getting this done was actually quite easy, as the SANE emulation already covers so many calls, so we just had to hook up the F-line exceptions, and implement two missing SANE FP68K selectors (FNEXTX and alternate FX2X), and we were able to run a test app written in THINK Pascal with native 68881/68882 code generation with correct results:

SoftFPU running on MACE

In the above test application, the Compile Options dialog shows that 68881/68882 codegen is active, the code contains math for 9 / 2, and the Text window shows the result of 4.5 (in scientific formatting, as the Dec2Str routine still has some unfinished features)

Some updates to get Civilization 2 to work…almost

One cool game we also have been wanting to play for a long time is legendary Civilization 2, and we took a small steps in getting closer to being able to play that game someday soon:

  • Time Manager’s “hidden” microseconds trap (A093). This one was a bit hard to find documentation for, but we were able to produce close-enough results to keep Civilization 2 happy, which uses it for some reason. Basically the call returns 64-bit microseconds counter, with low 32 bits in D0, and high 32 bits in A0 register.
  • Added DriverGestalt (43) status call to NativeFS, and dgDeviceType (‘devt’) to it, which Civilization 2 seems to use to detect the media type of volume it was launched from (to see if it was started from the CD-ROM or Hard Disk)
  • CopyPalette trap handler (only partial implementation, but seems to be enough for Civ2 startup)
  • Added some more fake process manager data to GetProcessInformation results, in this case basically faked the processAppSpec by using HGetVol to get active directory, and CurApName from low mem…really dirty, but luckily enough again for Civ2. When process manager is someday added, this hack will be replaced by a proper implementation

With these done, we did get the game to progress quite far already:

There are still some big issues in the game, such as missing for some reason the entire backdrop images from the start-up menus, fonts looking ugly because truetype is not implemented (bitmap fonts have the pixelation on non-exact sizes), and color picture recording has still missing features causing city screens to crash.

Newer Technology GURU: “GUide to Ram Upgrades”

One other nice application that we were also experimenting is NewerTech’s GURU, which not only at the time was nice tool for checking out what RAM/VRAM upgrade options you had for Macs, but also doubles as nice mini-encyclopdia of various Macs, clones – and even printers – with their specs and nice color icons included.

GURU running on MACE

To get GURU running, there were a couple things needed:

  • We had again to temporarily tweak the GetProcessInformation’s processSignature (which sadly also WarCraft 2 uses, so both this app and that game need a proper implementation for this
  • Interestingly, the tiny and very harmless-looking popup menu triangles (seen in the screenshot on right-hand side) were actually 16-bit RLE-compressed pixmap images, so we had to implement both the 16-bit pixel translator, and the RLE decompressor in the Color QD Picture bits opcode handler
  • Also, the About Box in GURU used TESetText for styled textfield, which was previously a TODO, so that had to be implemented (it basically just replaces existing styles with a single style run)

MacWrite (finally) works now!

We also took some time to dig into other long-time known issues, one of which the MacWrite crashing on newline issue. Interestingly, two separate bugs did surface:

  • The biggest issue was that doing post/pre-increment of registers in middle of execution was not handled properly, in MacWrite’s case the offending instruction was ADDA.W (A0)+,A0, where value from memory pointed was read, A0 was supposed to be incremented by the word size (2 bytes), and the result added to A0 register. The bug caused the increment to get missed before adding the value to A0, causing it to be 2 bytes too low. This caused a bunch of havok in MacWrite, as the app used its own data structures to keep style data for rows, and this made – among memory corruption – the font size to go to a whopping 255 pixels when adding a new line on keyboard
  • The “justify” text alignment was one of rare cases where spExtra of GrafPorts was used to do sub-pixel (fixed-point) spacing of text, so we didn’t notice before Font Manager was missing a byteswap in handling of spExtra, which caused the cached spExtra to get totally crazy values
  • A rare case of resource map not being initialized properly surfaced on document saving, which was fixed
  • And also, document saving in MacWrite seems to depend on IUSetIntl trap (to apparently write localization data to the document), that trap had to be implemented

With these fixes, MacWrite finally works:

MacWrite works now!

Strategic Conquest

Although most of the features we had tested in Strategic Conquest were working, the map drawing had glitches: polygon lines were missing. We did some investigation about this, and found out that MapPoly trap only mapped the polygon points, but totally forgot to do the mapping for polyBBox. This in turn caused the polygon drawing to assume points were out of range, and fail to render anything in most of cases. With this fixed, the map seems to work fine now (at least in the B&W version):

Strategic Conquest MapPoly works now!

Arkanoid has sound!!!

One issue that was also mysterious for long time was why Arkanoid had no audio, while (almost) every single other black & white game/application had sound. After some researching, we found out that being super smart (and bizarre), instead of the standard VLB queue item (like 99.9% of games), or the not-so-common Lvl1DTVIACA1 interrupt handler (which Fokker Triplane does), Arkanoid actually hooks directly to the AutoInt1 vector on the 68K exception vector list, which normally would be handled by the Mac OS to invoke the VBL interrupts. After adding a level of indirection to the AutoInt1 vector (and adding possibility to later add other interrupt handlers to this level), Arkanoid sounds works perfectly! Sadly we did not have time to get a nice video capture of this for this update 😦

THINK Pascal zone check fixed

Another long-time issue that had been bothering us was that THINK Pascal kept saying in debug mode all the time that all zones were damaged, so we finally took time to dig into the THINK Pascal code and look for their zone check code and see what it was doing. Luckily, the only part that was failing was the trailer check, which checked that the bkLim block was supposed to be always 12 bytes in 24-bit mode, was getting triggered because when GrowZone was adjusting the zone trailer, it accidentally wrote 0 (zero) as trailer size, instead of the expected 12 (ironically InitZone did set it up properly). Although this bug had no functional effects to anything else but the zone check, the THINK Pascal was way more happier now, and looks like the LightsBug debugger is working perfectly, zone browser now included!

LightsBug working nicely after zone checks pass

Other bug fixes

There were a couple bugs/missing features that were fixed, with varying effects:

  • Fixed mask overflow in 32-bit pixel data stretching blitter, and implemented TODOs for some 32-bit pixel data colorization variables – These caused black buttons in some F/A Hornet 2.0 dialogs
  • ScrollRect passed wrong offsetPt to ShieldCursor – this caused some cursor artifacts (this bug did not manifest itself until after the actual software cursor code was added recently)
  • The WDEF 0 (standard window defproc) did not offset the grow box drawing correctly when a window grafport was offset to a non-zero origin (like in PhotoShop) – this caused the bottom-right growbox to get drawn in wrong position on the desktop)
  • 1-bit cursor data saving was missing from SetCCursor – This caused the cursor update to not get triggered if doing InitCursor or SetCursor after doing SetCCursor
  • Fixed issue in RestoreBits, where the menu bar was invalidated in RestoreBits even though it was restored, which in turn caused recursive call to DrawMenuBar when had a menu highlighted (the kMBDFMessageHilite message in MBDF code called RestoreBits which in turn did InvalMenuBar call, which caused the DrawMenuBar to get triggered from the second HiliteMenu call inside the DrawMenuBar) – Fixes the issue of MenuBarPattern code getting stuck in infinite recursion in Civilization, as it tried to double-patch itself from the recursed DrawMenuBar call
  • Added missing call to SystemEvent in GetNextEvent, which caused some events, such as key press events, to not get passed properly to Desk Accessories – Fixes the issue of Key Caps DA not receiving text input
  • Allow BlockMove to receive negative lengths. After researching how the List Manager in some 68k Mac OS versions handle the case of having zero rows but non-zero columns, it seems that they do pass negative lengths (maybe on purpose) to BlockMove with no side effects, and BlockMove ignores those – Fixes the unncessary negative length assertion in ResEdit with empty resource files
  • vRefNum case was missing for GetWDInfo calls in NativeFS, which caused ResEdit to not be able to open files from root directory of a volume
  • Do proper setup of stack pointer on application launch to BufPtr, because this was missing (and SP was left in boot-time default), it cut amount of available memory to apps down to 75% of total RAM! This also surfaced another bug that the startup-time boot grafport (used to draw any stuff during INIT loading etc) was not closed, so any code assuming that all PortList entries were valid were randomly crashing
  • Added style support for TEDelete, so using backspace key in SimpleText works now

What next?

It’s always hard to estimate what will be done and when, but there are still some key goals we’re aiming in the near future:

  • To get the public binaries finally updated after we have time to figure out not only a nice, cheap and practical CDN or other way update the files
  • When electricity prices go down (which got crazy during winter, so had to turn off most of extra computer equipment), work on automating the builds for different platforms, instead of manually building everything (even though CMake does a lot of the hard lifting)
  • Get Sound Manager 3.x to work, so we can start putting out the color version too
  • Try to make sure ReserveMem & NewHandle combos work as expected, right now this is causing THINK Pascal to run out of memory – this is something we want to make sure works, before we move to:
  • 32-bit memory manager. Something that’s needed not just to get more than 8 megabytes of accessible memory, but also to get some picky games (such as Doom) to run, AND to allow:
  • Direct memory access support, for avoiding the overhead of virtual memory interface, potentially speeding up emulation quite a lot. This requires 32-bit memory model to work efficiently.
  • Update build system to include creation of the System file from resource scripts – it’s still being handled as binary file that’s edited using native resource tools, which is not only cumbersome, but also makes it difficult to have variants of the System file for different system types – when we at some point do add process manager support, the way for example desk accessories and fonts are handled needs adjustment, as in process manager-aware (System 7 and later) those are external files instead of ones in System like in System 6 and earlier
  • Work on the so-many missing features (which do also cause known bad behaviour or crashes)
  • Debug and research the problems and crashes which we know about, but haven’t yet figured out what is causing them (such as F/A Hornet and F117A drawing issues, ball missing bug in Loony Labyrinth, timing issues in Monkey Island and Prince of Persia 2…)
  • Prepare a Discord server for public access
  • Many, many, ….many other things

We will as always update our progress on this blog, hopefully a bit more frequently. Your support and encouragement has been very inspiring, and we’re trying as soon as possible to share more and more of the stuff we’ve been making with you.

Full list of changes since last post

2023-02-15 14:56:38 +0200 • Fix 24-bit zone trailer & add bkLim validation
2023-02-15 03:45:35 +0200 • Add dummy ADBOp trap (for SoftWindows)
2023-02-14 21:47:21 +0200 • Expose & use low-level AutoInt1 vector for VBLs
2023-02-13 23:34:21 +0200 • Add LMKbdType and use it for Gestalt & SysEnvirons
2023-02-13 00:27:16 +0200 • Also adjust polyBBox in MapPoly
2023-02-12 17:40:45 +0200 • Style support for TEDelete
2023-02-12 17:39:11 +0200 • Disable font width table logging in debug mode
2023-02-08 23:48:12 +0200 • Merge branch 'master' of
2023-02-08 23:47:43 +0200 • Remember to close the startup-time GrafPort
2023-02-08 06:12:54 +0200 • Merge branch 'master' of
2023-02-08 06:12:50 +0200 • Handle TEMeasure start in middle of style run
2023-02-08 06:12:02 +0200 • Don't return random value if FindFolder fails
2023-02-08 06:11:09 +0200 • Some cleanup in HighLevelFSDispatch
2023-02-08 06:10:30 +0200 • Don't ignore opIFore and opIBack
2023-02-06 02:47:11 +0200 • Reset stack pointer A7 in non-multitasking Launch
2023-02-06 00:48:02 +0200 • Handle vRefNum case in GetWDInfo
2023-02-05 23:15:40 +0200 • Implement IUSetIntl selector for IntlUtils Pack6
2023-02-05 22:29:59 +0200 • Fix rare case of res map handle not initialized
2023-02-05 22:26:45 +0200 • Fix ADDA.W/L postincrement same as destination bug
2023-01-30 12:28:55 +0200 • Fix byteswap bug on spExtra handling in FMSwapFont
2023-01-29 01:26:40 +0200 • Add dummy stub for HMRemoveBalloon (for Excel 3.0)
2023-01-28 08:35:17 +0200 • Implement TESetText styled textfield case
2023-01-28 00:35:35 +0200 • Some process manager placeholder hacks for GURU2.6
2023-01-28 00:34:03 +0200 • Use 16-bit RLE decoder for PICT packtype 3
2023-01-28 00:33:37 +0200 • Add 16-bit RLE decompressor for QD Pictures
2023-01-28 00:32:33 +0200 • Add 16bit direct to indexed color pixel translator
2023-01-26 21:06:19 +0200 • Merge branch 'master' of
2023-01-26 21:06:17 +0200 • Fix 68k Bxx opcode with 32-bit extension
2023-01-26 01:07:16 +0200 • Fix return value of Microseconds trap
2023-01-25 14:45:34 +0200 • Hack face processAppSpec in GetProcessInformation
2023-01-25 13:52:55 +0200 • Partial CopyPalette (0xAAA1) trap implementation
2023-01-25 03:32:02 +0200 • Add dummy Lower/Strip/Upper/StripUpperText handler
2023-01-25 03:01:56 +0200 • Handle 'devt' driver gestalt in NativeFS
2023-01-25 03:00:19 +0200 • Return controlErr on non-support NFS Control codes
2023-01-25 02:41:18 +0200 • Add DriverGestaltParam & dummy handler in NativeFS
2023-01-25 02:39:21 +0200 • Fix broken return from NativeFS Status handler
2023-01-25 02:38:02 +0200 • Implement Microseconds trap (A093) for Time Mgr
2023-01-23 03:10:20 +0200 • Expose some rsc manager stuff for SetResourceSize
2023-01-23 03:09:21 +0200 • Merge branch 'master' of
2023-01-23 03:08:20 +0200 • Log also 68k program counter in trap debug msgs
2023-01-23 03:07:21 +0200 • Update TimeManager.c
2023-01-23 03:06:42 +0200 • Work on SetResourceSize
2023-01-17 22:25:49 +0200 • F-line handler for M68kHelper glue module
2023-01-17 22:04:05 +0200 • Implement FNEXTX and alternative FX2X selector $10
2023-01-17 22:01:38 +0200 • Fix f-line dispatcher installation in 68k cpu code
2023-01-17 00:27:06 +0200 • Add CountDITL, and a VERY bizarre A08B dispatcher
2023-01-16 14:06:31 +0200 • Fix invalid icon csCode in NFS + add assert checks
2023-01-16 13:54:23 +0200 • Fix byteswap bug
2023-01-16 13:41:18 +0200 • Remove VBL tasks in app zone in InitApplZone
2023-01-16 13:34:27 +0200 • Dispose palettes in app zone in InitApplZone
2023-01-16 13:22:09 +0200 • Close all open grafports in InitApplZone
2023-01-16 13:21:38 +0200 • Flush font caches in InitApplZone
2023-01-16 13:02:15 +0200 • Flush font caches in SetApplBase
2023-01-16 13:01:45 +0200 • Add SLCheckApplZoneAddress, for app zone cleanup
2023-01-16 13:01:04 +0200 • Detect use of ResErrProc in resource manager
2023-01-16 13:00:29 +0200 • Add (partial) font cache flushing in Font Dispatch
2023-01-16 12:59:34 +0200 • Implement FCMPL selector in SANE FP68K trap
2023-01-09 23:32:54 +0200 • Implement QDExtensions's GDeviceChanged selector
2023-01-09 23:22:39 +0200 • Implement QDExtensions's OffscreenVersion selector
2023-01-08 23:17:28 +0200 • Added AVL Tree node deletion routines
2023-01-08 13:49:24 +0200 • Implement SeedCFill + CalcCMask QD traps
2023-01-06 16:57:46 +0200 • Fix handling of zero & negative BlockMove lengths
2023-01-06 11:24:27 +0200 • Check VCB flags in SetFileInfo/SetCatInfo
2023-01-01 17:46:21 +0200 • List Mgr's LClick multiselect (shift+cmd) support
2022-12-29 11:06:57 +0200 • Implement RsrcMapEntry trap handler
2022-12-20 00:02:35 +0200 • Don't return mouseMovedMessage unless app4 bit set
2022-12-18 14:05:14 +0200 • Implement SysEdit trap handler
2022-12-18 14:04:49 +0200 • Fix issue of GetNextEvent not calling SystemEvent
2022-12-17 00:25:55 +0200 • Fix unneeded invalidate of menu bar in restorebits
2022-12-14 21:29:16 +0200 • Save 1-bit cursor data in SetCCursor
2022-12-14 16:21:12 +0200 • Fix wDrawGIcon incorrect offset in nonzero origin
2022-12-13 21:49:42 +0200 • Proper fix for horizontal stretch pixel masking
2022-08-24 02:02:08 +0300 • Fix ShieldCursor offset in ScrollRect
2022-08-22 23:21:44 +0300 • Improve relative mouse mode host cursor behaviour
2022-08-22 22:11:12 +0300 • Merge branch 'master' of
2022-08-22 22:11:02 +0300 • Add dummy MIDI driver module (for MIDI Manager)
2022-08-22 22:09:16 +0300 • Fixes to 32-bit direct-to-8bit color QD blitter
2022-08-22 22:08:03 +0300 • Fix mask overflow in 32-bit horizontal CQD stretch
2022-08-21 13:30:13 +0300 • Fix sound manager header
2022-08-05 03:58:52 +0300 • Add empty dummy MIDIGetClients selector
2022-08-05 02:58:50 +0300 • Refactor filesystem AVL tree code & add validation
2022-08-05 02:57:45 +0300 • Cleanup SoundDispatch & add SndDispVersion handler
2022-08-01 17:28:51 +0300 • Merge branch 'master' of
2022-08-01 17:28:46 +0300 • Implement DirCreate file manager trap
2022-07-31 23:09:20 +0300 • Re-export traps & selectors for status update

Summer ’22 update

In attempt to increase frequency of status updates on the project after slow progress during the past year, here’s some information about what we’ve been working hard during the summer vacation.

Styled TextEdit updates

One of the most overlooked – but still very important – features has been the Styled TextEdit support. We already had started working on the foundations almost two years ago, and had last year got the drawing to work pretty well (mostly focusing on Marathon’s “computer terminal” screens) – but actual editing features of the styled text have been largely missing. Luckily SimpleText, with its fully-featured styled text editing features, provides a bunch of test cases for a number of them. Below is screenshot of some text styling at work:

Basic styled text editing in SimpleText

Right now, styled text can be finally entered (using various style parameters such as face, font, size), and SimpleText can also open various text documents with styling information. Below is one example, the READ ME file of Prince of Destruction:

Opening a styled text document in SimpleText

But a lot of work needs to be still done, as major features are still unfinished (such as hit-testing of styled text records, which is needed for both mouse click, arrow key and selection support).

“AppleDoubler” tool

Motivation to work on the “AppleDoubler” tool got boost by a question asked in the June on emaculation about our file system choices. We had planned for a long time to make tool for converting native Mac files to the ADF format, but hadn’t taken time to work on that until now. It didn’t actually take more than a couple hours to write (plus some random time to do some tweaks later), but as nice effect we are able now to convert applications for testing blazingly quickly (compared to the manual conversion process earlier). This has led to discovery of a number of bugs which were fixed, and missing special cases of existing features that have been tweaked.

The AppleDoubler tool will be available as soon as we sort out our binary distributions to work a bit better (until now, files have been hosted here on the WP blog, but due to a bunch of issues with executables, and the time-consuming progress of updating downloads page, we will look into more automated alternate solutions, to allow more frequent updates, and also more downloads to be available.)

Software cursor

One longtime “to-do” task has been proper software cursor implementation, which has been delayed mostly because SDL’s cursor API has handled the monochrome cursors quite well for most of the use cases. However, there have been three downsides of this approach:

  1. The “inverted” cursors (such as the I-beam, and Lemming’s cursors) don’t show up properly, as most modern host systems don’t support inversions in cursor graphics. Especially in lemmings this has been tricky in the monochrome mode, as the cursor would appear black on black background, making the game really hard to play
  2. The native cursors don’t show up when doing screenshots of windows, or when capturing in OBS using window capture. This has been mostly prominent on Twitch streams where mouse has been invisible
  3. Color cursor support has been unimplemented, as for proper ‘crsr’ display the mapping of cursor color table needs to be done

The final push for software cursor implementation came when we tried running Super Studio Session editor, which replaces a number of default cursor vectors with its own implementation (which it uses to align the “note” cursor on music sheet at certain spots). We saw that the cursor that application implemented all by itself worked mostly really well, but because of some ShieldCursor bugs, it was leaving trails at certain places. Below are screenshots of Super Studio Session (ignore the “THINK Pascal” window title, we don’t yet have proper general-purpose shell/desktop application yet, so we used the very practical “Transfer” feature of THINK Pascal to launch any application from the file system through Standard File dialog, without needing to do any extra work 😀 )

It took a couple days of work to get the software cursor to work (the work was sped up a lot by a number abstractions we had done earlier, related to VBL task execution etc), and adding color cursor support was not that tough as ‘crsr’ and ‘ppat’ resources share a common heritage, and thus their color table and depth expansion code could be shared. Below are some screenshots of Civilization, showing the color mouse cursor in action:

SoftWindows

As a curiosity, in progress of trying out various applications, we noticed that SoftWindows 1.x (the last 68k-compatible version of that application) seems to work pretty well. As it does have quite high memory requirements (considering the currently implemented 24-bit memory manager by default has only 8 megabytes of RAM), we did have to make a temporary hack to boost the RAM limit in the test configuration to 12 megabytes (leaving space for only 3 slots in the emulated slot address space – while the default configuration allows up to 7). This allowed us to actually boot into Windows 3.1 and run a number of games/apps on it (biggest limiting factor for what worked was that this version SoftWindows only emulates a 286, thus allowing only Standard mode in Windows 3, instead of the Enhanced mode required by a lot of applications). Below are some screenshots of what we tried out:

MIDI Manager research

As we knew that certain Sierra games do advertise MT-32 compatibility, we did some quick snooping around, and learned that at least Space Quest 1 does use Apple’s little-known MIDI Manager to handle the hardware MIDI playback (unlike Thexder, which appears to have its own serial driver for MIDI, choosing to use the serial port directly). This led to some curiosity about the MIDI Manager implementation, for which there is sadly very little documentation – an article about programming it on the always valuable MacTech archive and the universal headers. A couple articles from mid 90’s point to ARPA as source to buy the MIDI documentation and SDK from, which sadly is no longer available.

The work on MIDI Manager support is still ongoing, but we feel it might be relatively easy to write a layer that emulates MIDI Manager’s patching features, and wrap the MIDI driver as a abstract device that could pass the MIDI packets to host OS’ native MIDI interface (in Mac OS X case, the CoreMIDI). All MIDI Manager calls go anyway through the same SoundDispatch trap like a number of Sound Manager calls, so tapping to that interface is really easy. (Another question, though, is how well timing will work, and whether default MIDI synthesizer (or the SC-55 midi hardware) will handle Space Quest’s MIDI output that expects an MT-32…)

Various other updates

As mentioned before, there have been a ton of fixes and updates, but here is mention of a couple ones that might be of interest:

Popup Control CDEF (and TextEdit) fixes: There were a number of bugs in both the Popup Control drawing (and TextEdit setup) code, which manifested quite visually in the HyperCard script editor. Below are screenshots of “before” and “after” to show what kind of effects the fixes had:

Menu Bar Pattern Control Panel: As another curiosity, we tried this one old Control Panel from early 90s, to see what would happen – and seems that whatever magic it uses to draw patterns behind menu bar, it seems to be 100% compatible:

Menu Bar Pattern Control Panel

FracSin/FracCos: The After Dark module called “Spotlight” (not to be confused with the OS X search tool) was the first case that needed FracSin/FracCos implementation to work, so we used it as a test case for those traps and got it working pretty well:

After Dark “Spotlight”

Palette fixes: There were a number of bugs & missing features in Palette Manager code (for example, SetEntries had bug that made it fail incorrectly with cProtectErr, which caused a number of issues around the place). Here is Lode Runner: The Legend Returns editor, which had weird color issues before the fix (ignore the palette debugger in bottom right):

Lode Runner: The Legend Returns level editor

BitmapToRegion: This trap was already before used by Escape Velocity, but as that game needs a couple other improvements to reach playable state, Snood worked out pretty well as a use case for this (as it uses it for practically all of its sprites to convert their masks to regions for drawing). After a couple hours, the game seems to be quite happy with the routine (Snood 1.x pictured):

Snood using sprites with masks defined by BitmapToRegion

Default MDEF ‘cicn’ support: While trying out Snood, we noticed that Snood 2 was the first use case of color icons (‘cicn’s) in menu items. As the MDEF already had almost-working handling for this case, we added some temporary code to the Icon Utilities module and got nice color icons in menus now:

Color icons in Snood 2.x Players menu

More blitter fixes/improvements: There were numerous fixes to basic blitters too, which affected test cases such as 3 in Three, “Spotlight” (when brightness was other than 0%), Shanghai II mahjong, etc). Here’s some screenshots of what we got working with the improvements:

Next step

We will continue working on the missing features as always, trying to reach the goal of a generic runtime release as soon as possible. We also will try to find solution for the binary file distribution in near future, so anybody interested trying the new features out could do that as soon as possible (especially considering the last released binaries are already getting quite old). We will keep you updated on this blog on our progress as always.

Full list of changes since last post

2022-07-31 00:45:08 +0300 • Implement colorizing srcOr rectangle blitter
2022-07-30 23:49:00 +0300 • Implement colorizing srcBic rectangle blitter
2022-07-30 13:34:42 +0300 • Fix missing handle derefence bug
2022-07-30 13:47:58 +0300 • Implement SaveEntries trap for Palette Manager
2022-07-30 04:09:17 +0300 • Disable potentially invalid check in Entry2Index
2022-07-30 03:08:06 +0300 • Stretching subPin blitter + improve call interface
2022-07-30 03:07:01 +0300 • Reinforce zone checks for handle operations
2022-07-30 01:27:53 +0300 • Fix AppendMenu/InsertMenuitem legnth > 127 cases
2022-07-30 01:14:39 +0300 • Implement a rudimentary PlotCIconHandle (for MDEF)
2022-07-30 00:39:04 +0300 • Merge branch 'master' of
2022-07-30 00:38:58 +0300 • Proper implementation for BitmapToRegion QD trap
2022-07-26 23:16:20 +0300 • Add dummy MIDIManager (+ MIDISignIn & MIDIAddPort)
2022-07-26 20:35:26 +0300 • Merge branch 'master' of
2022-07-26 20:35:16 +0300 • Implement PaletteDispatch ResizePalette selector
2022-07-26 18:28:13 +0300 • Fix timer thread race condition issue
2022-07-26 15:53:28 +0300 • Implement color QD opDefHilite PICT opcode
2022-07-26 15:52:42 +0300 • Implement opPnLocHFrac PICT opcode
2022-07-26 15:52:06 +0300 • Fix edge case of shielding cursor in classic mode
2022-07-26 14:51:53 +0300 • Fix GetNew(C)Window autopositioning code
2022-07-26 14:07:53 +0300 • Fix TESetStyleScrap (StyleDataPtr -> TextStylePtr)
2022-07-26 05:35:47 +0300 • Version 9 compressed resource support (+fixes)
2022-07-26 03:05:37 +0300 • Add dummy ReplaceText selector stub for ScriptUtil
2022-07-26 00:46:57 +0300 • Add TESetStyleScrap (needs still some work)
2022-07-25 03:33:36 +0300 • Update line start for redraw when setting heights
2022-07-24 14:12:29 +0300 • Implement styled TESetSelect
2022-07-24 14:11:48 +0300 • Partial implementation of styled TEInsert
2022-07-24 06:08:06 +0300 • Merge branch 'master' of
2022-07-24 06:05:17 +0300 • Work on styled text (TEContinuousStyle selector)
2022-07-24 06:03:22 +0300 • Implement AdMin blend mode in color region blitter
2022-07-23 22:33:53 +0300 • Call vector #4 for unimplemented instructions
2022-07-23 02:07:22 +0300 • AppleDoubler: cleanup tool console output logging
2022-07-23 01:40:40 +0300 • AppleDoubler: add timestamps,buildscript & cleanup
2022-07-21 16:26:26 +0300 • Fix incorrect cProtectErr check in SetEntries
2022-07-21 15:32:55 +0300 • Implement FracSin and FracCos traps
2022-07-19 15:40:00 +0300 • Only mark arc dirty, if drawn on the screen port
2022-07-19 15:02:32 +0300 • Fix some compiler warnings (missing QD includes)
2022-07-19 15:00:12 +0300 • Use bullet (0xA5) as mark in popupUseWFont CDEF 63
2022-07-19 14:58:54 +0300 • Fix one-off error in MBDF hittest (crashed popups)
2022-07-19 06:45:32 +0300 • Fix saving of port state in TextEdit calls
2022-07-19 06:44:33 +0300 • Fix warnings in cursor module
2022-07-19 06:13:22 +0300 • Merge branch 'master' of
2022-07-19 06:12:48 +0300 • Add color QD hilite & fix font state in CDEF 63
2022-07-18 21:14:00 +0300 • Merge branch 'master' of
2022-07-18 21:13:52 +0300 • Cleanup: Refactor cursor code out of Mouse module
2022-07-18 04:12:22 +0300 • Support also function key (F1-F15) key codes
2022-07-17 07:38:02 +0300 • Fix incorrect ShieldCursor offsetPt in CopyBits
2022-07-17 07:27:27 +0300 • Implement DefaultSetCCursor (for 'crsr' support)
2022-07-17 07:26:49 +0300 • Fix MCallSetCCursor (called wrong vector)
2022-07-17 07:26:03 +0300 • Fix handle resizing bug in GetCCursor
2022-07-17 06:15:09 +0300 • Fix cursor left-side clipping
2022-07-17 02:36:52 +0300 • Color QD monochrome software cursor implemented
2022-07-11 23:12:03 +0300 • Use DoVBLTask do update cursor in color QD mode
2022-07-11 23:09:54 +0300 • Implement AddIconToSuite selector in IconDispatch
2022-07-11 21:56:20 +0300 • Implement NewIconSuite selector for IconDispatch
2022-07-11 19:40:19 +0300 • Implement AttackVBL trap
2022-07-11 14:27:11 +0300 • More color vs b&w QD cursor code specialization
2022-07-11 02:43:18 +0300 • Cleanup Cursor module code
2022-07-11 02:42:49 +0300 • Specialize Color QD case in ShieldCursor
2022-07-11 02:35:42 +0300 • Init cursor at startup
2022-07-10 14:29:23 +0300 • Redraw software cursor in SetCursor, if changed
2022-07-10 13:13:16 +0300 • Fix clamping of mouse in DefaultCrsrTask
2022-07-10 04:07:45 +0300 • Merge branch 'master' of
2022-07-10 04:07:02 +0300 • Implement software cursor for "classic" QD mode
2022-07-10 04:05:22 +0300 • Fix DefaultShieldCursor (it did not erase cursor)
2022-07-10 03:58:34 +0300 • Fix CrsrObscure handling in the DefaultCrsrTask
2022-07-10 03:57:44 +0300 • Only setup AllocCursor and SetCCursor in color QD
2022-07-10 03:56:18 +0300 • Increase screen buffer refresh rate temporarily
2022-07-10 03:55:34 +0300 • Fix mouse native window clamping (-1 from bounds)
2022-07-08 02:35:07 +0300 • Merge branch 'master' of
2022-07-08 02:35:00 +0300 • Vectorize SetCCursor (& fix some setup bugs)
2022-07-08 02:17:30 +0300 • Merge branch 'master' of
2022-07-07 20:25:22 +0300 • Fix ShieldCursor bugs
2022-07-05 23:44:59 +0300 • Fix Serial.h
2022-07-05 02:56:01 +0300 • Merge branch 'master' of
2022-07-05 02:55:56 +0300 • AppleDoubler: Fix OSX's weird swap of ':' and '/'
2022-07-04 16:50:27 +0300 • Fix LoadSeg 32K+ offset wraparound (use unsigned)
2022-07-04 16:29:48 +0300 • Merge branch 'master' of
2022-07-04 16:29:41 +0300 • Add dummy serial driver stub (AIn/AOut/Bin/BOut)
2022-07-04 15:04:51 +0300 • Fix UPP call signature of JShieldCursor
2022-07-04 04:28:09 +0300 • Merge branch 'master' of
2022-07-04 04:27:59 +0300 • AppleDoubler: Also encode folder names
2022-07-04 02:16:46 +0300 • Fix byteswap bug in font size check
2022-07-04 02:00:14 +0300 • Fix FOND style lookup: start at 1st match,not last
2022-07-04 01:56:59 +0300 • Add Oregon Trail (1.x) to test app configs
2022-07-03 14:05:54 +0300 • Implement QDDone selector for QDExtensions
2022-07-03 13:56:22 +0300 • Merge branch 'master' of
2022-07-03 13:56:16 +0300 • Add (no-op) LockRange & UnlockRange in FSDispatch
2022-07-03 04:29:30 +0300 • Add first version of AppleDoubler converter tool
2022-07-02 06:13:32 +0300 • Handle NFSGetDirInfo errors in NFSCreateFileHook
2022-07-02 06:12:36 +0300 • Implement DateToSeconds
2022-07-02 04:06:13 +0300 • Add SoftWindows test app to JSON configs
2022-07-02 04:05:42 +0300 • Implement GetGWorldDevice selector in QDExtensions
2022-06-18 02:05:16 +0300 • Add ZPC to test app config JSONs
2022-04-28 04:01:02 +0300 • Fix crash in TECallCharByte utility routine
2022-04-28 04:00:57 +0300 • Add missing header file from previous commit
2022-04-28 03:57:54 +0300 • Tweak naming of some private TE data structures
2022-04-28 01:18:54 +0300 • Fix GetCTable crash of locked 'clut' in 24bit mode
2022-04-23 22:04:03 +0300 • Implement styled TESetStyle
2022-04-23 21:42:07 +0300 • Work a bit on InitScripts (load smRoman 'itlb' 0)
2022-04-23 13:55:03 +0300 • Add Font2Script & implement FontScript+IntlScript
2022-04-18 11:28:33 +0300 • Temporary fail-safe in _Enqueue
2022-04-18 02:06:31 +0300 • Finish faster non-MeasureText path in NPixel2Char
2022-04-17 22:52:23 +0300 • Use NPixel2Char in TextEdit (FindLine etc)
2022-04-17 22:50:50 +0300 • First version of working NPixel2Char in Script Mgr
2022-04-16 21:08:10 +0300 • Implement SndControl (classic SM2)
2022-04-15 05:03:02 +0300 • Prep TEHitTestHook calls to work with NPixel2Char
2022-04-15 04:59:57 +0300 • Handle 0x2C (font) and 0x2E (glyph state) in PICTs
2022-04-13 16:20:10 +0300 • Fix Munger ptr2=nil & len2=0 case (search)
2022-04-13 02:41:36 +0300 • Allow bypass of ampCmd and timbreCmd in snth 4101

First status update of 2021

For the past half year progress has been a bit more slower than usually, mostly due to Toni being busy with the daily work, playing around on Twitch, and experimenting with his retro raycaster 3D engine prototype, while Pekka has been busy with work and private stuff. There has however been some bits of progress, which are summarized in this post:

“Classic” audio upsampling

Even though Sound Manager support is still under development (with relatively good progress), the audio support for “Classic” type audio (that is, the emulation of audio hardware of Mac 128K through Plus/SE/Classic series machines) has been improved a bit. Originally the audio buffer with 22255 Hz sample rate was passed directly to SDL2, which caused some problems as some systems were not able to handle that format very well. Even though it worked on Mac Pro, for example on M1 Macs it caused the audio in other applications to start cracking and breaking up. By allocating the SDL2 audio buffer in default native format (usually 44100hz), and upsampling the audio data in emulator, most of this problem was eliminated. However, in some cases, clicks are still present in the audio, mostly due to the way how original hardware handles square-wave and sampled sound as a mix of both unsigned and signed 8-bit samples (that is, square wave sound amplitude ranges from 0 to 255, while in same buffer, sampled sounds are in range -128 to 127, with different “silent” baseline level.

TextEdit fixes

There were two critical fixes in the TextEdit, one of which caused at least one of Marathon terminals to crash:

  • In styled text line height table handling code, the code that was used to zero newly added line heights (when adding new lines) was not working properly in the case number of lines was reduced (causing it to try to clear a negative number of lines, wrapping around to a crazy number)
  • TESetStyle was calling TESelView with an invalid pointer

With these fixes, this particular Marathon terminal is now working without crashes – and looks identical to the one on real Macs:

The previously crashed Marathon terminal that works now

Minor fixes to allow streaming of The Fool’s Errand

Most of code needed to support running The Fool’s Errand was already implemented long time ago, but one of the most important things, a way to display the prologue and finale was missing. The original game used a separate application for prologue, and also a dynamically generated file for viewing the finale after completing the game.

On real Macs they were opened using Finder, but we needed to have an easy-to-use way to open them when running the emulator from the single-click app bundle. For this purpose, we hacked very quickly a “MiniLauncher” tool, which allows not only selecting the launch application, but also passing a document in launch parameters – which is required to show the finale (as clicking “Show finale” on Macs actually launches “prologue – finale” application passing the “Show finale” as opened document to it).

Right now the Minilauncher is very primitive and a quick hack to support this one single game, but we plan to improve it later to a more reusable launch tool, probably similar to Apple’s old MiniFinder, to use as a stopgap tool for the first general-purpose version of M.A.C.E.

While implementing this, we found a minor byteswap bug in Launch trap’s handling of AppParmHandle. (Also, Toni was able to complete the full Fool’s Errand playthrough on Twitch using this improved version).

Star Wars day

This year we also celebrated the official Star Wars day (May the 4th) by trying out how the Brøderbund’s Star Wars arcade game’s Mac port works on M.A.C.E. and streaming a bit of it on Twitch:

Star Wars for Mac

Both the sound and visuals seemed to work without any problems. The “main menu” of the game did seem to run a bit faster than on real Macs, but luckily the actual ingame play was not affected by machine speed, and ran just fine.

Monkey Island

Inspired by the number of people recently streaming Monkey Island on Twitch, we were interested to see how the Mac version of that game would run on M.A.C.E. There were a couple tweaks needed to get it to run:

  • The Start Manager traps GetVideoDefault and SetVideoDefault traps were needed, and it seems the the dummy implementations were good enough to make Monkey Island happy
  • ReserveEntry palette manager trap had a bug where the GDevice’s color table was not reseeded when clearing the “reserve” (only when setting it). This caused the inverse color lookup table to not update properly, turning at least the pile of monkeys in Monkey Island about box from grayscale to black & white 🙂

It seems that Monkey Island runs quite well now on the emulator, although doesn’t yet have any sounds until the Sound Manager implementation gets finished. Also, it has some timing glitches at least in cutscenes, which may be related to the timer issues with Prince of Persia 2 and Loony Labyrinth (which need more investigation).

Hilite transfer mode

Another task from long time ago was implementing the hilite transfer mode for Color QuickDraw. It is basically a special transfer mode used to improve the highlighting of selections, done with simple color inversion in monochrome Macs, with a more colorful visualization.

In this mode, the color ports have special rgbHiliteColor field used to determine highlighting color (which by default is populated from HiliteRGB low-memory global). If using the hilite transfer mode of 50 or 58 (or when the special hilitebit in HiliteMode low-memory global is cleared in combination of using xor transfer mode), QuickDraw will swap background and hiliteColor with each other, producing toggleable highlight coloring:

Additionally, the hilite mode was also one missing piece of the scrollbar CDEF thumbnail drag drawing code, so that is now also visualized correctly.

The mysterious stuff in Sierra games #1: Sound in Mixed-Up Mother Goose

Although King’s Quest 1 was already working nicely since last year, Mixed-Up Mother Goose was interestingly having trouble playing audio, so we did a bit of investigation about it. It turns out that game is very strangely using some of the unused 68K user exception vectors to save handle to data being used to track music/audio playback in their VBL handler.

The reason this didn’t work, is that all those vectors were originally uninitialized (set to zero), and this particular version Sierra’s AGI engine checked if the exception vector pointer was set to a value above ROMBase, and it being lower assumed some handler was already present, and skipped using it for its own data. On real Macs, every unused 68K exception vector is initialized during startup by the Error Manager to DS exception handler, which by default is in ROM, and thus makes the game work on those systems. By adding a dummy exception handler and populating all the exception vectors, Mixed-Up Mother Goose was able to play music & sounds without any problems (Toni also did a one-hour playthrough of this game on Twitch to celebrate this fix).

Mixed-Up Mother Goose (with audio working)

The mysterious stuff in Sierra games #2: Color support

One of Toni’s friends on Twitch mentioned that some Sierra AGI games had problems running the 16-color versions in Mac emulators (specifically Space Quest 1), so we were curious and investigated this issue. On the first try, the same problem manifested also in M.A.C.E., so we started to dig a little bit deeper to find the cause of this, and found something interesting.

When I dissected the AGI code in Space Quest 1, I noticed that really weirdly, as the very first thing, the game checks if the the baseAddr of screenBits is above $F000 0000 – and if this check failed, even if the screen would be set to higher bit depth, it would go on and assume it was displaying the game on a monochrome screen.

As the problem on other Mac emulators may be partially related to inability of switching to 24-bit mode (at least when I tried it with Basilisk II), I believe that what is happening is that Slot Manager addresses the cards in different way in 24- vs 32-bit modes (for example, card $9 is accessed through “minor slot space” range of $009x xxxx, which translates to 32-bit address range in “standard slot space” of $F90x xxxx – problem is, that in 32-bit mode, the address would be in “super slot space” of $9xxx xxxx). It should be noted that even in 24-bit mode, at least QuickDraw handles the actual video memory access in 32-bit mode by using SwapMMUMode to temporarily switch the mode – same thing that some 24-bit compatible early color games also do, such as Maelstrom.

In our emulator, as we ran everything in pure 24-bit mode, including the video memory access, we didn’t care about the high byte of the address, which being zero originally displayed the same behaviour. However, after populating the high byte with “faked” standard slot space-type address of 0xF9900000 for video memory as a hack, both Space Quest 1 and Mixed-Up Mother Goose started to work in color mode:

Space Quest 1 in color mode

A more proper memory addressing and slot manager implementation will however be definitely needed, and that will most likely be done when we will be adding the 32-bit memory addressing support in the later part of this year.

Minor Warcraft 2 demo progress

We also did a little bit of work on trying to get Warcraft 2 (and its demo) to work. As it’s so far the only game that requires Thread Manager, it was previously put on a hold due to uncertainty about how much threading features it would be using. Turns out that adding dummy implementations for MacGetCurrentThread, SetThreadSwitcher and YieldToThread were enough to get Warcraft 2 progress a bit. Naturally proper Thread Manager implementation will be added at a later point, most likely in combination of Process Manager and EPPC/AppleTalk support which all are related to each other. But for now, we are able to get at least to the startup options screen – but sadly not further yet:

Warcraft 2 demo startup options dialog

What’s next?

For now, we will try to focus on continuing the research of Sound Manager during the summer. So far the progress on that has been pretty good, as we have already good idea about some of the sound manager data structures and behaviour – but more work is still needed to get it to the point where it can be used in the test applications, and to actually produce the sounds. It should be noted that we will be adding two variants of Sound Manager, the 2.x compatible version that will be used in the “classic” mode (which was the highest Sound Manager version supported by the old monochrome Macs), and 3.x compatible version for the color-capable (i.e. slot manager) emulation mode. We also may need to implement ASC-compatible version of the “.Sound” driver to support stuff like fourtone synthesizer in early color games (but instead of hardware emulation like in “classic” mode, that will be all done directly in software).

Full list of changes since last post

2021-06-21 03:42:10 +0300 • Add dummy IconIDTorgn & PlotIconID to IconDispatch
2021-06-21 03:41:08 +0300 • Fix NewGWorld fail crash (duplicate DisposeHandle)
2021-06-21 03:39:03 +0300 • Add dummy SPBOpenDevice to SoundInputManager      
2021-06-21 03:38:17 +0300 • Add dummy YieldToThread selector to ThreadDispatch
2021-06-19 13:27:53 +0300 • Fix some incorrect PaletteDispatch selector sizes 
2021-06-19 13:04:30 +0300 • Add dummy SetThreadSwitcher to ThreadDispatch     
2021-06-19 13:01:37 +0300 • Don't crash MDEF 0 on unsupported messages        
2021-06-18 21:00:20 +0300 • Add ThreadDispatch & dummy MacGetCurrentThread    
2021-06-18 17:30:21 +0300 • Add dummy Thread Manager module                   
2021-06-14 16:30:06 +0300 • Add Space Quest 1 test application JSON configs   
2021-06-14 16:29:41 +0300 • Add 16-color Sierra AGI compatibility HACK        
2021-06-14 16:27:15 +0300 • Add dummy _Eject trap handler                     
2021-06-05 04:09:17 +0300 • Fix drawing of scroll thumb outline in color mode 
2021-06-05 03:18:30 +0300 • Add Civilization DEMO test application JSON config
2021-06-04 22:18:11 +0300 • Fix GetResource (DON'T set resNotFound to ResErr) 
2021-06-04 00:03:10 +0300 • Implement PixMap32Bit                             
2021-06-04 00:02:12 +0300 • Fix initialization of screen GDevice pmVersion    
2021-06-03 23:39:35 +0300 • Fix byteswap bug in GetPixelsState in QDExtensions
2021-06-03 23:00:04 +0300 • TextEdit fixes for the hilite mode support        
2021-06-03 22:58:40 +0300 • Implement GetIconSuite for IconDispatch           
2021-06-03 21:11:28 +0300 • Fix inet_ntop buffer size in AddrToStr in MacTCP  
2021-06-03 17:43:28 +0300 • Also add hilite transfer mode to region blitter   
2021-06-03 17:21:44 +0300 • Support hilite transfer mode in rectangle blitter 
2021-06-03 17:18:33 +0300 • Fix mask of source pixels in transparent blit mode
2021-06-03 01:39:31 +0300 • Merge branch 'master' of <redacted> 
2021-06-03 01:39:26 +0300 • Fix ReserveEntry (reseed CT also w/ reserve=false)
2021-06-03 01:35:55 +0300 • Add StartManager + dummy Get/SetVideoDefault traps
2021-06-03 01:35:02 +0300 • Add Monkey Island test app JSON configs           
2021-05-31 11:50:14 +0300 • Merge branch 'master' of <redacted> 
2021-05-31 11:50:10 +0300 • Add dummy minilauncher code, to be improved later 
2021-05-30 22:01:00 +0300 • Fix nested VBL interrupt support (to not hang)    
2021-05-30 20:25:37 +0300 • Add a generic DS exception handler to all vectors 
2021-05-30 20:21:55 +0300 • Add Mother Goose test app JSON configs            
2021-05-04 04:55:48 +0300 • Add Star Wars test app, for May 4th celebration 🙂
2021-04-13 16:47:10 +0300 • Merge branch 'master' of <redacted> 
2021-04-13 16:47:05 +0300 • Fix 1-bit pixmap expansion with custom colortable 
2021-03-30 02:09:37 +0300 • Fix byteswap bug of AppParmHandle in A5 world     
2021-03-03 13:15:25 +0200 • Ignore thirdparty lib xcode user workspace folder 
2021-03-02 22:45:30 +0200 • Merge branch 'master' of <redacted> 
2021-03-02 22:45:12 +0200 • Fix invalid pointer bug in TESetStyle             
2021-03-02 22:44:15 +0200 • Fix negative bytecount bug in TESetLineHeights    
2021-03-02 19:42:19 +0200 • Fix debug mode in posix file copy utlity (errno)  
2021-03-02 19:41:43 +0200 • Fix __APPLE_ preprocessor typo to __APPLE__       
2021-03-02 19:11:43 +0200 • Make raspberry pi version compile again           
2021-03-02 02:45:14 +0200 • Make CMP0114 policy compatible with old CMake too 
2021-03-01 22:22:12 +0200 • Remove printf                                     
2021-03-01 04:09:50 +0200 • Setup QoS class for main thread on Apple M1       
2021-03-01 04:09:09 +0200 • Upsample audio from 22255 to 44100 manually       
2021-02-24 22:56:53 +0200 • Universal compilation cmake config for M1 macs    
2021-02-21 01:20:48 +0200 • Minor fixes(?) to 16/32-bit bitmap upscaling      
2021-02-21 01:18:25 +0200 • Fix planeBytes comparison in PixMap equality check

Happy new year! First M1 benchmarks, and other fixes

First tests on Apple Silicon

Toni finally got a M1 MacBook Air in mid-January, so we have now been able to try out compiling the emulator on macOS arm64 target. As all arm-specific issues were already fixed in the Raspberry port, the code compiled directly without any modifications needed, and is also running without any issues. However, the CMake build system needs to be tweaked a little bit to allow universal builds, as by default it generates only arm64-only builds. Soon when this is sorted out, we will update the available downloads to include the M1-native versions. Below however are some Speedometer test that we got from quick testing:

Here’s breakdown of the scores:

  • The first score, 35.8 total (0.774 cpu) is from x64 native code running on 2015 MacBook Pro (2.7 Ghz i5)
  • The second score, 90.6 total (1.700 cpu) is from x64 code running on M1 MacBook Air in Rosetta emulation
  • The third score, 146.2 total (2.770 cpu) is from arm64 code running on M1 MacBook Air natively

So it seems that the Apple Silicon builds seem to be working quite well (even though according to Pukka, there is a lot of possibility for optimization; more about this later)

Color support for scrollbar controls

Another TODO-task from long time ago was adding finally color support for the scroll bar control (CDEF 1). The windows, standard buttons and menus had already color support, but this was the last piece missing from a full reproduction of System 7-style appearance. Technically the control code is complete, but the scrollbar thumb dragging is still missing hilite mode rendering, so it is only 99% complete. Below is screenshot of one of the games where this visual change is visible (scrollbars on the SimCity 2000 map window):

Color scrollbar (CDEF 1) contols, here in SimCity 2000

Boolean bitmap color blending fixed

Another fix we did was analyzing and fixing the problem with text rendering in Master of orion, which we wrote about in the last month’s update. What we found out, was that according to IM:Imaging With QuickDraw book, sourcing any bitmap transfers from monochrome sources to color destinations need to be colorized in a bit different way compared to color transfers. What this means, is that when doing pixel scaling, the source color table lookups are skipped, and the foreground/background colors are applied directly on the source bitmap data. With this fixed, all the texts appear now correctly in Master of Orion:

Master of Orion with text blending issue fixed

Trying out a couple more new games

We also added some new games to the suite of test cases, in this case Might & Magic II and Loom:

  • Might & Magic III needed a couple Script Manager routines, which we added as placeholders, so the game starts up, but text rendering is still a bit off
  • Loom seems to work nicely as-is, although like all other color applications, needs Sound Manager support to get any sound.

68k TRAP instructions and THINK Pascal LightsBug

Another thing that we got to work was the 68K TRAP instruction handler, which enabled the debugging in THINK Pascal to work quite nicely. Breakpoints, execution control, LightsBug features (variable views, 68K registers, heap) seem to work mostly okay. The IDE does however complain about memory zone corruption, although all zones are fine (something is also causing the LightsBug zone explorer to fail, so there may be still some minor incompatiblity there).

Pukka is currently in progress of improving the exception support in the 68k emulator, so we will have the support for TRAPs fully implemented soon.

Other stuff

Here’s a couple other things that were fixed:

  • Added support for drawing labels for the popup menu control (CDEF 63). This is used by Master of Orion in the new game setup dialogs
  • Don’t assume FMExist low-memory global exists on “classic” type Macs. This came up as THINK Pascal does a lot low-level patching on a number of Toolbox routines (to allow running applications inside THINK Pascal itself), InitFonts is expected to run on the older machine profiles even if FMExist would be marked to tell that Font Manager is initialized
  • Fixed CopyBits device port pre-draw intersection to take port origin into account; ignoring this cased scrolling up ResEdit editors to make contents of window disappear as the origin moved far enough up off the screen
  • Graying of standard button control (CDEF 0) checkbox and radio button variants; this fixes the issue that disabled controls did not render as grayed out in color ports
  • Added a number of color menu table access routines (GetMCInfo, SetMCInfo, DisposeMCInfo + other tweaks), which allow ResEdit to now display MENU resource previews also in Color QD mode – and also, the MENU resource editor seems to also work, with full color editing features

Regarding optimization, after discussion with Pukka, we decided that we should try in very near future an alternate way of mapping the emulated machine memory using host system/machine paging instead of the currently VM lookup table. Theoretically, using mmap (with possible combination of libsegv or similar) to map memory to a certain fixed “window” in memory, we could almost completely eliminate the penalty of emulated machine memory accesses. According to profiling results, should theoretically double the emulation speed, but we need to experiment with this to see how the results are. We will write more about this when we soon have chance to try it out.

Also, Toni has been doing a couple small experiments on using M.A.C.E. for trying out Twitch.TV streaming at https://www.twitch.tv/truetonizz.

Full list of changes since last post

2021-01-12 13:55:56 +0200 • Add missing path to toolbox cmake build script
2021-01-12 11:03:38 +0200 • Inline VM access calls & add dummy page handler
2021-01-12 02:57:09 +0200 • Add Loom test app JSON config settings for CMake
2021-01-12 02:55:57 +0200 • QDScaleColorize1ToIndexed4 (colorizing 1-to-4 bit)
2021-01-08 13:58:28 +0200 • Add QDScale1ToIndexed4 (1-to-4-bit depth scaling)
2021-01-06 05:12:58 +0200 • Apply bgColor in patBic mode in color rect blitter
2021-01-05 22:22:34 +0200 • Force also ROM clut copies to NoPurge in GetCTable
2021-01-05 22:19:49 +0200 • Set MemErr in HPurge/HNoPurge/HClrRBit/HSetRBit
2021-01-05 16:37:01 +0200 • Handle empty (zero-size) 'ictb' resources properly
2021-01-05 02:10:20 +0200 • Fix also graying of CDEF 0 radio/checkbox buttons
2021-01-05 01:50:08 +0200 • Color QD button graying (text & default frame)
2021-01-04 22:41:52 +0200 • Fix color QD CopyBits when scrolling w/ SetOrigin
2021-01-04 06:00:32 +0200 • Implement GetMCInfo/SetMCInfo/DisposeMCInfo traps
2021-01-03 03:10:35 +0200 • Don't use FMExist on "classic" b&w configuration
2021-01-03 03:09:32 +0200 • Use non-MacPlus trap table profile in THINK Pascal
2021-01-02 20:32:55 +0200 • Minor code cleanup in standard windowproc (WDEF 0)
2021-01-02 20:31:57 +0200 • Add color support to scrollbar controls (CDEF #1)
2021-01-02 20:30:52 +0200 • Merge branch 'master' of
2021-01-01 10:49:54 +0200 • Clean up Dialog Manager drawing save state locals
2021-01-01 02:28:56 +0200 • Implement VisibleLength selector for ScriptUtil
2021-01-01 01:34:20 +0200 • Add dummy StyledLineBreak selector to ScriptUtil
2021-01-01 01:12:18 +0200 • Partial implementation of TEGetStyleScrap selector
2020-12-30 23:20:43 +0200 • Merge branch 'master' of
2020-12-30 23:08:14 +0200 • Add CMake JSON test config for Might & Magic III
2020-12-30 20:47:49 +0200 • Add colorizing 1-to-8bit pixel translation
2020-12-30 20:45:07 +0200 • Fix ctSeed byteswap in stretch dither mode check
2020-12-30 18:45:02 +0200 • Uncheck item after popup menu selection
2020-12-30 18:41:35 +0200 • Draw labels in popup menu control + colorQD stuff
2020-12-30 10:14:41 +0200 • Fix some byteswap bugs in the popup menu control
2020-12-30 00:42:07 +0200 • Fix popup menu control MENU reloading
2020-12-29 23:28:18 +0200 • Fix mouseMoved message signature
2020-12-29 22:16:18 +0200 • Pixpat expander a bit safer in case of memory move
2020-12-29 22:12:37 +0200 • Add correct 1-bit boolean stretching depth scaling
2020-12-24 00:11:46 +0200 • use memory macros for all 68k emulator memory i/o
2020-12-24 00:10:27 +0200 • use memory macro in cpu look, remove unused proc..
2020-12-24 00:09:10 +0200 • make index offset branchless
2020-12-22 00:09:37 +0200 • Add Solarian II to test application CMake configs

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

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: http://www.the8bitguy.com/product/planet-x3-for-ms-dos-computers/

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

Post-midsummer update; Eric’s Ultimate Solitaire

As we estimated previously, the progress has been a bit slow during the summer months, with so many things to do in “real life”. But there have been a few things here and there that have been tweaked in the moments, when there has been a moment of time. Here’s a brief breakdown of the key things that have been changed:

In attempt to get some picky color games to work (such as Warlords 2, Warcraft and A/10 attack), a number of hacks have been added:

  • A number of placeholder gestalt functions, with dummy values to allow the games to pass startup tests (for example, Warlords 2 appears to not start unless the system tells it supports truetype fonts…)
  • Some help manager’s Pack14 selectors, such as querying balloon help mode and setting the balloon help mode
  • A number of process manager selectors in OSDispatch, which seem to be used by some apps to check if it is in foreground in multitasking environment
  • More dummy placeholders for Apple Events. There was not yet time to research futher, but I’m guessing some of the apps are expecting kAEOpenApplication (‘oapp’) event at startup to proceed correctly. The apple events will most likely be implemented parallel to better process manager support later, so that any dependencies with EPPC can be verified)
  • subPin mode for the awesome looking alpha-blended shadows in Warlord’s 2 windows

More work is still needed to make the above games work, assumedly the lack of AppleEvents right now is blocking a number of them from working.

Eric’s Ultimate Solitaire Sampler also required implementing (& fixing) some things:

  • Some color blitter updates (blend and srcBic transfer mode improvements, and other minor improvements). The game uses these to do nice blending effects on the highlighted cards, including blending the card “slots” with background. These appear now to draw exactly like on real Mac.
  • ‘PICT’ opOrigin opcode was fixed, if a picture would have a non-zero origin, the fact that V and H values were swapped would cause it to be drawn at a wrong location

One of the most important changes was finally fixing the SANE’s Extended 80-bit to 64-bit double encoding/decoding bugs. The basic exponent/fraction conversion was already fixed over one year ago, but the special cases were completely broken (such as NaN, Inf and zero values). Also, clamping the exponent/fraction values when doing conversion to lower bit size was broken, instead of actually getting clamped these values would wrap around…not good! Most notable result of these fixes is that Speedometer now displays properly zero (0) as the initial score instead of 2.0.

Below are some screenshots of this awesome-looking card game:

There are still a couple issues left to fix, most notably the game complains about missing resources on each startup, even though it still succeeds to open. And as the sound manager implementation for the color version environment is still unfinished, there are no sounds yet. But mostly, the game works quite well, and is very playable, as you can see from the number of games and time played statistics screenshot above 🙂

At the moment, Toni is working on getting the picture recording to work in color mode (PICT2 support), which is required to get some editors to work properly in ResEdit, and Pukka is researching the full extension word format of 68020 emulation, which when will allow a large number of new color applications to work.

Full list of changes since last post

2020-07-31 22:06:34 +0300 • More work on PICT2 recording (pixpats in-progress)
2020-07-21 05:29:26 +0300 • Support grafProcs' putPicProc for StdPutPic
2020-07-21 05:01:31 +0300 • Implement CopyPixPat trap
2020-07-16 22:41:09 +0300 • Initialize pnMode correctly in OpenPicture
2020-07-16 22:40:40 +0300 • Fix PICT verb recorder bugs (pnSize & swap pnMode)
2020-07-16 05:13:03 +0300 • Make StdComment recording version 2 compatible
2020-07-14 05:47:44 +0300 • OpenCPicture & ColorQD OpenPicture abstraction
2020-07-08 05:31:55 +0300 • Tweak Float64 to Float80 conversion (denorm exp)
2020-07-07 14:34:46 +0300 • Other Float80 special cases; NaN, denormals, infs
2020-07-04 20:35:08 +0300 • Handle zero special case @ 80-bit float conversion
2020-07-04 12:28:21 +0300 • Fix mixed up H and V delta values in opOrigin
2020-07-04 12:26:43 +0300 • Add non-colorizing stretch blitter for srcBic mode
2020-07-04 04:05:17 +0300 • Fix opOrigin picture opcode
2020-07-04 02:35:44 +0300 • Fix missing alignment shift of arithmetic blitters
2020-07-03 14:39:58 +0300 • Implement FSUBS for SANE's FP68K dispatcher
2020-07-03 14:34:15 +0300 • Improve direct color support in stretch blitter
2020-06-28 01:38:25 +0300 • Add indexed region blitter for "blend" (0x20) mode
2020-06-28 01:36:23 +0300 • Add Eric's Ultimate Solitaire Sample test app
2020-06-22 02:45:59 +0300 • Fix inverted handling of TE record's active flag
2020-06-22 02:44:50 +0300 • Add AE and ProcMgr control configs to environment
2020-06-14 04:58:58 +0300 • Add Prince of Destruction test app to cmake JSON
2020-06-13 21:42:12 +0300 • Add missing procNotFound define to MacErrors.h
2020-06-13 21:41:27 +0300 • Add A10 Attack! Demo test app to cmake json config
2020-06-13 19:13:46 +0300 • Add dummy GetNextProcess
2020-06-13 19:13:10 +0300 • Add some missing data types & enums to Processes.h
2020-06-12 04:08:43 +0300 • Add dummy InitEditionPack & EditionManager module
2020-06-12 03:56:06 +0300 • Add dummy RestoreDeviceClut selector
2020-06-12 03:44:33 +0300 • Properly fix the previously disabled optimization
2020-06-12 00:10:50 +0300 • Add dummy AESetInteractionAllowed Pack8 selector
2020-06-11 17:48:36 +0300 • Fix InvalMenuBar to really work (Warlords 2 menus)
2020-06-10 20:57:41 +0300 • Disable a buggy copybits colorization optimization
2020-06-10 19:09:03 +0300 • subPin mode color region blitter (WarLords 2 demo)
2020-06-10 19:08:15 +0300 • Fix invCT pointer in color mapping (skip header)
2020-06-10 13:59:56 +0300 • Fix WDCB allocation: list size is bytes, not count
2020-06-10 05:57:31 +0300 • Dummy HMIsBalloon & HMSetBalloons for Pack14
2020-06-10 05:51:30 +0300 • GetCurrentProcess, GetProcessFromLayer, SameProc..
2020-06-10 05:29:24 +0300 • Implement AECreateDesc in Pack8 (AppleEvents)
2020-06-10 05:28:23 +0300 • Add MacAppleEvents.h (+move old stuff from Events)
2020-06-10 05:27:17 +0300 • Tweak trap generator to allow "result" param name
2020-06-10 04:49:08 +0300 • Add dummy OSDispatch & GetProcessInformation
2020-06-10 04:17:52 +0300 • Fake gestaltLaunchControl flag for Warlords 2
2020-06-10 03:52:44 +0300 • Fix script mgr gestalt functions (emIntlGlobals)
2020-06-10 02:35:00 +0300 • Add 'a/ux', 'edtn', 'help', 'pop!', 'font', 'stdf'
2020-06-10 01:23:22 +0300 • Add dummy AEInteractWithUser selector for Pack8
2020-06-10 01:14:16 +0300 • Add 'kbd', 'hdwr', 'evnt' and 'os ' gestalt funcs

GWorlds and PixPats

Since the last update, there has been progress on many features, but especially on the following ones to highlight:

GWorlds

The GWorld routines are practical utility functions for easy creation and handling of off-screen color ports, relieving the developer from a lot of mundane tasks for allocating the memory structures and house-keeping them. In the old “classic” QuickDraw, the developers were forced to do all this by themselves, but on other hand, the old-style QuickDraw had a lot less complexity and fewer data structures. The color QD requires maintenance of PixMap structures, and possibly “fake” GDevice handles with unique color tables and inverse color lookup tables, etc. The routines which color version were implemented this time were (* indicates ones that previously existed for “classic” QD’s GWorld wrappers):

  • NewGWorld
  • LockPixels*
  • UnlockPixels*
  • DisposeGWorld
  • GetGWorld
  • SetGWorld
  • CTabChanged
  • AllowPurgePixels
  • NoPurgePixels
  • GetPixelsState
  • SetPixelsState
  • GetPixBaseAddr
  • GetGWorldPixMap

The games which benefitted most of the new GWorld routines were Wolfenstein 3D, SimCity 2000 and Civilization. It is also possible other games are utilizing them, but these were the ones first encountered in the test suite:

Wolfenstein 3D

PixPat support

Another new feature added in the color QuickDraw are the PixPat patterns. As old QuickDraw only allowed 1-bit monochrome patterns, these PixPats have much more flexibility allowing multi-color patterns and also higher resolutions (most commonly seen as powers-of-two from 8 to 64 pixels, and up to 256 colors, although the PixPat data supports also “direct” pixel data).

The interesting feature of these “pixel patterns” is the fact that they actually use regular PixMap data as the pattern storage, so that a lot of internal routines for PixMap manipulation were directly helpful in the implementation of the color patterns. The most code needed for pixpat-specific drawing were the conversion to target depth (using the shader PixMap translators), and handling the special pattern modes in blitters, with repetition of pattern with variable-size dimensions.

Glider 4.0 in color

The first games requiring use of PixPats were Glider 4.0 and Siege of Darkwood – but as a nice side effect, we now also have support for using color patterns on the desktop!

Other stuff

There were also many other minor improvements, some of which include:

  • Finally a proper region-clipped color blitter (was on TODO list for a long time…)
  • 32-bit PICT pixel data support, needed for Escape Velocity
  • CopyBits & ScrollRect, for Civilization and SimCity 2000 map scrolling
  • A bunch of new blitter modes
  • Partial resouce read support for SimCity 2000
  • Abstracted resource loading as a magic “CheckLoad” vector, to make AutoDoubler-compressed applications work (the one we encountered was the color version of Lemmings)
  • MANY bug fixes and other improvements (complete list of everything at the end of this post)

New videos

Since the the last post, we have two new videos of test applications running in color mode. First is Glider 4.0, which seems to now be playable, benefitting especially from the most recent transparent arithmetic transfer mode support:

Glider 4.0 running in color mode on M.A.C.E.

Also, here’s video of Wolfenstein 3D running (the lag is from QT video capture, game itself runs quite smoothly):

Wolfenstein 3D running on M.A.C.E.

And of course as Sound Manager is not yet implemented, there is no audio in either videos.

Status of some of the color test applications

There are also some other games which are starting to get more functional in color mode, here’s a brief update on where they’re at right now:

Most of these games run nicely, but there are some common issues still to be resolved:

  • Menu drawing still need to be updated to support color mode properly
  • List Manager does not yet handle hilite mode properly
  • Scroll Bars are still rendered as monochrome versions only
  • Standard File dialogs have still issues with color mode (folder popup menu, hilite mode, etc)
  • No sound yet because of incomplete Sound Manager implementation
  • Horizontal stretching for pixmap data is not yet implemented (although vertical stretching is), so horizontally scaled text/images do not yet appear properly
  • A lot of missing blitter modes (they will be written as needed in the first pass, but will be generalized and optimized later so that all cases will be properly covered)

There are also a couple cases with application-specific problems:

  • Maelstrom is playable & smooth, but gets stuck at end of level screen probably because of missing Sound Manager Implementation
  • Civilization has a rare bug where inverse color tables appear to break down after playing the game for some time
  • SimCity 2000 has a palette manager bug where a couple of palette entries go to wrong slots, causing a couple specific colors to not display properly (mostly visible in the title screen, and “Dispatch Firefighters” map sprite)
  • Escape Velocity gets to main menu, but crashes due to some unresolved 68k cpu emulation bugs which Pukka is investigating

The status page will be updated in the coming weeks to reflect this new status.

Full list of changes since last post

2020-04-07 00:38:42 +0300 • Add pixpat patOr mode for color rectangle blitter
2020-04-07 00:31:42 +0300 • Add srcBic support to color rectangle blitter
2020-04-07 00:30:52 +0300 • Fix outline/shadow text style in color text render
2020-04-06 21:29:15 +0300 • Do 68K VM stack guard magic check for native fra..
2020-04-06 01:07:31 +0300 • Set bg color in SetWinColor, fix Siege of Darkwood
2020-04-06 00:39:03 +0300 • Fix crash when decoding pixpats from PICT resource
2020-04-05 23:10:26 +0300 • Fix GetPalette bitmasking (missing window redraws)
2020-04-05 05:21:26 +0300 • Indexed transparent arithmetic region renderer
2020-04-05 04:39:00 +0300 • Indexed transparent arithmetic rectangle renderer
2020-04-05 03:22:26 +0300 • Indexed transparent arithmetic scanline renderer
2020-04-04 16:53:34 +0300 • Clean up old commented-out legacy code
2020-04-04 16:52:27 +0300 • Handle undefined EnvDefaultColorDepth case
2020-04-04 16:51:21 +0300 • Handle arithmetic mode setup for color mapping
2020-04-01 22:24:46 +0300 • Update test desktop background pattern
2020-04-01 03:01:26 +0300 • Color desktop ppat (forced on for now for testing)
2020-04-01 02:47:14 +0300 • Fix 8x8 pixpat expansion
2020-04-01 01:59:00 +0300 • Implement (mostly) pixpat conversion & rendering
2020-04-01 01:57:35 +0300 • Separate pixel translation from stretch blitter
2020-04-01 01:43:46 +0300 • Clear CGrafPort refs to pixpat in DisposePixPat
2020-03-30 16:59:25 +0300 • Add (partial) FillCRect/Oval/Arc/Rgn/Poly
2020-03-30 16:00:04 +0300 • Add EnvDefaultColorDepth for app-specific default
2020-03-30 15:32:31 +0300 • Fix region masking bug of diagonal Line/LineTo
2020-03-30 15:30:07 +0300 • Fix ErasePoly (typo from copy-paste)
2020-03-30 11:53:03 +0300 • Fix right-to-left color rectblit & right-edge mask
2020-03-30 04:57:07 +0300 • Add srcXor mode for non-colorizing stretch blitter
2020-03-30 04:54:25 +0300 • Color QD version of polygon operations
2020-03-30 04:47:10 +0300 • Add region-clipped color blitter & fix LOT of bugs
2020-03-30 04:44:10 +0300 • Fix invalid masking in srcCopy in translating blit
2020-03-30 01:18:15 +0300 • Fix iteration of region 3-only non-rect case
2020-03-28 21:53:06 +0200 • Fix inverted hilite flag check in colorized WDEF 0
2020-03-27 21:39:58 +0200 • Fix TextEdit locals saved forecolor overlap bug
2020-03-27 20:45:13 +0200 • Add color support also to WDEF 0 zoom box drawing
2020-03-27 19:34:27 +0200 • Add color support to WDEF 0 growbox drawing
2020-03-27 16:36:51 +0200 • Add (partial) color QD support for ScrollRect
2020-03-27 15:18:16 +0200 • Add Loony Labyrinth test app to CMake JSON configs
2020-03-27 15:17:43 +0200 • Implement SaveFore/Back & RestoreFore/Back
2020-03-27 02:46:11 +0200 • Fix (again) AnimatePalette
2020-03-27 01:36:19 +0200 • Set default palette in GetNewWindow/GetNewCWindow
2020-03-26 23:12:07 +0200 • Implement ReadPartialResource in ResourceDispatch
2020-03-26 22:26:03 +0200 • Fix HCreateResFile (dirID mishandled)
2020-03-26 21:02:04 +0200 • Improve StdText CGrafPort/GWorld compatibility
2020-03-26 21:00:46 +0200 • Fix CloseResFile stack frame mismatch
2020-03-26 20:11:11 +0200 • Implement SetPixelsState and AllowPurgePixels
2020-03-26 19:54:40 +0200 • Implement GetPixelsState selector in QDExtensions
2020-03-26 19:46:06 +0200 • Implement SetGWorld selector in QDExtensions
2020-03-26 19:33:15 +0200 • Implement GetGWorldPixMap selector in QDExtensions
2020-03-26 19:16:17 +0200 • Implement GetGWorld in QDExtensions
2020-03-26 19:12:42 +0200 • Implement Palette2CTab
2020-03-26 18:45:36 +0200 • Add SimCity 2000 test app to CMake JSON configs
2020-03-26 17:24:03 +0200 • CopyBits improvements (fix Escape Velocity crash)
2020-03-26 02:59:02 +0200 • Add 32-bit to indexed color conversion to blitter
2020-03-26 02:57:00 +0200 • Fix rgb PICT data unpack for rowBytes > 250
2020-03-26 02:56:00 +0200 • Implement DisposeCIcon
2020-03-25 22:09:57 +0200 • Support 'PICT' packType=4 RGB data (run-packed)
2020-03-25 20:45:05 +0200 • Start collision check from current link, not next
2020-03-25 19:08:43 +0200 • Fix color blitter for <=32bit wide transfers
2020-03-25 18:35:49 +0200 • Conditionalize Paletter Manager debug log output
2020-03-25 18:34:59 +0200 • Handle collisions in inverse color table lookup
2020-03-25 14:08:12 +0200 • Validate input in SetEntries & clear cached fonts
2020-03-25 03:01:34 +0200 • Fix UInt16/SInt16 RGB delta bug in palette update
2020-03-25 01:13:22 +0200 • Add missing A6 setup for the CheckLoad wrapper
2020-03-25 01:05:40 +0200 • Add secret "CheckLoad" hook (AutoDoubler support)
2020-03-25 00:57:35 +0200 • Add color Lemmings JSON to CMake test apps configs
2020-03-24 22:34:47 +0200 • Clamp cursor hotspot between [0, 15]
2020-03-24 22:34:15 +0200 • Fix color CopyBits thePort/dstBits comparison bug
2020-03-24 19:55:58 +0200 • Extract color QD rect blitter to own module
2020-03-24 19:30:09 +0200 • Implement DisposeGDevice (used in DisposeGWorld)
2020-03-24 14:47:56 +0200 • Implement color QD version of ClosePort
2020-03-24 04:24:57 +0200 • Unreserve palette entry when cleared (single GD)
2020-03-24 04:23:41 +0200 • Set MemErr to noErr in ReservMem on success
2020-03-24 02:35:37 +0200 • Fix negative dstLeft corruption @ B/W stretch blit
2020-03-23 21:01:59 +0200 • Implement DeleteMCEntries
2020-03-23 20:50:33 +0200 • Paint window (and invalidate) on ActivatePalette
2020-03-23 20:49:14 +0200 • Draw desktop pattern for PaintOne(nil) case
2020-03-23 20:44:03 +0200 • Fix AnimatePalette for srcIndex > 0 cases
2020-03-23 01:41:36 +0200 • Fix GetCatInfo bug by previous fix (non-WDCB case)
2020-03-23 01:27:40 +0200 • Minor menu color entry manipulation tweaks
2020-03-23 01:25:58 +0200 • Fix monochrome QD compilation error
2020-03-22 23:36:53 +0200 • Implement SetEntryColor
2020-03-22 23:24:53 +0200 • Implement GetPalette trap for Palette Manager
2020-03-22 22:09:37 +0200 • Extract PaletteDispatch routines to own C module
2020-03-22 21:42:58 +0200 • Add Ultimate Doom test app to JSON configs
2020-03-22 21:42:24 +0200 • Add CTabChanged and (partial) DisposeGWorld
2020-03-22 07:33:06 +0200 • Give more CPU time for 68020+ mode
2020-03-22 06:46:10 +0200 • Fix buffer size bug in NewGWorld w/ pixelDepth = 0
2020-03-22 03:55:04 +0200 • Implement FCMPS in FP68K (SANE) for Wolf3D
2020-03-22 03:42:46 +0200 • Improve bits opcode (9x) for non-indexed support
2020-03-22 03:37:10 +0200 • Implement NoPurgePixels selector
2020-03-22 03:36:45 +0200 • Fix unassigned pmBounds.left bug in NewGWorld
2020-03-22 02:23:21 +0200 • Implement color QD version of NewGWorld
2020-03-22 02:22:18 +0200 • Resolve WDCB to DirID in GetCatInfo ioFDirIndex>1
2020-03-21 18:50:18 +0200 • Add 'qdrw' Gestalt selector (Quickdraw features)
2020-03-21 04:44:26 +0200 • Fix pixpat opcodes in DrawPicture
2020-03-21 04:42:32 +0200 • Implement unpacked pixmap data load in DrawPicture
2020-03-21 04:40:28 +0200 • Fix CloseWD crash (ignore ioNamePtr)
2020-03-21 03:43:35 +0200 • Implement CopyPixMap
2020-03-21 02:26:20 +0200 • Fix GetPenState bug (caused gray fills everywhere)
2020-03-21 01:33:43 +0200 • Implement color QD version of ScrnBitMap
2020-03-21 01:20:54 +0200 • Hack tmp SoundBase to make Glider 4 happy in color
2020-03-21 01:19:08 +0200 • Implement color CopyMask (untested!)
2020-03-21 01:17:37 +0200 • Fix missing argument deref in color pat conversion
2020-03-21 01:16:34 +0200 • Add 'vm ' Gestalt selector (returns 0 for no VM)
2020-03-21 01:14:12 +0200 • Add HWPriv & dummy FlushData/FlushInstructionCache
2020-03-20 19:18:33 +0200 • Fix colorQD highlight bug of radio/checkbox button
2020-03-20 19:09:02 +0200 • Implement grayishTextOr mode for StdText
2020-03-20 19:07:55 +0200 • Implement GetGray selector for PaletteDispatch
2020-03-20 19:06:06 +0200 • Tweak signature of rgb delta calculation to UInt16
2020-03-20 18:20:45 +0200 • Implement patBic mode in pattern rect blitter
2020-03-20 06:22:31 +0200 • Fix StdGetPic, handle byteCount as unsigned UInt16
2020-03-20 06:20:48 +0200 • Implement GetPixBaseAddr selector in QDExtensions
2020-03-20 05:27:15 +0200 • Fix masking bug in color stretch blitter
2020-03-20 03:38:11 +0200 • Add a bunch empty dummy SoundDispatch placeholders
2020-03-20 02:57:14 +0200 • Implement QDError trap
2020-03-20 02:54:26 +0200 • Implement FSpOpenResFile and FSpCreateResFile
2020-03-20 02:52:57 +0200 • Implement HCreateResFile
2020-03-20 02:29:20 +0200 • Add semi-dummy ResolveAliasFile selector
2020-03-20 02:08:52 +0200 • Add Escape Velocity test app to cmake configs
2020-03-20 02:08:30 +0200 • Add missing file from previous commit
2020-03-20 02:08:18 +0200 • Add Pack12 & Fix2SmallFract+SmallFract2Fix+RGB2HSL
2020-03-20 00:06:06 +0200 • Fix signature of SwapMMUMode
2020-03-19 23:25:45 +0200 • Fix text styling buffer overflow in color QD
2020-03-19 23:22:36 +0200 • Apply kernMax in color font renderer
2020-03-19 19:18:59 +0200 • Update & re-seed GDevice pmTable in SetEntries too
2020-03-19 16:01:13 +0200 • 4-bit debug palette view
2020-03-19 16:00:59 +0200 • Implement SetPortPix trap
2020-03-19 01:26:06 +0200 • Add fake SwapMMUMode trap
2020-03-19 01:24:19 +0200 • Add dummy 'snd ' Gestalt selector
2020-03-19 01:23:39 +0200 • Dummy SoundDispatch (& dummy SndPlayDoubleBuffer)
2020-03-19 00:40:09 +0200 • Add Maelstrom test app to cmake configs
2020-03-19 00:39:47 +0200 • Dispose auxCtlRec also in DisposeControl trap
2020-03-19 00:29:57 +0200 • Fix 'cctb' ID=0 bug
2020-03-19 00:15:34 +0200 • Implement ProtectEntry and ReserveEntry traps
2020-03-18 23:53:47 +0200 • Fix RS stack frame mismatch in FrameRect
2020-03-18 23:53:10 +0200 • Implement TestDeviceAttribute & SetDeviceAttribute
2020-03-18 23:44:13 +0200 • Implement GetCWMgrPort trap

More color support & Palette Manager

The ongoing epidemic in the world these days is sadly the focus of the news and is touching in some way all of us, and we hope the people reading this will stay safe and healthy during these challenging times. Although our close ones have not (yet) been affected directly by the situation, the impact on our daily lives is already taking effect, as some of us are currently working remotely from home, borders are being closed, and toilet paper is being stockpiled.

One way for us to deal in these times when our lives are getting limited, is to focus our energy on the things we love, one of which for us is working on this project. And hopefully our ongoing efforts will encourage others to look forward into the future with positive thoughts.

Since last post, the focus has been on improving color support on multiple fronts, and testing the new functionality on color-capable test applications. Last month, we already got gameplay to work in KYE, and now two more games are starting to give good results; Railroad Tycoon and Prince of Persia.

Font rendering & window widgets

One important part missing from KYE (and all apps in general) was the font rendering. This was visible as the absence of menu items and window titles, which works now for the basic cases:

Font rendering works now in color mode (and window widgets)

Also the window widgets finally work, which can be seen in the above screenshot as the goAway box is visible in topleft corner of the Window. The WDEF 0 supports all ‘wctb’ parts now as the original System 7 WDEF did, and colorizes them using a method which should visually give nearly equal results.

At the time of writing this, text rendering in color mode only works for non-styled, and non-scaled text. The styling requires use of an extra offscreen buffer, which we haven’t yet had time to implement for the color version, and scaling requires stretching color blitter, which is not yet implemented.

Menu, Dialog and Alert color tables

As the basic text rendering works now, one interesting game to try it out with is Railroad Tycoon, because that game utilizes heavily custom color tables for menus, windows, dialogs and alerts:

Railroad Tycoon first intro dialog box in color

The above screenshot demonstrates all of those features in one picture:

  • The blue menus are colorized using ‘mctb’ resources
  • The red dialog background comes from ‘dctb’ resource (which is equal to both ‘actb’ and ‘wctb’ resources in both structure and usage)
  • The white text in labels (and red background for them) comes from ‘ictb’ resources

Color ‘PICT’ Pictures

Another new feature is the (partial) support for color pictures, that is, PICT resources containing pixmap data in addition to 1-bit bitmap data and methods for controlling the color-specific features in CGrafPorts. With a couple opcodes improved with color support, we got this:

The picture data reading and blitting works nicely, except that the Railroad Tycoon logo has some glitches on left and right edges. It might be related to unfinished region clipping code, but I suspect we might also need to double-check the alignment handling. The main menu in Railroad Tycoon looks a bit messed up at the moment, as the pen pattern setting is probably having some minor issues (it should have solid black pattern, but defaults to 50% gray-dither pattern at the moment).

And the Glider 4.0 main screen also works now with the picture rendering code:

Glider 4.0 main screen in color

Palette Manager

One thing that was a bit off in the Railroad Tycoon intro and main menus was also the color table, because the game actually uses a custom palette for a nice sepia tone. This meant that next up was the implementation of Palette Manager, as up until now only the default system color lookup table (‘clut’ resources for individual color depths) was used to colorize everything.

Tolerant colors

The first use case, as mentioned above, was Railroad Tycoon, which was a bit easier to deal with, as it uses ‘tolerant’ colors in its palette. The palettes in the game are actually 16-color palettes, replacing the entire color lookup table, but they work also nicely in the 256-color mode which we tested:

On the left, you can see that the skin and map have highly ‘carroty’ orange shade, while on the right, with correct palette, they appear in nice sepia tones as intended. We also added a small palette debug feature to show state of color lookup tables. In this case, the ‘tolerant’ colors replaced the closest matches in the system ‘clut’, making it appear nearly same.

Animated colors

Another game which uses palettes heavily, is our beloved Prince of Persia game. Unlike Railroad Tycoon, PoP uses actually ‘animated’ colors, as it depends on AnimateEntries/AnimateEntry to do color animation, AND nice fade-to-black palette effect.

The above screenshots show the progress made during ‘animated’ color implementation. There were a lot quirks and stumbles along the way, but here are key findings of Palette Manager regarding Prince of Persia:

  • It uses ‘animated’ palette entries to do color animation (fade-to-black, twinkling stars, flash effects)
  • The black & white entries of palette are manually set by the game as ‘tolerant’ to allow mapping them to correct black & white at indices 255 and 0 respectively
  • The game maps each of the 200+ colors dynamically to the ColorTable indices using PmForeColor, and polling the resulting color index
  • It appears to convert the images itself to correct indices using the mapping data it gathered
  • The CopyBits calls to blit graphics depend highly on a “same bit-depth, same color table seeds and uncolorized” optimization, where we skip creation of color translation table in the blitter. This is also one part which requires the black to be mapped correctly at index 255, as it allows detecting that using combination of white background (index 0) and black foreground (index 255) skips the need for colorizing
Prince of Persia level 1

The game almost works now, and is actually playable, but encountered a strange crash inside VBL handler during the first level (VBL queue got corrupted, the screenshot above is from the moment when the crash happened). We need to investigate that further in the near future.

Prince of Persia color intro video

To celebrate the advancements made in M.A.C.E., we made a short video of how the color version of emulator looks like when running Prince of Persia:

Prince of Persia Mac Color version intro & demo level

Note that the bottom-right corner shows the rather ‘hacky’ palette debugger, which nicely demonstrates how the game is using AnimateEntries to do color fades & effects.

Next steps

There are a lot of things still to do, but the progress seems promising. For example, we need to get menus to actually work (the saving & restoring menu background is not yet adapted to support color mode), text rendering needs the support for styling, QDExtensions needs desperately GWorld routines, region blitter needs to be finished, etc. This is a short breakdown which is blocking what test apps:

  • Glider 4.0: Needs CopyMask, etc.
  • Indy 3: Needs TestDeviceAttribute, etc.
  • Siege of Darkwood: Needs FillCRgn, etc.
  • Crystal Quest: Needs blitter improvements, etc.
  • Railroad Tycoon: Needs font styling, CopyMask, etc.
  • Civilization: Needs GWorld routines
  • Wolfenstein 3D: Needs GWorld routines

When we get those tasks to advance, we should be able to run more color games in the near future. Stay tuned!

Full list of changes since last post

2020-03-18 03:28:52 +0200 • Implement colorizing srcBic pixel blitter
2020-03-18 03:27:51 +0200 • Implement AnimateEntry (used in PoP flash effect)
2020-03-18 02:29:02 +0200 • Tweak debug palette display
2020-03-18 02:27:32 +0200 • Implement SetEntryUsage (part of the PoP fixes)
2020-03-18 02:24:11 +0200 • No color translate if seeds match (fix PoP colors)
2020-03-18 02:19:39 +0200 • Implement AnimatePalette
2020-03-17 19:40:11 +0200 • Fix MakeITable buffer size bug at 5-bit resolution
2020-03-17 02:14:27 +0200 • Fix Entry2Index for animated palette entries
2020-03-17 01:09:16 +0200 • BIG PaletteMgr commit - first ActivatePalette pass
2020-03-17 01:05:39 +0200 • Implement (most of) SetEntries Color Manager call
2020-03-17 00:03:48 +0200 • Use TheGDevice defaults in MakeITable w/ zero args
2020-03-12 22:01:48 +0200 • 8bit clut debug overlay (to debug Palette Manager)
2020-03-12 21:56:06 +0200 • Implement (most of) PmForeColor/PmBackColor
2020-03-12 19:11:35 +0200 • Implement (most of) Entry2Index
2020-03-12 19:09:51 +0200 • Handle both index & sequence cluts in video driver
2020-03-12 17:25:54 +0200 • Add some missing color QD error numbers
2020-03-12 17:24:56 +0200 • Implement Index2Color in Color Manager
2020-03-11 03:19:45 +0200 • Update trap generator source CSV file too
2020-03-11 03:19:24 +0200 • Implement (most) of ActivatePalette (no updte yet)
2020-03-11 03:18:39 +0200 • Fix IODone invocation for SlotVideo DRVR driver
2020-03-11 03:17:46 +0200 • Fix byteswap bug in Color QD PortList insertion
2020-03-11 03:16:47 +0200 • Switch SetPalette to NSetPalette to use SInt16 arg
2020-03-11 03:16:25 +0200 • Implement (most) of SetPalette (no update yet)
2020-03-11 00:58:34 +0200 • Implement DisposePalette
2020-03-10 04:58:59 +0200 • Clear TmpResLoad at SetResLoad exit
2020-03-10 04:58:16 +0200 • Add empty stub for SetEntryUsage & AnimatePalette
2020-03-10 02:34:26 +0200 • Add gestalt function for 'vers' selector
2020-03-10 02:33:55 +0200 • Fix plotting of color icons in Dialogs
2020-03-10 02:32:49 +0200 • Add dummy SetEntries to Color Manager
2020-03-10 02:32:25 +0200 • Add PaletteDispatch & dummy Entry2Index & HasDepth
2020-03-10 01:52:01 +0200 • Add color QD old-style pattern patXor rect blitter
2020-03-10 01:51:09 +0200 • Add cmake JSON config for wolfenstein 3D
2020-03-10 01:10:52 +0200 • Update QDExtensions selector source csv too
2020-03-10 01:10:20 +0200 • Fix bug handling of version opcode in DrawPicture
2020-03-10 01:09:36 +0200 • Fix signatures of QDExtensions selectors
2020-03-10 01:08:09 +0200 • Add dummy SetCCursor for Glider 4 and Civilization
2020-03-10 01:07:09 +0200 • Add dummy HMGetHelpMenuHandle and Help Mgr module
2020-03-09 23:47:50 +0200 • Add $AB03 trap for 32-bit QuickDraw detection
2020-03-09 23:46:39 +0200 • Add cmake config for Color VETTE!
2020-03-09 22:21:59 +0200 • Partial DrawPicture bits opcode $9x color support
2020-03-09 22:13:15 +0200 • Add empty dummy MakeRGBPat placeholder
2020-03-08 21:32:21 +0200 • Make PICT opcodes $00 through $0B color-compatible
2020-03-08 21:29:45 +0200 • Fix WDEF 0 forecolor bug in monochrome mode
2020-03-08 03:03:28 +0200 • Support control colors in 'ictb' resouces also now
2020-03-08 03:00:51 +0200 • Add color QD Std/Fill/Frame/Paint/Erase/InvertOval
2020-03-08 02:41:23 +0200 • Init DrawPicture playback state for color ports
2020-03-08 02:39:59 +0200 • Fix invalid item index given for text colorization
2020-03-07 17:43:39 +0200 • Restore old colors after menu title draw
2020-03-07 17:14:45 +0200 • Load cctb in GetNewControl & call SetControlColor
2020-03-07 17:13:01 +0200 • Empty stubs for PmForeColor and PmBackColor
2020-03-07 16:48:05 +0200 • Fix swapped fore/background color in menu titles
2020-03-07 16:46:21 +0200 • Implement GetGDevice and SetGDevice
2020-03-07 16:24:30 +0200 • Dialog text & editfield 'ictb' color table support
2020-03-07 15:37:12 +0200 • Paint window background using 'wctb' wContentColor
2020-03-07 15:19:54 +0200 • Fix fallback of missing wctb entry to default wctb
2020-03-07 15:01:12 +0200 • Temporary placeholder for color desktop painter
2020-03-07 15:00:20 +0200 • Improve color QD CopyBits
2020-03-07 04:49:17 +0200 • Fix CopyBits case for WDEF 0 widgets
2020-03-07 04:02:30 +0200 • Makes text colorization work, but breaks CopyBits
2020-03-07 01:09:07 +0200 • Improve CDEF 0 colorQD support (cctb colorization)
2020-03-06 02:41:55 +0200 • Fix detection of color mode in WDEF 0
2020-03-06 01:57:51 +0200 • Draw colorized goAway box in WDEF 0
2020-03-06 01:44:48 +0200 • Implement partial CopyBits color QD compatibility
2020-03-06 01:03:42 +0200 • Improve WDEF 0 color compatibility (in progress)
2020-03-05 18:45:48 +0200 • First proto of color font renderer (srcOr mode)
2020-03-05 18:44:11 +0200 • Export QDRepeatPixels helper
2020-03-05 18:40:48 +0200 • Fix source scanline alignment bug in color stretch
2020-03-04 00:21:02 +0200 • Fix byte-swap bug in 1-to-32-bit pattern expansion
2020-02-26 22:52:01 +0200 • Extract B&W text renderer into a separate module
2020-02-26 22:49:52 +0200 • Move B&W rectangle blitter code to a new folder
2020-02-26 04:47:18 +0200 • Tweak RS local variables names to avoid conflicts
2020-02-26 04:46:38 +0200 • Abstract StdText for color QD & 255+ char support
2020-02-26 04:42:59 +0200 • Don't allocate storage for debug string in release

2 year anniversary of MACE! And some color progress & bonus

It is now two years since we started this project, and so far the progress is looking promising. At this point, it is good to take a brief overall look at where we are right now… so far, we have a lot of phase #1 goals accomplished:

  • Good enough 68000 emulation to run majority of games designed to use that CPU.
  • Majority of “classic” QuickDraw traps implemented to allow black & white games which needs them to work. Also hardware-level VIA page-swapping support for double-buffered games such as Dark Castle and Continuum.
  • Complete “.Sound” driver functionality, including ~99% coverage of low-level sound hardware emulation to allow games such as Dark Castle, Tetris and Pirates! to have working sound.
  • External file system emulation with HFS metadata support abstracted to ADF files, with almost all read/write operations tested working (except delete/rename, which have so far been rarely needed)
  • Basically implemented most of toolbox calls needed to, get out of the 87 test applications, 78 to work in at least somewhat usable way, and 43 to function near-perfectly.
  • Ability to run (or try running) the test applications/games as native OSX application bundles (and now with Windows support, also as windows EXE files), with full mouse/keyboard support, fullscreen/windowed and pixel-double support. Sound also mostly works but the SDL buffering needs some tweaking especially on windows…

As the toolbox is quite large, and there is a large number of traps/selectors which are rarely needed, and have not been encountered in the applications we have been testing vigorously. These APIs are still unimplemented, but they will be eventually added to the emulation. However, because these missing phase #1 features have such minor impact on most test applications, we also have started to work on some phase #2 features which are not only beneficial for a lot of current test suite, but which also will allow a huge number of new applications to be added to our tests:

  • 68020/030/040 emulation, which Pukka has already done a lot of progress on.
  • Color QuickDraw support, which was started after Christmas (more about that later in this post – very important for getting color games to work!)
  • Some preliminary progress on System 7.x APIs (FSSpec calls, Folder Manager, Time Manager, Script Manager, etc.).

Because of the fact that as we are implementing new features in a parallel fashion, we don’t have any fixed schedule for milestones. But realistically we expect to get a lot progress on the color support during the spring, which is the biggest bottleneck for getting much larger test application coverage. The downside of this is, however, that a “generic” emulator release will get delayed, because we want it to be as complete as possible, so that you won’t have to suffer from the incomplete features until we get everything polished. You can always follow the test application coverage (and overall progress) on our status page at https://mace.software/status/.

Color QuickDraw progress & first color game (somewhat) playable: KYE!

Since the previous post, majority of work as focused on getting source-mode blitting to work within the color hardware and Color QD API emulation. One of the easiest test cases for that purpose is a fun game called KYE, which was one of personal favorites of Toni on his LC II in early 90’s. The reason why this particular game is nicely suited for this early-stage testing is the fact that it uses mostly just PlotCIcon to draw all of its “sprite” graphics. Thanks to this, we did not have to work on a huge number of different calls at once, but were able to focus on getting that single call working. That way we could get something visible progress on the screen, instead of the invisible “under-the-hood” type of progress which has more impact on the long term.

For curiosity, below is a set of screenshots taken during the PlotCIcon development, which shows how the bugs were squished one by one until the rendering was finally okay:

Here’s a screenshot of latest stage of PlotCIcon functionality in KYE:

Level 3 of KYE

As you can see in the screenshot, icon rendering is working nicely, but text rendering is still completely missing. We also updated the WDEF 0 to have most of color support, so it uses now shading from the default ‘wctb’, leading to authentic System 7-style look and feel. Because of early stage of implementation, the color blitter has right now following limitations:

  • Blitter only works on “indexed” targets (1-8 bit pixmaps), i.e. not on “direct” (16/32-bit) screens
  • Only supports indexed sources too
  • Only simple srcCopy and srcOr modes supported (non-colorized)
  • No stretching support yet (only 1:1 scaling)
  • No arithmetic modes yet
  • Focus at this stage is on accuracy – that is, getting the output results to look exactly same as on the original, “real” Color QD – so performance is far from optimal for now. Leaves a lot of space for blitter optimization in future though…
  • Probably a lot of other use cases which I can’t recall right now…

Below is also a short video of level 2 gameplay:

Test run of level 2 of KYE (in 8-bit color mode)

Anniversary bonus! PT-109 gameplay video

To celebrate the two-year anniversary, we also recorded 90 minutes of PT-109 gameplay to show the current state of that game’s compatibility with M.A.C.E. below:

90 minutes of PT-109 campaign gameplay (16 missions)

This video shows what to expect when we get the “generic” emulator released some day in the future. For now, we can only share the video of this awesome game as it is sadly copyrighted – but we have a bunch of freely available games at our downloads page at https://mace.software/files for both Mac OS X and Windows 64-bit.

If you are interested in keeping up with our progress (now that we start the third year with full speed) you can follow this blog, or one or more of the following:

Full list of changes since last post

2020-02-23 22:32:57 +0200 • Add srcOr transfer mode to generic (=slow) blitter
2020-02-22 21:39:25 +0200 • Fix MOVE SR,-(A7) bug
2020-02-22 19:27:03 +0200 • Fix byteswap bug of ctSeed & tweak 2-&4- bit cluts
2020-02-22 18:51:04 +0200 • PenMode color QD compatibility
2020-02-22 18:50:30 +0200 • Add patXor mode for pixpat color rectangle blitter
2020-02-22 18:03:25 +0200 • Implement color QD versions of Get/SetPenState
2020-02-22 18:02:26 +0200 • Implement PenPixPat
2020-02-22 17:25:03 +0200 • Apply source mask to region scanlines when seeking
2020-02-22 17:24:06 +0200 • Fix align to destination in color srcCopy blitter
2020-02-22 17:21:57 +0200 • Fix b&w pixel data expansion being off by 32 bits
2020-02-22 17:19:46 +0200 • Add extra space after mask buffer for alignment
2020-02-22 17:18:43 +0200 • Keep rgn buffers 1-bit until destination expansion
2020-02-22 05:10:55 +0200 • Fix rowbytes calculation, cicns are now almost ok
2020-02-22 04:45:39 +0200 • Color blitter progress, KYE cicns almost visible
2020-02-22 02:33:59 +0200 • Region scanline to destination scaling functions
2020-02-21 22:50:17 +0200 • First successful pixel depth & clut translation
2020-02-21 22:17:11 +0200 • Get source & mask pixel data to translation buffer
2020-02-21 22:14:54 +0200 • Fix missing DerefHandle in PlotCIcon pixmap setup
2020-02-21 02:59:49 +0200 • More work on color blitter (PlotCIcon case init)
2020-02-18 01:02:13 +0200 • Progress on pixel translation in color src blitter
2020-02-17 17:05:51 +0200 • First colorized WDEF 0 parts (doc variant tested)
2020-02-17 17:03:33 +0200 • Fix missing deref of pixpat handle in color mapper
2020-02-17 16:18:49 +0200 • Fix assignment of WMgrCPort in InitWindows
2020-02-17 16:17:55 +0200 • Fix byteswap bug in PlotCIcon (b&w case detection)
2020-02-17 16:16:12 +0200 • Fix invalid portRect in InitCPort
2020-02-17 02:53:34 +0200 • Add RSAllocArray to allocate arrays in the scratch
2020-02-16 01:58:21 +0200 • Separate color QD CopyMask trap from "classic" one
2020-02-16 01:57:31 +0200 • Add dummy color stretch blitter & map use cases
2020-02-13 02:28:58 +0200 • Fix WindowManager colorQD CalcVis portBits mapping
2020-02-13 02:26:55 +0200 • Fix incorrect source rect passed in PlotCIcon
2020-02-13 02:01:51 +0200 • Half-dummy PlotCIcon, missing still src blitters
2020-02-13 02:00:49 +0200 • Fix window port bitmap size for color QD wCalcRgns
2020-02-12 02:24:35 +0200 • Fix MovePortTo (target rect did not map to pixmap)
2020-02-11 23:09:14 +0200 • Implement GetCIcon
2020-02-11 00:41:10 +0200 • Single-device colorQD DeviceLoop implementation
2020-02-11 00:29:28 +0200 • Improve WDEF 0 color compatibility for NewWindow
2020-02-11 00:20:50 +0200 • Fix default AuxWinHandle result of GetAuxWin trap
2020-02-10 23:46:56 +0200 • ColorQD version of BackPat
2020-02-10 21:25:14 +0200 • Fix wrong pattern given by QDDrawRegion to blitter
2020-02-10 06:25:48 +0200 • MovePortTo and PortSize colorQD compatibility
2020-02-10 05:37:21 +0200 • Fix colorQD multidevice StdArc drawing
2020-02-10 05:03:29 +0200 • Refactor 'MBDF' 0 for more color QD compatibility
2020-02-10 02:36:45 +0200 • Finish implementation of SetMCEntries
2020-02-10 02:16:13 +0200 • First (non-complete) InitPalettes pass
2020-02-10 02:15:26 +0200 • Add RSEnter/RSReturn pair to colorQD PenNormal
2020-02-10 02:14:46 +0200 • Fix RSEnter/RSReturn imbalance in QDDrawRegion
2020-02-10 02:14:11 +0200 • Tweak GestaltQDVersion selector result in color QD
2020-02-10 02:13:24 +0200 • Tweak default placeholder device mode
2020-02-09 23:05:22 +0200 • Tweak fake-ROM clut table seeds to match rsrc IDs
2020-02-09 03:38:12 +0200 • Implement NewPalette in Palette Manager
2020-02-09 02:33:13 +0200 • Implement GetNewPalette trap for Palette Manager
2020-02-08 17:09:07 +0200 • ColorQD compatible SetPortBits (no-op @CGrafPorts)
2020-02-08 17:08:02 +0200 • ColorQD SetOrigin (dereference CGrafPort pixmap)
2020-02-08 13:43:47 +0200 • Fix GrayRgn calculation in colorQD mode
2020-02-08 13:41:36 +0200 • Add ColorQD Region draw operations (non-masked)
2020-02-08 05:29:59 +0200 • Fix window manager clip bug in colorQD InitWindows
2020-02-08 05:27:57 +0200 • Fix detection of color port in ColorStretchBits
2020-02-08 04:54:31 +0200 • ColorQD Line and LineTo + line renderer
2020-02-08 02:42:58 +0200 • Implement ColorQD Move and MoveTo
2020-02-08 02:12:25 +0200 • ColorQD versions of PenNormal and PenPat
2020-02-08 02:02:08 +0200 • Fix CGrafPort/GrafPort target check for patterns
2020-02-08 02:00:44 +0200 • Start work on FillCRoundRect (PixPat expansion)
2020-02-08 00:01:45 +0200 • 8- & 16-bit scanline srcCopy & fix PixPat handling
2020-02-07 17:20:08 +0200 • 1, 2 & 4-bit scanline blitter and region expansion
2020-02-07 01:52:53 +0200 • Unify color QD and classic QD Arc draw traps
2020-02-07 01:44:43 +0200 • Generalize color QD pattern expansion for arcs too
2020-02-06 22:54:14 +0200 • Implement custom grafProcs support for Arc drawing
2020-02-06 22:36:47 +0200 • Refactor scanline blitters into separate module
2020-02-06 04:11:58 +0200 • Tweak base address and rowbytes for arc draw loop
2020-02-06 03:46:00 +0200 • Major region buffer refactor part #1 for color QD
2020-02-06 03:33:18 +0200 • Setup default mctb colors for drawing the menu bar
2020-02-03 22:58:37 +0200 • Implement GetMaskTable
2020-02-01 19:28:29 +0200 • Use OpenCPort instead of OpenPort in color QD init
2020-02-01 19:27:36 +0200 • Add RGBWhite/RGBBlack low-mem globals
2020-02-01 19:26:23 +0200 • GetForeColor/GetBackColor CGrafPort support
2020-02-01 19:14:41 +0200 • Implement GetMCEntry
2020-02-01 18:05:19 +0200 • Implement GetMaxDevice
2020-02-01 01:44:33 +0200 • Fix ShieldCursor/ShowCursor imbalance in QDDrawArc
2020-02-01 01:04:38 +0200 • Fix byteswap bug in rectangle region recording
2020-02-01 01:03:00 +0200 • Disable ROM write check for now, DungeonOfDoom fix