This code appears in the following versions (click to see it in the source code):
Code variations between these versions are shown below.
Name: TT23 Type: Subroutine Category: Charts
.TT23 LDA #128 \ Clear the top part of the screen, draw a border box, JSR TT66 \ and set the current view type in QQ11 to 128 (Short- \ range Chart)
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.
LDA #190 \ Print recursive token 30 ("SHORT RANGE CHART") and JSR NLIN3 \ draw a horizontal line at pixel row 19 to box in the \ title JSR TT14 \ Call TT14 to draw a circle with crosshairs at the \ current system's galactic coordinates JSR TT103 \ Draw small crosshairs at coordinates (QQ9, QQ10), \ i.e. at the selected system JSR TT81 \ Set the seeds in QQ15 to those of system 0 in the \ current galaxy (i.e. copy the seeds from QQ21 to QQ15)
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.
LDA #0 \ Set A = 0, which we'll use below to zero out the INWK \ workspace STA XX20 \ We're about to start working our way through each of \ the galaxy's systems, so set up a counter in XX20 for \ each system, starting at 0 and looping through to 255 LDX #24 \ First, though, we need to zero out the 25 bytes at \ INWK so we can use them to work out which systems have \ room for a label, so set a counter in X for 25 bytes .EE3 STA INWK,X \ Set the X-th byte of INWK to zero DEX \ Decrement the counter BPL EE3 \ Loop back to EE3 for the next byte until we've zeroed \ all 25 bytes \ We now loop through every single system in the galaxy \ and check the distance from the current system whose \ coordinates are in (QQ0, QQ1). We get the galactic \ coordinates of each system from the system's seeds, \ like this: \ \ x = s1_hi (which is stored in QQ15+3) \ y = s0_hi (which is stored in QQ15+1) \ \ so the following loops through each system in the \ galaxy in turn and calculates the distance between \ (QQ0, QQ1) and (s1_hi, s0_hi) to find the closest one .TT182 LDA QQ15+3 \ Set A = s1_hi - QQ0, the horizontal distance between SEC \ (s1_hi, s0_hi) and (QQ0, QQ1) SBC QQ0 BCS TT184 \ If a borrow didn't occur, i.e. s1_hi >= QQ0, then the \ result is positive, so jump to TT184 and skip the \ following two instructions EOR #&FF \ Otherwise negate the result in A, so A is always ADC #1 \ positive (i.e. A = |s1_hi - QQ0|) .TT184
The Master version includes systems on the Short-range Chart if they are in the horizontal range 0-29, while the other versions include systems in the range 0-20, so the Master version can show systems that are further to the right. You can see an example of this difference in the Short-range Chart at Lave, which contains a lone system (Qutiri) out to the far right. This system isn't shown in the other versions because of their stricter horizontal distance check.
Tap on a block to expand it, and tap it again to revert.
LDA QQ15+1 \ Set A = s0_hi - QQ1, the vertical distance between SEC \ (s1_hi, s0_hi) and (QQ0, QQ1) SBC QQ1 BCS TT186 \ If a borrow didn't occur, i.e. s0_hi >= QQ1, then the \ result is positive, so jump to TT186 and skip the \ following two instructions EOR #&FF \ Otherwise negate the result in A, so A is always ADC #1 \ positive (i.e. A = |s0_hi - QQ1|) .TT186
The Master version includes systems on the Short-range Chart if they are in the vertical range 0-40, while the other versions include systems in the range 0-38, so the Master version version can show systems that are further down the chart.
Tap on a block to expand it, and tap it again to revert.
\ This system should be shown on the Short-range Chart, \ so now we need to work out where the label should go, \ and set up the various variables we need to draw the \ system's filled circle on the chart LDA QQ15+3 \ Set A = s1_hi - QQ0, the horizontal distance between SEC \ this system and the current system, where |A| < 20. SBC QQ0 \ Let's call this the x-delta, as it's the horizontal \ difference between the current system at the centre of \ the chart, and this system (and this time we keep the \ sign of A, so it can be negative if it's to the left \ of the chart's centre, or positive if it's to the \ right)
The Master version contains code to scale the chart views, though it has no effect in this version. The code is left over from the Apple II version, which uses a different scale.
See below for more variations related to this code.
Tap on a block to expand it, and tap it again to revert.
LDA QQ15+1 \ Set A = s0_hi - QQ1, the vertical distance between SEC \ this system and the current system, where |A| < 38. SBC QQ1 \ Let's call this the y-delta, as it's the vertical \ difference between the current system at the centre of \ the chart, and this system (and this time we keep the \ sign of A, so it can be negative if it's above the \ chart's centre, or positive if it's below)
Code variation 9 of 17
See variation 7 above for details.
Tap on a block to expand it, and tap it again to revert.
\ Now to see if there is room for this system's label. \ Ideally we would print the system name on the same \ text row as the system, but we only want to print one \ label per row, to prevent overlap, so now we check \ this system's row, and if that's already occupied, \ the row above, and if that's already occupied, the \ row below... and if that's already occupied, we give \ up and don't print a label for this system LDX INWK,Y \ If the value in INWK+Y is 0 (i.e. the text row BEQ EE4 \ containing this system does not already have another \ system's label on it), jump to EE4 to store this \ system's label on this row INY \ If the value in INWK+Y+1 is 0 (i.e. the text row below LDX INWK,Y \ the one containing this system does not already have BEQ EE4 \ another system's label on it), jump to EE4 to store \ this system's label on this row DEY \ If the value in INWK+Y-1 is 0 (i.e. the text row above DEY \ the one containing this system does not already have LDX INWK,Y \ another system's label on it), fall through into to BNE ee1 \ EE4 to store this system's label on this row, \ otherwise jump to ee1 to skip printing a label for \ this system (as there simply isn't room) .EE4
CPY #3 \ If Y < 3, then the system would clash with the chart BCC TT187 \ title, so jump to TT187 to skip showing the system
The Master version only shows systems on the Short-range Chart that are within 7 light years of the current system, whereas the other versions show all systems in the vicinity, irrespective of the distance. You can see this on the Short-range Chart at Lave, where Orrere, Uszaa and Tionisla are all missing from the Master version's chart, but are present in the other versions. Interestingly, the unlabelled system on the far right (Qutiri) that slipped through the Master's more generous horizontal distance check is still shown, even though it's more than 7 light years away. This is a bug, and it's caused by the label-printing logic; because there is no room for a label for this system, the code skips label-printing by jumping to ee1 rather than TT187, inadvertently jumping to the system-drawing routine rather than moving on to the next system.
This variation is blank in the Cassette, Disc (flight), Disc (docked), 6502 Second Processor and Electron versions.
CPY #21 \ If Y > 21, then the label will be off the bottom of BCS TT187 \ the chart, so jump to TT187 to skip showing the system TYA \ Store Y on the stack so it can be preserved across the PHA \ call to readdistnce LDA QQ15+3 \ Set A = s1_hi, so A contains the galactic x-coordinate \ of the system we are displaying on the chart JSR readdistnce \ Call readdistnce to calculate the distance between the \ system with galactic coordinates (A, QQ15+1) - i.e. \ the system we are displaying - and the current system \ at (QQ0, QQ1), returning the result in QQ8(1 0) PLA \ Restore Y from the stack TAY LDA QQ8+1 \ If the high byte of the distance in QQ8(1 0) is BNE TT187 \ non-zero, jump to TT187 to skip showing the system as \ it is too far away from the current system LDA QQ8 \ If the low byte of the distance in QQ8(1 0) is >= 70, CMP #70 \ jump to TT187 to skip showing the system as it is too \ far away from the current system .TT187s BCS TT187 \ If we get here from the instruction above, we jump to \ TT187 if QQ8(1 0) >= 70, so we only show systems that \ are within distance 70 (i.e. 7 light years) of the \ current system \ \ If we jump here from elsewhere with a BCS TT187s, we \ jump straight on to TT187
LDA #%10000000 \ Set bit 7 of QQ17 to switch to Sentence Case STA QQ17 JSR cpl \ Call cpl to print out the system name for the seeds \ in QQ15 (which now contains the seeds for the current \ system) .ee1
In the non-Electron versions, the same code is used to draw both the sun and the systems on the Short-range Chart. The Electron version doesn't include suns, so systems on the chart are drawn as dots rather than filled circles.
This variation is blank in the Electron version.
LDA #0 \ Now to plot the star, so set the high bytes of K, K3 STA K3+1 \ and K4 to 0 STA K4+1 STA K+1 LDA XX12 \ Set the low byte of K3 to XX12, the pixel x-coordinate STA K3 \ of this system LDA QQ15+5 \ Fetch s2_hi for this system from QQ15+5, extract bit 0 AND #1 \ and add 2 to get the size of the star, which we store ADC #2 \ in K. This will be either 2, 3 or 4, depending on the STA K \ value of bit 0, and whether the C flag is set (which \ will vary depending on what happens in the above call \ to cpl). Incidentally, the planet's average radius \ also uses s2_hi, bits 0-3 to be precise, but that \ doesn't mean the two sizes affect each other \ We now have the following: \ \ K(1 0) = radius of star (2, 3 or 4) \ \ K3(1 0) = pixel x-coordinate of system \ \ K4(1 0) = pixel y-coordinate of system \ \ which we can now pass to the SUN routine to draw a \ small "sun" on the Short-range Chart for this system JSR FLFLLS \ Call FLFLLS to reset the LSO block JSR SUN \ Call SUN to plot a sun with radius K at pixel \ coordinate (K3, K4) JSR FLFLLS \ Call FLFLLS to reset the LSO block
This variation is blank in the Cassette, Disc (flight), Disc (docked), 6502 Second Processor and Electron versions.
LDA #CYAN \ Switch to colour 3, which is white in the chart view STA COL
.TT187 JSR TT20 \ We want to move on to the next system, so call TT20 \ to twist the three 16-bit seeds in QQ15 INC XX20 \ Increment the counter
JMP TT182 \ Otherwise jump back up to TT182 to process the next \ system
This variation is blank in the Cassette, Disc (flight), Disc (docked), 6502 Second Processor and Electron versions.
\LDA #0 \ These instructions are commented out in the original \STA dontclip \ source \ \LDA #2*Y-1 \STA Yx2M1 RTS \ Return from the subroutine