gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 3ae2a52757877352bf4608005313674a9003e270 parent f5dd2c740cd7b2c20f1ecbb93f0ab66ba30222b1 Author: Toxa <56631470+untoxa@users.noreply.github.com> Date: Fri, 29 Sep 2023 00:55:17 +0300 Merge pull request #581 from michel-iwaniec/cross_platform_multiplayer_demo Make multiplayer demo multi-platform Diffstat:
| A | gbdk-lib/examples/cross-platform/multiplayer/Makefile | 78 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | gbdk-lib/examples/cross-platform/multiplayer/Makefile.targets | 55 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | gbdk-lib/examples/cross-platform/multiplayer/src/multiplayer.c | 46 | ++++++++++++++++++++++++++++++++++++++++++++++ |
| D | gbdk-lib/examples/gb/sgb_multiplayer/Makefile | 17 | ----------------- |
| D | gbdk-lib/examples/gb/sgb_multiplayer/sgb_multiplayer.c | 48 | ------------------------------------------------ |
5 files changed, 179 insertions(+), 65 deletions(-)
diff --git a/gbdk-lib/examples/cross-platform/multiplayer/Makefile b/gbdk-lib/examples/cross-platform/multiplayer/Makefile @@ -0,0 +1,78 @@ +# 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 megaduck sms gg +TARGETS=gb pocket megaduck sms gg nes + +# Configure platform specific LCC flags here: +LCCFLAGS_gb = -Wm-ys -Wl-yt0x1B -autobank # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT) +LCCFLAGS_pocket = -Wm-ys -Wl-yt0x1B -autobank # Usually the same as required for .gb +LCCFLAGS_duck = -Wm-ys -Wl-yt0x1B -autobank # Usually the same as required for .gb +LCCFLAGS_gbc = -Wm-ys -Wl-yt0x1B -Wm-yc -autobank # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive) +LCCFLAGS_sms = -autobank +LCCFLAGS_gg = -autobank +LCCFLAGS_nes = + +LCCFLAGS += $(LCCFLAGS_$(EXT)) # This adds the current platform specific LCC Flags + +LCCFLAGS += -Wl-j -Wm-yoA -Wm-ya4 -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 = multiplayer + +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 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/cross-platform/multiplayer/Makefile.targets b/gbdk-lib/examples/cross-platform/multiplayer/Makefile.targets @@ -0,0 +1,55 @@ + +# 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/cross-platform/multiplayer/src/multiplayer.c b/gbdk-lib/examples/cross-platform/multiplayer/src/multiplayer.c @@ -0,0 +1,45 @@ +//#include <stdint.h> +#include <gbdk/platform.h> + +uint8_t sprite_data[] = { + 0x3C,0x3C,0x42,0x7E,0x99,0xFF,0xA9,0xFF,0x89,0xFF,0x89,0xFF,0x42,0x7E,0x3C,0x3C, + 0x3C,0x3C,0x42,0x7E,0xB9,0xFF,0x89,0xFF,0x91,0xFF,0xB9,0xFF,0x42,0x7E,0x3C,0x3C, + 0x3C,0x3C,0x42,0x7E,0x99,0xFF,0x89,0xFF,0x99,0xFF,0x89,0xFF,0x5A,0x7E,0x3C,0x3C, + 0x3C,0x3C,0x42,0x7E,0xA9,0xFF,0xA9,0xFF,0xB9,0xFF,0x89,0xFF,0x42,0x7E,0x3C,0x3C +}; + +joypads_t joypads; + +void main(void) { + set_sprite_data(0, 4, sprite_data); + for (uint8_t i = 0; i < 4; i++) { + set_sprite_tile(i, i); + move_sprite(i, (i << 3) + 64, 64); + } + SHOW_SPRITES; + + // Wait 4 frames + // For SGB on PAL SNES this delay is required on startup, otherwise borders don't show up + for (uint8_t i = 4; i != 0; i--) vsync(); + + // init joypads + joypad_init(4, &joypads); + + while(1) { + // poll joypads + joypad_ex(&joypads); + // iterate joypads, move sprites + for (uint8_t i = 0; i < joypads.npads; i++) { + uint8_t joy = joypads.joypads[i]; + if (joy & J_LEFT) scroll_sprite(i, -1, 0); + if (joy & J_RIGHT) scroll_sprite(i, 1, 0); + if (joy & J_UP) scroll_sprite(i, 0, -1); + if (joy & J_DOWN) scroll_sprite(i, 0, 1); + } + // start on joypad 1 resets position + if (joypads.joy0 & J_START) { + for (uint8_t i = 0; i < 4; i++) move_sprite(i, (i << 3) + 64, 64); + } + vsync(); + } +} + diff --git a/gbdk-lib/examples/gb/sgb_multiplayer/Makefile b/gbdk-lib/examples/gb/sgb_multiplayer/Makefile @@ -1,17 +0,0 @@ -CC = ../../../bin/lcc -Wa-l -Wl-m -Wl-j -Wm-ys - -BINS = sgb_multiplayer.gb - -all: $(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 and link single file in one pass -%.gb: %.c - $(CC) -o $@ $< - -clean: - rm -f *.o *.lst *.map *.gb *~ *.rel *.cdb *.ihx *.lnk *.sym *.asm *.noi - diff --git a/gbdk-lib/examples/gb/sgb_multiplayer/sgb_multiplayer.c b/gbdk-lib/examples/gb/sgb_multiplayer/sgb_multiplayer.c @@ -1,47 +0,0 @@ -#include <gb/gb.h> -#include <stdint.h> -#include <gb/sgb.h> - -uint8_t sprite_data[] = { - 0x3C,0x3C,0x42,0x7E,0x99,0xFF,0xA9,0xFF,0x89,0xFF,0x89,0xFF,0x42,0x7E,0x3C,0x3C, - 0x3C,0x3C,0x42,0x7E,0xB9,0xFF,0x89,0xFF,0x91,0xFF,0xB9,0xFF,0x42,0x7E,0x3C,0x3C, - 0x3C,0x3C,0x42,0x7E,0x99,0xFF,0x89,0xFF,0x99,0xFF,0x89,0xFF,0x5A,0x7E,0x3C,0x3C, - 0x3C,0x3C,0x42,0x7E,0xA9,0xFF,0xA9,0xFF,0xB9,0xFF,0x89,0xFF,0x42,0x7E,0x3C,0x3C -}; - -joypads_t joypads; - -void main(void) { - BGP_REG = OBP0_REG = OBP1_REG = 0xE4; - set_sprite_data(0, 4, sprite_data); - for (uint8_t i = 0; i < 4; i++) { - set_sprite_tile(i, i); - move_sprite(i, (i << 3) + 64, 64); - } - SHOW_SPRITES; - - // Wait 4 frames - // For SGB on PAL SNES this delay is required on startup, otherwise borders don't show up - for (uint8_t i = 4; i != 0; i--) vsync(); - - // init joypads - joypad_init(4, &joypads); - - while(1) { - // poll joypads - joypad_ex(&joypads); - // iterate joypads, move sprites - for (uint8_t i = 0; i < joypads.npads; i++) { - uint8_t joy = joypads.joypads[i]; - if (joy & J_LEFT) scroll_sprite(i, -1, 0); - if (joy & J_RIGHT) scroll_sprite(i, 1, 0); - if (joy & J_UP) scroll_sprite(i, 0, -1); - if (joy & J_DOWN) scroll_sprite(i, 0, 1); - } - // start on joypad 1 resets position - if (joypads.joy0 & J_START) { - for (uint8_t i = 0; i < 4; i++) move_sprite(i, (i << 3) + 64, 64); - } - vsync(); - } -} -
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.