ref: 93dcc8b6ebe30c0ef6b62eca228b6d75f92e8a65
parent: 7b12060e6a6c276f3c044c04f131befa28749da5
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Wed Oct 21 11:39:15 EDT 2020
Identify SwitchItemsInBag labels Thanks to FIQ for having done so in Polished Crystal
--- a/engine/battle/effect_commands.asm
+++ b/engine/battle/effect_commands.asm
@@ -2532,10 +2532,10 @@
ldh a, [hBattleTurn]
and a
ld a, [hl]
- jr nz, .Ditto
+ jr nz, .got_species
ld a, [wTempEnemyMonSpecies]
-.Ditto:
+.got_species
cp DITTO
ret nz
--- a/engine/items/pack.asm
+++ b/engine/items/pack.asm
@@ -1103,7 +1103,7 @@
.ItemsMenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
- db 2 ; horizontal spacing
+ db SCROLLINGMENU_ITEMS_QUANTITY ; item format
dbw 0, wDudeNumItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
@@ -1123,7 +1123,7 @@
.KeyItemsMenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
- db 1 ; horizontal spacing
+ db SCROLLINGMENU_ITEMS_NORMAL ; item format
dbw 0, wDudeNumKeyItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
@@ -1152,7 +1152,7 @@
.BallsMenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
- db 2 ; horizontal spacing
+ db SCROLLINGMENU_ITEMS_QUANTITY ; item format
dbw 0, wDudeNumBalls
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
--- a/engine/items/switch_items.asm
+++ b/engine/items/switch_items.asm
@@ -15,76 +15,76 @@
ld a, [wSwitchItem]
dec a
ld [wSwitchItem], a
- call Function249a7
- jp c, Function249d1
+ call .try_combining_stacks
+ jp c, .combine_stacks
ld a, [wScrollingMenuCursorPosition]
ld c, a
ld a, [wSwitchItem]
cp c
- jr c, .asm_2497a
- jr .asm_2494a
+ jr c, .above
+ jr .below
-.init
+.init:
ld a, [wScrollingMenuCursorPosition]
inc a
ld [wSwitchItem], a
ret
-.trivial
+.trivial:
xor a
ld [wSwitchItem], a
ret
-.asm_2494a
+.below:
ld a, [wSwitchItem]
- call Function24a40
+ call ItemSwitch_CopyItemToBuffer
ld a, [wScrollingMenuCursorPosition]
ld d, a
ld a, [wSwitchItem]
ld e, a
- call Function24a6c
+ call ItemSwitch_GetItemOffset
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
dec hl
push hl
- call ItemSwitch_ConvertItemFormatToDW
+ call ItemSwitch_GetItemFormatSize
add hl, bc
ld d, h
ld e, l
pop hl
pop bc
- call Function24aab
+ call ItemSwitch_BackwardsCopyBytes
ld a, [wScrollingMenuCursorPosition]
- call Function24a4d
+ call ItemSwitch_CopyBufferToItem
xor a
ld [wSwitchItem], a
ret
-.asm_2497a
+.above:
ld a, [wSwitchItem]
- call Function24a40
+ call ItemSwitch_CopyItemToBuffer
ld a, [wScrollingMenuCursorPosition]
ld d, a
ld a, [wSwitchItem]
ld e, a
- call Function24a6c
+ call ItemSwitch_GetItemOffset
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld d, h
ld e, l
- call ItemSwitch_ConvertItemFormatToDW
+ call ItemSwitch_GetItemFormatSize
add hl, bc
pop bc
call CopyBytes
ld a, [wScrollingMenuCursorPosition]
- call Function24a4d
+ call ItemSwitch_CopyBufferToItem
xor a
ld [wSwitchItem], a
ret
-Function249a7:
+.try_combining_stacks:
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
ld d, h
@@ -93,24 +93,23 @@
call ItemSwitch_GetNthItem
ld a, [de]
cp [hl]
- jr nz, .asm_249cd
+ jr nz, .no_combine
ld a, [wScrollingMenuCursorPosition]
- call Function24a97
+ call ItemSwitch_GetItemQuantity
cp MAX_ITEM_STACK
- jr z, .asm_249cd
+ jr z, .no_combine
ld a, [wSwitchItem]
- call Function24a97
+ call ItemSwitch_GetItemQuantity
cp MAX_ITEM_STACK
- jr nz, .asm_249cf
-.asm_249cd
+ jr nz, .combine
+.no_combine
and a
ret
-
-.asm_249cf
+.combine
scf
ret
-Function249d1:
+.combine_stacks:
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
inc hl
@@ -122,7 +121,7 @@
pop hl
add [hl]
cp MAX_ITEM_STACK + 1
- jr c, .asm_24a01
+ jr c, .merge_stacks
sub MAX_ITEM_STACK
push af
ld a, [wScrollingMenuCursorPosition]
@@ -138,7 +137,7 @@
ld [wSwitchItem], a
ret
-.asm_24a01
+.merge_stacks:
push af
ld a, [wScrollingMenuCursorPosition]
call ItemSwitch_GetNthItem
@@ -151,18 +150,18 @@
ld l, a
ld a, [wSwitchItem]
cp [hl]
- jr nz, .asm_24a25
+ jr nz, .not_combining_last_item
dec [hl]
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
- ld [hl], $ff
+ ld [hl], -1 ; end
xor a
ld [wSwitchItem], a
ret
-.asm_24a25
+.not_combining_last_item:
dec [hl]
- call ItemSwitch_ConvertItemFormatToDW
+ call ItemSwitch_GetItemFormatSize
push bc
ld a, [wSwitchItem]
call ItemSwitch_GetNthItem
@@ -170,35 +169,35 @@
push hl
add hl, bc
pop de
-.asm_24a34
+.copy_loop
ld a, [hli]
ld [de], a
inc de
- cp $ff
- jr nz, .asm_24a34
+ cp -1 ; end?
+ jr nz, .copy_loop
xor a
ld [wSwitchItem], a
ret
-Function24a40:
+ItemSwitch_CopyItemToBuffer:
call ItemSwitch_GetNthItem
- ld de, wd002
- call ItemSwitch_ConvertItemFormatToDW
+ ld de, wSwitchItemBuffer
+ call ItemSwitch_GetItemFormatSize
call CopyBytes
ret
-Function24a4d:
+ItemSwitch_CopyBufferToItem:
call ItemSwitch_GetNthItem
ld d, h
ld e, l
- ld hl, wd002
- call ItemSwitch_ConvertItemFormatToDW
+ ld hl, wSwitchItemBuffer
+ call ItemSwitch_GetItemFormatSize
call CopyBytes
ret
ItemSwitch_GetNthItem:
push af
- call ItemSwitch_ConvertItemFormatToDW
+ call ItemSwitch_GetItemFormatSize
ld hl, wMenuData_ItemsPointerAddr
ld a, [hli]
ld h, [hl]
@@ -208,9 +207,9 @@
call AddNTimes
ret
-Function24a6c:
+ItemSwitch_GetItemOffset:
push hl
- call ItemSwitch_ConvertItemFormatToDW
+ call ItemSwitch_GetItemFormatSize
ld a, d
sub e
jr nc, .dont_negate
@@ -224,12 +223,12 @@
pop hl
ret
-ItemSwitch_ConvertItemFormatToDW:
+ItemSwitch_GetItemFormatSize:
push hl
ld a, [wMenuData_ScrollingMenuItemFormat]
ld c, a
ld b, 0
- ld hl, .format_dws
+ ld hl, .item_format_sizes
add hl, bc
add hl, bc
ld c, [hl]
@@ -238,17 +237,18 @@
pop hl
ret
-.format_dws
- dw 0
- dw 1
- dw 2
+.item_format_sizes:
+; entries correspond to SCROLLINGMENU_ITEMS_* constants
+ dw 0 ; unused
+ dw 1 ; SCROLLINGMENU_ITEMS_NORMAL
+ dw 2 ; SCROLLINGMENU_ITEMS_QUANTITY
-Function24a97:
+ItemSwitch_GetItemQuantity:
push af
- call ItemSwitch_ConvertItemFormatToDW
+ call ItemSwitch_GetItemFormatSize
ld a, c
cp 2
- jr nz, .not_2
+ jr nz, .no_quantity
pop af
call ItemSwitch_GetNthItem
inc hl
@@ -255,12 +255,12 @@
ld a, [hl]
ret
-.not_2
+.no_quantity
pop af
- ld a, $1
+ ld a, 1
ret
-Function24aab:
+ItemSwitch_BackwardsCopyBytes:
.loop
ld a, [hld]
ld [de], a
--- a/wram.asm
+++ b/wram.asm
@@ -1815,6 +1815,10 @@
wEarthquakeMovementDataBuffer:: ds 5
NEXTU
+; switching items in pack
+wSwitchItemBuffer:: ds 2 ; may store 1 or 2 bytes
+
+NEXTU
; miscellaneous
wTempDayOfWeek::
wApricorns::