Skip to navigation

Elite on the BBC Micro and NES

Equipment: PrintEquipment

[NES version, Bank 0]

Name: PrintEquipment [Show more] Type: Subroutine Category: Equipment Summary: Print the name and price for a specified item of equipment Deep dive: Multi-language support in NES Elite
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MoveEquipmentDown calls PrintEquipment * MoveEquipmentUp calls PrintEquipment * EQSHP calls via PrintEquipment+2 * HighlightEquipment calls via PrintEquipment+2

Arguments: XX13 The item number + 1 (i.e. 1 for fuel) Q The highest item number on sale + 1
Other entry points: PrintEquipment+2 Print the item number in X
.PrintEquipment LDX XX13 ; Set X to the item number to print JSR SetupPPUForIconBar ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 STX XX13 ; Store the item number in XX13, in case we entered the ; routine at PrintEquipment+2 TXA ; Set A = X + 2 CLC ; ADC #2 ; So the first item (item 1) will be on row 3, and so on LDX Q ; If Q >= 12, set A = A - 1 so we move everything up the CPX #12 ; screen by one line when the highest item number on BCC preq1 ; sale is at least 11 SEC SBC #1 .preq1 STA YC ; Move the text cursor to row A LDA #1 ; Move the text cursor to column 1 STA XC LDA languageNumber ; If bit 1 of languageNumber is set then the chosen AND #%00000010 ; language is French, so jump to preq2 to skip the BNE preq2 ; following JSR TT162 ; Print a space .preq2 JSR TT162 ; Print a space LDA XX13 ; Print recursive token 104 + XX13, which will be in the CLC ; range 105 ("FUEL") to 116 ("GALACTIC HYPERSPACE ") ADC #104 ; so this prints the current item's name JSR TT27_b2 JSR WaitForIconBarPPU ; Wait until the PPU starts drawing the icon bar LDA XX13 ; If the current item number in XX13 is not 1, then it CMP #1 ; is not the fuel level, so jump to preq3 to skip the BNE preq3 ; following (which prints the fuel level) LDA #' ' ; Print a space JSR TT27_b2 LDA #'(' ; Print an open bracket JSR TT27_b2 LDX QQ14 ; Set X to the current fuel level * 10 SEC ; Set the C flag so the call to pr2+2 prints a decimal ; point LDA #0 ; Set the number of digits to 0 for the call to pr2+2, ; so the number is not padded with spaces JSR pr2+2 ; Print the fuel level with a decimal point and no ; padding LDA #195 ; Print recursive token 35 ("LIGHT YEARS") JSR TT27_b2 LDA #')' ; Print a closing bracket JSR TT27_b2 LDA languageNumber ; If bit 2 of languageNumber is set then the chosen AND #%00000100 ; language is French, so jump to preq3 to skip the BNE preq3 ; following (which prints the price) ; Bit 2 of languageNumber is clear, so the chosen ; language is English or German, so now we print the ; price LDA XX13 ; Call prx-3 to set (Y X) to the price of the item with JSR prx-3 ; number XX13 - 1 (as XX13 contains the item number + 1) SEC ; Set the C flag so we will print a decimal point when ; we print the price LDA #5 ; Print the number in (Y X) to 5 digits, left-padding JSR TT11 ; with spaces and including a decimal point, which will ; be the correct price for this item as (Y X) contains ; the price * 10, so the trailing zero will go after the ; decimal point (i.e. 5250 will be printed as 525.0) LDA #' ' ; Print a space JMP TT27_b2 .preq3 LDA #' ' ; Print a space JSR TT27_b2 LDA XC ; Loop back to print another space until XC = 24, so CMP #24 ; so this tabs the text cursor to column 24 BNE preq3 LDA XX13 ; Call prx-3 to set (Y X) to the price of the item with JSR prx-3 ; number XX13 - 1 (as XX13 contains the item number + 1) SEC ; Set the C flag so we will print a decimal point when ; we print the price LDA #6 ; Print the number in (Y X) to 6 digits, left-padding JSR TT11 ; with spaces and including a decimal point, which will ; be the correct price for this item as (Y X) contains ; the price * 10, so the trailing zero will go after the ; decimal point (i.e. 5250 will be printed as 525.0) JMP TT162 ; Print a space and return from the subroutine using a ; tail call