Skip to content

Commit 3e5b5a1

Browse files
committed
Initial version.
1 parent b1335d1 commit 3e5b5a1

15 files changed

+2065
-62
lines changed

Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ INCDIRS = $(SRCDIR)/ $(SRCDIR)/include/
2929
WARNINGS = all extra
3030
ASFLAGS = -p $(PADVALUE) $(addprefix -i,$(INCDIRS)) $(addprefix -W,$(WARNINGS))
3131
LDFLAGS = -p $(PADVALUE)
32-
FIXFLAGS = -p $(PADVALUE) -v -i "$(GAMEID)" -k "$(LICENSEE)" -l $(OLDLIC) -m $(MBC) -n $(VERSION) -r $(SRAMSIZE) -t $(TITLE)
32+
FIXFLAGS = -p $(PADVALUE) -v -l $(OLDLIC) -m $(MBC) -n $(VERSION) -r $(SRAMSIZE) -t $(TITLE)
3333

3434
# The list of "root" ASM files that RGBASM will be invoked on
3535
SRCS = $(wildcard $(SRCDIR)/*.asm)
@@ -79,8 +79,7 @@ rebuild:
7979
# How to build a ROM
8080
$(BINDIR)/%.$(ROMEXT) $(BINDIR)/%.sym $(BINDIR)/%.map: $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRCS))
8181
@$(MKDIR) -p $(@D)
82-
$(RGBASM) $(ASFLAGS) -o $(OBJDIR)/build_date.o $(SRCDIR)/res/build_date.asm
83-
$(RGBLINK) $(LDFLAGS) -m $(BINDIR)/$*.map -n $(BINDIR)/$*.sym -o $(BINDIR)/$*.$(ROMEXT) $^ $(OBJDIR)/build_date.o \
82+
$(RGBLINK) $(LDFLAGS) -m $(BINDIR)/$*.map -n $(BINDIR)/$*.sym -o $(BINDIR)/$*.$(ROMEXT) $^ \
8483
&& $(RGBFIX) -v $(FIXFLAGS) $(BINDIR)/$*.$(ROMEXT)
8584

8685
# `.mk` files are auto-generated dependency lists of the "root" ASM files, to save a lot of hassle.

README.md

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
1-
# gb-boilerplate
1+
# bgbtest.gb
22

3-
A minimal, customizable, ready-to-compile boilerplate for Game Boy RGBDS projects.
3+
## What is it?
44

5-
## Downloading
5+
![Screenshot](screenshot.png) ![Screenshot with all buttons pressed](screenshot-allpressed.png)
66

7-
You can simply clone the repository using Git, or if you just want to download this, click the `Clone or download` button up and to the right of this. This repo is also usable as a GitHub template for creating new repositories.
7+
This is the source code for the bgbtest.gb ROM that is shipped with beware's Gameboy emulator, [BGB](https://bgb.bircd.org/). It was made on request by beware and was designed to be a first ROM that a new user of BGB can open to confirm that the emulator is working correctly. It was created a few years ago now, but from memory, these are the design requirements given to me by beware:
88

9-
## Setting up
9+
* **Should test graphics.** Needs to show some form of animation without requiring user input, to confirm that graphical output is working.
10+
* **Should test audio.** Needs to play some form of sound without requiring user input, to confirm that audio output is working.
11+
* **Should be able to test buttons.** Needs to detect when buttons are pressed and indicate which button is pressed, to confirm that input is working and configured as per the user's preference. Should also indicate on the screen that this a function.
12+
* **Should be 32 kiB.** Needs to use minimal disk space when stored and network traffic when being downloaded. (beware remains seemingly one of the few people who actually cares about these things in this day and age.)
13+
* **Should not be a "room heater".** Needs to use the CPU's `halt` mode when idle to preserve CPU time (if used in an emulator) or battery life (if used on real hardware).
14+
* **Should be branded BGB.** Needs to show the BGB name and application icon, as this is BGB's official test ROM.
1015

11-
Make sure you have [RGBDS](https://github.com/rednex/rgbds), at least version 0.4.0, and GNU Make installed. Python 3 is required for the PB16 compressor bundled as a usage example, but that script is optional.
16+
The original version of the code compiled by using a Windows batch file and the original Windows 95 compatible RGBDS binaries.
1217

13-
## Customizing
18+
This version of the code is...
19+
* slightly cleaned up and much more well commented.
20+
* changed to compile on modern RGBDS versions. Tested on 0.4.1 but should work a few versions back as well. This is mostly about replacing deprecated keywords like `HOME` and `BSS` with modern ones like `ROM0` and `WRAM0`.
21+
* adapted to use ISSOtm's [gb-boilerplate](https://github.com/ISSOtm/gb-boilerplate) for easier compilation.
22+
* adapted to use the IO register definitions from the modern [hardware.inc](https://github.com/gbdev/hardware.inc) file.
1423

15-
Edit `project.mk` to customize most things specific to the project (like the game name, file name and extension, etc.). Everything has accompanying doc comments.
24+
For now, it should however compile to the exact same file as is shipped with BGB. If I decide to fix bugs/add features in future, code compiling to the original version will be kept as a branch for posterity. The original version has the following hashes:
1625

17-
Everything in the `src` folder is the source, and can be freely modified however you want. The basic structure in place should hint you at how things are organized. If you want to create a new "module", you simply need to drop a `.asm` file in the `src` directory, name does not matter. All `.asm` files in that root directory will be individually compiled by RGBASM.
26+
* md5: d4dd708dd0de6ba003006004d53d21ac
27+
* sha1: 1ea7c76a76427d1c1a85427f3eacc16d142ffc56
1828

19-
The file at `src/res/build_date.asm` is compiled individually to include a build date in your ROM. Always comes in handy.
29+
## Functionality
2030

21-
If you want to add resources, I recommend using the `src/res` folder. Add rules in the Makefile; an example is provided for compressing files using PB16 (a variation of [PackBits](https://wiki.nesdev.com/w/index.php/Tile_compression#PackBits)).
31+
When you run the ROM, it shows the BGB application icon and name, and a parallax starfield effect flying by vertically in the background.
2232

23-
## Compiling
33+
It's playing a (pseudo)random melody on the wave channel using a sawtooth wave. This melody can be turned off or on by holding select and pressing start.
2434

25-
Simply open you favorite command prompt / terminal, place yourself in this directory (the one the Makefile is located in), and run the command `make`. This should create a bunch of things, including the output in the `bin` folder.
35+
If you press any button, the button in question is indicated on the screen, and a tone unique to that button is played on one of the pulse channels.
2636

27-
If you get errors that you don't understand, try running `make clean`. If that gives the same error, try deleting the `deps` folder. If that still doesn't work, try deleting the `bin` and `obj` folders as well. If that still doesn't work, you probably did something wrong yourself.
37+
If you play all the notes in ascending order, an easter egg is unlocked: a sine wave effect that is applied to the BGB logo.
2838

29-
## See also
39+
It's shipped with BGB as a first ROM to try in the emulator. However, if you are a Gameboy modder or second hand buyer, it might be useful to put this ROM on a flash cartridge to test the buttons, sound output and graphics on a modded 'boy or a 'boy of unknown condition. It can also be a useful test in the very early stages of developing a GB emulator, as it's both not a completely trivial program, and not doing anything too crazy.
3040

31-
If you want something less barebones, already including some "base" code, check out [gb-starter-kit](https://github.com/ISSOtm/gb-starter-kit).
41+
## Trivia
3242

33-
[Here](https://gist.github.com/ISSOtm/a9057e7c66080f36afcd82ed2863fd62) are the naming conventions used in this code; maybe you'll find them useful.
43+
Sound trivia 1: All sound that's played (both the pseudorandom melody and the button sounds) is in the C mixolydian scale. That is to say, on a piano keyboard, it would be using all white keys in one octave, except B which is flattened to B♭.
3444

35-
I recommend the [BGB](https://bgb.bircd.org) emulator for developing ROMs on Windows and, via Wine, Linux and macOS (64-bit build available for Catalina). [SameBoy](https://github.com/LIJI32/SameBoy) is more accurate, but has a much worse interface except on macOS.
45+
Sound trivia 2: I didn't want to kill the previously playing note when the user pressed a new button, so I made it alternate between pulse channels 1 and 2. However, that created a new problem. Pressing the same button multiple times would create an ugly phased sound that was different each time due to the phase relation between the channels. The solution to this was to detune every second note which gives a much more pleasant sound.
3646

37-
### Libraries
47+
Graphics trivia: At the time I wrote this code, my own graphics conversion scripts were pretty dumb and used to use color 0 as the darkest color and color 3 as the lightest color, corresponding to the brightness order of regular RGB values. This means the palette set in BGP is effectively inverted compared to most GB software.
3848

39-
- [Variable-width font engine](https://github.com/ISSOtm/gb-vwf)
40-
- [structs in RGBDS](https://github.com/ISSOtm/rgbds-structs)
49+
Data compression trivia: bgbtest.gb is using a simple decompression routine which can decode RLE as well as sequences. It was originally adapted from data compression used in LSDj which I had already written a decompression routine for in [LittleFM](https://blog.gg8.se/wordpress/gameboy-resources/littlefm-an-alternative-file-manager-for-lsdj/), an alternative file manager for [LSDj](https://www.littlesounddj.com/) which can be patched onto an LSDj ROM. But I expanded to use it more as a general purpose data encoding that's especially useful for tile data which are often either sequential or repeating in nature. In bgbtest.gb, it was used to manually specify data, rather than being generated by other tools.
50+
51+
## Disassembly
52+
53+
[CelestialAmber](https://github.com/CelestialAmber) made a [disassembly of bgbtest.gb](https://github.com/CelestialAmber/bgbtest). While still being a work in progress, it's interesting to see how another person interprets your code when disassembling it.

project.mk

+4-10
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ PADVALUE := 0xFF
99
# ROM version (typically starting at 0 and incremented for each published version)
1010
VERSION := 0
1111

12-
# 4-ASCII letter game ID
13-
GAMEID := BOIL
14-
1512
# Game title, up to 11 ASCII chars
16-
TITLE := BOILERPLATE
13+
TITLE := BGBWELCOME
1714

18-
# New licensee, 2 ASCII chars
19-
# Homebrew games FTW!
20-
LICENSEE := HB
2115
# Old licensee, please set to 0x33 (required to get SGB compatibility)
22-
OLDLIC := 0x33
16+
OLDLIC := 0x00
2317

2418
# MBC type, tells which hardware is in the cart
2519
# See https://gbdev.io/pandocs/#_0147-cartridge-type or consult any copy of Pan Docs
@@ -34,15 +28,15 @@ MBC := 0x00
3428
SRAMSIZE := 0x00
3529

3630
# ROM name
37-
ROMNAME := boilerplate
31+
ROMNAME := bgbtest
3832
ROMEXT := gb
3933

4034

4135
# Compilation parameters, uncomment to apply, comment to cancel
4236
# "Sensible defaults" are included
4337

4438
# Disable automatic `nop` after `halt`
45-
ASFLAGS += -h
39+
#ASFLAGS += -h
4640

4741
# Export all labels
4842
# This means they must all have unique names, but they will all show up in the .sym and .map files

screenshot-allpressed.png

2.99 KB
Loading

screenshot.png

2.49 KB
Loading

0 commit comments

Comments
 (0)