SelectQuantityToToss:
	ld hl, TossItem_MenuDataHeader
	call LoadMenuDataHeader
	jr Toss_Sell_Loop

SelectQuantityToBuy:
	callba GetItemPrice
RooftopSale_SelectQuantityToBuy:
	ld a, d
	ld [wCurItemPrice], a
	ld a, e
	ld [wCurItemPrice + 1], a
	ld hl, BuyItem_MenuDataHeader
	call LoadMenuDataHeader
	jr Toss_Sell_Loop

SelectQuantityToSell:
	callba GetItemPrice
	ld a, d
	ld [wCurItemPrice], a
	ld a, e
	ld [wCurItemPrice + 1], a
	ld hl, SellItem_MenuDataHeader
	call LoadMenuDataHeader
	; fallthrough

Toss_Sell_Loop:
	ld a, 1
	ld [wItemQuantityChangeBuffer], a
	ld [hBGMapMode], a
.loop
	call BuySellToss_UpdateQuantityDisplay
	call BuySellToss_InterpretJoypad
	jr nc, .loop
	cp -1
	jr nz, .nope ; pressed B
	scf
	ret

.nope
	and a
	ret

BuySellToss_InterpretJoypad:
	call GetJoypadForQuantitySelectionMenus
	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
	xor a
	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, [wMenuData2Pointer]
	ld c, a
	ld a, [wMenuData2Pointer + 1]
	ld b, a
	or b
	ret z
	push hl
	ld h, b
	ld l, c
	ld a, [wMenuDataBank]
	call FarCall_hl
	ld hl, hMoneyTemp
	ld a, [hProduct + 1]
	ld [hli], a
	ld a, [hProduct + 2]
	ld [hli], a
	ld a, [hProduct + 3]
	ld [hl], a
	pop hl
	inc hl
	ld de, hMoneyTemp
	lb bc, PRINTNUM_MONEY | 3, 6
	jp PrintNum

BuySell_MultiplyPrice:
	xor a
	ld [hMultiplicand + 0], a
	ld a, [wCurItemPrice]
	ld [hMultiplicand + 1], a
	ld a, [wCurItemPrice + 1]
	ld [hMultiplicand + 2], a
	ld a, [wItemQuantityChangeBuffer]
	ld [hMultiplier], a
	predef_jump Multiply

DisplaySellingPrice:
	call BuySell_MultiplyPrice
	ld hl, hProduct + 1
	srl [hl]
	inc hl
	rr [hl]
	inc hl
	rr [hl]
	ret

TossItem_MenuDataHeader:
	db $40 ; flags
	db 09, 15 ; start coords
	db 11, 19 ; end coords
	dw NULL
	db 0 ; default option

BuyItem_MenuDataHeader:
	db $40 ; flags
	db 15, 07 ; start coords
	db 17, 19 ; end coords
	dw BuySell_MultiplyPrice
	db -1 ; default option

SellItem_MenuDataHeader:
	db $40 ; flags
	db 15, 07 ; start coords
	db 17, 19 ; end coords
	dw DisplaySellingPrice
	db 0 ; default option
