Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OverworldLoop:
- rst wait_vblank
- ; Reset "single-frame" vars
- xor a
- ld [wCurStateFirstFrame], a
- ; Change state if needed
- ld a, [wNextState]
- and a
- jr z, .keepCurrentState
- ld a, [wOverworldState]
- ld [wPreviousState], a
- ld a, [wNextState]
- ld [wOverworldState], a
- xor a
- ld [wNextState], a
- inc a ; ld a, 1
- ld [wCurStateFirstFrame], a
- .keepCurrentState
- ; Begin by retrieving info from the current state
- ld a, BANK(OverworldStatePtrs)
- rst bankswitch
- ld a, [wOverworldState]
- add a, a
- add a, LOW(OverworldStatePtrs)
- ld l, a
- adc a, HIGH(OverworldStatePtrs)
- sub l
- ld h, a
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ; hl points to current state struct
- ld a, [hli]
- ld e, a
- ld a, [hli]
- ld d, a
- or e
- jr z, .noFunction
- push hl
- call CallDE
- pop hl
- .noFunction
- ; BUTTON PROCESSING
- ld a, [wNextState]
- and a
- jr nz, .skipButtons ; Skip any button operations if we need to change states
- ld a, [hli] ; Get button mask
- ld c, a
- ldh a, [hHeldButtons]
- and c
- ld c, a
- ldh a, [hPressedButtons]
- or c
- ld c, a
- ld b, 8
- .checkButton
- rl c
- ld a, [hli]
- ld e, a
- ld a, [hli]
- jr nc, .skipButton ; Skip button if not selected
- ld d, a
- or e
- jr z, .skipButton
- push hl
- push bc
- call CallDE
- pop bc
- pop hl
- .skipButton
- dec b
- jr nz, .checkButton
- .skipButtons
- OverworldUpdate:
- ld a, [wDoOverworldUpdates]
- and a
- jp z, OverworldLoop
- ; Redraw NPCs
- ld hl, wPlayer
- ld de, wShadowOAM
- ; (SNIP...)
- ld a, d ; ld a, HIGH(wShadowOAM)
- ldh [hOAMBufferHigh], a
- ld a, e
- cp $A0
- jr nc, .OAMFull
- .clearOAM
- xor a
- ld [de], a
- ld a, e
- add a, 4
- ld e, a
- cp $A0
- jr c, .clearOAM
- .OAMFull
- ; Check the direction the camera moved, if at all
- ; Ugly, but that's because we have to offset the camera's position, otherwise there are overflows when the camera gets close to the top/left edge
- ld de, wCameraYPos
- ld hl, wCameraPrevYPos
- ; (SNIP...)
- ldh [hCameraXMovementDirection], a
- ; Update BG position(s)
- ld a, [wScrollingType]
- add a, a
- add a, LOW(.scrollingFuncs)
- ld l, a
- adc a, HIGH(.scrollingFuncs)
- sub l
- ld h, a
- ld a, [hli]
- ld h, [hl]
- ld l, a
- rst call_hl
- jp OverworldLoop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement