melonDS - now also for macOS!


Yep.
If you want to test it, scroll down to the bottom of the post. I’ll be explaining about what needed to be changed for it to work.

This originally started as a little challenge. "It shouldn't be that hard," I thought. However, it wasn't as easy as I would have hoped, but I got there in the end.

- The JIT recompiler

Thanks Generic (aka RSDuck) for helping me out a lot here and guiding me!

Fastmem

It mapped memory using "memfd_create()" on Linux, which didn't exist on macOS. Instead, on macOS shm_open is used to create the fastmem memory.
macOS also didn't have "->gregs" in "uc_mcontext" and no "REG_RIP" either. This has to be changed to "->__ss.__rip" instead.
Then, it would crash with a "bus error" on attempting to load. This was caused because macOS returned "bus error" instead of "segmentation fault", so the signal handler couldn't handle it.
Note: fastmem was disabled because it caused all sorts of errors while trying to boot firmware or run games. If anyone manages to fix it, send a pull request!

The JIT itself

The JIT would build, but at link time it would complain about "ARM_Dispatch" and "ARM_Ret" being undefined. Apparently in the Mach-O format (used in macOS) global function names defined in assembly are required to be prepended by an underscore.
Then it would crash upon booting firmware or trying to load a game. This was caused by the line here which tried to reprotect some memory to make it executable. On macOS, new memory is now mmap'ed instead.

- The OpenGL renderer

macOS complained about not being able to find "GL/gl.h" and "GL/glext.h". These includes had to be changed to "OpenGL/gl3.h" and "OpenGL/gl3ext.h" on macOS and the OpenGL framework was linked.
Also the functions defined by the OpenGL macronator already existed on macOS, which caused "ambiguous reference" errors. The macronator was ifndef'd out.

- Direct Mode

Direct Mode used "AF_PACKET" to get the MAC address, which doesn't exist on macOS. "AF_LINK" was used instead.
The library names of libpcap had to be changed to "libpcap.A.dylib" and "libpcap.dylib" on macOS.

- Binding Keys

This was a simple fix. For some reason, macOS didn't give focus to the buttons in the key binding menu when they were pressed, which meant that they couldn't detect keys. I had to set the focus policy to Qt::StrongFocus to get them to accept focus.

- App Bundle

Now it built fine and it worked, but it came as a Unix executable, not a macOS app bundle. I had to add some lines in CMakeLists.txt to make it build an app bundle.
I also generated a macOS ".icns" icon file for melonDS, so now the icon showed up on the app bundle.

- No libslirp available in Homebrew

Homebrew (the package manager) didn't have libslirp in their repositories, so I created a pull request here which was merged.


Here are the downloads. If you find any issues, make sure you comment here and tell me so I can fix it!
You will have to install the appropriate libraries beforehand with the Homebrew Package Manager.
In Terminal paste the following command to install the required libraries.
brew install qt@5 sdl2 libslirp
NOTE: melonDS now ships macOS releases as of 0.9.1. We recommend you to use that instead.
melonDS 0.9 beta for macOS x86_64
To unzip the above download, you may need to use a program like The Unarchiver.
reglo says:
Jan 22nd 2021
The top screen of the nds isn't working. Sometimes the bottom screen doesn't work.
Justin says:
Jan 26th 2021
hey, why does it say every time I open it it reads: "MelonDS cannot be opened because the developer cannot be verified"? I just need to run regular DS games with it, and I don't need homebrew either. Im running this on a 2015 MacBook Pro, so it should run fine. What has to be one to stop this message from appearing and the program to be loaded? It can't open it without the program saying that it cant verify that its free from malware.
revolug says:
Mar 17th 2021
Hey I had the same problem as Joel here, but I don't quite understand how he fixed it.
I tried opening melonDS after downloading the libraries with homebrew and it still gave me this error message:

Date/Time: 2021-03-17 15:56:38.675 -0500
OS Version: Mac OS X 10.13.6 (17G14033)
Report Version: 12
Anonymous UUID: D9E1E34D-A0E5-5C64-E6DE-04565113AF20


Time Awake Since Boot: 5200 seconds

System Integrity Protection: enabled

Crashed Thread: 0

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY

Termination Reason: DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
Library not loaded: /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib
Referenced from: /Applications/pokerando/melonDS.app/Contents/MacOS/melonDS
Reason: image not found

(pokerando is the folder I have melonDS in, for a pokemon randomizer i'm trying to setup)

Do you know how I could fix this?
oneminato says:
Mar 25th 2021
Hi, I am having an issue installing melonDS for macOS Mojave. I have a 2017 MacBook Pro i5 2.5 Ghz and when I install it (v0.9.1)it says there are compatibility issues. Is there something wrong with my MacBook (do I have to update to Catalina) to make it work or is melonDS broken?
seochannie says:
Apr 2nd 2021
Process: melonDS [43339]
Path: /private/var/folders/*/melonDS-1.app/Contents/MacOS/melonDS
Identifier: net.kuribo64.melonDS
Version: 0.9 (0.9)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: melonDS [43339]
User ID: 501

Date/Time: 2021-04-02 02:13:07.001 -0400
OS Version: Mac OS X 10.15.7 (19H512)
Report Version: 12
Bridge OS Version: 5.2 (18P4346)
Anonymous UUID: 63372EE0-7495-949B-4E9F-36CBFBE6EFFF

Sleep/Wake UUID: A3BD4A92-E06E-46E6-A879-CCF891FDCCF7

Time Awake Since Boot: 350000 seconds
Time Since Wake: 1400 seconds

System Integrity Protection: enabled

Notes: Translocated Process

Crashed Thread: 0

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY

Termination Reason: DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
Library not loaded: /usr/local/opt/qt/lib/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /private/var/folders/*/melonDS-1.app/Contents/MacOS/melonDS
Reason: image not found

Binary Images:
0x10d483000 - 0x10d59afff +net.kuribo64.melonDS (0.9 - 0.9) <DDCC7775-CC41-3841-95BC-6A45691E88D4> /var/folders/*/melonDS-1.app/Contents/MacOS/melonDS
0x1147c6000 - 0x1148bdff3 +libSDL2-2.0.0.dylib (0) <5576C373-E496-3F4E-BBEF-18B45E623C2C> /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib
0x114906000 - 0x11491dff7 +libslirp.0.dylib (0) <82FF1DF1-4F88-3A7C-931F-4D58DEB9DCFB> /usr/local/opt/libslirp/lib/libslirp.0.dylib
0x114931000 - 0x114a3cffb +libglib-2.0.0.dylib (0) <7E73DDCD-EAE4-3E7E-B301-B28C5F5FCB52> /usr/local/opt/glib/lib/libglib-2.0.0.dylib
0x114a6f000 - 0x114a78fff +libintl.8.dylib (0) <FA921CC0-395B-3155-8259-EA61DE25C5D2> /usr/local/opt/gettext/lib/libintl.8.dylib
0x11dc11000 - 0x11dca2f47 dyld (750.6) <326C6480-04F4-3164-A363-53079A148E2F> /usr/lib/dyld
0x7fff6e52b000 - 0x7fff6e52cfff libSystem.B.dylib (1281.100.1) <C49167AD-722B-3DF3-9031-7D6B59FC2A06> /usr/lib/libSystem.B.dylib
0x7fff6f304000 - 0x7fff6f3f4fff libiconv.2.dylib (59) <18311A67-E4EF-3CC7-95B3-C0EDEE3A282F> /usr/lib/libiconv.2.dylib

Model: MacBookPro16,2, BootROM 1554.80.3.0.0 (iBridge: 18.16.14346.0.0,0), 4 processors, Quad-Core Intel Core i5, 2 GHz, 16 GB, SMC
Graphics: kHW_IntelIrisPlusGraphicsItem, Intel Iris Plus Graphics, spdisplays_builtin
Memory Module: BANK 0/ChannelA-DIMM0, 8 GB, LPDDR4X, 3733 MHz, Micron, -
Memory Module: BANK 2/ChannelB-DIMM0, 8 GB, LPDDR4X, 3733 MHz, Micron, -
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x7BF), wl0: Oct 28 2020 14:13:29 version 9.30.357.42.32.5.48 FWID 01-767f6cce
Bluetooth: Version 7.0.6f8, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB 3.1 Bus
USB Device: USB 3.1 Bus
USB Device: Apple T2 Bus
USB Device: Touch Bar Backlight
USB Device: Touch Bar Display
USB Device: Apple Internal Keyboard / Trackpad
USB Device: Headset
USB Device: Ambient Light Sensor
USB Device: FaceTime HD Camera (Built-in)
USB Device: Apple T2 Controller
Thunderbolt Bus: MacBook Pro, Apple Inc., 85.0
Thunderbolt Bus: MacBook Pro, Apple Inc., 0.0


This is the message that keeps popping up. I downloaded Homebrew, but it still won't work.
YoungHomo says:
Apr 4th 2021
Any way to get this to work on High Sierra? The newer versions of OSX require recent graphics cards to upgrade.
Jack says:
Apr 22nd 2021
I am getting the same error message as seochannie.

Process: melonDS [35253]
Path: /private/var/folders/*/melonDS.app/Contents/MacOS/melonDS
Identifier: net.kuribo64.melonDS
Version: 0.9 (0.9)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: melonDS [35253]
User ID: 501

Date/Time: 2021-04-22 14:19:02.225 -0700
OS Version: macOS 11.2.3 (20D91)
Report Version: 12
Anonymous UUID: 372B8D46-F797-B6EE-F9EA-CE2350FB1600

Sleep/Wake UUID: 4C4E3201-51D3-4C2D-BFC4-3BCA24954F43

Time Awake Since Boot: 570000 seconds
Time Since Wake: 5700 seconds

System Integrity Protection: enabled

Notes: Translocated Process

Crashed Thread: 0

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY

Termination Reason: DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
dyld: Using shared cache: 52762DF1-0E55-3F8B-9588-8169E6D0EB95
Library not loaded: /usr/local/opt/qt/lib/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /private/var/folders/*/melonDS.app/Contents/MacOS/melonDS
Reason: image not found

Binary Images:
0x1071cd000 - 0x1072e4fff +net.kuribo64.melonDS (0.9 - 0.9) <D0A13208-ABF2-3D44-9349-8E55741D96FB> /var/folders/*/melonDS.app/Contents/MacOS/melonDS
0x10e7f3000 - 0x10e8eefff +libSDL2-2.0.0.dylib (0) <C8F7F43F-39EC-32F9-8183-1AD47AF40911> /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib
0x10e940000 - 0x10e957fff +libslirp.0.dylib (0) <52126D55-9EA2-3B5E-A7FD-7B80C8750386> /usr/local/opt/libslirp/lib/libslirp.0.dylib
0x10e968000 - 0x10ea73fff +libglib-2.0.0.dylib (0) <0520F795-35CD-3E8C-8AD1-D98D83DE7763> /usr/local/opt/glib/lib/libglib-2.0.0.dylib
0x10eaa3000 - 0x10eaaefff +libintl.8.dylib (0) <F1C4D8E0-D7AF-3BAD-A329-B9AB3241CA2D> /usr/local/opt/gettext/lib/libintl.8.dylib
0x10edff000 - 0x10ee9afff dyld (832.7.3) <0D4EA85F-7E30-338B-9215-314A5A5539B6> /usr/lib/dyld
0x7fff2a5b7000 - 0x7fff2a5b8fff libSystem.B.dylib (1292.60.1) <83503CE0-32B1-36DB-A4F0-3CC6B7BCF50A> /usr/lib/libSystem.B.dylib
0x7fff2a5f6000 - 0x7fff2a6e6fff libiconv.2.dylib (59) <AD10ECF4-E137-3152-9612-7EC548D919E8> /usr/lib/libiconv.2.dylib

Model: MacBookAir7,2, BootROM 426.0.0.0.0, 2 processors, Dual-Core Intel Core i5, 1.6 GHz, 8 GB, SMC 2.27f2
Graphics: kHW_IntelHDGraphics6000Item, Intel HD Graphics 6000, spdisplays_builtin
Memory Module: BANK 0/DIMM0, 4 GB, DDR3, 1600 MHz, 0x80AD, 0x483943434E4E4E424C54424C41522D4E5444
Memory Module: BANK 1/DIMM0, 4 GB, DDR3, 1600 MHz, 0x80AD, 0x483943434E4E4E424C54424C41522D4E5444
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x117), Broadcom BCM43xx 1.0 (7.77.111.1 AirPortDriverBrcmNIC-1675.1)
Bluetooth: Version 8.0.3d9, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
Serial ATA Device: APPLE SSD SM0256G, 251 GB
USB Device: USB 3.0 Bus
USB Device: BRCM20702 Hub
USB Device: Bluetooth USB Host Controller
Thunderbolt Bus: MacBook Air, Apple Inc., 27.2
Post a comment
Name:
DO NOT TOUCH