First Commit

Upload literally everything from the pokecrystal16 expand-move-ID branch
This commit is contained in:
Zeta_Null 2023-09-10 12:35:35 -04:00
commit 2f8a41f833
4618 changed files with 480386 additions and 0 deletions

View file

@ -0,0 +1,221 @@
SelectQuantityToToss:
ld hl, TossItem_MenuHeader
call LoadMenuHeader
call Toss_Sell_Loop
ret
SelectQuantityToBuy:
farcall GetItemPrice
RooftopSale_SelectQuantityToBuy:
ld a, d
ld [wBuySellItemPrice + 0], a
ld a, e
ld [wBuySellItemPrice + 1], a
ld hl, BuyItem_MenuHeader
call LoadMenuHeader
call Toss_Sell_Loop
ret
SelectQuantityToSell:
farcall GetItemPrice
ld a, d
ld [wBuySellItemPrice + 0], a
ld a, e
ld [wBuySellItemPrice + 1], a
ld hl, SellItem_MenuHeader
call LoadMenuHeader
call Toss_Sell_Loop
ret
Toss_Sell_Loop:
ld a, 1
ld [wItemQuantityChange], a
.loop
call BuySellToss_UpdateQuantityDisplay ; update display
call BuySellToss_InterpretJoypad ; joy action
jr nc, .loop
cp -1
jr nz, .nope ; pressed B
scf
ret
.nope
and a
ret
BuySellToss_InterpretJoypad:
call JoyTextDelay_ForcehJoyDown ; get joypad
bit B_BUTTON_F, c
jr nz, .b
bit A_BUTTON_F, c
jr nz, .a
bit D_DOWN_F, c
jr nz, .down
bit D_UP_F, c
jr nz, .up
bit D_LEFT_F, c
jr nz, .left
bit D_RIGHT_F, c
jr nz, .right
and a
ret
.b
ld a, -1
scf
ret
.a
ld a, 0
scf
ret
.down
ld hl, wItemQuantityChange
dec [hl]
jr nz, .finish_down
ld a, [wItemQuantity]
ld [hl], a
.finish_down
and a
ret
.up
ld hl, wItemQuantityChange
inc [hl]
ld a, [wItemQuantity]
cp [hl]
jr nc, .finish_up
ld [hl], 1
.finish_up
and a
ret
.left
ld a, [wItemQuantityChange]
sub 10
jr c, .load_1
jr z, .load_1
jr .finish_left
.load_1
ld a, 1
.finish_left
ld [wItemQuantityChange], a
and a
ret
.right
ld a, [wItemQuantityChange]
add 10
ld b, a
ld a, [wItemQuantity]
cp b
jr nc, .finish_right
ld b, a
.finish_right
ld a, b
ld [wItemQuantityChange], a
and a
ret
BuySellToss_UpdateQuantityDisplay:
call MenuBox
call MenuBoxCoord2Tile
ld de, SCREEN_WIDTH + 1
add hl, de
ld [hl], "×"
inc hl
ld de, wItemQuantityChange
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
ld a, [wMenuDataPointer]
ld e, a
ld a, [wMenuDataPointer + 1]
ld d, a
ld a, [wMenuDataBank]
call FarCall_de
ret
NoPriceToDisplay:
; Does nothing.
ret
DisplayPurchasePrice:
call BuySell_MultiplyPrice
call BuySell_DisplaySubtotal
ret
DisplaySellingPrice:
call BuySell_MultiplyPrice
call Sell_HalvePrice
call BuySell_DisplaySubtotal
ret
BuySell_MultiplyPrice:
xor a
ldh [hMultiplicand + 0], a
ld a, [wBuySellItemPrice + 0]
ldh [hMultiplicand + 1], a
ld a, [wBuySellItemPrice + 1]
ldh [hMultiplicand + 2], a
ld a, [wItemQuantityChange]
ldh [hMultiplier], a
push hl
call Multiply
pop hl
ret
Sell_HalvePrice:
push hl
ld hl, hProduct + 1
ld a, [hl]
srl a
ld [hli], a
ld a, [hl]
rra
ld [hli], a
ld a, [hl]
rra
ld [hl], a
pop hl
ret
BuySell_DisplaySubtotal:
push hl
ld hl, hMoneyTemp
ldh a, [hProduct + 1]
ld [hli], a
ldh a, [hProduct + 2]
ld [hli], a
ldh a, [hProduct + 3]
ld [hl], a
pop hl
inc hl
ld de, hMoneyTemp
lb bc, PRINTNUM_MONEY | 3, 6
call PrintNum
call WaitBGMap
ret
TossItem_MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 15, 9, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw NoPriceToDisplay
db 0 ; default option
BuyItem_MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 15, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw DisplayPurchasePrice
db -1 ; default option
SellItem_MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 15, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw DisplaySellingPrice
db 0 ; default option

File diff suppressed because it is too large Load diff

560
engine/items/items.asm Normal file
View file

@ -0,0 +1,560 @@
_ReceiveItem::
call DoesHLEqualNumItems
jp nz, PutItemInPocket
push hl
call CheckItemPocket
pop de
ld a, [wItemAttributeValue]
dec a
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to item types
dw .Item
dw .KeyItem
dw .Ball
dw .TMHM
.Item:
ld h, d
ld l, e
jp PutItemInPocket
.KeyItem:
ld h, d
ld l, e
jp ReceiveKeyItem
.Ball:
ld hl, wNumBalls
jp PutItemInPocket
.TMHM:
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
call GetTMHMNumber
jp ReceiveTMHM
_TossItem::
call DoesHLEqualNumItems
jr nz, .remove
push hl
call CheckItemPocket
pop de
ld a, [wItemAttributeValue]
dec a
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to item types
dw .Item
dw .KeyItem
dw .Ball
dw .TMHM
.Ball:
ld hl, wNumBalls
jp RemoveItemFromPocket
.TMHM:
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
call GetTMHMNumber
jp TossTMHM
.KeyItem:
ld h, d
ld l, e
jp TossKeyItem
.Item:
ld h, d
ld l, e
.remove
jp RemoveItemFromPocket
_CheckItem::
call DoesHLEqualNumItems
jr nz, .nope
push hl
call CheckItemPocket
pop de
ld a, [wItemAttributeValue]
dec a
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to item types
dw .Item
dw .KeyItem
dw .Ball
dw .TMHM
.Ball:
ld hl, wNumBalls
jp CheckTheItem
.TMHM:
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
call GetTMHMNumber
jp CheckTMHM
.KeyItem:
ld h, d
ld l, e
jp CheckKeyItems
.Item:
ld h, d
ld l, e
.nope
jp CheckTheItem
DoesHLEqualNumItems:
ld a, l
cp LOW(wNumItems)
ret nz
ld a, h
cp HIGH(wNumItems)
ret
GetPocketCapacity:
ld c, MAX_ITEMS
ld a, e
cp LOW(wNumItems)
jr nz, .not_bag
ld a, d
cp HIGH(wNumItems)
ret z
.not_bag
ld c, MAX_PC_ITEMS
ld a, e
cp LOW(wNumPCItems)
jr nz, .not_pc
ld a, d
cp HIGH(wNumPCItems)
ret z
.not_pc
ld c, MAX_BALLS
ret
PutItemInPocket:
ld d, h
ld e, l
inc hl
ld a, [wCurItem]
ld c, a
ld b, 0
.loop
ld a, [hli]
cp -1
jr z, .terminator
cp c
jr nz, .next
ld a, MAX_ITEM_STACK
sub [hl]
add b
ld b, a
ld a, [wItemQuantityChange]
cp b
jr z, .ok
jr c, .ok
.next
inc hl
jr .loop
.terminator
call GetPocketCapacity
ld a, [de]
cp c
jr c, .ok
and a
ret
.ok
ld h, d
ld l, e
ld a, [wCurItem]
ld c, a
ld a, [wItemQuantityChange]
ld [wItemQuantity], a
.loop2
inc hl
ld a, [hli]
cp -1
jr z, .terminator2
cp c
jr nz, .loop2
ld a, [wItemQuantity]
add [hl]
cp MAX_ITEM_STACK + 1
jr nc, .newstack
ld [hl], a
jr .done
.newstack
ld [hl], MAX_ITEM_STACK
sub MAX_ITEM_STACK
ld [wItemQuantity], a
jr .loop2
.terminator2
dec hl
ld a, [wCurItem]
ld [hli], a
ld a, [wItemQuantity]
ld [hli], a
ld [hl], -1
ld h, d
ld l, e
inc [hl]
.done
scf
ret
RemoveItemFromPocket:
ld d, h
ld e, l
ld a, [hli]
ld c, a
ld a, [wCurItemQuantity]
cp c
jr nc, .ok ; memory
ld c, a
ld b, 0
add hl, bc
add hl, bc
ld a, [wCurItem]
cp [hl]
inc hl
jr z, .skip
ld h, d
ld l, e
inc hl
.ok
ld a, [wCurItem]
ld b, a
.loop
ld a, [hli]
cp b
jr z, .skip
cp -1
jr z, .nope
inc hl
jr .loop
.skip
ld a, [wItemQuantityChange]
ld b, a
ld a, [hl]
sub b
jr c, .nope
ld [hl], a
ld [wItemQuantity], a
and a
jr nz, .yup
dec hl
ld b, h
ld c, l
inc hl
inc hl
.loop2
ld a, [hli]
ld [bc], a
inc bc
cp -1
jr nz, .loop2
ld h, d
ld l, e
dec [hl]
.yup
scf
ret
.nope
and a
ret
CheckTheItem:
ld a, [wCurItem]
ld c, a
.loop
inc hl
ld a, [hli]
cp -1
jr z, .done
cp c
jr nz, .loop
scf
ret
.done
and a
ret
ReceiveKeyItem:
ld hl, wNumKeyItems
ld a, [hli]
cp MAX_KEY_ITEMS
jr nc, .nope
ld c, a
ld b, 0
add hl, bc
ld a, [wCurItem]
ld [hli], a
ld [hl], -1
ld hl, wNumKeyItems
inc [hl]
scf
ret
.nope
and a
ret
TossKeyItem:
ld a, [wCurItemQuantity]
ld e, a
ld d, 0
ld hl, wNumKeyItems
ld a, [hl]
cp e
jr nc, .ok
call .Toss
ret nc
jr .ok2
.ok
dec [hl]
inc hl
add hl, de
.ok2
ld d, h
ld e, l
inc hl
.loop
ld a, [hli]
ld [de], a
inc de
cp -1
jr nz, .loop
scf
ret
.Toss:
ld hl, wNumKeyItems
ld a, [wCurItem]
ld c, a
.loop3
inc hl
ld a, [hl]
cp c
jr z, .ok3
cp -1
jr nz, .loop3
xor a
ret
.ok3
ld a, [wNumKeyItems]
dec a
ld [wNumKeyItems], a
scf
ret
CheckKeyItems:
ld a, [wCurItem]
ld c, a
ld hl, wKeyItems
.loop
ld a, [hli]
cp c
jr z, .done
cp -1
jr nz, .loop
and a
ret
.done
scf
ret
ReceiveTMHM:
dec c
ld b, 0
ld hl, wTMsHMs
add hl, bc
ld a, [wItemQuantityChange]
add [hl]
cp MAX_ITEM_STACK + 1
jr nc, .toomany
ld [hl], a
scf
ret
.toomany
and a
ret
TossTMHM:
dec c
ld b, 0
ld hl, wTMsHMs
add hl, bc
ld a, [wItemQuantityChange]
ld b, a
ld a, [hl]
sub b
jr c, .nope
ld [hl], a
ld [wItemQuantity], a
jr nz, .yup
ld a, [wTMHMPocketScrollPosition]
and a
jr z, .yup
dec a
ld [wTMHMPocketScrollPosition], a
.yup
scf
ret
.nope
and a
ret
CheckTMHM:
dec c
ld b, $0
ld hl, wTMsHMs
add hl, bc
ld a, [hl]
and a
ret z
scf
ret
GetTMHMNumber::
; Return the number of a TM/HM by item id c.
ld a, c
sub TM01 - 1
ld c, a
ret
GetNumberedTMHM:
; Return the item id of a TM/HM by number c.
ld a, c
add a, TM01 - 1
ld c, a
ret
_CheckTossableItem::
; Return 1 in wItemAttributeValue and carry if wCurItem can't be removed from the bag.
ld a, ITEMATTR_PERMISSIONS
call GetItemAttr
bit CANT_TOSS_F, a
jr nz, ItemAttr_ReturnCarry
and a
ret
CheckSelectableItem:
; Return 1 in wItemAttributeValue and carry if wCurItem can't be selected.
ld a, ITEMATTR_PERMISSIONS
call GetItemAttr
bit CANT_SELECT_F, a
jr nz, ItemAttr_ReturnCarry
and a
ret
CheckItemPocket::
; Return the pocket for wCurItem in wItemAttributeValue.
ld a, ITEMATTR_POCKET
call GetItemAttr
and $f
ld [wItemAttributeValue], a
ret
CheckItemContext:
; Return the context for wCurItem in wItemAttributeValue.
ld a, ITEMATTR_HELP
call GetItemAttr
and $f
ld [wItemAttributeValue], a
ret
CheckItemMenu:
; Return the menu for wCurItem in wItemAttributeValue.
ld a, ITEMATTR_HELP
call GetItemAttr
swap a
and $f
ld [wItemAttributeValue], a
ret
GetItemAttr:
; Get attribute a of wCurItem.
push hl
push bc
ld hl, ItemAttributes
ld c, a
ld b, 0
add hl, bc
xor a
ld [wItemAttributeValue], a
ld a, [wCurItem]
dec a
ld c, a
ld a, ITEMATTR_STRUCT_LENGTH
call AddNTimes
ld a, BANK(ItemAttributes)
call GetFarByte
pop bc
pop hl
ret
ItemAttr_ReturnCarry:
ld a, 1
ld [wItemAttributeValue], a
scf
ret
GetItemPrice:
; Return the price of wCurItem in de.
push hl
push bc
ld a, ITEMATTR_PRICE_LO
call GetItemAttr
ld e, a
ld a, ITEMATTR_PRICE_HI
call GetItemAttr
ld d, a
pop bc
pop hl
ret

866
engine/items/mart.asm Normal file
View file

@ -0,0 +1,866 @@
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
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
dw RooftopSale
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
RooftopSale:
ld b, BANK(RooftopSaleMart1)
ld de, RooftopSaleMart1
ld hl, wStatusFlags
bit STATUSFLAGS_HALL_OF_FAME_F, [hl]
jr z, .ok
ld b, BANK(RooftopSaleMart2)
ld de, RooftopSaleMart2
.ok
call LoadMartPointer
call ReadMart
call LoadStandardMenuHeader
ld hl, MartWelcomeText
call MartTextbox
call BuyMenu
ld hl, MartComeAgainText
call MartTextbox
ret
INCLUDE "data/items/rooftop_sale.asm"
LoadMartPointer:
ld a, b
ld [wMartPointerBank], a
ld a, e
ld [wMartPointer], a
ld a, d
ld [wMartPointer + 1], a
ld hl, wCurMartCount
assert wCurMartCount + 1 == wCurMartItems
xor a
ld bc, 16
call ByteFill
xor a ; STANDARDMART_HOWMAYIHELPYOU
ld [wMartJumptableIndex], a
ld [wBargainShopFlags], a
ld [wFacingDirection], a
ret
GetMart:
ld a, e
cp NUM_MARTS
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
; 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
DEF 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, wCurMartCount
.CopyMart:
ld a, [wMartPointerBank]
call GetFarByte
ld [de], a
inc hl
inc de
cp -1
jr nz, .CopyMart
ld hl, wMartItem1BCD
ld de, wCurMartItems
.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, wCurMartItems
.loop
; copy the items to wCurMartItems
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 [wCurMartCount], a
ret
INCLUDE "data/items/bargain_shop.asm"
BuyMenu:
call FadeToMenu
farcall BlankScreen
xor a
ld [wMenuScrollPositionBackup], a
ld a, 1
ld [wMenuCursorPositionBackup], 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
cp 1
jp z, BargainShopAskPurchaseQuantity
jp RooftopSaleAskPurchaseQuantity
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
dwb .StandardMartPointers, 2
.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, [wMenuCursorPositionBackup]
ld [wMenuCursorPosition], a
ld a, [wMenuScrollPositionBackup]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wMenuScrollPositionBackup], a
ld a, [wMenuCursorY]
ld [wMenuCursorPositionBackup], 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, MAX_ITEM_STACK
ld [wItemQuantity], 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 [wItemQuantityChange], 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
RooftopSaleAskPurchaseQuantity:
ld a, MARTTEXT_HOW_MANY
call LoadBuyMenuText
call .GetSalePrice
ld a, MAX_ITEM_STACK
ld [wItemQuantity], a
farcall RooftopSale_SelectQuantityToBuy
call ExitMenu
ret
.GetSalePrice:
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 e, [hl]
inc hl
ld d, [hl]
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, wCurMartCount
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
.NothingToSell: ; unreferenced
ld hl, .NothingToSellText
call MenuTextboxBackup
and a
ret
.NothingToSellText:
text_far _NothingToSellText
text_end
.TryToSellItem:
farcall CheckItemMenu
ld a, [wItemAttributeValue]
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, [wItemAttributeValue]
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
UnusedDummyString: ; unreferenced
db "!ダミー!@" ; "!Dummy!"
MartWelcomeText:
text_far _MartWelcomeText
text_end
MenuHeader_BuySell:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, 7, 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

1581
engine/items/pack.asm Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
DrawKrisPackGFX:
ld hl, PackFGFXPointers
add hl, de
add hl, de
ld a, [hli]
ld e, a
ld d, [hl]
ld hl, vTiles2 tile $50
lb bc, BANK(PackFGFX), 15
call Request2bpp
ret
PackFGFXPointers:
dw PackFGFX + (15 tiles) * 1 ; ITEM_POCKET
dw PackFGFX + (15 tiles) * 3 ; BALL_POCKET
dw PackFGFX + (15 tiles) * 0 ; KEY_ITEM_POCKET
dw PackFGFX + (15 tiles) * 2 ; TM_HM_POCKET
PackFGFX:
INCBIN "gfx/pack/pack_f.2bpp"

View file

@ -0,0 +1,32 @@
PrintItemDescription:
; Print the description for item [wCurSpecies] at de.
ld a, [wCurSpecies]
cp TM01
jr c, .not_a_tm
ld [wCurItem], a
push de
farcall GetTMHMItemMove
pop hl
ld a, [wTempTMHM]
ld [wCurSpecies], a
predef PrintMoveDescription
ret
.not_a_tm
push de
ld hl, ItemDescriptions
ld a, [wCurSpecies]
dec a
ld c, a
ld b, 0
add hl, bc
add hl, bc
ld e, [hl]
inc hl
ld d, [hl]
pop hl
jp PlaceString
INCLUDE "data/items/descriptions.asm"

View file

@ -0,0 +1,272 @@
SwitchItemsInBag:
ld a, [wSwitchItem]
and a
jr z, .init
ld b, a
ld a, [wScrollingMenuCursorPosition]
inc a
cp b
jr z, .trivial
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
ld a, [hl]
cp -1
ret z
ld a, [wSwitchItem]
dec a
ld [wSwitchItem], a
call .try_combining_stacks
jp c, .combine_stacks
ld a, [wScrollingMenuCursorPosition]
ld c, a
ld a, [wSwitchItem]
cp c
jr c, .above
jr .below
.init:
ld a, [wScrollingMenuCursorPosition]
inc a
ld [wSwitchItem], a
ret
.trivial:
xor a
ld [wSwitchItem], a
ret
.below:
ld a, [wSwitchItem]
call ItemSwitch_CopyItemToBuffer
ld a, [wScrollingMenuCursorPosition]
ld d, a
ld a, [wSwitchItem]
ld e, a
call ItemSwitch_GetItemOffset
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
dec hl
push hl
call ItemSwitch_GetItemFormatSize
add hl, bc
ld d, h
ld e, l
pop hl
pop bc
call ItemSwitch_BackwardsCopyBytes
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_CopyBufferToItem
xor a
ld [wSwitchItem], a
ret
.above:
ld a, [wSwitchItem]
call ItemSwitch_CopyItemToBuffer
ld a, [wScrollingMenuCursorPosition]
ld d, a
ld a, [wSwitchItem]
ld e, a
call ItemSwitch_GetItemOffset
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld d, h
ld e, l
call ItemSwitch_GetItemFormatSize
add hl, bc
pop bc
call CopyBytes
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_CopyBufferToItem
xor a
ld [wSwitchItem], a
ret
.try_combining_stacks:
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld d, h
ld e, l
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
ld a, [de]
cp [hl]
jr nz, .no_combine
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetItemQuantity
cp MAX_ITEM_STACK
jr z, .no_combine
ld a, [wSwitchItem]
call ItemSwitch_GetItemQuantity
cp MAX_ITEM_STACK
jr nz, .combine
.no_combine
and a
ret
.combine
scf
ret
.combine_stacks:
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
inc hl
push hl
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
inc hl
ld a, [hl]
pop hl
add [hl]
cp MAX_ITEM_STACK + 1
jr c, .merge_stacks
sub MAX_ITEM_STACK
push af
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
inc hl
ld [hl], MAX_ITEM_STACK
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
inc hl
pop af
ld [hl], a
xor a
ld [wSwitchItem], a
ret
.merge_stacks:
push af
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
inc hl
pop af
ld [hl], a
ld hl, wMenuData_ItemsPointerAddr
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wSwitchItem]
cp [hl]
jr nz, .not_combining_last_item
dec [hl]
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld [hl], -1 ; end
xor a
ld [wSwitchItem], a
ret
.not_combining_last_item:
dec [hl]
call ItemSwitch_GetItemFormatSize
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
pop bc
push hl
add hl, bc
pop de
.copy_loop
ld a, [hli]
ld [de], a
inc de
cp -1 ; end?
jr nz, .copy_loop
xor a
ld [wSwitchItem], a
ret
ItemSwitch_CopyItemToBuffer:
call ItemSwitch_GetNthItem
ld de, wSwitchItemBuffer
call ItemSwitch_GetItemFormatSize
call CopyBytes
ret
ItemSwitch_CopyBufferToItem:
call ItemSwitch_GetNthItem
ld d, h
ld e, l
ld hl, wSwitchItemBuffer
call ItemSwitch_GetItemFormatSize
call CopyBytes
ret
ItemSwitch_GetNthItem:
push af
call ItemSwitch_GetItemFormatSize
ld hl, wMenuData_ItemsPointerAddr
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
pop af
call AddNTimes
ret
ItemSwitch_GetItemOffset:
push hl
call ItemSwitch_GetItemFormatSize
ld a, d
sub e
jr nc, .dont_negate
dec a
cpl
.dont_negate
ld hl, 0
call AddNTimes
ld b, h
ld c, l
pop hl
ret
ItemSwitch_GetItemFormatSize:
push hl
ld a, [wMenuData_ScrollingMenuItemFormat]
ld c, a
ld b, 0
ld hl, .item_format_sizes
add hl, bc
add hl, bc
ld c, [hl]
inc hl
ld b, [hl]
pop hl
ret
.item_format_sizes:
; entries correspond to SCROLLINGMENU_ITEMS_* constants
dw 0 ; unused
dw 1 ; SCROLLINGMENU_ITEMS_NORMAL
dw 2 ; SCROLLINGMENU_ITEMS_QUANTITY
ItemSwitch_GetItemQuantity:
push af
call ItemSwitch_GetItemFormatSize
ld a, c
cp 2
jr nz, .no_quantity
pop af
call ItemSwitch_GetNthItem
inc hl
ld a, [hl]
ret
.no_quantity
pop af
ld a, 1
ret
ItemSwitch_BackwardsCopyBytes:
.loop
ld a, [hld]
ld [de], a
dec de
dec bc
ld a, b
or c
jr nz, .loop
ret

554
engine/items/tmhm.asm Normal file
View file

@ -0,0 +1,554 @@
TMHMPocket:
ld a, $1
ldh [hInMenu], a
call TMHM_PocketLoop
ld a, $0
ldh [hInMenu], a
ret nc
call PlaceHollowCursor
call WaitBGMap
ld a, [wCurItem]
dec a
ld [wCurItemQuantity], a
ld hl, wTMsHMs
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
ld [wItemQuantity], a
call .ConvertItemToTMHMNumber
scf
ret
.ConvertItemToTMHMNumber:
ld a, [wCurItem]
ld c, a
callfar GetNumberedTMHM
ld a, c
ld [wCurItem], a
ret
ConvertCurItemIntoCurTMHM:
ld a, [wCurItem]
ld c, a
callfar GetTMHMNumber
ld a, c
ld [wTempTMHM], a
ret
GetTMHMItemMove:
call ConvertCurItemIntoCurTMHM
predef GetTMHMMove
ret
AskTeachTMHM:
ld hl, wOptions
ld a, [hl]
push af
res NO_TEXT_SCROLL, [hl]
ld a, [wCurItem]
cp TM01
jr c, .NotTMHM
call GetTMHMItemMove
ld a, [wTempTMHM]
ld [wPutativeTMHMMove], a
call GetMoveName
call CopyName1
ld hl, BootedTMText ; Booted up a TM
ld a, [wCurItem]
cp HM01
jr c, .TM
ld hl, BootedHMText ; Booted up an HM
.TM:
call PrintText
ld hl, ContainedMoveText
call PrintText
call YesNoBox
.NotTMHM:
pop bc
ld a, b
ld [wOptions], a
ret
ChooseMonToLearnTMHM:
ld hl, wStringBuffer2
ld de, wTMHMMoveNameBackup
ld bc, MOVE_NAME_LENGTH - 1
call CopyBytes
call ClearBGPalettes
ChooseMonToLearnTMHM_NoRefresh:
farcall LoadPartyMenuGFX
farcall InitPartyMenuWithCancel
farcall InitPartyMenuGFX
ld a, PARTYMENUACTION_TEACH_TMHM
ld [wPartyMenuActionText], a
.loopback
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
call WaitBGMap
call SetPalettes
call DelayFrame
farcall PartyMenuSelect
push af
ld a, [wCurPartySpecies]
cp EGG
pop bc ; now contains the former contents of af
jr z, .egg
push bc
ld hl, wTMHMMoveNameBackup
ld de, wStringBuffer2
ld bc, MOVE_NAME_LENGTH - 1
call CopyBytes
pop af ; now contains the original contents of af
ret
.egg
push hl
push de
push bc
push af
ld de, SFX_WRONG
call PlaySFX
call WaitSFX
pop af
pop bc
pop de
pop hl
jr .loopback
TeachTMHM:
predef CanLearnTMHMMove
push bc
ld a, [wCurPartyMon]
ld hl, wPartyMonNicknames
call GetNickname
pop bc
ld a, c
and a
jr nz, .compatible
push de
ld de, SFX_WRONG
call PlaySFX
pop de
ld hl, TMHMNotCompatibleText
call PrintText
jr .nope
.compatible
callfar KnowsMove
jr c, .nope
predef LearnMove
ld a, b
and a
jr z, .nope
farcall StubbedTrainerRankings_TMsHMsTaught
ld a, [wCurItem]
call IsHM
ret c
ld c, HAPPINESS_LEARNMOVE
callfar ChangeHappiness
call ConsumeTM
jr .learned_move
.nope
and a
ret
.didnt_use ; unreferenced
ld a, 2
ld [wItemEffectSucceeded], a
.learned_move
scf
ret
BootedTMText:
text_far _BootedTMText
text_end
BootedHMText:
text_far _BootedHMText
text_end
ContainedMoveText:
text_far _ContainedMoveText
text_end
TMHMNotCompatibleText:
text_far _TMHMNotCompatibleText
text_end
TMHM_PocketLoop:
xor a
ldh [hBGMapMode], a
call TMHM_DisplayPocketItems
ld a, 2
ld [w2DMenuCursorInitY], a
ld a, 7
ld [w2DMenuCursorInitX], a
ld a, 1
ld [w2DMenuNumCols], a
ld a, 5
sub d
inc a
cp 6
jr nz, .okay
dec a
.okay
ld [w2DMenuNumRows], a
ld a, $c
ld [w2DMenuFlags1], a
xor a
ld [w2DMenuFlags2], a
ld a, $20
ld [w2DMenuCursorOffsets], a
ld a, A_BUTTON | B_BUTTON | D_UP | D_DOWN | D_LEFT | D_RIGHT
ld [wMenuJoypadFilter], a
ld a, [wTMHMPocketCursor]
inc a
ld [wMenuCursorY], a
ld a, $1
ld [wMenuCursorX], a
jr TMHM_ShowTMMoveDescription
TMHM_JoypadLoop:
call TMHM_DisplayPocketItems
call StaticMenuJoypad
ld b, a
ld a, [wMenuCursorY]
dec a
ld [wTMHMPocketCursor], a
xor a
ldh [hBGMapMode], a
ld a, [w2DMenuFlags2]
bit 7, a
jp nz, TMHM_ScrollPocket
ld a, b
ld [wMenuJoypad], a
bit A_BUTTON_F, a
jp nz, TMHM_ChooseTMorHM
bit B_BUTTON_F, a
jp nz, TMHM_ExitPack
bit D_RIGHT_F, a
jp nz, TMHM_ExitPocket
bit D_LEFT_F, a
jp nz, TMHM_ExitPocket
TMHM_ShowTMMoveDescription:
call TMHM_CheckHoveringOverCancel
jp nc, TMHM_ExitPocket
hlcoord 0, 12
ld b, 4
ld c, SCREEN_WIDTH - 2
call Textbox
ld a, [wCurItem]
cp NUM_TMS + NUM_HMS + 1
jr nc, TMHM_JoypadLoop
ld [wTempTMHM], a
predef GetTMHMMove
ld a, [wTempTMHM]
ld [wCurSpecies], a
hlcoord 1, 14
call PrintMoveDescription
jp TMHM_JoypadLoop
TMHM_ChooseTMorHM:
call TMHM_PlaySFX_ReadText2
call CountTMsHMs ; This stores the count to wTempTMHM.
ld a, [wMenuCursorY]
dec a
ld b, a
ld a, [wTMHMPocketScrollPosition]
add b
ld b, a
ld a, [wTempTMHM]
cp b
jr z, _TMHM_ExitPack ; our cursor was hovering over CANCEL
TMHM_CheckHoveringOverCancel:
call TMHM_GetCurrentPocketPosition
ld a, [wMenuCursorY]
ld b, a
.loop
inc c
ld a, c
cp NUM_TMS + NUM_HMS + 1
jr nc, .okay
ld a, [hli]
and a
jr z, .loop
dec b
jr nz, .loop
ld a, c
.okay
ld [wCurItem], a
cp -1
ret
TMHM_ExitPack:
call TMHM_PlaySFX_ReadText2
_TMHM_ExitPack:
ld a, B_BUTTON
ld [wMenuJoypad], a
and a
ret
TMHM_ExitPocket:
and a
ret
TMHM_ScrollPocket:
ld a, b
bit 7, a
jr nz, .skip
ld hl, wTMHMPocketScrollPosition
ld a, [hl]
and a
jp z, TMHM_JoypadLoop
dec [hl]
call TMHM_DisplayPocketItems
jp TMHM_ShowTMMoveDescription
.skip
call TMHM_GetCurrentPocketPosition
ld b, 5
.loop
inc c
ld a, c
cp NUM_TMS + NUM_HMS + 1
jp nc, TMHM_JoypadLoop
ld a, [hli]
and a
jr z, .loop
dec b
jr nz, .loop
ld hl, wTMHMPocketScrollPosition
inc [hl]
call TMHM_DisplayPocketItems
jp TMHM_ShowTMMoveDescription
TMHM_DisplayPocketItems:
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
jp z, Tutorial_TMHMPocket
hlcoord 5, 2
lb bc, 10, 15
ld a, " "
call ClearBox
call TMHM_GetCurrentPocketPosition
ld d, $5
.loop2
inc c
ld a, c
cp NUM_TMS + NUM_HMS + 1
jr nc, .NotTMHM
ld a, [hli]
and a
jr z, .loop2
ld b, a
ld a, c
ld [wTempTMHM], a
push hl
push de
push bc
call TMHMPocket_GetCurrentLineCoord
push hl
ld a, [wTempTMHM]
cp NUM_TMS + 1
jr nc, .HM
ld de, wTempTMHM
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
jr .okay
.HM:
push af
sub NUM_TMS
ld [wTempTMHM], a
ld [hl], "H"
inc hl
ld de, wTempTMHM
lb bc, PRINTNUM_LEFTALIGN | 1, 2
call PrintNum
pop af
ld [wTempTMHM], a
.okay
predef GetTMHMMove
ld a, [wNamedObjectIndex]
ld [wPutativeTMHMMove], a
call GetMoveName
pop hl
ld bc, 3
add hl, bc
push hl
call PlaceString
pop hl
pop bc
ld a, c
push bc
cp NUM_TMS + 1
jr nc, .hm2
ld bc, SCREEN_WIDTH + 9
add hl, bc
ld [hl], "×"
inc hl
ld a, "0" ; why are we doing this?
pop bc
push bc
ld a, b
ld [wTempTMHM], a
ld de, wTempTMHM
lb bc, 1, 2
call PrintNum
.hm2
pop bc
pop de
pop hl
dec d
jr nz, .loop2
jr .done
.NotTMHM:
call TMHMPocket_GetCurrentLineCoord
inc hl
inc hl
inc hl
push de
ld de, TMHM_CancelString
call PlaceString
pop de
.done
ret
TMHMPocket_GetCurrentLineCoord:
hlcoord 5, 0
ld bc, 2 * SCREEN_WIDTH
ld a, 6
sub d
ld e, a
; AddNTimes
.loop
add hl, bc
dec e
jr nz, .loop
ret
PlaceMoveNameAfterTMHMName: ; unreferenced
; Similar to a part of TMHM_DisplayPocketItems.
pop hl
ld bc, 3
add hl, bc
predef GetTMHMMove
ld a, [wTempTMHM]
ld [wPutativeTMHMMove], a
call GetMoveName
push hl
call PlaceString
pop hl
ret
TMHM_CancelString:
db "CANCEL@"
TMHM_GetCurrentPocketPosition:
ld hl, wTMsHMs
ld a, [wTMHMPocketScrollPosition]
ld b, a
inc b
ld c, 0
.loop
inc c
ld a, [hli]
and a
jr z, .loop
dec b
jr nz, .loop
dec hl
dec c
ret
Tutorial_TMHMPocket:
hlcoord 9, 3
push de
ld de, TMHM_CancelString
call PlaceString
pop de
ret
TMHM_PlaySFX_ReadText2:
push de
ld de, SFX_READ_TEXT_2
call PlaySFX
pop de
ret
VerboseReceiveTMHM: ; unreferenced
call ConvertCurItemIntoCurTMHM
call .CheckHaveRoomForTMHM
ld hl, .NoRoomTMHMText
jr nc, .print
ld hl, .ReceivedTMHMText
.print
jp PrintText
.NoRoomTMHMText:
text_far _NoRoomTMHMText
text_end
.ReceivedTMHMText:
text_far _ReceivedTMHMText
text_end
.CheckHaveRoomForTMHM:
ld a, [wTempTMHM]
dec a
ld hl, wTMsHMs
ld b, 0
ld c, a
add hl, bc
ld a, [hl]
inc a
cp MAX_ITEM_STACK + 1
ret nc
ld [hl], a
ret
ConsumeTM:
call ConvertCurItemIntoCurTMHM
ld a, [wTempTMHM]
dec a
ld hl, wTMsHMs
ld b, 0
ld c, a
add hl, bc
ld a, [hl]
and a
ret z
dec a
ld [hl], a
ret nz
ld a, [wTMHMPocketScrollPosition]
and a
ret z
dec a
ld [wTMHMPocketScrollPosition], a
ret
CountTMsHMs:
ld b, 0
ld c, NUM_TMS + NUM_HMS
ld hl, wTMsHMs
.loop
ld a, [hli]
and a
jr z, .skip
inc b
.skip
dec c
jr nz, .loop
ld a, b
ld [wTempTMHM], a
ret

57
engine/items/tmhm2.asm Normal file
View file

@ -0,0 +1,57 @@
CanLearnTMHMMove:
ld a, [wCurPartySpecies]
ld [wCurSpecies], a
call GetBaseData
ld hl, wBaseTMHM
push hl
ld a, [wPutativeTMHMMove]
call GetMoveIndexFromID
ld b, h
ld c, l
ld hl, TMHMMoves
.loop
ld a, [hli]
or [hl]
jr z, .end
dec hl
ld a, [hli]
cp c
ld a, [hli]
jr nz, .loop
cp b
jr nz, .loop
ld a, l
sub LOW(TMHMMoves + 2)
rrca
ld c, a
pop hl
ld b, CHECK_FLAG
push de
ld d, 0
predef SmallFarFlagAction
pop de
ret
.end
pop hl
ld c, 0
ret
GetTMHMMove:
ld a, [wTempTMHM]
dec a
add a, a
ld hl, TMHMMoves
ld b, 0
ld c, a
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
call GetMoveIDFromIndex
ld [wTempTMHM], a
ret
INCLUDE "data/moves/tmhm_moves.asm"

View file

@ -0,0 +1,13 @@
UpdateItemDescription:
ld a, [wMenuSelection]
ld [wCurSpecies], a
hlcoord 0, 12
ld b, 4
ld c, SCREEN_WIDTH - 2
call Textbox
ld a, [wMenuSelection]
cp -1
ret z
decoord 1, 14
farcall PrintItemDescription
ret