Browse Source

Almost have scrolling up working

master
Forest Belton 2 years ago
parent
commit
adc9cfa632
2 changed files with 154 additions and 2 deletions
  1. +28
    -0
      src/main.s
  2. +126
    -2
      src/map.s

+ 28
- 0
src/main.s View File

@ -62,16 +62,43 @@ start:
and BTN_UP
jr z, .down
; don't scroll up if on last tile
ld hl, rSCY
ld a, [hl]
and %111
jr nz, .update_up
ld hl, CURRENT_CAMERA_Y
ld a, [hl]
or a
jr z, .vbl
.update_up:
ld hl, rSCY
dec [hl]
call Map_Scroll
.down:
ld a, [keys]
and BTN_DOWN
jr z, .right
; don't scroll down if on last tile
ld a, [rSCY]
and %111
jr nz, .update_down
ld a, [CURRENT_MAP_HEIGHT]
ld b, a
ld a, [CURRENT_CAMERA_Y]
add 18
cp b
jr z, .vbl
.update_down:
ld hl, rSCY
inc [hl]
call Map_Scroll
.right:
ld a, [keys]
@ -80,6 +107,7 @@ start:
ld hl, rSCX
inc [hl]
call Map_Scroll
.left:
ld a, [keys]

+ 126
- 2
src/map.s View File

@ -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

Loading…
Cancel
Save