gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 32123ded27a630a90472a53d3af6c6dbf8819f90 parent a5edf665a1e7679d2523951879e0b60ec6c27c6c Author: bbbbbr <bbbbbr@users.noreply.github.com> Date: Fri, 18 Jul 2025 13:33:04 -0700 Merge pull request #789 from EV3lindaboi/develop (MBC5 Rumble) Rumble Pak example Diffstat:
| A | gbdk-lib/examples/gb/mbc5_rumble/Makefile | 98 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | gbdk-lib/examples/gb/mbc5_rumble/Makefile.targets | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | gbdk-lib/examples/gb/mbc5_rumble/Readme.md | 15 | +++++++++++++++ |
| A | gbdk-lib/examples/gb/mbc5_rumble/src/main.c | 20 | ++++++++++++++++++++ |
| A | gbdk-lib/examples/gb/mbc5_rumble/src/mbc5_rumble.c | 27 | +++++++++++++++++++++++++++ |
| A | gbdk-lib/examples/gb/mbc5_rumble/src/mbc5_rumble.h | 13 | +++++++++++++ |
6 files changed, 227 insertions(+), 0 deletions(-)
diff --git a/gbdk-lib/examples/gb/mbc5_rumble/Makefile b/gbdk-lib/examples/gb/mbc5_rumble/Makefile @@ -0,0 +1,98 @@ +# 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 + +# Set platforms to build here, spaced separated. (These are in the separate Makefile.targets) +# They can also be built/cleaned individually: "make gg" and "make gg-clean" +# Possible are: gb gbc pocket megaduck sms gg +TARGETS= gb # gb pocket megaduck sms gg nes + +# Configure platform specific LCC flags here: +LCCFLAGS_gb = -Wl-yt0x1E -Wm-ya4 # Set an MBC for banking (0x1E: ROM+MBC5+RUMBLE+SRAM+BATT) with 4 cart SRAM banks +LCCFLAGS_pocket = -Wl-yt0x1E -Wm-ya4 # Usually the same as required for .gb +LCCFLAGS_duck = # -Wl-yt0x1E -Wm-ya4 # Usually the same as required for .gb +LCCFLAGS_gbc = -Wl-yt0x1E -Wm-ya4 -Wm-yc # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive) +LCCFLAGS_sms = +LCCFLAGS_gg = +LCCFLAGS_nes = + +LCCFLAGS += $(LCCFLAGS_$(EXT)) # This adds the current platform specific LCC Flags + +LCCFLAGS += -Wl-j # -Wm-yS -Wm-yoA -Wm-ya4 -autobank -Wb-ext=.rel -Wb-v # MBC + Autobanking related flags +# LCCFLAGS += -debug # Uncomment to enable debug output +# LCCFLAGS += -v # Uncomment for lcc verbose output +LCCFLAGS += -Wf-MMD -Wf-Wp-MP # Header file dependency output (-MMD) for Makefile use + per-header Phony rules (-MP) +CFLAGS += -Wf-MMD -Wf-Wp-MP # Header file dependency output (-MMD) for Makefile use + per-header Phony rules (-MP) + +# You can set the name of the ROM file here +PROJECTNAME = mbc5_rumble + +# EXT?=gb # Only sets extension to default (game boy .gb) if not populated +SRCDIR = src +OBJDIR = obj/$(EXT) +RESDIR = res +BINDIR = build/$(EXT) +MKDIRS = $(OBJDIR) $(BINDIR) # See bottom of Makefile for directory auto-creation + +BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT) +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) + +# Dependencies (using output from -Wf-MMD -Wf-Wp-MP) +DEPS = $(OBJS:%.o=%.d) + +-include $(DEPS) + +# Builds all targets sequentially +all: $(TARGETS) + +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 + +test: + echo $(CSOURCES) + + +# Compile .c files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(LCC) $(CFLAGS) -c -o $@ $< + +# Compile .c files in "res/" to .o object files +$(OBJDIR)/%.o: $(RESDIR)/%.c + $(LCC) $(CFLAGS) -c -o $@ $< + +# Compile .s assembly files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.s + $(LCC) $(CFLAGS) -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) $(CFLAGS) -S -o $@ $< + +# Link the compiled object files into a .gb ROM file +$(BINS): $(OBJS) + $(LCC) $(LCCFLAGS) $(CFLAGS) -o $(BINDIR)/$(PROJECTNAME).$(EXT) $(OBJS) + +clean: + @echo Cleaning + @for target in $(TARGETS); do \ + $(MAKE) $$target-clean; \ + done + +# Include available build targets +include Makefile.targets + + +# create necessary directories after Makefile is parsed but before build +# info prevents the command from being pasted into the makefile +ifneq ($(strip $(EXT)),) # Only make the directories if EXT has been set by a target +$(info $(shell mkdir -p $(MKDIRS))) +endif diff --git a/gbdk-lib/examples/gb/mbc5_rumble/Makefile.targets b/gbdk-lib/examples/gb/mbc5_rumble/Makefile.targets @@ -0,0 +1,54 @@ + +# Platform specific flags for compiling (only populate if they're both present) +ifneq ($(strip $(PORT)),) +ifneq ($(strip $(PLAT)),) +CFLAGS += -m$(PORT):$(PLAT) +endif +endif + +# Called by the individual targets below to build a ROM +build-target: $(BINS) + +clean-target: + rm -rf $(OBJDIR) + rm -rf $(BINDIR) + +gb-clean: + ${MAKE} clean-target EXT=gb +gb: + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb + + +gbc-clean: + ${MAKE} clean-target EXT=gbc +gbc: + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc + + +pocket-clean: + ${MAKE} clean-target EXT=pocket +pocket: + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket + + +megaduck-clean: + ${MAKE} clean-target EXT=duck +megaduck: + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck + + +sms-clean: + ${MAKE} clean-target EXT=sms +sms: + ${MAKE} build-target PORT=z80 PLAT=sms EXT=sms + + +gg-clean: + ${MAKE} clean-target EXT=gg +gg: + ${MAKE} build-target PORT=z80 PLAT=gg EXT=gg + +nes-clean: + ${MAKE} clean-target EXT=nes +nes: + ${MAKE} build-target PORT=mos6502 PLAT=nes EXT=nes diff --git a/gbdk-lib/examples/gb/mbc5_rumble/Readme.md b/gbdk-lib/examples/gb/mbc5_rumble/Readme.md @@ -0,0 +1,14 @@ +# GBDK example for using the Rumble motor on the Game Boy MBC5 Cartridge +This example demonstrates using the Rumble motor that can be on MBC5 cartridges +The Rumble motor was infamously used in Pokemon Pinball + +# Makefile MBC +You need to use one of the following MBCs in the Makefile: +0x1C: ROM+MBC5+RUMBLE +0x1D: ROM+MBC5+RUMBLE+SRAM +0x1E: ROM+MBC5+RUMBLE+SRAM+BATT +In this example the last one is used. You can change it in the LCCFLAGS + +# Emulators +Not every emulator supports Rumble, and most of the ones that do only work +when you plug a controller. + diff --git a/gbdk-lib/examples/gb/mbc5_rumble/src/main.c b/gbdk-lib/examples/gb/mbc5_rumble/src/main.c @@ -0,0 +1,20 @@ +#include <gbdk/platform.h> +#include <stdint.h> +#include <stdio.h> +#include "mbc5_rumble.h" + +void main(void) +{ + printf("GBDK Rumble Example.\n"); + printf("Press A for a strongRumble.\n"); + printf("Press B for a weak\nRumble.\n"); + while(1) { + if(joypad() & J_A) + MBC5_RUMBLE_MAX(); + else if (joypad() & J_B) + MBC5_RUMBLE_LOW(); + else + MBC5_RUMBLE_OFF; + vsync(); + } +} diff --git a/gbdk-lib/examples/gb/mbc5_rumble/src/mbc5_rumble.c b/gbdk-lib/examples/gb/mbc5_rumble/src/mbc5_rumble.c @@ -0,0 +1,26 @@ +#include <gbdk/platform.h> +#include <stdint.h> +#define MBC_RUMBLE_BIT_ON 0b00001000u +#define MBC_RUMBLE_BIT_OFF 0b00000000u +#define MBC5_RUMBLE_ON SWITCH_RAM_MBC5(0 | MBC_RUMBLE_BIT_ON) +#define MBC5_RUMBLE_OFF SWITCH_RAM_MBC5(0 | MBC_RUMBLE_BIT_OFF) + +uint8_t rumble_counter = 0; + +void MBC5_RUMBLE_LOW(void) +{ + rumble_counter++; + if(rumble_counter%4==0)MBC5_RUMBLE_ON; + else MBC5_RUMBLE_OFF; +} +void MBC5_RUMBLE_MED(void) +{ + rumble_counter++; + if(rumble_counter%2==0)MBC5_RUMBLE_ON; + else MBC5_RUMBLE_OFF; +} + +void MBC5_RUMBLE_MAX(void) +{ + MBC5_RUMBLE_ON; +} + diff --git a/gbdk-lib/examples/gb/mbc5_rumble/src/mbc5_rumble.h b/gbdk-lib/examples/gb/mbc5_rumble/src/mbc5_rumble.h @@ -0,0 +1,12 @@ +#include <gbdk/platform.h> +#include <stdint.h> +#ifndef MBC5_RUMBLE_H_ +#define MBC5_RUMBLE_H_ +#define MBC_RUMBLE_BIT_ON 0b00001000u +#define MBC_RUMBLE_BIT_OFF 0b00000000u +#define MBC5_RUMBLE_ON SWITCH_RAM_MBC5(0 | MBC_RUMBLE_BIT_ON) +#define MBC5_RUMBLE_OFF SWITCH_RAM_MBC5(0 | MBC_RUMBLE_BIT_OFF) +void MBC5_RUMBLE_LOW(void); +void MBC5_RUMBLE_MED(void); +void MBC5_RUMBLE_MAX(void); +#endif +
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.