|
|
@ -88,23 +88,57 @@ Map_Load:: |
|
|
|
|
|
|
|
; Scroll the map upwards |
|
|
|
; @param d The amount to scroll by (0 < d < 8) |
|
|
|
; |
|
|
|
; SCY_T = SCY % 8; |
|
|
|
; if CAMERA_Y = 0 { |
|
|
|
; if SCY_T != 0 { |
|
|
|
; SCY -= MIN(D, SCY_T); |
|
|
|
; } |
|
|
|
; return; |
|
|
|
; } |
|
|
|
; SCY -= D; |
|
|
|
; if SCY_T - D < 0 { |
|
|
|
; CAMERA_Y -= 1; |
|
|
|
; Map_ScrollRow(CAMERA_X - 2, CAMERA_Y - 2); |
|
|
|
; } |
|
|
|
Map_ScrollUp:: |
|
|
|
; Check whether we crossed tile boundary |
|
|
|
ld a, [rSCY] |
|
|
|
and %111 |
|
|
|
cp d |
|
|
|
jr nc, .done |
|
|
|
|
|
|
|
; Don't scroll if at top tile |
|
|
|
add sp, -1 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld [hl], a |
|
|
|
|
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
or a |
|
|
|
ret z |
|
|
|
jr nz, .scroll |
|
|
|
|
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
or a |
|
|
|
jr z, .done |
|
|
|
|
|
|
|
ld b, d |
|
|
|
call min |
|
|
|
ld d, a |
|
|
|
ld a, [rSCY] |
|
|
|
sub d |
|
|
|
ld [rSCY], a |
|
|
|
jr .done |
|
|
|
|
|
|
|
.scroll: |
|
|
|
ld a, [rSCY] |
|
|
|
sub d |
|
|
|
ld [rSCY], a |
|
|
|
|
|
|
|
; Check SCY_T - D < 0 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
sub d |
|
|
|
jr nc, .done |
|
|
|
|
|
|
|
; CAMERA_Y -= 1 |
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
dec a |
|
|
|
ld [CURRENT_CAMERA_Y], a |
|
|
|
|
|
|
@ -123,57 +157,73 @@ Map_ScrollUp:: |
|
|
|
srln a, 3 |
|
|
|
sub 2 |
|
|
|
|
|
|
|
add sp, 1 |
|
|
|
jr Map_ScrollRow |
|
|
|
|
|
|
|
.done: |
|
|
|
ld a, [rSCY] |
|
|
|
sub d |
|
|
|
ld [rSCY], a |
|
|
|
add sp, 1 |
|
|
|
ret |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Map_ScrollDown(D) |
|
|
|
; |
|
|
|
; SCY_T = SCY % 8; |
|
|
|
; if CAMERA_Y + 18 = MAP_HEIGHT { |
|
|
|
; if SCY_T != 0 { |
|
|
|
; SCY += MIN(D, 8 - SCY_T); |
|
|
|
; } |
|
|
|
; return; |
|
|
|
; } |
|
|
|
; SCY += D; |
|
|
|
; if SCY_T + D >= 8 { |
|
|
|
; CAMERA_Y += 1; |
|
|
|
; Map_ScrollRow(CAMERA_X - 2, CAMERA_Y + 18 + 1); |
|
|
|
; } |
|
|
|
Map_ScrollDown:: |
|
|
|
; Don't scroll if at bottom tile |
|
|
|
ld a, [rSCY] |
|
|
|
and %111 |
|
|
|
|
|
|
|
add sp, -1 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld [hl], a |
|
|
|
|
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
add SCRN_Y_B |
|
|
|
ld hl, CURRENT_MAP_HEIGHT |
|
|
|
cp [hl] |
|
|
|
jr nz, .down |
|
|
|
jr nz, .scroll |
|
|
|
|
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
or a |
|
|
|
jr z, .done |
|
|
|
|
|
|
|
sub 8 |
|
|
|
cpl |
|
|
|
|
|
|
|
ld b, d |
|
|
|
call min |
|
|
|
ld d, a |
|
|
|
ld a, [rSCY] |
|
|
|
add d |
|
|
|
and %111 |
|
|
|
ld [rSCY], a |
|
|
|
ret |
|
|
|
jr .done |
|
|
|
|
|
|
|
; Check whether we crossed tile boundary |
|
|
|
.down: |
|
|
|
.scroll: |
|
|
|
ld a, [rSCY] |
|
|
|
and %111 |
|
|
|
add d |
|
|
|
cp 8 |
|
|
|
jr c, .done |
|
|
|
|
|
|
|
; TODO: |
|
|
|
; if CAMERA_Y + 18 = MAP_HEIGHT { |
|
|
|
; if SCY % 8 != 0 { |
|
|
|
; SCY += MIN(D, 8 - SCY % 8) |
|
|
|
; } |
|
|
|
; return |
|
|
|
; } |
|
|
|
; if SCY % 8 + D > 8 { |
|
|
|
; SCY += D |
|
|
|
; LOAD_COLUMN(CAMERA_X - 2, CAMERA_Y + 18 + 1); |
|
|
|
; } else { |
|
|
|
; SCY += D |
|
|
|
; } |
|
|
|
ld [rSCY], a |
|
|
|
|
|
|
|
ld a, [rSCY] |
|
|
|
; Check SCY_T + D < 8 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
add d |
|
|
|
ld [rSCY], a |
|
|
|
cp 8 |
|
|
|
jr c, .done |
|
|
|
|
|
|
|
; CAMERA_Y += 1 |
|
|
|
ld a, [CURRENT_CAMERA_Y] |
|
|
|
inc a |
|
|
|
ld [CURRENT_CAMERA_Y], a |
|
|
|
|
|
|
@ -192,12 +242,11 @@ Map_ScrollDown:: |
|
|
|
srln a, 3 |
|
|
|
add SCRN_Y_B + 1 |
|
|
|
|
|
|
|
add sp, 1 |
|
|
|
jr Map_ScrollRow |
|
|
|
|
|
|
|
.done: |
|
|
|
ld a, [rSCY] |
|
|
|
add d |
|
|
|
ld [rSCY], a |
|
|
|
add sp, 1 |
|
|
|
ret |
|
|
|
|
|
|
|
|
|
|
@ -222,21 +271,47 @@ Map_ScrollRow: |
|
|
|
call enqueue_row_write |
|
|
|
ret |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map_ScrollLeft:: |
|
|
|
; Check whether we crossed tile boundary |
|
|
|
ld a, [rSCX] |
|
|
|
and %111 |
|
|
|
cp d |
|
|
|
jr nc, .done |
|
|
|
|
|
|
|
add sp, -1 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld [hl], a |
|
|
|
|
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
or a |
|
|
|
jr nz, .scroll |
|
|
|
|
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
or a |
|
|
|
jr z, .done |
|
|
|
|
|
|
|
ld b, d |
|
|
|
call min |
|
|
|
ld d, a |
|
|
|
ld a, [rSCX] |
|
|
|
sub d |
|
|
|
ld [rSCX], a |
|
|
|
jr .done |
|
|
|
|
|
|
|
.scroll: |
|
|
|
ld a, [rSCX] |
|
|
|
sub d |
|
|
|
ld [rSCX], a |
|
|
|
|
|
|
|
; Check SCX_T - D < 0 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
sub d |
|
|
|
jr nc, .done |
|
|
|
|
|
|
|
; Don't scroll if at left tile |
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
or a |
|
|
|
ret z |
|
|
|
dec a |
|
|
|
ld [CURRENT_CAMERA_X], a |
|
|
|
|
|
|
|
ld a, [rSCY] |
|
|
|
sub 16 |
|
|
@ -254,37 +329,61 @@ Map_ScrollLeft:: |
|
|
|
ld a, [rSCX] |
|
|
|
srln a, 3 |
|
|
|
sub 2 |
|
|
|
ADD16 hl |
|
|
|
|
|
|
|
add sp, 1 |
|
|
|
jr Map_ScrollColumn |
|
|
|
|
|
|
|
.done: |
|
|
|
ld a, [rSCX] |
|
|
|
sub d |
|
|
|
ld [rSCX], a |
|
|
|
add sp, 1 |
|
|
|
ret |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map_ScrollRight:: |
|
|
|
; Check whether we crossed tile boundary |
|
|
|
ld a, [rSCX] |
|
|
|
and %111 |
|
|
|
|
|
|
|
add sp, -1 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld [hl], a |
|
|
|
|
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
add SCRN_X_B |
|
|
|
ld hl, CURRENT_MAP_WIDTH |
|
|
|
cp [hl] |
|
|
|
jr nz, .scroll |
|
|
|
|
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
or a |
|
|
|
jr z, .done |
|
|
|
|
|
|
|
sub 8 |
|
|
|
cpl |
|
|
|
|
|
|
|
ld b, d |
|
|
|
call min |
|
|
|
ld d, a |
|
|
|
ld a, [rSCX] |
|
|
|
add d |
|
|
|
cp 8 |
|
|
|
jr nc, .done |
|
|
|
ld [rSCX], a |
|
|
|
jr .done |
|
|
|
|
|
|
|
.scroll: |
|
|
|
ld a, [rSCX] |
|
|
|
add d |
|
|
|
ld [rSCX], a |
|
|
|
|
|
|
|
; Don't scroll if at bottom tile |
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
inc a |
|
|
|
ld hl, CURRENT_MAP_WIDTH |
|
|
|
cp [hl] |
|
|
|
ret z |
|
|
|
; Check SCX_T + D < 8 |
|
|
|
ld hl, sp + 0 |
|
|
|
ld a, [hl] |
|
|
|
add d |
|
|
|
cp 8 |
|
|
|
jr c, .done |
|
|
|
|
|
|
|
; CAMERA_X += 1 |
|
|
|
ld a, [CURRENT_CAMERA_X] |
|
|
|
inc a |
|
|
|
ld [CURRENT_CAMERA_X], a |
|
|
|
|
|
|
@ -306,14 +405,14 @@ Map_ScrollRight:: |
|
|
|
srl a |
|
|
|
srl a |
|
|
|
add SCRN_X_B + 1 |
|
|
|
ld e, a |
|
|
|
and %11111 |
|
|
|
ADD16 hl |
|
|
|
|
|
|
|
add sp, 1 |
|
|
|
jr Map_ScrollColumn |
|
|
|
|
|
|
|
.done: |
|
|
|
ld a, [rSCX] |
|
|
|
add d |
|
|
|
ld [rSCX], a |
|
|
|
add sp, 1 |
|
|
|
ret |
|
|
|
|
|
|
|
|
|
|
|