motoku
motoku

Reputation: 1581

How To Compile Game Boy ROM From C or C++

I need to compile a Game Boy ROM in Windows. How is that done? I've looked everywhere on Google, only to find dead links.

Upvotes: 2

Views: 7967

Answers (2)

PPCMD
PPCMD

Reputation: 13

There is a working link on this page:

GameBoy Programming and Development - Loirak Development

First, you must download these compiler Files:

agb-win-binutils-r4.zip (2.3MB)

agb-win-core-r5.zip (481kB)

agb-win-gcc-r4.zip (2.4MB)

agb-win-newlib-r4.zip (3.8MB)

These Files can be found here.

Only the 'agb-win-core-r5.zip' is in the 'Release 5' section.

After downloading these files, extract them in your operating system directory. eg:- 'C:\'. This will create another folder called 'devkitadv'. Create a 'start.bat' file in Notepad and add the following code(if you're using Windows XP or later):

set PATH=c:\devkitadv\bin;%PATH%
cmd

Save it in the 'devkitadv' directory. Next, create a 'make.bat' file in Notepad, and type the following code:

set path=C:\devkitadv\bin;%path%
gcc -o <file_name>.elf <file_name>.c -lm
objcopy -O binary <file_name>.elf <file_name>.gb
pause

After saving it in your program's directory, run the 'make.bat' program. This should create a compiled ROM file, along with an '.elf' file. You can use the Game emulator VisualBoy Advance, to test your ROM file. Hope this helps.

Upvotes: 1

Jeff Alyanak
Jeff Alyanak

Reputation: 334

There are quite a few different options out there. First you need to decide whether you'll be programming in assembly or C. C is by far the easier option, especially if you've never worked with assembly before. For the example below, I'll assume you're using the GBDK (http://gbdk.sourceforge.net/) to compile from C.

Here's an example build command. I'm assuming that you're using a linux environment and that you've placed your dev kit into /opt but simply substitute the correct location for the lcc or lcc.exe executable:

/opt/gbdk/bin/lcc -Wa-l -Wl-m -o output.gb input.c

That should work well, but let me break it down so you understand why you're sending those arguments.

The -W (case sensitive) allows you to send arguments to the assembler, linker or compiler:

The first argument - -Wa-l - is sending the assembler the -l argument, in order to have it generate a list output file (as opposed to an object file, for example).

The second argument - -Wl-m - is sending the linker the argument -m, to produce a map file (useful for various reasons).

The third argument is -o, which will generate an output binary (ROM) of the build. You probably want this to end in .gb as this is the actual file that your emulator or flash cart will run.

Finally, you need to point to your source code. Easy as pie.

Upvotes: 2

Related Questions