|
@ -91,6 +91,40 @@ Map_Load:: |
|
|
|
|
|
|
|
|
ret |
|
|
ret |
|
|
|
|
|
|
|
|
|
|
|
; Loads the map X-coordinate into B |
|
|
|
|
|
MACRO LOAD_MAPX |
|
|
|
|
|
; if SCX <= 0x7f |
|
|
|
|
|
ld a, [rSCX] |
|
|
|
|
|
cp $80 |
|
|
|
|
|
jr nc, .wrap\@ |
|
|
|
|
|
|
|
|
|
|
|
; B = CAMERA_X - SCX/8 |
|
|
|
|
|
ld a, [rSCX] |
|
|
|
|
|
ld b, a |
|
|
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
|
|
srln b, 3 |
|
|
|
|
|
sub b |
|
|
|
|
|
ld b, a |
|
|
|
|
|
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\@: |
|
|
|
|
|
ENDM |
|
|
|
|
|
|
|
|
; Update map state based on SCX/SCY |
|
|
; Update map state based on SCX/SCY |
|
|
Map_Scroll:: |
|
|
Map_Scroll:: |
|
|
; If SCY = PAGEY, write map row |
|
|
; If SCY = PAGEY, write map row |
|
@ -154,15 +188,7 @@ Map_Scroll:: |
|
|
ld e, a |
|
|
ld e, a |
|
|
call compute_vram_ptr |
|
|
call compute_vram_ptr |
|
|
|
|
|
|
|
|
; B = CAMERA_X - SCX/8 |
|
|
|
|
|
ld a, [rSCX] |
|
|
|
|
|
ld b, a |
|
|
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
|
|
srl b |
|
|
|
|
|
srl b |
|
|
|
|
|
srl b |
|
|
|
|
|
sub b |
|
|
|
|
|
ld b, a |
|
|
|
|
|
|
|
|
LOAD_MAPX |
|
|
|
|
|
|
|
|
; C = CAMERA_Y + 18 + 1 |
|
|
; C = CAMERA_Y + 18 + 1 |
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
ld a, [CURRENT_CAMERA_Y] |
|
@ -271,7 +297,27 @@ Map_Update:: |
|
|
|
|
|
|
|
|
ld hl, PENDING_ROW_DATA |
|
|
ld hl, PENDING_ROW_DATA |
|
|
ld d, SCRN_VX_B |
|
|
ld d, SCRN_VX_B |
|
|
MEMCPY bc, hl, d |
|
|
|
|
|
|
|
|
.copy_row: |
|
|
|
|
|
ld a, [hl+] |
|
|
|
|
|
ld [bc], a |
|
|
|
|
|
inc bc |
|
|
|
|
|
|
|
|
|
|
|
; if BC % 32 == 0 (we just crossed a row boundary) |
|
|
|
|
|
ld a, c |
|
|
|
|
|
and %11111 |
|
|
|
|
|
jr nz, .copy_row1 |
|
|
|
|
|
|
|
|
|
|
|
; BC -= 32 (reset back to beginning of row) |
|
|
|
|
|
ld a, c |
|
|
|
|
|
sub 32 |
|
|
|
|
|
ld c, a |
|
|
|
|
|
ld a, b |
|
|
|
|
|
sbc 0 |
|
|
|
|
|
ld b, a |
|
|
|
|
|
|
|
|
|
|
|
.copy_row1: |
|
|
|
|
|
dec d |
|
|
|
|
|
jr nz, .copy_row |
|
|
|
|
|
|
|
|
.update_col: |
|
|
.update_col: |
|
|
; Skip column update if PENDING_COL_PTR is 0 |
|
|
; Skip column update if PENDING_COL_PTR is 0 |
|
@ -361,6 +407,14 @@ enqueue_row_write: |
|
|
ld c, SCRN_VX_B |
|
|
ld c, SCRN_VX_B |
|
|
ld de, PENDING_ROW_DATA |
|
|
ld de, PENDING_ROW_DATA |
|
|
|
|
|
|
|
|
|
|
|
; If X > 0, increment map pointer by X |
|
|
|
|
|
bit 7, b |
|
|
|
|
|
jr nz, .pad_left |
|
|
|
|
|
|
|
|
|
|
|
ld a, b |
|
|
|
|
|
ADD16 hl |
|
|
|
|
|
jr .copy_middle |
|
|
|
|
|
|
|
|
; Note: Can skip checking BYTES_LEFT > 0 in this loop. If there were |
|
|
; Note: Can skip checking BYTES_LEFT > 0 in this loop. If there were |
|
|
; SCRN_VX_B zeros to write, then Y would be 1 greater and we would have |
|
|
; SCRN_VX_B zeros to write, then Y would be 1 greater and we would have |
|
|
; jumped into .zero_row before reaching this code |
|
|
; jumped into .zero_row before reaching this code |
|
@ -446,6 +500,7 @@ write_map_row: |
|
|
ld a, [PENDING_ROW_PTR + 1] |
|
|
ld a, [PENDING_ROW_PTR + 1] |
|
|
ld b, a |
|
|
ld b, a |
|
|
|
|
|
|
|
|
|
|
|
; TODO: Fix |
|
|
ld hl, PENDING_ROW_DATA |
|
|
ld hl, PENDING_ROW_DATA |
|
|
ld d, SCRN_VX_B |
|
|
ld d, SCRN_VX_B |
|
|
MEMCPY bc, hl, d |
|
|
MEMCPY bc, hl, d |
|
|