gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit ce3c57764996907a754e3989b156e921b83b5783 parent f220abc6c6e78175f2fc156895abbdb527ead81e Author: Toxa <untoxa@mail.ru> Date: Fri, 27 Aug 2021 16:41:22 +0300 examples: cross-platform scroller example Diffstat:
| A | gbdk-lib/examples/cross-platform/scroller/Makefile | 77 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | gbdk-lib/examples/cross-platform/scroller/Makefile.targets | 44 | ++++++++++++++++++++++++++++++++++++++++++++ |
| A | gbdk-lib/examples/cross-platform/scroller/src/text_scroller.c | 53 | +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 174 insertions(+), 0 deletions(-)
diff --git a/gbdk-lib/examples/cross-platform/scroller/Makefile b/gbdk-lib/examples/cross-platform/scroller/Makefile @@ -0,0 +1,77 @@ +# If you move this project you can change the directory +# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" +GBDK_HOME = ../../../ +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 sms gg +TARGETS=gb pocket sms gg + +# Configure platform specific LCC flags here: +LCCFLAGS_gb = -Wl-yt0x1B # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT) +LCCFLAGS_pocket = -Wl-yt0x1B # Usually the same as required for .gb +LCCFLAGS_gbc = -Wl-yt0x1B -Wm-yc # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive) +LCCFLAGS_sms = +LCCFLAGS_gg = + +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 + +# You can set the name of the ROM file here +PROJECTNAME = example + +# 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) + +# Builds all targets sequentially +all: $(TARGETS) + +# 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 i n"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/cross-platform/scroller/Makefile.targets b/gbdk-lib/examples/cross-platform/scroller/Makefile.targets @@ -0,0 +1,44 @@ + +# Platform specific flags for compiling (only populate if they're both present) +ifneq ($(strip $(PORT)),) +ifneq ($(strip $(PLAT)),) +CFLAGS += -m$(PORT):$(PLAT) -D_PLAT_$(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=gbz80 PLAT=gb EXT=gb + + +gbc-clean: + ${MAKE} clean-target EXT=gbc +gbc: + ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + + +pocket-clean: + ${MAKE} clean-target EXT=pocket +pocket: + ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + + +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 + diff --git a/gbdk-lib/examples/cross-platform/scroller/src/text_scroller.c b/gbdk-lib/examples/cross-platform/scroller/src/text_scroller.c @@ -0,0 +1,52 @@ +#include <gbdk/platform.h> +#include <stdint.h> +#include <stdio.h> + +const uint8_t scanline_offsets_tbl[] = {0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0}; +const uint8_t * scanline_offsets = scanline_offsets_tbl; + +#define SCROLL_POS 15 + +uint8_t scroller_x = 0; +void scanline_isr() { +} + +const uint8_t scroller_text[] = "This is a text scroller demo for GBDK-2020. You can use ideas, that are "\ +"shown in this demo, to make different parallax effects, scrolling of tilemaps which are larger than 32x32 "\ +"tiles and TEXT SCROLLERS, of course! Need to write something else to make this text longer than 256 characters. "\ +"The quick red fox jumps over the lazy brown dog. 0123456789. "; + +const uint8_t * scroller_next_char = scroller_text; +uint8_t * scroller_vram_addr; +uint8_t * base, * limit; + +void main() { + printf("Scrolling %d chars", sizeof(scroller_text) - 1); + + HIDE_LEFT_COLUMN; + base = (uint8_t *)((uint16_t)get_bkg_xy_addr(0, SCROLL_POS) & (DEVICE_SCREEN_MAP_ENTRY_SIZE==1?0xffe0:0xffc0)); + limit = base + (DEVICE_SCREEN_BUFFER_WIDTH * DEVICE_SCREEN_MAP_ENTRY_SIZE); + + scroller_vram_addr = base + ((DEVICE_SCREEN_X_OFFSET + DEVICE_SCREEN_WIDTH) * DEVICE_SCREEN_MAP_ENTRY_SIZE); + if (scroller_vram_addr >= limit) scroller_vram_addr = base; + + set_vram_byte(scroller_vram_addr, *scroller_next_char - 0x20); + + while (1) { + scroller_x++; + move_bkg(scroller_x, 0); + if ((scroller_x & 0x07) == 0) { + // next letter + scroller_next_char++; + if (*scroller_next_char == 0) scroller_next_char = scroller_text; + + // next vram position + scroller_vram_addr += DEVICE_SCREEN_MAP_ENTRY_SIZE; + if (scroller_vram_addr >= limit) scroller_vram_addr = base; + + // put next char + set_vram_byte(scroller_vram_addr, *scroller_next_char - 0x20); + } + 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.