Code:
@sets a counter to 0
@searches the map, adding to the counter for each slot
@once an item is found,
@divide by 256 to determine which acre it is in
@quotient is acre (A), remainder is the slot in that acre(B)
@divide (A) by 5 to determine which acre row/column that acre is in
@quotient is Y acre row (the rows going left to right), remainder is X acre row (rows going up and down), multiply by 32 and add to x/y coords
@divide (B) by 16 to determine which slot row it is in
@quotient is Y slot row, remainder is X slot row, multiply by 2 and add to coords
Code:
li r5,0 //set a counter to 0
lis r14, 0x90E8
ori r14,r14,0xF052 // r14 holds slot before first mapslot 90E8F052
addi r17,r14,0x3202 // r17 holds 90E92254
maploop:
lhzu r27,2(r14) //load the item stored in each slot
cmpwi r27,0x57 //check if that item is a weed
blt notreplace
cmpwi r27,0x5A
ble Move
notreplace: //if not, add to the counter, and search the next slot
addi r5,r5,0x1
cmpw r14,r17 //until we reach the last slot of the map
ble maploop
blr
Move:
li r17,0x11 //set r17 to the value of the top left corner's coordinates?
mr r14,r17 //set r14 to this value too (so now we have x and y)
andi. r9,r5,0xFF //get the slot number the item is on for the remainder
srwi r5,r5,0x8 // and the acre we are in, for the quotient
li r30,0
div: //i got lazy and used this stupid divide routine,even thought there is a divide instruction in PPC...once i get this code working ill change it
cmpwi r5,0x5 //r5 will hold remainder, which is the acre row
blt Next
subi r5,r5,0x5
addi r30,r30,0x1 //r30 will hold acre column
b div
Next:
slwi r30,r30,0x5 //multiply by 32 but im not sure how the coordinates are structured on this game
add r14,r14,r30 //add to y coordinates
slwi r5,r5,0x5
add r17,r17,r5 //add to x coordinates
andi. r5,r9,0xF //get the remainder, which will be the row slot
srwi r9,r9,0x4 //quotient, which is the column slot
slwi r5,r5,0x1 //multiply by 2
add r17,r17,r5 //add to x coordinate
slwi r9,r9,0x1
add r14,r14,r9 //add to y coordinate
lis r30,0x80E6
stbu r17,0x38D7(r30) //store x coordinate in 80E638D7
stb r14,0x8(r30) //store y coordinate in 80E638DB
blr
I just used the Real-Time World Edit source to come up with this, and I'm guessing the address where the X and Y values are stored is "read only" because I can't write to it....So I guess I'll just keep this here, until I get it to work