I've expanded my ROM, so I'll not even bother to find enough free space in the ROM.
I'll have to leave that to each user for themselves. Mine'll sit at E8/3B30.
So a few JMPs will have to be adjusted.
Since this relies on the item name, it won't work as it is for untranslated versions. They use different addresses for the item name.
$C2/E08D
A5 E2 99 00 81
place a JSL to your routine here instead
E8/3B30
A5 E2 LDA $E2 [$00:01E2]
99 00 81 STA $8100,y[$7E:8100]
C0 00 00 CPY #$0000
D0 01 BNE
6B RTL
DA PHX
5A PHY
---loop start---
88 DEY
30 24 BMI go to end if Y < 0
B9 00 80 LDA $8000,y[$7E:8000]
20 90 3B JSR validate item
F0 1C BEQ if 0 exit
85 E0 STA $E0
B9 01 80 LDA $8001,y[$7E:8001]
20 90 3B JSR validate
F0 12 BEQ if 0 exit
C5 E0 CMP $E0
F0 04 BEQ
10 0C BPL go to end if right sorting
30 05 BMI go to switch
20 D0 3B JSR compare both items for attack/defense
---compare both values; value != id
F0 05 BEQ if 0 exit
20 70 3B JSR switch items
80 D9 BRA loop start
---loop end---
7A PLY
FA PLX
6B RTL
switch items
E8/3B70
B9 00 80 LDA $8000,y[$7E:8000]
48 PHA
B9 01 80 LDA $8001,y[$7E:8001]
99 00 80 STA $8000,y[$7E:8000]
68 PLA
99 01 80 STA $8001,y[$7E:8001]
B9 00 81 LDA $8100,y[$7E:8100]
48 PHA
B9 01 81 LDA $8101,y[$7E:8101]
99 00 81 STA $8100,y[$7E:8100]
68 PLA
99 01 81 STA $8101,y[$7E:8101]
60 RTS
validate item, returns primary sorting value of item
E8/3B90
F0 12 BEQ
C9 01 CMP #$01
F0 0E BEQ
C9 80 CMP #$80
F0 0A BEQ
C5 93 CMP $93
30 06 BMI
C5 95 CMP $95
10 02 BPL
80 03 BRA
A9 00 LDA #$00
60 RTS
C9 E0 CMP #$E0 if it is a consumable, return id
90 03 BCC $03
29 FF AND #$FF
60 RTS
C2 20 REP #$20
29 FF 00 AND #$00FF #$1380 + 9xID is the offset for name
48 PHA
0A ASL A
0A ASL A
0A ASL A
18 CLC
63 01 ADC $01,s
18 CLC
69 80 13 ADC #$1380
FA PLX
AA TAX
BF 00 00 D1 LDA $0000,x weapon symbol
29 FF 00 AND #$00FF
E2 20 SEP #$20
60 RTS
compare both items for attack/defense
E8/3BD0
B9 00 80 LDA $8000,y[$7E:8000]
20 F0 3B JSR get atk/def
85 E0 STA $E0
B9 01 80 LDA $8001,y[$7E:8001]
20 F0 3B JSR get atk/def
C5 E0 CMP $E0
F0 05 BEQ
90 03 BCC
A9 01 LDA #$01
60 RTS
A9 00 LDA #$00
60 RTS
get atk/def
E8/3BF0
C2 20 REP #$20
48 PHA
0A ASL A
18 CLC
63 01 ADC $01,s
0A ASL A
0A ASL A
FA PLX
AA TAX
29 FF 00 AND #$00FF
E2 20 SEP #$20
BF 07 00 D1 LDA $0007,x atk/def, highest value to the top
60 RTS