.GetAlienWeakSpot LDX #2 \ Set a counter in X to iterate through 2, 1, 0, which \ has the following effect: \ \ When X = 2: \ \ * (I+2 W+2) = (xObjectHi xObjectLo) + (5 Q) \ \ When X = 1: \ \ * (I+1 W+1) = (yObjectHi yObjectLo) \ \ When X = 0: \ \ * (I W) = (zObjectHi zObjectLo) + (5 Q) \ \ note that .weak1 LDA xObjectLo,Y \ Set (I+X W+X) = (xObjectHi xObjectLo) + (5 Q) CLC \ ADC Q \ starting with the low bytes STA W,X LDA xObjectHi,Y \ And then the high bytes ADC #5 STA I,X .weak2 TYA \ Point Y to the next axis (xObject, yObject, zObject) CLC ADC #nextAxis TAY DEX \ Decrement the loop counter BPL weak3 \ If we haven't yet done all three calculations, jump \ to weak3 RTS \ Return from the subroutine .weak3 BEQ weak1 \ If X = 0, jump up to weak1 to add (5 Q) LDA xObjectLo,Y \ If we get here then X = 1, so do the calculation STA W,X \ without adding (5 Q) LDA xObjectHi,Y STA I,X JMP weak2 \ Jump back to weak2 to move on to X = 0Name: GetAlienWeakSpot [Show more] Type: Subroutine Category: The Theme Summary: Calculate the coordinates of an alien's weak spot Deep dive: Detecting alien hitsContext: See this subroutine in context in the source code References: This subroutine is called as follows: * CheckIfAlienIsHit (Part 2 of 2) calls GetAlienWeakSpot
The alien's weak spot is calculated as follows: * x-coordinate = (xObjectHi xObjectLo) + (5 Q) * y-coordinate = (yObjectHi yObjectLo) * z-coordinate = (zObjectHi zObjectLo) + (5 Q) where Q is the low byte of the amount to add, depending on the feeding state of the alien. This is called STIP in the original source code.
Arguments: Y The object ID of the alien (30 to 33) Q The low byte of the amount to add
Returns: (I+2 W+2) The x-coordinate of the alien's weak spot (I+1 W+1) The y-coordinate of the alien's weak spot (I W) The z-coordinate of the alien's weak spot
[X]
Configuration variable nextAxis = 40
The xObject, yObject and zObject tables each contain 40 bytes, and they are positioned one after the other in memory, so if we access, say, the x-coordinate for object Y at xObjectHi+Y, then adding #nextAxis to Y will point xObjectHi+Y to the y-coordinate, and adding it again will point it to the z-coordinate
[X]
Label weak1 is local to this routine
[X]
Label weak2 is local to this routine
[X]
Label weak3 is local to this routine
[X]
Variable xObjectHi (category: 3D geometry)
High byte of the x-coordinate for an object
[X]
Variable xObjectLo (category: 3D geometry)
Low byte of the x-coordinate for an object