From f0daf2ca11be14633d789dda13bc29f167c45f4e Mon Sep 17 00:00:00 2001 From: Forest Belton <65484+forestbelton@users.noreply.github.com> Date: Mon, 28 Jun 2021 15:51:43 -0400 Subject: [PATCH] Start player draw code --- .gitignore | 3 ++- Makefile | 18 +++++++++++++++--- png/player.png | Bin 0 -> 135 bytes src/main.s | 15 ++++++++++++++- src/player.s | 43 +++++++++++++++++++++++++++++++++++++++++++ src/util.s | 13 +++++++++++++ 6 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 png/player.png create mode 100644 src/player.s create mode 100644 src/util.s diff --git a/.gitignore b/.gitignore index dbd5d74..fd03f29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ is.gb is.gb.sym -*.o \ No newline at end of file +*.o +*.2bpp \ No newline at end of file diff --git a/Makefile b/Makefile index 8de0fcb..2d8cd9c 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,22 @@ +PNGFILES := $(shell find png -type f -name '*.png') +IMGFILES := $(PNGFILES:%.png=%.2bpp) + SFILES := $(shell find src -type f -name '*.s') OFILES := $(SFILES:%.s=%.o) -OUTPUT := is.gb -$(OUTPUT): $(OFILES) +.PHONY: clean + +is.gb is.gb.sym: $(IMGFILES) $(OFILES) rgblink -o $@ -n $@.sym $(OFILES) rgbfix -v $@ +$(OFILES): $(IMGFILES) + %.o: %.s - rgbasm -o $@ $< \ No newline at end of file + rgbasm -o $@ $< + +%.2bpp: %.png + rgbgfx -o $@ $< + +clean: + rm -f is.gb is.gb.sym $(IMGFILES) $(OFILES) \ No newline at end of file diff --git a/png/player.png b/png/player.png new file mode 100644 index 0000000000000000000000000000000000000000..645c4f60f0327895237bb0448477e4f3fff25b09 GIT binary patch literal 135 zcmeAS@N?(olHy`uVBq!ia0vp^93afW3?x5a^xFxf7>k44ofy`glX(f`@C5jTxX#|g z-@S(4AjyE=g8zqidoxg6)6>N`cOxfId-IyV|BH<|r#LcbzPNd_W{TUkjGk4D eZMRS7zh~g}V~Ez7v2+7a6N9I#pUXO@geCwGM<{dv literal 0 HcmV?d00001 diff --git a/src/main.s b/src/main.s index 9563dc5..d6f8b9e 100644 --- a/src/main.s +++ b/src/main.s @@ -13,5 +13,18 @@ endr SECTION "Code", ROM0 start: + call PlayerInit + + ; enable lcd and interrupts + ld hl, rLCDC + set 7, [hl] + ei + +.vbl: + ld a, [$ff41] + and 3 + cp 1 + jr nz, .vbl + halt - jp start + jp .vbl diff --git a/src/player.s b/src/player.s new file mode 100644 index 0000000..37f8236 --- /dev/null +++ b/src/player.s @@ -0,0 +1,43 @@ +INCLUDE "hardware.inc" + +Section "Player Data", WRAM0 + +playerWorldX: dw +playerWorldY: dw + +; Sprite data +playerScreenX: db +playerScreenY: db +playerTileIndex: db +playerFlags: db + +Section "Player Code", ROM0 + +spriteData: + INCBIN "png/player.2bpp" + +PlayerInit:: + ld a, 8 + ld hl, playerScreenX + ld [hl], a + + ld bc, _VRAM8800 + ld hl, spriteData + ld d, 16 + call memcpy + + ld hl, playerScreenX + ld a, 8 + ld [hli], a + ld a, 144-8*3 + ld [hli], a + + ld bc, _OAMRAM + ld hl, playerScreenX + ld d, 4 + call memcpy + + ret + +PlayerDraw:: + ret diff --git a/src/util.s b/src/util.s new file mode 100644 index 0000000..b2e3945 --- /dev/null +++ b/src/util.s @@ -0,0 +1,13 @@ +SECTION "Utilities", ROM0 + +; Copies data between two regions +; @param d Size (in bytes) to copy. Must be >0 +; @param bc Pointer to the destination region +; @param hl Pointer to the source region +memcpy:: + ld a, [hli] + ld [bc], a + inc bc + dec d + jr nz, memcpy + ret