+#define SCRN0_END 0x9BF3
+
; loads a map
; including the required tileset
; sets current page to 0
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
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:
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