Category Archives: 68K CPU

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

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

Side projects, fixes to full extension addressing mode & new video

The summer is soon over, so we are getting a bit more time to work again on MACE. There’s not much to report at this point, but here’s a short breakdown of the most important news

Side Projects

During August, Toni got did the first side project, which in this case was creating a hack to fix the graphics corruption issue in Vette! in color mode. More information about that is available on the new side projects page here:

mace.software/side-projects

The side projects will eventually also include other interesting tools, we will write more information about this when we have something more to show

Full extension addressing mode fixes

In this past weekend, we took a moment of time to refine and fix the 68020 full extension addressing mode support, which had some bugs in it. With these fixes, a number of games are now working better:

  • Loony Labyrinth now survives through first-time decompression & startup, but still fails after first two intro screens in some data validation
  • Escape Velocity no longer crashes in the main menu, and can actually enter the gameplay screen. There are however other issues that still need to be investigated and fixed (for example, the star-field appears distorted, and opening map crashes the game)
  • Prince of Persia 2 no longer crashes during startup, BUT because MakeFSSpec is not completely finished, it fails to resolve pathname to the data folder, causing the load to fail at the moment
  • F117A no longer crashes during intro, but plays all the FLVC animations nicely, and has (almost) completely functional menus. The in-game does not yet work, though, as the game uses ADB Manager calls to (most likely) interface joysticks and/or other input devices. It should be pretty trivial to add some placeholder trap handlers in the near future.

Other applications may also be positively affected, but those were the most notable ones we were able to briefly test during the weekend. Here are also some screenshots of the progress:

New video (Continuum)

We also took a moment to create a video of Continuum gameplay, which was long due since we got the game already working literally almost one year ago. The video also attempts to show the experimental “CRT simulation” rendering, which however is a bit butchered by the Youtube compression & video playback scaling (for best results, use either HD resolution in fullscreen, or SD with scaled-down player):

Finally, gameplay video of Continuum

This new rendering mode is not yet available in the downloadable applications, but will be added later as optional feature that can be activated by user preference.

Standard File Package

It’s been quite a while since last update, which is due to combination of us being busy real-life jobs, and focusing work on this project on a monolithic feature, which in this case is nothing less than getting the Standard File Package to work!

Features

This is list of the features which the M.A.C.E. Standard File Package emulation is currently capable of:

  • All 8 selectors for Pack3 (SFPutFile, SFGetFile, SFPPutFile, SFPGetFile, StandardPutFile, StandardGetFile, CustomPutFile, & CustomGetFile). The ones tested are highlighted, but others should work too.
  • Support for custom file dialogs (with assorted hacks to convert MFS-style dialogs, such as the “Save” dialog in MS-BASIC 2.00, to the new HFS-style format)
  • Supports both SFReply and StandardFileReply outputs
  • File listing using List Manager, which displays currently System 6-style SICNs, but with System 7.1+ style spacing (later expandable to use the real icons, when we get Desktop Manager interface)
  • Path popup menu, visually and functionally like on real System 7.x
  • Desktop folder support
  • Focus on selected items (including file list with highlight frame), alterable by mouse or tab key
  • Most of common SF key shortcuts: Clipboard shortcuts, Cmd+S (Save), Cmd+O (Open), Cmd+N (New folder), Cmd+D (Go to desktop), Cmd+Up (Go to parent), Cmd+Shift+Up (Go to root/desktop), Cmd+Down (Open folder), (Cmd+Left/Right to browse volumes not yet implemented)
  • Filename field input filtering (prevents “:” from being used in filenames, which is path separator). Also, copy-pasted filenames will be filtered with proper alert messages.
  • Most of SF items/hooks implemented:
    • Items: sfItemOpenButton, sfItemCancelButton, sfItemVolumeUser, sfItemEjectButton, sfItemDesktopButton, sfItemFileListUser, sfItemPopUpMenuUser, sfItemDividerLinePict, sfItemFileNameTextEdit, sfItemPromptStaticText, sfItemNewFolderUser,
    • Hooks: sfHookFirstCall, sfHookCharOffset, sfHookNullEvent, sfHookRebuildList, sfHookFolderPopUp, sfHookOpenFolder, sfHookLastCall, sfHookGoToDesktop
    • Not yet implemented: sfHookOpenAlias, sfHookGoToAliasTarget, sfHookGoToNextDrive, sfHookGoToPrevDrive, sfHookChangeSelection, sfHookSetActiveOffset
  • File type filtering supported, both by typeList and FileFilterProc
A GIF animation showing the progress done in the past month, from scratch to the latest version

Known issues

Although most of the Standard File Package is functional, and usable, there are still some issues left:

  • Because DirCreate is not yet implemented in NativeFS layer, FindFolder cannot create the Desktop Folder/Trash folders to the file system, thus at least Desktop Folder needs to exist to allow access to “Desktop” level in the SF dialogs. This also prevents “New folder” from actually creating the folders.
  • Eject button does not yet do anything, as the NativeFS volumes are non-ejectable
  • There are minor differences to real System 7.x style SF dialogs, for example with certain elements being a few pixels off their intended locations, and popup menu’s width not always expanding
  • Some custom dialogs don’t yet work exactly as they should, for example THINK Pascal 4.0 “Add files” dialog erases left edge of the applications own custom list located below the SF file list, and for some reason it allows attempts to add folders as source files…
  • Location of the SF dialog is sometimes not correct (for example, Railroad Tycoon’s “Save game” dialog is partially under the menu bar)
  • We cannot yet create app bundles for the currently working freeware/shareware applications that use StandardFile, because when sandboxed the bundle file system is read-only, and thus attempting to save anything to it would straight out fail. To work around this, we need to implement certain changes to the way file system in bundled applications is handled, but we are already working on that for the next release

Other improvements made for Standard File

There were a couple features that were implemented as part of Standard File Package implementation, some of which were necessary to make it work

NativeFS AVL tree balancing and iteration support

One important feature was the need for catalog iteration, which is used by Standard File dialogs to enumerate the files in current folder to be displayed in the file list. This allows for example GetCatInfo to use ioFDirIndex in the parameter block to index specific files inside given directory.

Also, this gave a good excuse to finally implement the actual AVL balancing algorithm in the NativeFS file system, which until now had behaved mostly as a dummy binary tree. Below is a screenshot of how the file system structure was changed by the balancing algorithm:

“Before” and “After” debug visualizations of the NativeFS binary tree data structure (click for larger view)

On the right-hand side, is the unbalanced “dummy” binary tree, and on left-hand side is the same file system, when using AVL balancing algorithm to do the insertions. The deepest nodes were reduced from, in this case, from way over 100+ key comparisons into a rough maximum of 10+.

Popup Menu Control

One important feature of the HFS-style Standard File dialogs is the navigation aid provided by the path popup menu. For this, the Popup Menu Control CDEF 63 was implemented. On real Macs, this was originally part of Communications Toolbox, before it was merged to the System 7.x at some point. The Standard File dialogs use only a subset of its features, but foundation for most use cases was built at the same time, so taking it into more common use should be quite easy. As it uses the Menu Manager’s PopUpMenuSelect trap call, the actual menu selection was already there.

One fun and tricky part though was the need to add MDEF “wrapper” for SF popup path menu, to ensure that the opened popup menu would never be narrower than width of the popup control. To do this, the control imitates how the real Macs did this by adding temporarily a MDEF “wrapper”, which injects modified menuWidth value to the menu after it receives a mSizeMsg message from the Menu Manager, thus modifying the resulting popup menu size.

Picture Button Control

The CDEF 61, picture button, was implemented just to allow adding the “New folder” button to the “put” dialogs. It is quite simple, at least in monochrome version, just drawing a PICT resource as content of a regular push button

Dialog Manager improvements

The StdFilter, which is also used by Standard File dialogs, was improved to add features used by it:

  • Outlining default button with FrameRoundRect
  • Handle “cancel” item’s shortcut key as escape/cmd+dot
  • Track cursor to turn it into i-beam over enabled textedit fields
  • Handle update events for default items

Also, the default shortcut keys (Cmd+X/C/V for Cut/Copy/Paste) were also implemented in DialogSelect trap.

Other news: 68020/68040 support

In other news, Pukka has also been busy adding 68020/68040 support, which includes:

  • Bitfield instructions (bfins, bfset, bftst, bfchg, bfclr, bfextu, bfffo)
  • cas2.b/w/l instruction
  • divs.l/divu.l 32-bit division instructions
  • move16 instruction for 68040
  • Disassembler support for the new and improved instructions
  • Various other improvements

Full list of changes since last post

2019-10-21 02:25:22 +0300 • GetResource falls back to TopMap if CurMap invalid
2019-10-20 23:00:18 +0300 • Fix byteswap bug in LDEF -4000 (item font & size) 
2019-10-19 21:44:23 +0300 • Update ArmorAlley JSON config, it now almost works
2019-10-19 02:18:39 +0300 • Fix _Allocate, use ioFRefNum/FCB to get the vcbPtr
2019-10-19 02:06:57 +0300 • Make MemoryManager allocation alignment adjustable
2019-10-19 01:54:24 +0300 • Fix AddResource bug, ResErr not cleared on success
2019-10-19 01:44:31 +0300 • Implemented RmveResource                          
2019-10-18 17:44:45 +0300 • Set ioFDirIndex for GetCatInfo in SF popup refresh
2019-10-18 17:21:28 +0300 • Desktop folder support improved in SFUpdateReply  
2019-10-18 17:08:07 +0300 • Show files in Desktop Folders on desktop          
2019-10-18 16:25:39 +0300 • Update StdFile Eject button enable/disable state  
2019-10-18 03:39:11 +0300 • Close app resource file on exit from emulator     
2019-10-18 03:07:05 +0300 • Draw CDEF 63 popup triangle & hack to resize menu 
2019-10-17 00:07:14 +0300 • Fix StdFile dirID byteswap bug for popup menu item
2019-10-17 00:05:13 +0300 • Rough proto of autoTrack to CDEF 63 popup tracking
2019-10-16 23:28:35 +0300 • Add sfHookFolderPopUp trigger & handler to StdFile
2019-10-16 23:27:14 +0300 • Implement testCntl in CDEF 63 (& refactor headers)
2019-10-16 22:47:54 +0300 • Merge branch 'master' of  
2019-10-16 22:47:13 +0300 • Fix popup menu creation (fix title & set icon cmd)
2019-10-16 22:45:09 +0300 • Work on CDEF 63 (draw menu in the control)        
2019-10-16 22:44:10 +0300 • Implement mDrawItemMsg in MDEF 0                  
2019-10-16 22:40:13 +0300 • fix initializing 68040 processor type and linkin..
2019-10-16 04:50:31 +0300 • Implement mCalcItemMsg in MDEF 0                  
2019-10-16 03:59:46 +0300 • Implement calculation of popup bounds in CDEF 63  
2019-10-16 03:58:56 +0300 • Make Mac_GetMenu visible in public headers        
2019-10-16 03:58:31 +0300 • Fix bugs in StdFile path popup folder iteration   
2019-10-15 02:25:13 +0300 • Work on CDEF 63 init, dispose and calc messages   
2019-10-14 21:40:29 +0300 • disassembler fixes and support for bit field ins..
2019-10-14 02:50:31 +0300 • Work on CDEF 63: Init StdFile dir popup contents  
2019-10-13 07:21:56 +0300 • Fix filename in GetFileInfo for ioFDirIndex > 0   
2019-10-12 23:57:53 +0300 • Fix old-style StdFile filelist bounds byteswap bug
2019-10-12 23:56:36 +0300 • Fix ioFDirIndex>0 case for GetFileInfo in NativeFS
2019-10-12 04:29:25 +0300 • "New folder" dialog added, and many fixes & tweaks
2019-10-12 02:09:45 +0300 • Cmd+Down in SF & fix list arrow when no selection 
2019-10-11 22:40:18 +0300 • Handle Cmd+S, Cmd+O, cmd+D and cmd+N in StdFile   
2019-10-11 22:21:15 +0300 • Fix crash in CDEF 61 dispCntl message handler     
2019-10-11 05:12:59 +0300 • Enable "new folder" button in StdFile put dialogs 
2019-10-11 05:11:37 +0300 • Implemented CDEF 61 ('PICT' button control for SF)
2019-10-11 02:44:50 +0300 • Don't try to go to the parent of Desktop          
2019-10-11 02:39:49 +0300 • Open parent with cmd+up, desktop with cmd+shift+up
2019-10-11 01:49:34 +0300 • Implement cut/copy/paste handling in DialogSelect 
2019-10-11 00:08:41 +0300 • Fix inverted zonecheck result in handle validation
2019-10-11 00:06:45 +0300 • Finish IsCmdChar implementation (& fix signature) 
2019-10-11 00:05:16 +0300 • Fix KCHR load from ROM (RomMapInsert & TmpResLoad)
2019-10-10 22:27:30 +0300 • Cache KCHR 0 in script manager expand mem globals 
2019-10-10 10:32:50 +0300 • Handle escape key in StdFilter                    
2019-10-10 10:32:26 +0300 • Add dummy IsCmdChar to ScriptUtil dispatcher      
2019-10-10 02:43:08 +0300 • Handle iBeam cursor in StdFilter null/updateEvents
2019-10-10 02:25:40 +0300 • Frame default button in StdFilter (also disabled) 
2019-10-10 01:53:25 +0300 • Handle desktop folder and related buttons         
2019-10-09 22:58:06 +0300 • Use new defines for FindFolder folders in StdFile 
2019-10-09 22:57:33 +0300 • Call DirCreate in FindFolder when createFolder set
2019-10-09 22:56:44 +0300 • Add dummy DirCreate placeholder to FSDispatch     
2019-10-09 22:55:41 +0300 • Merge branch 'master' of  
2019-10-09 22:55:37 +0300 • Fix font strike size to inRec size scale ratio    
2019-10-09 22:20:59 +0300 • disassembler support for move16                   
2019-10-09 21:54:33 +0300 • remove unused sr_bits field from instruction data 
2019-10-09 21:33:53 +0300 • finish implementing move16 instruction            
2019-10-09 21:26:06 +0300 • update xcode 6 project                            
2019-10-09 17:23:48 +0300 • Fix FindFolder memory corrupt (ioNamePtr not set) 
2019-10-09 11:16:53 +0300 • Fix byteswap bug in fld# type comparison          
2019-10-09 11:15:00 +0300 • Fix fld# search to work on non-system folder lists
2019-10-09 03:46:40 +0300 • Add linecount script                              
2019-10-09 03:46:28 +0300 • Add empty desktop/trash folders to THINK Pascal   
2019-10-09 03:32:46 +0300 • AliasManager added, to implement FindFolder for SF
2019-10-09 02:42:02 +0300 • Implemented HOpenResFile                          
2019-10-08 00:43:44 +0300 • Implement sfHookCharOffset and sHookRebuildList   
2019-10-07 21:56:21 +0300 • Found hidden ListManager selector, used by StdFile
2019-10-07 21:55:09 +0300 • Add PageUp/Down and Home/End keys to SDL keymapper
2019-10-07 04:57:10 +0300 • Use inThumb also to draw control on SetCtlMin/Max 
2019-10-07 04:55:48 +0300 • Fix wrong zero-case part code bug in HiliteControl
2019-10-07 03:16:46 +0300 • Fix ignore dot & '%'-prefix items in InsertResMenu
2019-10-07 02:19:28 +0300 • Fix memory leak in DrawPicture                    
2019-10-07 02:18:10 +0300 • Fix conversion of uncompressed pixmap data to b&w 
2019-10-06 23:37:38 +0300 • fix divs.l, start implementing move16 instruction 
2019-10-06 00:00:12 +0300 • allocate move16 instruction                       
2019-10-05 23:07:36 +0300 • fixes for divs.l/divu.l instruction               
2019-10-05 22:00:21 +0300 • Merge branch 'master' of  
2019-10-05 21:59:44 +0300 • implement chk2.b/w/l instructions                 
2019-10-05 21:57:57 +0300 • Merge branch 'master' of  
2019-10-05 21:57:22 +0300 • Fix resource name remove bug                      
2019-10-05 21:27:28 +0300 • implement cas2.w and cas2.l instructions          
2019-10-05 20:34:46 +0300 • finish cas.b/w/l instruction implementation       
2019-10-05 04:50:14 +0300 • Fix bug in FindWindow (theWindow not initialized) 
2019-10-05 04:10:11 +0300 • Merge branch 'master' of  
2019-10-05 00:11:35 +0300 • make bsr instruction branchless                   
2019-10-04 23:43:40 +0300 • THINK Pascal def missing from root CMakeLists.txt 
2019-10-04 23:25:35 +0300 • register variants for bfins, bfset and bftst      
2019-10-04 23:05:14 +0300 • remove unused c16 param from bfxxx_read/write     
2019-10-04 22:42:22 +0300 • use read_pc_immediate for bit field extension     
2019-10-04 22:30:25 +0300 • fixes for bit field instructions                  
2019-10-04 01:06:20 +0300 • Add THINK Pascal 4.0 test app JSON config to CMake
2019-10-04 01:06:00 +0300 • Implemented MaxSizeRsrc                           
2019-10-03 22:25:37 +0300 • Reinforce fake handle handling in memory manager  
2019-10-03 22:21:15 +0300 • bfchg, bfclr, bfext, bfextu and bfffo instructio..
2019-10-03 22:09:06 +0300 • Revert "bfchg, bfclr, bfext, bfextu and bfffo in..
2019-10-03 22:08:15 +0300 • bfchg, bfclr, bfext, bfextu and bfffo instructio..
2019-10-03 04:04:45 +0300 • Escape MacRoman filenames & avoid UTF8 conversions
2019-10-03 00:27:19 +0300 • SF key filtering (max length, skip ':' & CR, etc.)
2019-10-03 00:26:24 +0300 • Support "autoKey" in keyboard and platform modules
2019-10-02 02:55:34 +0300 • Handle tab key in SFDialogFilter                  
2019-10-02 02:14:00 +0300 • Tweak list ListManagerClickTrackProc visible size 
2019-10-02 02:00:26 +0300 • Fix missing sfHookLastCall set on SF dialog close 
2019-10-02 01:58:50 +0300 • Escape characters in NFS (and fix full-path bug)  
2019-10-02 00:08:29 +0300 • Adjust Art Class JSON to use 68020 machine config 
2019-10-02 00:07:57 +0300 • Update SF reply records during event loop         
2019-10-02 00:07:24 +0300 • Handle invalid names and replace in "save" dialogs
2019-10-02 00:05:56 +0300 • Reduce keyboard debug logging                     
2019-10-01 22:34:26 +0300 • Fix missing origName in SFPutFile                 
2019-10-01 22:06:24 +0300 • Merge branch 'master' of  
2019-10-01 22:06:17 +0300 • Tweak Gestalt and fix M68kHelper for 68020 support
2019-10-01 21:35:17 +0300 • kemu header cleanup                               
2019-10-01 21:33:14 +0300 • update xcode6 project                             
2019-10-01 20:38:00 +0300 • 020 bit field instructions, optimizations, some ..
2019-10-01 17:01:23 +0300 • First successful "open" from Standard File        
2019-10-01 15:37:53 +0300 • Missing header update for no-read privilege flag  
2019-10-01 15:37:03 +0300 • Add missing part of previous LayerDispatch fix    
2019-10-01 15:36:20 +0300 • Handle cancel button & implement closing dialogs  
2019-10-01 15:20:57 +0300 • Handle opening of folder in file list             
2019-10-01 15:20:00 +0300 • Don't hilite disabled items in file list lDrawMsg 
2019-10-01 14:58:06 +0300 • Error dialog support for Standard File            
2019-10-01 14:57:19 +0300 • Add some more TODOs to StdFilter proc             
2019-10-01 14:56:52 +0300 • Fix bug in AutoPositionWindow lcParentWindow case 
2019-10-01 13:42:47 +0300 • Fix redraw bug in file list item selection        
2019-10-01 13:40:58 +0300 • Detect when a folder is opened instead of file    
2019-10-01 13:39:08 +0300 • Fix accidental file list framing in "Get" dialogs 
2019-10-01 03:24:36 +0300 • Update save/open button state (and title)         
2019-10-01 01:21:11 +0300 • Add Desktop Folder and Trash to TeachText config  
2019-10-01 01:20:45 +0300 • Add empty folder creation support to make.cmake   
2019-10-01 01:06:51 +0300 • Go to parent folder by clicking volume name       
2019-09-30 02:06:23 +0300 • Handle more events in SF(update, activate & mouse)
2019-09-30 02:02:42 +0300 • Fix byteswap bug in FindDialogItem                
2019-09-29 03:39:31 +0300 • SF activation handling: set reply & frame filelist
2019-09-29 03:35:48 +0300 • Fix more maxIndex bugs in LGetSelect and LSearch  
2019-09-28 03:54:21 +0300 • Add file type filtering & call custom file filters
2019-09-28 03:53:38 +0300 • Fix bug in Standard File dialog autopositioning   
2019-09-28 03:28:31 +0300 • Fix SF special folder detection bytes-wap bug     
2019-09-28 03:27:37 +0300 • Fix ioDrDirID for folders in GetCatInfo           
2019-09-28 03:08:52 +0300 • Handle list clicking in SF dialog event handler   
2019-09-28 03:08:12 +0300 • Fix maxIndex case in LClick selection clearing    
2019-09-28 03:07:09 +0300 • Set mouseLoc in ListRec in LClick                 
2019-09-28 03:05:32 +0300 • Fix ioDirFlg setup in GetCatInfo                  
2019-09-28 01:59:31 +0300 • Re-enable EraseRect calls in SF dialog item redraw
2019-09-28 01:57:24 +0300 • Fix ioNamePtr handling in GetCatInfo              
2019-09-28 01:56:01 +0300 • Draw volume icon & name in Standard File dialogs  
2019-09-27 15:40:16 +0300 • Finalize LDEF -4000 drawing for standard file list
2019-09-27 15:38:52 +0300 • Fix file type mapping bugs in standard file pack  
2019-09-27 15:37:44 +0300 • Add Scratch20 low memory global                   
2019-09-27 04:21:58 +0300 • First real filelist shown in Standard File Dialogs
2019-09-26 22:56:17 +0300 • Add balancing algorithm to the AVL tree (+debug)  
2019-09-26 22:54:32 +0300 • Add missing header from previous commit           
2019-09-26 22:53:19 +0300 • Finish volume/directory setup in SF initialization
2019-09-26 11:30:42 +0300 • Reset to VCBQHdr after last VCB in SF volume scan 
2019-09-26 04:06:05 +0300 • Work on volume state initialization in SF package 
2019-09-26 04:03:16 +0300 • Tweak FMGetDrive to allow passing nil driverRefNum
2019-09-26 04:02:01 +0300 • Support GetVolInfo calls with drvNum as vRefNum   
2019-09-26 04:01:13 +0300 • Add four flag bytes in front of DrvQEl in NativeFS
2019-09-25 04:33:14 +0300 • Set default SF volume&folder to application folder
2019-09-25 04:11:00 +0300 • Add indexing to GetCatInfo + fetch real ioDrNmFls 
2019-09-25 04:09:38 +0300 • Add rough iteration support to file system AVLTree
2019-09-22 13:09:58 +0300 • Refresh file list in StdFile dialogs              
2019-09-22 05:17:32 +0300 • First StdFile dialogs visible, not yet functional 
2019-09-22 05:15:58 +0300 • Support opcodes 0x12, 0x13 and 0x14 in pictures   
2019-09-22 04:41:36 +0300 • More progress on StdFilePack                      
2019-09-22 04:39:36 +0300 • Minor List Manager fixes and tweaks               
2019-09-22 04:37:15 +0300 • Placeholder for popup CDEF (63)                   
2019-09-19 23:06:31 +0300 • Finalize CheckWindow selector for LayerDispatch   
2019-09-19 03:25:17 +0300 • More work on Standard File Package                
2019-09-19 03:23:39 +0300 • Add two new selectors to LayerDispatch for StdFile
2019-09-18 03:58:15 +0300 • Some work on Standard File Package                
2019-09-18 03:54:32 +0300 • Use _RelString in IUMagIDString for now           
2019-09-13 01:48:34 +0300 • Mac OS X 10.6.8 compatibility                     
2019-09-11 21:30:30 +0300 • Enable GetNextEvent CPU throttle for Arkanoid     
2019-09-11 18:25:41 +0300 • Add Crystal Quest and Armor Alley test apps       
2019-09-09 01:31:04 +0300 • Bump up runtime version for new bundles           
2019-09-09 00:58:48 +0300 • Tweak IAGO cmake config                           
2019-09-07 14:04:32 +0300 • Add two more test app configs, IAGO and EveryMan 1
2019-09-07 14:04:02 +0300 • Add substitution for missing fonts in Font Manager

A bit of nVIR-A experience, and a new test application

Infection compatibility

We had this week a rather interesting thing happen by accident, which was rather unusual: While trying out a couple potential test applications with the emulator, we ran into an application which was infected by nVIR A type virus ( https://en.wikipedia.org/wiki/NVIR ). What makes this interesting, is that it apparently was able to infect the System file of that application’s bundle, as we now have near-complete resource write support:

Above is partial output of the System file’s resource map debug dump (and Rezilla screenshot of infected System file), and the ‘nVIR’ and ‘INIT’ resources were actually written into the System file by the virus in infected application – and the system resource map seemed to be (mostly) still functional! I only found this out because a bug in resource writing corrupted Geneva font, causing the infected application to crash. A kind of controversial achievement, having good enough compatibility for even viruses to work in the toolbox emulation…

One of the positive sides of the current per-application bundling of files as isolated file systems, is that the infection never was able to break out of the application bundle. We have also scrubbed through all the disk images and Mac files downloaded we use for development and testing, to make sure there will not be any risk of infection at later time (and run Disinfectant on the source Macs/emulators regularly). These viruses are ancient, but can awake up at any time it seems…

New test application: IAGO

After we got the infection sorted out and everything back to normal, we experimented with a couple of new test applications, and found out that IAGO, which is a public domain game written by David Reed in 1984.

We were able to identify one bug in ROXLI.L instruction, which caused the game timer to not advance correctly. After it was fixed, the game works as smoothly as it does on a (fast) real Macs. It is now also available for testing as application bundle in the downloads section.

Performance improvements and menu stuff

The past few weeks have mostly gone to improving performance of the runtime environment. Although all the apps have been running smoothly without any issues, there was not much focus on improving the actual CPU usage of the host system.

Unlike hardware-based emulators such as Mini vMac, where everything including applications, ROM, and system software run on 68K, in M.A.C.E. there is distinct separation of execution between 68K based code, and the Toolbox code written in native C. This creates some minor issues with managing performance, as especially in regards of early software – QuickDraw routines would be much slower on real 68000 hardware, and thus games depending on certain 68000 execution speed would experience certain slowdown of using those QuickDraw (and other Toolbox) routines.

However, in M.A.C.E., the native code always runs at full speed, and those expectations break down as experienced in Stunt Copter, Zero Gravity, Harrier Strike Mission II, Brickles among some other applications. To mitigate this, there is an artificial slowdown that the emulator can optionally enable delay throttle in GetNextEvent, which we have so far used to make most of the aforementioned applications usable.

68K emulation throttle

Pukka added an experimental throttle to the 68K emulator, which attempts to slow down applications which do for example busy-looping and polling of TickCount to perform timing. In the old non-multithreading MacOS, this kind of timing was pretty common especially in games that required precise control on the CPU resources. This should in future help CPU usage in programs heavy on 68K code in game loops, such as Dark Castle and Apache Strike. This however does not help the cases which rely a lot on Toolbox, such as the applications which benefit of the GetNextEvent delay throttle.

SystemTask and execution yielding in Toolbox routines

As some may remember, when Apple transitioned from Mac OS 9 to X, one way to yield execution was to add SystemTask calls to blocking loops (in cases where WaitNextEvent would not be desirable). As the Toolbox in M.A.C.E. is completely implemented in C, we have the power to choose yielding strategy ourself, and for that we are experimenting at the moment with very small delays of 1 millisecond on each call to SystemTask, and any other busy-looping toolbox routines, which include:

  • MenuSelect and PopUpMenuSelect
  • TrackControl and DragControl
  • DragTheRgn (affecting DragGrayRgn and DragWindow), GrowWindow and TrackBox
  • TEClick
  • LClick
  • Delay (it had earlier implementation used by the GetNextEvent hack, but was implemented in a rather stupid way which ended up as a busy-loop on host CPU…)
  • File Manager synchronous command queueing
  • Device Manager synchronous command execution, and driver close

Video rendering and dirty-rectangle detection

Another optimization feature was the addition of detection of video memory “dirty rectangles”, which define which areas of video memory have changed, so that only those would need to be drawn to the screen. This optimization is being experimented especially to improve the future fullscreen and pixeldouble modes (which are not yet enabled due to requiring still some work), and depending on the machine and application, there is varying degree of performance improvement, but not very much (which is to be expected as the 512×342 screen with 1-bit colors does not require a lot of the CPU in regards of pixel format expansion and SDL surface updates).

With these changes, we got CPU usage of 100% to drop to around 7-10% on a Mid-2010 Mac Pro, and 9-12% on 2015 MacBook Pro of the currently bundled applications. Of course, some test applications we are experimenting with still require further work to gain these benefits, but this should help at least keep those fans more quiet on MacBook computers 🙂

We have also updated the test application bundles with these new optimizations in the downloads section on this blog.

Hierarhical menus and PopUpMenuSelect

In addition to performance optimizations, we also finally added the hierarhical menu and popup menu support which was for a long time waited to make especially Railroad Tycoon way more playable.

There was a bit of tweaking, bug fixing, polishing, more bug fixing and tweaking to get those two features to work, but now they appear to work exactly like on a real Mac (timing, positioning, mouse tracking behaviour, screen buffer saving, etc). Sadly we don’t have yet any bundled test applications to demonstrate this, but at least the applications we are using internally all work perfectly.

These are again another major features which gets us closer to the “general classic replacement” release, although there is still lot of work needed to get us there. The progress is however very promising at current pace.

Full list of changes since last post

2019-09-05 01:47:24 +0300 • Add dirty rectangle visualization to debug build 
2019-09-05 00:35:24 +0300 • Update runtime version in cmake script 
2019-09-04 12:44:03 +0300 • Fix offset of minimum-intersection dirty-rectangle 
2019-09-04 03:38:02 +0300 • Finally fix that darn StretchBits… 
2019-09-04 03:14:55 +0300 • Improved, faster dirty rectangles with bit-o-magic 
2019-09-03 22:35:25 +0300 • Implement GetItemIcon and SetItemIcon traps 
2019-09-03 22:21:14 +0300 • Add pixel-double support also to windowed mode 
2019-09-03 22:20:11 +0300 • Fix uninitialized mouse loc in PopUpMenuSelect 
2019-09-03 01:27:55 +0300 • Implement prototype dirty-rectangle video renderer 
2019-09-02 22:42:44 +0300 • Add EnvRunBackgroundTasksReleaseCPULockWithYield 
2019-09-02 20:43:19 +0300 • Fix hit-testing of hierarchical menus in MBDF 
2019-08-30 22:31:02 +0300 • Fix mouse button check in relative mouse mode 
2019-08-30 03:13:25 +0300 • Update trap list XLS/CSV 
2019-08-30 03:06:21 +0300 • Implement basic non-styled TEPaste 
2019-08-30 02:56:58 +0300 • Fix two masking bugs in CopyMask 
2019-08-30 02:07:25 +0300 • Implement pic opcodes 0x1A & 0x1B (RGBColor fg/bg) 
2019-08-30 02:04:08 +0300 • Fix popup menu crash 
2019-08-30 01:13:42 +0300 • Initial fullscreen (and pixel-double) support 
2019-08-28 22:25:51 +0300 • Enable delay hack in Brickles test app 
2019-08-28 22:25:34 +0300 • Add execution yield for 1ms to SystemTask 
2019-08-28 21:54:36 +0300 • Fix the earlier video update limiter adjustment 
2019-08-28 13:31:18 +0300 • Experimental change to lower CPU usage, has issues 
2019-08-27 23:54:36 +0300 • usleep logic to m68k helper 
2019-08-27 05:04:18 +0300 • First proto of PopupMenuSelect, has bugs 
2019-08-27 00:32:21 +0300 • Merge branch 'master' of  
2019-08-27 00:32:17 +0300 • Also handle shortcut keys for submenus in _MenuKey 
2019-08-26 21:46:33 +0300 • Merge branch 'master' of  
2019-08-26 21:45:28 +0300 • revert unwanted modification 
2019-08-26 17:02:42 +0300 • Fix left-hand side hierarchical menu handling 
2019-08-26 03:13:36 +0300 • Fix icon alignment in default MDEF 0 item drawing 
2019-08-26 02:30:48 +0300 • Merge branch 'master' of  
2019-08-26 02:30:42 +0300 • Add "bermuda triangle" to hierarchical menus 
2019-08-25 20:36:24 +0300 • move pc increment away from instructions + some optimizations 
2019-08-24 23:38:22 +0300 • Update instructions.c 
2019-08-24 23:17:34 +0300 • some optimizations and ea macros 
2019-08-24 15:33:05 +0300 • Improve hierarchical menu tracking 
2019-08-24 01:12:35 +0300 • Fix GetItemMark/Cmd/Style result byteswap bug 
2019-08-23 19:41:36 +0300 • Fix drawing of hierarchical menu items 
2019-08-23 04:36:38 +0300 • Merge branch 'master' of  
2019-08-23 04:35:57 +0300 • First rough proto of hierarhical menu support 
2019-08-22 21:51:52 +0300 • fix cmpm instruction with FAST_ADDRESSING 
2019-08-21 00:30:28 +0300 • Add cmake config for Brickles, which was missing 
2019-08-20 02:31:00 +0300 • Use rb fallback in NFSOpenFileHook is r+b fails 

A LOT of fixes, improvements and new test applications

It’s now approximately one month since last update, and a lot of “under the hood” type progress has been made.

M68K Tester and 68K bug fixes

One major task we had on roadmap was attempting to see how we could integrate Pukka’s emulator core with the amazing M68K Emulator Testsuite (by Gwenolé Beauchesne and Ray Arachelian, archived at this URL: http://web.archive.org/web/20090417202939/http://gwenole.beauchesne.info/en/projects/68ktester ). After holidays, Pukka was able to get the integration done, and we found a bunch of hard-to-find CPU bugs thanks to it:

Even though a lot of bugs were fixed, there are still test cases which do not pass, and will be fixed soon. However, with the fixes already done to the bugs that were found thanks to the test suite, Dark Castle and Beyond Dark Castle appear to be stable in rooms that used to crash before:

New relative mouse mode

A long-time task that has been waiting implementation has been the relative mouse mode, in which M.A.C.E. captures mouse cursor entirely, and instead of using the absolute position given by the host operation system, calculates mouse motion itself using the mouse delta vectors. This both prevents stray clicks outside emulated desktop window, and allows long delta swipes such as required to control helicopter in Apache Strike. As a result of this, Apache Strike can now be played, as previously it would immediately crash into the wall – and Pirates! no longer hangs in the swordfight at beginning – both which depended on certain low-level mouse low memory globals being emulated correctly:

Another fun feature which we added to complement the relative mouse mode as experimenting with game controller input API of SDL, which took about 30 minutes to do and works quite OK as seen on this video:

Apache Strike controlled using USB gamepad

Another issue that was fixed was missed clicks problem with “Tap to Click” MacBooks, which now should generate mouseDown events correctly.

Currently the cursor itself is still displayed using SDL “hardware” cursor API, but with the recent changes adding support for software cursor should not be a big problem – One that might be required to have decent cursor is certain games, where the cursor visibility depends on the cursor having ability to “invert” depending on underlaying graphics (such as the crosshair on black background in lemmings), which the SDL hardware cursor does not support.

Keyboard text input rewritten with proper character mapping

In first iteration of keyboard handler, we only had scancode support with minimal MacRoman mapping (without modifiers), which although was working for the simple use cases, did not allow flexibility required for example to enter upper-case letters.

For second iteration, we attempted to utilize host operating system keyboard layout mapping by using SDL text input API, and although it worked nicely for TextEdit text input, broke command keys and other things (such as Dark Castle & Lode Runner controls) horribly.

For the latest, third iteration, we went back to scancode based input, but instead are simulating the exactly same type KCHR scancode to MacRoman mapping like on real Macs. This allows every key to work properly in text editing, game input and menu shortcut etc, but one downside is that for international layouts we will need to have separate KCHR resources, currently only having U.S. as default layout. However, as “dead keys” are also working, typing special characters such as accents, umlauts, etc is working nicely even on this layout.

ResEdit bug “treasure chest”

ResEdit proved to be a real “treasure chest” of bugs and improvements, as it used literally every possible List Manager routine, and it also surfaced some unexpected bugs in other places such as TextEdit, Dialog Manager, QuickDraw, and other already heavily used toolbox traps.

Some major improvements found through testing ResEdit:

  • Most of List Manager calls were implemented, including resizing lists, deleting rows/columns, searching data. Also some bugs were fixed, such as corruption of data offsets in some cases, etc.
  • Dialog manager edit field handling had a number of bugs, which surfaced in the DLOG editor, and there also were bugs in item hiding/showing which were also manifesting in Civilization.
  • TextEdit had some bugs in the MixedMode handling of special case calling conventions, which caused crash in the hex editor. After fixing them, not only the hex editor works, but also MacPascal editing bugs were fixed, as it also used custom TEDoText hooks.
  • The PACK 1 (“BitEdit”) package in ResEdit surface a couple QuickDraw bugs, such as random SeedFill memory corruption (using the paint bucket tool) and StretchBits memory corruption. These also make MacPaint more stable, which was also suffering from the SeedFill bug.

Some of these fixes had quite universal effects, such as improving the previously buggy behaviour of Lists and TextEdit in HyperCard 1.x:

Other improvements

  • Text scaling and measuring had some bugs, which were fixed so that MacPaint and Macwrite can display text of all sizes, faces and styles.
  • MacWrite now works, at least kind of…all other edition options are working (styling, page breaks, font sizes, fonts, rulers, etc), except adding newline using enter/return causes text to corrupt.
  • As the region corruption bug in polygon rendering was fixed, PT-109 appears now the be completely stable.
  • With “dummy” SetPalette trap implemented, Railroad Tycoon is now able to proceed past first “End of Fiscal Period” report
  • Scrollbar (CDEF 1) implementation (and related Control Manager TrackControl/DragControl stuff) were finally finished, so the indicator thumb dragging works now.
  • Prototype of font fractional width support added, only test case for this is curently Photoshop, which enables them. Right now only FOND width tables are supported, but extended width tables could be easily added as soon as some application needs them.

New test applications added

Also, we have now finally two new test app bundles that should be complete enough for trying out. These are ZeroGravity by Duane Blehm, and Blob Manager Demo by Paul DuBois. They are now available for trying out in the Downloads section.

Additionally, the old test application bundles have been updated with the new M.A.C.E. runtime, which includes all the bug fixes and improvements done since their last update. For example, Stunt Copter uses now the new relative mouse mode, and all apps have been updated to support the “Tap to Click” trackpad mode on MacBooks.

Full list of changes since last post

There are too many changes to detail in a single post, so as a new feature below is the version control log of all changes made since last update:

2019-08-19 22:54:49 +0300 • Add SetDialogDefaultItem/CancelItem/TracksCursor 
2019-08-19 22:47:32 +0300 • Tweak TrackControl and LClick delay to 8 ticks 
2019-08-19 18:15:47 +0300 • Save alert default item also in the DialogRecord 
2019-08-19 16:23:03 +0300 • Partial support for default dialog StdFilter proc 
2019-08-19 07:03:12 +0300 • Bumb the M.A.C.E. version number & use current date 
2019-08-19 07:02:52 +0300 • Replace printfs with log, and add a few DEBUG #ifs 
2019-08-19 07:00:17 +0300 • Fix the SDL window title for now by using EnvStartupFile 
2019-08-19 06:59:57 +0300 • Tweak Blob Mgr Demo and ZeroGravity for release 
2019-08-19 06:00:30 +0300 • Work on FOND widthtable and fractional size support 
2019-08-17 03:17:27 +0300 • Work a little on resource map "shadowing" handling 
2019-08-17 03:04:32 +0300 • Fix WaitMouseUp to not return 1 extra "down" state 
2019-08-17 02:23:40 +0300 • Fix SeedFill random memory corruption case 
2019-08-15 23:36:01 +0300 • Merge branch 'master' of  
2019-08-15 23:35:56 +0300 • Fix TextEdit cursor right-side clamping 
2019-08-15 22:55:05 +0300 • add xcode 6 project 
2019-08-15 22:43:06 +0300 • Fix incorrect register usage in TEDoText overrides 
2019-08-15 21:21:29 +0300 • Fix StretchBits stack buffer overrun 
2019-08-14 23:46:30 +0300 • Fix scrollbar redraw bug in List Manager 
2019-08-14 23:25:48 +0300 • SetPalette classic-QD dummy trap 
2019-08-14 21:44:36 +0300 • Fix LSetSelect highlight bugs 
2019-08-14 19:28:32 +0300 • Fix lNoNilHilite flag handling in LSetSelect 
2019-08-13 03:14:24 +0300 • Fix value clamping in Control Manager 
2019-08-13 03:11:51 +0300 • Tweak CloseWD stub to not crash 
2019-08-13 03:11:28 +0300 • Implement LClrCell and proto of LDelRow/LDelColumn 
2019-08-12 21:10:26 +0300 • Fix a couple byteswap bugs in lists (selection) 
2019-08-12 17:39:11 +0300 • Fix one-cell delta calculation in list pageup/down 
2019-08-12 15:03:44 +0300 • Fix maxIndex bug in LNew 
2019-08-12 02:34:18 +0300 • List Manager LSize implementation 
2019-08-11 05:12:39 +0300 • Finished LAutoScroll, another easy one for ResEdit 
2019-08-11 04:56:40 +0300 • Implemented C_LFind, was simpler than I thought… 
2019-08-11 04:46:28 +0300 • Finish LNextCell trap, work on LClick multiselect 
2019-08-11 02:18:20 +0300 • Implement C_LClick scroll indicator handling 
2019-08-11 02:06:55 +0300 • Fix dividend overflow in scrollbar CDEF 1 rounding 
2019-08-11 01:43:52 +0300 • Implement DragControl, finish TrackControl & CDEF1 
2019-08-10 03:41:37 +0300 • Fix caps lock usage in SDL key event handler 
2019-08-10 02:01:37 +0300 • SDL gamecontroller support "hack" to Apache Strike 
2019-08-09 20:45:44 +0300 • Add FSpOpenDF, FSpCreate, FSpDelete, FSpGetInfo, FSpRename & (dummy) _Rename 
2019-08-09 18:08:02 +0300 • Hacked procinfo for UIMagIDString call in LSearch 
2019-08-09 03:28:00 +0300 • Fix buffer overflow in GetVolParms 
2019-08-09 02:42:54 +0300 • Added dummy GetVolParms selector to _FSDispatch 
2019-08-09 02:00:31 +0300 • Add Jigsaw test app 
2019-08-09 02:00:10 +0300 • Implement LSearch, and (dummy stub) IUMagIDString 
2019-08-09 01:58:42 +0300 • Implemented 1-bit NewGWorld in QDExtensions 
2019-08-08 17:10:34 +0300 • Fix allocation of key state buffer 
2019-08-08 02:45:45 +0300 • C_KeyTranslate Deadkey support + fix mac scancodes 
2019-08-07 18:30:41 +0300 • Fix dialog edit field handling 
2019-08-07 12:13:26 +0300 • Fix picture recording of port fgColor/bkColor 
2019-08-07 04:49:10 +0300 • Add git log generator, for fun 🙂 
2019-08-07 04:21:32 +0300 • Tweak type of ScrapSize in low memory 
2019-08-07 04:21:04 +0300 • Fix fromMode handling in Picture Line recording 
2019-08-07 04:19:58 +0300 • Fix picture line recording Point saving 
2019-08-07 04:17:59 +0300 • Fix Hide/Show dialog item bounds calculation 
2019-08-07 04:15:36 +0300 • Prevent editfield citation replacements in dialogs 
2019-08-06 19:43:28 +0300 • Fix Scrap Manager bugs 
2019-08-06 19:41:31 +0300 • Clean up Mouse module a bit 
2019-08-06 19:07:03 +0300 • Fix bug in DefaultShowCursor 
2019-08-06 16:38:47 +0300 • Un-obscure cursor before _MDrawCursor in CrsrTask 
2019-08-06 01:42:37 +0300 • Make phase-shift adjustment configurable 
2019-08-06 00:20:31 +0300 • Move audio phase-shift from RAM to ClassicSound 
2019-08-06 00:17:50 +0300 • Disable VM_MAP and reverse-page mapping 
2019-08-05 20:44:39 +0300 • Disable a couple of mouse debug log calls 
2019-08-05 00:10:21 +0300 • Updated some test apps with relative mouse mode 
2019-08-05 00:09:22 +0300 • Refactor cursor to support relative motion mode 
2019-08-04 00:30:38 +0300 • fix abcd, partially fix sbcd instruction 
2019-08-03 23:20:09 +0300 • fix zero status for subx.b/w/l instruction 
2019-08-03 00:40:07 +0300 • fix add.b, addx.b/w/l and negx.b/w/l status bits 
2019-08-03 00:40:01 +0300 • Merge branch 'master' of  
2019-08-02 00:05:57 +0300 • Fix TEIdle blinker 
2019-08-01 23:10:07 +0300 • Implement LLastClick and tweak trap glue generator 
2019-08-01 16:03:22 +0300 • Disable the extra log debug trace of heap compact 
2019-08-01 16:02:28 +0300 • Reduce logging in MixedMode calls 
2019-08-01 16:01:44 +0300 • Fix size bug in WriteResource 
2019-08-01 16:00:47 +0300 • Fix resProtected flag check in ChangedResource 
2019-08-01 15:58:51 +0300 • Fix dialog edit field disabled check + others 
2019-08-01 05:19:49 +0300 • Add missing lowmem changes for CurActivate bug fix 
2019-08-01 05:19:04 +0300 • Work on KeyTranslate KCHR mapping (fix keyboard) 
2019-07-31 01:21:08 +0300 • Add MacConcentration test app 
2019-07-31 01:20:39 +0300 • Implement FADDD & fix major 64-bit float SANE bug 
2019-07-31 01:08:21 +0300 • fix lsl and lsr instruction for shift > 31 
2019-07-30 22:53:46 +0300 • fixes for m68k tester 
2019-07-30 21:50:19 +0300 • move x68k xcode6 project to x68k root 
2019-07-30 21:48:42 +0300 • add m68k tester 
2019-07-30 21:46:25 +0300 • make kemu lib c++ compatible 
2019-07-29 15:51:21 +0300 • Tweak GunShy config to use version 1.3 
2019-07-28 04:54:27 +0300 • Fix window activation handling 
2019-07-27 04:36:27 +0300 • Fix GetFontInfo for scaled fonts 
2019-07-27 04:22:21 +0300 • Fix bug in fast-case of text blitter 
2019-07-27 02:13:56 +0300 • Set Lo3Bytes lowmem global properly 
2019-07-27 02:12:01 +0300 • Implemented ReadDateTime and (dummy) SetDateTime 
2019-07-27 01:26:28 +0300 • Fix LActivate 
2019-07-27 00:46:46 +0300 • Fix cursor leak 
2019-07-26 18:29:56 +0300 • Tweak InitResources to be (again) re-callable 
2019-07-26 17:32:20 +0300 • Fix UPP ProcInfo of DABeeper callback 
2019-07-26 15:46:55 +0300 • Implemented LActivate selector in List Manager 
2019-07-26 05:45:33 +0300 • Fix bug in resource manager name remove code 
2019-07-26 05:44:44 +0300 • Add Glider4 test app 
2019-07-26 05:44:24 +0300 • Fix possible bug in SetVol NFS handler 
2019-07-26 05:43:07 +0300 • Setup CurrentA5 during boot stage 2 for INITs 
2019-07-26 02:55:49 +0300 • Re-fix PurgeSpace to also return correct D0 
2019-07-26 01:52:59 +0300 • Optimize FramePolygon case 
2019-07-26 01:43:57 +0300 • Actually update the existing ADF header 
2019-07-26 01:36:18 +0300 • Finish SetFileinfo handler in NativeFS 
2019-07-26 01:35:28 +0300 • Fix region corruption bug in polygon drawing 
2019-07-25 23:16:56 +0300 • Fix MapRgn duplicate inversion point bug 
2019-07-25 23:07:21 +0300 • Fix MapPt negativity check 
2019-07-25 22:08:06 +0300 • Fix size of ScriptUtil selector 
2019-07-25 22:02:10 +0300 • Fix edge case bug in UnpackBits 
2019-07-25 21:02:00 +0300 • Fix ADF file create bug, mixed up rsrc and data 
2019-07-25 19:27:32 +0300 • Also reserve space for mapping in the stack after packBuffer 

Remote Debugging (et al)

Today Pukka added remote control interface to the 68k debugger. Earlier the debugger commands had to be entered in the Xcode console. From now on, any device with Telnet (with ANSI escape code support) can be used for debugging the emulated programs even from the other side of the world.

Stunt Copter debugged remotely

In other news, Pukka’s 68k debugger also can now be compiled and run on his Rasperry Pi using manually created makefile:

68k debugger test on Rasperry Pi 3 model B

Meanwhile, I rewrote the VBL interrupt handling code, so now it handles all edge cases and works reliably. Also, I started work on restructuring project for first demo build:

  • Started work on Haiku GCC compatibility
  • Enforced all warnings on (with “warnings as errors” option) – which already surfaced one region blitter bug that was causing graphic corruption in Pipe Dream and got fixed
  • Include SFTP server as source/destination storage in build process
  • Started investigating and experimenting CMake as a one potential build generation tool