diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-09 22:43:33 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-09 22:43:33 +0100 |
commit | d532317c011b9e5653241d50b961ee8caa710144 (patch) | |
tree | cb9fb308b9a92aa667ee626c8474b3e1e9f6f083 | |
parent | 741561787cc2df547d5f520a142beaff234c488e (diff) | |
download | tr8vm-d532317c011b9e5653241d50b961ee8caa710144.tar.gz tr8vm-d532317c011b9e5653241d50b961ee8caa710144.zip |
Playground
Potential example game.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | game/Makefile | 15 | ||||
-rw-r--r-- | game/assets/player.png | bin | 0 -> 7775 bytes | |||
-rw-r--r-- | game/entities.asm | 263 | ||||
-rw-r--r-- | game/main.asm | 75 | ||||
-rw-r--r-- | game/player.asm | 48 |
6 files changed, 405 insertions, 1 deletions
@@ -24,11 +24,14 @@ stb_image.o: stb_image.c stb_image.h example: example.tr8 tr8vm ./tr8vm example.tr8 +game: + make -C game run + example.tr8: example.asm tr8as ./tr8as example.asm example.tr8 clean: rm -f tr8as tr8vm example.tr8 *.o -.PHONY: clean all example +.PHONY: clean all example game diff --git a/game/Makefile b/game/Makefile new file mode 100644 index 0000000..9014844 --- /dev/null +++ b/game/Makefile @@ -0,0 +1,15 @@ + +BIN := game.tr8 +SRCS := $(wildcard *.asm) $(wildcard assets/*.png) + +game.tr8: $(SRCS) + ../tr8as main.asm $(BIN) + +run: $(BIN) + ../tr8vm $< + +clean: + rm -f $(BIN) + +.PHONY: clean run + diff --git a/game/assets/player.png b/game/assets/player.png Binary files differnew file mode 100644 index 0000000..13b7242 --- /dev/null +++ b/game/assets/player.png diff --git a/game/entities.asm b/game/entities.asm new file mode 100644 index 0000000..fa9d8fd --- /dev/null +++ b/game/entities.asm @@ -0,0 +1,263 @@ +; +; Simple array based entity system +; + +.equ ET_NONE 0 +.equ ET_PLAYER 1 +.equ ET_ENEMY 2 +.equ ET_END 0xff + +.equ ET_BG 0xa000 + +entities_erase: + ; bg is stored in ET_BG addr + ld b, >ET_BG + push b + + ld x, <entities + ld a, >entities + +entities_erase_next: + ld y, [a : x] + cmp y, ET_END + bz + jmp entities_erase_done + + ; write, no transparent + ld y, 1 + push y + + ; dst: x + inc x + bo + inc a + ld y, [a : x] + push y + + ; dst: y + inc x + bo + inc a + ld y, [a : x] + push y + + ; src: saved bg + ld y, [sp + 3] + push y + ld y, 0 + push y + + call entities_blt + + pop y + pop y + pop y + pop y + pop y + + ; next entity + add x, 5 + bo + inc a + + pop b + inc b + push b + + jmp entities_erase_next + +entities_erase_done: + pop a + ret + +entities_update: + ld x, <entities + ld a, >entities + +entities_update_next: + ld y, [a : x] + cmp y, ET_END + bz + ret + + push a + push x + + add x, 5 + bo + inc a + + ld y, [a : x] + inc x + bo + inc a + ld b, [a : x] + inc x + bo + inc a + + ld x, [sp + 0] + ld a, [sp + 1] + + ; entity update + push a + push x + call [b : y] + pop x + pop x + + pop x + pop a + + add x, 7 + bo + inc a + + jmp entities_update_next + +entities_draw: + ; bg is stored in ET_BG addr + ld b, >ET_BG + push b + + ld x, <entities + ld a, >entities + +entities_draw_next: + ld y, [a : x] + cmp y, ET_END + bz + jmp entities_draw_done + + inc x + bo + inc a + ; save x addr for later + push a + push x + + ; save bg + + ; read, no transparent + ld y, 4 + push y + + ; dst: x + ld y, [a : x] + push y + + ; dst: y + inc x + bo + inc a + ld y, [a : x] + push y + + ; dst: save bg + ld y, [sp + 5] + push y + ld y, 0 + push y + + call entities_blt + + pop y + pop y + pop y + pop y + pop y + + ; draw sprite + + ; x addr + pop x + pop a + + ; write, transparent + ld y, 3 + push y + + ; dst: x + ld y, [a : x] + push y + + ; dst: y + inc x + bo + inc a + ld y, [a : x] + push y + + ; src: the sprite + inc x + bo + inc a + ld y, [a : x] + inc x + bo + inc a + ld b, [a : x] + push b + push y + + call entities_blt + + pop y + pop y + pop y + pop y + pop y + + ; next entity + add x, 3 + bo + inc a + + pop b + inc b + push b + + jmp entities_draw_next + +entities_draw_done: + pop a + ret + +; sp: write mode +; y coord +; x coord +; addr +entities_blt: + ; settings mode + ld y, 128 + ld b, 0xb0 + port b, y + + ; setup + inc b + + ; addr + ld y, [sp + 2] + port b, y + ld y, [sp + 3] + port b, y + + ; x + ld y, [sp + 5] + port b, y + ; y + ld y, [sp + 4] + port b, y + + ; 16x16 + ld y, 16 + port b, y + port b, y + + ; blit + dec b + ; write mode + ld y, [sp + 6] + port b, y + ret + diff --git a/game/main.asm b/game/main.asm new file mode 100644 index 0000000..3062ead --- /dev/null +++ b/game/main.asm @@ -0,0 +1,75 @@ +.org 0 + +.equ INT_VECTOR 0xff00 + + call init + +game_loop: + halt + + call entities_erase + call entities_update + call entities_draw + + jmp game_loop + +init: + ; setup an int handler so we + ; can use the frame int to sync + ld a, >INT_VECTOR + ld x, <INT_VECTOR + ld b, <int_handler + ld [a : x], b + inc x + ld b, >int_handler + ld [a : x], b + + ; enable interrupts + cif + + halt + + ; pattern for the BG + ld b, 15 + ld a, 0xbf + ld x, 0 + ld y, 0x40 +fill_loop: + ld [a : x], b + xor b, 5 + inc x + bno + jmp fill_loop + inc a + dec y + bnz + jmp fill_loop + + call entities_draw + + ret + +int_handler: + iret + +.include "entities.asm" +.include "player.asm" + +; +; entity data +; +entities: + ; type + .db ET_PLAYER + ; x, y + .db 0, 0 + .dw player_sprite + .dw player_update + + ; end of list + .db ET_END + +; sprite data +player_sprite: + .incpng "assets/player.png" + diff --git a/game/player.asm b/game/player.asm new file mode 100644 index 0000000..4a6537f --- /dev/null +++ b/game/player.asm @@ -0,0 +1,48 @@ +; +; player update code +; + +player_update: + ld x, [sp + 2] + ld a, [sp + 3] + + ; read controller 1 + ld b, 0xf0 + port b, b + + inc x + bo + inc a + ; x coord + ld y, [a : x] + + ; left + bit b, 4 + bz + dec y + ; right + bit b, 5 + bz + inc y + + ld [a : x], y + + inc x + bo + inc a + ; y coord + ld y, [a : x] + + ; up + bit b, 2 + bz + dec y + ; down + bit b, 3 + bz + inc y + + ld [a : x], y + + ret + |