Find Unit at Coordinates (0x19d294)
Jump to navigation
Jump to search
# ROUTINE: FIND UNIT AT COORDINATES (0x19d294) ALTERNATIVE VERSION Get_unit_that_matches_coordinates # Parameters: # r4 = Integer byte array: [X Coordinate, Higher Elevation bit, Y Coordinate] # Returns: # r2 = Unit index of the unit found at the specified coordinates (0-20), or 21 if no unit found
0019d294: 00003021 addu r6,r0,r0 # [Unit index] = 0 0019d298: 340700ff ori r7,r0,0x00ff 0019d29c: 3c058019 lui r5,0x8019 0019d2a0: 24a508cc addiu r5,r5,0x08cc # Unit = UnitArray[0] # do { 0019d2a4: 90a20001 lbu r2,0x0001(r5) # [Unit ID] 0019d2a8: 00000000 nop 0019d2ac: 10470010 beq r2,r7,0x0019d2f0 # If [Unit ID] == 0xFF (doesn't exist), continue (skip to next loop iteration) 0019d2b0: 00000000 nop 0019d2b4: 90a30047 lbu r3,0x0047(r5) # [Unit X Coordinate] 0019d2b8: 90820000 lbu r2,0x0000(r4) # ParameterArray[0] 0019d2bc: 00000000 nop 0019d2c0: 1462000b bne r3,r2,0x0019d2f0 # If [Unit X Coordinate] != ParameterArray[0], continue (skip to next loop iteration) 0019d2c4: 00000000 nop 0019d2c8: 90a30048 lbu r3,0x0048(r5) # [Unit Y Coordinate] 0019d2cc: 90820002 lbu r2,0x0002(r4) # ParameterArray[2] 0019d2d0: 00000000 nop 0019d2d4: 14620006 bne r3,r2,0x0019d2f0 # If [Unit Y Coordinate] != ParameterArray[0], continue (skip to next loop iteration) 0019d2d8: 00000000 nop 0019d2dc: 94a20048 lhu r2,0x0048(r5) # Load halfword with high byte = [Unit 0x49 flags], low byte = [Unit Y Coordinate] 0019d2e0: 90830001 lbu r3,0x0001(r4) # ParameterArray[1] 0019d2e4: 000213c2 srl r2,r2,0x0f # [Higher Elevation] bit 0019d2e8: 10430005 beq r2,r3,0x0019d300 # If [Higher Elevation] = ParameterArray[1], break out of the loop 0019d2ec: 00000000 nop 0019d2f0: 24c60001 addiu r6,r6,0x0001 # Increment [Unit index] 0019d2f4: 28c20015 slti r2,r6,0x0015 # Check [Unit index] < 21 0019d2f8: 1440ffea bne r2,r0,0x0019d2a4 0019d2fc: 24a501c0 addiu r5,r5,0x01c0 # Unit = UnitArray[Unit index + 1] # } while ([Unit index] < 21) 0019d300: 03e00008 jr r31 # Return [Unit index] 0019d304: 00c01021 addu r2,r6,r0