pokecrystal-board/engine/events/mom.asm

542 lines
8.1 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
BankOfMom:
ldh a, [hInMenu]
push af
ld a, $1
ldh [hInMenu], a
xor a
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
2015-12-18 17:07:09 -08:00
.loop
2015-10-24 16:49:19 -07:00
ld a, [wJumptableIndex]
bit 7, a
2015-12-18 17:07:09 -08:00
jr nz, .done
call .RunJumptable
jr .loop
2015-12-18 17:07:09 -08:00
.done
pop af
ldh [hInMenu], a
ret
2018-06-24 07:09:41 -07:00
.RunJumptable:
jumptable .dw, wJumptableIndex
2018-06-24 07:09:41 -07:00
.dw
2015-12-26 18:59:03 -08:00
dw .CheckIfBankInitialized
dw .InitializeBank
dw .IsThisAboutYourCoins
2015-12-26 18:59:03 -08:00
dw .AccessBankOfMom
dw .StoreCoins
dw .TakeCoins
dw .StopOrStartSavingCoins
2015-12-26 18:59:03 -08:00
dw .JustDoWhatYouCan
dw .AskDST
2018-06-24 07:09:41 -07:00
.CheckIfBankInitialized:
ld a, [wMomSavingCoins]
2018-01-22 10:57:44 -08:00
bit MOM_ACTIVE_F, a
jr nz, .savingcoinsalready
2018-01-22 10:57:44 -08:00
set MOM_ACTIVE_F, a
ld [wMomSavingCoins], a
ld a, $1
2015-10-19 13:49:29 -07:00
jr .done_0
.savingcoinsalready
ld a, $2
2015-10-19 13:49:29 -07:00
.done_0
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
2018-06-24 07:09:41 -07:00
.InitializeBank:
ld hl, MomLeavingText1
call PrintText1bpp
call YesNoBox
jr c, .DontSaveCoins
ld hl, MomLeavingText2
call PrintText1bpp
ld a, (1 << MOM_ACTIVE_F) | (1 << MOM_SAVING_SOME_COINS_F)
2015-10-19 13:49:29 -07:00
jr .done_1
.DontSaveCoins:
2018-01-22 10:57:44 -08:00
ld a, 1 << MOM_ACTIVE_F
2015-10-19 13:49:29 -07:00
.done_1
ld [wMomSavingCoins], a
ld hl, MomLeavingText3
call PrintText1bpp
ld a, $8
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
.IsThisAboutYourCoins:
ld hl, MomIsThisAboutYourCoinsText
call PrintText1bpp
call YesNoBox
2015-10-19 13:49:29 -07:00
jr c, .nope
ld a, $3
2015-10-19 13:49:29 -07:00
jr .done_2
2015-10-19 13:49:29 -07:00
.nope
ld a, $7
2015-10-19 13:49:29 -07:00
.done_2
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
2018-06-24 07:09:41 -07:00
.AccessBankOfMom:
ld hl, MomBankWhatDoYouWantToDoText
call PrintText1bpp
call LoadStandardMenuHeader
ld hl, BankOfMom_MenuHeader
call CopyMenuHeader
2015-12-15 15:59:49 -08:00
call VerticalMenu
call CloseWindow
2015-10-19 13:49:29 -07:00
jr c, .cancel
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
cp $1
2015-10-19 13:49:29 -07:00
jr z, .withdraw
cp $2
2015-10-19 13:49:29 -07:00
jr z, .deposit
cp $3
2015-10-19 13:49:29 -07:00
jr z, .stopsaving
2015-10-19 13:49:29 -07:00
.cancel
ld a, $7
2015-10-19 13:49:29 -07:00
jr .done_3
2015-10-19 13:49:29 -07:00
.withdraw
ld a, $5
2015-10-19 13:49:29 -07:00
jr .done_3
2015-10-19 13:49:29 -07:00
.deposit
ld a, $4
2015-10-19 13:49:29 -07:00
jr .done_3
2015-10-19 13:49:29 -07:00
.stopsaving
ld a, $6
2015-10-19 13:49:29 -07:00
.done_3
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
.StoreCoins:
ld hl, MomStoreCoinsText
call PrintText1bpp
xor a
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld [hli], a
ld [hli], a
ld [hl], a
2018-01-22 10:57:44 -08:00
ld a, 5
2018-01-11 12:36:11 -08:00
ld [wMomBankDigitCursorPosition], a
call LoadStandardMenuHeader
2016-05-10 09:59:34 -07:00
call Mom_SetUpDepositMenu
call Mom_Wait10Frames
call Mom_WithdrawDepositMenuJoypad
call CloseWindow
2015-10-19 13:49:29 -07:00
jr c, .CancelDeposit
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld a, [hli]
or [hl]
inc hl
or [hl]
2015-10-19 13:49:29 -07:00
jr z, .CancelDeposit
ld de, wCoins
2018-01-23 14:39:09 -08:00
ld bc, wStringBuffer2
farcall CompareCoins
jr c, .InsufficientFundsInWallet
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld de, wStringBuffer2 + 3
2015-10-19 13:49:29 -07:00
ld bc, 3
call CopyBytes
ld bc, wMomsCoins
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
farcall GiveCoins
jr c, .NotEnoughRoomInBank
2018-01-23 14:39:09 -08:00
ld bc, wStringBuffer2 + 3
ld de, wCoins
farcall TakeCoins
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld de, wMomsCoins
2015-10-19 13:49:29 -07:00
ld bc, 3
call CopyBytes
ld de, SFX_TRANSACTION
call PlaySFX
call WaitSFX
ld hl, MomStoredCoinsText
call PrintText1bpp
ld a, $8
2015-10-19 13:49:29 -07:00
jr .done_4
.InsufficientFundsInWallet:
ld hl, MomInsufficientFundsInWalletText
call PrintText1bpp
ret
.NotEnoughRoomInBank:
ld hl, MomNotEnoughRoomInBankText
call PrintText1bpp
ret
.CancelDeposit:
ld a, $7
2015-10-19 13:49:29 -07:00
.done_4
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
.TakeCoins:
ld hl, MomTakeCoinsText
call PrintText1bpp
xor a
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld [hli], a
ld [hli], a
ld [hl], a
2018-01-22 10:57:44 -08:00
ld a, 5
2018-01-11 12:36:11 -08:00
ld [wMomBankDigitCursorPosition], a
call LoadStandardMenuHeader
2016-05-10 09:59:34 -07:00
call Mom_SetUpWithdrawMenu
call Mom_Wait10Frames
call Mom_WithdrawDepositMenuJoypad
call CloseWindow
2015-10-19 13:49:29 -07:00
jr c, .CancelWithdraw
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld a, [hli]
or [hl]
inc hl
or [hl]
2015-10-19 13:49:29 -07:00
jr z, .CancelWithdraw
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld de, wStringBuffer2 + 3
ld bc, 3
call CopyBytes
ld de, wMomsCoins
2018-01-23 14:39:09 -08:00
ld bc, wStringBuffer2
farcall CompareCoins
2015-10-19 13:49:29 -07:00
jr c, .InsufficientFundsInBank
ld bc, wCoins
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
farcall GiveCoins
2015-10-19 13:49:29 -07:00
jr c, .NotEnoughRoomInWallet
2018-01-23 14:39:09 -08:00
ld bc, wStringBuffer2 + 3
ld de, wMomsCoins
farcall TakeCoins
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer2
ld de, wCoins
ld bc, 3
call CopyBytes
ld de, SFX_TRANSACTION
call PlaySFX
call WaitSFX
ld hl, MomTakenCoinsText
call PrintText1bpp
ld a, $8
2015-10-19 13:49:29 -07:00
jr .done_5
.InsufficientFundsInBank:
ld hl, MomHaventSavedThatMuchText
call PrintText1bpp
ret
.NotEnoughRoomInWallet:
ld hl, MomNotEnoughRoomInWalletText
call PrintText1bpp
ret
.CancelWithdraw:
2015-10-19 13:49:29 -07:00
ld a, $7
2015-10-19 13:49:29 -07:00
.done_5
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
.StopOrStartSavingCoins:
ld hl, MomSaveCoinsText
call PrintText1bpp
call YesNoBox
jr c, .StopSavingCoins
ld a, (1 << MOM_ACTIVE_F) | (1 << MOM_SAVING_SOME_COINS_F)
ld [wMomSavingCoins], a
ld hl, MomStartSavingCoinsText
call PrintText1bpp
ld a, $8
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
.StopSavingCoins:
2018-01-22 10:57:44 -08:00
ld a, 1 << MOM_ACTIVE_F
ld [wMomSavingCoins], a
ld a, $7
2015-10-24 16:49:19 -07:00
ld [wJumptableIndex], a
ret
.JustDoWhatYouCan:
ld hl, MomJustDoWhatYouCanText
call PrintText1bpp
.AskDST:
2015-10-24 16:49:19 -07:00
ld hl, wJumptableIndex
set 7, [hl]
ret
2018-06-24 07:09:41 -07:00
Mom_SetUpWithdrawMenu:
2016-05-10 09:59:34 -07:00
ld de, Mon_WithdrawString
jr Mom_ContinueMenuSetup
2018-06-24 07:09:41 -07:00
Mom_SetUpDepositMenu:
2016-05-10 09:59:34 -07:00
ld de, Mom_DepositString
2018-06-24 07:09:41 -07:00
Mom_ContinueMenuSetup:
push de
xor a
ldh [hBGMapMode], a
hlcoord 0, 0
lb bc, 6, 18
call Textbox1bpp
hlcoord 1, 2
2016-05-10 09:59:34 -07:00
ld de, Mom_SavedString
call PlaceString
hlcoord 12, 2
ld de, wMomsCoins
lb bc, PRINTNUM_COINS | 3, 6
call PrintNum
hlcoord 1, 4
2016-05-10 09:59:34 -07:00
ld de, Mom_HeldString
call PlaceString
hlcoord 12, 4
ld de, wCoins
lb bc, PRINTNUM_COINS | 3, 6
call PrintNum
hlcoord 1, 6
pop de
call PlaceString
hlcoord 12, 6
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
lb bc, PRINTNUM_COINS | PRINTNUM_LEADINGZEROS | 3, 6
call PrintNum
call UpdateSprites
call CopyTilemapAtOnce
ret
2018-06-24 07:09:41 -07:00
Mom_Wait10Frames:
ld c, 10
call DelayFrames
ret
2018-06-24 07:09:41 -07:00
Mom_WithdrawDepositMenuJoypad:
.loop
call JoyTextDelay
ld hl, hJoyPressed
ld a, [hl]
and B_BUTTON
jr nz, .pressedB
ld a, [hl]
and A_BUTTON
jr nz, .pressedA
call .dpadaction
xor a
ldh [hBGMapMode], a
hlcoord 12, 6
ld bc, 7
ld a, " "
call ByteFill
hlcoord 12, 6
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
lb bc, PRINTNUM_COINS | PRINTNUM_LEADINGZEROS | 3, 6
call PrintNum
ldh a, [hVBlankCounter]
and $10
jr nz, .skip
hlcoord 13, 6
ld a, [wMomBankDigitCursorPosition]
ld c, a
ld b, 0
add hl, bc
ld [hl], " "
.skip
call WaitBGMap
jr .loop
.pressedB
scf
ret
.pressedA
and a
ret
2016-05-10 09:59:34 -07:00
.dpadaction
ld hl, hJoyLast
ld a, [hl]
and D_UP
jr nz, .incrementdigit
ld a, [hl]
and D_DOWN
jr nz, .decrementdigit
ld a, [hl]
and D_LEFT
jr nz, .movecursorleft
ld a, [hl]
and D_RIGHT
jr nz, .movecursorright
and a
ret
.movecursorleft
ld hl, wMomBankDigitCursorPosition
ld a, [hl]
and a
ret z
dec [hl]
ret
.movecursorright
ld hl, wMomBankDigitCursorPosition
ld a, [hl]
cp 5
ret nc
inc [hl]
ret
.incrementdigit
ld hl, .DigitQuantities
call .getdigitquantity
ld c, l
ld b, h
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
farcall GiveCoins
ret
.decrementdigit
ld hl, .DigitQuantities
call .getdigitquantity
ld c, l
ld b, h
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
farcall TakeCoins
ret
2016-05-10 09:59:34 -07:00
.getdigitquantity
ld a, [wMomBankDigitCursorPosition]
push de
ld e, a
ld d, 0
add hl, de
add hl, de
add hl, de
pop de
ret
2018-06-24 07:09:41 -07:00
.DigitQuantities:
dt 100000
dt 10000
dt 1000
dt 100
dt 10
dt 1
dt 100000
dt 10000
dt 1000
dt 100
dt 10
dt 1
dt 900000
dt 90000
dt 9000
dt 900
dt 90
dt 9
MomLeavingText1:
text_far _MomLeavingText1
text_end
MomLeavingText2:
text_far _MomLeavingText2
text_end
MomLeavingText3:
text_far _MomLeavingText3
text_end
MomIsThisAboutYourCoinsText:
text_far _MomIsThisAboutYourCoinsText
text_end
MomBankWhatDoYouWantToDoText:
text_far _MomBankWhatDoYouWantToDoText
text_end
MomStoreCoinsText:
text_far _MomStoreCoinsText
text_end
MomTakeCoinsText:
text_far _MomTakeCoinsText
text_end
MomSaveCoinsText:
text_far _MomSaveCoinsText
text_end
MomHaventSavedThatMuchText:
text_far _MomHaventSavedThatMuchText
text_end
MomNotEnoughRoomInWalletText:
text_far _MomNotEnoughRoomInWalletText
text_end
MomInsufficientFundsInWalletText:
text_far _MomInsufficientFundsInWalletText
text_end
MomNotEnoughRoomInBankText:
text_far _MomNotEnoughRoomInBankText
text_end
MomStartSavingCoinsText:
text_far _MomStartSavingCoinsText
text_end
MomStoredCoinsText:
text_far _MomStoredCoinsText
text_end
MomTakenCoinsText:
text_far _MomTakenCoinsText
text_end
MomJustDoWhatYouCanText:
text_far _MomJustDoWhatYouCanText
text_end
2018-06-24 07:09:41 -07:00
Mom_SavedString:
db "SAVED@"
2018-06-24 07:09:41 -07:00
Mon_WithdrawString:
db "WITHDRAW@"
2018-06-24 07:09:41 -07:00
Mom_DepositString:
db "DEPOSIT@"
2018-06-24 07:09:41 -07:00
Mom_HeldString:
db "HELD@"
BankOfMom_MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, 10, 10
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR ; flags
db 4 ; items
db "GET@"
db "SAVE@"
db "CHANGE@"
db "CANCEL@"