Browse Source

Update camera when left/right pressed

master
Forest Belton 3 years ago
parent
commit
9ca2b10062
1 changed files with 69 additions and 18 deletions
  1. +69
    -18
      src/main.s

+ 69
- 18
src/main.s View File

@ -61,8 +61,22 @@ start:
ld [PENDING_ROW_PTR], a ld [PENDING_ROW_PTR], a
ld [PENDING_ROW_PTR + 1], a ld [PENDING_ROW_PTR + 1], a
; TODO: remove once scrolling is implemented
; scroll map with arrow keys
call scroll_update
; wait for vblank
halt
call Map_Update
; ~160 cycles
ld a, HIGH(_OAM)
call DMA_Start
jp .loop
; TODO: remove once scrolling is implemented
scroll_update:
; scroll map with arrow keys
ld a, [keys] ld a, [keys]
and PADF_UP and PADF_UP
jr z, .down jr z, .down
@ -76,7 +90,7 @@ start:
ld hl, CURRENT_CAMERA_Y ld hl, CURRENT_CAMERA_Y
ld a, [hl] ld a, [hl]
or a or a
jr z, .vbl
ret z
.update_up: .update_up:
ld hl, rSCY ld hl, rSCY
@ -93,7 +107,7 @@ start:
.update_up_map: .update_up_map:
call Map_Scroll call Map_Scroll
jr .vbl
ret
.down: .down:
ld a, [keys] ld a, [keys]
@ -110,7 +124,7 @@ start:
ld a, [CURRENT_CAMERA_Y] ld a, [CURRENT_CAMERA_Y]
add 18 add 18
cp b cp b
jr z, .vbl
ret z
.update_down: .update_down:
ld hl, rSCY ld hl, rSCY
@ -126,36 +140,73 @@ start:
.update_down_map: .update_down_map:
call Map_Scroll call Map_Scroll
jr .vbl
ret
.right: .right:
ld a, [keys] ld a, [keys]
and PADF_RIGHT and PADF_RIGHT
jr z, .left jr z, .left
; don't scroll right if on last tile
ld hl, rSCX
ld a, [hl]
and %111
jr nz, .update_right
ld a, [CURRENT_MAP_WIDTH]
ld b, a
ld a, [CURRENT_CAMERA_X]
inc a
; add 18
cp b
ret z
.update_right:
ld hl, rSCX ld hl, rSCX
inc [hl] inc [hl]
ld a, [hl]
and %111
jr nz, .update_right_map
ld a, [CURRENT_CAMERA_X]
inc a
ld [CURRENT_CAMERA_X], a
.update_right_map:
call Map_Scroll call Map_Scroll
ret
.left: .left:
ld a, [keys] ld a, [keys]
and PADF_LEFT and PADF_LEFT
jr z, .vbl
ret z
; don't scroll left if on last tile
ld hl, rSCX ld hl, rSCX
dec [hl]
ld a, [hl]
and %111
cp %111
jr nz, .update_left
call Map_Scroll
; call Player_Update
ld hl, CURRENT_CAMERA_X
ld a, [hl]
or a
ret z
; wait for vblank
.vbl:
halt
.update_left:
ld hl, rSCX
dec [hl]
call Map_Update
ld a, [hl]
and %111
cp %111
jr nz, .update_left_map
; ~160 cycles
ld a, HIGH(_OAM)
call DMA_Start
ld a, [CURRENT_CAMERA_X]
dec a
ld [CURRENT_CAMERA_X], a
jp .loop
.update_left_map:
call Map_Scroll
ret

Loading…
Cancel
Save