map: Re-added tile bank loader
authorLukas Krickl <lukas@krickl.dev>
Fri, 19 Sep 2025 09:23:24 +0000 (11:23 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 19 Sep 2025 09:23:24 +0000 (11:23 +0200)
src/defs.s
src/macros.inc
src/map.s
src/mem.s
src/rowpatterns.s
src/update.s

index df046ab87d7480626b028d3368fc94036a32f7f7..484509944c80ff447829eb395b5b6cbe04be1cfd 100644 (file)
   ; map header struct
 .se 0
 .de map_flags, 1
-  ; 8 bytes reserved for map names
-  ; map_name in map properties
-.de map_bg_ptr, 2
-
+.de map_init_pat, 2
        ; ptr to map objects list
 .de map_objs_ptr, 2
   ; pointers to tile banks to be loaded 
index 45f76546717114299b6d5aa391b4b71633ed56a1..284c601ac55c26549a06be8e67dafbdb58f8621f 100644 (file)
@@ -149,4 +149,22 @@ $1:
 .str $2
 .db 0
 #endmacro
-
+       
+       ; defines a map header
+       ; inputs:
+       ;               $1: flags
+       ;               $2: initial pattern
+       ;               $3: objs ptr
+       ;               $4: tile bank 0
+       ;               $5: tile bank 1
+       ;               $6: tile bank 2
+       ;               $7: tile bank 3
+#macro mapdef
+       .db $1
+       dw $2
+       dw $3
+       dw $4
+       dw $5
+       dw $6
+       dw $7
+#endmacro
index 480856fe9098e1ef7853b84f01afe0ad67c98529..435355d4aca28df3c68fc6400b93e9bf45168f30 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -1,9 +1,68 @@
-       ; tile space
-.def int TS = 0x30
+       ; loads a map 
+       ; including the required tileset
+       ; sets current page to 0
+       ; draws page 0 to the screen
+       ; loads map objects
+       ; inputs:
+       ;               de: map ptr
+map_load:
+       call disableinterrupts
+       call next_vblank_wait
+       call lcd_off
 
-pat_empty:
-.db TS, TS, TS, TS, TS, TS, TS, TS, TS, TS 
+       call map_tile_banks_load
+
+       call lcd_on
+       call vblank_wait
+       call enableinterrupts
+       ret
+       
+       ; loads all tile banks 
+       ; for a specific map
+       ; inputs:
+       ;               de: map ptr
+map_tile_banks_load:
+  ld hl, map_tile_bank0_ptr
+  add hl, de ; hl = bank0 ptr
+
+       ; load ptr 
+       ld a, [hl+]
+       ld e, a
+       ld a, [hl+]
+       ld d, a
+       push hl
+       call tiles_load_bank8000
        
-       ; enf of level row pattern
-pat_eol:
-.db 0xFF       
+       pop hl
+       ld a, [hl+]
+       ld e, a
+       ld a, [hl+]
+       ld d, a
+       push hl
+       call tiles_load_bank8800
+       
+       pop hl
+       ld a, [hl+]
+       ld e, a
+       ld a, [hl+]
+       ld d, a
+       push hl
+       call tiles_load_bank8C00
+
+       pop hl
+       ld a, [hl+]
+       ld e, a
+       ld a, [hl+]
+       ld d, a
+       call tiles_load_bank9000
+
+       ret
+       
+       ; draws the current row pattern
+       ; only call during blank
+map_draw_row:
+       ret
+
+
+l1_map:
+       mapdef 0, pat_empty, NULL, bank8000, bank8800, bank8C00, bank9000       
index 4d803d0b1d9f110efd2cdc5e42363c1b6c4b64b2..f2a9485f0641cb5349c5a749d46bdeafed93483d 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -26,7 +26,7 @@ mem_init:
   ; call load_demo_ptr
 
        ; set initial game state ptr
-       ld hl, update_game
+       ld hl, new_game 
        call game_set_state
 
   ret
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..1192abbbd81be24a922bda77a6623d6ff034654d 100644 (file)
@@ -0,0 +1,10 @@
+
+       ; tile space
+.def int TS = 0x30
+
+pat_empty:
+.db TS, TS, TS, TS, TS, TS, TS, TS, TS, TS 
+       
+       ; enf of level row pattern
+pat_eol:
+.db 0xFF       
index a160c8d29a4163b5bb653fd76663350edfb8528f..2cbedc96b4eafb3518cd322fb56c07f7531b82a6 100644 (file)
@@ -10,6 +10,14 @@ update_game:
        
   ret
 
+new_game:
+       ld de, l1_map
+       call map_load
+
+       ld hl, update_game
+       call game_set_state
+       ret
+
   ; called after vblank
 update:
   ld a, [frame_count]