map: Added initial pattern page draw
authorLukas Krickl <lukas@krickl.dev>
Fri, 19 Sep 2025 14:52:03 +0000 (16:52 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 19 Sep 2025 14:52:03 +0000 (16:52 +0200)
src/map.s
src/rowpatterns.s
src/ui.s
src/update.s
src/wram.s

index 6c25cf5745d6d816c6b67f52e4937f1e0b3a019d..eb40337964da6c70306abc9134fd7cbbb6a3a942 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -1,3 +1,5 @@
+#define SCRN0_END 0x9BF3
+
        ; loads a map 
        ; including the required tileset
        ; sets current page to 0
@@ -14,14 +16,38 @@ map_load:
        ld [map], a
        ld a, d
        ld [map+1], a
-
+       
+       push de
        call map_tile_banks_load
+       pop de
+
+       ; load initial pattern
+       ld hl, map_init_pat
+       add hl, de
+       ld a, [hl+] 
+       ld [map_curr_pat], a
+       ld a, [hl] 
+       ld [map_curr_pat+1], a
+
+       ; reset bg ptr
+       ld a, SCRN0_END LO
+       ld [map_scrn_ptr], a
+       ld a, SCRN0_END HI
+       ld [map_scrn_ptr+1], a
 
-       call map_page_full_draw
 
        call lcd_on
        call vblank_wait
        call enableinterrupts
+
+
+       call map_page_full_draw
+       call ui_init
+
+       ; initial scroll value 
+       ; to make bottom of scrn0 visible
+       ld a, 144
+       ld [scroll_y], a
        ret
        
        ; loads all tile banks 
@@ -65,16 +91,128 @@ map_tile_banks_load:
 
        ret
        
-       ; draws the current row pattern
+       ; draw command for a single sub tile draw
+       ; top row
+#macro map_advance_row_draw_top
+       ld a, [hl+]
+       inc a
+       ld [de], a
+       dec de
+       dec a
+       ld [de], a
+       dec de
+#endmacro
+
+#macro map_advance_row_draw_bot
+       ld a, [hl+]
+       add a, 0x11
+       ld [de], a
+       dec de
+       dec a
+       ld [de], a
+       dec de
+#endmacro
+
+       ; draws the current row pattern of 16x16 tiles
        ; only call during blank
        ; also triggers objects 
-map_draw_row:
+map_advance_row:
+       ld a, [map_scrn_ptr]
+       ld e, a
+       ld a, [map_scrn_ptr+1]
+       ld d, a
+
+       ld a, [map_curr_pat]
+       ld l, a
+       ld a, [map_curr_pat+1]
+       ld h, a
+
+       push hl 
+       
+       ; first row of tiles
+
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+       map_advance_row_draw_bot
+
+       ; move to next row
+       ld hl, -12 & 0xFFFF
+       add hl, de 
+       push hl
+       pop de ; de = next row
+
+       pop hl 
+       ; second row of tiles
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+       map_advance_row_draw_top
+
+       ; write new scrn ptr
+       ld hl, -12 & 0xFFFF
+       add hl, de
+       ; hl = new scrn ptr
+       ld a, l
+       ld [map_scrn_ptr], a
+       ld a, h
+       ld [map_scrn_ptr+1], a
+       
+       ; move to next row
+       ld a, [map_curr_row]
+       inc a
+       ld [map_curr_row], a
+       call map_check_obj
+
+       ret
+       
+       ; checks the newly drawn row for objects
+       ; that can execute code
+map_check_obj:
+       ; TODO
        ret
        
        ; draws a full page of the currently selected map
+       ; waits for blank between each row
        ; inputs:
        ;               [map]
 map_page_full_draw:
+       call next_vblank_wait
+       call map_advance_row
+
+       call next_vblank_wait
+       call map_advance_row
+
+       call next_vblank_wait
+       call map_advance_row
+
+       call next_vblank_wait
+       call map_advance_row
+
+       call next_vblank_wait
+       call map_advance_row
+
+       call next_vblank_wait
+       call map_advance_row
+
+       call next_vblank_wait
+       call map_advance_row
+       
+       ; last row will be out of visible scroll
+       call next_vblank_wait
+       call map_advance_row
        ret
 
 l1_map:
index 1192abbbd81be24a922bda77a6623d6ff034654d..3ca43c606e86af827f64f760a73d7ffc00c56539 100644 (file)
@@ -1,6 +1,6 @@
 
        ; tile space
-.def int TS = 0x30
+.def int TS = 0x40
 
 pat_empty:
 .db TS, TS, TS, TS, TS, TS, TS, TS, TS, TS 
index b053cbe83153014a985e1f37975027c679b0b027..4f2df7d5ec920c7a90e1fc5b75233d10b62544dd 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -12,5 +12,4 @@ ui_str_clear:
 
   ; inits UI
 ui_init:
-
   ret
index 2cbedc96b4eafb3518cd322fb56c07f7531b82a6..139fab5a6f0eb10654355085cb836493e3a3026f 100644 (file)
@@ -16,6 +16,8 @@ new_game:
 
        ld hl, update_game
        call game_set_state
+
+       call game_init
        ret
 
   ; called after vblank
@@ -35,3 +37,30 @@ update:
        jp hl
   
   ret
+
+
+  ; geric game init call
+  ; sets up window
+  ; inits UI
+game_init:
+  ; set up UI
+  ld a, WINDOW_Y
+  ld [RWY], a
+  ld a, WINDOW_X
+  ld [RWX], a
+
+  ; set up palettes for
+  ; gameplay
+  ld a, BGP 
+  ld [RBGP], a
+  ld [shadow_bpg], a 
+
+  ld a, 0b11100100 
+  ld [ROBP0], a
+  ld [shadow_robp0], a
+
+  ld a, 0b11011000
+  ld [ROBP1], a
+  ld [shadow_robp1], a
+
+  ret
index 7ad3c4543ed9d4425570a015a40a73594c5bb012..27e86b388b9cf30752f13e4597fc4775b11294af 100644 (file)
@@ -62,12 +62,15 @@ actors: .adv act_size * ACTS_MAX
 map_objs: .adv mo_size * MAP_OBJ_MAX
 
        ; current row that is being drawn
-map_current_row: .adv 1
+map_curr_row: .adv 1
        ; current pattern to be drawn
-map_current_pattern: .adv 2
+map_curr_pat: .adv 2
        
        ; current map ptr
 map: .adv 2
        ; ptr to the next map object
        ; that may be loaded
 map_obj_ptr: .adv 2
+       
+       ; current bg pointer to write to
+map_scrn_ptr: .adv 2