Monthly Archives: January 2021

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