Skip to navigation

Elite on the BBC Micro and NES

Status: STATUS

[Elite-A, Parasite]

Name: STATUS [Show more] Type: Subroutine Category: Status Summary: Show the Status Mode screen (red key f8) Deep dive: Combat rank
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * TT102 calls STATUS * sell_jump calls via sell_equip

Other entry points: sell_equip Show the Sell Equipment screen, i.e. show a "Sell(Y/N)?" prompt as we print each item of equipment
.st4 \ We call this from st5 below with the high byte of the \ kill tally in A, which is non-zero, and want to return \ with the following in X, depending on our rating: \ \ Competent = 6 \ Dangerous = 7 \ Deadly = 8 \ Elite = 9 \ \ The high bytes of the top tier ratings are as follows, \ so this a relatively simple calculation: \ \ Competent = 1 to 2 \ Dangerous = 2 to 9 \ Deadly = 10 to 24 \ Elite = 25 and up LDX #9 \ Set X to 9 for an Elite rating CMP #25 \ If A >= 25, jump to st3 to print out our rating, as we BCS st3 \ are Elite DEX \ Decrement X to 8 for a Deadly rating CMP #10 \ If A >= 10, jump to st3 to print out our rating, as we BCS st3 \ are Deadly DEX \ Decrement X to 7 for a Dangerous rating CMP #2 \ If A >= 2, jump to st3 to print out our rating, as we BCS st3 \ are Dangerous DEX \ Decrement X to 6 for a Competent rating BNE st3 \ Jump to st3 to print out our rating, as we are \ Competent (this BNE is effectively a JMP as A will \ never be zero) .STATUS LDA #8 \ Clear the top part of the screen, draw a white border, JSR TT66 \ and set the current view type in QQ11 to 8 (Status \ Mode screen) JSR TT111 \ Select the system closest to galactic coordinates \ (QQ9, QQ10) LDA #7 \ Move the text cursor to column 7 STA XC LDA #126 \ Print recursive token 126, which prints the top JSR NLIN3 \ four lines of the Status Mode screen: \ \ COMMANDER {commander name} \ \ \ Present System : {current system name} \ Hyperspace System : {selected system name} \ Condition : \ \ and draw a horizontal line at pixel row 19 to box \ in the title BIT dockedp \ If bit 7 of dockedp is clear, then we are docked, so BPL stat_dock \ jump to stat_dock to print "Docked" for our ship's \ condition LDA #230 \ Otherwise we are in space, so start off by setting A \ to token 70 ("GREEN") LDY JUNK \ Set Y to the number of junk items in our local bubble \ of universe (where junk is asteroids, canisters, \ escape pods and so on) LDX FRIN+2,Y \ The ship slots at FRIN are ordered with the first two \ slots reserved for the planet and sun/space station, \ and then any ships, so if the slot at FRIN+2+Y is not \ empty (i.e. is non-zero), then that means the number \ of non-asteroids in the vicinity is at least 1 BEQ st6 \ So if X = 0, there are no ships in the vicinity, so \ jump to st6 to print "Green" for our ship's condition LDY ENERGY \ Otherwise we have ships in the vicinity, so we load \ our energy levels into Y CPY #128 \ Set the C flag if Y >= 128, so C is set if we have \ more than half of our energy banks charged ADC #1 \ Add 1 + C to A, so if C is not set (i.e. we have low \ energy levels) then A is set to token 231 ("RED"), \ and if C is set (i.e. we have healthy energy levels) \ then A is set to token 232 ("YELLOW") .st6 JSR plf \ Print the text token in A (which contains our ship's \ condition) followed by a newline JMP stat_legal \ Jump to stat_legal to skip the following, as we are \ not docked and have already printed the correct \ in-flight status .stat_dock LDA #205 \ Print extended token 205 ("DOCKED") JSR DETOK JSR TT67 \ Print a newline .stat_legal LDA #125 \ Print recursive token 125, which prints the next JSR spc \ three lines of the Status Mode screen: \ \ Fuel: {fuel level} Light Years \ Cash: {cash} Cr \ Legal Status: \ \ followed by a space LDA #19 \ Set A to token 133 ("CLEAN") LDY FIST \ Fetch our legal status, and if it is 0, we are clean, BEQ st5 \ so jump to st5 to print "Clean" CPY #50 \ Set the C flag if Y >= 50, so C is set if we have \ a legal status of 50+ (i.e. we are a fugitive) ADC #1 \ Add 1 + C to A, so if C is not set (i.e. we have a \ legal status between 1 and 49) then A is set to token \ 134 ("OFFENDER"), and if C is set (i.e. we have a \ legal status of 50+) then A is set to token 135 \ ("FUGITIVE") .st5 JSR plf \ Print the text token in A (which contains our legal \ status) followed by a newline LDA #16 \ Print recursive token 130 ("RATING:") followed by a JSR spc \ space LDA TALLY+1 \ Fetch the high byte of the kill tally, and if it is BNE st4 \ not zero, then we have more than 256 kills, so jump \ to st4 to work out whether we are Competent, \ Dangerous, Deadly or Elite \ Otherwise we have fewer than 256 kills, so we are one \ of Harmless, Mostly Harmless, Poor, Average or Above \ Average TAX \ Set X to 0 (as A is 0) LDA TALLY \ Set A = lower byte of tally / 4 LSR A LSR A .st5L \ We now loop through bits 2 to 7, shifting each of them \ off the end of A until there are no set bits left, and \ incrementing X for each shift, so at the end of the \ process, X contains the position of the leftmost 1 in \ A. Looking at the rank values in TALLY: \ \ Harmless = %00000000 to %00000011 \ Mostly Harmless = %00000100 to %00000111 \ Poor = %00001000 to %00001111 \ Average = %00010000 to %00011111 \ Above Average = %00100000 to %11111111 \ \ we can see that the values returned by this process \ are: \ \ Harmless = 1 \ Mostly Harmless = 2 \ Poor = 3 \ Average = 4 \ Above Average = 5 INX \ Increment X for each shift LSR A \ Shift A to the right BNE st5L \ Keep looping around until A = 0, which means there are \ no set bits left in A .st3 TXA \ A now contains our rating as a value of 1 to 9, so \ transfer X to A, so we can print it out CLC \ Print recursive token 135 + A, which will be in the ADC #21 \ range 136 ("HARMLESS") to 144 ("---- E L I T E ----") JSR plf \ followed by a newline LDA #18 \ Call status_equip with A set to recursive token 132 JSR status_equip \ to print the next bit of the Status Mode screen: \ \ {current ship type}: \ \ followed by a newline and an indent of 8 characters .sell_equip LDA CRGO \ If we don't have an I.F.F. system fitted (i.e. CRGO is BEQ P%+9 \ zero), skip the following three instructions LDA #107 \ We do have an I.F.F. system fitted, so print recursive LDX #6 \ token 107 ("I.F.F.SYSTEM"). If this is the Status Mode JSR status_equip \ or Inventory screen, print a newline and an indent of \ 8 characters, or if this is the Sell Equipment screen, \ show and process a sell prompt for the piece of \ equipment at LASER+X = LASER+6 = CRGO before printing \ a newline LDA BST \ If we don't have fuel scoops fitted, skip the BEQ P%+9 \ following three instructions LDA #111 \ We do have fuel scoops fitted, so print recursive LDX #25 \ token 111 ("FUEL SCOOPS"). If this is the Status Mode JSR status_equip \ or Inventory screen, print a newline and an indent of \ 8 characters, or if this is the Sell Equipment screen, \ show and process a sell prompt for the piece of \ equipment at LASER+X = LASER+25 = BST before printing \ a newline LDA ECM \ If we don't have an E.C.M. fitted, skip the following BEQ P%+9 \ three instructions LDA #108 \ We do have an E.C.M. fitted, so print recursive token LDX #24 \ 108 ("E.C.M.SYSTEM"). If this is the Status Mode or JSR status_equip \ Inventory screen, print a newline and an indent of 8 \ characters, or if this is the Sell Equipment screen, \ show and process a sell prompt for the piece of \ equipment at LASER+X = LASER+24 = ECM before printing \ a newline \LDA #113 \ These instructions are commented out in the original \STA XX4 \ source LDX #26 \ Set X = 26 so we now process equipment from LASER+26 \ onwards (i.e. BOMB onwards), using X as a counter \ going from LASER+26 (BOMB) to LASER+29 (GHYP) .stqv STX CNT \ Store the X counter in CNT so we can retrieve it below \TAY \ These instructions are commented out in the original \LDX FRIN,Y \ source LDY LASER,X \ Fetch the equipment flag from LASER+X, and if we do BEQ P%+9 \ not have that equipment fitted, skip the following \ four instructions to move onto the next piece of \ equipment TXA \ Set A = X + 87 CLC \ ADC #87 \ so A is now a token number between 113 ("HYPERSPACE \ UNIT") and 116 ("GALACTIC HYPERSPACE ") JSR status_equip \ Print the recursive token in A. If this is the Status \ Mode or Inventory screen, print a newline and an \ indent of 8 characters, or if this is the Sell \ Equipment screen, show and process a sell prompt for \ the piece of equipment at LASER+X before printing a \ newline \INC XX4 \ These instructions are commented out in the original \LDA XX4 \ source \CMP #117 LDX CNT \ Retrieve the X counter from CNT that we stored above INX \ Increment the loop counter CPX #30 \ Loop back to print the next piece of equipment until BCC stqv \ we have done LASER+26 (BOMB) to LASER+29 (GHYP) LDX #0 \ Now to print our ship's lasers, so set a counter in X \ to count through the four views (0 = front, 1 = rear, \ 2 = left, 3 = right) .st STX CNT \ Store the view number in CNT LDY LASER,X \ Fetch the laser power for view X, and if we do not BEQ st1 \ have a laser fitted to that view, jump to st1 to move \ on to the next one TXA \ Print recursive token 96 + X, which will print from 96 ORA #96 \ ("FRONT") through to 99 ("RIGHT"), followed by a space JSR spc \ (the ORA acts like an addition as 96 = %01100000) LDA #103 \ Set A to token 103 ("PULSE LASER") LDX CNT \ Retrieve the view number from CNT that we stored above LDY LASER,X \ Set Y = the laser power for view X CPY new_beam \ If the laser power for view X is not that of a beam BNE P%+4 \ laser when fitted to our current ship type, skip the \ next LDA instruction LDA #104 \ This sets A = 104 if the laser in view X is a beam \ laser (token 104 is "BEAM LASER") CPY new_military \ If the laser power for view X is not that of a BNE P%+4 \ military laser when fitted to our current ship type, \ skip the next LDA instruction LDA #117 \ This sets A = 117 if the laser in view X is a military \ laser (token 117 is "MILITARY LASER") CPY new_mining \ If the laser power for view X is not that of a mining BNE P%+4 \ laser when fitted to our current ship type, skip the \ next LDA instruction LDA #118 \ This sets A = 118 if the laser in view X is a mining \ laser (token 118 is "MINING LASER") JSR status_equip \ Print the recursive token in A. If this is the Status \ Mode or Inventory screen, print a newline and an \ indent of 8 characters, or if this is the Sell \ Equipment screen, show and process a sell prompt for \ the piece of equipment at LASER+X before printing a \ newline .st1 LDX CNT \ Increment the counter in X and CNT to point to the INX \ next view CPX #4 \ If this isn't the last of the four views, jump back up BCC st \ to st to print out the next one RTS \ Return from the subroutine