From 37d7c20ef4bd2befc0a4a9bbbf4d8edb2edcdc9d Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 17 Dec 2025 06:05:54 +0100 Subject: [PATCH] ui: minimap is now a regular UI element rendered with tiles --- src/debug.s | 66 ------------------------------- src/map.s | 2 + src/ui.s | 96 ++++++++++++++++++++++++++++++++++++++++++---- src/update.s | 3 ++ src/wram.s | 1 + tiles/bank8C00.inc | 32 ++++++++-------- 6 files changed, 111 insertions(+), 89 deletions(-) diff --git a/src/debug.s b/src/debug.s index d0cf0f6..d0e6309 100644 --- a/src/debug.s +++ b/src/debug.s @@ -46,70 +46,4 @@ debug_draw_player_pos: ld [hl+], a - ret - - ; debug draws a tile based on player position - ; inputs: - ; $1: y offset - ; $2: x offset - ; hl: oam ptr - ; returns: - ; hl: next oam ptr -#macro debug_draw_tile - ld de, player+act_pos_y - ld a, [de] - inc de - add a, $1 & 0xFF - - ld b, a ; b = y - ld a, [de] - add a, $2 & 0xFF - ld c, a ; c = x - - push hl - call map_get_tile - push hl - pop de ; de = tile - inc de ; de = tile flags - - pop hl ; hl = oam - - ; y pos - ld a, 136 + $1 * 8 - ld [hl+], a - - ; x pos - ld a, 136 + $2 * 8 - ld [hl+], a - - ; tile - ld a, [de] - add a, 0x60 ; tile offset for debug tiles - ld [hl+], a - - ; flags - xor a, a - ld [hl+], a - -#endmacro - - ; draws the tiles around the player - ; only draws the exit flags -debug_draw_map: - ld a, 9 - call oamalloc - - debug_draw_tile -1, 0 - debug_draw_tile 0, 0 - debug_draw_tile 1, 0 - - debug_draw_tile 0, -1 - debug_draw_tile 0, 1 - - debug_draw_tile 1, 1 - debug_draw_tile -1, 1 - - debug_draw_tile -1, -1 - debug_draw_tile 1, -1 - ret diff --git a/src/map.s b/src/map.s index 3aed0a3..26b87b9 100644 --- a/src/map.s +++ b/src/map.s @@ -500,6 +500,8 @@ map_full_draw: call _map_full_draw_near_doors @done: + call minimap_full_draw + ; 4) go to render state call update_render ret diff --git a/src/ui.s b/src/ui.s index e1525d7..964df47 100644 --- a/src/ui.s +++ b/src/ui.s @@ -1,9 +1,9 @@ #define UI_TILE_NAME SCRN1+33 -#define TILE_SOUTH 0xEC -#define TILE_NORTH 0xE7 -#define TILE_EAST 0xDE -#define TILE_WEST 0xF0 +#define TILE_SOUTH 0xF9 +#define TILE_NORTH 0xFA +#define TILE_EAST 0xFC +#define TILE_WEST 0xFB ; one tile after 'Z' #define UI_WINDOW_BACKGROUND 0xF4 @@ -30,10 +30,93 @@ ui_update: - ; draws the entire UI ; only call during blank ui_draw: + + ; draw minimap to ui + ld hl, SCRN1 + 16 + ld de, 29 ; offset for next row + + ; row 0 + ld a, [minimap_buffer] + ld [hl+], a + + ld a, [minimap_buffer+1] + ld [hl+], a + + ld a, [minimap_buffer+2] + ld [hl+], a + + ; row 1 + add hl, de + ld a, [minimap_buffer+3] + ld [hl+], a + + ld a, [minimap_buffer+4] + ld [hl+], a + + ld a, [minimap_buffer+5] + ld [hl+], a + + ; row 2 + add hl, de + ld a, [minimap_buffer+6] + ld [hl+], a + + ld a, [minimap_buffer+7] + ld [hl+], a + + ld a, [minimap_buffer+8] + ld [hl+], a + + ret + + ; draws a single minimap tile based on the player's position + ; inputs: + ; $1: y offset + ; $2: x offset + ; returns: + ; writes into minimap_buffer at the offset +#macro minimap_draw_tile +.beginscope + ld a, [player+act_pos_y] + add a, $1 & 0xFF + ld b, a + + ld a, [player+act_pos_x] + add a, $2 & 0xFF + ld c, a + + call map_get_tile + ; hl = tile + + inc hl ; hl = tile flags + ld a, [hl] ; load tile information + add a, 0x60 ; tile offset for map tiles + + ; 0/0 is the center of the minimap + ; so +4 and then offset by $1 and $2 + ld [minimap_buffer+4+($1*3)+$2], a +.endscope +#endmacro + + ; redraws the minimap + ; into a 3x3 minimap buffer +minimap_full_draw: + minimap_draw_tile 0, 0 + minimap_draw_tile 0, 1 + + minimap_draw_tile 1, 0 + minimap_draw_tile 1, 1 + + minimap_draw_tile -1, 1 + minimap_draw_tile 1, -1 + minimap_draw_tile -1, -1 + + minimap_draw_tile 0, -1 + minimap_draw_tile -1, 0 + ret compass_tiles: @@ -51,7 +134,7 @@ compass_draw: ld [hl+], a ; x - ld a, 64 + ld a, 138 ld [hl+], a ; tile @@ -73,6 +156,5 @@ compass_draw: #ifdef DEBUG_UI call debug_draw_player_pos - call debug_draw_map #endif ret diff --git a/src/update.s b/src/update.s index 6c04bfe..b5a1953 100644 --- a/src/update.s +++ b/src/update.s @@ -71,6 +71,9 @@ update_render: dec b jp nz, @render_loop + + call next_vblank_wait + call ui_draw call enableinterrupts ret diff --git a/src/wram.s b/src/wram.s index 6f39dfa..8fcf163 100644 --- a/src/wram.s +++ b/src/wram.s @@ -123,6 +123,7 @@ update_tile_vram: .adv 2 update_tile_ptr: .adv 2 render_buffer: .adv RENDER_BUF_TILES +minimap_buffer: .adv 9 tmp_map_forward: .adv 1 tmp_map_near_left_door: .adv 1 diff --git a/tiles/bank8C00.inc b/tiles/bank8C00.inc index 20e88ac..78cd9c3 100644 --- a/tiles/bank8C00.inc +++ b/tiles/bank8C00.inc @@ -513,38 +513,38 @@ .chr 22223222 ; tile 57 .chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 00020000 +.chr 00020000 +.chr 00020000 +.chr 00222000 +.chr 00020000 .chr 00000000 .chr 00000000 ; tile 58 .chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 00020000 +.chr 00222000 +.chr 00020000 +.chr 00020000 +.chr 00020000 .chr 00000000 .chr 00000000 ; tile 59 .chr 00000000 .chr 00000000 .chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 00200000 +.chr 02222200 +.chr 00200000 .chr 00000000 .chr 00000000 ; tile 60 .chr 00000000 .chr 00000000 .chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 00000200 +.chr 02222220 +.chr 00000200 .chr 00000000 .chr 00000000 ; tile 61 -- 2.30.2