This code appears in the following versions (click to see it in the source code):
Code variations between these versions are shown below.
Name: FMLTU Type: Subroutine Category: Maths (Arithmetic) Summary: Calculate A = A * Q / 256
This variation is blank in the Cassette, Disc (flight), Disc (docked) and Electron versions.
Deep dive: Multiplication and division using logarithms
Do the following multiplication of two unsigned 8-bit numbers, returning only the high byte of the result: (A ?) = A * Q or, to put it another way: A = A * Q / 256
.FMLTU
The FMLTU routine in the advanced versions uses logarithms to speed up the multiplication.
Tap on a block to expand it, and tap it again to revert.
In the FMLTU multiplication routine, the Master version omits half of the logarithm algorithm when compared to the 6502SP version. The effect of this in-game is most noticeable in the Short-range Chart, where the fuel circle is a different shape to the other versions (the Master version looks rather less smooth, as if it has a slightly larger step size, though it's actually down to the less accurate FMLTU routine).
See below for more variations related to this code.
This variation is blank in the Cassette, Disc (flight), Disc (docked), Master and Electron versions.
BMI oddlog \ If A > 127, jump to oddlog
Code variation 5 of 7
See variation 4 above for details.
This variation is blank in the Cassette, Disc (flight), Disc (docked) and Electron versions.
Tap on a block to expand it, and tap it again to revert.
Code variation 6 of 7
See variation 4 above for details.
This variation is blank in the Cassette, Disc (flight), Disc (docked), Master and Electron versions.
.oddlog LDA log,X \ Set A = high byte of Lq LDX widget \ Set A = A + C + high byte of La ADC log,X \ = high byte of Lq + high byte of La + C \ \ so we now have: \ \ A = high byte of (La + Lq) BCC MU3again \ If the addition fitted into one byte and didn't carry, \ then La + Lq < 256, so we jump to MU3again to return a \ result of 0 and the C flag clear \ If we get here then the C flag is set, ready for when \ we return from the subroutine below TAX \ Otherwise La + Lq >= 256, so we return the A-th entry LDA antilogODD,X \ from the antilogODD table
Code variation 7 of 7
See variation 4 above for details.
This variation is blank in the Cassette, Disc (flight), Disc (docked) and Electron versions.
Tap on a block to expand it, and tap it again to revert.