pokecrystal/engine/events/mom.asm

675 lines
10 KiB
NASM
Raw Normal View History

2018-06-24 14:09:41 +00:00
BankOfMom:
ldh a, [hInMenu]
push af
ld a, $1
ldh [hInMenu], a
xor a
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
2015-12-19 01:07:09 +00:00
.loop
2015-10-24 23:49:19 +00:00
ld a, [wJumptableIndex]
bit 7, a
2015-12-19 01:07:09 +00:00
jr nz, .done
call .RunJumptable
jr .loop
2015-12-19 01:07:09 +00:00
.done
pop af
ldh [hInMenu], a
ret
2018-06-24 14:09:41 +00:00
.RunJumptable:
2015-10-24 23:49:19 +00:00
ld a, [wJumptableIndex]
ld e, a
ld d, 0
2015-12-27 02:59:03 +00:00
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2018-06-24 14:09:41 +00:00
.dw
2015-12-27 02:59:03 +00:00
dw .CheckIfBankInitialized
dw .InitializeBank
dw .IsThisAboutYourMoney
dw .AccessBankOfMom
dw .StoreMoney
dw .TakeMoney
dw .StopOrStartSavingMoney
dw .JustDoWhatYouCan
dw .AskDST
2018-06-24 14:09:41 +00:00
.CheckIfBankInitialized:
2015-11-13 05:49:27 +00:00
ld a, [wMomSavingMoney]
2018-01-22 18:57:44 +00:00
bit MOM_ACTIVE_F, a
2015-10-19 20:49:29 +00:00
jr nz, .savingmoneyalready
2018-01-22 18:57:44 +00:00
set MOM_ACTIVE_F, a
2015-11-13 05:49:27 +00:00
ld [wMomSavingMoney], a
ld a, $1
2015-10-19 20:49:29 +00:00
jr .done_0
2015-10-19 20:49:29 +00:00
.savingmoneyalready
ld a, $2
2015-10-19 20:49:29 +00:00
.done_0
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
2018-06-24 14:09:41 +00:00
.InitializeBank:
ld hl, MomLeavingText1
call PrintText
call YesNoBox
2015-10-19 20:49:29 +00:00
jr c, .DontSaveMoney
ld hl, MomLeavingText2
call PrintText
2018-01-22 18:57:44 +00:00
ld a, (1 << MOM_ACTIVE_F) | (1 << MOM_SAVING_SOME_MONEY_F)
2015-10-19 20:49:29 +00:00
jr .done_1
.DontSaveMoney:
2018-01-22 18:57:44 +00:00
ld a, 1 << MOM_ACTIVE_F
2015-10-19 20:49:29 +00:00
.done_1
2015-11-13 05:49:27 +00:00
ld [wMomSavingMoney], a
ld hl, MomLeavingText3
call PrintText
ld a, $8
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
2018-06-24 14:09:41 +00:00
.IsThisAboutYourMoney:
ld hl, MomIsThisAboutYourMoneyText
call PrintText
call YesNoBox
2015-10-19 20:49:29 +00:00
jr c, .nope
ld a, $3
2015-10-19 20:49:29 +00:00
jr .done_2
2015-10-19 20:49:29 +00:00
.nope
call DSTChecks
ld a, $7
2015-10-19 20:49:29 +00:00
.done_2
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
2018-06-24 14:09:41 +00:00
.AccessBankOfMom:
ld hl, MomBankWhatDoYouWantToDoText
call PrintText
call LoadStandardMenuHeader
ld hl, MenuHeader_0x166b5
call CopyMenuHeader
2015-12-15 23:59:49 +00:00
call VerticalMenu
call CloseWindow
2015-10-19 20:49:29 +00:00
jr c, .cancel
2015-12-15 23:59:49 +00:00
ld a, [wMenuCursorY]
cp $1
2015-10-19 20:49:29 +00:00
jr z, .withdraw
cp $2
2015-10-19 20:49:29 +00:00
jr z, .deposit
cp $3
2015-10-19 20:49:29 +00:00
jr z, .stopsaving
2015-10-19 20:49:29 +00:00
.cancel
ld a, $7
2015-10-19 20:49:29 +00:00
jr .done_3
2015-10-19 20:49:29 +00:00
.withdraw
ld a, $5
2015-10-19 20:49:29 +00:00
jr .done_3
2015-10-19 20:49:29 +00:00
.deposit
ld a, $4
2015-10-19 20:49:29 +00:00
jr .done_3
2015-10-19 20:49:29 +00:00
.stopsaving
ld a, $6
2015-10-19 20:49:29 +00:00
.done_3
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
2018-06-24 14:09:41 +00:00
.StoreMoney:
ld hl, MomStoreMoneyText
call PrintText
xor a
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
ld [hli], a
ld [hli], a
ld [hl], a
2018-01-22 18:57:44 +00:00
ld a, 5
2018-01-11 20:36:11 +00:00
ld [wMomBankDigitCursorPosition], a
call LoadStandardMenuHeader
2016-05-10 16:59:34 +00:00
call Mom_SetUpDepositMenu
call Mom_Wait10Frames
call Mom_WithdrawDepositMenuJoypad
call CloseWindow
2015-10-19 20:49:29 +00:00
jr c, .CancelDeposit
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
ld a, [hli]
or [hl]
inc hl
or [hl]
2015-10-19 20:49:29 +00:00
jr z, .CancelDeposit
2018-01-23 22:39:09 +00:00
ld de, wMoney
ld bc, wStringBuffer2
2017-12-24 17:47:30 +00:00
farcall CompareMoney
jr c, .InsufficientFundsInWallet
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
ld de, wStringBuffer2 + 3
2015-10-19 20:49:29 +00:00
ld bc, 3
call CopyBytes
2015-11-13 05:49:27 +00:00
ld bc, wMomsMoney
2018-01-23 22:39:09 +00:00
ld de, wStringBuffer2
2017-12-24 17:47:30 +00:00
farcall GiveMoney
jr c, .NotEnoughRoomInBank
2018-01-23 22:39:09 +00:00
ld bc, wStringBuffer2 + 3
ld de, wMoney
2017-12-24 17:47:30 +00:00
farcall TakeMoney
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
2015-11-13 05:49:27 +00:00
ld de, wMomsMoney
2015-10-19 20:49:29 +00:00
ld bc, 3
call CopyBytes
ld de, SFX_TRANSACTION
call PlaySFX
call WaitSFX
ld hl, MomStoredMoneyText
call PrintText
ld a, $8
2015-10-19 20:49:29 +00:00
jr .done_4
.InsufficientFundsInWallet:
ld hl, MomInsufficientFundsInWalletText
call PrintText
ret
.NotEnoughRoomInBank:
ld hl, MomNotEnoughRoomInBankText
call PrintText
ret
.CancelDeposit:
ld a, $7
2015-10-19 20:49:29 +00:00
.done_4
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
2018-06-24 14:09:41 +00:00
.TakeMoney:
ld hl, MomTakeMoneyText
call PrintText
xor a
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
ld [hli], a
ld [hli], a
ld [hl], a
2018-01-22 18:57:44 +00:00
ld a, 5
2018-01-11 20:36:11 +00:00
ld [wMomBankDigitCursorPosition], a
call LoadStandardMenuHeader
2016-05-10 16:59:34 +00:00
call Mom_SetUpWithdrawMenu
call Mom_Wait10Frames
call Mom_WithdrawDepositMenuJoypad
call CloseWindow
2015-10-19 20:49:29 +00:00
jr c, .CancelWithdraw
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
ld a, [hli]
or [hl]
inc hl
or [hl]
2015-10-19 20:49:29 +00:00
jr z, .CancelWithdraw
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
ld de, wStringBuffer2 + 3
ld bc, 3
call CopyBytes
2015-11-13 05:49:27 +00:00
ld de, wMomsMoney
2018-01-23 22:39:09 +00:00
ld bc, wStringBuffer2
2017-12-24 17:47:30 +00:00
farcall CompareMoney
2015-10-19 20:49:29 +00:00
jr c, .InsufficientFundsInBank
2018-01-23 22:39:09 +00:00
ld bc, wMoney
ld de, wStringBuffer2
2017-12-24 17:47:30 +00:00
farcall GiveMoney
2015-10-19 20:49:29 +00:00
jr c, .NotEnoughRoomInWallet
2018-01-23 22:39:09 +00:00
ld bc, wStringBuffer2 + 3
2015-11-13 05:49:27 +00:00
ld de, wMomsMoney
2017-12-24 17:47:30 +00:00
farcall TakeMoney
2018-01-23 22:39:09 +00:00
ld hl, wStringBuffer2
ld de, wMoney
ld bc, 3
call CopyBytes
ld de, SFX_TRANSACTION
call PlaySFX
call WaitSFX
ld hl, MomTakenMoneyText
call PrintText
ld a, $8
2015-10-19 20:49:29 +00:00
jr .done_5
.InsufficientFundsInBank:
ld hl, MomHaventSavedThatMuchText
call PrintText
ret
.NotEnoughRoomInWallet:
ld hl, MomNotEnoughRoomInWalletText
call PrintText
ret
.CancelWithdraw:
2015-10-19 20:49:29 +00:00
ld a, $7
2015-10-19 20:49:29 +00:00
.done_5
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
2018-06-24 14:09:41 +00:00
.StopOrStartSavingMoney:
ld hl, MomSaveMoneyText
call PrintText
call YesNoBox
2015-10-19 20:49:29 +00:00
jr c, .StopSavingMoney
2018-01-22 18:57:44 +00:00
ld a, (1 << MOM_ACTIVE_F) | (1 << MOM_SAVING_SOME_MONEY_F)
2015-11-13 05:49:27 +00:00
ld [wMomSavingMoney], a
ld hl, MomStartSavingMoneyText
call PrintText
ld a, $8
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
.StopSavingMoney:
2018-01-22 18:57:44 +00:00
ld a, 1 << MOM_ACTIVE_F
2015-11-13 05:49:27 +00:00
ld [wMomSavingMoney], a
ld a, $7
2015-10-24 23:49:19 +00:00
ld [wJumptableIndex], a
ret
.JustDoWhatYouCan:
ld hl, MomJustDoWhatYouCanText
call PrintText
.AskDST:
2015-10-24 23:49:19 +00:00
ld hl, wJumptableIndex
set 7, [hl]
ret
2018-06-24 14:09:41 +00:00
DSTChecks:
; check the time; avoid changing DST if doing so would change the current day
ld a, [wDST]
bit 7, a
ldh a, [hHours]
2015-12-19 01:07:09 +00:00
jr z, .NotDST
and a ; within one hour of 00:00?
jr z, .LostBooklet
jr .loop
.NotDST:
cp 23 ; within one hour of 23:00?
jr nz, .loop
; fallthrough
.LostBooklet:
2015-12-19 01:07:09 +00:00
call .ClearBox
bccoord 1, 14
ld hl, .TimesetAskAdjustDSTText
call PlaceHLTextAtBC
call YesNoBox
ret c
2015-12-19 01:07:09 +00:00
call .ClearBox
bccoord 1, 14
ld hl, .MomLostGearBookletText
call PlaceHLTextAtBC
ret
.loop
2015-12-19 01:07:09 +00:00
call .ClearBox
bccoord 1, 14
ld a, [wDST]
bit 7, a
2015-12-19 01:07:09 +00:00
jr z, .SetDST
ld hl, .TimesetAskNotDSTText
call PlaceHLTextAtBC
call YesNoBox
ret c
ld a, [wDST]
res 7, a
ld [wDST], a
2015-12-19 01:07:09 +00:00
call .SetClockBack
call .ClearBox
bccoord 1, 14
ld hl, .TimesetNotDSTText
call PlaceHLTextAtBC
ret
.SetDST:
ld hl, .TimesetAskDSTText
call PlaceHLTextAtBC
call YesNoBox
ret c
ld a, [wDST]
set 7, a
ld [wDST], a
2015-12-19 01:07:09 +00:00
call .SetClockForward
call .ClearBox
bccoord 1, 14
ld hl, .TimesetDSTText
call PlaceHLTextAtBC
ret
2018-06-24 14:09:41 +00:00
.SetClockForward:
2018-01-23 22:39:09 +00:00
ld a, [wStartHour]
add 1
sub 24
2015-12-19 01:07:09 +00:00
jr nc, .DontLoopHourForward
add 24
.DontLoopHourForward:
2018-01-23 22:39:09 +00:00
ld [wStartHour], a
ccf
2018-01-23 22:39:09 +00:00
ld a, [wStartDay]
adc 0
2018-01-23 22:39:09 +00:00
ld [wStartDay], a
ret
2018-06-24 14:09:41 +00:00
.SetClockBack:
2018-01-23 22:39:09 +00:00
ld a, [wStartHour]
sub 1
2015-12-19 01:07:09 +00:00
jr nc, .DontLoopHourBack
add 24
.DontLoopHourBack:
2018-01-23 22:39:09 +00:00
ld [wStartHour], a
ld a, [wStartDay]
sbc 0
2015-12-19 01:07:09 +00:00
jr nc, .DontLoopDayBack
add 7
.DontLoopDayBack:
2018-01-23 22:39:09 +00:00
ld [wStartDay], a
ret
2018-06-24 14:09:41 +00:00
.ClearBox:
hlcoord 1, 14
lb bc, 3, 18
call ClearBox
ret
.TimesetAskAdjustDSTText:
text_far _TimesetAskAdjustDSTText
text_end
.MomLostGearBookletText:
text_far _MomLostGearBookletText
text_end
.TimesetAskDSTText:
text_far _TimesetAskDSTText
text_end
.TimesetDSTText:
text_far _TimesetDSTText
text_end
.TimesetAskNotDSTText:
text_far _TimesetAskNotDSTText
text_end
.TimesetNotDSTText:
text_far _TimesetNotDSTText
text_end
2018-06-24 14:09:41 +00:00
Mom_SetUpWithdrawMenu:
2016-05-10 16:59:34 +00:00
ld de, Mon_WithdrawString
jr Mom_ContinueMenuSetup
2018-06-24 14:09:41 +00:00
Mom_SetUpDepositMenu:
2016-05-10 16:59:34 +00:00
ld de, Mom_DepositString
2018-06-24 14:09:41 +00:00
Mom_ContinueMenuSetup:
push de
xor a
ldh [hBGMapMode], a
hlcoord 0, 0
lb bc, 6, 18
2019-04-08 12:15:10 +00:00
call Textbox
hlcoord 1, 2
2016-05-10 16:59:34 +00:00
ld de, Mom_SavedString
call PlaceString
hlcoord 12, 2
2015-11-13 05:49:27 +00:00
ld de, wMomsMoney
lb bc, PRINTNUM_MONEY | 3, 6
call PrintNum
hlcoord 1, 4
2016-05-10 16:59:34 +00:00
ld de, Mom_HeldString
call PlaceString
hlcoord 12, 4
2018-01-23 22:39:09 +00:00
ld de, wMoney
lb bc, PRINTNUM_MONEY | 3, 6
call PrintNum
hlcoord 1, 6
pop de
call PlaceString
hlcoord 12, 6
2018-01-23 22:39:09 +00:00
ld de, wStringBuffer2
lb bc, PRINTNUM_MONEY | PRINTNUM_LEADINGZEROS | 3, 6
call PrintNum
call UpdateSprites
call CGBOnly_CopyTilemapAtOnce
ret
2018-06-24 14:09:41 +00:00
Mom_Wait10Frames:
ld c, 10
call DelayFrames
ret
2018-06-24 14:09:41 +00: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 22:39:09 +00:00
ld de, wStringBuffer2
lb bc, PRINTNUM_MONEY | 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 16:59:34 +00: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 22:39:09 +00:00
ld de, wStringBuffer2
2017-12-24 17:47:30 +00:00
farcall GiveMoney
ret
.decrementdigit
ld hl, .DigitQuantities
call .getdigitquantity
ld c, l
ld b, h
2018-01-23 22:39:09 +00:00
ld de, wStringBuffer2
2017-12-24 17:47:30 +00:00
farcall TakeMoney
ret
2016-05-10 16:59:34 +00: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 14:09:41 +00: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
MomIsThisAboutYourMoneyText:
text_far _MomIsThisAboutYourMoneyText
text_end
MomBankWhatDoYouWantToDoText:
text_far _MomBankWhatDoYouWantToDoText
text_end
MomStoreMoneyText:
text_far _MomStoreMoneyText
text_end
MomTakeMoneyText:
text_far _MomTakeMoneyText
text_end
MomSaveMoneyText:
text_far _MomSaveMoneyText
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
MomStartSavingMoneyText:
text_far _MomStartSavingMoneyText
text_end
MomStoredMoneyText:
text_far _MomStoredMoneyText
text_end
MomTakenMoneyText:
text_far _MomTakenMoneyText
text_end
MomJustDoWhatYouCanText:
text_far _MomJustDoWhatYouCanText
text_end
2018-06-24 14:09:41 +00:00
Mom_SavedString:
db "SAVED@"
2018-06-24 14:09:41 +00:00
Mon_WithdrawString:
db "WITHDRAW@"
2018-06-24 14:09:41 +00:00
Mom_DepositString:
db "DEPOSIT@"
2018-06-24 14:09:41 +00:00
Mom_HeldString:
db "HELD@"
MenuHeader_0x166b5:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, 10, 10
dw MenuData_0x166bd
db 1 ; default option
MenuData_0x166bd:
db STATICMENU_CURSOR ; flags
db 4 ; items
db "GET@"
db "SAVE@"
db "CHANGE@"
db "CANCEL@"