debug: debug rectangle draw now uses the same point functions as collisions
authorLukas Krickl <lukas@krickl.dev>
Tue, 23 Sep 2025 03:45:06 +0000 (05:45 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 23 Sep 2025 03:45:06 +0000 (05:45 +0200)
This is still wip and kinda broken now

src/debug.s

index 66d3c5b517149fbded9268fcef4ea98aecf2cf33..427c406a580340059878da12e0617be772b18c9d 100644 (file)
@@ -68,6 +68,25 @@ dbg_update:
        ld [dbg_delay], a
        ret
        
+       ; gets rectangle point and loads it into de
+       ; preserves all other registers
+       ; inputs:
+       ;               $1: rect_br/bl/tr/tl
+       ;               de: rectangle ptr
+#macro dbg_rect_draw_get
+       push hl
+       push de
+       
+       push de
+       pop hl ; hl = rectangle
+       call $1
+       push de
+       pop bc ; bc = point
+
+       pop de
+       pop hl
+#endmacro
+
        ; draws a marker obj at 
        ; the edge of a rectangle
        ; keys:
@@ -97,24 +116,17 @@ dbg_rect_draw:
        pop de
 
        ; hl = oam
-       inc de ; de = y position
-
-       ld a, [de]
-       add a, OBJ_OFF_Y
-       ld b, a ; b = y
-       
-       inc de
-       ld a, [de]
-       add a, OBJ_OFF_X
-       ld c, a ; c = x
-       inc de ; de = height
+       dbg_rect_draw_get rect_tl
+       ; bc = top left
        
        ; write top left y
        ld a, b
+       add a, OBJ_OFF_Y
        ld [hl+], a
 
        ; write top left x
        ld a, c
+       add a, OBJ_OFF_X
        ld [hl+], a
 
        ; write tile
@@ -124,20 +136,19 @@ dbg_rect_draw:
        ; write flags
        xor a, a
        ld [hl+], a
-       
-       ; write top left y
-       ld a, [de] ; a = heigth
 
-       push bc
-       ld c, a 
-       ld a, b
-       sub a, c ; height -  y
-       pop bc
 
+       ; bottom left
+       dbg_rect_draw_get rect_bl
+       
+       ; write bottom left y
+       ld a, b
+       add a, OBJ_OFF_Y
        ld [hl+], a
 
-       ; write top left x
+       ; write bottom left x
        ld a, c 
+       add a, OBJ_OFF_X
        ld [hl+], a
        
        ; write tile
@@ -148,14 +159,19 @@ dbg_rect_draw:
        xor a, a
        ld [hl+], a
 
+
+
+       ; bottom right
+       dbg_rect_draw_get rect_br
+
        ; write bottom right y
-       inc de ; de = width
-       ld a, b ; a = y
+       ld a, b
+       add a, OBJ_OFF_Y
        ld [hl+], a
 
        ; write bottomt right x
        ld a, [de]
-       add a, c ; width + x
+       add a, OBJ_OFF_X
        ld [hl+], a
 
        ; write tile 
@@ -166,23 +182,18 @@ dbg_rect_draw:
        xor a, a
        ld [hl+], a
 
-       dec de ; de = height
 
-       ; write top right y
-       ld a, [de] ; a = height
 
-       push bc
-       ld c, a
-       ld a, b
-       sub a, c ; height - y
-       pop bc
+       ; top right
+       dbg_rect_draw_get rect_tr
 
+       ld a, b
+       add a, OBJ_OFF_X
        ld [hl+], a
 
        ; write top left x
-       inc de ; de = width
-       ld a, [de]
-       add a, c ; width + x 
+       add a, c 
+       add a, OBJ_OFF_X
        ld [hl+], a
 
        ; write tile