Skip to navigation


Equipment: EQSHP

[NES version, Bank 0]

Name: EQSHP [Show more] Type: Subroutine Category: Equipment Summary: Show the Equip Ship screen
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * refund calls EQSHP * TT102 calls EQSHP * UpdateEquipment calls via equi1

Other entry points: pres Given an item number A with the item name in recursive token Y, show an error to say that the item is already present, refund the cost of the item, and then beep and exit to the docking bay (i.e. show the Status Mode screen) equi1 A re-entry point into the key-pressing loop, used when processing key presses in subroutines
.EQSHP LDA #$B9 ; Clear the screen and set the view type in QQ11 to $B9 JSR SetNewViewType ; (Equip Ship) LDX languageIndex ; Move the text cursor to the correct column for the LDA xEquipShip,X ; Equip Ship title in the chosen language STA XC LDA #207 ; Print recursive token 47 ("EQUIP") on the top row JSR NLIN3 LDA #%10000000 ; Set bit 7 of QQ17 to switch to Sentence Case, with the STA QQ17 ; next letter in capitals LDA tek ; Fetch the tech level of the current system from tek CLC ; and add 3 (the tech level is stored as 0-14, so A is ADC #3 ; now set to between 3 and 17) CMP #12 ; If A >= 12 then set A = 14, so A is now set to between BCC P%+4 ; 3 and 14 LDA #14 STA Q ; Set QQ25 = A (so QQ25 is in the range 3-14 and STA QQ25 ; represents number of the most advanced item available INC Q ; in this system, which we can pass to gnum below when ; asking which item we want to buy) ; ; Set Q = A + 1 (so Q is in the range 4-15 and contains ; QQ25 + 1, i.e. the highest item number on sale + 1) LDA #70 ; Set A = 70 - QQ14, where QQ14 contains the current SEC ; fuel in light years * 10, so this leaves the amount SBC QQ14 ; of fuel we need to fill 'er up (in light years * 10) LDX #1 ; We are now going to work our way through the equipment ; price list at PRXS, printing out the equipment that is ; available at this station, so set a counter in X, ; starting at 1, to hold the number of the current item ; plus 1 (so the item number in X loops through 1-13) .EQL1 JSR PrintEquipment+2 ; Print the name and price for the equipment item in X LDX XX13 ; Increment the current item number in XX13 INX CPX Q ; If X < Q, loop back up to print the next item on the BCC EQL1 ; list of equipment available at this station LDX #1 ; Set XX13 = 1 to pass to the HighlightEquipment routine STX XX13 ; so we highlight the first item on the list (Fuel) JSR HighlightEquipment ; Highlight the item of equipment in XX13, i.e. Fuel JSR dn ; Print the amount of money we have left in the cash pot JSR SetScreenForUpdate ; Get the screen ready for updating by hiding all ; sprites, after fading the screen to black if we are ; changing view JSR DrawCobraMkIII ; Draw the Cobra Mk III that we embellish with our ; fitted equipment JSR UpdateView ; Update the view ; The Equip Ship view is now on-screen, so we move on to ; checking for key presses .equi1 SETUP_PPU_FOR_ICON_BAR ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 LDA controller1Up ; If the up button has not been pressed, jump to equi2 BPL equi2 ; to keep checking for other buttons JMP MoveEquipmentUp ; Move the currently selected item up the list of ; equipment and rejoin the loop by jumping up to equi1 ; to keep checking for other buttons .equi2 LDA controller1Down ; If the down button has not been pressed, jump to equi3 BPL equi3 ; to keep checking for other buttons JMP MoveEquipmentDown ; Move the currently selected item down the list of ; equipment and rejoin the loop by jumping up to equi1 ; to keep checking for other buttons .equi3 LDA controller1A ; If the A button has been pressed, jump to equi4 to BMI equi4 ; process a purchase LDA iconBarChoice ; If iconBarChoice = 0 then nothing has been chosen on BEQ equi1 ; the icon bar (if it had, iconBarChoice would contain ; the number of the chosen icon bar button), so loop ; back to equi1 to keep checking for button presses ; If we get here then either a choice has been made on ; the icon bar during NMI and the number of the icon bar ; button is in iconBarChoice, or the Start button has ; been pressed to pause the game and iconBarChoice is 80 JSR CheckForPause ; If the Start button has been pressed then process the ; pause menu and set the C flag, otherwise clear it BCS equi1 ; If it was the pause button, loop back to equi1 to pick ; up where we left off and keep checking for button ; presses RTS ; Otherwise a choice has been made from the icon bar, so ; return from the subroutine .equi4 JSR UpdateSaveCount ; Update the save counter for the current commander LDA XX13 ; Set A = XX13 - 1, so A contains the item number of the SEC ; currently selected item, less 1, which will be the SBC #1 ; actual number of the item we want to buy PHA ; Store the value of A on the stack, so we can retrieve ; it after the call to eq JSR eq ; Call eq to subtract the price of the item we want to ; buy (which is in A) from our cash pot BCS equi5 ; If we had enough cash to make the purchase, then the C ; flag will be set by eq, so jump to equi5 with the ; original value of A still on the stack ; If we get here then we didn't have enough cash to make ; the purchase PLA ; Retrieve the value of A from the stack, so A contains ; the number of the item we couldn't afford JSR DrawScreenInNMI ; Configure the NMI handler to draw the screen, so the ; screen gets updated JMP equi1 ; Loop back up to equi1 to keep checking for button ; presses .equi5 ; If we get here then we just successfully bought an ; item of equipment PLA ; Retrieve the value of A from the stack, so A contains ; the number of the item we just bought BNE et0 ; If A is not 0 (i.e. the item we've just bought is not ; fuel), skip to et0 PHA ; Store the value of A on the stack, so we can retrieve ; it after the following calculation LDA QQ14 ; Fetch our current fuel level from Q114 into A CLC ; Increment our fuel level in A ADC #1 CMP #71 ; If A < 71 then the tank is not overflowing, so jump to BCC equi6 ; equi6 to store the updated fuel level LDY #105 ; Set Y to recursive token 105 ("FUEL") to display as ; the error in the call to pres PLA ; Restore A from the stack JMP pres ; Jump to pres to show the error "Fuel Present", beep ; and exit to the docking bay (i.e. show the Status Mode ; screen) .equi6 STA QQ14 ; Update the fuel level in QQ14 to the value in A, as we ; have just bought some fuel PLA ; Restore A from the stack, so it once again contains ; the number of the item we are buying .et0 CMP #1 ; If A is not 1 (i.e. the item we've just bought is not BNE et1 ; a missile), skip to et1 LDX NOMSL ; Fetch the current number of missiles from NOMSL into X INX ; Increment X to the new number of missiles LDY #124 ; Set Y to recursive token 124 ("ALL") CPX #5 ; If buying this missile would give us 5 missiles, this BCS pres ; is more than the maximum of 4 missiles that we can ; fit, so jump to pres to show the error "All Present", ; beep and exit to the docking bay (i.e. show the Status ; Mode screen) STX NOMSL ; Otherwise update the number of missiles in NOMSL LDA #1 ; Set A to 1 as the call to msblob will have overwritten ; the original value, and we still need it set ; correctly so we can continue through the conditional ; statements for all the other equipment .et1 LDY #107 ; Set Y to recursive token 107 ("LARGE CARGO{sentence ; case} BAY") CMP #2 ; If A is not 2 (i.e. the item we've just bought is not BNE et2 ; a large cargo bay), skip to et2 LDX #37 ; If our current cargo capacity in CRGO is 37, then we CPX CRGO ; already have a large cargo bay fitted, so jump to pres BEQ pres ; to show the error "Large Cargo Bay Present", beep and ; exit to the docking bay (i.e. show the Status Mode ; screen) STX CRGO ; Otherwise we just scored ourselves a large cargo bay, ; so update our current cargo capacity in CRGO to 37 .et2 CMP #3 ; If A is not 3 (i.e. the item we've just bought is not BNE et3 ; an E.C.M. system), skip to et3 INY ; Increment Y to recursive token 108 ("E.C.M.SYSTEM") LDX ECM ; If we already have an E.C.M. fitted (i.e. ECM is BNE pres ; non-zero), jump to pres to show the error "E.C.M. ; System Present", beep and exit to the docking bay ; (i.e. show the Status Mode screen) DEC ECM ; Otherwise we just took delivery of a brand new E.C.M. ; system, so set ECM to $FF (as ECM was 0 before the DEC ; instruction) .et3 CMP #4 ; If A is not 4 (i.e. the item we've just bought is not BNE et4 ; an extra pulse laser), skip to et4 JSR qv ; Print a menu listing the four views, with a "View ?" ; prompt, and ask for a view number, which is returned ; in X (which now contains 0-3) LDA #POW+9 ; Call refund with A set to the power of the new pulse JMP refund ; laser to install the new laser and process a refund if ; we already have a laser fitted to this view ; ; The refund routine jumps back to EQSHP, so this also ; redisplays the Equip Ship screen LDA #4 ; Set A to 4 as we just overwrote the original value, ; and we still need it set correctly so we can continue ; through the conditional statements for all the other ; equipment .et4 CMP #5 ; If A is not 5 (i.e. the item we've just bought is not BNE et5 ; an extra beam laser), skip to et5 JSR qv ; Print a menu listing the four views, with a "View ?" ; prompt, and ask for a view number, which is returned ; in X (which now contains 0-3) LDA #POW+128 ; Call refund with A set to the power of the new beam JMP refund ; laser to install the new laser and process a refund if ; we already have a laser fitted to this view ; ; The refund routine jumps back to EQSHP, so this also ; redisplays the Equip Ship screen .et5 LDY #111 ; Set Y to recursive token 107 ("FUEL SCOOPS") CMP #6 ; If A is not 6 (i.e. the item we've just bought is not BNE et6 ; a fuel scoop), skip to et6 LDX BST ; If we already have fuel scoops fitted (i.e. BST is BEQ ed9 ; zero), jump to ed9, otherwise fall through into pres ; to show the error "Fuel Scoops Present", beep and ; exit to the docking bay (i.e. show the Status Mode ; screen) .pres ; If we get here we need to show an error to say that ; the item whose name is in recursive token Y is already ; present, and then process a refund for the cost of ; item number A STY K ; Store the item's name in K PHA ; Wait until the next NMI interrupt has passed (i.e. the JSR WaitForNMI ; next VBlank), preserving the value in A via the stack PLA JSR prx ; Call prx to set (Y X) to the price of equipment item ; number A JSR MCASH ; Add (Y X) cash to the cash pot in CASH, as the station ; already took the money for this item in the JSR eq ; instruction above, but we can't fit the item, so need ; our money back LDA #2 ; Move the text cursor to column 2 on row 17 STA XC LDA #17 STA YC LDA K ; Print the recursive token in K (the item's name) JSR spc ; followed by a space LDA #31 ; Print recursive token 145 ("PRESENT") JSR TT27_b2 .equi7 JSR TT162 ; Print a space LDA XC ; If the text cursor is not in column 31, loop back to CMP #31 ; equi7 to keep printing spaces until it reaches column BNE equi7 ; 31 at the right end of the screen, so we clear up to ; the end of the line containing the error message JSR BOOP ; Call the BOOP routine to make a low, long beep to ; indicate an error JSR DrawScreenInNMI ; Configure the NMI handler to draw the screen, so the ; screen gets updated LDY #40 ; Wait until 40 NMI interrupts have passed (i.e. the JSR DELAY ; next 40 VBlanks) LDA #6 ; Move the text cursor to column 6 STA XC LDA #17 ; Move the text cursor to row 17 STA YC .equi8 JSR TT162 ; Print a space LDA XC ; If the text cursor is not in column 31, loop back to CMP #31 ; equi8 to keep printing spaces until it reaches column BNE equi8 ; 31 at the right end of the screen, so we clear the ; whole line containing the error message JSR dn ; Print the amount of money we have left in the cash pot JSR DrawEquipment_b6 ; Draw the currently fitted equipment onto the Cobra Mk ; III image JSR DrawScreenInNMI ; Configure the NMI handler to draw the screen, so the ; screen gets updated JMP equi1 ; Loop back up to equi1 to keep checking for button ; presses .equi9 JMP pres ; Jump to pres to show an error, beep and exit to the ; docking bay (i.e. show the Status Mode screen) JSR DrawScreenInNMI ; Configure the NMI handler to draw the screen, so the ; screen gets updated JMP equi1 ; Loop back up to equi1 to keep checking for button ; presses .ed9 DEC BST ; We just bought a shiny new fuel scoop, so set BST to ; $FF (as BST was 0 before the jump to ed9 above) .et6 INY ; Increment Y to recursive token 112 ("E.C.M.SYSTEM") CMP #7 ; If A is not 7 (i.e. the item we've just bought is not BNE et7 ; an escape pod), skip to et7 LDX ESCP ; If we already have an escape pod fitted (i.e. ESCP is BNE pres ; non-zero), jump to pres to show the error "Escape Pod ; Present", beep and exit to the docking bay (i.e. show ; the Status Mode screen) DEC ESCP ; Otherwise we just bought an escape pod, so set ESCP ; to $FF (as ESCP was 0 before the DEC instruction) .et7 INY ; Increment Y to recursive token 113 ("ENERGY BOMB") CMP #8 ; If A is not 8 (i.e. the item we've just bought is not BNE et8 ; an energy bomb), skip to et8 LDX BOMB ; If we already have an energy bomb fitted (i.e. BOMB BNE pres ; is non-zero), jump to pres to show the error "Energy ; Bomb Present", beep and exit to the docking bay (i.e. ; show the Status Mode screen) LDX #$7F ; Otherwise we just bought an energy bomb, so set BOMB STX BOMB ; to $7F .et8 INY ; Increment Y to recursive token 114 ("ENERGY UNIT") CMP #9 ; If A is not 9 (i.e. the item we've just bought is not BNE etA ; an energy unit), skip to etA LDX ENGY ; If we already have an energy unit fitted (i.e. ENGY is BNE equi9 ; non-zero), jump to pres via equi9 to show the error ; "Energy Unit Present", beep and exit to the docking ; bay (i.e. show the Status Mode screen) INC ENGY ; Otherwise we just picked up an energy unit, so set ; ENGY to 1 (as ENGY was 0 before the INC instruction) .etA INY ; Increment Y to recursive token 115 ("DOCKING ; COMPUTERS") CMP #10 ; If A is not 10 (i.e. the item we've just bought is not BNE etB ; a docking computer), skip to etB LDX DKCMP ; If we already have a docking computer fitted (i.e. BNE equi9 ; DKCMP is non-zero), jump to pres via equi9 to show the ; error "Docking Computer Present", beep and exit to the ; docking bay (i.e. show the Status Mode screen) DEC DKCMP ; Otherwise we just got hold of a docking computer, so ; set DKCMP to $FF (as DKCMP was 0 before the DEC ; instruction) .etB INY ; Increment Y to recursive token 116 ("GALACTIC ; HYPERSPACE ") CMP #11 ; If A is not 11 (i.e. the item we've just bought is not BNE et9 ; a galactic hyperdrive), skip to et9 LDX GHYP ; If we already have a galactic hyperdrive fitted (i.e. BNE equi9 ; GHYP is non-zero), jump to pres via equi9 to show the ; error "Galactic Hyperspace Present", beep and exit to ; the docking bay (i.e. show the Status Mode screen) DEC GHYP ; Otherwise we just splashed out on a galactic ; hyperdrive, so set GHYP to $FF (as GHYP was 0 before ; the DEC instruction) .et9 INY ; Increment Y to recursive token 117 ("MILITARY LASER") CMP #12 ; If A is not 12 (i.e. the item we've just bought is not BNE et10 ; a military laser), skip to et10 JSR qv ; Print a menu listing the four views, with a "View ?" ; prompt, and ask for a view number, which is returned ; in X (which now contains 0-3) LDA #Armlas ; Call refund with A set to the power of the new JMP refund ; military laser to install the new laser and process a ; refund if we already have a laser fitted to this view ; ; The refund routine jumps back to EQSHP, so this also ; redisplays the Equip Ship screen .et10 INY ; Increment Y to recursive token 118 ("MINING LASER") CMP #13 ; If A is not 13 (i.e. the item we've just bought is not BNE et11 ; a mining laser), skip to et11 JSR qv ; Print a menu listing the four views, with a "View ?" ; prompt, and ask for a view number, which is returned ; in X (which now contains 0-3) LDA #Mlas ; Call refund with A set to the power of the new mining JMP refund ; laser to install the new laser and process a refund if ; we already have a laser fitted to this view ; ; The refund routine jumps back to EQSHP, so this also ; redisplays the Equip Ship screen .et11 JSR equi10 ; Call equi10 below to print the amount of money we have ; left and make a short, high beep to indicate that the ; transaction was successful JMP UpdateEquipment ; Jump up to UpdateEquipment to highlight the newly ; bought item of equipment, update the Cobra Mk III, ; redraw the screen and rejoin the main EQSHP routine to ; continue checking for button presses .equi10 SETUP_PPU_FOR_ICON_BAR ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 JSR dn ; Print the amount of money we have left in the cash pot JMP BEEP_b7 ; Call the BEEP subroutine to make a short, high beep ; and return from the subroutine using a tail call