diff options
| author | Marcus Huderle <huderlem@gmail.com> | 2017-09-07 20:30:27 -0700 |
|---|---|---|
| committer | Marcus Huderle <huderlem@gmail.com> | 2017-09-07 20:49:20 -0700 |
| commit | 61ce00763a3f4cb7e2d2f1aa49a2a7eed848aec3 (patch) | |
| tree | 77c07339de49b6bbb2ac59375033da8f2999510c /home | |
| parent | 023bacc23fa0e400ca7ae5b7c9e507f6a6b87c8b (diff) | |
Move some code out of home.asm
Diffstat (limited to 'home')
| -rwxr-xr-x | home/animation.asm | 48 | ||||
| -rwxr-xr-x | home/bcd.asm | 109 | ||||
| -rwxr-xr-x | home/tilt.asm | 240 |
3 files changed, 397 insertions, 0 deletions
diff --git a/home/animation.asm b/home/animation.asm new file mode 100755 index 0000000..7566fb1 --- /dev/null +++ b/home/animation.asm @@ -0,0 +1,48 @@ +InitAnimation: ; 0x28a0
+; Initializes an OAM animation.
+; hl = pointer to first frame of animation
+; de = pointer to destination animation struct
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hli]
+ ld [de], a
+ inc de
+ xor a
+ ld [de], a
+ ret
+
+UpdateAnimation: ; 0x28a9
+; Updates an animation struct. (See wDugtrioAnimationFrameCounter)
+; Input: de = pointer to 3-byte animation struct
+; hl = pointer to animation frames data
+; Sets carry flag if the animation is over.
+ ld a, [de]
+ and a
+ ret z ; return, if counter is zero
+ dec a
+ ld [de], a
+ ret nz ; return if counter is not zero after the decrement
+ push de
+ inc de
+ inc de
+ ld a, [de] ; a = current frame index
+ inc a
+ ld [de], a
+ ld c, a
+ ld b, $0
+ sla c
+ rl b
+ add hl, bc ; hl = pointer to two-byte entry in the frames data table
+ ld a, [hli]
+ pop de
+ and a
+ scf
+ ret z ; return if the next entry is $00
+ push de
+ ld [de], a ; save the animation duration
+ inc de
+ ld a, [hli]
+ ld [de], a ; save the next animation frame id
+ pop de
+ ret
diff --git a/home/bcd.asm b/home/bcd.asm new file mode 100755 index 0000000..49055ad --- /dev/null +++ b/home/bcd.asm @@ -0,0 +1,109 @@ +; This file contains functions to handle adding and retrieving BCD (binary coded decimal) values.
+
+Func_3500:
+ ld hl, wScoreToAdd
+ ld a, e
+ ld [hli], a
+ ld a, d
+ ld [hli], a
+ ld a, c
+ ld [hli], a
+ ld a, b
+ ld [hli], a
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ld bc, wScoreToAdd
+ callba AddBigBCD6FromQueueWithBallMultiplier
+ ret
+
+AddBCDEToCurBufferValue: ; 0x351c
+ ld hl, wScoreToAdd
+ ld a, e
+ ld [hli], a
+ ld a, d
+ ld [hli], a
+ ld a, c
+ ld [hli], a
+ ld a, b
+ ld [hli], a
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ld bc, wScoreToAdd
+ callba AddBigBCD6FromQueue
+ ret
+
+AddBCDEToJackpot: ; 0x3538
+; Add BCD value bcde to [wCurrentJackpot]. Cap at $99999999.
+ ld hl, wCurrentJackpot
+ ld a, [hl]
+ add e
+ daa
+ ld [hli], a
+ ld a, [hl]
+ adc d
+ daa
+ ld [hli], a
+ ld a, [hl]
+ adc c
+ daa
+ ld [hli], a
+ ld a, [hl]
+ adc b
+ daa
+ ld [hli], a
+ ret nc
+ ld hl, wCurrentJackpot
+ ld a, $99
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ret
+
+RetrieveJackpot: ; 0x3556
+; Retrieves a 4-byte BCD value at wCurrentJackpot
+ ld a, [wCurrentJackpot]
+ ld e, a
+ ld a, [wCurrentJackpot + 1]
+ ld d, a
+ ld a, [wCurrentJackpot + 2]
+ ld c, a
+ ld a, [wCurrentJackpot + 3]
+ ld b, a
+ ret
+
+Func_3567:
+; BCD add bc to hl
+ ld a, l
+ add c
+ daa
+ ld l, a
+ ld a, h
+ adc b
+ daa
+ ld h, a
+ ret
+
+Func_3570:
+; BCD add de to hl
+ ld a, l
+ add e
+ daa
+ ld l, a
+ ld a, h
+ adc d
+ daa
+ ld h, a
+ ret
+
+Func_3579: ; 0x3579
+; Delete 4-byte BCD value at wCurrentJackpot
+ ld hl, wCurrentJackpot
+ xor a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ret
diff --git a/home/tilt.asm b/home/tilt.asm new file mode 100755 index 0000000..058c554 --- /dev/null +++ b/home/tilt.asm @@ -0,0 +1,240 @@ +HandleTilts: ; 0x3582
+ call HandleLeftTilt
+ call HandleRightTilt
+ call HandleUpperTilt
+ ret
+
+HandleLeftTilt: ; 0x358c
+ ld a, [wLeftTiltReset]
+ and a
+ jr nz, .tiltCoolDown
+ ld hl, wKeyConfigLeftTilt
+ call IsKeyPressed2
+ jr z, .tiltCoolDown
+ ld a, [wLeftTiltCounter]
+ cp $3
+ jr z, .startCoolDown
+ inc a
+ ld [wLeftTiltCounter], a
+ cp $1
+ jr nz, .skipSoundEffect
+ lb de, $00, $3f
+ call PlaySoundEffect
+.skipSoundEffect
+ ld a, [wPinballIsVisible]
+ ld hl, wEnableBallGravityAndTilt
+ and [hl]
+ jr z, .skipBallMovement
+ ld a, [wBallXPos + 1]
+ dec a ; move ball's position to the left by 1 pixel
+ ld [wBallXPos + 1], a
+.skipBallMovement
+ ld a, [wLeftAndRightTiltPixelsOffset]
+ inc a
+ ld [wLeftAndRightTiltPixelsOffset], a
+ ld a, $1
+ ld [wLeftTiltPushing], a
+ ret
+
+.startCoolDown
+ ld a, $1
+ ld [wLeftTiltReset], a
+.tiltCoolDown
+ xor a
+ ld [wLeftTiltPushing], a
+ ld a, [wLeftTiltCounter]
+ and a
+ jr z, .done
+ dec a
+ ld [wLeftTiltCounter], a
+ ld a, [wLeftAndRightTiltPixelsOffset]
+ dec a
+ ld [wLeftAndRightTiltPixelsOffset], a
+ ret
+
+.done
+ ld hl, wKeyConfigLeftTilt
+ call IsKeyPressed2
+ ret nz
+ xor a
+ ld [wLeftTiltReset], a
+ ret
+
+HandleRightTilt: ; 0x35f3
+ ld a, [wRightTiltReset]
+ and a
+ jr nz, .tiltCoolDown
+ ld hl, wKeyConfigRightTilt
+ call IsKeyPressed2
+ jr z, .tiltCoolDown
+ ld a, [wRightTiltCounter]
+ cp $3
+ jr z, .startCoolDown
+ inc a
+ ld [wRightTiltCounter], a
+ cp $1
+ jr nz, .skipSoundEffect
+ lb de, $00, $3f
+ call PlaySoundEffect
+.skipSoundEffect
+ ld a, [wPinballIsVisible]
+ ld hl, wEnableBallGravityAndTilt
+ and [hl]
+ jr z, .skipBallMovement
+ ld a, [wBallXPos + 1]
+ inc a ; move ball's position to the right by 1 pixel
+ ld [wBallXPos + 1], a
+.skipBallMovement
+ ld a, [wLeftAndRightTiltPixelsOffset]
+ dec a
+ ld [wLeftAndRightTiltPixelsOffset], a
+ ld a, $1
+ ld [wRightTiltPushing], a
+ ret
+
+.startCoolDown
+ ld a, $1
+ ld [wRightTiltReset], a
+.tiltCoolDown
+ xor a
+ ld [wRightTiltPushing], a
+ ld a, [wRightTiltCounter]
+ and a
+ jr z, .done
+ dec a
+ ld [wRightTiltCounter], a
+ ld a, [wLeftAndRightTiltPixelsOffset]
+ inc a
+ ld [wLeftAndRightTiltPixelsOffset], a
+ ret
+
+.done
+ ld hl, wKeyConfigRightTilt
+ call IsKeyPressed2
+ ret nz
+ xor a
+ ld [wRightTiltReset], a
+ ret
+
+HandleUpperTilt: ; 0x365a
+ ld a, [wUpperTiltReset]
+ and a
+ jr nz, .tiltCoolDown
+ ld hl, wKeyConfigUpperTilt
+ call IsKeyPressed2
+ jr z, .tiltCoolDown
+ ld a, [wUpperTiltCounter]
+ cp $4
+ jr z, .startCoolDown
+ inc a
+ ld [wUpperTiltCounter], a
+ cp $1
+ jr nz, .skipSoundEffect
+ lb de, $00, $3f
+ call PlaySoundEffect
+.skipSoundEffect
+ ld a, [wPinballIsVisible]
+ ld hl, wEnableBallGravityAndTilt
+ and [hl]
+ jr z, .skipBallMovement
+ ld a, [wBallYPos + 1]
+ inc a ; move ball's position down by 1 pixel
+ ld [wBallYPos + 1], a
+.skipBallMovement
+ ld a, [wUpperTiltPixelsOffset]
+ dec a
+ ld [wUpperTiltPixelsOffset], a
+ ld a, $1
+ ld [wUpperTiltPushing], a
+ ret
+
+.startCoolDown
+ ld a, $1
+ ld [wUpperTiltReset], a
+.tiltCoolDown
+ xor a
+ ld [wUpperTiltPushing], a
+ ld a, [wUpperTiltCounter]
+ and a
+ jr z, .done
+ dec a
+ ld [wUpperTiltCounter], a
+ ld a, [wUpperTiltPixelsOffset]
+ inc a
+ ld [wUpperTiltPixelsOffset], a
+ ret
+
+.done
+ ld hl, wKeyConfigUpperTilt
+ call IsKeyPressed2
+ ret nz
+ xor a
+ ld [wUpperTiltReset], a
+ ret
+
+ApplyTiltForces: ; 0x36c1
+ ld a, [wPinballIsVisible]
+ ld hl, wEnableBallGravityAndTilt
+ and [hl]
+ ret z
+ ld c, $0
+ ld a, [wUpperTiltPushing]
+ srl a
+ rl c
+ ld a, [wRightTiltPushing]
+ srl a
+ rl c
+ ld a, [wLeftTiltPushing]
+ srl a
+ rl c
+ ld b, $0
+ sla c
+ ld hl, TiltForces
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ bit 7, h
+ ret nz
+ ld a, [wCollisionForceAngle]
+ ld c, a
+ ld b, $0
+ sla c
+ rl b
+ sla c
+ rl b
+ add hl, bc
+ ld a, [hLoadedROMBank]
+ push af
+ ld a, BANK(TiltLeftOnlyForce)
+ ld [hLoadedROMBank], a
+ ld [MBC5RomBank], a
+ ld a, [wBallXVelocity]
+ add [hl]
+ ld [wBallXVelocity], a
+ inc hl
+ ld a, [wBallXVelocity + 1]
+ adc [hl]
+ ld [wBallXVelocity + 1], a
+ inc hl
+ ld a, [wBallYVelocity]
+ add [hl]
+ ld [wBallYVelocity], a
+ inc hl
+ ld a, [wBallYVelocity + 1]
+ adc [hl]
+ ld [wBallYVelocity + 1], a
+ pop af
+ ld [hLoadedROMBank], a
+ ld [MBC5RomBank], a
+ ret
+
+TiltForces: ; 0x372d
+ dw $FFFF ; no tilt
+ dw TiltLeftOnlyForce
+ dw TiltRightOnlyForce
+ dw $FFFF ; left + right (cancel each other, so no tilt)
+ dw TiltUpOnlyForce
+ dw TiltUpLeftForce
+ dw TiltUpRightForce
+ dw TiltUpOnlyForce
|
