Monthly Archives: June 2021

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