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:
Score on 2015 MBP, Intel native
Score on M1, Rosetta Intel emulation
Score on M1, arm64 native
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.
Might & Magic III
Loom
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.
THINK Pascal LightsBug with variable list
THINK Pascal LightsBug with 68K registers
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
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!
MS-BASIC “Save” dialog
THINK Pascal “Add Files” dialog
TeachText “Open” dialog
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.
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: