git.y1.nz

gbdk-2020

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

commit 2b9a2f4d71d3b58db848c3b2c8a0180bfbcd4c2f
parent 30c17a79f4b268447705522be669a90159662ca4
Author: Toxa <untoxa@mail.ru>
Date:   Thu,  2 Sep 2021 11:48:21 +0300

INCBIN cross-platform example

Diffstat:
Dgbdk-lib/examples/ap/incbin/Makefile60------------------------------------------------------------
Dgbdk-lib/examples/ap/incbin/Readme.md8--------
Dgbdk-lib/examples/ap/incbin/src/main.c58----------------------------------------------------------
Agbdk-lib/examples/cross-platform/incbin/Makefile77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/incbin/Makefile.targets44++++++++++++++++++++++++++++++++++++++++++++
Rgbdk-lib/examples/ap/incbin/res/blanktile.bin -> gbdk-lib/examples/cross-platform/incbin/res/blanktile.bin0
Rgbdk-lib/examples/ap/incbin/res/blanktile.png -> gbdk-lib/examples/cross-platform/incbin/res/blanktile.png0
Rgbdk-lib/examples/ap/incbin/res/gbdk2020.bin -> gbdk-lib/examples/cross-platform/incbin/res/gbdk2020.bin0
Rgbdk-lib/examples/ap/incbin/res/gbdk2020.png -> gbdk-lib/examples/cross-platform/incbin/res/gbdk2020.png0
Rgbdk-lib/examples/ap/incbin/res/gbdk2020_map.bin -> gbdk-lib/examples/cross-platform/incbin/res/gbdk2020_map.bin0
Agbdk-lib/examples/cross-platform/incbin/src/main.c58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 179 insertions(+), 126 deletions(-)

diff --git a/gbdk-lib/examples/ap/incbin/Makefile b/gbdk-lib/examples/ap/incbin/Makefile @@ -1,60 +0,0 @@ -# -# 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/" -GBDK_HOME = ../../../ - -LCC = $(GBDK_HOME)bin/lcc - -# You can set flags for LCC here -# For example, you can uncomment the line below to turn on debug output -LCCFLAGS = -mgbz80:ap -Wl-j -Wm-yS - -# You can set the name of the .pocket ROM file here -PROJECTNAME = Example - -SRCDIR = src -OBJDIR = obj -RESDIR = res -BINS = $(PROJECTNAME).pocket -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/\\//\\\\/ | 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 i n"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 .pocket ROM file -$(BINS): $(OBJS) - $(LCC) $(LCCFLAGS) -o $(BINS) $(OBJS) - -prepare: - mkdir -p $(OBJDIR) - -clean: - rm -f *.pocket *.ihx *.cdb *.adb *.noi *.map *.sym - rm -rf $(OBJDIR) - diff --git a/gbdk-lib/examples/ap/incbin/Readme.md b/gbdk-lib/examples/ap/incbin/Readme.md @@ -1,8 +0,0 @@ - -An example project showing how to use 'incbin.h' to include binary files into C source files. - - -The 4 color .png files were exported to .bin format (2bpp gb) using the gimp plugin listed below. -There are many other tools which can also do the conversion. - -https://github.com/bbbbbr/gimp-rom-bin diff --git a/gbdk-lib/examples/ap/incbin/src/main.c b/gbdk-lib/examples/ap/incbin/src/main.c @@ -1,58 +0,0 @@ -#include <gb/gb.h> -#include <stdint.h> - -#include <gbdk/incbin.h> - -INCBIN(logo_tiles_data, "res/gbdk2020.bin") // Variable name to use, Path to file -INCBIN_EXTERN(logo_tiles_data) // Extern declarations for binary data - -INCBIN(logo_map, "res/gbdk2020_map.bin") -INCBIN_EXTERN(logo_map) - -INCBIN(blank_tile_data, "res/blanktile.bin") -INCBIN_EXTERN(blank_tile_data) - - -#define TILE_BYTES 16 // 16 bytes per background tile - - -// Since incbin just includes a binary file (the logo tiles) -// a map needs to be created for them. For this example -// the tiles are non-deduplciated, so a array of incrementing -// values can be used. There are 84 tiles. -#define LOGO_MAP_WIDTH 7u -#define LOGO_MAP_HEIGHT 12u -#define LOGO_MAP_X (20u - LOGO_MAP_WIDTH) / 2u // Center on X axis -#define LOGO_MAP_Y (18u - LOGO_MAP_HEIGHT) / 2u // Center on Y axis - -void init_gfx() { - // Load a single clear background tile at location 0x80 and clear/fill the map with it - set_bkg_data(0x80u, 1u, blank_tile_data); // The first 0x80u here is the tile ID - fill_bkg_rect(0u, 0u, 20u, 18u, 0x80u); // The last 0x80u here is the tile ID - - // Load logo background tiles and map - // They start at 0u - set_bkg_data(0u, SIZE(logo_tiles_data) / TILE_BYTES, logo_tiles_data); - set_bkg_tiles(LOGO_MAP_X, LOGO_MAP_Y, - LOGO_MAP_WIDTH, LOGO_MAP_HEIGHT, - logo_map); - - // Turn the background map on to make it visible - SHOW_BKG; -} - - - -void main(void) -{ - init_gfx(); - - // Loop forever - while(1) { - - // Game main loop processing goes here - - // Done processing, yield CPU and wait for start of next frame - wait_vbl_done(); - } -} diff --git a/gbdk-lib/examples/cross-platform/incbin/Makefile b/gbdk-lib/examples/cross-platform/incbin/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-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 = incbin + +# 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/incbin/Makefile.targets b/gbdk-lib/examples/cross-platform/incbin/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/ap/incbin/res/blanktile.bin b/gbdk-lib/examples/cross-platform/incbin/res/blanktile.bin Binary files differ. diff --git a/gbdk-lib/examples/ap/incbin/res/blanktile.png b/gbdk-lib/examples/cross-platform/incbin/res/blanktile.png Binary files differ. diff --git a/gbdk-lib/examples/ap/incbin/res/gbdk2020.bin b/gbdk-lib/examples/cross-platform/incbin/res/gbdk2020.bin Binary files differ. diff --git a/gbdk-lib/examples/ap/incbin/res/gbdk2020.png b/gbdk-lib/examples/cross-platform/incbin/res/gbdk2020.png Binary files differ. diff --git a/gbdk-lib/examples/ap/incbin/res/gbdk2020_map.bin b/gbdk-lib/examples/cross-platform/incbin/res/gbdk2020_map.bin Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/incbin/src/main.c b/gbdk-lib/examples/cross-platform/incbin/src/main.c @@ -0,0 +1,58 @@ +#include <gbdk/platform.h> +#include <stdint.h> + +#include <gbdk/incbin.h> + +INCBIN(logo_tiles_data, "res/gbdk2020.bin") // Variable name to use, Path to file +INCBIN_EXTERN(logo_tiles_data) // Extern declarations for binary data + +INCBIN(logo_map, "res/gbdk2020_map.bin") +INCBIN_EXTERN(logo_map) + +INCBIN(blank_tile_data, "res/blanktile.bin") +INCBIN_EXTERN(blank_tile_data) + + +#define TILE_BYTES 16 // 16 bytes per background tile + + +// Since incbin just includes a binary file (the logo tiles) +// a map needs to be created for them. For this example +// the tiles are non-deduplciated, so a array of incrementing +// values can be used. There are 84 tiles. +#define LOGO_MAP_WIDTH 7u +#define LOGO_MAP_HEIGHT 12u +#define LOGO_MAP_X (20u - LOGO_MAP_WIDTH) / 2u // Center on X axis +#define LOGO_MAP_Y (18u - LOGO_MAP_HEIGHT) / 2u // Center on Y axis + +void init_gfx() { + // Load a single clear background tile at location 0x80 and clear/fill the map with it + set_bkg_data(0x80u, 1u, blank_tile_data); // The first 0x80u here is the tile ID + fill_bkg_rect(0u, 0u, DEVICE_SCREEN_WIDTH, DEVICE_SCREEN_HEIGHT, 0x80u); // The last 0x80u here is the tile ID + + // Load logo background tiles and map + // They start at 0u + set_bkg_data(0u, SIZE(logo_tiles_data) / TILE_BYTES, logo_tiles_data); + set_bkg_tiles(LOGO_MAP_X, LOGO_MAP_Y, + LOGO_MAP_WIDTH, LOGO_MAP_HEIGHT, + logo_map); + + // Turn the background map on to make it visible + SHOW_BKG; +} + + + +void main(void) +{ + init_gfx(); + + // Loop forever + while(1) { + + // Game main loop processing goes here + + // Done processing, yield CPU and wait for start of next frame + 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.