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
; 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
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
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