Code:
@Convert to thumb
add r2,pc,#1
bx r2
.thumb
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
sub r1,r2
ldr r3,[r1] @r3 now holds X coordinates
lsr r3,#0xD
ldr r2,[r1,#8] @r2 now holds y coordinate
lsr r2,#0xD
@---DPad check---@
@start with left
mov r0,#0x20
tst r4,r0
bne Right
sub r3,#1
Right:
mov r0,#0x10
tst r4,r0
bne Up
add r3,#1
Up:
mov r0,#0x40
tst r4,r0
bne Down
sub r2,#1
Down:
mov r0,#0x80
tst r4,r0
bne None
add r2,#1
None:
OutdoorsCheck:
cmp r3,#0x10 @check if you're before the map
blt Exit
cmp r3,#0x50 @check if you're after the map
bgt Exit
cmp r2,#0x10 @check if you're before the map
blt Exit
cmp r2,#0x50 @check if you're after the map
bgt Exit
@subtract #0x10 so you end up with the Row/Column number
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
@add to the map to get the space you're on
AddSlot:
add r0,r4
add r0,r2
add r0,r3
@[texttoItem] = r5
@My version allows removing of leading zeros
ldr r4, Text
mov r5,#0x0
mov r2,#0xF
loop:
ldrb r3,[r4]
add r4,#0x1
cmp r3,#0x2F
ble Store
cmp r3,#0x40
blt skip
sub r3,#0x7
skip:
and r3,r2
lsl r5,#4
add r5,r3
b loop
@Store the item in that space
Store:
ldr r1,Map
strh r5,[r1,r0]
Exit:
bx lr
.arm
CoordinatesPointer:
.long 0x21C6DEC
Map:
.long 0x21E3124
Text:
.long 0x22AF136
IOKeys:
.long 0x4000130