mapgen: Added simple room drawing test
authorLukas Krickl <lukas@krickl.dev>
Wed, 11 Feb 2026 04:46:12 +0000 (05:46 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 11 Feb 2026 04:46:12 +0000 (05:46 +0100)
src/mapgen.s

index 614c056ba06694b2f256d20e22b0771bfb941736..71d9dbfded3f497e2d5b6be224add5c14e4f69c3 100644 (file)
@@ -51,6 +51,11 @@ map_generate:
        ld [hl+], a
        
        ; 3) make rooms
+
+       ; TODO: this is a test room
+       ld hl, mapgen_tiles+1+MAP_W
+       ld bc, 0x0505 ; 5x5
+       call mapgen_mak_room
        
 
        ; cleanup) finally
@@ -66,3 +71,41 @@ map_generate:
        ld [mapgen_game_seed+1], a
        ld [srand+1], a
        ret
+       
+       ; generates a single rectanglular room
+       ; the caller must ensutre hl has enough tiles in 
+       ;       the y and x direction to allow the room to fit.
+       ; places actors in the room
+       ; inputs:
+       ;               hl: start position in tile map
+       ;       b/c: height/width of room
+mapgen_mak_room:
+       ld de, MAP_W
+@draw_row:
+               ; save original hl
+               push hl
+               
+               ; save original w
+               push bc
+
+@draw_col:
+                       ld a, TI_FLOOR
+                       ld [hl+], a
+
+                       dec c ; width--
+                       jr nz, @draw_col REL
+               
+               ; restore w
+               ld a, b ; need to save height
+               pop bc
+               ld b, a
+
+               pop hl
+               ; go to next row
+               add hl, de
+               dec b ; height--
+               jr nz, @draw_row REL
+       
+       ; TODO: place actors
+       ret
+