Code:
ldrh r5,Activator
ldrh r4,Done
@convert to thumb
add r2,pc,#1
bx r2
.thumb
mov r12,lr
@[Text to Item] = r5
ldr r1, text
ldrh r2,[r1]
cmp r2,r5
bne End
strh r4,[r1]
add r1,#1
bl TextToItem
mov r4,r5
bl TextToItem
@[Item Address] = r2
ldr r2, Map
ldr r1, =0x10
lsl r1, #0x8
sub r1, #0x1
maploop:
ldrh r3, [r2]
cmp r3, r5
bne notreplace
cmp r4,#0
beq Move
sub r4,#1
notreplace:
add r2, #0x2 @add 2 to the map address, thus going to the next spot
sub r1, #0x1 @subtract 1 from r5, this is howmany times the loop repeats
bpl maploop
b End
@[Calculations..]
Move:
mov r1,#0x21
lsl r1,#0xC @r1 X coordinate
mov r5,r1 @r5 y coordinate
ldr r3, Map
sub r2, r3
mov r3,#0x20
lsl r3,#8
lsr r2,#1
mov r4,#2
lsl r4,#7
mov r0,#0
@Box Number
Div1:
cmp r2,r4
blt Add1
sub r2,r4
add r0,#1
b Div1
Add1:
mov r4,r0
mov r0,#0
@Row number
Div2:
cmp r4,#4
blt Next
sub r4,#4
add r0,#1
b Div2
Next:
@r0 holds row number
@r4 holds box number
@r2 holds slot number
mul r0,r3
lsl r0, #4
add r5,r0
mul r4,r3
lsl r4,#4
add r1,r4
mov r0,#0
Div3:
cmp r2,#16
blt Finish
sub r2,#16
add r0,#1
b Div3
Finish:
mul r0,r3
add r5,r0
mul r2,r3
add r1,r2
ldr r0,Pointer
ldr r0,[r0]
mov r2, #0xA9
lsl r2, #3
sub r0,r2
str r1,[r0]
str r5,[r0,#8]
End:
mov lr,r12
bx lr
TextToItem:
mov r0,#0xC
add r1, #0x1
mov r5,#0x0
mov r2,#0xF
@[[Final text address in r5]]
loop:
ldrb r3,[r1]
add r1,#1
cmp r3,#0x20
bgt skipthis
sub r1,#1
lsr r5,r0
lsr r5,#4
b exit
skipthis:
cmp r3,#0x40
blt skip
sub r3,#0x7
skip:
and r3,r2
lsl r3,r0
add r5,r3
sub r0,#0x4
bpl loop
exit:
bx lr
.arm
Map:
.long 0x021E3124
text:
.long 0x022AF136
Pointer:
.long 0x21C6DEC
Activator:
.ascii "zn"
Done:
.ascii "$$"