From 58a2afc01f8ef64b8f92c5c26e05d3e54adf64f6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 4 Dec 2024 08:11:11 +0100 Subject: [PATCH] WIP: reworking room flag access --- src/collision.s | 42 +----------------------------------------- src/macros.inc | 10 ++++++++++ src/map.s | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/collision.s b/src/collision.s index 5d84f71..4ecd53c 100644 --- a/src/collision.s +++ b/src/collision.s @@ -35,8 +35,6 @@ collision_player: col_head 1 col_point 0, 0 -collision_tile_lut: - .rep cti, ROOM_H, 1, .db cti * ROOM_W ; checks an entire collision table based on an original point ; and a ptr to a collision point table @@ -108,45 +106,7 @@ collision_tile_table_check: ; a = 0 -> no collision ; a = 1 -> collision collision_tile: - ; y pos / 16 -> tile pos - srl d ; / 2 - srl d ; / 4 - srl d ; / 8 - srl d ; / 16 - - ; x pos / 16 -> tile pos - srl e ; / 2 - srl e ; / 4 - srl e ; / 8 - srl e ; / 16 - ld a, e ; a = x pos - - ld e, d - ld d, 0 ; de = y position now - - ; -> now convert position to - ; map flag index using a simple lut - ; for y position + x - ld hl, collision_tile_lut - add hl, de ; hl + y offset - ; hl = row ptr - ld e, a ; e = x pos - ld a, [hl] ; a = map flags row offset - add a, e ; row + x = position of tile in map - - push af - - ld hl, curr_room_flags ; hl = flags for currently loaded room - ld a, [hl+] ; load curr room flags ptr - ld e, a - ld a, [hl] - ld d, a ; de = flags pointer - - pop af - ld h, 0 - ld l, a ; hl = tile offset - add hl, de ; hl + de - + call room_get_flag_ptr ; hl = current tile flags ld a, [hl] ; load flags diff --git a/src/macros.inc b/src/macros.inc index a0fd3c8..91a04e9 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -73,4 +73,14 @@ ld e, a add hl, de ; hl = correct tile index ld a, [hl] +#endmacro + + ; divides a regiser by 16 + ; inputs: + ; $1: the register +#macro div16 + srl $1 ; / 2 + srl $1 ; / 4 + srl $1 ; / 8 + srl $1 ; / 16 #endmacro diff --git a/src/map.s b/src/map.s index 41acf89..d6e4409 100644 --- a/src/map.s +++ b/src/map.s @@ -195,6 +195,51 @@ room_draw: ret +room_tile_lut: + .rep cti, ROOM_H, 1, .db cti * ROOM_W + + ; loads the flag pointer for a position into hl + ; inputs: + ; de: y/x + ; returns: + ; hl: pointer to flag at position y/x + ; uses: + ; de, hl, a +room_get_flag_ptr: + ; y pos / 16 -> tile pos + div16 d + + ; x pos / 16 -> tile pos + div16 e + ld a, e ; a = x pos + + ld e, d + ld d, 0 ; de = y position now + + ; -> now convert position to + ; map flag index using a simple lut + ; for y position + x + ld hl, room_tile_lut + add hl, de ; hl + y offset + ; hl = row ptr + ld e, a ; e = x pos + ld a, [hl] ; a = map flags row offset + add a, e ; row + x = position of tile in map + + push af + + ld hl, curr_room_flags ; hl = flags for currently loaded room + ld a, [hl+] ; load curr room flags ptr + ld e, a + ld a, [hl] + ld d, a ; de = flags pointer + + pop af + ld h, 0 + ld l, a ; hl = tile offset + add hl, de ; hl + de + ret + ; sets a tile position flag ; as a flag ; for actor -> actor collision detection -- 2.30.2