gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 2dba64d663a3f5eabccd510fedeebd368d5ab9cc parent fbd765331322fd54f9e9117ea8ac2cb3df7460c3 Author: bbbbbr <bbbbbr@users.noreply.github.com> Date: Wed, 23 Oct 2024 03:11:49 -0700 Merge pull request #723 from bbbbbr/examples/mbc7_accelerometer Examples: MBC7 support and example Diffstat:
24 files changed, 570 insertions(+), 0 deletions(-)
diff --git a/gbdk-lib/examples/gb/mbc7_accelerometer/Makefile b/gbdk-lib/examples/gb/mbc7_accelerometer/Makefile @@ -0,0 +1,94 @@ +# 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-yt0x22 # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT) +LCCFLAGS_pocket = -Wl-yt0x22 # Usually the same as required for .gb +LCCFLAGS_duck = # -Wl-yt0x1B # Usually the same as required for .gb +LCCFLAGS_gbc = -Wl-yt0x22 -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 = mbc7_accelerometer + +# 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) + +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/mbc7_accelerometer/Makefile.targets b/gbdk-lib/examples/gb/mbc7_accelerometer/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/mbc7_accelerometer/Readme.md b/gbdk-lib/examples/gb/mbc7_accelerometer/Readme.md @@ -0,0 +1,49 @@ +# GBDK example for using the Accelerometer sensor on the Game Boy MBC7 Cartridge +This example demonstrates using data from the accelerometer sensor on MBC7 cartridges +such as used by Kirby Tilt 'n' Tumble. + +# Important hardware information +Do not use regular `vsync()` or `wait_vbl_done()` for at least `1.2 msec` after +triggering a latch of the accelerometer data (in this example with `mbc7_accel_read()`). +Doing that will cause the MBC7 accelerometer sensor to return errors in the data. + +This is because `vsync()` puts the CPU into `HALT` (until the next frame) +which turns off the cartridge PHI clock. The MBC7 cartridge relies +on that clock to accurately sample the accelerometer sensor. + +This example provides an alternative `vsync_no_halt()` that is safe to use +without concern for timing limitations. It may result in slightly higher +battery usage since the CPU will not enter the `HALT` state. + +# Emulators +At present most emulators do not fully emulate the MBC7 cartridge hardware, +in particular the latching behavior mentioned above. In some cases the range +of outputs data is different. So when testing, if possible, include a MBC7 +cartridge as part of the process. + +Some example ranges for the sensor data: + +`` +Slow rotation, measuring mostly the pull +earth's gravity when the sensor not flat. +The range is for a full rotation of 90 degrees from flat + +X: Left Centered Right + 0x8230 <------- 0x81BC -------> 0x8148 + +116 0 -116 + +Y: Forward Centered Backward + 0x8253 <------- 0x81DE -------> 0x8170 + +117 0 -110 + + +Higher end ranges for fast horizontal movements + +X: Left Centered Right + 0x837E <------- 0x81BC -------> 0x8000 + +450 0 -444 + +Y: Forward Centered Backward + 0x837D <------- 0x81DE -------> 0x8020 + +416 0 -446 +``` diff --git a/gbdk-lib/examples/gb/mbc7_accelerometer/src/main.c b/gbdk-lib/examples/gb/mbc7_accelerometer/src/main.c @@ -0,0 +1,116 @@ +#include <gbdk/platform.h> +#include <stdint.h> +#include <stdbool.h> +#include <stdio.h> +#include <gbdk/console.h> + +#include "mbc7_accelerometer.h" +#include "vsync_no_halt.h" + + +/* **** IMPORTANT **** + +** DO NOT ** use regular vsync() or wait_vbl_done() for at least 1.2 msec after + latching accelerometer data with mbc7_accel_read(). Doing that will cause the +MBC7 accelerometer sensor data to have errors. + +This is because vsync() puts the CPU into HALT (until the next frame) +which turns off the cartridge PHI clock that the MBC7 accelerometer +sensor relies on. + +This example provides an alternative vsync_no_halt() that is safe to use +without timing limitations. +*/ + + +// New and previous values of the joypad input +uint8_t joy = 0, old_joy; +// User input macros +#define INPUT_UPDATE (old_joy=joy,joy=joypad()) +#define INPUT_BUTTON(key) (joy&(key)) +#define INPUT_BUTTONPRESS(key) ((joy & ~old_joy) & (key)) + + +// A plus shaped spite for showing the accelerometer movement +#define SPR_TILE_0 0u // Use tile number 0 +#define SPR_ID_CROSS 0u // Use sprite id number 0 + +#define SCRN_CENTER_X (((DEVICE_SCREEN_PX_WIDTH - 8u) / 2u) + DEVICE_SPRITE_PX_OFFSET_X) +#define SCRN_CENTER_Y (((DEVICE_SCREEN_PX_HEIGHT - 8u) / 2u) + DEVICE_SPRITE_PX_OFFSET_Y) + +const uint8_t sprite_tile[] = { + 0b00111100, 0b00011000, + 0b01111110, 0b00011000, + 0b11111111, 0b00011000, + 0b11111111, 0b11111111, + 0b11111111, 0b11111111, + 0b11111111, 0b00011000, + 0b01111110, 0b00011000, + 0b00111100, 0b00011000, +}; + + +// How much to divide the relative accelerometer data by. +// Dividing by larger amounts filters out small unwanted movements, but reduces sensitivity +#define ACCEL_DIVIDE_AMT 8 + + +void main(void) +{ + bool do_set_origin = false; + bool show_data = false; + + HIDE_SPRITES; + // Assign a sprite with a tile, but hide it by default + set_sprite_data(SPR_TILE_0, 1u, sprite_tile); + set_sprite_tile(SPR_ID_CROSS, SPR_TILE_0); + + printf("-B to Center\n"); + printf("-SELECT toggles info"); + + mbc7_accel_init(); + + while(1) { + + // Check for Gamepad input + INPUT_UPDATE; + switch (INPUT_BUTTONPRESS(J_B | J_SELECT)) { + case J_B: do_set_origin = true; break; + case J_SELECT: show_data ^= true; break; + } + + mbc7_accel_update(do_set_origin); + + // Once the origin has been set, clear the flag and show some data about it + if (do_set_origin) { + do_set_origin = false; + // Display origin, center the sprite and turn on sprites + gotoxy(0,3); + printf("origin x:%x\norigin y:%x", accel_x_origin, accel_y_origin); + SHOW_SPRITES; + move_sprite(SPR_ID_CROSS, SCRN_CENTER_X, SCRN_CENTER_Y); + } + + // Use the Accelerometer data if the origin has been set + if (accel_origin_set) { + + // Move the sprite around the screen using the accelerometer data + scroll_sprite(SPR_ID_CROSS, accel_x_relative / ACCEL_DIVIDE_AMT, accel_y_relative / ACCEL_DIVIDE_AMT); + + if (show_data) { + gotoxy(0,6); + printf("%x\n" + "%x\n" + "%d \n" + "%d \n", + (uint16_t)accel_x, (uint16_t)accel_y, + (int16_t)accel_x_relative, (int16_t)accel_y_relative); + } + } + + // Use an alternate to regular vsync() / wait_vbl_done() which + // does not put the CPU into HALT. This is important since HALT + // interferes with the reading the MBC7 Accelerometer sensor data. + vsync_no_halt(); + } +} diff --git a/gbdk-lib/examples/gb/mbc7_accelerometer/src/mbc7_accelerometer.c b/gbdk-lib/examples/gb/mbc7_accelerometer/src/mbc7_accelerometer.c @@ -0,0 +1,114 @@ +#include <gbdk/platform.h> +#include <stdint.h> +#include <stdbool.h> + + +// **** IMPORTANT **** +// +// ** DO NOT ** use regular vsync() or wait_vbl_done() for at least 1.2 msec after +// latching accelerometer data with mbc7_accel_read(). Doing that will cause the +// MBC7 accelerometer sensor data to have errors. +// +// This is because vsync() puts the CPU into HALT (until the next frame) +// which turns off the cartridge PHI clock that the MBC7 accelerometer +// sensor relies on. +// +// This example provides an alternative vsync_no_halt() that is safe to use +// without timing limitations. + + +// Accelerometer Sensor data ranges +// +// Slow rotation, measuring mostly the pull +// earth's gravity when the sensor not flat. +// +// The range is for a full rotation of 90 degrees from flat +// +// X: Left Centered Right +// 0x8230 <------- 0x81BC -------> 0x8148 +// +116 0 -116 +// +// Y: Forward Centered Backward +// 0x8253 <------- 0x81DE -------> 0x8170 +// +117 0 -110 +// +// +// Higher end ranges for fast horizontal movements +// +// X: Left Centered Right +// 0x837E <------- 0x81BC -------> 0x8000 +// +450 0 -444 +// +// Y: Forward Centered Backward +// 0x837D <------- 0x81DE -------> 0x8020 +// +416 0 -446 + + +// ADXL202 or ADXL210 accelerometer +// https://www.analog.com/media/en/technical-documentation/obsolete-data-sheets/ADXL210.pdf + + + +bool accel_origin_set = false; +uint16_t accel_x; +uint16_t accel_y; +uint16_t accel_x_origin = 0u; +uint16_t accel_y_origin = 0u; +int16_t accel_x_relative = 0; +int16_t accel_y_relative = 0; + + + +// Call this once per frame to update the accelerometer data +// +// Optionally it may be installed as a VBL handler +void mbc7_accel_read(void) { + // Read the Raw sensor values + accel_x = ((uint16_t)(rMBC7_ACCEL_X_HI) << 8) | (uint16_t)rMBC7_ACCEL_X_LO; + accel_y = ((uint16_t)(rMBC7_ACCEL_Y_HI) << 8) | (uint16_t)rMBC7_ACCEL_Y_LO; + + // Latch data that doesn't get read until next frame + // requires ~1.2 msec of settling time during which the CPU + // ** MUST NOT ** be put into HALT or STOP (so do not use regular + // vsync() or wait_vbl_done(), instead use the vsync_no_halt() ). + rMBC7_LATCH_1 = MBC7_LATCH_ERASE; + rMBC7_LATCH_2 = MBC7_LATCH_CAPTURE; +} + + +void mbc7_accel_init(void) { + + // Enable SRAM MVBC7 access (required for accessing accelerometer data) + rMBC7_SRAM_ENABLE_1 = MBC7_SRAM_ENABLE_KEY_1; + rMBC7_SRAM_ENABLE_2 = MBC7_SRAM_ENABLE_KEY_2; + + // Do a single read to prime the sensor + mbc7_accel_read(); + + // The data read won't be valid until ~1.2 msec after latching + // so for the initial one just delay + delay(2); +} + + +void mbc7_accel_setorigin(void) { + accel_x_origin = accel_x; + accel_y_origin = accel_y; + accel_origin_set = true; +} + + +void mbc7_accel_update(bool do_set_origin) { + + mbc7_accel_read(); + + if (do_set_origin) { + mbc7_accel_setorigin(); + } + + if (accel_origin_set) { + // Calculate relative movement of sensor compared to user prompted origin + accel_x_relative = (int16_t)(accel_x_origin - accel_x); + accel_y_relative = (int16_t)(accel_y_origin - accel_y); + } +} diff --git a/gbdk-lib/examples/gb/mbc7_accelerometer/src/mbc7_accelerometer.h b/gbdk-lib/examples/gb/mbc7_accelerometer/src/mbc7_accelerometer.h @@ -0,0 +1,19 @@ +#ifndef _MBC7_ACCELEROMETER_H +#define _MBC7_ACCELEROMETER_H + +extern bool accel_origin_set; +extern uint16_t accel_x; +extern uint16_t accel_y; +extern uint16_t accel_x_origin; +extern uint16_t accel_y_origin; +extern int16_t accel_x_relative; +extern int16_t accel_y_relative; + + +void mbc7_accel_read(void); +void mbc7_accel_init(void); +void mbc7_accel_setorigin(void); + +void mbc7_accel_update(bool do_set_origin); + +#endif diff --git a/gbdk-lib/examples/gb/mbc7_accelerometer/src/vsync_no_halt.c b/gbdk-lib/examples/gb/mbc7_accelerometer/src/vsync_no_halt.c @@ -0,0 +1,12 @@ +#include <gbdk/platform.h> + +void vsync_no_halt(void) { + + // Return if the screen isn't on since + // VBL isr to toggle vbl_done won't run + if ((LCDC_REG & LCDCF_ON) == 0) return; + + // Wait until VBlank ISR marks the frame done + VBL_DONE = 0; + while (VBL_DONE == 0); +} diff --git a/gbdk-lib/examples/gb/mbc7_accelerometer/src/vsync_no_halt.h b/gbdk-lib/examples/gb/mbc7_accelerometer/src/vsync_no_halt.h @@ -0,0 +1,7 @@ + +#ifndef _VSYNC_NO_HALT_H +#define _VSYNC_NO_HALT_H + +void vsync_no_halt(void); + +#endif diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -463,6 +463,13 @@ extern uint8_t _is_GBA; */ extern volatile uint16_t sys_time; +/** Flag indicating the VBlank ISR has run + + Flag gets cleared at the start of @ref vsync() / @ref wait_vbl_done() + and set in the default VBlank ISR handler. +*/ +__REG _vbl_done; +#define VBL_DONE _vbl_done /** Serial Link: Send the byte in @ref _io_out out through the serial port diff --git a/gbdk-lib/include/gb/hardware.h b/gbdk-lib/include/gb/hardware.h @@ -36,6 +36,22 @@ __BYTE_REG rROMB0; __BYTE_REG rROMB1; __BYTE_REG rRAMB; +/** MBC7 registers */ + +__BYTE_REG rMBC7_SRAM_ENABLE_1; +__BYTE_REG rMBC7_SRAM_ENABLE_2; +__BYTE_REG rMBC7_LATCH_1; +__BYTE_REG rMBC7_LATCH_2; +__BYTE_REG rMBC7_ACCEL_X_LO; +__BYTE_REG rMBC7_ACCEL_X_HI; +__BYTE_REG rMBC7_ACCEL_Y_LO; +__BYTE_REG rMBC7_ACCEL_Y_HI; + +#define MBC7_LATCH_ERASE 0x55u +#define MBC7_LATCH_CAPTURE 0xAAu +#define MBC7_SRAM_ENABLE_KEY_1 0x0Au +#define MBC7_SRAM_ENABLE_KEY_2 0x40u + /** IO Registers */ __REG P1_REG; /**< Joystick register @see joypad(), add_JOY(), IEF_HILO, P1F_5, P1F_4, P1F_3, P1F_2, P1F_1, P1F_0, P1F_GET_DPAD, P1F_GET_BTN, P1F_GET_NONE */ diff --git a/gbdk-lib/include/msx/msx.h b/gbdk-lib/include/msx/msx.h @@ -334,6 +334,14 @@ void refresh_OAM(void); */ extern volatile uint16_t sys_time; +/** Flag indicating the VBlank ISR has run + + Flag gets cleared at the start of @ref vsync() / @ref wait_vbl_done() + and set in the default VBlank ISR handler. +*/ +extern volatile uint8_t _vbl_done; +#define VBL_DONE _vbl_done + /** Return R register for the DIV_REG emulation Increments once per CPU instruction (fetches the Z80 CPU R register) diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -339,6 +339,14 @@ void refresh_OAM(void); */ extern volatile uint16_t sys_time; +/** Flag indicating the VBlank ISR has run + + Flag gets cleared at the start of @ref vsync() / @ref wait_vbl_done() + and set in the default VBlank ISR handler. +*/ +extern volatile uint8_t _vbl_done; +#define VBL_DONE _vbl_done + /** Return R register for the DIV_REG emulation diff --git a/gbdk-lib/libc/targets/sm83/ap/crt0.s b/gbdk-lib/libc/targets/sm83/ap/crt0.s @@ -424,6 +424,7 @@ _sys_time:: __current_bank:: ; Current bank .ds 0x01 .vbl_done: +__vbl_done:: .ds 0x01 ; Is VBL interrupt finished? __shadow_OAM_base:: .ds 0x01 diff --git a/gbdk-lib/libc/targets/sm83/ap/global.s b/gbdk-lib/libc/targets/sm83/ap/global.s @@ -19,6 +19,15 @@ rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) + rMBC7_SRAM_ENABLE_1 = 0x0000 + rMBC7_SRAM_ENABLE_2 = 0x4000 + rMBC7_LATCH_1 = 0xA000 + rMBC7_LATCH_2 = 0xA010 + rMBC7_ACCEL_X_LO = 0xA020 + rMBC7_ACCEL_X_HI = 0xA030 + rMBC7_ACCEL_Y_LO = 0xA040 + rMBC7_ACCEL_Y_HI = 0xA050 + ;; Keypad .START = 0x80 .SELECT = 0x40 diff --git a/gbdk-lib/libc/targets/sm83/ap/sfr.s b/gbdk-lib/libc/targets/sm83/ap/sfr.s @@ -21,6 +21,17 @@ _rRAMB = 0x4000 .globl _rRAMG, _rROMB0, _rROMB1, _rRAMB +_rMBC7_SRAM_ENABLE_1 = 0x0000 +_rMBC7_SRAM_ENABLE_2 = 0x4000 +_rMBC7_LATCH_1 = 0xA000 +_rMBC7_LATCH_2 = 0xA010 +_rMBC7_ACCEL_X_LO = 0xA020 +_rMBC7_ACCEL_X_HI = 0xA030 +_rMBC7_ACCEL_Y_LO = 0xA040 +_rMBC7_ACCEL_Y_HI = 0xA050 + +.globl _rMBC7_SRAM_ENABLE_1, _rMBC7_SRAM_ENABLE_2, _rMBC7_LATCH_1, _rMBC7_LATCH_2, _rMBC7_ACCEL_X_LO, _rMBC7_ACCEL_X_HI, _rMBC7_ACCEL_Y_LO, _rMBC7_ACCEL_Y_HI + _P1_REG = 0xFF00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 _SB_REG = 0xFF01 ; Serial IO data buffer _SC_REG = 0xFF02 ; Serial IO control register diff --git a/gbdk-lib/libc/targets/sm83/duck/crt0.s b/gbdk-lib/libc/targets/sm83/duck/crt0.s @@ -366,6 +366,7 @@ _sys_time:: __current_bank:: ; Current bank .ds 0x01 .vbl_done: +__vbl_done:: .ds 0x01 ; Is VBL interrupt finished? __shadow_OAM_base:: .ds 0x01 diff --git a/gbdk-lib/libc/targets/sm83/duck/global.s b/gbdk-lib/libc/targets/sm83/duck/global.s @@ -19,6 +19,15 @@ rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) + rMBC7_SRAM_ENABLE_1 = 0x0000 + rMBC7_SRAM_ENABLE_2 = 0x4000 + rMBC7_LATCH_1 = 0xA000 + rMBC7_LATCH_2 = 0xA010 + rMBC7_ACCEL_X_LO = 0xA020 + rMBC7_ACCEL_X_HI = 0xA030 + rMBC7_ACCEL_Y_LO = 0xA040 + rMBC7_ACCEL_Y_HI = 0xA050 + ;; Keypad .START = 0x80 .SELECT = 0x40 diff --git a/gbdk-lib/libc/targets/sm83/duck/sfr.s b/gbdk-lib/libc/targets/sm83/duck/sfr.s @@ -21,6 +21,17 @@ _rRAMB = 0x4000 .globl _rRAMG, _rROMB0, _rROMB1, _rRAMB +_rMBC7_SRAM_ENABLE_1 = 0x0000 +_rMBC7_SRAM_ENABLE_2 = 0x4000 +_rMBC7_LATCH_1 = 0xA000 +_rMBC7_LATCH_2 = 0xA010 +_rMBC7_ACCEL_X_LO = 0xA020 +_rMBC7_ACCEL_X_HI = 0xA030 +_rMBC7_ACCEL_Y_LO = 0xA040 +_rMBC7_ACCEL_Y_HI = 0xA050 + +.globl _rMBC7_SRAM_ENABLE_1, _rMBC7_SRAM_ENABLE_2, _rMBC7_LATCH_1, _rMBC7_LATCH_2, _rMBC7_ACCEL_X_LO, _rMBC7_ACCEL_X_HI, _rMBC7_ACCEL_Y_LO, _rMBC7_ACCEL_Y_HI + _P1_REG = 0xFF00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 _SB_REG = 0xFF01 ; Serial IO data buffer _SC_REG = 0xFF02 ; Serial IO control register diff --git a/gbdk-lib/libc/targets/sm83/gb/crt0.s b/gbdk-lib/libc/targets/sm83/gb/crt0.s @@ -434,6 +434,7 @@ _sys_time:: __current_bank:: ; Current bank .ds 0x01 .vbl_done: +__vbl_done:: .ds 0x01 ; Is VBL interrupt finished? __shadow_OAM_base:: .ds 0x01 diff --git a/gbdk-lib/libc/targets/sm83/gb/global.s b/gbdk-lib/libc/targets/sm83/gb/global.s @@ -19,6 +19,15 @@ rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) + rMBC7_SRAM_ENABLE_1 = 0x0000 + rMBC7_SRAM_ENABLE_2 = 0x4000 + rMBC7_LATCH_1 = 0xA000 + rMBC7_LATCH_2 = 0xA010 + rMBC7_ACCEL_X_LO = 0xA020 + rMBC7_ACCEL_X_HI = 0xA030 + rMBC7_ACCEL_Y_LO = 0xA040 + rMBC7_ACCEL_Y_HI = 0xA050 + ;; Keypad .UP = 0x04 .DOWN = 0x08 diff --git a/gbdk-lib/libc/targets/sm83/gb/sfr.s b/gbdk-lib/libc/targets/sm83/gb/sfr.s @@ -21,6 +21,17 @@ _rRAMB = 0x4000 .globl _rRAMG, _rROMB0, _rROMB1, _rRAMB +_rMBC7_SRAM_ENABLE_1 = 0x0000 +_rMBC7_SRAM_ENABLE_2 = 0x4000 +_rMBC7_LATCH_1 = 0xA000 +_rMBC7_LATCH_2 = 0xA010 +_rMBC7_ACCEL_X_LO = 0xA020 +_rMBC7_ACCEL_X_HI = 0xA030 +_rMBC7_ACCEL_Y_LO = 0xA040 +_rMBC7_ACCEL_Y_HI = 0xA050 + +.globl _rMBC7_SRAM_ENABLE_1, _rMBC7_SRAM_ENABLE_2, _rMBC7_LATCH_1, _rMBC7_LATCH_2, _rMBC7_ACCEL_X_LO, _rMBC7_ACCEL_X_HI, _rMBC7_ACCEL_Y_LO, _rMBC7_ACCEL_Y_HI + _P1_REG = 0xFF00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 _SB_REG = 0xFF01 ; Serial IO data buffer _SC_REG = 0xFF02 ; Serial IO control register diff --git a/gbdk-lib/libc/targets/z80/gg/crt0.s b/gbdk-lib/libc/targets/z80/gg/crt0.s @@ -280,6 +280,7 @@ _shadow_VDP_R10:: _sys_time:: .ds 0x02 .vbl_done:: +__vbl_done:: .ds 0x01 _VDP_ATTR_SHIFT:: .vdp_shift:: diff --git a/gbdk-lib/libc/targets/z80/msxdos/crt0.s b/gbdk-lib/libc/targets/z80/msxdos/crt0.s @@ -482,6 +482,7 @@ _shadow_VDP_RBORDER:: _sys_time:: .dw 0x0000 .vbl_done:: +__vbl_done:: .db 0 __shadow_OAM_base:: .db #>_shadow_OAM diff --git a/gbdk-lib/libc/targets/z80/sms/crt0.s b/gbdk-lib/libc/targets/z80/sms/crt0.s @@ -286,6 +286,7 @@ _shadow_VDP_R10:: _sys_time:: .ds 0x02 .vbl_done:: +__vbl_done:: .ds 0x01 _VDP_ATTR_SHIFT:: .vdp_shift::
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.