From: Lukas Krickl Date: Fri, 19 Sep 2025 14:52:03 +0000 (+0200) Subject: map: Added initial pattern page draw X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=e7dc2eb88e9cb39a370f0dea4fd5def3e331aa01;p=gbrg%2F.git map: Added initial pattern page draw --- diff --git a/src/map.s b/src/map.s index 6c25cf5..eb40337 100644 --- 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: diff --git a/src/rowpatterns.s b/src/rowpatterns.s index 1192abb..3ca43c6 100644 --- a/src/rowpatterns.s +++ b/src/rowpatterns.s @@ -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 diff --git a/src/ui.s b/src/ui.s index b053cbe..4f2df7d 100644 --- a/src/ui.s +++ b/src/ui.s @@ -12,5 +12,4 @@ ui_str_clear: ; inits UI ui_init: - ret diff --git a/src/update.s b/src/update.s index 2cbedc9..139fab5 100644 --- a/src/update.s +++ b/src/update.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 7ad3c45..27e86b3 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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