map: wip full map draw
authorLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 11:19:28 +0000 (12:19 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 11:19:28 +0000 (12:19 +0100)
src/levels.s
src/map.s
src/tiles.s

index 63cd581c76b42f363a4b132e49a11dd9dbcb164e..d7bc667247a1e97f46092e06c2486e28e62a8697 100644 (file)
@@ -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
index 831d41fb09c0f58d74b02652b8d1d7cdcd2eb196..7bb3dea91a969dcfca7416470b70bffc4561c18f 100644 (file)
--- 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
index 5a9afad719f76cdeffde4b1ec5017c745607f5f3..7f178fa31cc7785642d6cb20efc6460d3f697024 100644 (file)
@@ -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