Skip to content

Commit aff2609

Browse files
committed
Initial commit
0 parents  commit aff2609

24 files changed

+2121
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "src/include/hardware.inc"]
2+
path = src/include/hardware.inc
3+
url = https://github.com/gbdev/hardware.inc.git
4+
[submodule "src/include/rgbds-structs"]
5+
path = src/include/rgbds-structs
6+
url = https://github.com/ISSOtm/rgbds-structs.git

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "emulicious-debugger",
9+
"request": "launch",
10+
"name": "Launch in Emulicious",
11+
"program": "${workspaceFolder}/${command:AskForProgramName}",
12+
"port": 58870,
13+
"stopOnEntry": true
14+
}
15+
]
16+
}

.vscode/tasks.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 all",
10+
"problemMatcher": [],
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
}
15+
},
16+
{
17+
"label": "Rebuild",
18+
"type": "shell",
19+
"command": "make rebuild",
20+
"problemMatcher": [],
21+
"group": {
22+
"kind": "build",
23+
"isDefault": true
24+
}
25+
},
26+
{
27+
"label": "Run Emulicious",
28+
"type": "shell",
29+
"command": "make runEmulicious",
30+
"problemMatcher": [],
31+
"group": {
32+
"kind": "build",
33+
"isDefault": true
34+
}
35+
},
36+
{
37+
"label": "Run BGB",
38+
"type": "shell",
39+
"command": "make runBGB",
40+
"problemMatcher": [],
41+
"group": {
42+
"kind": "build",
43+
"isDefault": true
44+
}
45+
},
46+
{
47+
"label": "Run romusage",
48+
"type": "shell",
49+
"command": "make romusage",
50+
"problemMatcher": [],
51+
"group": {
52+
"kind": "build",
53+
"isDefault": true
54+
}
55+
}
56+
]
57+
}

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) 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: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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+
ifneq ($(shell which rm),)
19+
# POSIX OSes
20+
RM_RF := rm -rf
21+
MKDIR_P := mkdir -p
22+
PY :=
23+
filesize = echo 'NB_PB$2_BLOCKS equ (' `wc -c $1 | cut -d ' ' -f 1` ' + $2 - 1) / $2'
24+
else
25+
# Windows outside of a POSIX env (Cygwin, MSYS2, etc.)
26+
# We need Powershell to get any sort of decent functionality
27+
$(warning Powershell is required to get basic functionality)
28+
RM_RF := -del /q
29+
MKDIR_P := -mkdir
30+
PY := python
31+
filesize = powershell Write-Output $$('NB_PB$2_BLOCKS equ ' + [string] [int] (([IO.File]::ReadAllBytes('$1').Length + $2 - 1) / $2))
32+
endif
33+
34+
# Shortcut if you want to use a local copy of RGBDS
35+
RGBDS := ../rgbds/
36+
RGBASM := $(RGBDS)rgbasm.exe
37+
RGBLINK := $(RGBDS)rgblink.exe
38+
RGBFIX := $(RGBDS)rgbfix.exe
39+
RGBGFX := $(RGBDS)rgbgfx.exe
40+
41+
EMULATOR_EMULICIOUS = ../../Emulicious/Emulicious.exe
42+
EMULATOR_BGB = ../../bgb64/bgb64.exe
43+
44+
ROMUSAGE := ../../Tools/romusage.exe
45+
46+
ROM = $(BINDIR)/$(ROMNAME).$(ROMEXT)
47+
48+
# Argument constants
49+
INCDIRS = $(SRCDIR)/ $(SRCDIR)/include/
50+
WARNINGS = all extra
51+
ASFLAGS = -p $(PADVALUE) $(addprefix -i,$(INCDIRS)) $(addprefix -W,$(WARNINGS))
52+
LDFLAGS = -p $(PADVALUE)
53+
FIXFLAGS = -p $(PADVALUE) -v -i "$(GAMEID)" -k "$(LICENSEE)" -l $(OLDLIC) -m $(MBC) -n $(VERSION) -r $(SRAMSIZE) -t $(TITLE)
54+
55+
# The list of "root" ASM files that RGBASM will be invoked on
56+
SRCS = $(wildcard $(SRCDIR)/*.asm)
57+
INCDIRS = $(SRCDIR)/ $(SRCDIR)/include/
58+
59+
## Project-specific configuration
60+
# Use this to override the above
61+
include project.mk
62+
63+
################################################
64+
# #
65+
# TARGETS #
66+
# #
67+
################################################
68+
69+
# `all` (Default target): build the ROM
70+
all: $(ROM)
71+
.PHONY: all
72+
73+
# `clean`: Clean temp and bin files
74+
clean:
75+
$(RM_RF) $(BINDIR)
76+
$(RM_RF) $(OBJDIR)
77+
$(RM_RF) $(DEPDIR)
78+
$(RM_RF) $(RESDIR)
79+
.PHONY: clean
80+
81+
# `rebuild`: Build everything from scratch
82+
# It's important to do these two in order if we're using more than one job
83+
rebuild:
84+
$(MAKE) clean
85+
$(MAKE) all
86+
.PHONY: rebuild
87+
88+
runEmulicious:
89+
$(EMULATOR_EMULICIOUS) $(ROM)
90+
.PHONY: runEmulicious
91+
92+
runBGB:
93+
$(EMULATOR_BGB) $(ROM) -watch
94+
.PHONY: runBGB
95+
96+
romusage:
97+
$(ROMUSAGE) $(BINDIR)/$(ROMNAME).map -g
98+
.PHONY: romusage
99+
100+
################################################
101+
# #
102+
# GIT SUBMODULES #
103+
# #
104+
################################################
105+
106+
# By default, cloning the repo does not init submodules
107+
# If that happens, warn the user
108+
# Note that the real paths aren't used!
109+
# Since RGBASM fails to find the files, it outputs the raw paths, not the actual ones.
110+
hardware.inc/hardware.inc rgbds-structs/structs.asm:
111+
@echo 'hardware.inc is not present; have you initialized submodules?'
112+
@echo 'Run `git submodule update --init`, then `make clean`, then `make` again.'
113+
@echo 'Tip: to avoid this, use `git clone --recursive` next time!'
114+
@exit 1
115+
116+
################################################
117+
# #
118+
# RESOURCE FILES #
119+
# #
120+
################################################
121+
122+
# By default, asset recipes convert files in `res/` into other files in `res/`
123+
# This line causes assets not found in `res/` to be also looked for in `src/res/`
124+
# "Source" assets can thus be safely stored there without `make clean` removing them
125+
VPATH := $(SRCDIR)
126+
127+
$(RESDIR)/%.1bpp: $(RESDIR)/%.png
128+
@$(MKDIR_P) $(@D)
129+
$(RGBGFX) -d 1 -o $@ $<
130+
131+
$(RESDIR)/%_linear.2bpp: $(RESDIR)/%_linear.png
132+
@$(MKDIR_P) $(@D)
133+
$(RGBGFX) -d 2 -o $@ $<
134+
135+
$(RESDIR)/%_map.2bpp $(RESDIR)/%_map.tilemap: $(RESDIR)/%_map.png
136+
@$(MKDIR_P) $(@D)
137+
$(RGBGFX) -u -T -d 2 -o $@ $<
138+
139+
$(RESDIR)/%.2bpp: $(RESDIR)/%.png
140+
@$(MKDIR_P) $(@D)
141+
$(RGBGFX) -h -d 2 -o $@ $<
142+
143+
# Define how to compress files using the PackBits16 codec
144+
# Compressor script requires Python 3
145+
$(RESDIR)/%.pb16: $(RESDIR)/% $(SRCDIR)/tools/pb16.py
146+
@$(MKDIR_P) $(@D)
147+
$(PY) $(SRCDIR)/tools/pb16.py $< $(RESDIR)/$*.pb16
148+
149+
$(RESDIR)/%.pb16.size: $(RESDIR)/%
150+
@$(MKDIR_P) $(@D)
151+
$(call filesize,$<,16) > $(RESDIR)/$*.pb16.size
152+
153+
# Define how to compress files using the PackBits8 codec
154+
# Compressor script requires Python 3
155+
$(RESDIR)/%.pb8: $(RESDIR)/% $(SRCDIR)/tools/pb8.py
156+
@$(MKDIR_P) $(@D)
157+
$(PY) $(SRCDIR)/tools/pb8.py $< $(RESDIR)/$*.pb8
158+
159+
$(RESDIR)/%.pb8.size: $(RESDIR)/%
160+
@$(MKDIR_P) $(@D)
161+
$(call filesize,$<,8) > $(RESDIR)/$*.pb8.size
162+
163+
###############################################
164+
# #
165+
# COMPILATION #
166+
# #
167+
###############################################
168+
169+
# How to build a ROM
170+
$(BINDIR)/%.$(ROMEXT) $(BINDIR)/%.sym $(BINDIR)/%.map: $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRCS))
171+
@$(MKDIR_P) $(@D)
172+
$(RGBASM) $(ASFLAGS) -o $(OBJDIR)/build_date.o $(SRCDIR)/res/build_date.asm
173+
$(RGBLINK) $(LDFLAGS) -m $(BINDIR)/$*.map -n $(BINDIR)/$*.sym -o $(BINDIR)/$*.$(ROMEXT) $^ $(OBJDIR)/build_date.o \
174+
&& $(RGBFIX) -v $(FIXFLAGS) $(BINDIR)/$*.$(ROMEXT)
175+
176+
# `.mk` files are auto-generated dependency lists of the "root" ASM files, to save a lot of hassle.
177+
# Also add all obj dependencies to the dep file too, so Make knows to remake it
178+
# Caution: some of these flags were added in RGBDS 0.4.0, using an earlier version WILL NOT WORK
179+
# (and produce weird errors)
180+
$(OBJDIR)/%.o $(DEPDIR)/%.mk: $(SRCDIR)/%.asm
181+
@$(MKDIR_P) $(patsubst %/,%,$(dir $(OBJDIR)/$* $(DEPDIR)/$*))
182+
$(RGBASM) $(ASFLAGS) -M $(DEPDIR)/$*.mk -MG -MP -MQ $(OBJDIR)/$*.o -MQ $(DEPDIR)/$*.mk -o $(OBJDIR)/$*.o $<
183+
184+
ifneq ($(MAKECMDGOALS),clean)
185+
-include $(patsubst $(SRCDIR)/%.asm,$(DEPDIR)/%.mk,$(SRCS))
186+
endif
187+
188+
# Catch non-existent files
189+
# KEEP THIS LAST!!
190+
%:
191+
@false

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# gb-starter-kit
2+
3+
A customizable and ready-to-compile bundle for Game Boy RGBDS projects. Contains your bread and butter, guaranteed 100% kitchen sink-free.
4+
5+
## Downloading
6+
7+
Downloading this repository requires some extra care, due to it using submodules. (If you know how to handle them, nothing more is needed.)
8+
9+
### Use as a template
10+
11+
You can [make a new repository using this one as a template](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) or click the green "Use this template" button near the top-right of this page.
12+
13+
### Cloning
14+
15+
If cloning this repo from scratch, make sure to pass the `--recursive` flag to `git clone`; if you have already cloned it, you can use `git submodule update --init` within the cloned repo.
16+
17+
If the project fails to build, and either `src/include/hardware.inc/` or `src/include/rgbds-structs/` are empty, try running `git submodule update --init`.
18+
19+
### Download ZIP
20+
21+
You can download a ZIP of this project by clicking the "Code" button next to the aforementioned green "Use this template" one. The resulting ZIP will however not contain the submodules, the files of which you will have to download manually.
22+
23+
## Setting up
24+
25+
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 most scripts in the `src/tools/` folder.
26+
27+
## Customizing
28+
29+
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.
30+
31+
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.
32+
33+
There is "basic" code in place, but some things need your manual intervention. Things requiring manual intervention will print an error message describing what needs to be changed, and a line number.
34+
35+
The file at `src/res/build_date.asm` is compiled individually to include a build date in your ROM. Always comes in handy, and displayed in the bundled error handler.
36+
37+
If you want to add resources, I recommend using the `src/res` folder. Add rules in the Makefile; there are several examples.
38+
39+
It is recommended that the start of your code be in `src/intro.asm`.
40+
41+
## Compiling
42+
43+
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.
44+
45+
While this project is able to compile under "bare" Windows (i.e. without using MSYS2, Cygwin, etc.), it requires PowerShell, and is sometimes unreliable. You should try running `make` two or three times if it errors out.
46+
47+
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.
48+
49+
## See also
50+
51+
If you want something more barebones, check out [gb-boilerplate](https://github.com/ISSOtm/gb-boilerplate).
52+
53+
[Here](https://gist.github.com/ISSOtm/a9057e7c66080f36afcd82ed2863fd62) are the naming conventions used in this code; maybe you'll find them useful.
54+
55+
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 outside of macOS.
56+
57+
### Libraries
58+
59+
- [Variable-width font engine](https://github.com/ISSOtm/gb-vwf)
60+
- [structs in RGBDS](https://github.com/ISSOtm/rgbds-structs)

0 commit comments

Comments
 (0)