mapgen: Added map section drawing macro
authorLukas Krickl <lukas@krickl.dev>
Sat, 14 Feb 2026 16:52:16 +0000 (17:52 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 14 Feb 2026 16:52:16 +0000 (17:52 +0100)
src/defs.s
src/mapgen.s

index afa9e441e68618318ea94eeca7b0da007f8dcbf4..e15293558f36ed7ddf6e6d0eb5fd6f047f43f1ae 100644 (file)
@@ -39,6 +39,7 @@
 #define MAP_H 32
 #define MAP_TILES (MAP_W * MAP_H)
 #define MAP_SECTION_SIZE 8
+#define MAP_SECTION_PER_ROW (MAP_W / MAP_SECTION_SIZE)
 
 #define RENDER_BUF_W 20
 #define RENDER_BUF_H 14
index 4e0d3dc4ee590c1a9ccfdcd0f45e192a414f56f1..343289a947e32f2b56edddc1b8f0c5859f5503c6 100644 (file)
@@ -69,16 +69,36 @@ map_generate:
        ld [srand+1], a
        ret
 
+       ; makes a room at a sector offset
+       ; the room is placed randomly within the sector
+       ; and then drawn.
+       ; inputs:
+       ;               $1: sector y
+       ;               $2: sector x
+#macro _mapgen_make_room_section
+.beginscope
+       ld hl, mapgen_tiles + MAP_SECTION_SIZE * MAP_SECTION_PER_ROW * MAP_SECTION_SIZE \
+               * $1 + MAP_SECTION_SIZE * $2
+       ld bc, 0x0808 ; 8x8 fill the entire sector for now
+       call mapgen_make_room
+.endscope
+#endmacro
+
        ; generates all rooms
        ; for each section of the map
        ; the map is split into MAP_SECTION_SIZExMAP_SECTION_SIZE
        ; sections (e.g. 4x4 sections of 8x8 tiles)
        ; rooms are placed in each section and then linked up using hallways
 mapgen_make_rooms:
-       ; TODO: this is a test room
-       ld hl, mapgen_tiles+1+MAP_W
-       ld bc, 0x0505 ; 5x5
-       call mapgen_make_room
+       _mapgen_make_room_section 0, 0
+       _mapgen_make_room_section 0, 1
+       _mapgen_make_room_section 0, 2
+       _mapgen_make_room_section 0, 3
+
+       _mapgen_make_room_section 1, 0
+       _mapgen_make_room_section 1, 1
+       _mapgen_make_room_section 1, 2
+       _mapgen_make_room_section 1, 3
        ret
        
        ; generates a single rectanglular room