Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to build with GBDK 4.3.0 #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.vscode/
gbdk/
Source/obj
mgb.gb
Source/out
mgb.gb
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@ mGB is a Gameboy cartridge program (You need a Flash Cart and Transfer hardware)

![ScreenShot](http://trash80.net/arduinoboy/mGB1_2_0.png)

## Building mGB

Follow the [GBDK-2020 instructions](https://github.com/gbdk-2020/gbdk-2020/tree/develop?tab=readme-ov-file#usage) and unzip v4.3.0+ into the `gbdk/` folder. Then run make:

```
cd Source

make # fast compile
make DEBUG=1 # enable debug symbols
make RELEASE=1 # slower compile but faster on device
make clean # clean up the build directories
```

## Change Log
* 07/05/24
* Project updated to build with [GBDK-2020](https://github.com/gbdk-2020/gbdk-2020) v4.3.0
* 06/26/15
* Project has been moved to GitHub along with sourcecode.
* 12/21/12 1.3.3
Expand Down
73 changes: 61 additions & 12 deletions Source/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,71 @@
BIN=../gbdk-n/bin
OBJ=./obj
# If you move this project you can change the directory
# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/"
ifndef GBDK_HOME
GBDK_HOME = ../gbdk
endif

PROJECTNAME = mGB

LCC = $(GBDK_HOME)/bin/lcc

build:
mkdir -p $(OBJ)
$(BIN)/gbdk-n-compile.sh mgb_save.c -o $(OBJ)/mgb_save.rel -Wa-l -ba0
LCCFLAGS += -msm83:gb # GB/GBC
# LCCFLAGS += -v # verbose
# LCCFLAGS += -autobank

ifdef DEBUG
LCCFLAGS += -debug -v
endif

ifdef RELEASE
LCCFLAGS += -Wf--max-allocs-per-node50000 # A better speed optimization than --opt-code-speed
else
LCCFLAGS += -Wf--opt-code-speed # Optimize for code speed rather than size
endif

# sdcc settings (-Wf and -Wp)
# LCCFLAGS += -Wf--legacy-banking # Use legacy method to call banked functions

# sdasgb (asm) settings (-Wa)
# LCCFLAGS += -Wa-l # generate asm listing
# LCCFLAGS += -Wa-a # All symbols are global
# LCCFLAGS += -Wa-s # Create symbol file/outfile[.sym]
# LCCFLAGS += -Wa-j # Enable NoICE Debug Symbols
# LCCFLAGS += -Wa-y # Enable SDCC Debug Symbols
# LCCFLAGS += -Wa-g # Undefined symbols are global
# LCCFLAGS += -Wa-n # Don't resolve global assigned value symbols
# LCCFLAGS += -Wa-z # Disable case sensitivity for symbols

$(BIN)/gbdk-n-assemble.sh $(OBJ)/mGBASMFunctions.rel mGBASMFunctions.s
$(BIN)/gbdk-n-assemble.sh $(OBJ)/mGBASMSynthFunctions.rel mGBASMSynthFunctions.s
$(BIN)/gbdk-n-assemble.sh $(OBJ)/mGBASMMidiFunctions.rel mGBASMMidiFunctions.s
# sdldgb (linker) settings (-Wl)
# LCCFLAGS += -Wl-m # Map output generated as (out)file[.map]
# LCCFLAGS += -Wl-j # NoICE Debug output as (out)file[.noi]
# LCCFLAGS += -Wl-w # Wide listing format for map file

$(BIN)/gbdk-n-compile.sh mgb.c -o $(OBJ)/mgb.rel -I ./ -Wa-l -Wl-m -Wl-j
# makebin settings (-Wm)
# LCCFLAGS += -Wm-yS # Convert .noi file named like input file to .sym
LCCFLAGS += -Wm-yc # GBC compatible
LCCFLAGS += -Wm-yn"$(PROJECTNAME)" # cartridge name
LCCFLAGS += -Wm-yt3 # MBC type = ROM+MBC1+RAM+BATT
LCCFLAGS += -Wm-ya1 # number of ram banks: -ya 1


OBJ=obj
OUT=out

build:
mkdir -p $(OBJ)
mkdir -p $(OUT)

# mostly so you can see the .asm
$(LCC) $(LCCFLAGS) -c -o $(OBJ)/mGB.rel mGB.c

$(BIN)/gbdk-n-link.sh $(OBJ)/mgb.rel $(OBJ)/mgb_save.rel $(OBJ)/mGBASMFunctions.rel $(OBJ)/mGBASMSynthFunctions.rel $(OBJ)/mGBASMMidiFunctions.rel -o $(OBJ)/mgb.ihx
# SRAM bank 0
$(LCC) $(LCCFLAGS) -Wf-ba0 -c -o $(OBJ)/mgb_save.rel mgb_save.c
$(LCC) $(LCCFLAGS) -o $(OUT)/$(PROJECTNAME).gb $(OBJ)/mGB.rel $(OBJ)/mgb_save.rel *.s

$(BIN)/gbdk-n-make-rom.sh -ya 1 $(OBJ)/mgb.ihx mgb.gb
compile.bat: Makefile
@echo "REM Automatically generated from Makefile" > compile.bat
@make -sn | sed y/\\//\\\\/ | sed s/mkdir\ \-p/mkdir/ | grep -v make >> compile.bat

clean:
rm -rf $(OBJ)
rm -f mgb.gb
rm -rf $(OUT)
8 changes: 8 additions & 0 deletions Source/compile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
REM Automatically generated from Makefile
mkdir obj
mkdir out
# -ba 0 probably not needed anymore
..\..\gbdk-4.3.0\bin\lcc -msm83:gb -Wf--opt-code-speed -Wf--legacy-banking -Wm-yc -Wm-yn"mGB" -Wm-yt3 -Wm-ya1 -c -Wb-ba0 -o obj\mgb_save.rel mgb_save.c
# mostly so you can see the .asm
..\..\gbdk-4.3.0\bin\lcc -msm83:gb -Wf--opt-code-speed -Wf--legacy-banking -Wm-yc -Wm-yn"mGB" -Wm-yt3 -Wm-ya1 -c -o obj\mGB.rel mGB.c
..\..\gbdk-4.3.0\bin\lcc -msm83:gb -Wf--opt-code-speed -Wf--legacy-banking -Wm-yc -Wm-yn"mGB" -Wm-yt3 -Wm-ya1 -o out\mGB.gb obj\mGB.rel obj\mgb_save.rel *.s
147 changes: 91 additions & 56 deletions Source/mGB.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,88 +1,123 @@
#include <gb/gb.h>
#include <mGB.h>
#include "mGB.h"

void printbyte(UBYTE v1, UBYTE v2, UBYTE v3)
{
bkg[0] = (v1 >> 4)+1;
bkg[1] = (0x0F & v1)+1;
void printbyte(UBYTE v1, UBYTE v2, UBYTE v3) {
bkg[0] = (v1 >> 4) + 1;
bkg[1] = (0x0F & v1) + 1;

bkg[2] = 0;
bkg[2] = 0;

bkg[3] = (v2 >> 4)+1;
bkg[4] = (0x0F & v2)+1;
bkg[3] = (v2 >> 4) + 1;
bkg[4] = (0x0F & v2) + 1;

bkg[5] = 0;
bkg[5] = 0;

bkg[6] = (v3 >> 4)+1;
bkg[7] = (0x0F & v3)+1;
bkg[6] = (v3 >> 4) + 1;
bkg[7] = (0x0F & v3) + 1;

bkg[8] = 0;
set_bkg_tiles(1,16,10,1,bkg);
bkg[8] = 0;
set_bkg_tiles(1, 16, 10, 1, bkg);
}

#include <mGBSynthPitchFunctions.c>
#include <mGBSynthCommonFunctions.c>
#include <mGBDisplayFunctions.c>
#include <mGBMemoryFunctions.c>
#include <mGBUserFunctions.c>
#include "mGBDisplayFunctions.c"
#include "mGBMemoryFunctions.c"
#include "mGBMidiFunctions.c"
#include "mGBSynthCommonFunctions.c"
#include "mGBSynthPitchFunctions.c"
#include "mGBUserFunctions.c"
#include "serial.c"

void setSoundDefaults()
{
NR52_REG = 0x8FU; //Turn sound on
NR50_REG = 0x77U; //Turn on Pulses outs
void setSoundDefaults(void) {
rAUDENA = 0x8FU; // Turn sound on
rAUDVOL = 0x77U; // Turn on Pulses outs

setOutputPan(0U, 64U);
setOutputPan(1U, 64U);
setOutputPan(2U, 64U);
setOutputPan(3U, 64U);

asmLoadWav(wavDataOffset); //tRIANGLE
NR32_REG = 0x00U;
asmLoadWav(wavDataOffset); // tRIANGLE
rAUD3LEVEL = 0x00U;

NR44_REG = 0x80U;
NR41_REG = 0x3FU; //sound length
rAUD4GO = 0x80U;
rAUD4LEN = 0x3FU; // sound length
}

void testSynths()
{
addressByte = 0x40;
valueByte = 0x7F;
asmPlayNotePu1();
void testSynths(void) {
addressByte = 0x40;
valueByte = 0x7F;
asmPlayNotePu1();
}

void main(void) {

void main()
{
disable_interrupts();
cpu_fast();
checkMemory();
displaySetup();
setSoundDefaults();
add_TIM(updateSynths);

loadDataSet(0x00U);
loadDataSet(0x01U);
loadDataSet(0x02U);
loadDataSet(0x03U);
enable_interrupts();
CRITICAL {
cpu_fast();
checkMemory();
displaySetup();
setSoundDefaults();
add_TIM(updateSynths);

loadDataSet(0x00U);
loadDataSet(0x01U);
loadDataSet(0x02U);
loadDataSet(0x03U);
}

/* Set TMA to divide clock by 0x100 */
TMA_REG = 0x00U;
rTMA = 0x00U;
/* Set clock to 262144 Hertz */
TAC_REG = 0x05U;
rTAC = TACF_START | TACF_262KHZ;
/* Handle VBL and TIM interrupts */

set_interrupts(VBL_IFLAG | TIM_IFLAG | SIO_IFLAG);

SHOW_BKG;
SHOW_SPRITES;
SHOW_BKG;
SHOW_SPRITES;

showSplashScreen();
delay(2000);
showSplashScreen();
delay(2000);

showMainScreen();
printversion();
//testSynths();
asmMain();
showMainScreen();
printversion();
// testSynths();
gameMain();
}

inline void gameMain(void) {
rSC = SIOF_XFER_START | SIOF_CLOCK_EXT;
while (1) {
systemIdle = 1;

updateMidiBuffer();

if (systemIdle)
getPad();

if (systemIdle)
asmUpdatePu1();

if (systemIdle)
asmUpdatePu2();

if (systemIdle)
asmUpdateWav();

if (systemIdle)
asmUpdateNoi();

if (systemIdle)
mainScreen();
}
}

void mainScreen(void) {
if (currentScreen == 0) {
return;
};

updateDisplaySynthCounter = (updateDisplaySynthCounter + 1) & 3U;

updateDisplaySynth();
// printbyte(statusByte, addressByte, valueByte);
setPlayMarker();
}
Loading