From: Lukas Krickl Date: Sun, 21 Sep 2025 15:46:04 +0000 (+0200) Subject: debug: wip rectangle debug renderer X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=89b050e6589ab8f5873e910046071dc410f8c903;p=gbrg%2F.git debug: wip rectangle debug renderer --- diff --git a/src/debug.s b/src/debug.s index 558c5b9..929c22b 100644 --- a/src/debug.s +++ b/src/debug.s @@ -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 diff --git a/src/rectangle.s b/src/rectangle.s index 74a0ee1..3e18848 100644 --- a/src/rectangle.s +++ b/src/rectangle.s @@ -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 diff --git a/src/update.s b/src/update.s index 788b685..016a04b 100644 --- a/src/update.s +++ b/src/update.s @@ -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 diff --git a/src/video.s b/src/video.s index 5611a83..4f73deb 100644 --- a/src/video.s +++ b/src/video.s @@ -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 diff --git a/tiles/bank8800.inc b/tiles/bank8800.inc index 4022f01..e2f301c 100644 --- a/tiles/bank8800.inc +++ b/tiles/bank8800.inc @@ -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