summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/events/pokemon_pc.asm658
-rwxr-xr-xengine/events/specials.asm2
-rwxr-xr-xengine/items/items.asm4
-rw-r--r--engine/items/mart.asm811
-rw-r--r--engine/menus/intro_menu.asm16
-rwxr-xr-xengine/overworld/time.asm6
-rw-r--r--engine/pokemon/bills_pc_top.asm14
7 files changed, 1490 insertions, 21 deletions
diff --git a/engine/events/pokemon_pc.asm b/engine/events/pokemon_pc.asm
new file mode 100644
index 00000000..e22a2ffc
--- /dev/null
+++ b/engine/events/pokemon_pc.asm
@@ -0,0 +1,658 @@
+PokemonCenterPC:
+ call PC_CheckPartyForPokemon
+ ret c
+ call PC_PlayBootSound
+ ld hl, PokecenterPCTurnOnText
+ call PC_DisplayText
+ ld hl, PokecenterPCWhoseText
+ call PC_DisplayTextWaitMenu
+ ld hl, .TopMenu
+ call LoadMenuHeader
+.loop
+ xor a
+ ldh [hBGMapMode], a
+ call .ChooseWhichPCListToUse
+ ld [wWhichIndexSet], a
+ call DoNthMenu
+ jr c, .shutdown
+ ld a, [wMenuSelection]
+ ld hl, .JumpTable
+ call MenuJumptable
+ jr nc, .loop
+
+.shutdown
+ call PC_PlayShutdownSound
+ call ExitMenu
+ call CloseWindow
+ ret
+
+.TopMenu:
+ db MENU_BACKUP_TILES | MENU_NO_CLICK_SFX ; flags
+ menu_coords 0, 0, 15, 12
+ dw .MenuData
+ db 1 ; default option
+
+.MenuData:
+ db STATICMENU_CURSOR | STATICMENU_WRAP ; flags
+ db 0 ; items
+ dw .WhichPC
+ dw PlaceNthMenuStrings
+ dw .JumpTable
+
+PCPC_PLAYERS_PC EQU 0
+PCPC_BILLS_PC EQU 1
+PCPC_OAKS_PC EQU 2
+PCPC_HALL_OF_FAME EQU 3
+PCPC_TURN_OFF EQU 4
+
+.JumpTable:
+; entries correspond to PCPC_* constants
+ dw PlayersPC, .String_PlayersPC
+ dw BillsPC, .String_BillsPC
+ dw OaksPC, .String_OaksPC
+ dw HallOfFamePC, .String_HallOfFame
+ dw TurnOffPC, .String_TurnOff
+
+.String_PlayersPC: db "<PLAYER>'s PC@"
+.String_BillsPC: db "BILL's PC@"
+.String_OaksPC: db "PROF.OAK's PC@"
+.String_HallOfFame: db "HALL OF FAME@"
+.String_TurnOff: db "TURN OFF@"
+
+.WhichPC:
+ ; before Pokédex
+ db 3
+ db PCPC_BILLS_PC
+ db PCPC_PLAYERS_PC
+ db PCPC_TURN_OFF
+ db -1 ; end
+
+ ; before Hall Of Fame
+ db 4
+ db PCPC_BILLS_PC
+ db PCPC_PLAYERS_PC
+ db PCPC_OAKS_PC
+ db PCPC_TURN_OFF
+ db -1 ; end
+
+ ; postgame
+ db 5
+ db PCPC_BILLS_PC
+ db PCPC_PLAYERS_PC
+ db PCPC_OAKS_PC
+ db PCPC_HALL_OF_FAME
+ db PCPC_TURN_OFF
+ db -1 ; end
+
+.ChooseWhichPCListToUse:
+ call CheckReceivedDex
+ jr nz, .got_dex
+ ld a, 0 ; before Pokédex
+ ret
+
+.got_dex
+ ld a, [wHallOfFameCount]
+ and a
+ ld a, 1 ; before Hall Of Fame
+ ret z
+ ld a, 2 ; postgame
+ ret
+
+PC_CheckPartyForPokemon:
+ ld a, [wPartyCount]
+ and a
+ ret nz
+ ld de, SFX_CHOOSE_PC_OPTION
+ call PlaySFX
+ ld hl, .PokecenterPCCantUseText
+ call PC_DisplayText
+ scf
+ ret
+
+.PokecenterPCCantUseText:
+ text_far _PokecenterPCCantUseText
+ text_end
+
+BillsPC:
+ call PC_PlayChoosePCSound
+ ld hl, PokecenterBillsPCText
+ call PC_DisplayText
+ farcall _BillsPC
+ and a
+ ret
+
+PlayersPC:
+ call PC_PlayChoosePCSound
+ ld hl, PokecenterPlayersPCText
+ call PC_DisplayText
+ ld b, $0
+ call _PlayersPC
+ and a
+ ret
+
+OaksPC:
+ call PC_PlayChoosePCSound
+ ld hl, PokecenterOaksPCText
+ call PC_DisplayText
+ farcall ProfOaksPC
+ and a
+ ret
+
+HallOfFamePC:
+ call PC_PlayChoosePCSound
+ call FadeToMenu
+ farcall _HallOfFamePC
+ call CloseSubmenu
+ and a
+ ret
+
+TurnOffPC:
+ ld hl, PokecenterPCOaksClosedText
+ call PrintText
+ scf
+ ret
+
+PC_PlayBootSound:
+ ld de, SFX_BOOT_PC
+ jr PC_WaitPlaySFX
+
+PC_PlayShutdownSound:
+ ld de, SFX_SHUT_DOWN_PC
+ call PC_WaitPlaySFX
+ call WaitSFX
+ ret
+
+PC_PlayChoosePCSound:
+ ld de, SFX_CHOOSE_PC_OPTION
+ jr PC_WaitPlaySFX
+
+PC_PlaySwapItemsSound:
+ ld de, SFX_SWITCH_POKEMON
+ call PC_WaitPlaySFX
+ ld de, SFX_SWITCH_POKEMON
+
+PC_WaitPlaySFX:
+ push de
+ call WaitSFX
+ pop de
+ call PlaySFX
+ ret
+
+_PlayersHousePC:
+ call PC_PlayBootSound
+ ld hl, PlayersPCTurnOnText
+ call PC_DisplayText
+ ld b, $1
+ call _PlayersPC
+ and a
+ jr nz, .asm_156f9
+ call OverworldTextModeSwitch
+ call ApplyTilemap
+ call UpdateSprites
+ call PC_PlayShutdownSound
+ ld c, $0
+ ret
+
+.asm_156f9
+ call ClearBGPalettes
+ ld c, $1
+ ret
+
+PlayersPCTurnOnText:
+ text_far _PlayersPCTurnOnText
+ text_end
+
+_PlayersPC:
+ ld a, b
+ ld [wWhichIndexSet], a
+ ld hl, PlayersPCAskWhatDoText
+ call PC_DisplayTextWaitMenu
+ call Function15715
+ call ExitMenu
+ ret
+
+Function15715:
+ xor a
+ ld [wPCItemsCursor], a
+ ld [wPCItemsScrollPosition], a
+ ld hl, PlayersPCMenuData
+ call LoadMenuHeader
+.asm_15722
+ call UpdateTimePals
+ call DoNthMenu
+ jr c, .asm_15731
+ call MenuJumptable
+ jr nc, .asm_15722
+ jr .asm_15732
+
+.asm_15731
+ xor a
+
+.asm_15732
+ call ExitMenu
+ ret
+
+PlayersPCMenuData:
+ db MENU_BACKUP_TILES ; flags
+ menu_coords 0, 0, 15, 12
+ dw .PlayersPCMenuData
+ db 1 ; default selected option
+
+.PlayersPCMenuData:
+ db STATICMENU_CURSOR | STATICMENU_WRAP ; flags
+ db 0 ; # items?
+ dw .PlayersPCMenuList1
+ dw PlaceNthMenuStrings
+ dw .PlayersPCMenuPointers
+
+PLAYERSPC_WITHDRAW_ITEM EQU 0
+PLAYERSPC_DEPOSIT_ITEM EQU 1
+PLAYERSPC_TOSS_ITEM EQU 2
+PLAYERSPC_MAIL_BOX EQU 3
+PLAYERSPC_DECORATION EQU 4
+PLAYERSPC_TURN_OFF EQU 5
+PLAYERSPC_LOG_OFF EQU 6
+
+.PlayersPCMenuPointers:
+; entries correspond to PLAYERSPC_* constants
+ dw PlayerWithdrawItemMenu, .WithdrawItem
+ dw PlayerDepositItemMenu, .DepositItem
+ dw PlayerTossItemMenu, .TossItem
+ dw PlayerMailBoxMenu, .MailBox
+ dw PlayerDecorationMenu, .Decoration
+ dw PlayerLogOffMenu, .LogOff
+ dw PlayerLogOffMenu, .TurnOff
+
+.WithdrawItem: db "WITHDRAW ITEM@"
+.DepositItem: db "DEPOSIT ITEM@"
+.TossItem: db "TOSS ITEM@"
+.MailBox: db "MAIL BOX@"
+.Decoration: db "DECORATION@"
+.TurnOff: db "TURN OFF@"
+.LogOff: db "LOG OFF@"
+
+.PlayersPCMenuList1:
+ db 5
+ db PLAYERSPC_WITHDRAW_ITEM
+ db PLAYERSPC_DEPOSIT_ITEM
+ db PLAYERSPC_TOSS_ITEM
+ db PLAYERSPC_MAIL_BOX
+ db PLAYERSPC_TURN_OFF
+ db -1 ; end
+
+.PlayersPCMenuList2:
+ db 6
+ db PLAYERSPC_WITHDRAW_ITEM
+ db PLAYERSPC_DEPOSIT_ITEM
+ db PLAYERSPC_TOSS_ITEM
+ db PLAYERSPC_MAIL_BOX
+ db PLAYERSPC_DECORATION
+ db PLAYERSPC_LOG_OFF
+ db -1 ; end
+
+PC_DisplayTextWaitMenu:
+ ld a, [wOptions]
+ push af
+ set NO_TEXT_SCROLL, a
+ ld [wOptions], a
+ call MenuTextbox
+ pop af
+ ld [wOptions], a
+ ret
+
+PlayersPCAskWhatDoText:
+ text_far _PlayersPCAskWhatDoText
+ text_end
+
+PlayerWithdrawItemMenu:
+ call LoadStandardMenuHeader
+ farcall ClearPCItemScreen
+.loop
+ call PCItemsJoypad
+ jr c, .quit
+ call .Submenu
+ jr .loop
+
+.quit
+ call CloseSubmenu
+ xor a
+ ret
+
+.Submenu:
+ ; check if the item has a quantity
+ farcall _CheckTossableItem
+ ld a, [wItemAttributeParamBuffer]
+ and a
+ jr z, .askquantity
+
+ ; items without quantity are always ×1
+ ld a, 1
+ ld [wItemQuantityChangeBuffer], a
+ jr .withdraw
+
+.askquantity
+ ld hl, .PlayersPCHowManyWithdrawText
+ call MenuTextbox
+ farcall SelectQuantityToToss
+ call ExitMenu
+ call ExitMenu
+ jr c, .done
+
+.withdraw
+ ld a, [wItemQuantityChangeBuffer]
+ ld [wBuffer1], a ; quantity
+ ld a, [wCurItemQuantity]
+ ld [wBuffer2], a
+ ld hl, wNumItems
+ call ReceiveItem
+ jr nc, .PackFull
+ ld a, [wBuffer1]
+ ld [wItemQuantityChangeBuffer], a
+ ld a, [wBuffer2]
+ ld [wCurItemQuantity], a
+ ld hl, wNumPCItems
+ call TossItem
+ predef PartyMonItemName
+ ld hl, .PlayersPCWithdrewItemsText
+ call MenuTextbox
+ xor a
+ ldh [hBGMapMode], a
+ call ExitMenu
+ ret
+
+.PackFull:
+ ld hl, .PlayersPCNoRoomWithdrawText
+ call MenuTextboxBackup
+ ret
+
+.done
+ ret
+
+.PlayersPCHowManyWithdrawText:
+ text_far _PlayersPCHowManyWithdrawText
+ text_end
+
+.PlayersPCWithdrewItemsText:
+ text_far _PlayersPCWithdrewItemsText
+ text_end
+
+.PlayersPCNoRoomWithdrawText:
+ text_far _PlayersPCNoRoomWithdrawText
+ text_end
+
+PlayerTossItemMenu:
+ call LoadStandardMenuHeader
+ farcall ClearPCItemScreen
+.loop
+ call PCItemsJoypad
+ jr c, .quit
+ ld de, wNumPCItems
+ farcall TossItemFromPC
+ jr .loop
+
+.quit
+ call CloseSubmenu
+ xor a
+ ret
+
+PlayerDecorationMenu:
+ farcall _PlayerDecorationMenu
+ ld a, c
+ and a
+ ret z
+ scf
+ ret
+
+PlayerLogOffMenu:
+ xor a
+ scf
+ ret
+
+PlayerDepositItemMenu:
+ call .CheckItemsInBag
+ jr c, .nope
+ call DisableSpriteUpdates
+ call LoadStandardMenuHeader
+ farcall DepositSellInitPackBuffers
+.loop
+ farcall DepositSellPack
+ ld a, [wPackUsedItem]
+ and a
+ jr z, .close
+ call .TryDepositItem
+ farcall CheckRegisteredItem
+ jr .loop
+
+.close
+ call CloseSubmenu
+
+.nope
+ xor a
+ ret
+
+.CheckItemsInBag:
+ farcall HasNoItems
+ ret nc
+ ld hl, .PlayersPCNoItemsText
+ call MenuTextboxBackup
+ scf
+ ret
+
+.PlayersPCNoItemsText:
+ text_far _PlayersPCNoItemsText
+ text_end
+
+.TryDepositItem:
+ ld a, [wSpriteUpdatesEnabled]
+ push af
+ ld a, $0
+ ld [wSpriteUpdatesEnabled], a
+ farcall CheckItemMenu
+ ld a, [wItemAttributeParamBuffer]
+ ld hl, .dw
+ rst JumpTable
+ pop af
+ ld [wSpriteUpdatesEnabled], a
+ ret
+
+.dw
+; entries correspond to ITEMMENU_* constants
+ dw .tossable ; ITEMMENU_NOUSE
+ dw .no_toss
+ dw .no_toss
+ dw .no_toss
+ dw .tossable ; ITEMMENU_CURRENT
+ dw .tossable ; ITEMMENU_PARTY
+ dw .tossable ; ITEMMENU_CLOSE
+
+.no_toss
+ ret
+
+.tossable
+ ld a, [wBuffer1]
+ push af
+ ld a, [wBuffer2]
+ push af
+ call .DepositItem
+ pop af
+ ld [wBuffer2], a
+ pop af
+ ld [wBuffer1], a
+ ret
+
+.DepositItem:
+ farcall _CheckTossableItem
+ ld a, [wItemAttributeParamBuffer]
+ and a
+ jr z, .AskQuantity
+ ld a, $1
+ ld [wItemQuantityChangeBuffer], a
+ jr .ContinueDeposit
+
+.AskQuantity:
+ ld hl, .PlayersPCHowManyDepositText
+ call MenuTextbox
+ farcall SelectQuantityToToss
+ push af
+ call ExitMenu
+ call ExitMenu
+ pop af
+ jr c, .DeclinedToDeposit
+
+.ContinueDeposit:
+ ld a, [wItemQuantityChangeBuffer]
+ ld [wBuffer1], a
+ ld a, [wCurItemQuantity]
+ ld [wBuffer2], a
+ ld hl, wNumPCItems
+ call ReceiveItem
+ jr nc, .NoRoomInPC
+ ld a, [wBuffer1]
+ ld [wItemQuantityChangeBuffer], a
+ ld a, [wBuffer2]
+ ld [wCurItemQuantity], a
+ ld hl, wNumItems
+ call TossItem
+ predef PartyMonItemName
+ ld hl, .PlayersPCDepositItemsText
+ call PrintText
+ ret
+
+.NoRoomInPC:
+ ld hl, .PlayersPCNoRoomDepositText
+ call PrintText
+ ret
+
+.DeclinedToDeposit:
+ and a
+ ret
+
+.PlayersPCHowManyDepositText:
+ text_far _PlayersPCHowManyDepositText
+ text_end
+
+.PlayersPCDepositItemsText:
+ text_far _PlayersPCDepositItemsText
+ text_end
+
+.PlayersPCNoRoomDepositText:
+ text_far _PlayersPCNoRoomDepositText
+ text_end
+
+PlayerMailBoxMenu:
+ farcall _PlayerMailBoxMenu
+ xor a
+ ret
+
+PCItemsJoypad:
+ xor a
+ ld [wSwitchItem], a
+.loop
+ ld a, [wSpriteUpdatesEnabled]
+ push af
+ ld a, $0
+ ld [wSpriteUpdatesEnabled], a
+ ld hl, .PCItemsMenuData
+ call CopyMenuHeader
+ hlcoord 0, 0
+ ld b, 10
+ ld c, 18
+ call Textbox
+ ld a, [wPCItemsCursor]
+ ld [wMenuCursorBuffer], a
+ ld a, [wPCItemsScrollPosition]
+ ld [wMenuScrollPosition], a
+ call ScrollingMenu
+ ld a, [wMenuScrollPosition]
+ ld [wPCItemsScrollPosition], a
+ ld a, [wMenuCursorY]
+ ld [wPCItemsCursor], a
+ pop af
+ ld [wSpriteUpdatesEnabled], a
+ ld a, [wSwitchItem]
+ and a
+ jr nz, .moving_stuff_around
+ ld a, [wMenuJoypad]
+ cp B_BUTTON
+ jr z, .b_1
+ cp A_BUTTON
+ jr z, .a_1
+ cp SELECT
+ jr z, .select_1
+ jr .next
+
+.moving_stuff_around
+ ld a, [wMenuJoypad]
+ cp B_BUTTON
+ jr z, .b_2
+ cp A_BUTTON
+ jr z, .a_select_2
+ cp SELECT
+ jr z, .a_select_2
+ jr .next
+
+.b_2
+ xor a
+ ld [wSwitchItem], a
+ jr .next
+
+.a_select_2
+ call PC_PlaySwapItemsSound
+.select_1
+ farcall SwitchItemsInBag
+.next
+ jp .loop
+
+.a_1
+ farcall ScrollingMenu_ClearLeftColumn
+ call PlaceHollowCursor
+ and a
+ ret
+
+.b_1
+ scf
+ ret
+
+.PCItemsMenuData:
+ db MENU_BACKUP_TILES ; flags
+ menu_coords 4, 1, 18, 10
+ dw .MenuData
+ db 1 ; default option
+
+.MenuData:
+ db SCROLLINGMENU_ENABLE_SELECT | SCROLLINGMENU_ENABLE_FUNCTION3 | SCROLLINGMENU_DISPLAY_ARROWS ; flags
+ db 4, 8 ; rows, columns
+ db SCROLLINGMENU_ITEMS_QUANTITY ; item format
+ dbw 0, wNumPCItems
+ dba PlaceMenuItemName
+ dba PlaceMenuItemQuantity
+ dba UpdateItemDescription
+
+PC_DisplayText:
+ call MenuTextbox
+ call ExitMenu
+ ret
+
+PokecenterPCTurnOnText:
+ text_far _PokecenterPCTurnOnText
+ text_end
+
+PokecenterPCWhoseText:
+ text_far _PokecenterPCWhoseText
+ text_end
+
+PokecenterBillsPCText:
+ text_far _PokecenterBillsPCText
+ text_end
+
+PokecenterPlayersPCText:
+ text_far _PokecenterPlayersPCText
+ text_end
+
+PokecenterOaksPCText:
+ text_far _PokecenterOaksPCText
+ text_end
+
+PokecenterPCOaksClosedText:
+ text_far _PokecenterPCOaksClosedText
+ text_end
diff --git a/engine/events/specials.asm b/engine/events/specials.asm
index 8b7243d1..11ae421e 100755
--- a/engine/events/specials.asm
+++ b/engine/events/specials.asm
@@ -248,7 +248,7 @@ DisplayLinkRecord: ; c434 (3:4434)
PlayersHousePC: ; c441 (3:4441)
xor a
ld [wScriptVar], a
- farcall Function159b0
+ farcall _PlayersHousePC
ld a, c
ld [wScriptVar], a
ret
diff --git a/engine/items/items.asm b/engine/items/items.asm
index 7cd1de67..c24d580b 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -139,10 +139,10 @@ GetPocketCapacity: ; d290 (3:5290)
.asm_d29b
ld c, MAX_PC_ITEMS
ld a, e
- cp wPCItems % $100
+ cp LOW(wNumPCItems)
jr nz, .asm_d2a6
ld a, d
- cp wPCItems / $100
+ cp HIGH(wNumPCItems)
ret z
.asm_d2a6
ld c, MAX_BALLS
diff --git a/engine/items/mart.asm b/engine/items/mart.asm
new file mode 100644
index 00000000..3978ef33
--- /dev/null
+++ b/engine/items/mart.asm
@@ -0,0 +1,811 @@
+ const_def
+ const MARTTEXT_HOW_MANY
+ const MARTTEXT_COSTS_THIS_MUCH
+ const MARTTEXT_NOT_ENOUGH_MONEY
+ const MARTTEXT_BAG_FULL
+ const MARTTEXT_HERE_YOU_GO
+ const MARTTEXT_SOLD_OUT
+
+GetMart:
+ ld a, e
+ cp (Marts.End - Marts) / 2
+ jr c, .IsAMart
+ ld b, BANK(DefaultMart)
+ ld de, DefaultMart
+ ret
+
+.IsAMart:
+ ld hl, Marts
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld b, BANK(Marts)
+ ret
+
+OpenMartDialog::
+ call GetMart
+ ld a, c
+ ld [wMartType], a
+ call LoadMartPointer
+ ld a, [wMartType]
+ ld hl, .dialogs
+ rst JumpTable
+ ret
+
+.dialogs
+ dw MartDialog
+ dw HerbShop
+ dw BargainShop
+ dw Pharmacist
+
+MartDialog:
+ ld a, MARTTYPE_STANDARD
+ ld [wMartType], a
+ xor a ; STANDARDMART_HOWMAYIHELPYOU
+ ld [wMartJumptableIndex], a
+ call StandardMart
+ ret
+
+HerbShop:
+ call FarReadMart
+ call LoadStandardMenuHeader
+ ld hl, HerbShopLadyIntroText
+ call MartTextbox
+ call BuyMenu
+ ld hl, HerbalLadyComeAgainText
+ call MartTextbox
+ ret
+
+BargainShop:
+ ld b, BANK(BargainShopData)
+ ld de, BargainShopData
+ call LoadMartPointer
+ call ReadMart
+ call LoadStandardMenuHeader
+ ld hl, BargainShopIntroText
+ call MartTextbox
+ call BuyMenu
+ ld hl, wBargainShopFlags
+ ld a, [hli]
+ or [hl]
+ jr z, .skip_set
+ ld hl, wDailyFlags1
+ set DAILYFLAGS1_GOLDENROD_UNDERGROUND_BARGAIN_F, [hl]
+
+.skip_set
+ ld hl, BargainShopComeAgainText
+ call MartTextbox
+ ret
+
+Pharmacist:
+ call FarReadMart
+ call LoadStandardMenuHeader
+ ld hl, PharmacyIntroText
+ call MartTextbox
+ call BuyMenu
+ ld hl, PharmacyComeAgainText
+ call MartTextbox
+ ret
+
+LoadMartPointer:
+ ld a, b
+ ld [wMartPointerBank], a
+ ld a, e
+ ld [wMartPointer], a
+ ld a, d
+ ld [wMartPointer + 1], a
+ ld hl, wCurMart
+ xor a
+ ld bc, wCurMartEnd - wCurMart
+ call ByteFill
+ xor a ; STANDARDMART_HOWMAYIHELPYOU
+ ld [wMartJumptableIndex], a
+ ld [wBargainShopFlags], a
+ ld [wFacingDirection], a
+ ret
+
+; StandardMart.MartFunctions indexes
+ const_def
+ const STANDARDMART_HOWMAYIHELPYOU ; 0
+ const STANDARDMART_TOPMENU ; 1
+ const STANDARDMART_BUY ; 2
+ const STANDARDMART_SELL ; 3
+ const STANDARDMART_QUIT ; 4
+ const STANDARDMART_ANYTHINGELSE ; 5
+
+STANDARDMART_EXIT EQU -1
+
+StandardMart:
+.loop
+ ld a, [wMartJumptableIndex]
+ ld hl, .MartFunctions
+ rst JumpTable
+ ld [wMartJumptableIndex], a
+ cp STANDARDMART_EXIT
+ jr nz, .loop
+ ret
+
+.MartFunctions:
+; entries correspond to STANDARDMART_* constants
+ dw .HowMayIHelpYou
+ dw .TopMenu
+ dw .Buy
+ dw .Sell
+ dw .Quit
+ dw .AnythingElse
+
+.HowMayIHelpYou:
+ call LoadStandardMenuHeader
+ ld hl, MartWelcomeText
+ call PrintText
+ ld a, STANDARDMART_TOPMENU
+ ret
+
+.TopMenu:
+ ld hl, MenuHeader_BuySell
+ call CopyMenuHeader
+ call VerticalMenu
+ jr c, .quit
+ ld a, [wMenuCursorY]
+ cp $1
+ jr z, .buy
+ cp $2
+ jr z, .sell
+.quit
+ ld a, STANDARDMART_QUIT
+ ret
+.buy
+ ld a, STANDARDMART_BUY
+ ret
+.sell
+ ld a, STANDARDMART_SELL
+ ret
+
+.Buy:
+ call ExitMenu
+ call FarReadMart
+ call BuyMenu
+ and a
+ ld a, STANDARDMART_ANYTHINGELSE
+ ret
+
+.Sell:
+ call ExitMenu
+ call SellMenu
+ ld a, STANDARDMART_ANYTHINGELSE
+ ret
+
+.Quit:
+ call ExitMenu
+ ld hl, MartComeAgainText
+ call MartTextbox
+ ld a, STANDARDMART_EXIT
+ ret
+
+.AnythingElse:
+ call LoadStandardMenuHeader
+ ld hl, MartAskMoreText
+ call PrintText
+ ld a, STANDARDMART_TOPMENU
+ ret
+
+FarReadMart:
+ ld hl, wMartPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, wCurMart
+.CopyMart:
+ ld a, [wMartPointerBank]
+ call GetFarByte
+ ld [de], a
+ inc hl
+ inc de
+ cp -1
+ jr nz, .CopyMart
+ ld hl, wMartItem1BCD
+ ld de, wCurMart + 1
+.ReadMartItem:
+ ld a, [de]
+ inc de
+ cp -1
+ jr z, .done
+ push de
+ call GetMartItemPrice
+ pop de
+ jr .ReadMartItem
+
+.done
+ ret
+
+GetMartItemPrice:
+; Return the price of item a in BCD at hl and in tiles at wStringBuffer1.
+ push hl
+ ld [wCurItem], a
+ farcall GetItemPrice
+ pop hl
+
+GetMartPrice:
+; Return price de in BCD at hl and in tiles at wStringBuffer1.
+ push hl
+ ld a, d
+ ld [wStringBuffer2], a
+ ld a, e
+ ld [wStringBuffer2 + 1], a
+ ld hl, wStringBuffer1
+ ld de, wStringBuffer2
+ lb bc, PRINTNUM_LEADINGZEROS | 2, 6 ; 6 digits
+ call PrintNum
+ pop hl
+
+ ld de, wStringBuffer1
+ ld c, 6 / 2 ; 6 digits
+.loop
+ call .CharToNybble
+ swap a
+ ld b, a
+ call .CharToNybble
+ or b
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ret
+
+.CharToNybble:
+ ld a, [de]
+ inc de
+ cp " "
+ jr nz, .not_space
+ ld a, "0"
+
+.not_space
+ sub "0"
+ ret
+
+ReadMart:
+; Load the mart pointer. Mart data is local (no need for bank).
+ ld hl, wMartPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ push hl
+; set hl to the first item
+ inc hl
+ ld bc, wMartItem1BCD
+ ld de, wCurMart + 1
+.loop
+; copy the item to wCurMart + (ItemIndex)
+ ld a, [hli]
+ ld [de], a
+ inc de
+; -1 is the terminator
+ cp -1
+ jr z, .done
+
+ push de
+; copy the price to de
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+; convert the price to 3-byte BCD at [bc]
+ push hl
+ ld h, b
+ ld l, c
+ call GetMartPrice
+ ld b, h
+ ld c, l
+ pop hl
+
+ pop de
+ jr .loop
+
+.done
+ pop hl
+ ld a, [hl]
+ ld [wCurMart], a
+ ret
+
+INCLUDE "data/items/bargain_shop.asm"
+
+BuyMenu:
+ call FadeToMenu
+ farcall BlankScreen
+ xor a
+ ld [wMenuScrollPositionBackup], a
+ ld a, 1
+ ld [wMenuCursorBufferBackup], a
+.loop
+ call BuyMenuLoop ; menu loop
+ jr nc, .loop
+ call CloseSubmenu
+ ret
+
+LoadBuyMenuText:
+; load text from a nested table
+; which table is in wMartType
+; which entry is in register a
+ push af
+ call GetMartDialogGroup ; gets a pointer from GetMartDialogGroup.MartTextFunctionPointers
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop af
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call PrintText
+ ret
+
+MartAskPurchaseQuantity:
+ call GetMartDialogGroup ; gets a pointer from GetMartDialogGroup.MartTextFunctionPointers
+ inc hl
+ inc hl
+ ld a, [hl]
+ and a
+ jp z, StandardMartAskPurchaseQuantity
+ jp BargainShopAskPurchaseQuantity
+
+GetMartDialogGroup:
+ ld a, [wMartType]
+ ld e, a
+ ld d, 0
+ ld hl, .MartTextFunctionPointers
+ add hl, de
+ add hl, de
+ add hl, de
+ ret
+
+.MartTextFunctionPointers:
+ dwb .StandardMartPointers, 0
+ dwb .HerbShopPointers, 0
+ dwb .BargainShopPointers, 1
+ dwb .PharmacyPointers, 0
+
+.StandardMartPointers:
+ dw MartHowManyText
+ dw MartFinalPriceText
+ dw MartNoMoneyText
+ dw MartPackFullText
+ dw MartThanksText
+ dw BuyMenuLoop
+
+.HerbShopPointers:
+ dw HerbalLadyHowManyText
+ dw HerbalLadyFinalPriceText
+ dw HerbalLadyNoMoneyText
+ dw HerbalLadyPackFullText
+ dw HerbalLadyThanksText
+ dw BuyMenuLoop
+
+.BargainShopPointers:
+ dw BuyMenuLoop
+ dw BargainShopFinalPriceText
+ dw BargainShopNoFundsText
+ dw BargainShopPackFullText
+ dw BargainShopThanksText
+ dw BargainShopSoldOutText
+
+.PharmacyPointers:
+ dw PharmacyHowManyText
+ dw PharmacyFinalPriceText
+ dw PharmacyNoMoneyText
+ dw PharmacyPackFullText
+ dw PharmacyThanksText
+ dw BuyMenuLoop
+
+BuyMenuLoop:
+ farcall PlaceMoneyTopRight
+ call UpdateSprites
+ ld hl, MenuHeader_Buy
+ call CopyMenuHeader
+ ld a, [wMenuCursorBufferBackup]
+ ld [wMenuCursorBuffer], a
+ ld a, [wMenuScrollPositionBackup]
+ ld [wMenuScrollPosition], a
+ call ScrollingMenu
+ ld a, [wMenuScrollPosition]
+ ld [wMenuScrollPositionBackup], a
+ ld a, [wMenuCursorY]
+ ld [wMenuCursorBufferBackup], a
+ call SpeechTextbox
+ ld a, [wMenuJoypad]
+ cp B_BUTTON
+ jr z, .set_carry
+ cp A_BUTTON
+ jr z, .useless_pointer
+
+.useless_pointer
+ call MartAskPurchaseQuantity
+ jr c, .cancel
+ call MartConfirmPurchase
+ jr c, .cancel
+ ld de, wMoney
+ ld bc, hMoneyTemp
+ ld a, 3 ; useless load
+ call CompareMoney
+ jr c, .insufficient_funds
+ ld hl, wNumItems
+ call ReceiveItem
+ jr nc, .insufficient_bag_space
+ ld a, [wMartItemID]
+ ld e, a
+ ld d, 0
+ ld b, SET_FLAG
+ ld hl, wBargainShopFlags
+ call FlagAction
+ call PlayTransactionSound
+ ld de, wMoney
+ ld bc, hMoneyTemp
+ call TakeMoney
+ ld a, MARTTEXT_HERE_YOU_GO
+ call LoadBuyMenuText
+ call JoyWaitAorB
+
+.cancel
+ call SpeechTextbox
+ and a
+ ret
+
+.set_carry
+ scf
+ ret
+
+.insufficient_bag_space
+ ld a, MARTTEXT_BAG_FULL
+ call LoadBuyMenuText
+ call JoyWaitAorB
+ and a
+ ret
+
+.insufficient_funds
+ ld a, MARTTEXT_NOT_ENOUGH_MONEY
+ call LoadBuyMenuText
+ call JoyWaitAorB
+ and a
+ ret
+
+StandardMartAskPurchaseQuantity:
+ ld a, 99
+ ld [wItemQuantityBuffer], a
+ ld a, MARTTEXT_HOW_MANY
+ call LoadBuyMenuText
+ farcall SelectQuantityToBuy
+ call ExitMenu
+ ret
+
+MartConfirmPurchase:
+ predef PartyMonItemName
+ ld a, MARTTEXT_COSTS_THIS_MUCH
+ call LoadBuyMenuText
+ call YesNoBox
+ ret
+
+BargainShopAskPurchaseQuantity:
+ ld a, 1
+ ld [wItemQuantityChangeBuffer], a
+ ld a, [wMartItemID]
+ ld e, a
+ ld d, 0
+ ld b, CHECK_FLAG
+ ld hl, wBargainShopFlags
+ call FlagAction
+ ld a, c
+ and a
+ jr nz, .SoldOut
+ ld a, [wMartItemID]
+ ld e, a
+ ld d, 0
+ ld hl, wMartPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ inc hl
+ add hl, de
+ add hl, de
+ add hl, de
+ inc hl
+ ld a, [hli]
+ ldh [hMoneyTemp + 2], a
+ ld a, [hl]
+ ldh [hMoneyTemp + 1], a
+ xor a
+ ldh [hMoneyTemp], a
+ and a
+ ret
+
+.SoldOut:
+ ld a, MARTTEXT_SOLD_OUT
+ call LoadBuyMenuText
+ call JoyWaitAorB
+ scf
+ ret
+
+MartHowManyText:
+ text_far _MartHowManyText
+ text_end
+
+MartFinalPriceText:
+ text_far _MartFinalPriceText
+ text_end
+
+MenuHeader_Buy:
+ db MENU_BACKUP_TILES ; flags
+ menu_coords 1, 3, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
+ dw .MenuData
+ db 1 ; default option
+
+.MenuData
+ db SCROLLINGMENU_DISPLAY_ARROWS | SCROLLINGMENU_ENABLE_FUNCTION3 ; flags
+ db 4, 8 ; rows, columns
+ db SCROLLINGMENU_ITEMS_NORMAL ; item format
+ dbw 0, wCurMart
+ dba PlaceMenuItemName
+ dba .PrintBCDPrices
+ dba UpdateItemDescription
+
+.PrintBCDPrices:
+ ld a, [wScrollingMenuCursorPosition]
+ ld c, a
+ ld b, 0
+ ld hl, wMartItem1BCD
+ add hl, bc
+ add hl, bc
+ add hl, bc
+ push de
+ ld d, h
+ ld e, l
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ ld c, PRINTNUM_LEADINGZEROS | PRINTNUM_MONEY | 3
+ call PrintBCDNumber
+ ret
+
+HerbShopLadyIntroText:
+ text_far _HerbShopLadyIntroText
+ text_end
+
+HerbalLadyHowManyText:
+ text_far _HerbalLadyHowManyText
+ text_end
+
+HerbalLadyFinalPriceText:
+ text_far _HerbalLadyFinalPriceText
+ text_end
+
+HerbalLadyThanksText:
+ text_far _HerbalLadyThanksText
+ text_end
+
+HerbalLadyPackFullText:
+ text_far _HerbalLadyPackFullText
+ text_end
+
+HerbalLadyNoMoneyText:
+ text_far _HerbalLadyNoMoneyText
+ text_end
+
+HerbalLadyComeAgainText:
+ text_far _HerbalLadyComeAgainText
+ text_end
+
+BargainShopIntroText:
+ text_far _BargainShopIntroText
+ text_end
+
+BargainShopFinalPriceText:
+ text_far _BargainShopFinalPriceText
+ text_end
+
+BargainShopThanksText:
+ text_far _BargainShopThanksText
+ text_end
+
+BargainShopPackFullText:
+ text_far _BargainShopPackFullText
+ text_end
+
+BargainShopSoldOutText:
+ text_far _BargainShopSoldOutText
+ text_end
+
+BargainShopNoFundsText:
+ text_far _BargainShopNoFundsText
+ text_end
+
+BargainShopComeAgainText:
+ text_far _BargainShopComeAgainText
+ text_end
+
+PharmacyIntroText:
+ text_far _PharmacyIntroText
+ text_end
+
+PharmacyHowManyText:
+ text_far _PharmacyHowManyText
+ text_end
+
+PharmacyFinalPriceText:
+ text_far _PharmacyFinalPriceText
+ text_end
+
+PharmacyThanksText:
+ text_far _PharmacyThanksText
+ text_end
+
+PharmacyPackFullText:
+ text_far _PharmacyPackFullText
+ text_end
+
+PharmacyNoMoneyText:
+ text_far _PharmacyNoMoneyText
+ text_end
+
+PharmacyComeAgainText:
+ text_far _PharmacyComeAgainText
+ text_end
+
+SellMenu:
+ call DisableSpriteUpdates
+ farcall DepositSellInitPackBuffers
+.loop
+ farcall DepositSellPack
+ ld a, [wPackUsedItem]
+ and a
+ jp z, .quit
+ call .TryToSellItem
+ jr .loop
+
+.quit
+ call ReturnToMapWithSpeechTextbox
+ and a
+ ret
+
+.Unreferenced_NothingToSell:
+ ld hl, .NothingToSellText
+ call MenuTextboxBackup
+ and a
+ ret
+
+.NothingToSellText:
+ text_far _NothingToSellText
+ text_end
+
+.TryToSellItem:
+ farcall CheckItemMenu
+ ld a, [wItemAttributeParamBuffer]
+ ld hl, .dw
+ rst JumpTable
+ ret
+
+.dw
+ dw .try_sell
+ dw .cant_buy
+ dw .cant_buy
+ dw .cant_buy
+ dw .try_sell
+ dw .try_sell
+ dw .try_sell
+
+.cant_buy
+ ret
+
+.try_sell
+ farcall _CheckTossableItem
+ ld a, [wItemAttributeParamBuffer]
+ and a
+ jr z, .okay_to_sell
+ ld hl, MartCantBuyText
+ call PrintText
+ and a
+ ret
+
+.okay_to_sell
+ ld hl, MartSellHowManyText
+ call PrintText
+ farcall PlaceMoneyAtTopLeftOfTextbox
+ farcall SelectQuantityToSell
+ call ExitMenu
+ jr c, .declined
+ hlcoord 1, 14
+ lb bc, 3, 18
+ call ClearBox
+ ld hl, MartSellPriceText
+ call PrintTextboxText
+ call YesNoBox
+ jr c, .declined
+ ld de, wMoney
+ ld bc, hMoneyTemp
+ call GiveMoney
+ ld a, [wMartItemID]
+ ld hl, wNumItems
+ call TossItem
+ predef PartyMonItemName
+ hlcoord 1, 14
+ lb bc, 3, 18
+ call ClearBox
+ ld hl, MartBoughtText
+ call PrintTextboxText
+ call PlayTransactionSound
+ farcall PlaceMoneyBottomLeft
+ call JoyWaitAorB
+
+.declined
+ call ExitMenu
+ and a
+ ret
+
+MartSellHowManyText:
+ text_far _MartSellHowManyText
+ text_end
+
+MartSellPriceText:
+ text_far _MartSellPriceText
+ text_end
+
+.UnusedString161d2:
+ db "!ダミー!@"
+
+MartWelcomeText:
+ text_far _MartWelcomeText
+ text_end
+
+MenuHeader_BuySell:
+ db MENU_BACKUP_TILES ; flags
+ menu_coords 0, 0, 11, 8
+ dw .MenuData
+ db 1 ; default option
+
+.MenuData
+ db STATICMENU_CURSOR ; strings
+ db 3 ; items
+ db "BUY@"
+ db "SELL@"
+ db "QUIT@"
+
+MartThanksText:
+ text_far _MartThanksText
+ text_end
+
+MartNoMoneyText:
+ text_far _MartNoMoneyText
+ text_end
+
+MartPackFullText:
+ text_far _MartPackFullText
+ text_end
+
+MartCantBuyText:
+ text_far _MartCantBuyText
+ text_end
+
+MartComeAgainText:
+ text_far _MartComeAgainText
+ text_end
+
+MartAskMoreText:
+ text_far _MartAskMoreText
+ text_end
+
+MartBoughtText:
+ text_far _MartBoughtText
+ text_end
+
+PlayTransactionSound:
+ call WaitSFX
+ ld de, SFX_TRANSACTION
+ call PlaySFX
+ ret
+
+MartTextbox:
+ call MenuTextbox
+ call JoyWaitAorB
+ call ExitMenu
+ ret
diff --git a/engine/menus/intro_menu.asm b/engine/menus/intro_menu.asm
index 0d8f7712..db0d929a 100644
--- a/engine/menus/intro_menu.asm
+++ b/engine/menus/intro_menu.asm
@@ -289,7 +289,7 @@ Function5c41: ; 5c41 (1:5c41)
ld [wPlayerID + 1], a
ld hl, wPartyCount
- call Function5d15
+ call .InitList
xor a
ld [wCurBox], a
@@ -300,17 +300,17 @@ Function5c41: ; 5c41 (1:5c41)
ld a, BANK(sBoxCount)
call OpenSRAM
ld hl, sBoxCount
- call Function5d15
+ call .InitList
call CloseSRAM
ld hl, wNumItems
- call Function5d15
+ call .InitList
ld hl, wNumKeyItems
- call Function5d15
+ call .InitList
ld hl, wNumBalls
- call Function5d15
- ld hl, wPCItems
- call Function5d15
+ call .InitList
+ ld hl, wNumPCItems
+ call .InitList
xor a
ld [wRoamMon1Species], a
@@ -373,7 +373,7 @@ ENDC
call ResetGameTime
ret
-Function5d15: ; 5d15 (1:5d15)
+.InitList:
xor a
ld [hli], a
dec a
diff --git a/engine/overworld/time.asm b/engine/overworld/time.asm
index 6324420f..2ca7e101 100755
--- a/engine/overworld/time.asm
+++ b/engine/overworld/time.asm
@@ -87,7 +87,7 @@ CheckDailyResetTimer:
call Function1183b
ret nc
xor a
- ld hl, wDailyFlags
+ ld hl, wDailyFlags1
ld [hli], a
ld [hl], a
jr asm_11867
@@ -170,12 +170,12 @@ Function118f8: ; 118f8 (4:58f8)
call Function11972
ret
- ld hl, wDailyFlags
+ ld hl, wDailyFlags1
set 2, [hl]
ret
and a
- ld hl, wDailyFlags
+ ld hl, wDailyFlags1
bit 2, [hl]
ret nz
scf
diff --git a/engine/pokemon/bills_pc_top.asm b/engine/pokemon/bills_pc_top.asm
index 1dad31a6..38cfc479 100644
--- a/engine/pokemon/bills_pc_top.asm
+++ b/engine/pokemon/bills_pc_top.asm
@@ -1,4 +1,4 @@
-BillsPC_:
+_BillsPC:
call BillsPC_CheckHavePokemon
ret c
call BillsPC_LogIn
@@ -22,7 +22,7 @@ BillsPC_LogIn: ; e3f7 (3:63f7)
xor a
ldh [hBGMapMode], a
call LoadStandardMenuHeader
- call Functione566
+ call ClearPCItemScreen
ld hl, wOptions
ld a, [hl]
push af
@@ -116,7 +116,7 @@ BillsPC_MovePKMNMenu:
jr c, .asm_e4cf
farcall MovePKMNWithoutMail_ ; 38:6f47
call ReturnToMapFromSubmenu
- call Functione566
+ call ClearPCItemScreen
.asm_e4cf
call CloseWindow
and a
@@ -130,7 +130,7 @@ BillsPC_DepositMenu:
call LoadStandardMenuHeader
farcall DepositPokemon_ ; 38:6b9e
call ReturnToMapFromSubmenu
- call Functione566
+ call ClearPCItemScreen
call CloseWindow
and a
ret
@@ -196,7 +196,7 @@ BillsPC_WithdrawMenu:
call LoadStandardMenuHeader
farcall WithdrawPokemon_ ; 38:6d71
call ReturnToMapFromSubmenu
- call Functione566
+ call ClearPCItemScreen
call CloseWindow
and a
ret
@@ -219,11 +219,11 @@ Text_CantTakeAnyMorePokemon:
db "@"
BillsPC_ChangeBoxMenu:
- farcall ChangeBox_ ; 38:7d25
+ farcall ChangeBox_
and a
ret
-Functione566: ; e566 (3:6566)
+ClearPCItemScreen:
call DisableSpriteUpdates
xor a
ldh [hBGMapMode], a