Skip to navigation

Maths: Negate16Bit

Name: Negate16Bit [Show more] Type: Subroutine Category: Maths Summary: Negate a 16-bit number
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * AddScaled calls Negate16Bit * ApplyAerodynamics (Part 3 of 3) calls Negate16Bit * ApplyFlightControl calls Negate16Bit * ProcessLanding (Part 7 of 7) calls Negate16Bit

Arguments: (G W) The 16-bit value to be negated C flag Must be set on entry to get the correct result
Returns: (G W) The original value, negated, i.e. -(G W) A The high byte of the negated result, (G)
.Negate16Bit LDA #0 \ Negate (G W) by setting (G W) = 0 - (G W), starting SBC W \ with the low byte STA W LDA #0 \ And then the high byte SBC G STA G RTS \ Return from the subroutine