git.y1.nz

gbdk-2020

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

commit 38f8df2cad993cf13a07c881cad72d98c6e3d6b4
parent 98d3a6d9501f4a34229fd926f5b0e6559a0a27ed
Author: Toxa <untoxa@mail.ru>
Date:   Thu, 24 Aug 2023 15:11:55 +0300

GB: HBlank copy routines and example

Diffstat:
Agbdk-lib/examples/gb/hblank_copy/Makefile68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/gb/hblank_copy/Readme.md5+++++
Agbdk-lib/examples/gb/hblank_copy/res/scene00001.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00002.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00003.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00004.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00005.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00006.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00007.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00008.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00009.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00010.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00011.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00012.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00013.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00014.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00015.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00016.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00017.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00018.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00019.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00020.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00021.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00022.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00023.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00024.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00025.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00026.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00027.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00028.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00029.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00030.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00031.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00032.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00033.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00034.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00035.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00036.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00037.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00038.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00039.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00040.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00041.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00042.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00043.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00044.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00045.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00046.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00047.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00048.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00049.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00050.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00051.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00052.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00053.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00054.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00055.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00056.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00057.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00058.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00059.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00060.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00061.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00062.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00063.png0
Agbdk-lib/examples/gb/hblank_copy/res/scene00064.png0
Agbdk-lib/examples/gb/hblank_copy/src/data.c136+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/gb/hblank_copy/src/data.h21+++++++++++++++++++++
Agbdk-lib/examples/gb/hblank_copy/src/main.c102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/include/gb/hblankcpy.h35+++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/targets/sm83/ap/Makefile1+
Mgbdk-lib/libc/targets/sm83/duck/Makefile1+
Mgbdk-lib/libc/targets/sm83/gb/Makefile1+
Agbdk-lib/libc/targets/sm83/hblankcpy.s93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
74 files changed, 463 insertions(+), 0 deletions(-)

diff --git a/gbdk-lib/examples/gb/hblank_copy/Makefile b/gbdk-lib/examples/gb/hblank_copy/Makefile @@ -0,0 +1,68 @@ +# +# 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 +PNG2ASSET = $(GBDK_HOME)bin/png2asset + +# You can set flags for LCC here +# For example, you can uncomment the line below to turn on debug output +# LCCFLAGS += -debug +LCCFLAGS += -Wm-yt0x19 -Wm-yoA -autobank -I$(OBJDIR) + +# You can set the name of the .gb ROM file here +PROJECTNAME = hblank_copy + +SRCDIR = src +OBJDIR = obj +RESDIR = res +BINS = $(OBJDIR)/$(PROJECTNAME).gb +RESOURCES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.png))) +CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) +ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) +OBJS = $(RESOURCES:%.png=$(OBJDIR)/%.o) $(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/\\//\\\\/ | sed s/mkdir\ -p\/mkdir\/ | 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)/%.c: $(RESDIR)/%.png + $(PNG2ASSET) $< -c $@ -map -noflip -tiles_only -keep_duplicate_tiles -b 255 + +# Compile .s assembly files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.s + $(LCC) $(LCCFLAGS) -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) $(LCCFLAGS) -S -o $@ $< + +# rule for the autogenerated files +$(OBJDIR)/%.o: $(OBJDIR)/%.c + $(LCC) $(CFLAGS) -c -o $@ $< + + +# Link the compiled object files into a .gb ROM file +$(BINS): $(OBJS) + $(LCC) $(LCCFLAGS) -o $(BINS) $(OBJS) + +prepare: + mkdir -p $(OBJDIR) $(RESDIR) + +clean: +# rm -f *.gb *.ihx *.cdb *.adb *.noi *.map + rm -f $(OBJDIR)/*.* + diff --git a/gbdk-lib/examples/gb/hblank_copy/Readme.md b/gbdk-lib/examples/gb/hblank_copy/Readme.md @@ -0,0 +1,5 @@ +HBlank VRAM fast copy routine demo + +Included png images are in the public domain + + diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00001.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00001.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00002.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00002.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00003.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00003.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00004.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00004.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00005.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00005.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00006.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00006.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00007.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00007.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00008.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00008.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00009.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00009.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00010.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00010.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00011.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00011.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00012.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00012.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00013.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00013.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00014.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00014.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00015.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00015.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00016.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00016.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00017.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00017.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00018.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00018.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00019.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00019.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00020.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00020.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00021.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00021.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00022.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00022.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00023.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00023.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00024.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00024.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00025.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00025.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00026.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00026.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00027.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00027.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00028.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00028.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00029.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00029.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00030.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00030.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00031.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00031.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00032.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00032.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00033.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00033.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00034.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00034.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00035.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00035.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00036.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00036.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00037.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00037.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00038.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00038.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00039.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00039.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00040.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00040.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00041.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00041.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00042.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00042.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00043.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00043.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00044.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00044.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00045.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00045.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00046.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00046.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00047.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00047.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00048.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00048.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00049.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00049.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00050.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00050.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00051.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00051.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00052.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00052.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00053.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00053.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00054.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00054.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00055.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00055.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00056.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00056.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00057.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00057.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00058.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00058.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00059.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00059.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00060.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00060.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00061.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00061.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00062.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00062.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00063.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00063.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/res/scene00064.png b/gbdk-lib/examples/gb/hblank_copy/res/scene00064.png Binary files differ. diff --git a/gbdk-lib/examples/gb/hblank_copy/src/data.c b/gbdk-lib/examples/gb/hblank_copy/src/data.c @@ -0,0 +1,136 @@ +#include <gbdk/platform.h> +#include <stdint.h> + +#include "data.h" + +#include "scene00001.h" +#include "scene00002.h" +#include "scene00003.h" +#include "scene00004.h" +#include "scene00005.h" +#include "scene00006.h" +#include "scene00007.h" +#include "scene00008.h" +#include "scene00009.h" +#include "scene00010.h" +#include "scene00011.h" +#include "scene00012.h" +#include "scene00013.h" +#include "scene00014.h" +#include "scene00015.h" +#include "scene00016.h" +#include "scene00017.h" +#include "scene00018.h" +#include "scene00019.h" +#include "scene00020.h" +#include "scene00021.h" +#include "scene00022.h" +#include "scene00023.h" +#include "scene00024.h" +#include "scene00025.h" +#include "scene00026.h" +#include "scene00027.h" +#include "scene00028.h" +#include "scene00029.h" +#include "scene00030.h" +#include "scene00031.h" +#include "scene00032.h" +#include "scene00033.h" +#include "scene00034.h" +#include "scene00035.h" +#include "scene00036.h" +#include "scene00037.h" +#include "scene00038.h" +#include "scene00039.h" +#include "scene00040.h" +#include "scene00041.h" +#include "scene00042.h" +#include "scene00043.h" +#include "scene00044.h" +#include "scene00045.h" +#include "scene00046.h" +#include "scene00047.h" +#include "scene00048.h" +#include "scene00049.h" +#include "scene00050.h" +#include "scene00051.h" +#include "scene00052.h" +#include "scene00053.h" +#include "scene00054.h" +#include "scene00055.h" +#include "scene00056.h" +#include "scene00057.h" +#include "scene00058.h" +#include "scene00059.h" +#include "scene00060.h" +#include "scene00061.h" +#include "scene00062.h" +#include "scene00063.h" +#include "scene00064.h" + +const frame_desc_t frames[ANIMATION_FRAME_COUNT] = { + {.tiles = scene00001_tiles, .bank = BANK(scene00001)}, + {.tiles = scene00002_tiles, .bank = BANK(scene00002)}, + {.tiles = scene00003_tiles, .bank = BANK(scene00003)}, + {.tiles = scene00004_tiles, .bank = BANK(scene00004)}, + {.tiles = scene00005_tiles, .bank = BANK(scene00005)}, + {.tiles = scene00006_tiles, .bank = BANK(scene00006)}, + {.tiles = scene00007_tiles, .bank = BANK(scene00007)}, + {.tiles = scene00008_tiles, .bank = BANK(scene00008)}, + {.tiles = scene00009_tiles, .bank = BANK(scene00009)}, + {.tiles = scene00010_tiles, .bank = BANK(scene00010)}, + {.tiles = scene00011_tiles, .bank = BANK(scene00011)}, + {.tiles = scene00012_tiles, .bank = BANK(scene00012)}, + {.tiles = scene00013_tiles, .bank = BANK(scene00013)}, + {.tiles = scene00014_tiles, .bank = BANK(scene00014)}, + {.tiles = scene00015_tiles, .bank = BANK(scene00015)}, + {.tiles = scene00016_tiles, .bank = BANK(scene00016)}, + {.tiles = scene00017_tiles, .bank = BANK(scene00017)}, + {.tiles = scene00018_tiles, .bank = BANK(scene00018)}, + {.tiles = scene00019_tiles, .bank = BANK(scene00019)}, + {.tiles = scene00020_tiles, .bank = BANK(scene00020)}, + {.tiles = scene00021_tiles, .bank = BANK(scene00021)}, + {.tiles = scene00022_tiles, .bank = BANK(scene00022)}, + {.tiles = scene00023_tiles, .bank = BANK(scene00023)}, + {.tiles = scene00024_tiles, .bank = BANK(scene00024)}, + {.tiles = scene00025_tiles, .bank = BANK(scene00025)}, + {.tiles = scene00026_tiles, .bank = BANK(scene00026)}, + {.tiles = scene00027_tiles, .bank = BANK(scene00027)}, + {.tiles = scene00028_tiles, .bank = BANK(scene00028)}, + {.tiles = scene00029_tiles, .bank = BANK(scene00029)}, + {.tiles = scene00030_tiles, .bank = BANK(scene00030)}, + {.tiles = scene00031_tiles, .bank = BANK(scene00031)}, + {.tiles = scene00032_tiles, .bank = BANK(scene00032)}, + {.tiles = scene00033_tiles, .bank = BANK(scene00033)}, + {.tiles = scene00034_tiles, .bank = BANK(scene00034)}, + {.tiles = scene00035_tiles, .bank = BANK(scene00035)}, + {.tiles = scene00036_tiles, .bank = BANK(scene00036)}, + {.tiles = scene00037_tiles, .bank = BANK(scene00037)}, + {.tiles = scene00038_tiles, .bank = BANK(scene00038)}, + {.tiles = scene00039_tiles, .bank = BANK(scene00039)}, + {.tiles = scene00040_tiles, .bank = BANK(scene00040)}, + {.tiles = scene00041_tiles, .bank = BANK(scene00041)}, + {.tiles = scene00042_tiles, .bank = BANK(scene00042)}, + {.tiles = scene00043_tiles, .bank = BANK(scene00043)}, + {.tiles = scene00044_tiles, .bank = BANK(scene00044)}, + {.tiles = scene00045_tiles, .bank = BANK(scene00045)}, + {.tiles = scene00046_tiles, .bank = BANK(scene00046)}, + {.tiles = scene00047_tiles, .bank = BANK(scene00047)}, + {.tiles = scene00048_tiles, .bank = BANK(scene00048)}, + {.tiles = scene00049_tiles, .bank = BANK(scene00049)}, + {.tiles = scene00050_tiles, .bank = BANK(scene00050)}, + {.tiles = scene00051_tiles, .bank = BANK(scene00051)}, + {.tiles = scene00052_tiles, .bank = BANK(scene00052)}, + {.tiles = scene00053_tiles, .bank = BANK(scene00053)}, + {.tiles = scene00054_tiles, .bank = BANK(scene00054)}, + {.tiles = scene00055_tiles, .bank = BANK(scene00055)}, + {.tiles = scene00056_tiles, .bank = BANK(scene00056)}, + {.tiles = scene00057_tiles, .bank = BANK(scene00057)}, + {.tiles = scene00058_tiles, .bank = BANK(scene00058)}, + {.tiles = scene00059_tiles, .bank = BANK(scene00059)}, + {.tiles = scene00060_tiles, .bank = BANK(scene00060)}, + {.tiles = scene00061_tiles, .bank = BANK(scene00061)}, + {.tiles = scene00062_tiles, .bank = BANK(scene00062)}, + {.tiles = scene00063_tiles, .bank = BANK(scene00063)}, + {.tiles = scene00064_tiles, .bank = BANK(scene00064)} +}; diff --git a/gbdk-lib/examples/gb/hblank_copy/src/data.h b/gbdk-lib/examples/gb/hblank_copy/src/data.h @@ -0,0 +1,20 @@ +#ifndef __DATA_H_INCLUDE__ +#define __DATA_H_INCLUDE__ + +#include <stdint.h> + +// width and height of the map +#define MAP_WIDTH 14 +#define MAP_HEIGHT 9 + +// number of animation frames +#define ANIMATION_FRAME_COUNT 64 + +typedef struct frame_desc_t { + const uint8_t * tiles; + uint8_t bank; +} frame_desc_t; + +extern const frame_desc_t frames[ANIMATION_FRAME_COUNT]; + +#endif + diff --git a/gbdk-lib/examples/gb/hblank_copy/src/main.c b/gbdk-lib/examples/gb/hblank_copy/src/main.c @@ -0,0 +1,101 @@ +#include <gbdk/platform.h> +#include <gb/hblankcpy.h> + +#include <stdint.h> +#include <stdbool.h> + +#include "data.h" + +// X and Y posisions are centered +#define POSITION_X ((DEVICE_SCREEN_WIDTH - MAP_WIDTH) >> 1) +#define POSITION_Y ((DEVICE_SCREEN_HEIGHT - MAP_HEIGHT) >> 1) + +const frame_desc_t * current_frame = frames; // pointer to the current animation frame + +void LCD_ISR(void) { + static bool odd_even_frame = false; + uint8_t _save = _current_bank; + SWITCH_ROM(current_frame->bank); + if (odd_even_frame = !odd_even_frame) { + LCDC_REG &= ~LCDCF_BG8000; + hblank_copy_destination = _VRAM8000; + hblank_copy_vram(current_frame->tiles, MAP_WIDTH * MAP_HEIGHT); + } else { + LCDC_REG |= LCDCF_BG8000; + hblank_copy_destination = _VRAM9000; + hblank_copy_vram(current_frame->tiles, MAP_WIDTH * MAP_HEIGHT); + } + SWITCH_ROM(_save); +} + +uint8_t joy = 0, old_joy; +inline void PROCESS_INPUT(void) { + old_joy = joy, joy = joypad(); +} +inline uint8_t KEY_PRESSED(uint8_t key) { + return ((joy & ~old_joy) & key); +} + +bool animation = true; // animation enabled +bool animation_direction = true; // animate forward or back +uint8_t animation_speed = 1, animation_counter = 0; // animation speed and counter + +void main(void) { + DISPLAY_OFF; + + CRITICAL { + LYC_REG = 0, STAT_REG |= STATF_LYC; + add_LCD(LCD_ISR); + } + set_interrupts(IE_REG | LCD_IFLAG); + + // set up palette + BGP_REG = DMG_PALETTE(DMG_WHITE, DMG_LITE_GRAY, DMG_DARK_GRAY, DMG_BLACK); + + // clear screen and set tile map + fill_bkg_rect(0, 0, 32, 32, 0); + uint8_t v = 0; + for (uint8_t y = POSITION_Y; y != POSITION_Y + MAP_HEIGHT; y++) { + uint8_t * addr = set_bkg_tile_xy(POSITION_X, y, v++); + for (uint8_t x = 0; x != MAP_WIDTH - 1; x++) set_vram_byte(++addr, v++); + } + + SHOW_BKG; + DISPLAY_ON; + + bool step_animation = false; + + while (true) { + vsync(); + PROCESS_INPUT(); + // stepping through animation frames with LEFT/RIGHT + if (joy & J_LEFT) { + animation = false; + animation_direction = false; + step_animation = true; + } else if (joy & J_RIGHT) { + animation = false; + animation_direction = true; + step_animation = true; + } + // change the animation speed with UP/DOWN + if (KEY_PRESSED(J_UP)) { + if (animation_speed) animation_speed--; + } else if (KEY_PRESSED(J_DOWN)) { + if (++animation_speed > 10) animation_speed = 10; + } + // start/stop animation with START + if (KEY_PRESSED(J_START)) animation = !animation; + + // process animation + if ((step_animation) || ((animation) && (++animation_counter > animation_speed))) { + animation_counter = 0; + if (animation_direction) CRITICAL { + if (++current_frame == (frames + ANIMATION_FRAME_COUNT)) current_frame = frames; + } else CRITICAL { + if (--current_frame < frames) current_frame = frames + (ANIMATION_FRAME_COUNT - 1); + } + step_animation = false; + } + } +} + diff --git a/gbdk-lib/include/gb/hblankcpy.h b/gbdk-lib/include/gb/hblankcpy.h @@ -0,0 +1,34 @@ +#ifndef __HBLANKCPY_H_INCLUDE__ +#define __HBLANKCPY_H_INCLUDE__ + +#include <stdint.h> + +/** HBlank stack copy routine + * takes stack_copy_destination and stack_copy_source global variables as parameters + * manipulates STAT, IE, IF on enter, restores STAT, IE on exit + * interrupts must be disabled on call + @param count number of 16 byte chunks to copy +*/ +void hblank_copy_vram(const uint8_t * sour, uint8_t count); + +/** HBlank stack copy routine + * takes stack_copy_destination and stack_copy_source global variables as parameters + * interrupts must be properly configured + * interrupts must be disabled on call + @param count number of 16 byte chunks to copy +*/ +void hblank_cpy_vram(const uint8_t * sour, uint8_t count); + +extern uint8_t * hblank_copy_destination; + +/** HBlank stack copy routine (must be called with disabled interrupts!) + @param dest destination pointer + @param sour source pointer + @param size number of bytes to copy (rounded to 16-byte chunks) +*/ +inline void hblank_copy(uint8_t * dest, const uint8_t * sour, uint16_t size) { + hblank_copy_destination = dest; + hblank_copy_vram(sour, size >> 4); +} + +#endif + diff --git a/gbdk-lib/libc/targets/sm83/ap/Makefile b/gbdk-lib/libc/targets/sm83/ap/Makefile @@ -34,6 +34,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_tile_submap.s set_win_tile_submap.s \ gb_decompress.s gb_decompress_tiles.s \ rle_decompress.s \ + hblankcpy.s \ heap.s \ sfr.s \ crt0.s diff --git a/gbdk-lib/libc/targets/sm83/duck/Makefile b/gbdk-lib/libc/targets/sm83/duck/Makefile @@ -34,6 +34,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_tile_submap.s set_win_tile_submap.s \ gb_decompress.s gb_decompress_tiles.s \ rle_decompress.s \ + hblankcpy.s \ heap.s \ sfr.s \ crt0.s diff --git a/gbdk-lib/libc/targets/sm83/gb/Makefile b/gbdk-lib/libc/targets/sm83/gb/Makefile @@ -34,6 +34,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_tile_submap.s set_win_tile_submap.s \ gb_decompress.s gb_decompress_tiles.s \ rle_decompress.s \ + hblankcpy.s \ heap.s \ sfr.s \ crt0.s diff --git a/gbdk-lib/libc/targets/sm83/hblankcpy.s b/gbdk-lib/libc/targets/sm83/hblankcpy.s @@ -0,0 +1,92 @@ +.include "global.s" + +.area _CODE + +; de : source +; a : count +; (hblank_copy_destination) : destination +_hblank_copy_vram:: + ld hl, #rIE + ld c, (hl) + ld (hl), #IEF_STAT + ld hl, #rSTAT + ld b, (hl) + ld (hl), #STATF_MODE00 + push bc + ld bc, #_hblank_copy_vram_tail + push bc + +; de : source +; a : count +; (hblank_copy_destination) : destination +_hblank_cpy_vram:: + ld h, d + ld l, e + ld (stack_save), sp + + ld sp, #_hblank_copy_destination + pop de + + ld sp, hl ; sp = sour + ld h, d + ld l, e ; hl = dest + +1$: + ld (vram_cpy_counter), a + + pop de ; prefetch + pop bc ; prefetch + xor a + ldh (rIF), a ; reset pending interrupts + ld a, e ; prepare the first byte + + halt + + ld (hl+), a ; copy two bytes + ld a, d + ld (hl+), a + ld a, c + ld (hl+), a ; copy two bytes + ld a, b + ld (hl+), a +.rept 5 + pop de ; copy ten bytes + ld a, e + ld (hl+), a + ld a, d + ld (hl+), a +.endm + pop de ; copy two bytes + ld a, e + ld (hl+), a + ld (hl), d + inc hl + + ld a, (vram_cpy_counter) + dec a + jr nz, 1$ + + ld sp, #stack_save + pop hl + ld sp, hl + ret + +_hblank_copy_vram_tail: + pop bc + ld a, b + ldh (rSTAT), a + ld a, c + ldh (rIE), a + xor a + ldh (rIF), a ; reset pending interrupts + ret + + +.area _DATA + +vram_cpy_counter: + .ds 1 +stack_save: + .ds 2 +_hblank_copy_destination:: + .ds 2 +

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.