debug: wip rectangle debug renderer
authorLukas Krickl <lukas@krickl.dev>
Sun, 21 Sep 2025 15:46:04 +0000 (17:46 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 21 Sep 2025 15:46:04 +0000 (17:46 +0200)
src/debug.s
src/rectangle.s
src/update.s
src/video.s
tiles/bank8800.inc

index 558c5b90628e78d8c85d22fd0488669a8f2ca49a..929c22b4f70cfe3781cad798af005c99e7913e02 100644 (file)
@@ -1,3 +1,5 @@
+#define DBG_MARKER_TILE 0x80
+
 debug_routines:
        dw dbg_nop
        dw dbg_rect_draw
@@ -8,6 +10,12 @@ dbg_nop:
        
        ; inits the debug interface
 dbg_init:
+       ; set first rectangle to display
+       ld a, rectangles LO
+       ld [dbg_rect], a
+       ld a, rectangles HI
+       ld [dbg_rect+1], a
+       
        ret
 
        ; updates debug options
@@ -65,4 +73,116 @@ dbg_update:
        ; keys:
        ;               up + select: cycle to next debug rectangle
 dbg_rect_draw:
+       ; TODO: add rectangle cycles
+
+       ; draw each corner of the rectangle if it is not 0
+       ld a, [dbg_rect]
+       ld e, a
+       ld a, [dbg_rect+1]
+       ld d, a
+
+       ; de = rectangle ptr
+       
+       ; if flags are 0 we exit
+       ld a, [de]
+       cp a, 0
+       jp z, @rect_not_alloced
+       
+       push de
+       ld a, 4
+       call oamalloc
+       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
+       
+       ; write top left y
+       ld a, b
+       ld [hl+], a
+
+       ; write top left x
+       ld a, c
+       ld [hl+], a
+
+       ; write tile
+       ld a, DBG_MARKER_TILE
+       ld [hl+], a
+
+       ; write flags
+       xor a, a
+       ld [hl+], a
+       
+       ; write top left y
+       ld a, [de] ; a = heigth
+       sub a, b ; height -  y
+       add a, 16 + OBJ_OFF_Y ; off by one obj height so it won't end up off-screen 
+       ld [hl+], a
+
+       ; write top left x
+       ld a, c 
+       ld [hl+], a
+       
+       ; write tile
+       ld a, DBG_MARKER_TILE
+       ld [hl+], a
+
+       ; write flags
+       xor a, a
+       ld [hl+], a
+
+       ; write bottom right y
+       inc de ; de = width
+       ld a, b ; a = y
+       ld [hl+], a
+
+       ; write bottomt right x
+       ld a, [de]
+       sub a, c
+       add a, OBJ_OFF_X + 8 
+       ld [hl+], a
+
+       ; write tile 
+       ld a, DBG_MARKER_TILE
+       ld [hl+], a
+
+       ; write flags
+       xor a, a
+       ld [hl+], a
+
+       dec de ; de = height
+
+       ; write top right y
+       ld a, [de] ; a = height
+       sub a, b ; height - y
+       add a, 16 + OBJ_OFF_Y ; off by one obj height so it won't end up off-screen 
+       ld [hl+], a
+
+       ; write top left x
+       inc de ; de = width
+       ld a, [de]
+       sub a, c
+       add a, OBJ_OFF_X + 8 
+       ld [hl+], a
+
+       ; write tile 
+       ld a, DBG_MARKER_TILE
+       ld [hl+], a
+
+       ; write flags
+       xor a, a
+       ld [hl+], a
+
+
+       ret
+@rect_not_alloced:
        ret
index 74a0ee1f3b91360a759caddeae4e008a586a0995..3e188481dd2e91c9909fefe76fa0068209f205b8 100644 (file)
@@ -111,4 +111,12 @@ rect_test:
        ;               a == 0: not inside
 rect_point_test:
        ret
+
        
+       ; removes a rectangle
+       ; inputs:
+       ;               de: rectangle
+rect_despawn:
+       xor a, a
+       ld [de], a
+       ret
index 788b685ae5daf39e23d8801d33479a4174db2a50..016a04b94f2745ae1e02ea1f143a2984b2e8b027 100644 (file)
@@ -36,14 +36,15 @@ update:
   ; reset objects
   call oamfree_all 
 
-       call dbg_update
 
        ; load current sate routine
        ld a, [game_state]
        ld l, a
        ld a, [game_state+1]
        ld h, a
-       jp hl
+       call_hl
+       
+       call dbg_update
   
   ret
 
index 5611a8392b7684dd058eb559e0648e35a81c74fa..4f73debcf8437f612e24bdc67784f2a42e07dd07 100644 (file)
@@ -129,6 +129,12 @@ scroll_up_adjust:
                ld a, [hl]
                inc a
                ld [hl], a
+       
+               ; check if off-screen
+               pop de
+               push de
+               cp a, 0x70 
+               call nc, rect_despawn
                
                pop hl
                dec b
index 4022f01833d961604bfd459ab4b51cccd0993686..e2f301c98bdc7a34af790f9ce372cbea018bad7b 100644 (file)
@@ -1,8 +1,8 @@
 ; tile 0
-.chr 32000000
-.chr 10000000
-.chr 00000000
-.chr 00000000
+.chr 32130000
+.chr 13330000
+.chr 23000000
+.chr 33000000
 .chr 00000000
 .chr 00000000
 .chr 00000000