Skip to navigation


Text: MT26

[BBC 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 .OSW0L 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 OSW03 BEQ OSW03 CMP #27 \ If ESCAPE was pressed, jump to OSW04 BEQ OSW04 CMP #127 \ If DELETE was pressed, jump to OSW05 BEQ OSW05 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 between 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 OSW01 \ OSWORD configuration block at RLINE), then jump to \ OSW01 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 OSW01 \ RLINE+3 (the lowest allowed character from the OSWORD \ configuration block at RLINE), then jump to OSW01 \ to give an error beep as the key pressed is out of \ range CMP RLINE+4 \ If the key pressed is greater than or equal to the BCS OSW01 \ character in RLINE+4 (the highest allowed character \ from the OSWORD configuration block at RLINE), then \ jump to OSW01 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 .OSW01 LDA #7 \ Set A to the beep character, so the next instruction \ makes a system beep .OSW06 JSR CHPR \ Print the character in A (and clear the C flag) BCC OSW0L \ Loop back to OSW0L to fetch another key press (this \ BCC is effectively a JMP as CHPR clears the C flag) .OSW03 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 .OSW04 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 .OSW05 TYA \ If the length of the line so far in Y is 0, then we BEQ OSW01 \ just pressed DELETE on an empty line, so jump to \ OSW01 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 OSW06 to print the BNE OSW06 \ character in A (i.e. the DELETE character) and listen \ for the next key press