Skip to navigation

Elite on the BBC Micro and NES

Keyboard: TT102

[Elite-A, Parasite]

Name: TT102 [Show more] Type: Subroutine Category: Keyboard Summary: Process function key, save key, hyperspace and chart key presses
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * Main game loop (Part 6 of 6) calls TT102 * Main game loop for flight (Part 6 of 6) calls TT102 * Main game loop for flight (Part 3 of 6) calls via BAD * TT110 calls via BAD * HME2 calls via T95 * Main game loop for flight (Part 6 of 6) calls via TT107

Process function key presses, plus "@" (save commander), "H" (hyperspace), "D" (show distance to system) and "O" (move chart cursor back to current system). We can also pass cursor position deltas in X and Y to indicate that the cursor keys or joystick have been used (i.e. the values that are returned by routine TT17).
Arguments: A The internal key number of the key pressed (see p.142 of the Advanced User Guide for a list of internal key numbers) X The amount to move the crosshairs in the x-axis Y The amount to move the crosshairs in the y-axis
Other entry points: BAD Work out how bad we are from the amount of contraband in our hold T95 Print the distance to the selected system TT107 Progress the countdown of the hyperspace counter
.TT102 CMP #f8 \ If red key f8 was pressed, jump to STATUS to show the BNE P%+5 \ Status Mode screen, returning from the subroutine JMP STATUS \ using a tail call CMP #f4 \ If red key f4 was pressed, jump to TT22 to show the BNE P%+5 \ Long-range Chart, returning from the subroutine using JMP TT22 \ a tail call CMP #f5 \ If red key f5 was pressed, jump to TT23 to show the BNE P%+5 \ Short-range Chart, returning from the subroutine using JMP TT23 \ a tail call CMP #f6 \ If red key f6 was pressed, call TT111 to select the BNE TT92 \ system nearest to galactic coordinates (QQ9, QQ10) JSR TT111 \ (the location of the chart crosshairs) and set ZZ to JMP TT25 \ the system number, and then jump to TT25 to show the \ Data on System screen (along with an extended system \ description for the system in ZZ if we're docked), \ returning from the subroutine using a tail call .TT92 CMP #f9 \ If red key f9 was pressed, jump to TT213 to show the BNE P%+5 \ Inventory screen, returning from the subroutine JMP TT213 \ using a tail call CMP #f7 \ If red key f7 was pressed, jump to TT167 to show the BNE P%+5 \ Market Price screen, returning from the subroutine JMP TT167 \ using a tail call .LABEL_3 CMP #&32 \ If "D" was pressed, jump to T95 to print the distance BEQ T95 \ to a system (if we are in one of the chart screens) CMP #&43 \ If "F" was not pressed, jump down to HME1, otherwise BNE HME1 \ keep going to process searching for systems (when \ docked) or toggle the compass display (when flying) LDA QQ11 \ If the current view is a chart (QQ11 = 64 or 128), AND #%11000000 \ keep going, otherwise jump to n_finder BEQ n_finder LDA dockedp \ If dockedp is non-zero, then we are not docked and BNE t95 \ can't search for a system, so return from the \ subroutine (as t95 contains an RTS) JMP HME2 \ Jump to HME2 to let us search for a system, returning \ from the subroutine using a tail call .n_finder LDA dockedp \ If dockedp is zero, then we are docked and we can't BEQ t95 \ change the compass configuration, so return from the \ subroutine (as t95 contains an RTS) LDA finder \ Set the value of A to finder, which determines whether \ the compass is configured to show the sun or the \ planet EOR #NI% \ The value of finder is 0 (show the planet) or NI% \ (show the sun), so this toggles the value between the \ two STA finder \ Store the toggled value in finder JMP WSCAN \ Jump to WSCAN to wait for the vertical sync and return \ from the subroutine using a tail call .t95 RTS \ Return from the subroutine .HME1 CMP #&36 \ If "O" was pressed, do the following, otherwise skip BNE not_home \ to not_home to continue checking key presses LDA QQ11 \ If bits 6 and 7 of the view type are both clear - so AND #%11000000 \ this is not the Short-range or Long-range Chart - then BEQ t95 \ jump to t95 to return from the subroutine, otherwise \ do the following three jumps JSR TT103 \ Draw small crosshairs at coordinates (QQ9, QQ10), \ which will erase the crosshairs currently there JSR ping \ Set the target system to the current system (which \ will move the location in (QQ9, QQ10) to the current \ home system JMP TT103 \ Draw small crosshairs at coordinates (QQ9, QQ10), \ which will draw the crosshairs at our current home \ system, and return from the subroutine using a tail \ call .not_home CMP #&21 \ If "W" was pressed, continue on to move the crosshairs BNE ee2 \ to the special cargo destination, otherwise skip to \ ee2 to continue LDA QQ11 \ If bits 6 and 7 of the view type are both clear - so AND #%11000000 \ this is not the Short-range or Long-range Chart - then BEQ t95 \ jump to t95 to return from the subroutine, otherwise \ do the following three jumps LDA cmdr_cour \ If there is no special cargo delivery mission in ORA cmdr_cour+1 \ progress, then the mission timer in cmdr_cour(1 0) BEQ t95 \ will be zero, so return from the subroutine (as t95 \ contains an RTS) JSR TT103 \ Draw small crosshairs at coordinates (QQ9, QQ10), \ which will erase the crosshairs currently there LDA cmdr_courx \ Set the galactic coordinates in (QQ9, QQ10) to the STA QQ9 \ current special cargo delivery destination in LDA cmdr_coury \ (cmdr_courx, cmdr_coury) STA QQ10 JSR TT103 \ Draw small crosshairs at coordinates (QQ9, QQ10), \ which will draw the crosshairs at our current home \ system .T95 \ If we get here, "D" was pressed, so we need to show \ the distance to the selected system (if we are in a \ chart view) LDA QQ11 \ If the current view is a chart (QQ11 = 64 or 128), AND #%11000000 \ keep going, otherwise return from the subroutine (as BEQ t95 \ t95 contains an RTS) JSR hm \ Call hm to move the crosshairs to the target system \ in (QQ9, QQ10), returning with A = 0 STA QQ17 \ Set QQ17 = 0 to switch to ALL CAPS JSR cpl \ Print control code 3 (the selected system name) LDA #%10000000 \ Set bit 7 of QQ17 to switch to Sentence Case, with the STA QQ17 \ next letter in capitals LDA #1 \ Move the text cursor to column 1 and down one line STA XC \ (in other words, to the start of the next line) INC YC JMP TT146 \ Print the distance to the selected system and return \ from the subroutine using a tail call .ee2 BIT dockedp \ If bit 7 of dockedp is set, then we are not docked, so BMI flying \ jump to flying CMP #f0 \ If red key f0 was not pressed, jump to fvw to check BNE fvw \ for the next key JSR CTRL \ Red key f0 was pressed, so check whether CTRL was BMI jump_stay \ also pressed, and if so, jump to jump_stay to skip the \ following instruction JMP RSHIPS \ Red key f0 was pressed on its own, so jump to RSHIPS \ to launch our ship, returning from the subroutine \ using a tail call .jump_stay JMP stay_here \ CTRL-f0 was pressed, so jump to stay_here to pay the \ docking fee and refresh prices .fvw CMP #f3 \ If red key f3 was pressed, jump to EQSHP to show the BNE P%+5 \ Equip Ship screen, returning from the subroutine using JMP EQSHP \ a tail call CMP #f1 \ If red key f1 was pressed, jump to TT219 to show the BNE P%+5 \ Buy Cargo screen, returning from the subroutine using JMP TT219 \ a tail call CMP #&47 \ If "@" was not pressed, skip to nosave BNE nosave JSR SVE \ "@" was pressed, so call SVE to show the disc access \ menu BCC P%+5 \ If the C flag was set by SVE, then we loaded a new JMP QU5 \ commander file, so jump to QU5 to restart the game \ with the newly loaded commander JMP BAY \ Otherwise the C flag was clear, so jump to BAY to go \ to the docking bay (i.e. show the Status Mode screen) .nosave CMP #f2 \ If red key f2 was pressed, jump to TT208 to show the BNE not_sell \ Sell Cargo screen, returning from the subroutine using JMP TT208 \ a tail call .not_sell CMP #&54 \ If "H" was not pressed, jump to NWDAV5 to skip the BNE NWDAV5 \ following JSR CLYNS \ "H" was pressed, so clear the bottom three text rows \ of the upper screen, and move the text cursor to \ column 1 on row 21, i.e. the start of the top row of \ the three bottom rows LDA #15 \ Move the text cursor to column 15 (the middle of the STA XC \ screen) LDA #205 \ Print extended token 205 ("DOCKED") and return from JMP DETOK \ the subroutine using a tail call .flying CMP #&20 \ If "D" was pressed, jump to TT110 to print the BNE P%+5 \ distance to a system (if we are in one of the chart JMP TT110 \ screens) CMP #f1 \ If the key pressed is < red key f1 or > red key f3, BCC d_4143 \ jump to d_4143 (so only do the following if the key CMP #f3+1 \ pressed is f1, f2 or f3) BCS d_4143 AND #3 \ If we get here then we are either in space, or we are TAX \ docked and none of f1-f3 were pressed, so we can now JMP LOOK1 \ process f1-f3 with their in-flight functions, i.e. \ switching space views \ \ A will contain &71, &72 or &73 (for f1, f2 or f3), so \ set X to the last digit (1, 2 or 3) and jump to LOOK1 \ to switch to view X (rear, left or right), returning \ from the subroutine using a tail call .d_4143 CMP #&54 \ If "H" was not pressed, jump to NWDAV5 to skip the BNE NWDAV5 \ following JMP hyp \ Jump to hyp to do a hyperspace jump (if we are in \ space), returning from the subroutine using a tail \ call .TT107 LDA QQ22+1 \ If the on-screen hyperspace counter is zero, return BEQ d_418a \ from the subroutine (as d_418a contains an RTS), as we \ are not currently counting down to a hyperspace jump DEC QQ22 \ Decrement the internal hyperspace counter BNE d_418a \ If the internal hyperspace counter is still non-zero, \ then we are still counting down, so return from the \ subroutine (as d_418a contains an RTS) \ If we get here then the internal hyperspace counter \ has just reached zero and it wasn't zero before, so \ we need to reduce the on-screen counter and update \ the screen. We do this by first printing the next \ number in the countdown sequence, and then printing \ the old number, which will erase the old number \ and display the new one because printing uses EOR \ logic LDX QQ22+1 \ Set X = the on-screen hyperspace counter - 1 DEX \ (i.e. the next number in the sequence) JSR ee3 \ Print the 8-bit number in X at text location (0, 1) LDA #5 \ Reset the internal hyperspace counter to 5 STA QQ22 LDX QQ22+1 \ Set X = the on-screen hyperspace counter (i.e. the \ current number in the sequence, which is already \ shown on-screen) JSR ee3 \ Print the 8-bit number in X at text location (0, 1), \ i.e. print the hyperspace countdown in the top-left \ corner DEC QQ22+1 \ Decrement the on-screen hyperspace countdown BNE d_418a \ If the countdown is not yet at zero, return from the \ subroutine (as d_418a contains an RTS) JMP TT18 \ Otherwise the countdown has finished, so jump to TT18 \ to do a hyperspace jump, returning from the subroutine \ using a tail call .BAD LDA QQ20+3 \ Set A to the number of tonnes of slaves in the hold CLC \ Clear the C flag so we can do addition without the \ C flag affecting the result ADC QQ20+6 \ Add the number of tonnes of narcotics in the hold ASL A \ Double the result and add the number of tonnes of ADC QQ20+10 \ firearms in the hold .d_418a RTS \ Return from the subroutine .NWDAV5 LDA QQ11 \ If the current view is a chart (QQ11 = 64 or 128), AND #%11000000 \ keep going, otherwise return from the subroutine (as BEQ d_418a \ d_418a contains an RTS) JMP TT16 \ Jump to TT16 to move the crosshairs by the amount in X \ and Y, which were passed to this subroutine as \ arguments, and return from the subroutine using a tail \ call