|
|
@ -112,12 +112,131 @@ Map_Load:: |
|
|
|
; Update map state based on SCX/SCY |
|
|
|
Map_Scroll:: |
|
|
|
; Adjust CURRENT_CAMERA_X |
|
|
|
; Adjust CURRENT_CAMERA_Y |
|
|
|
|
|
|
|
; ; Adjust CURRENT_CAMERA_Y if [LAST_SCY]/8 != [rSCY]/8 |
|
|
|
; ld a, [rSCY] |
|
|
|
; srl a |
|
|
|
; srl a |
|
|
|
; srl a |
|
|
|
|
|
|
|
; ld hl, LAST_SCY |
|
|
|
; ld b, [hl] |
|
|
|
; srl b |
|
|
|
; srl b |
|
|
|
; srl b |
|
|
|
|
|
|
|
; cp b |
|
|
|
; jr c, .cmp |
|
|
|
; jr z, .scroll_up_check |
|
|
|
|
|
|
|
; sub $20 |
|
|
|
|
|
|
|
; .cmp: |
|
|
|
; sub b |
|
|
|
|
|
|
|
; ld hl, CURRENT_CAMERA_Y |
|
|
|
; add [hl] |
|
|
|
; ld [hl], a |
|
|
|
|
|
|
|
; min([LAST_SCY]/8 - [SCY/8], [SCY/8] - [LAST_SCY]/8) |
|
|
|
|
|
|
|
ld a, [LAST_SCY] |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
ld b, a |
|
|
|
|
|
|
|
ld a, [rSCY] |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
|
|
|
|
; c <- scy/8 - last_scy/8 |
|
|
|
sub b |
|
|
|
ld c, a |
|
|
|
|
|
|
|
ld a, [rSCY] |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
ld b, a |
|
|
|
|
|
|
|
ld a, [LAST_SCY] |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
sub b |
|
|
|
; a <- last_scy/8 - scy/8 |
|
|
|
|
|
|
|
cp c |
|
|
|
|
|
|
|
.tryit: |
|
|
|
ld [CURRENT_CAMERA_Y], a |
|
|
|
|
|
|
|
.scroll_up_check: |
|
|
|
; If SCY = PAGEY, write map row |
|
|
|
; map coords = CURRENT_CAMERA_X, CURRENT_CAMERA_Y - 2 |
|
|
|
; HL = _SCRN0 + 32 * (page_y - 1) |
|
|
|
; HL = _SCRN0 + 32 * (32 - page_y/8 - 2) |
|
|
|
ld hl, PAGEY |
|
|
|
ld a, [rSCY] |
|
|
|
cp [hl] |
|
|
|
jr nz, .scroll_down_check |
|
|
|
|
|
|
|
ld a, [rSCX] |
|
|
|
ld b, a |
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
srl b |
|
|
|
srl b |
|
|
|
srl b |
|
|
|
sub b |
|
|
|
ld b, a |
|
|
|
|
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
cp 2 |
|
|
|
jr c, .done |
|
|
|
|
|
|
|
sub 2 |
|
|
|
ld c, a |
|
|
|
|
|
|
|
; a = scy/8 + (scy/8 < 2 ? 30 : -2) |
|
|
|
|
|
|
|
ld a, [rSCY] |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
|
|
|
|
cp 2 |
|
|
|
jr nc, .loop0 |
|
|
|
add 32 |
|
|
|
|
|
|
|
.loop0: |
|
|
|
sub 2 |
|
|
|
|
|
|
|
; hl = _SCRN0 + 32 * a |
|
|
|
ld e, a |
|
|
|
ld hl, _SCRN0 |
|
|
|
.loop: |
|
|
|
ld a, e |
|
|
|
or a |
|
|
|
jr z, .write_up |
|
|
|
|
|
|
|
ld a, 32 |
|
|
|
ADD16 hl |
|
|
|
|
|
|
|
dec e |
|
|
|
jr .loop |
|
|
|
|
|
|
|
.write_up: |
|
|
|
halt |
|
|
|
call write_map_row |
|
|
|
|
|
|
|
ld a, [PAGEY] |
|
|
|
sub 8 |
|
|
|
ld [PAGEY], a |
|
|
|
|
|
|
|
jr .done |
|
|
|
|
|
|
|
.scroll_down_check: |
|
|
|
; If SCY = SCRN_Y - PAGEY, write map row |
|
|
|
; map coords = CURRENT_CAMERA_X, CURRENT_CAMERA_Y + 21 |
|
|
|
; HL = _SCRN0 + 32 * ((32 - page_y) - 1) |
|
|
@ -126,6 +245,11 @@ Map_Scroll:: |
|
|
|
; If SCX = PAGEX, write map col |
|
|
|
; If SCX = SCRN_X - PAGEX, write map col |
|
|
|
|
|
|
|
.done: |
|
|
|
ld hl, LAST_SCY |
|
|
|
ld a, [rSCY] |
|
|
|
ld [hl], a |
|
|
|
|
|
|
|
ret |
|
|
|
|
|
|
|
; Write a row of map data into map RAM |
|
|
|