git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 9bc0c38eecc2acb892508628da75dbc45332abe8
parent 99c2e580b7223fc5115c73a7d27e2e42367dca53
Author: Toxa <untoxa@mail.ru>
Date:   Sun, 20 Jul 2025 00:58:20 +0300

EXAMPLES: SMS: the NMI handler example

Diffstat:
Agbdk-lib/examples/sms/pause_button/Makefile68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/sms/pause_button/Readme.md2++
Agbdk-lib/examples/sms/pause_button/src/pause.c22++++++++++++++++++++++
3 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/gbdk-lib/examples/sms/pause_button/Makefile b/gbdk-lib/examples/sms/pause_button/Makefile @@ -0,0 +1,68 @@ +# +# A Makefile that compiles all .c and .s files in "src" and "res" +# subdirectories and places the output in a "obj" subdirectory +# + +# 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 = ../../../ +endif + +LCC = $(GBDK_HOME)bin/lcc + + +# GBDK_DEBUG = ON +ifdef GBDK_DEBUG + LCCFLAGS += -debug -v +endif + +# You can set flags for LCC here +# For example, you can uncomment the line below to turn on debug output +LCCFLAGS += -mz80:sms -autobank + +# You can set the name of the .gb ROM file here +PROJECTNAME = pause + +SRCDIR = src +OBJDIR = obj +RESDIR = res +BINS = $(OBJDIR)/$(PROJECTNAME).sms +CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c))) +ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) +OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) + +all: prepare $(BINS) + +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 + +# Compile .c files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(LCC) $(LCCFLAGS) -c -o $@ $< + +# Compile .c files in "res/" to .o object files +$(OBJDIR)/%.o: $(RESDIR)/%.c + $(LCC) $(LCCFLAGS) -c -o $@ $< + +# Compile .s assembly files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.s + $(LCC) $(LCCFLAGS) -c -o $@ $< + +# If needed, compile .c files in "src/" to .s assembly files +# (not required if .c is compiled directly to .o) +$(OBJDIR)/%.s: $(SRCDIR)/%.c + $(LCC) $(LCCFLAGS) -S -o $@ $< + +# Link the compiled object files into a .gb ROM file +$(BINS): $(OBJS) + $(LCC) $(LCCFLAGS) -o $(BINS) $(OBJS) + +prepare: + mkdir -p $(OBJDIR) $(RESDIR) + +clean: +# rm -f *.gb *.ihx *.cdb *.adb *.noi *.map + rm -f $(OBJDIR)/*.* + diff --git a/gbdk-lib/examples/sms/pause_button/Readme.md b/gbdk-lib/examples/sms/pause_button/Readme.md @@ -0,0 +1,2 @@ + +Demonstration of how to create the NMI handler diff --git a/gbdk-lib/examples/sms/pause_button/src/pause.c b/gbdk-lib/examples/sms/pause_button/src/pause.c @@ -0,0 +1,22 @@ +#include <gbdk/platform.h> +#include <stdio.h> +#include <stdbool.h> + +volatile bool PauseRequested = false; + +void NMI_ISR (void) CRITICAL INTERRUPT { // the function name MUST be "NMI_ISR" + PauseRequested = true; +} + +void main(void) { + puts("Press PAUSE button"); + while(1) { + if (PauseRequested) { + puts("PAUSED! press A to unpause"); + waitpad(J_A); + puts("UNPAUSED"); + PauseRequested = false; + } + wait_vbl_done(); + } +}

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.