Skip to content

Commit b1335d1

Browse files
committed
Initial commit
0 parents  commit b1335d1

File tree

12 files changed

+373
-0
lines changed

12 files changed

+373
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/bin/
2+
/obj/
3+
/dep/
4+
/res/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/include/hardware.inc"]
2+
path = src/include/hardware.inc
3+
url = https://github.com/gbdev/hardware.inc.git

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"rgbdsz80.includePath": [
3+
"src/",
4+
"src/constants",
5+
"src/macros"
6+
]
7+
}

.vscode/tasks.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Build",
8+
"type": "shell",
9+
"command": "make",
10+
"group": {
11+
"kind": "build",
12+
"isDefault": true
13+
},
14+
"problemMatcher": "$rgbdserror"
15+
},
16+
{
17+
"label": "Clean",
18+
"type": "shell",
19+
"command": "make clean",
20+
"group": "none",
21+
"problemMatcher": "$rgbdserror"
22+
}
23+
]
24+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018–2020 Eldred Habert
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
.SUFFIXES:
3+
4+
################################################
5+
# #
6+
# CONSTANT DEFINITIONS #
7+
# #
8+
################################################
9+
10+
# Directory constants
11+
SRCDIR := src
12+
BINDIR := bin
13+
OBJDIR := obj
14+
DEPDIR := dep
15+
RESDIR := res
16+
17+
# Program constants
18+
MKDIR := $(shell which mkdir)
19+
# Shortcut if you want to use a local copy of RGBDS
20+
RGBDS =
21+
RGBASM = $(RGBDS)rgbasm
22+
RGBLINK = $(RGBDS)rgblink
23+
RGBFIX = $(RGBDS)rgbfix
24+
25+
ROM = $(BINDIR)/$(ROMNAME).$(ROMEXT)
26+
27+
# Argument constants
28+
INCDIRS = $(SRCDIR)/ $(SRCDIR)/include/
29+
WARNINGS = all extra
30+
ASFLAGS = -p $(PADVALUE) $(addprefix -i,$(INCDIRS)) $(addprefix -W,$(WARNINGS))
31+
LDFLAGS = -p $(PADVALUE)
32+
FIXFLAGS = -p $(PADVALUE) -v -i "$(GAMEID)" -k "$(LICENSEE)" -l $(OLDLIC) -m $(MBC) -n $(VERSION) -r $(SRAMSIZE) -t $(TITLE)
33+
34+
# The list of "root" ASM files that RGBASM will be invoked on
35+
SRCS = $(wildcard $(SRCDIR)/*.asm)
36+
37+
## Project-specific configuration
38+
# Use this to override the above
39+
include project.mk
40+
41+
################################################
42+
# #
43+
# RESOURCE FILES #
44+
# #
45+
################################################
46+
47+
# By default, asset recipes convert files in `res/` into other files in `res/`
48+
# This line causes assets not found in `res/` to be also looked for in `src/res/`
49+
# "Source" assets can thus be safely stored there without `make clean` removing them
50+
VPATH := $(SRCDIR)
51+
52+
# Define how to compress files using the PackBits16 codec
53+
# Compressor script requires Python 3
54+
$(RESDIR)/%.pb16: $(SRCDIR)/tools/pb16.py $(RESDIR)/%
55+
$^ $@
56+
57+
###############################################
58+
# #
59+
# COMPILATION #
60+
# #
61+
###############################################
62+
63+
# `all` (Default target): build the ROM
64+
all: $(ROM)
65+
.PHONY: all
66+
67+
# `clean`: Clean temp and bin files
68+
clean:
69+
-rm -rf $(BINDIR) $(OBJDIR) $(DEPDIR) $(RESDIR)
70+
.PHONY: clean
71+
72+
# `rebuild`: Build everything from scratch
73+
# It's important to do these two in order if we're using more than one job
74+
rebuild:
75+
$(MAKE) clean
76+
$(MAKE) all
77+
.PHONY: rebuild
78+
79+
# How to build a ROM
80+
$(BINDIR)/%.$(ROMEXT) $(BINDIR)/%.sym $(BINDIR)/%.map: $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRCS))
81+
@$(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 \
84+
&& $(RGBFIX) -v $(FIXFLAGS) $(BINDIR)/$*.$(ROMEXT)
85+
86+
# `.mk` files are auto-generated dependency lists of the "root" ASM files, to save a lot of hassle.
87+
# Also add all obj dependencies to the dep file too, so Make knows to remake it
88+
# Caution: some of these flags were added in RGBDS 0.4.0, using an earlier version WILL NOT WORK
89+
# (and produce weird errors)
90+
$(OBJDIR)/%.o $(DEPDIR)/%.mk: $(SRCDIR)/%.asm
91+
@$(MKDIR) -p $(dir $(OBJDIR)/$* $(DEPDIR)/$*)
92+
$(RGBASM) $(ASFLAGS) -M $(DEPDIR)/$*.mk -MG -MP -MQ $(OBJDIR)/$*.o -MQ $(DEPDIR)/$*.mk -o $(OBJDIR)/$*.o $<
93+
94+
ifneq ($(MAKECMDGOALS),clean)
95+
-include $(patsubst $(SRCDIR)/%.asm,$(DEPDIR)/%.mk,$(SRCS))
96+
endif

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# gb-boilerplate
2+
3+
A minimal, customizable, ready-to-compile boilerplate for Game Boy RGBDS projects.
4+
5+
## Downloading
6+
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.
8+
9+
## Setting up
10+
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.
12+
13+
## Customizing
14+
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.
16+
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.
18+
19+
The file at `src/res/build_date.asm` is compiled individually to include a build date in your ROM. Always comes in handy.
20+
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)).
22+
23+
## Compiling
24+
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.
26+
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.
28+
29+
## See also
30+
31+
If you want something less barebones, already including some "base" code, check out [gb-starter-kit](https://github.com/ISSOtm/gb-starter-kit).
32+
33+
[Here](https://gist.github.com/ISSOtm/a9057e7c66080f36afcd82ed2863fd62) are the naming conventions used in this code; maybe you'll find them useful.
34+
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.
36+
37+
### Libraries
38+
39+
- [Variable-width font engine](https://github.com/ISSOtm/gb-vwf)
40+
- [structs in RGBDS](https://github.com/ISSOtm/rgbds-structs)

project.mk

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file contains project configuration
2+
3+
4+
# Value that the ROM will be filled with
5+
PADVALUE := 0xFF
6+
7+
## Header constants (passed to RGBFIX)
8+
9+
# ROM version (typically starting at 0 and incremented for each published version)
10+
VERSION := 0
11+
12+
# 4-ASCII letter game ID
13+
GAMEID := BOIL
14+
15+
# Game title, up to 11 ASCII chars
16+
TITLE := BOILERPLATE
17+
18+
# New licensee, 2 ASCII chars
19+
# Homebrew games FTW!
20+
LICENSEE := HB
21+
# Old licensee, please set to 0x33 (required to get SGB compatibility)
22+
OLDLIC := 0x33
23+
24+
# MBC type, tells which hardware is in the cart
25+
# See https://gbdev.io/pandocs/#_0147-cartridge-type or consult any copy of Pan Docs
26+
# If using no MBC, consider enabling `-t` below
27+
MBC := 0x00
28+
29+
# ROM size is set automatically by RGBFIX
30+
31+
# Size of the on-board SRAM; MBC type should indicate the presence of RAM
32+
# See https://gbdev.io/pandocs/#_0149-ram-size or consult any copy of Pan Docs
33+
# Set this to 0 when using MBC2's built-in SRAM
34+
SRAMSIZE := 0x00
35+
36+
# ROM name
37+
ROMNAME := boilerplate
38+
ROMEXT := gb
39+
40+
41+
# Compilation parameters, uncomment to apply, comment to cancel
42+
# "Sensible defaults" are included
43+
44+
# Disable automatic `nop` after `halt`
45+
ASFLAGS += -h
46+
47+
# Export all labels
48+
# This means they must all have unique names, but they will all show up in the .sym and .map files
49+
# ASFLAGS += -E
50+
51+
# Game Boy Color compatible
52+
# FIXFLAGS += -c
53+
# Game Boy Color required
54+
# FIXFLAGS += -C
55+
56+
# Super Game Boy compatible
57+
# FIXFLAGS += -s
58+
59+
# Game Boy mode
60+
# LDFLAGS += -d
61+
62+
# No banked WRAM mode
63+
# LDFLAGS += -w
64+
65+
# 32k mode
66+
# LDFLAGS += -t

src/header.asm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
SECTION "Header", ROM0[$100]
3+
4+
; This is your ROM's entry point
5+
; You have 4 bytes of code to do... something
6+
di
7+
jp EntryPoint
8+
9+
; Make sure to allocate some space for the header, so no important
10+
; code gets put there and later overwritten by RGBFIX.
11+
; RGBFIX is designed to operate over a zero-filled header, so make
12+
; sure to put zeros regardless of the padding value. (This feature
13+
; was introduced in RGBDS 0.4.0, but the -MG etc flags were also
14+
; introduced in that version.)
15+
ds $150 - @, 0
16+
17+
SECTION "Entry point", ROM0
18+
19+
EntryPoint:
20+
; Here is where the fun begins, happy coding :)
21+
jr @

src/res/build_date.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
SECTION "Build date", ROM0
3+
4+
db "Built "
5+
BuildDate::
6+
db __ISO_8601_UTC__
7+
db 0

0 commit comments

Comments
 (0)