Code:
@Convert to thumb
add r2,pc,#1
bx r2
.thumb
ldr r5,CheckLocation
ldrb r5,[r5]
cmp r5,#5
@Check if you're in a location other than outdoors/player house
bgt Exit
ldr r1,CoordinatesPointer
ldr r1,[r1]
cmp r1,#0
@Check if you're at the games menu or some place that clears the address in the pointer
beq Exit
ldr r4,IOKeys
ldrb r4,[r4]
mov r2,#0xA9
lsl r2,#3
neg r2,r2 @r2 now holds negative #0x548
ldr r3,[r1,r2] @r3 now holds X coordinates
lsr r3,#0xC
add r2,#8
ldr r2,[r1,r2] @r2 now holds y coordinate
lsr r2,#0xC
@---DPad check---@
@start with left
mov r0,#0x20
tst r4,r0
bne Right
sub r3,#2
Right:
mov r0,#0x10
tst r4,r0
bne Up
add r3,#2
Up:
mov r0,#0x40
tst r4,r0
bne Down
sub r2,#2
Down:
mov r0,#0x80
tst r4,r0
bne None
add r2,#2
None:
cmp r5,#0
beq OutdoorsCheck
cmp r3,#0 @check if you're outside of the house's item slots
blt Exit
cmp r3,#0x1E @check if you're outside of the house's item slots
bgt Exit
cmp r2,#0
blt Exit
cmp r2,#0x1E
bgt Exit
b Continue
OutdoorsCheck:
cmp r3,#0x20 @check if you're before the map
blt Exit
cmp r3,#0xA0 @check if you're after the map
bgt Exit
cmp r2,#0x20 @check if you're before the map
blt Exit
cmp r2,#0xA0 @check if you're after the map
bgt Exit
@Divide by 2 and subtract #0x10 so you end up with the Row/Column number
Continue:
lsr r3,#1
lsr r2,#1
cmp r5,#0
@If you're in the house, there's no need to subtract
bgt BeginDivision
sub r3,#0x10
sub r2,#0x10
@r2 holds column
@r3 holds row
BeginDivision:
mov r0,#0xF
mov r4,#0xF
@-----------My routine
Divide1:
and r0,r3,r0
lsr r3,#4
@-----------My routine
Divide2:
and r4,r2,r4
lsr r2,#4
Finish:
@r3 holds y box multiply by #0x200
@r2 holds x box multiply by #0x800
@r0 holds column multiply by #0x2
@r4 holds row multiply by #0x20
lsl r0,#1 @multiply by #2
lsl r4,#5 @multiply by #32
lsl r3,#9 @multiply by #512
lsl r2,#0xB @multiply by #2048
ldr r1,Map
cmp r5,#0
beq AddSlot
sub r5,#1
mov r1,#0x45
lsl r1,#4
mul r5,r1
ldr r1,House
add r1,r5
@add to the map to get the space you're on
AddSlot:
add r1,r4
add r1,r0
add r1,r2
add r1,r3
@[texttoItem] = r5
@My version allows removing of leading zeros
ldr r4, Text
mov r5,#0x0
mov r0,#0xC
mov r2,#0xF
loop:
ldrb r3,[r4]
add r4,#0x1
cmp r3,#0x20
bgt skipthis
sub r4,#1
lsr r5,r0
lsr r5,#4
b Store
skipthis:
cmp r3,#0x40
blt skip
sub r3,#0x7
skip:
and r3,r2
lsl r3,r0
add r5,r3
sub r0,#0x4
bpl loop
@Store the item in that space
Store:
strh r5,[r1]
Exit:
bx lr
.arm
CoordinatesPointer:
.long 0x21C6DEC
Map:
.long 0x21E3124
Text:
.long 0x22AF136
CheckLocation:
.long 0x21EED6C
House:
.long 0x21E5328
IOKeys:
.long 0x4000130