From: Lukas Krickl Date: Wed, 2 Oct 2024 04:40:14 +0000 (+0200) Subject: Added basic setup for game loop updating X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=1b4e2e5cb9dea72a504734c58510555825e3738d;p=gbrg%2F.git Added basic setup for game loop updating --- diff --git a/src/main.s b/src/main.s index 9d751ff..0f83161 100644 --- a/src/main.s +++ b/src/main.s @@ -23,7 +23,13 @@ entry: main: @forever: - jp @forever + ld a, [frame_ready] + cp a, 0 + jr z, @forever REL + call update + xor a, a + ld [frame_ready], a + jr @forever REL #include "tiles.inc" #include "video.s" @@ -31,6 +37,8 @@ main: #include "strings.s" #include "sys.s" #include "input.s" +#include "player.s" +#include "update.s" ; fill bank .fill 0, 0x7FFF - $ diff --git a/src/player.s b/src/player.s new file mode 100644 index 0000000..43401ef --- /dev/null +++ b/src/player.s @@ -0,0 +1,8 @@ + ; update the player + ; players do not behave like regular actors + ; and are not allocate to the regular + ; actor table + ; inputs: + ; hl: pointer to player memory +player_update: + ret diff --git a/src/update.s b/src/update.s new file mode 100644 index 0000000..aafc220 --- /dev/null +++ b/src/update.s @@ -0,0 +1,11 @@ + ; called after vblank +update: + ld a, [frame_count] + inc a + ld [frame_count], a + + ; update player + ld hl, player + call player_update + + ret diff --git a/src/video.s b/src/video.s index b61bac0..4d4bf54 100644 --- a/src/video.s +++ b/src/video.s @@ -1,7 +1,9 @@ ; vblank handler vblank: + ; dma previous frame's oam call OAMDMAFN + ; get inputs call poll_inputs ; test puts @@ -9,7 +11,8 @@ vblank: ld de, SCRN0 call puts - + ld a, 1 + ld [frame_ready], a ret ; wait for next vblank diff --git a/src/wram.s b/src/wram.s index c206cc6..e96ab66 100644 --- a/src/wram.s +++ b/src/wram.s @@ -6,6 +6,9 @@ shadow_oam: .adv OBJSMAX * oamsize +frame_ready: .adv 1 +frame_count: .adv 1 + #define ACTORS_MAX 16 ; current frame's inputs @@ -26,3 +29,12 @@ prev_inputs: .adv 1 .de actor_size, 0 actor_table: .adv ACTORS_MAX * actor_size + +; struct player +.se 0 +.de player_y, 1 +.de player_x, 1 +.de player_flags, 1 +.de player_size, 0 + +player: .adv player_size