map: Added tile draw routine
authorLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 10:22:55 +0000 (11:22 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 30 Oct 2025 10:22:55 +0000 (11:22 +0100)
src/map.s

index 4e41567ec1c13c1b554abbc95b7cecd0cd1cdd51..831d41fb09c0f58d74b02652b8d1d7cdcd2eb196 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -23,12 +23,13 @@ map_load:
        push de
        call map_tiles_load
        pop de
+       
+       call map_full_draw
 
        call lcd_on
        call vblank_wait
        call enableinterrupts
 
-       call map_full_draw
        call player_init
        call ui_init
 
@@ -158,11 +159,62 @@ map_tile_banks_load:
 #endmacro
        
        
+       ; 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
+       
+       ; load tile into a
+       ld a, [hl] ; a = tile
+       push af ; save tile gfx
+
+       ld hl, SCRN0
+       ld de, MAP_W 
+       
+       ; skip y loop if b is 0
+       ld a, b
+       cp a, 0
+       jr z, @skip_y REL
+
+@y_loop:
+               add hl, de 
+               dec b
+               jr nz, @y_loop REL
+@skip_y:
+
+       ld d, 0
+       ld e, c
+       add hl, de ; hl = SCRN location
+               
+       pop af 
+       ld [hl], a
+
+       ret
+       
+       ; draws 16 tiles
+       ; inputs:
+       ;               hl: start tile
+       ;               b: y position
+map_draw_row:
+       ret
+       
        ; draws a full page of the currently selected map
-       ; waits for blank between each row
        ; inputs:
        ;               [map]
 map_full_draw:
+       ld bc, MAP_TILES
+       ld hl, tiles
+
+       push hl
+       ld bc, 0
+       call map_draw_tile
+       pop hl
+       
        ret
        
        ; nop map rotuine