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 | |
parent | 023bacc23fa0e400ca7ae5b7c9e507f6a6b87c8b (diff) |
Move some code out of home.asm
22 files changed, 475 insertions, 487 deletions
diff --git a/engine/pinball_game/ball_init/ball_init_blue_field.asm b/engine/pinball_game/ball_init/ball_init_blue_field.asm index 9728be0..ec486c7 100644 --- a/engine/pinball_game/ball_init/ball_init_blue_field.asm +++ b/engine/pinball_game/ball_init/ball_init_blue_field.asm @@ -80,7 +80,7 @@ StartBallAfterBonusStageBlueField: ; 0x1c129 ld [wBallXVelocity + 1], a
ld [wReturningFromBonusStage], a
ld [wSCX], a
- ld [wd7be], a
+ ld [wFlippersDisabled], a
ld a, [wBallTypeBackup]
ld [wBallType], a
ld a, $10
diff --git a/engine/pinball_game/ball_init/ball_init_red_field.asm b/engine/pinball_game/ball_init/ball_init_red_field.asm index c37e21c..1f0d531 100644 --- a/engine/pinball_game/ball_init/ball_init_red_field.asm +++ b/engine/pinball_game/ball_init/ball_init_red_field.asm @@ -85,7 +85,7 @@ StartBallAfterBonusStageRedField: ; 0x30128 ld [wBallXVelocity + 1], a
ld [wReturningFromBonusStage], a
ld [wSCX], a
- ld [wd7be], a
+ ld [wFlippersDisabled], a
ld a, [wBallTypeBackup]
ld [wBallType], a
ld a, $f
diff --git a/engine/pinball_game/ball_loss/ball_loss_meowth_bonus.asm b/engine/pinball_game/ball_loss/ball_loss_meowth_bonus.asm index cfd12b5..6e9f994 100644 --- a/engine/pinball_game/ball_loss/ball_loss_meowth_bonus.asm +++ b/engine/pinball_game/ball_loss/ball_loss_meowth_bonus.asm @@ -1,13 +1,13 @@ HandleBallLossMeowthBonus: ; 0xdfe2
xor a
ld [wd64e], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
- jr z, .asm_dff2
+ jr z, .flippersEnabled
ld a, [wCompletedBonusStage]
and a
jr z, .asm_e00f
-.asm_dff2
+.flippersEnabled
ld a, [wMeowthStageScore]
cp 20
jr nc, .asm_e00f
diff --git a/engine/pinball_game/ball_loss/ball_loss_seel_bonus.asm b/engine/pinball_game/ball_loss/ball_loss_seel_bonus.asm index 18baa5a..6fbce47 100644 --- a/engine/pinball_game/ball_loss/ball_loss_seel_bonus.asm +++ b/engine/pinball_game/ball_loss/ball_loss_seel_bonus.asm @@ -1,13 +1,13 @@ HandleBallLossSeelBonus: ; 0xe08b
xor a
ld [wd64e], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
- jr z, .asm_e09b
+ jr z, .flippersEnabled
ld a, [wCompletedBonusStage]
and a
jr z, .asm_e0b8
-.asm_e09b
+.flippersEnabled
ld a, [wd793]
cp $14
jr nc, .asm_e0b8
diff --git a/engine/pinball_game/flippers.asm b/engine/pinball_game/flippers.asm index 466975e..c6bd5ab 100644 --- a/engine/pinball_game/flippers.asm +++ b/engine/pinball_game/flippers.asm @@ -21,7 +21,7 @@ Func_e118: ; 0xe118 call IsKeyPressed2
ld hl, -$0333
jr z, .asm_e13b
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr nz, .asm_e13b
ld hl, $0333
@@ -67,7 +67,7 @@ Func_e118: ; 0xe118 call IsKeyPressed2
ld hl, -$0333
jr z, .asm_e18e
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr nz, .asm_e18e
ld hl, $0333
@@ -112,7 +112,7 @@ Func_e118: ; 0xe118 ret
PlayFlipperSoundIfPressed: ; 0xe1ce
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
ret nz
ld hl, wKeyConfigLeftFlipper
@@ -676,7 +676,7 @@ DrawFlippers: ; 0xe4a1 ld a, [hGameBoyColorFlag]
and a
jr nz, .asm_e4d4
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr z, .asm_e4d4
ld a, $18
@@ -708,7 +708,7 @@ DrawFlippers: ; 0xe4a1 ld a, [hGameBoyColorFlag]
and a
jr nz, .asm_e504
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr z, .asm_e504
ld a, $17
diff --git a/engine/pinball_game/load_stage_data/load_diglett_bonus.asm b/engine/pinball_game/load_stage_data/load_diglett_bonus.asm index 6be87a9..6fbb02b 100644 --- a/engine/pinball_game/load_stage_data/load_diglett_bonus.asm +++ b/engine/pinball_game/load_stage_data/load_diglett_bonus.asm @@ -1,6 +1,6 @@ _LoadStageDataDiglettBonus: ; 0x19a76
callba Func_142fc
- call Func_2862
+ call LoadFlippersPalette
ld a, [wd7c1]
and a
ret z
diff --git a/engine/pinball_game/load_stage_data/load_gengar_bonus.asm b/engine/pinball_game/load_stage_data/load_gengar_bonus.asm index b6d30fd..31a26a7 100644 --- a/engine/pinball_game/load_stage_data/load_gengar_bonus.asm +++ b/engine/pinball_game/load_stage_data/load_gengar_bonus.asm @@ -1,6 +1,6 @@ _LoadStageDataGengarBonus: ; 0x1818b
callba Func_142fc
- call Func_2862
+ call LoadFlippersPalette
call Func_18d72
ld a, [wd7c1]
callba LoadTimerGraphics
diff --git a/engine/pinball_game/load_stage_data/load_meowth_bonus.asm b/engine/pinball_game/load_stage_data/load_meowth_bonus.asm index e51c8af..fd53f2a 100644 --- a/engine/pinball_game/load_stage_data/load_meowth_bonus.asm +++ b/engine/pinball_game/load_stage_data/load_meowth_bonus.asm @@ -1,6 +1,6 @@ _LoadStageDataMeowthBonus: ; 0x24128
callba Func_142fc
- call Func_2862
+ call LoadFlippersPalette
callba Func_24fa3
call Func_24516
callba LoadTimerGraphics
diff --git a/engine/pinball_game/load_stage_data/load_mewtwo_bonus.asm b/engine/pinball_game/load_stage_data/load_mewtwo_bonus.asm index 567576a..9c89fb6 100644 --- a/engine/pinball_game/load_stage_data/load_mewtwo_bonus.asm +++ b/engine/pinball_game/load_stage_data/load_mewtwo_bonus.asm @@ -1,6 +1,6 @@ _LoadStageDataMewtwoBonus: ; 0x19310
callba Func_142fc
- call Func_2862
+ call LoadFlippersPalette
callba LoadTimerGraphics
ld a, [wd7c1]
and a
diff --git a/engine/pinball_game/load_stage_data/load_seel_bonus.asm b/engine/pinball_game/load_stage_data/load_seel_bonus.asm index 45dcf75..ab3fca4 100644 --- a/engine/pinball_game/load_stage_data/load_seel_bonus.asm +++ b/engine/pinball_game/load_stage_data/load_seel_bonus.asm @@ -1,6 +1,6 @@ _LoadStageDataSeelBonus: ; 0x25b97
callba Func_142fc
- call Func_2862
+ call LoadFlippersPalette
callba Func_262f4
call Func_25d0e
callba LoadTimerGraphics
diff --git a/engine/pinball_game/object_collision/diglett_bonus_resolve_collision.asm b/engine/pinball_game/object_collision/diglett_bonus_resolve_collision.asm index 902fd69..3e1b663 100644 --- a/engine/pinball_game/object_collision/diglett_bonus_resolve_collision.asm +++ b/engine/pinball_game/object_collision/diglett_bonus_resolve_collision.asm @@ -683,8 +683,8 @@ Func_1ab30: ; 0x1ab30 lb de, $4b, $2a
call PlaySoundEffect
ld a, $1
- ld [wd7be], a
- call Func_2862
+ ld [wFlippersDisabled], a
+ call LoadFlippersPalette
ld hl, Data_1ac56
jr asm_1ac2f
diff --git a/engine/pinball_game/object_collision/gengar_bonus_resolve_collision.asm b/engine/pinball_game/object_collision/gengar_bonus_resolve_collision.asm index 69dac96..9aa99c3 100644 --- a/engine/pinball_game/object_collision/gengar_bonus_resolve_collision.asm +++ b/engine/pinball_game/object_collision/gengar_bonus_resolve_collision.asm @@ -11,8 +11,8 @@ ResolveGengarBonusGameObjectCollisions: ; 0x18377 xor a
ld [wTimeRanOut], a
ld a, $1
- ld [wd7be], a
- call Func_2862
+ ld [wFlippersDisabled], a
+ call LoadFlippersPalette
callba StopTimer
ld a, [wd6a2]
cp $5
@@ -176,7 +176,7 @@ Func_18464: ; 0x18464 jr z, .asm_184d5
xor a
ld [wd657], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr nz, .asm_184d5
ld a, [wd658]
@@ -424,7 +424,7 @@ Func_1860b: ; 0x1860b jr z, .asm_1867c
xor a
ld [wd67c], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr nz, .asm_1867c
ld a, [wd67d]
@@ -674,7 +674,7 @@ Func_187b1: ; 0x187b1 jp z, .asm_1885d
xor a
ld [wd696], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jp nz, .asm_1885d
ld a, [wd697]
@@ -718,8 +718,8 @@ Func_187b1: ; 0x187b1 ld a, $3
ld [de], a
ld a, $1
- ld [wd7be], a
- call Func_2862
+ ld [wFlippersDisabled], a
+ call LoadFlippersPalette
callba StopTimer
ld de, $0000
call PlaySong
@@ -1423,7 +1423,7 @@ Func_18d34: ; 0x18d34 jr z, .asm_18d71
xor a
ld [wWhichGravestone], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr nz, .asm_18d71
ld bc, OneHundredPoints
diff --git a/engine/pinball_game/object_collision/meowth_bonus_resolve_collision.asm b/engine/pinball_game/object_collision/meowth_bonus_resolve_collision.asm index fe9b7a9..1c7e194 100644 --- a/engine/pinball_game/object_collision/meowth_bonus_resolve_collision.asm +++ b/engine/pinball_game/object_collision/meowth_bonus_resolve_collision.asm @@ -230,8 +230,8 @@ ResolveMeowthBonusGameObjectCollisions: ; 0x2442a xor a
ld [wTimeRanOut], a
ld a, $1
- ld [wd7be], a
- call Func_2862
+ ld [wFlippersDisabled], a
+ call LoadFlippersPalette
callba StopTimer
ld a, $1
ld [wd713], a
diff --git a/engine/pinball_game/object_collision/mewtwo_bonus_resolve_collision.asm b/engine/pinball_game/object_collision/mewtwo_bonus_resolve_collision.asm index 0d8dd5a..1e1a925 100644 --- a/engine/pinball_game/object_collision/mewtwo_bonus_resolve_collision.asm +++ b/engine/pinball_game/object_collision/mewtwo_bonus_resolve_collision.asm @@ -9,8 +9,8 @@ ResolveMewtwoBonusGameObjectCollisions: ; 0x19451 xor a
ld [wTimeRanOut], a
ld a, $1
- ld [wd7be], a
- call Func_2862
+ ld [wFlippersDisabled], a
+ call LoadFlippersPalette
callba StopTimer
ld a, [wd6b1]
cp $8
@@ -170,7 +170,7 @@ Func_19531: ; 0x19531 jr z, .asm_195a2
xor a
ld [wd6aa], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr nz, .asm_195a2
ld a, [wd6af]
@@ -204,8 +204,8 @@ Func_19531: ; 0x19531 ld de, wd6ae
call Func_19679
ld a, $1
- ld [wd7be], a
- call Func_2862
+ ld [wFlippersDisabled], a
+ call LoadFlippersPalette
callba StopTimer
ld de, $0000
call PlaySong
@@ -411,7 +411,7 @@ Func_19701: ; 0x19701 jr z, .asm_19742
xor a
ld [wd6b4], a
- ld a, [wd7be]
+ ld a, [wFlippersDisabled]
and a
jr nz, .asm_19742
ld a, [wd6b5]
diff --git a/engine/pinball_game/object_collision/seel_bonus_resolve_collision.asm b/engine/pinball_game/object_collision/seel_bonus_resolve_collision.asm index a545eca..4eb7406 100644 --- a/engine/pinball_game/object_collision/seel_bonus_resolve_collision.asm +++ b/engine/pinball_game/object_collision/seel_bonus_resolve_collision.asm @@ -45,8 +45,8 @@ ResolveSeelBonusGameObjectCollisions: ; 0x25c5a xor a
ld [wTimeRanOut], a
ld a, $1
- ld [wd7be], a
- call Func_2862
+ ld [wFlippersDisabled], a
+ call LoadFlippersPalette
callba StopTimer
ld a, $3
ld [wd791], a
diff --git a/engine/pinball_game/stage_init/init_blue_field.asm b/engine/pinball_game/stage_init/init_blue_field.asm index ed624c5..24730dc 100644 --- a/engine/pinball_game/stage_init/init_blue_field.asm +++ b/engine/pinball_game/stage_init/init_blue_field.asm @@ -20,7 +20,7 @@ InitBlueField: ; 0x1c000 ld [hli], a ; wNumPokeballs
ld [hli], a ; wPokeballBlinkingCounter
ld [wDisableHorizontalScrollForBallStart], a
- ld [wd7be], a
+ ld [wFlippersDisabled], a
ld [wCurrentMap], a ; PALLET_TOWN
ld a, $1
ld [wd49d], a
diff --git a/engine/pinball_game/stage_init/init_red_field.asm b/engine/pinball_game/stage_init/init_red_field.asm index 82778c3..fe98569 100644 --- a/engine/pinball_game/stage_init/init_red_field.asm +++ b/engine/pinball_game/stage_init/init_red_field.asm @@ -20,7 +20,7 @@ InitRedField: ; 0x30000 ld [hli], a ; wNumPokeballs
ld [hli], a ; wPokeballBlinkingCounter
ld [wDisableHorizontalScrollForBallStart], a
- ld [wd7be], a
+ ld [wFlippersDisabled], a
ld [wCurrentMap], a ; PALLET_TOWN
ld a, $1
ld [wd49d], a
@@ -151,8 +151,8 @@ Start: ; 0x150 call ResetRNG xor a ld [wBootCheck], a - ld a, BANK(Func_1ffc) - ld hl, Func_1ffc + ld a, BANK(Main) + ld hl, Main call BankSwitchSimple Func_23b: ; 0x23b ld a, [hGameBoyColorFlag] @@ -243,7 +243,7 @@ SoftReset: xor a ld [wBootCheck], a ld a, $0 - ld hl, Func_1ffc + ld hl, Main call BankSwitchSimple ; fallthrough @@ -2076,7 +2076,8 @@ asm_1fca pop bc ret -Func_1ffc: ; 0x1ffc +Main: ; 0x1ffc +; This is the main game loop. ld a, $b ld [wd806], a ld a, $4 @@ -2116,36 +2117,15 @@ DoScreenLogic: ; 0x2043 ld a, [wCurrentScreen] call CallInFollowingTable CallTable_2049: ; 0x2049 -; First two bytes is function pointer. -; Third byte is bank of function. -; Fourth byte seems to be unused. - ; SCREEN_SELECT_GAMEBOY_TARGET - padded_dab HandleSelectGameboyTargetMenu - - ; SCREEN_ERASE_ALL_DATA - padded_dab HandleEraseAllDataMenu - - ; SCREEN_COPYRIGHT - padded_dab HandleCopyrightScreen - - ; SCREEN_TITLESCREEN - padded_dab HandleTitlescreen - - ; SCREEN_PINBALL_GAME - padded_dab HandlePinballGame - - ; SCREEN_POKEDEX - padded_dab HandlePokedexScreen - - ; SCREEN_OPTIONS - padded_dab HandleOptionsScreen - - ; SCREEN_HIGH_SCORES - padded_dab HandleHighScoresScreen - - ; SCREEN_FIELD_SELECT - padded_dab HandleFieldSelectScreen - ; end of call table + padded_dab HandleSelectGameboyTargetMenu ; SCREEN_SELECT_GAMEBOY_TARGET + padded_dab HandleEraseAllDataMenu ; SCREEN_ERASE_ALL_DATA + padded_dab HandleCopyrightScreen ; SCREEN_COPYRIGHT + padded_dab HandleTitlescreen ; SCREEN_TITLESCREEN + padded_dab HandlePinballGame ; SCREEN_PINBALL_GAME + padded_dab HandlePokedexScreen ; SCREEN_POKEDEX + padded_dab HandleOptionsScreen ; SCREEN_OPTIONS + padded_dab HandleHighScoresScreen ; SCREEN_HIGH_SCORES + padded_dab HandleFieldSelectScreen ; SCREEN_FIELD_SELECT LoadDexVWFCharacter: ; 0x206d ; Loads a single variable-width-font character used in various parts of the Pokedex screen. @@ -3166,38 +3146,42 @@ SubTileXPos_CollisionData7: ; 0x268e INCLUDE "data/sine_table.asm" INCLUDE "engine/pinball_game/object_collision/object_collision.asm" -Func_2862: ; 0x2862 - ld a, [wd7be] +LoadFlippersPalette: ; 0x2862 +; Loads the flippers' color palette. +; When the flippers are active, they are white/blue. When disabled at the end of a Bonus Stage, they turn Red. + ld a, [wFlippersDisabled] and a - jr nz, .asm_287c + jr nz, .flippersDisabled ld a, [hGameBoyColorFlag] and a - jr z, .asm_287b - ld a, $0 - ld hl, Data_2890 + jr z, .done + ld a, Bank(ActiveFlippersPalette) + ld hl, ActiveFlippersPalette ld de, $0052 ld bc, $0004 call FarCopyPalettes -.asm_287b +.done ret -.asm_287c +.flippersDisabled ld a, [hGameBoyColorFlag] and a - jr z, .asm_288f - ld a, $0 - ld hl, Data_2894 + jr z, .done2 + ld a, Bank(DisabledFlippersPalette) + ld hl, DisabledFlippersPalette ld de, $0052 ld bc, $0004 call FarCopyPalettes -.asm_288f +.done2 ret -Data_2890: +ActiveFlippersPalette: +; The white/blue color when the flippers are active. RGB 31, 31, 31 RGB 21, 21, 27 -Data_2894: +DisabledFlippersPalette: +; The reddish colors when the flippers are disabled at the end of a Bonus Stage. RGB 27, 10, 10 RGB 20, 04, 04 @@ -3206,405 +3190,10 @@ CatchBarTiles: db $80, $AE, $AF, $B0, $B1, $B2, $B3, $80 CatchBarTilesEnd: -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 - +INCLUDE "home/animation.asm" INCLUDE "home/text.asm" - -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 - -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, Data_372d - 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 - -Data_372d: - dw -1 ; no tilt - dw TiltLeftOnlyForce - dw TiltRightOnlyForce - dw -1 ; left + right (cancel) - dw TiltUpOnlyForce - dw TiltUpLeftForce - dw TiltUpRightForce - dw TiltUpOnlyForce +INCLUDE "home/bcd.asm" +INCLUDE "home/tilt.asm" SECTION "bank0.2", ROM0 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
@@ -1778,7 +1778,9 @@ wFlipperXForce:: ; 0xd7ba wFlipperYForce:: ; 0xd7bc dw -wd7be:: ; 0xd7be +wFlippersDisabled:: ; 0xd7be +; 0 = enabled +; 1 = disabled ds $1 wStageSong:: ; 0xd7bf |