From: Lukas Krickl Date: Sat, 28 Jun 2025 16:52:21 +0000 (+0200) Subject: wip: demo inputs X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=6b14a93e3cf2f141cb58686fac364cc61cdc99c0;p=gbrg%2F.git wip: demo inputs This is currently very broken due to a map actor loader out of bounds read --- diff --git a/BUGS.md b/BUGS.md index b5b30c1..a2a242e 100644 --- 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 index 0000000..795b839 --- /dev/null +++ b/src/demos.s @@ -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 diff --git a/src/input.s b/src/input.s index b07239f..10c024e 100644 --- a/src/input.s +++ b/src/input.s @@ -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: diff --git a/src/main.s b/src/main.s index ae6ddb2..d48f976 100644 --- a/src/main.s +++ b/src/main.s @@ -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 - $ diff --git a/src/mem.s b/src/mem.s index cdad297..7c1391b 100644 --- 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: diff --git a/src/wram.s b/src/wram.s index 30ed67f..516f054 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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