Skip to content

Commit

Permalink
first commit yay!
Browse files Browse the repository at this point in the history
  • Loading branch information
marcrobledo committed Feb 9, 2024
1 parent 685d0e0 commit 6c6e727
Show file tree
Hide file tree
Showing 33 changed files with 3,322 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/rgbds/*
!/rgbds/place rgbds here.txt
/roms/*
!/roms/place original rom here.txt
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ MIT License

Copyright (c) 2024 Marc Robledo

This project incorporates components from Octicons
(https://github.com/primer/octicons/) Copyright (c) 2022 GitHub Inc.,
also released under MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Super Game Boy Border Injector
==============================

This project contains code designed to inject a custom Super Game Boy Border into any Game Boy ROM in the most possible user-friendly way.

It comes in two different implementations:
- Web implementation
- ASM implementation



## Web implementation
This is probably what everyone is looking for: a simple [web app](https://www.marcrobledo.com/super-game-boy-border-converter/) that does the magic for you!

Just select your desired ROM and Super Game Boy border data and the app will build the SGB compatible ROM with your border and even custom palette.

You might probably need [Super Game Boy Border Converter](https://github.com/marcrobledo/super-game-boy-border-converter/), which will convert any image to the needed data the injector asks for.

This web injector just automatizes the process of injecting the assembled code from the ASM implementation below.



## ASM implementation
This [RGBDS](https://github.com/gbdev/rgbds) skeleton project allows you to inject a custom Super Game Boy Border to any Game Boy ROM.

Thanks to [xenophile](https://github.com/xenophile127), [Imanol Barriuso](https://github.com/imanolea) and [nitro2k01](https://github.com/nitro2k01) for their help!

### How to compile
1. Get [RGBDS](https://rgbds.gbdev.io/install) and unzip it at `rgbds` folder.
2. Place the game you are going to patch as `roms/input.gb` file.
3. Read `src/settings.asm` carefully and edit it, filling all needed offsets and constants for your game.
4. Compile with `assemble.bat` (Windows) or `assemble.sh` (Unix).
5. If there were no errors, a ROM `roms/output.gb` will be created.
31 changes: 31 additions & 0 deletions assemble.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@echo off

SET SOURCE_FILENAME=input.gb
SET TARGET_FILENAME=output.gb



REM delete current assembled rom
IF EXIST .\roms\%TARGET_FILENAME% del .\roms\%TARGET_FILENAME%

SET OBJ_FILENAME=%TARGET_FILENAME:.gb=.obj%
SET SYM_FILENAME=%TARGET_FILENAME:.gb=.sym%

cd src
:begin
set assemble=1
echo assembling...
..\rgbds\rgbasm -o%OBJ_FILENAME% main.asm
if errorlevel 1 goto error
echo linking...
REM -n generates a sym file with subroutines name and offsets for debugger
..\rgbds\rgblink -o../roms/%TARGET_FILENAME% -O./../roms/%SOURCE_FILENAME% -n../roms/%SYM_FILENAME% %OBJ_FILENAME%
if errorlevel 1 goto error
echo fixing...
..\rgbds\rgbfix -p0 -v ../roms/%TARGET_FILENAME%
del %OBJ_FILENAME%
goto end
:error
pause
:end
cd..
32 changes: 32 additions & 0 deletions assemble.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

source_filename='input.gb'
target_filename='output.gb'

if [ -f $target_filename ]; then
rm $target_filename
fi

cd src
export assemble=1

echo "assembling..."
../rgbds/rgbasm -ooutput.obj main.asm
if [ $? -eq 1 ]
then
echo "Failed assembling"
exit 1
fi

echo "linking..."
../rgbds/rgblink -o../roms/$target_filename -O./../roms/$source_filename -n../roms/output.sym output.obj
if [ $? -eq 1 ]
then
echo "Failed linking"
exit 1
fi

echo "fixing..."
../rgbds/rgbfix -p0 -v ../roms/$target_filename
rm output.obj
cd ..
7 changes: 7 additions & 0 deletions clean.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

SET TARGET_FILENAME=output.gb

del roms\%TARGET_FILENAME%
del roms\*.sym
del src\*.obj
58 changes: 58 additions & 0 deletions example/kid_dracula/settings.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
; ------------------------------------------------------------------------------
; Super Game Boy border injector for Kid Dracula
; by Marc Robledo 2024
;
; More info at https://github.com/marcrobledo/super-game-boy-border-injector
; ------------------------------------------------------------------------------



; GAME BOOT OFFSET
; ----------------
; Put here the game's boot jp offset found in in $0101.
; Usually $0150, but could be different depending on game.
DEF GAME_BOOT_OFFSET EQU $0150



; BANK 0 ROM FREE SPACE
; ---------------------
; 16 bytes in bank 0 are needed for the game's boot hook subroutine.
; Hopefully, there should be enough space at the end of bank 0 or in the
; interruption or rst vector ($0000-$00ff).
; In the worst scenario, you will need to carefully move some code/data to
; other banks.
DEF BANK0_FREE_SPACE EQU $3fd0



; NEW CODE LOCATION
; -----------------
; We need an empty bank to store all new code plus border data, which will be
; quite big.
; If the game has no empty bank, just use a bank higher than the original
; game's bank number, RGBDS will expand the ROM and fix the header.
; Safe bank numbers, depending on original game's ROM size:
; - 32kb --> impossible to do it without changing MBC
; - 64kb --> bank $04
; - 128kb --> bank $08
; - 256kb --> bank $10
; - 512kb --> bank $20
; - 1024kb --> bank $40
DEF SGB_CODE_BANK EQU $10



; CUSTOM GB PALETTE
; -----------------
; set CUSTOM_GB_PALETTE_ENABLED to 1 if you want a custom GB palette for the
; entire game screen
; colors are RGB15 which means RGB components can go from 0 up to 31
; warning: even if set to 0, do not delete BUILD_CUSTOM_GB_PALETTE macro!
DEF CUSTOM_GB_PALETTE_ENABLED EQU 1
MACRO BUILD_CUSTOM_GB_PALETTE
RGB 29, 30, 26 ;color 0 (light)
RGB 30, 18, 4 ;color 1
RGB 9, 7, 18 ;color 2
RGB 3, 0, 5 ;color 3 (dark)
ENDM
Binary file added example/kid_dracula/sgb_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/kid_dracula/sgb_border_map.bin
Binary file not shown.
Binary file added example/kid_dracula/sgb_border_palettes.bin
Binary file not shown.
Binary file added example/kid_dracula/sgb_border_tiles.bin
Binary file not shown.
1 change: 1 addition & 0 deletions rgbds/place rgbds here.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
download at https://github.com/gbdev/rgbds/releases
1 change: 1 addition & 0 deletions roms/place original rom here.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
place original ROM as "input.gb"
Loading

0 comments on commit 6c6e727

Please sign in to comment.