.TT23 LDA #128 \ Clear the top part of the screen, draw a white border, JSR TT66 \ and set the current view type in QQ11 to 128 (Short- \ range Chart) LDA #16 \ Switch to the mode 1 palette for the trade view, which JSR DOVDU19 \ is yellow (colour 1), magenta (colour 2) and white \ (colour 3) LDA #CYAN \ Switch to colour 3, which is white in the chart view STA COL LDA #7 \ Move the text cursor to column 7 STA XC 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) LDA #CYAN \ Switch to colour 3, which is white in the chart view STA COL 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 CMP #29 \ If the horizontal distance in A is >= 29, then this BCS TT187S \ system is too far away from the current system to \ appear in the Short-range Chart, so jump to TT187 via \ TT187S to move on to the next system 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 CMP #40 \ If the vertical distance in A is >= 40, then this BCS TT187S \ system is too far away from the current system to \ appear in the Short-range Chart, so jump to TT187 via \ TT187S to move on to the next system \ 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) ASL A \ Set XX12 = 104 + x-delta * 4 ASL A \ ADC #104 \ 104 is the x-coordinate of the centre of the chart, JSR SCALEY2 \ so this sets XX12 to the centre 104 +/- 76, the pixel STA XX12 \ x-coordinate of this system \ \ The call to SCALEY2 has no effect as it only contains \ an RTS, but having this call instruction here would \ enable different scaling to be applied by altering \ the SCALE routines. This code is left over from the \ conversion to other platforms, where the scale factor \ might need to be different LSR A \ Move the text cursor to column x-delta / 2 + 1 LSR A \ which will be in the range 1-10 LSR A INC A STA XC 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) ASL A \ Set K4 = 90 + y-delta * 2 ADC #90 \ JSR SCALEY2 \ 90 is the y-coordinate of the centre of the chart, STA K4 \ so this sets K4 to the centre 90 +/- 74, the pixel \ y-coordinate of this system \ \ The call to SCALEY2 has no effect as it only contains \ an RTS, but having this call instruction here would \ enable different scaling to be applied by altering \ the SCALE routines. This code is left over from the \ conversion to other platforms, where the scale factor \ might need to be different LSR A \ Set Y = K4 / 8, so Y contains the number of the text LSR A \ row that contains this system LSR A TAY \ 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 STY YC \ Now to print the label, so move the text cursor to row \ Y (which contains the row where we can print this \ system's label) 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 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 DIST LDA QQ15+3 \ Set A = s1_hi, so A contains the galactic x-coordinate \ of the system we are displaying on the chart JSR DIST \ Call DIST 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 #&FF \ Store &FF in INWK+Y, to denote that this row is now STA INWK,Y \ occupied so we don't try to print another system's \ label on this row 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 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 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 BEQ P%+5 \ If X = 0 then we have done all 256 systems, so skip \ the next instruction to return from the subroutine JMP TT182 \ Otherwise jump back up to TT182 to process the next \ system RTS \ Return from the subroutineName: TT23 [Show more] Type: Subroutine Category: Charts Summary: Show the Short-range Chart (red key f5)Context: See this subroutine in context in the source code Variations: See code variations for this subroutine in the different versions References: This subroutine is called as follows: * TT102 calls TT23 * TT114 calls TT23

[X]

Configuration variable: CYAN = %11111111

Four mode 1 pixels of colour 3 (cyan or white)

[X]

Entry point DIST in subroutine TT111 (category: Universe)

Calculate the distance between the system with galactic coordinates (A, QQ15+1) and the system at (QQ0, QQ1), returning the result in QQ8(1 0)

[X]

Subroutine DOVDU19 (category: Screen mode)

Change the mode 1 palette

[X]

Label EE3 is local to this routine

[X]

Label EE4 is local to this routine

[X]

Subroutine FLFLLS (category: Drawing suns)

Reset the sun line heap

[X]

Subroutine NLIN3 (category: Drawing lines)

Print a title and a horizontal line at row 19 to box it in

[X]

Subroutine SCALEY2 (category: Utility routines)

Scale the y-coordinate in A

[X]

Subroutine SUN (Part 1 of 4) (category: Drawing suns)

Draw the sun: Set up all the variables needed

[X]

Subroutine TT103 (category: Charts)

Draw a small set of crosshairs on a chart

[X]

Subroutine TT14 (category: Drawing circles)

Draw a circle with crosshairs on a chart

[X]

Label TT182 is local to this routine

[X]

Label TT184 is local to this routine

[X]

Label TT186 is local to this routine

[X]

Label TT187 is local to this routine

[X]

Label TT187S is local to this routine

[X]

Subroutine TT20 (category: Universe)

Twist the selected system's seeds four times

[X]

Subroutine TT66 (category: Utility routines)

Clear the screen and set the current view type

[X]

Subroutine TT81 (category: Universe)

Set the selected system's seeds to those of system 0

[X]

Subroutine cpl (category: Text)

Print the selected system name

[X]

Label ee1 is local to this routine