Announcing ARM64 Mac (aka Apple Silicon Mac) support!
First of all I'd like to thank StLouisCPhT for testing all the changes I made to try and get melonDS to work on ARM64 Macs. Without them, this wouldn't be possible as I don't have an ARM64 Mac (I don't have any Mac at all, however x86-64 macOS can be run in VMs). I would also like to thank Generic (aka RSDuck) for helping me out with JIT issues.

This started when a user named "Joel" (now StLouisCPhT) commented on my earlier post about compiling melonDS for ARM64 Macs. We took this to Private Messages on the forum board, and we were making progress slowly, but surely.

Here's a quick overview of the things that were needed for melonDS to run on ARM64 Macs (if you want to download the beta, scroll to the bottom of this post).

- The JIT compiler
The first issue was adding a way to get the Program Counter on ARM64 Macs. This was easy, all it needed was an ifdef to use "uc_mcontext->__ss.__pc".
The second issue was that Apple introduced W^X for JIT memory. This meant that we can only have Read-Write and Read-Execute permissions at one time, and this could be toggled by setting "pthread_jit_write_protect_np" to either true or false. This command had to be added to some location, otherwise the JIT would crash when trying to run something.

There was also another strange issue when some lines would cause the JIT to crash.
   for (int i = 0; i < (JitMemMainSize + JitMemSecondarySize) / 4; i++)
       *(((u32*)GetRWPtr()) + i) = brk_0;
Generic (aka RSDuck) told me that this was for adding breakpoint instructions to the JIT buffer. StLouisCPhT and I tried various things, but to no avail. However, once the changes were rebased on master, it seemed to work fine....

- Microphone
This wasn't affecting just ARM64 Macs, but I'll add it anyway.
We got a bug report on GitHub for the microphone not working on macOS. The solution? Add the "NSMicrophoneUsageDescription" key in the plist file, otherwise macOS would not ask for microphone access.

- Known Issues

* The fastmem checkbox is disabled: This is intentional, I cannot get fastmem to work on either x86-64 Macs or ARM64 Macs.
* Local Multiplayer doesn't work by running more than one instance on the same Mac: This needs to be investigated, although Local Multiplayer doesn't have the best support yet. It seems to work by running two copies of melonDS on different Macs though.


Well, that's all.
The beta builds for ARM64 include the libraries bundled, so you won't have to install them separately.

This build is outdated - see Downloads
melonDS 0.9.1 beta for ARM64 macOS
(For future reference, this build is based off commit 2c2e868.)
WhoNeedsAUserName says:
Mar 23rd 2021
This is cool
Admiral H. Curtiss says:
Mar 24th 2021
That highlighted piece of code looks like undefined behavior to me, so it's not surprising it could cause seemingly random crashes. Compare with ARM64XEmitter::Write32() which uses std::memcpy() instead to do ostensibly the same thing, but is allowed. If you rewrite that line as `std::memcpy(GetRWPtr() + i * 4, &brk_0, 4)` it should be safe.
Jinkson says:
Mar 29th 2021
I hope these improvements pave the way to higher performance and compatibility on ARM64 devices like the Raspberry Pi or RK3326 handheld. Right now, Drastic has that market cornered.
Rayyan says:
Mar 29th 2021
Jinkson: melonDS already has compatibility for ARM64 Linux. melonDS 0.9.1 added an ARM64 Linux release.
Post a comment
Name:
DO NOT TOUCH