|
|
@ -1,10 +1,10 @@ |
|
|
|
INCLUDE "dir.inc" |
|
|
|
INCLUDE "hardware.inc" |
|
|
|
INCLUDE "util.inc" |
|
|
|
|
|
|
|
SECTION "Map Data", WRAM0 |
|
|
|
|
|
|
|
PAGEX:: DB ; X coordinate to enqueue map column at |
|
|
|
PAGEY:: DB ; Y coordinate to enqueue map row at |
|
|
|
SCROLL_DIR:: DB |
|
|
|
|
|
|
|
PENDING_ROW_PTR:: DW ; Where to write pending row data (0 = no write) |
|
|
|
PENDING_ROW_DATA:: DS SCRN_VX_B ; Row to be written |
|
|
@ -40,10 +40,6 @@ Map_Load:: |
|
|
|
ld a, INIT_SCY |
|
|
|
ld [rSCY], a |
|
|
|
|
|
|
|
ld a, 8 |
|
|
|
ld [PAGEX], a |
|
|
|
ld [PAGEY], a |
|
|
|
|
|
|
|
; Store metadata |
|
|
|
ld bc, CURRENT_DATA_START |
|
|
|
ld d, CURRENT_DATA_END - CURRENT_DATA_START |
|
|
@ -89,9 +85,9 @@ Map_Load:: |
|
|
|
; Loads the map X-coordinate into B |
|
|
|
MACRO LOAD_MAPX |
|
|
|
; if SCX <= 0x7f |
|
|
|
ld a, [rSCX] |
|
|
|
cp $80 |
|
|
|
jr nc, .wrap\@ |
|
|
|
; ld a, [rSCX] |
|
|
|
; cp $80 |
|
|
|
; jr nc, .wrap\@ |
|
|
|
|
|
|
|
; B = CAMERA_X - SCX/8 |
|
|
|
ld a, [rSCX] |
|
|
@ -100,32 +96,32 @@ MACRO LOAD_MAPX |
|
|
|
srln b, 3 |
|
|
|
sub b |
|
|
|
ld b, a |
|
|
|
jr .done\@ |
|
|
|
; jr .done\@ |
|
|
|
|
|
|
|
; else SCX > 0x7f |
|
|
|
.wrap\@: |
|
|
|
; B = CAMERA_X - PAGE_X/8 |
|
|
|
ld a, [PAGEX] |
|
|
|
ld b, a |
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
srln b, 3 |
|
|
|
sub b |
|
|
|
ld b, a |
|
|
|
|
|
|
|
; HL += PAGE_X/8 |
|
|
|
ld a, [PAGEX] |
|
|
|
srln a, 3 |
|
|
|
ADD16 hl |
|
|
|
|
|
|
|
.done\@: |
|
|
|
; .wrap\@: |
|
|
|
; ; B = CAMERA_X - PAGE_X/8 |
|
|
|
; ld a, [PAGEX] |
|
|
|
; ld b, a |
|
|
|
; ld a, [CURRENT_CAMERA_X] |
|
|
|
; srln b, 3 |
|
|
|
; sub b |
|
|
|
; ld b, a |
|
|
|
|
|
|
|
; ; HL += PAGE_X/8 |
|
|
|
; ld a, [PAGEX] |
|
|
|
; srln a, 3 |
|
|
|
; ADD16 hl |
|
|
|
|
|
|
|
; .done\@: |
|
|
|
ENDM |
|
|
|
|
|
|
|
; Loads the map Y-coordinate into C |
|
|
|
MACRO LOAD_MAPY |
|
|
|
; if SCY <= 0x7f |
|
|
|
ld a, [rSCY] |
|
|
|
cp $80 |
|
|
|
jr nc, .wrap\@ |
|
|
|
; ld a, [rSCY] |
|
|
|
; cp $80 |
|
|
|
; jr nc, .wrap\@ |
|
|
|
|
|
|
|
; C = CAMERA_Y - SCY/8 |
|
|
|
ld a, [rSCY] |
|
|
@ -134,151 +130,121 @@ MACRO LOAD_MAPY |
|
|
|
srln c, 3 |
|
|
|
sub c |
|
|
|
ld c, a |
|
|
|
jr .done\@ |
|
|
|
|
|
|
|
; else SCY > 0x7f |
|
|
|
.wrap\@: |
|
|
|
; C = CAMERA_Y - PAGE_Y/8 |
|
|
|
ld a, [PAGEY] |
|
|
|
ld c, a |
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
srln c, 3 |
|
|
|
sub c |
|
|
|
ld c, a |
|
|
|
|
|
|
|
; HL += 32 * PAGE_Y/8 |
|
|
|
ld a, [PAGEY] |
|
|
|
srln a, 3 |
|
|
|
ld d, a |
|
|
|
ld e, 32 |
|
|
|
.adjust_hl\@: |
|
|
|
ld a, d |
|
|
|
ADD16 hl |
|
|
|
dec e |
|
|
|
jr nz, .adjust_hl\@ |
|
|
|
|
|
|
|
.done\@: |
|
|
|
; jr .done\@ |
|
|
|
|
|
|
|
; ; else SCY > 0x7f |
|
|
|
; .wrap\@: |
|
|
|
; ; C = CAMERA_Y - SCY/8 |
|
|
|
; ld a, [PAGEY] |
|
|
|
; ld c, a |
|
|
|
; ld a, [CURRENT_CAMERA_Y] |
|
|
|
; srln c, 3 |
|
|
|
; sub c |
|
|
|
; ld c, a |
|
|
|
|
|
|
|
; ; HL += 32 * PAGE_Y/8 |
|
|
|
; ld d, 0 |
|
|
|
; ld a, [PAGEY] |
|
|
|
; ld e, a |
|
|
|
; REPT 5 |
|
|
|
; SLA16 de |
|
|
|
; ENDR |
|
|
|
; add hl, de |
|
|
|
; .done\@: |
|
|
|
ENDM |
|
|
|
|
|
|
|
; Update map state based on SCX/SCY |
|
|
|
Map_Scroll:: |
|
|
|
; If SCY = PAGEY, write map row |
|
|
|
ld hl, PAGEY |
|
|
|
; Check scroll up/down |
|
|
|
ld a, [SCROLL_DIR] |
|
|
|
and DIRF_UP | DIRF_DOWN |
|
|
|
jr nz, .scroll_horiz |
|
|
|
|
|
|
|
; Check SCY % 8 = 0 |
|
|
|
ld a, [rSCY] |
|
|
|
cp [hl] |
|
|
|
jr nz, .scroll_down_check |
|
|
|
and %111 |
|
|
|
ret nz |
|
|
|
|
|
|
|
LOAD_MAPX |
|
|
|
|
|
|
|
ld a, [SCROLL_DIR] |
|
|
|
cp DIRB_UP |
|
|
|
jr nz, .scroll_down |
|
|
|
|
|
|
|
; C = CAMERA_Y - 2 |
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
sub 2 |
|
|
|
ld c, a |
|
|
|
|
|
|
|
; HL = _SCRN0 + 32 * (SCY/8 - 2) |
|
|
|
ld a, [rSCY] |
|
|
|
sub 16 |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
call get_row_ptr |
|
|
|
|
|
|
|
call enqueue_row_write |
|
|
|
|
|
|
|
ld a, [PAGEY] |
|
|
|
sub 8 |
|
|
|
ld [PAGEY], a |
|
|
|
|
|
|
|
ret |
|
|
|
|
|
|
|
.scroll_down_check: |
|
|
|
; Check SCY + (SCRN_Y + 16) = PAGEY |
|
|
|
ld a, [PAGEY] |
|
|
|
sub SCRN_Y + 16 |
|
|
|
ld hl, rSCY |
|
|
|
cp [hl] |
|
|
|
jr nz, .scroll_left_check |
|
|
|
|
|
|
|
ld a, [PAGEY] |
|
|
|
; HL = _SCRN0 + 32 * ((SCX/8 - 2) % 32) |
|
|
|
ld a, [rSCX] |
|
|
|
srln a, 3 |
|
|
|
dec a |
|
|
|
sub 2 |
|
|
|
and %11111 |
|
|
|
call get_row_ptr |
|
|
|
|
|
|
|
LOAD_MAPX |
|
|
|
jr .write_row |
|
|
|
|
|
|
|
.scroll_down: |
|
|
|
; C = CAMERA_Y + 18 + 1 |
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
add SCRN_Y_B + 1 |
|
|
|
ld c, a |
|
|
|
|
|
|
|
; HL = _SCRN0 + 32 * (SCY/8 + SCRN_Y_B + 1) |
|
|
|
ld a, [rSCY] |
|
|
|
srln a, 3 |
|
|
|
add SCRN_Y_B + 1 |
|
|
|
call get_row_ptr |
|
|
|
|
|
|
|
.write_row: |
|
|
|
call enqueue_row_write |
|
|
|
ret |
|
|
|
|
|
|
|
ld a, [PAGEY] |
|
|
|
add 8 |
|
|
|
ld [PAGEY], a |
|
|
|
.scroll_horiz: |
|
|
|
; Check SCX % 8 = 0 |
|
|
|
ld a, [rSCX] |
|
|
|
and %111 |
|
|
|
ret nz |
|
|
|
|
|
|
|
ret |
|
|
|
LOAD_MAPY |
|
|
|
|
|
|
|
.scroll_left_check: |
|
|
|
; If SCX = PAGEX, write map col |
|
|
|
ld a, [PAGEX] |
|
|
|
ld hl, rSCX |
|
|
|
cp [hl] |
|
|
|
jr nz, .scroll_right_check |
|
|
|
ld a, [SCROLL_DIR] |
|
|
|
cp DIRB_LEFT |
|
|
|
jr nz, .scroll_right |
|
|
|
|
|
|
|
; HL = VRAM + PAGEX/8 |
|
|
|
; HL = VRAM + (SCX/8 - 2) % 32 |
|
|
|
ld hl, _SCRN0 |
|
|
|
ld a, [PAGEX] |
|
|
|
ld a, [rSCX] |
|
|
|
srln a, 3 |
|
|
|
dec a |
|
|
|
sub 2 |
|
|
|
and %11111 |
|
|
|
ADD16 hl |
|
|
|
|
|
|
|
; B = CAMERA_X - 1 |
|
|
|
; B = CAMERA_X - 2 |
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
dec a |
|
|
|
sub 2 |
|
|
|
ld b, a |
|
|
|
|
|
|
|
; C = CAMERA_Y - SCY/8 |
|
|
|
LOAD_MAPY |
|
|
|
|
|
|
|
call enqueue_col_write |
|
|
|
|
|
|
|
ld a, [PAGEX] |
|
|
|
sub 8 |
|
|
|
ld [PAGEX], a |
|
|
|
|
|
|
|
.scroll_right_check: |
|
|
|
; If SCX = SCRN_X - PAGEX, write map col |
|
|
|
; Check SCX + (SCRN_X + 16) = PAGEX |
|
|
|
ld a, [PAGEX] |
|
|
|
sub SCRN_X + 16 |
|
|
|
ld hl, rSCX |
|
|
|
cp [hl] |
|
|
|
ret nz |
|
|
|
jr .write_col |
|
|
|
|
|
|
|
; HL = VRAM + PAGEX/8 |
|
|
|
.scroll_right: |
|
|
|
; HL = VRAM + SCX/8 + SCRN_X_B + 1 |
|
|
|
ld hl, _SCRN0 |
|
|
|
ld a, [PAGEX] |
|
|
|
ld a, [rSCX] |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
dec a |
|
|
|
add SCRN_X_B + 1 |
|
|
|
ADD16 hl |
|
|
|
|
|
|
|
; B = CAMERA_X + 20 |
|
|
|
; B = CAMERA_X + 20 + 1 |
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
add SCRN_X_B + 1 |
|
|
|
ld b, a |
|
|
|
|
|
|
|
; C = CAMERA_Y - SCY/8 |
|
|
|
LOAD_MAPY |
|
|
|
|
|
|
|
.write_col: |
|
|
|
call enqueue_col_write |
|
|
|
|
|
|
|
ld a, [PAGEX] |
|
|
|
add 8 |
|
|
|
ld [PAGEX], a |
|
|
|
|
|
|
|
ret |
|
|
|
|
|
|
|
Map_Update:: |
|
|
|