Added basic setup for game loop updating
authorLukas Krickl <lukas@krickl.dev>
Wed, 2 Oct 2024 04:40:14 +0000 (06:40 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 2 Oct 2024 04:40:14 +0000 (06:40 +0200)
src/main.s
src/player.s [new file with mode: 0644]
src/update.s [new file with mode: 0644]
src/video.s
src/wram.s

index 9d751ff05b645dde72a3c77b9f1ad5d70acf2c86..0f8316112fae53dfcd875478b7e82a2e79309cff 100644 (file)
@@ -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 (file)
index 0000000..43401ef
--- /dev/null
@@ -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 (file)
index 0000000..aafc220
--- /dev/null
@@ -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
index b61bac05b13a89d6d98530315a4dedf6997b69b0..4d4bf54d6f23ac396b72cbd8c63b00337f704b48 100644 (file)
@@ -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
index c206cc6a04a8a3d4736f5360e1517bab18717694..e96ab66cb97bc804ad1b4dea7d410c255feefe6f 100644 (file)
@@ -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