Skip to navigation


The Theme: GetAlienWeakSpot

Name: GetAlienWeakSpot [Show more] Type: Subroutine Category: The Theme Summary: Calculate the coordinates of an alien's weak spot Deep dive: Detecting alien hits
Context: 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 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
.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 = 0