diff options
Diffstat (limited to 'engine/items')
-rw-r--r-- | engine/items/buy_sell_toss.asm | 218 | ||||
-rw-r--r-- | engine/items/switch_items.asm | 272 | ||||
-rw-r--r-- | engine/items/update_item_description.asm | 13 |
3 files changed, 503 insertions, 0 deletions
diff --git a/engine/items/buy_sell_toss.asm b/engine/items/buy_sell_toss.asm new file mode 100644 index 00000000..45c3dfcf --- /dev/null +++ b/engine/items/buy_sell_toss.asm @@ -0,0 +1,218 @@ +SelectQuantityToToss: + ld hl, TossItem_MenuHeader + call LoadMenuHeader + call Toss_Sell_Loop + ret + +SelectQuantityToBuy: + farcall GetItemPrice + ld a, d + ld [wBuffer1], a + ld a, e + ld [wBuffer2], a + ld hl, BuyItem_MenuHeader + call LoadMenuHeader + call Toss_Sell_Loop + ret + +SelectQuantityToSell: + farcall GetItemPrice + ld a, d + ld [wBuffer1], a + ld a, e + ld [wBuffer2], a + ld hl, SellItem_MenuHeader + call LoadMenuHeader + call Toss_Sell_Loop + ret + +Toss_Sell_Loop: + ld a, 1 + ld [wItemQuantityChangeBuffer], 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, wItemQuantityChangeBuffer + dec [hl] + jr nz, .finish_down + ld a, [wItemQuantityBuffer] + ld [hl], a + +.finish_down + and a + ret + +.up + ld hl, wItemQuantityChangeBuffer + inc [hl] + ld a, [wItemQuantityBuffer] + cp [hl] + jr nc, .finish_up + ld [hl], 1 + +.finish_up + and a + ret + +.left + ld a, [wItemQuantityChangeBuffer] + sub 10 + jr c, .load_1 + jr z, .load_1 + jr .finish_left + +.load_1 + ld a, 1 + +.finish_left + ld [wItemQuantityChangeBuffer], a + and a + ret + +.right + ld a, [wItemQuantityChangeBuffer] + add 10 + ld b, a + ld a, [wItemQuantityBuffer] + cp b + jr nc, .finish_right + ld b, a + +.finish_right + ld a, b + ld [wItemQuantityChangeBuffer], a + and a + ret + +BuySellToss_UpdateQuantityDisplay: + call MenuBox + call MenuBoxCoord2Tile + ld de, SCREEN_WIDTH + 1 + add hl, de + ld [hl], "×" + inc hl + ld de, wItemQuantityChangeBuffer + lb bc, PRINTNUM_LEADINGZEROS | 1, 2 + call PrintNum + ld a, [wMenuDataPointer] + ld e, a + ld a, [wMenuDataPointer + 1] + ld d, a + push de + ret + +ret_24ff3: + 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, [wBuffer1] + ldh [hMultiplicand + 1], a + ld a, [wBuffer2] + ldh [hMultiplicand + 2], a + ld a, [wItemQuantityChangeBuffer] + 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 ret_24ff3 + 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 diff --git a/engine/items/switch_items.asm b/engine/items/switch_items.asm new file mode 100644 index 00000000..283823e4 --- /dev/null +++ b/engine/items/switch_items.asm @@ -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 Function248cf + jp c, Function248f9 + ld a, [wScrollingMenuCursorPosition] + ld c, a + ld a, [wSwitchItem] + cp c + jr c, .asm_248a2 + jr .asm_24872 + +.init + ld a, [wScrollingMenuCursorPosition] + inc a + ld [wSwitchItem], a + ret + +.trivial + xor a + ld [wSwitchItem], a + ret + +.asm_24872 + ld a, [wSwitchItem] + call Function24968 + ld a, [wScrollingMenuCursorPosition] + ld d, a + ld a, [wSwitchItem] + ld e, a + call Function24994 + push bc + ld a, [wSwitchItem] + call ItemSwitch_GetNthItem + dec hl + push hl + call ItemSwitch_ConvertItemFormatToDW + add hl, bc + ld d, h + ld e, l + pop hl + pop bc + call Function249d3 + ld a, [wScrollingMenuCursorPosition] + call Function24975 + xor a + ld [wSwitchItem], a + ret + +.asm_248a2 + ld a, [wSwitchItem] + call Function24968 + ld a, [wScrollingMenuCursorPosition] + ld d, a + ld a, [wSwitchItem] + ld e, a + call Function24994 + push bc + ld a, [wSwitchItem] + call ItemSwitch_GetNthItem + ld d, h + ld e, l + call ItemSwitch_ConvertItemFormatToDW + add hl, bc + pop bc + call CopyBytes + ld a, [wScrollingMenuCursorPosition] + call Function24975 + xor a + ld [wSwitchItem], a + ret + +Function248cf: + 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, .asm_249cd + ld a, [wScrollingMenuCursorPosition] + call Function249bf + cp 99 + jr z, .asm_249cd + ld a, [wSwitchItem] + call Function249bf + cp 99 + jr nz, .asm_249cf +.asm_249cd + and a + ret + +.asm_249cf + scf + ret + +Function248f9: + 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 100 + jr c, .asm_24a01 + sub 99 + push af + ld a, [wScrollingMenuCursorPosition] + call ItemSwitch_GetNthItem + inc hl + ld [hl], 99 + ld a, [wSwitchItem] + call ItemSwitch_GetNthItem + inc hl + pop af + ld [hl], a + xor a + ld [wSwitchItem], a + ret + +.asm_24a01 + 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, .asm_24a25 + dec [hl] + ld a, [wSwitchItem] + call ItemSwitch_GetNthItem + ld [hl], $ff + xor a + ld [wSwitchItem], a + ret + +.asm_24a25 + dec [hl] + call ItemSwitch_ConvertItemFormatToDW + push bc + ld a, [wSwitchItem] + call ItemSwitch_GetNthItem + pop bc + push hl + add hl, bc + pop de +.asm_24a34 + ld a, [hli] + ld [de], a + inc de + cp $ff + jr nz, .asm_24a34 + xor a + ld [wSwitchItem], a + ret + +Function24968: + call ItemSwitch_GetNthItem + ld de, wceed + call ItemSwitch_ConvertItemFormatToDW + call CopyBytes + ret + +Function24975: + call ItemSwitch_GetNthItem + ld d, h + ld e, l + ld hl, wceed + call ItemSwitch_ConvertItemFormatToDW + call CopyBytes + ret + +ItemSwitch_GetNthItem: + push af + call ItemSwitch_ConvertItemFormatToDW + ld hl, wMenuData_ItemsPointerAddr + ld a, [hli] + ld h, [hl] + ld l, a + inc hl + pop af + call AddNTimes + ret + +Function24994: + push hl + call ItemSwitch_ConvertItemFormatToDW + 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_ConvertItemFormatToDW: + push hl + ld a, [wMenuData_ScrollingMenuItemFormat] + ld c, a + ld b, 0 + ld hl, .format_dws + add hl, bc + add hl, bc + ld c, [hl] + inc hl + ld b, [hl] + pop hl + ret + +.format_dws + dw 0 + dw 1 + dw 2 + +Function249bf: + push af + call ItemSwitch_ConvertItemFormatToDW + ld a, c + cp 2 + jr nz, .not_2 + pop af + call ItemSwitch_GetNthItem + inc hl + ld a, [hl] + ret + +.not_2 + pop af + ld a, $1 + ret + +Function249d3: +.loop + ld a, [hld] + ld [de], a + dec de + dec bc + ld a, b + or c + jr nz, .loop + ret diff --git a/engine/items/update_item_description.asm b/engine/items/update_item_description.asm new file mode 100644 index 00000000..da56732a --- /dev/null +++ b/engine/items/update_item_description.asm @@ -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 |