From: Lukas Krickl Date: Fri, 19 Sep 2025 09:23:24 +0000 (+0200) Subject: map: Re-added tile bank loader X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=50baec810f9abd47aa34e98e297f205f4dc83948;p=gbrg%2F.git map: Re-added tile bank loader --- diff --git a/src/defs.s b/src/defs.s index df046ab..4845099 100644 --- a/src/defs.s +++ b/src/defs.s @@ -58,10 +58,7 @@ ; 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 diff --git a/src/macros.inc b/src/macros.inc index 45f7654..284c601 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -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 diff --git a/src/map.s b/src/map.s index 480856f..435355d 100644 --- 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 diff --git a/src/mem.s b/src/mem.s index 4d803d0..f2a9485 100644 --- 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 diff --git a/src/rowpatterns.s b/src/rowpatterns.s index e69de29..1192abb 100644 --- a/src/rowpatterns.s +++ b/src/rowpatterns.s @@ -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 diff --git a/src/update.s b/src/update.s index a160c8d..2cbedc9 100644 --- a/src/update.s +++ b/src/update.s @@ -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]