2018-06-24 14:09:41 +00:00
|
|
|
SwitchItemsInBag:
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [wSwitchItem]
|
|
|
|
and a
|
|
|
|
jr z, .init
|
|
|
|
ld b, a
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-13 19:15:16 +00:00
|
|
|
inc a
|
|
|
|
cp b
|
|
|
|
jr z, .trivial
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [hl]
|
2015-12-23 19:00:29 +00:00
|
|
|
cp -1
|
2015-12-13 19:15:16 +00:00
|
|
|
ret z
|
|
|
|
ld a, [wSwitchItem]
|
|
|
|
dec a
|
|
|
|
ld [wSwitchItem], a
|
2020-10-21 19:39:15 +00:00
|
|
|
call .try_combining_stacks
|
|
|
|
jp c, .combine_stacks
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-13 19:15:16 +00:00
|
|
|
ld c, a
|
|
|
|
ld a, [wSwitchItem]
|
|
|
|
cp c
|
2020-10-21 19:39:15 +00:00
|
|
|
jr c, .above
|
|
|
|
jr .below
|
2015-12-13 19:15:16 +00:00
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.init:
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-13 19:15:16 +00:00
|
|
|
inc a
|
|
|
|
ld [wSwitchItem], a
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.trivial:
|
2015-12-13 19:15:16 +00:00
|
|
|
xor a
|
|
|
|
ld [wSwitchItem], a
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.below:
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [wSwitchItem]
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_CopyItemToBuffer
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-13 19:15:16 +00:00
|
|
|
ld d, a
|
|
|
|
ld a, [wSwitchItem]
|
|
|
|
ld e, a
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemOffset
|
2015-12-13 19:15:16 +00:00
|
|
|
push bc
|
|
|
|
ld a, [wSwitchItem]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
dec hl
|
|
|
|
push hl
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemFormatSize
|
2015-12-13 19:15:16 +00:00
|
|
|
add hl, bc
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
pop hl
|
|
|
|
pop bc
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_BackwardsCopyBytes
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_CopyBufferToItem
|
2015-12-13 19:15:16 +00:00
|
|
|
xor a
|
|
|
|
ld [wSwitchItem], a
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.above:
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [wSwitchItem]
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_CopyItemToBuffer
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-13 19:15:16 +00:00
|
|
|
ld d, a
|
|
|
|
ld a, [wSwitchItem]
|
|
|
|
ld e, a
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemOffset
|
2015-12-13 19:15:16 +00:00
|
|
|
push bc
|
|
|
|
ld a, [wSwitchItem]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemFormatSize
|
2015-12-13 19:15:16 +00:00
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
call CopyBytes
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_CopyBufferToItem
|
2015-12-13 19:15:16 +00:00
|
|
|
xor a
|
|
|
|
ld [wSwitchItem], a
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.try_combining_stacks:
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [wSwitchItem]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [de]
|
|
|
|
cp [hl]
|
2020-10-21 19:39:15 +00:00
|
|
|
jr nz, .no_combine
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemQuantity
|
2020-07-13 17:05:05 +00:00
|
|
|
cp MAX_ITEM_STACK
|
2020-10-21 19:39:15 +00:00
|
|
|
jr z, .no_combine
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [wSwitchItem]
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemQuantity
|
2020-07-13 17:05:05 +00:00
|
|
|
cp MAX_ITEM_STACK
|
2020-10-21 19:39:15 +00:00
|
|
|
jr nz, .combine
|
|
|
|
.no_combine
|
2015-12-13 19:15:16 +00:00
|
|
|
and a
|
|
|
|
ret
|
2020-10-21 19:39:15 +00:00
|
|
|
.combine
|
2015-12-13 19:15:16 +00:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.combine_stacks:
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [wSwitchItem]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
inc hl
|
|
|
|
push hl
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
inc hl
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
|
|
|
add [hl]
|
2020-07-13 17:05:05 +00:00
|
|
|
cp MAX_ITEM_STACK + 1
|
2020-10-21 19:39:15 +00:00
|
|
|
jr c, .merge_stacks
|
2020-07-13 17:05:05 +00:00
|
|
|
sub MAX_ITEM_STACK
|
2015-12-13 19:15:16 +00:00
|
|
|
push af
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
inc hl
|
2020-07-13 17:05:05 +00:00
|
|
|
ld [hl], MAX_ITEM_STACK
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [wSwitchItem]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
inc hl
|
|
|
|
pop af
|
|
|
|
ld [hl], a
|
|
|
|
xor a
|
|
|
|
ld [wSwitchItem], a
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.merge_stacks:
|
2015-12-13 19:15:16 +00:00
|
|
|
push af
|
2015-12-17 22:51:32 +00:00
|
|
|
ld a, [wScrollingMenuCursorPosition]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
inc hl
|
|
|
|
pop af
|
|
|
|
ld [hl], a
|
2018-01-23 21:08:43 +00:00
|
|
|
ld hl, wMenuData_ItemsPointerAddr
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wSwitchItem]
|
|
|
|
cp [hl]
|
2020-10-21 19:39:15 +00:00
|
|
|
jr nz, .not_combining_last_item
|
2015-12-13 19:15:16 +00:00
|
|
|
dec [hl]
|
|
|
|
ld a, [wSwitchItem]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2020-10-21 19:39:15 +00:00
|
|
|
ld [hl], -1 ; end
|
2015-12-13 19:15:16 +00:00
|
|
|
xor a
|
|
|
|
ld [wSwitchItem], a
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.not_combining_last_item:
|
2015-12-13 19:15:16 +00:00
|
|
|
dec [hl]
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemFormatSize
|
2015-12-13 19:15:16 +00:00
|
|
|
push bc
|
|
|
|
ld a, [wSwitchItem]
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
pop bc
|
|
|
|
push hl
|
|
|
|
add hl, bc
|
|
|
|
pop de
|
2020-10-21 19:39:15 +00:00
|
|
|
.copy_loop
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
2020-10-21 19:39:15 +00:00
|
|
|
cp -1 ; end?
|
|
|
|
jr nz, .copy_loop
|
2015-12-13 19:15:16 +00:00
|
|
|
xor a
|
|
|
|
ld [wSwitchItem], a
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
ItemSwitch_CopyItemToBuffer:
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2020-10-21 19:39:15 +00:00
|
|
|
ld de, wSwitchItemBuffer
|
|
|
|
call ItemSwitch_GetItemFormatSize
|
2015-12-13 19:15:16 +00:00
|
|
|
call CopyBytes
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
ItemSwitch_CopyBufferToItem:
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2020-10-21 19:39:15 +00:00
|
|
|
ld hl, wSwitchItemBuffer
|
|
|
|
call ItemSwitch_GetItemFormatSize
|
2015-12-13 19:15:16 +00:00
|
|
|
call CopyBytes
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ItemSwitch_GetNthItem:
|
2015-12-13 19:15:16 +00:00
|
|
|
push af
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemFormatSize
|
2018-01-23 21:08:43 +00:00
|
|
|
ld hl, wMenuData_ItemsPointerAddr
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
inc hl
|
|
|
|
pop af
|
|
|
|
call AddNTimes
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
ItemSwitch_GetItemOffset:
|
2015-12-13 19:15:16 +00:00
|
|
|
push hl
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemFormatSize
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, d
|
|
|
|
sub e
|
2015-12-23 19:00:29 +00:00
|
|
|
jr nc, .dont_negate
|
2015-12-13 19:15:16 +00:00
|
|
|
dec a
|
|
|
|
cpl
|
2015-12-23 19:00:29 +00:00
|
|
|
.dont_negate
|
2015-12-13 19:15:16 +00:00
|
|
|
ld hl, 0
|
|
|
|
call AddNTimes
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
ItemSwitch_GetItemFormatSize:
|
2015-12-13 19:15:16 +00:00
|
|
|
push hl
|
2019-06-09 00:31:24 +00:00
|
|
|
ld a, [wMenuData_ScrollingMenuItemFormat]
|
2015-12-13 19:15:16 +00:00
|
|
|
ld c, a
|
|
|
|
ld b, 0
|
2020-10-21 19:39:15 +00:00
|
|
|
ld hl, .item_format_sizes
|
2015-12-13 19:15:16 +00:00
|
|
|
add hl, bc
|
2016-05-04 15:46:23 +00:00
|
|
|
add hl, bc
|
2015-12-13 19:15:16 +00:00
|
|
|
ld c, [hl]
|
|
|
|
inc hl
|
|
|
|
ld b, [hl]
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.item_format_sizes:
|
|
|
|
; entries correspond to SCROLLINGMENU_ITEMS_* constants
|
|
|
|
dw 0 ; unused
|
|
|
|
dw 1 ; SCROLLINGMENU_ITEMS_NORMAL
|
|
|
|
dw 2 ; SCROLLINGMENU_ITEMS_QUANTITY
|
2015-12-13 19:15:16 +00:00
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
ItemSwitch_GetItemQuantity:
|
2015-12-13 19:15:16 +00:00
|
|
|
push af
|
2020-10-21 19:39:15 +00:00
|
|
|
call ItemSwitch_GetItemFormatSize
|
2015-12-13 19:15:16 +00:00
|
|
|
ld a, c
|
2015-12-23 19:00:29 +00:00
|
|
|
cp 2
|
2020-10-21 19:39:15 +00:00
|
|
|
jr nz, .no_quantity
|
2015-12-13 19:15:16 +00:00
|
|
|
pop af
|
2015-12-23 19:00:29 +00:00
|
|
|
call ItemSwitch_GetNthItem
|
2015-12-13 19:15:16 +00:00
|
|
|
inc hl
|
|
|
|
ld a, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
.no_quantity
|
2015-12-13 19:15:16 +00:00
|
|
|
pop af
|
2020-10-21 19:39:15 +00:00
|
|
|
ld a, 1
|
2015-12-13 19:15:16 +00:00
|
|
|
ret
|
|
|
|
|
2020-10-21 19:39:15 +00:00
|
|
|
ItemSwitch_BackwardsCopyBytes:
|
2015-12-13 19:15:16 +00:00
|
|
|
.loop
|
|
|
|
ld a, [hld]
|
|
|
|
ld [de], a
|
|
|
|
dec de
|
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
|
|
|
jr nz, .loop
|
|
|
|
ret
|