Skip to content

Instantly share code, notes, and snippets.

@keztricks
Last active March 27, 2024 19:50
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keztricks/863349fd597f8e43f42976a1ca19e263 to your computer and use it in GitHub Desktop.
Save keztricks/863349fd597f8e43f42976a1ca19e263 to your computer and use it in GitHub Desktop.
Developing in gbdc on Mac

I've been following GamingMonsters's gbdk Gameboy Dev tutorial (it's rad! https://www.youtube.com/playlist?list=PLeEj4c2zF7PaFv5MPYhNAkBGrkx4iPGJo).

Was doing this for my own reference, but thought I may as well flesh out & share I'm on MacOS, so have put together anywhere I've had to do something different, I'm up to Session 10, so will update if anything further comes along as we progress.

Quick heads up, before you run anything here make sure you know what it's doing, this all worked fine and dandy for me, but I'm not making any promises!

"Hello World" - Part 1

Installing gdbk

Only Windows & Linux versions are available at Sourceforge.

A Mac version is available on github, however I had real trouble getting it to compile, fortunately, a pre-compiled version is available.

  1. Download gdbk-mac here Source: https://www.gbdkjs.com/docs/installation/.
  2. Unzip, and stick it wherever you like (I recommend /opt/gbdk/).
  3. Tell the OS where you've installed gbdk, open a terminal and run export GBDKDIR=/path/to/gbdk/ swapping out /path/to/gbdk/ with the wherever you've chosen to put gbdk.

BAT file

The make.bat file is Windows specific, instead we have the lovely makefile.

  1. Instead of make.bat create makefile
  2. Inside your makefile you'll want:
all:
  /path/to/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j -c -o main.o main.c
  /path/to/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j -o main.gb main.o

Be sure to swap out /path/to/gbdk/ with wherever you've put gbdk
3. When you want to compile your code, in terminal run make, be sure you're in the same directory as the makefile.

Note we've removed -DUSE_SFR_FOR_REG from our commands, I'm unsure what this does (let me know if you know!), we're possibly using a different version of gbdk that is used in the tutorial, and this was preventing compiling code.

Emulator (BGB Alternative)

BGB is not available for Mac, Sameboy is, and shares many of BGB's nice dev tools.

https://sameboy.github.io/downloads/

"Sprites" - Part 2

Gameboy Tile Designer

Unfortunately Gameboy Tile Designer is Windows only, and I had trouble finding an alternative. Fortunately it runs brilliantly in Wine.

To get running in Wine:

  1. Install Homebrew: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Use Homebrew to install xquartz: brew cask install xquartz
  3. Use Homebrew to install Wine: brew install wine
  4. Download Gameboy Tile Designer
  5. In terminal, launch Gameboy Tile Designer wine /path/to/GBTD/GBTD.exe, make sure to swap out that path for wherever you have downloaded to.

(Source)[https://www.davidbaumgold.com/tutorials/wine-mac/]

"Backgrounds" - Part 4

Gameboy Map Builder

This is exactly the same as getting the Tile Designer running in part 2, so take a look there!

@JL2210
Copy link

JL2210 commented Apr 13, 2020

I have some patches for GBDK if you're interested: https://github.com/JL2210/gbdk

@jesi-rgb
Copy link

jesi-rgb commented May 9, 2020

Hello! Thanks for this useful information, it's been great!

Here, I would like to propose a better makefile that keeps things a bit more organized in our project. It is actually the same exact one as you and GamingMonsters's, but with some folders involved.

Note that you must create a src, game and bin folders at the root of the project for this to work, and the files must be named main. You may of course change this to your liking, creating your own directories and naming them as you wish. The simple rule is that every decision you make must be reflected in the makefile. Here's my exact Makefile, with my exact configuration as an example. It's been working great.

export GBDK=/path/to/gbdk #your specific path to GBDK, mine was /opt/gbdk as you pointed out.
LCC = $(GBDK)/bin/lcc
FLAGS := -Wa-l -Wl-m -Wl-j # notice the flags are the exact same ones
TARGET := $(CURDIR)/game #game folder, this is where our .gb/.gba game will be outputed. CURDIR means Current Directory, the root of the project
SOURCE := $(CURDIR)/src #src folder, where our code lives
BIN := $(CURDIR)/bin #bin folder, for some intermediate files the compiler needs to create in order to build the game

all:
	$(LCC) $(FLAGS) -c -o $(BIN)/main.o $(SOURCE)/main.c  # i named my files main, but you can name them whatever you want, as long as it is also specified in here.
	$(LCC) $(FLAGS) -o $(TARGET)/main.gb $(BIN)/main.o
	@echo "Game exported succesfully!"

Screenshot 2020-05-09 at 08 13 48

As you can see, having folders keeps things neatly organized, which I find pretty important. Just wanted to share this with you since you were so kind to share this with us! Thank you very much for your work and happy coding!

@Challenger-Games
Copy link

brew install wine says it cant find it!

@ccano2011
Copy link

I'm hoping this gets an answer, but I'm having a heck of a time trying to just compile a rom. I followed everything to a tee but getting an ASXXXX error every time I run make. Any suggestions are appreciated
Screen Shot 2021-03-12 at 12 56 31 AM

@mcguire-jack-ece
Copy link

I'm hoping this gets an answer, but I'm having a heck of a time trying to just compile a rom. I followed everything to a tee but getting an ASXXXX error every time I run make. Any suggestions are appreciated
Screen Shot 2021-03-12 at 12 56 31 AM

It's strange that the error points to that .lst file. I'm not sure what that is, though I see you have it open, but know that mine compiles fine without that. I would recommend starting off with keztrick's makefile,

all:
  /path/to/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j -c -o main.o main.c
  /path/to/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j -o main.gb main.o

before getting fancy with jesi-rgb's.

Also, for anyone who hasn't figured this out yet, Wine is no longer operable on macOS since 10.15 stopped supporting 32-bit binaries altogether. I suggest using PlayOnMac instead. I got the Windows programs working in no time: https://www.playonmac.com/en/

@freitzzz
Copy link

Some remarks (September 2021)

If you are running macOS Catalina and above, do not install the official binaries of wine! They do not run function properly as Apple dropped support for 32 bit software starting on Catalina.
Instead use homebrew-wine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment