Skip to navigation

Elite on the BBC Micro

Keyboard: TT102 [Electron version]

Name: TT102 [Show more] Type: Subroutine Category: Keyboard Summary: Process function key, save key, hyperspace and chart key presses and update the hyperspace counter
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: * Main game loop (Part 6 of 6) calls TT102

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 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.40 of the Electron 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: T95 Print the distance to the selected system
.VKEYS EQUB func2 \ The key to press for showing view 1 (back) EQUB func3 \ The key to press for showing view 2 (left) EQUB func4 \ The key to press for showing view 3 (right) .TT102 CMP #func9 \ If FUNC-9 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 #func5 \ If FUNC-5 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 #func6 \ If FUNC-6 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 #func7 \ If FUNC-7 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 jump to JMP TT25 \ TT25 to show the Data on System screen, returning \ from the subroutine using a tail call .TT92 CMP #func0 \ If FUNC-0 was pressed, jump to TT213 to show the BNE P%+5 \ Inventory screen, returning from the subroutine JMP TT213 \ using a tail call CMP #func8 \ If FUNC-8 was pressed, jump to TT167 to show the BNE P%+5 \ Market Price screen, returning from the subroutine JMP TT167 \ using a tail call CMP #func1 \ If FUNC-1 was pressed, jump to TT110 to launch our BNE fvw \ ship (if docked), returning from the subroutine using JMP TT110 \ a tail call .fvw BIT QQ12 \ If bit 7 of QQ12 is clear (i.e. we are not docked, but BPL INSP \ in space), jump to INSP to skip the following checks \ for FUNC-2 to FUNC-4 and "@" (save commander file) key \ presses CMP #func4 \ If FUNC-4 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 #func2 \ If FUNC-2 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 #&48 \ If "@" was pressed, jump to SVE to save the commander BNE P%+5 \ file, returning from the subroutine using a tail call JMP SVE CMP #func3 \ If FUNC-3 was pressed, jump to TT208 to show the Sell BNE LABEL_3 \ Cargo screen, returning from the subroutine using a JMP TT208 \ tail call .INSP STX T \ Store X in T so we can retrieve it after the following LDX #3 \ We are about to loop through the key presses for the \ four views, so set a counter in X, starting with a \ value of X = 3 (for the right view) .LOOKL CMP VKEYS-1,X \ If the key pressed does not match the value in VKEYS BNE P%+5 \ for view X, skip the following instruction JMP LOOK1 \ The key pressed matches the key in position X, so jump \ to LOOK1 to switch to view X (rear, left or right), \ returning from the subroutine using a tail call DEX \ Decrement the view number in X, so we start with view \ 3 (right), then work backwards through 2 (left) and \ 1 (rear) BNE LOOKL \ Loop back to check the next key until we have checked \ for f3, f2 and f1 LDX T \ Fetch the value of X that we stored in T above .LABEL_3 CMP #&54 \ If "H" was pressed, jump to hyp to do a hyperspace BNE P%+5 \ jump (if we are in space), returning from the JMP hyp \ subroutine using a tail call 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) STA T1 \ Store A (the key that's been pressed) in T1 LDA QQ11 \ If the current view is a chart (QQ11 = 64 or 128), AND #%11000000 \ keep going, otherwise jump down to TT107 to skip the BEQ TT107 \ following LDA QQ22+1 \ If the on-screen hyperspace counter is non-zero, BNE TT107 \ then we are already counting down, so jump to TT107 \ to skip the following LDA T1 \ Restore the original value of A (the key that's been \ pressed) from T1 CMP #&36 \ If "O" was pressed, do the following three jumps, BNE ee2 \ otherwise skip to ee2 to continue 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 JSR TT103 \ Draw small crosshairs at coordinates (QQ9, QQ10), \ which will draw the crosshairs at our current home \ system .ee2 JSR TT16 \ Call TT16 to move the crosshairs by the amount in X \ and Y, which were passed to this subroutine as \ arguments .TT107 LDA QQ22+1 \ If the on-screen hyperspace counter is zero, return BEQ t95 \ from the subroutine (as t95 contains an RTS), as we \ are not currently counting down to a hyperspace jump DEC QQ22 \ Decrement the internal hyperspace counter BNE t95 \ If the internal hyperspace counter is still non-zero, \ then we are still counting down, so return from the \ subroutine (as t95 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 t95 \ If the countdown is not yet at zero, return from the \ subroutine (as t95 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 .t95 RTS \ Return from the subroutine .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