From fc186fc15318f99b83e856e01dd0fc7176bdb2f9 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 30 Oct 2025 12:19:28 +0100 Subject: [PATCH] map: wip full map draw --- src/levels.s | 4 +- src/map.s | 124 +++++++++++++++++++++++++++++++++++++++++++++------ src/tiles.s | 4 +- 3 files changed, 114 insertions(+), 18 deletions(-) diff --git a/src/levels.s b/src/levels.s index 63cd581..d7bc667 100644 --- a/src/levels.s +++ b/src/levels.s @@ -28,8 +28,8 @@ level_def_to_tile: l1: mapdef 0, map_r_nop, bank8000, bank8800, bank8C00, bank9000 .db TPH, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS - .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS - .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TPH, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TPH, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS diff --git a/src/map.s b/src/map.s index 831d41f..7bb3dea 100644 --- a/src/map.s +++ b/src/map.s @@ -162,19 +162,21 @@ map_tile_banks_load: ; draws a tile ; to the screen ; inputs: - ; hl: tile ; b/c: y/x position map_draw_tile: ; find tile to draw - ld de, t_tile - add hl, de + push bc + call map_get_tile + ld bc, t_tile + add hl, bc ; hl = tile gfx + pop bc ; load tile into a ld a, [hl] ; a = tile push af ; save tile gfx ld hl, SCRN0 - ld de, MAP_W + ld de, MAP_W * 4 ; * 4 because tiles are 8x8 ; skip y loop if b is 0 ld a, b @@ -188,33 +190,127 @@ map_draw_tile: @skip_y: ld d, 0 - ld e, c + ld a, c + add a, a ; * 2 because tiles are 8x8 + ld e, a add hl, de ; hl = SCRN location pop af + + ; draw 2x2 tile + ld [hl+], a + inc a + ld [hl], a + + ; next row + ld de, (MAP_W * 2) - 1 + add hl, de + + ; move down one tile row as well + add a, 15 + + ld [hl+], a + inc a ld [hl], a ret + ; gets a tile based on a position + ; inputs: + ; b/c: y/x + ; returns: + ; hl: tile +map_get_tile: + ld hl, tiles + + ld de, MAP_W * t_size + ld a, b + cp a, 0 + jr z, @skip_y_loop REL + +@y_loop: + add hl, de ; next row + dec b + jr z, @y_loop REL +@skip_y_loop: + + ld de, t_size + ld a, c + cp a, 0 + jr z, @skip_x_loop REL + +@x_loop: + add hl, de ; next tile over + dec c + jr z, @x_loop REL +@skip_x_loop: + + ; hl = tile now + ret + +#macro map_draw_row_inc_c + push bc + call map_draw_tile + pop bc + inc c +#endmacro + ; draws 16 tiles ; inputs: - ; hl: start tile ; b: y position map_draw_row: + ld c, 0 + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c + + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c + + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c + + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c + map_draw_row_inc_c ret - + +#macro map_full_draw_inc_b + call map_draw_row + inc b +#endmacro + ; draws a full page of the currently selected map ; inputs: ; [map] map_full_draw: - ld bc, MAP_TILES - ld hl, tiles - - push hl - ld bc, 0 - call map_draw_tile - pop hl + ld b, 0 + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + map_full_draw_inc_b + ret ; nop map rotuine diff --git a/src/tiles.s b/src/tiles.s index 5a9afad..7f178fa 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -1,8 +1,8 @@ ; tile definitions #define GFX_GRASS 0x00 -#define GFX_PHIVE 0x01 -#define GFX_EHIVE 0x02 +#define GFX_PHIVE 0x4A +#define GFX_EHIVE 0x4A #define GFX_FOOD 0x03 ; updates a tile with its -- 2.30.2