Compare commits

..

10 Commits

Author SHA1 Message Date
55392b1acc new stuff idk 2026-03-03 23:48:15 -06:00
ISSOtm
b69c9b91dc Repoint URLs to Codeberg 2025-09-24 21:38:50 +02:00
ISSOtm
2fca4a9a09 Update hardware.inc 2025-05-20 14:49:27 +02:00
ISSOtm
a2e82037df Correctly force refreshing the build date
Fixes #6
2025-05-05 17:11:18 -04:00
Pierre Wacrenier
1d49826117 Vendor hardware.inc 2025-01-17 12:13:55 +01:00
Robbi Blechdose
a74131c1be Renamed license file and added explanatory paragraph to README 2024-05-08 00:01:33 +02:00
ISSOtm
94ea749c25 Fix build errors on Windows
Thanks to @ghostsoft for help testing this!
2023-11-24 12:38:47 +01:00
ISSOtm
22850286e5 Remove tool obsoleted by RGBGFX 0.6.0 2023-11-05 17:23:30 +01:00
ISSOtm
21a66fb027 Include hardware.inc by default 2023-11-05 17:22:56 +01:00
ISSOtm
860170ebc1 Update hardware.inc 2023-11-05 17:22:10 +01:00
19 changed files with 1487 additions and 55 deletions

3
.gitignore vendored
View File

@@ -2,3 +2,6 @@
/obj/
/dep/
/assets/
src/*.2bpp
src/*.tilemap

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "src/include/hardware.inc"]
path = include/hardware.inc
url = https://github.com/gbdev/hardware.inc.git

18
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "emulicious-debugger",
"request": "launch",
"name": "Launch in Emulicious",
"program": "./bin/binx.gb",
"host": "172.19.64.1",
"port": 58870,
"stopOnEntry": true
}
]
}

View File

@@ -2,6 +2,7 @@
"rgbdsz80.includePath": [
"src/",
"src/constants",
"src/macros"
"src/macros",
"include"
]
}

19
LICENSE
View File

@@ -1,19 +0,0 @@
zlib License
Copyright (c) 2020-2022 Eldred Habert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

View File

@@ -10,7 +10,7 @@ RM_RF := rm -rf
MKDIR_P := mkdir -p
ifeq ($(strip $(shell which rm)),)
# Windows *really* tries its hardest to be Special™!
RM_RF := -del /q
RM_RF := -rmdir /s /q
MKDIR_P := -mkdir
endif
@@ -60,14 +60,14 @@ VPATH := src
# Define how to compress files using the PackBits16 codec.
# (The compressor script requires Python 3.)
assets/%.pb16: src/tools/pb16.py assets/%
@${MKDIR_P} ${@D}
@${MKDIR_P} "${@D}"
$^ $@
# How to build a ROM.
# Notice that the build date is always refreshed.
bin/%.${ROMEXT}: $(patsubst src/%.asm,obj/%.o,${SRCS})
@${MKDIR_P} ${@D}
${RGBASM} ${ASFLAGS} -o obj/build_date.o src/assets/build_date.asm
@${MKDIR_P} "${@D}"
${RGBASM} ${ASFLAGS} -o obj/lib/build_date.o src/lib/build_date.asm
${RGBLINK} ${LDFLAGS} -m bin/$*.map -n bin/$*.sym -o $@ $^ \
&& ${RGBFIX} -v ${FIXFLAGS} $@
@@ -76,7 +76,7 @@ bin/%.${ROMEXT}: $(patsubst src/%.asm,obj/%.o,${SRCS})
# Caution: some of these flags were added in RGBDS 0.4.0, using an earlier version WILL NOT WORK
# (and produce weird errors).
obj/%.mk: src/%.asm
@${MKDIR_P} ${@D}
@${MKDIR_P} "${@D}"
${RGBASM} ${ASFLAGS} -M $@ -MG -MP -MQ ${@:.mk=.o} -MQ $@ -o ${@:.mk=.o} $<
# DO NOT merge this with the rule above, otherwise Make will assume that the `.o` file is generated,
# even when it isn't!

View File

@@ -25,6 +25,14 @@ Always comes in handy.
If you want to add resources, I recommend using the `src/assets` directory.
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)).
## Licensing
You must keep LICENSE-gb-boilerplate in your repository, but it will not affect the rest of your project (i.e. your files).
Attribution in the README is appreciated, for instance like this:
```
This project uses the [gb-boilerplate](https://codeberg.org/ISSOtm/gb-boilerplate) template by ISSOtm, under the zlib license.
```
## Compiling
Simply open you favorite command prompt / terminal, place yourself in this directory (the one the Makefile is located in), and run the command `make`.
@@ -40,7 +48,7 @@ If that still doesn't work, feel free to ask for help.
## See also
If you want something less barebones, already including some "base" code, check out [gb-starter-kit](https://github.com/ISSOtm/gb-starter-kit).
If you want something less barebones, already including some "base" code, check out [gb-starter-kit](https://codeberg.org/ISSOtm/gb-starter-kit).
Perhaps [a gbdev style guide](https://gbdev.io/guides/asmstyle) may be of interest to you?
@@ -49,5 +57,5 @@ I recommend the [BGB](https://bgb.bircd.org) emulator for developing ROMs on Win
### Libraries
- [Variable-width font engine](https://github.com/ISSOtm/gb-vwf)
- [Structs in RGBDS](https://github.com/ISSOtm/rgbds-structs)
- [Variable-width font engine](https://codeberg.org/ISSOtm/gb-vwf)
- [Structs in RGBDS](https://codeberg.org/ISSOtm/rgbds-structs)

1157
include/hardware.inc Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
# Value that the ROM will be filled with.
PADVALUE := 0xFF
PADVALUE := 0x00
## Header constants (passed to RGBFIX).
@@ -11,10 +11,10 @@ PADVALUE := 0xFF
VERSION := 0
# 4-ASCII letter game ID.
GAMEID := BOIL
GAMEID := BINX
# Game title, up to 11 ASCII chars.
TITLE := BOILERPLATE
TITLE := BINX
# New licensee, 2 ASCII chars.
# Homebrew games FTW!.
@@ -36,7 +36,7 @@ MBC := 0x00
SRAMSIZE := 0x00
# ROM name.
ROMNAME := boilerplate
ROMNAME := binx
ROMEXT := gb

6
scripts/update_hardware_inc.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
HARDWARE_INC_URL='https://raw.githubusercontent.com/gbdev/hardware.inc/refs/heads/master/hardware.inc'
GIT_ROOT=$(git rev-parse --show-toplevel)
curl "${HARDWARE_INC_URL}" -o "${GIT_ROOT}/include/hardware.inc"

1
src/data.asm Normal file
View File

@@ -0,0 +1 @@
if !DEF(DATA_ASM)

23
src/game.asm Normal file
View File

@@ -0,0 +1,23 @@
if !def(GAME_INC)
DEF GAME_INC EQU 1
INCLUDE "hardware.inc"
rev_Check_hardware_inc 5.3.0
INCLUDE "input.asm"
INCLUDE "util.asm"
INCLUDE "ram.asm"
SECTION FRAGMENT "Game", ROM0
loop: ; Main Loop
call WaitVBlank
call RUN_DMA
call HandleDirectionInput
jr loop
done:
jr done
endc ; game_inc

View File

@@ -1,21 +1,68 @@
INCLUDE "hardware.inc"
rev_Check_hardware_inc 5.3.0
INCLUDE "util.asm"
INCLUDE "ram.asm"
INCLUDE "data.asm"
INCLUDE "game.asm"
INCLUDE "input.asm"
INCLUDE "screen.asm"
SECTION "Header", ROM0[$100]
; This is your ROM's entry point
; You have 4 bytes of code to do... something
di
jp EntryPoint
; Make sure to allocate some space for the header, so no important
; code gets put there and later overwritten by RGBFIX.
; RGBFIX is designed to operate over a zero-filled header, so make
; sure to put zeros regardless of the padding value. (This feature
; was introduced in RGBDS 0.4.0, but the -MG etc flags were also
; introduced in that version.)
ds $150 - @, 0
SECTION "Entry point", ROM0
EntryPoint:
; Here is where the fun begins, happy coding :)
jr @
; turn off audio
ld a, $00
ld [rNR52], a
call WaitVBlank
; turn the LCD off, but wait for VBlank first
ld a, $00
ld [rLCDC], a
; Copy the DMA proc to HRAM
ld de, RUN_DMA
ld hl, DMA_Stub
ld bc, DMA_Stub.End - DMA_Stub
call CopyData
; Clear shadow OAM
call ResetShadowOAM
; Load tile data
ld de, $9000
ld hl, TestLevelTileData
ld bc, TestLevelTileData.End - TestLevelTileData
call CopyData
; Load level tilemap
ld de, $9800
ld hl, TestLevelTileMap
ld bc, TestLevelTileMap.End - TestLevelTileMap
call CopyData
; Set the scroll registers
ld a, $00
ld [rSCY], a
ld [rSCX], a
; Initialize scroll speed counter
ld a, $00
ld [INPUT_COUNTER_ADDR], a
; Set the pallets
ld a, %11100100
ld [rBGP], a
; Turn on the display
ld a, %11000001
ld [rLCDC], a
jp loop

121
src/input.asm Normal file
View File

@@ -0,0 +1,121 @@
if !def(INPUT_INC)
DEF INPUT_INC EQU 1
INCLUDE "hardware.inc"
rev_Check_hardware_inc 5.3.0
INCLUDE "ram.asm"
SECTION FRAGMENT "Input", ROM0
DEF DPAD_BUTTON_MASK EQU %11101111
DEF RIGHT_DPAD_MASK EQU %00000001
DEF LEFT_DPAD_MASK EQU %00000010
DEF UP_DPAD_MASK EQU %00000100
DEF DOWN_DPAD_MASK EQU %00001000
DEF COUNTER_TICKRATE EQU 10
; register b will contain the direction button data
ReadDirectionButtons:
ld a, DPAD_BUTTON_MASK
ld [rJOYP], a
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld b, a
ret
HandleDirectionInput:
; load counter and check
ld a, [INPUT_COUNTER_ADDR]
cp a, COUNTER_TICKRATE
jr c, .ret ; return if we haven't hit the tickrate
call ReadDirectionButtons ; b = input data
ld a, b
ld a, b
and a, RIGHT_DPAD_MASK
call z, PressRight
ld a, b
and a, LEFT_DPAD_MASK
call z, PressLeft
ld a, b
and a, UP_DPAD_MASK
call z, PressUp
ld a, b
and a, DOWN_DPAD_MASK
call z, PressDown
; reset the counter
ld a, $00
ld [INPUT_COUNTER_ADDR], a
.ret
; increment the counter on every call
ld a, [INPUT_COUNTER_ADDR]
inc a
ld [INPUT_COUNTER_ADDR], a
ret
PressLeft:
push af
ld a, [rSCX]
or a, a
jr z, .ret
dec a
ld [rSCX], a
.ret:
pop af
ret
PressRight:
push af
ld a, [rSCX]
add a, 159
jr c, .ret ; c is set if we go above 255, which means past this tileset
ld a, [rSCX]
inc a
ld [rSCX], a
.ret:
pop af
ret
PressUp:
push af
ld a, [rSCY]
or a, a
jr z, .ret
dec a
ld [rSCY], a
.ret
pop af
ret
PressDown:
push af
ld a, [rSCY]
add a, 143
jr c, .ret ; c is set if we go above 255, which means past this tileset
inc a
ld [rSCY], a
.ret:
pop af
ret
endc ; input_inc

10
src/ram.asm Normal file
View File

@@ -0,0 +1,10 @@
if !def(RAM_INC)
DEF RAM_INC EQU 1
DEF WRAM_START EQU $C000
DEF SHADOW_OAM_ADDR EQU WRAM_START
DEF RUN_DMA EQU $FF80
DEF INPUT_COUNTER_ADDR EQU $C100
endc ; ram_inc

10
src/screen.asm Normal file
View File

@@ -0,0 +1,10 @@
if !def(SCREEN_INC)
DEF SCREEN_INC EQU 1
INCLUDE "hardware.inc"
rev_Check_hardware_inc 5.3.0
SECTION FRAGMENT "Input", ROM0
endc ; screen_inc

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env python3
from sys import argv
with open(argv[1], "rb") as input:
with open(argv[2], "wb") as output:
output.write(bytes((byte ^ 0x80 for byte in input.read())))

58
src/util.asm Normal file
View File

@@ -0,0 +1,58 @@
if !def(UTIL_INC)
DEF UTIL_INC EQU 1
INCLUDE "hardware.inc"
rev_Check_hardware_inc 5.3.0
SECTION FRAGMENT "Utilities", ROM0
WaitVBlank:
ldh a, [rLY]
cp 144 ;
jr c, WaitVBlank
ret
; Params
; de: dest
; hl: source
; bc: size
CopyData:
ld a, [hli]
ld [de], a
inc de
dec bc
ld a, b
or c
jr nz, CopyData
ret
; Needs to be copied to HRAM
DMA_Stub:
ld a, HIGH($C100)
ldh [$FF46], a ; start DMA transfer (starts right after instruction)
ld a, 40 ; delay for a total of 4×40 = 160 M-cycles
.wait
dec a ; 1 M-cycle
jr nz, .wait ; 3 M-cycles
ret
.End
ResetShadowOAM:
ld bc, $F9
ld de, $C100
.copy
ld a, 0
ld [de], a
inc de
dec bc
ld a, b
or c
jr nz, .copy
ret
endc ; util_inc