Skip to navigation

Elite on the BBC Micro

Text: MT26 [Master version]

Name: MT26 [Show more] Type: Subroutine Category: Text Summary: Fetch a line of text from the keyboard Deep dive: Extended text tokens
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: * DELT calls MT26 * GTDIR calls MT26 * GTNMEW calls MT26 * JMTB calls MT26

Returns: Y The size of the entered text, or 0 if none was entered INWK+5 The entered text, terminated by a carriage return C flag Set if ESCAPE was pressed
.MT26 LDA COL \ Store the current colour on the stack PHA LDA #RED \ Switch to colour 2, which is magenta in the trade view STA COL LDY #8 \ Wait for 8/50 of a second (0.16 seconds) JSR DELAY JSR FLKB \ Call FLKB to flush the keyboard buffer LDY #0 \ Set Y = 0 to hold the length of the text entered .MT26L JSR TT217 \ Scan the keyboard until a key is pressed, and return \ the key's ASCII code in A (and X) CMP #13 \ If RETURN was pressed, jump to MT26ret BEQ MT26ret CMP #27 \ If ESCAPE was pressed, jump to MT26esc BEQ MT26esc CMP #127 \ If DELETE was pressed, jump to MT26ret BEQ MT26del IF _COMPACT PHX \ Store X on the stack so we can retrieve it after the \ call to SHIFT PHA \ Store the number of the key being pressed on the stack JSR SHIFT \ If SHIFT is not being pressed, jump to noshift to skip BPL noshift \ the following PLA \ SHIFT is being pressed, so fetch the number of the key \ being pressed from the stack CMP #'@' \ If A >= ASCII "@", then we are pressing a letter key, BCS P%+4 \ so skip the following instruction EOR #%00010000 \ We are pressing SHIFT and a number key, so flip bit 4 \ of the key number, which flips the letter betweeen the \ ASCII code of the number being pressed and the ASCII \ code of the number being pressed when SHIFT is being \ held down (so SHIFT-1 will enter !, SHIFT-2 will enter \ ", and so on) PHA \ Push the updated key number onto the stack .noshift PLA \ Retrieve the values of X and A we stored on the stack PLX \ above ENDIF CPY RLINE+2 \ If Y >= RLINE+2 (the maximum line length from the BCS MT26err \ OSWORD configuration block at RLINE), then jump to \ MT26err to give an error beep as we have reached the \ character limit CMP RLINE+3 \ If the key pressed is less than the character in BCC MT26err \ RLINE+3 (the lowest allowed character from the OSWORD \ configuration block at RLINE), then jump to MT26err \ to give an error beep as the key pressed is out of \ range CMP RLINE+4 \ If the key pressed is geater than or equal to the BCS MT26err \ character in RLINE+4 (the highest allowed character \ from the OSWORD configuration block at RLINE), then \ jump to MT26err to give an error beep as the key \ pressed is out of range STA INWK+5,Y \ Store the key's ASCII code in the Y-th byte of INWK+5 INY \ Increment Y to point to the next free byte in INWK+5 EQUB &2C \ Skip the next instruction by turning it into \ &2C &A9 &07, or BIT &07A9, which does nothing apart \ from affect the flags .MT26err LDA #7 \ Set A to the beep character, so the next instruction \ makes a system beep .MT26LS JSR CHPR \ Print the character in A (and clear the C flag) BCC MT26L \ Loop back to MT26L to fetch another key press (this \ BCC is effectively a JMP as CHPR clears the C flag) .MT26ret STA INWK+5,Y \ Store the return character in the Y-th byte of INWK+5 LDA #12 \ Print a newline JSR CHPR EQUB &24 \ Skip the next instruction by turning it into &24 &38, \ or BIT &0038, which does nothing apart from affect the \ flags .MT26esc SEC \ Set the C flag as ESCAPE was pressed PLA \ Restore the original colour from the stack and set it STA COL \ as the current colour RTS \ Return from the subroutine .MT26del TYA \ If the length of the line so far in Y is 0, then we BEQ MT26err \ just pressed DELETE on an empty line, so jump to \ MT26err give an error beep DEY \ Otherwise we want to delete a character, so decrement \ the length of the line so far in Y LDA #127 \ Set A = 127 and jump back to MT26LS to print the BNE MT26LS \ character in A (i.e. the DELETE character) and listen \ for the next key press