wip: demo inputs
authorLukas Krickl <lukas@krickl.dev>
Sat, 28 Jun 2025 16:52:21 +0000 (18:52 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 28 Jun 2025 16:52:21 +0000 (18:52 +0200)
This is currently very broken due to a map actor loader out of bounds
read

BUGS.md
src/demos.s [new file with mode: 0644]
src/input.s
src/main.s
src/mem.s
src/wram.s

diff --git a/BUGS.md b/BUGS.md
index b5b30c1f3fe773c8ca117d9fd9aea54ef1ccb45e..a2a242edcbda419e41deefb54bbf0b56168623fa 100644 (file)
--- a/BUGS.md
+++ b/BUGS.md
@@ -1,4 +1,9 @@
 # Known Bugs
 
+## Map actor loads are happening far out of bounds
+
+This causes random values being read as actor data.
+This bug only manifested itself as code went beyond 0x22a2.
+
 
 
diff --git a/src/demos.s b/src/demos.s
new file mode 100644 (file)
index 0000000..795b839
--- /dev/null
@@ -0,0 +1,23 @@
+demo_inputs1:
+; this file contains some demo-input recordings
+.db BTNLEFT, BTNLEFT, BTNLEFT, BTNLEFT, BTNLEFT, BTNLEFT, 0xFF 
+
+  ; load demo ptr
+  ; inputs
+  ;   hl: demo ptr
+  ; writes ptr to demo_inpiuts
+ load_demo_ptr:
+  ld l, a
+  ld [de], a
+  inc de
+  ld h, a
+  ld [de], a
+  ret
+  
+  ; clears demo inputs 
+clear_demo_ptr:
+  ld hl, demo_inputs
+  xor a, a
+  ld [hl+], a
+  ld [hl], a
+  ret
index b07239f74db753cd2db404c7216e673ac52468c0..10c024eb43ac89f3f1f80805dabcc627bbb3dede 100644 (file)
@@ -23,7 +23,8 @@
   ld a, [curr_inputs] 
   and a, $1
 #endmacro
-
+  
+  ; TODO: if demo_inputs is set read from inputs instead of polling 
   ; poll inputs
   ; returns:
   ;   new inputs in [curr_inputs]
@@ -32,6 +33,13 @@ poll_inputs:
   ld a, [curr_inputs]
   ld [prev_inputs], a
 
+  ld a, [demo_inputs]
+  ld b, a
+  ld a, [demo_inputs+1]
+  or a, b 
+  ; a == null?
+  jr nz, @read_demo_input REL
+
   ld a, P1FDPAD
   call poll_p1
   swap a
@@ -47,6 +55,31 @@ poll_inputs:
 
   ret 
 
+@read_demo_input:
+  ; load ptr 
+  ld de, demo_inputs
+  ld a, [de]
+  ld l, a
+  inc de
+  ld a, [de] 
+  ld h, a ; hl = inputs
+  dec de
+
+  ld a, [hl+]
+  cp a, 0xFF ; is the list done?
+  jr z, @demo_done REL
+  
+  ; sotre value
+  ld [curr_inputs], a
+
+  ; store new ptr
+  jp load_demo_ptr
+@demo_done:
+  xor a, a
+  ; clear inputs and ptr
+  ld [curr_inputs], a
+  jp clear_demo_ptr 
+
 
   ; poll p1 
   ; inputs:
index ae6ddb20b840e7a8b0d2a582095f8a96bb5cd75f..d48f97670eaf191d5a9120c8d6b1368760e06129 100644 (file)
@@ -68,6 +68,7 @@ main:
 #include "text.s"
 #include "stats.s"
 #include "actortables.s"
+#include "demos.s"
 
 ; fill bank
-.fill 0, 0x7FFF - $
+.fill 0xFF, 0x7FFF - $
index cdad297f026d6984b5e3bd88ba5eed8391d781b4..7c1391b1ebb43fb62f3487b28e77828b0692a5c1 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -25,6 +25,10 @@ mem_init:
   ld bc, st_size
   call memcpy
 
+  ; load a demo
+  ; ld hl, demo1
+  ; call load_demo_ptr
+
   ret
 
 game_init:
index 30ed67fb9b83c4b11ec6610b41ded7e1862cc4bb..516f05443152ca598f8977c1741d63c9fdd36198 100644 (file)
@@ -26,6 +26,13 @@ game_mode: .adv st_size
   ; status text buffer
 status_text: .adv 32
 
+  ; ptr to demo inputs
+  ; provides one byte of inputs per frame
+  ; if all buttons are held (value is 0xFF) it indicates the end
+  ; of the input list
+  ; if set to NULL do not read from this address
+demo_inputs: .adv 2
+
   ; offset into bg_update_queue 
 bg_update_index: .adv 2
 bg_update_queue: .adv bge_size * BGE_MAX