Routines
| Prev: D898 | Up: Map | Next: D95C |
D8AD: The line editor
|
Prints the '> ' prompt and reads up to 128 characters into $5B00 through A536: DELETE rubs out (and keeps track of quote marks, D897), $18 clears the line (D9B7), letters, digits and a few punctuation marks are accepted, ENTER ends the line (D949). A time-out from A536 ends it with nothing (D9AC).
How it works:
1. Print the prompt '> ' and set up the buffer at $5B00; B counts down from 128, with bit 7 set while nothing has been typed.
2. Wait for a key with the time limit (A536). If time runs out, give up: the player will wait.
3. On an empty line, '@' repeats the last command (D99E). The first key of a line may be a cursor key, which is turned into a one-key move (D978).
4. Rub-out ($18) clears the whole line; DELETE removes one character, and removing a quote mark flips the inside-quotes flag.
5. Letters are taken. A quote mark flips the flag (closing a quotation first ends it with a full stop). Space, full stop, comma, slash, the pound sign, hyphen, colon and digits are taken. Anything else is ignored.
6. ENTER closes any open quotation, ends the line with a full stop (D968) and a carriage return, and returns NZ.
|
||||||||||
| D8AD | LD A,$3E | Load A with $3E - Print the prompt '> ' | ||||||||
| D8AF | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||
| D8B2 | LD A,$20 | Load A with $20 | ||||||||
| D8B4 | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||
| D8B7 | LD HL,$5B00 | Load HL with $5B00 - The line goes to $5B00; B counts down from $80 (bit 7 set: nothing typed yet) | ||||||||
| D8BA | LD B,$80 | Load B with $80 | ||||||||
| D8BC | LD A,$01 | Load A with $01 - D897 = 1: not inside quotes; C = 0: no key yet | ||||||||
| D8BE | LD ($D897),A | Store A in "The line editor's inside-quotes flag" (D897) | ||||||||
| D8C1 | LD C,$00 | Load C with $00 | ||||||||
|
This entry point is used by the routine at D99E.
|
||||||||||
| D8C3 | CALL $A536 | Call the routine "Wait for a key, but not for ever" (A536) - Wait for a key, with the time limit (A536); time up: give up the line | ||||||||
| D8C6 | JP Z,$D9AC | If the zero flag is set, jump on to D9AC | ||||||||
| D8C9 | BIT 7,B | Test bit 7 of B - On an empty line '@' repeats the last command (D99E) | ||||||||
| D8CB | JR Z,$D8D2 | If bit 7 of B is clear, skip ahead to D8D2 | ||||||||
| D8CD | CP $40 | Compare A with $40 | ||||||||
| D8CF | JP Z,$D99E | If A equals $40, jump on to the routine "The '@' key on an empty line: do the last command..." (D99E) | ||||||||
| D8D2 | BIT 0,C | Test bit 0 of C - The first key of a line may be a cursor key: a one-key move (D978) | ||||||||
| D8D4 | CALL Z,$D978 | If bit 0 of C is clear, call the routine "A cursor key on an empty line is a compass move" (D978) | ||||||||
| D8D7 | LD C,$01 | Load C with $01 | ||||||||
| D8D9 | CP $18 | Compare A with $18 - $18 ('_', made so by GET-KEY): rub out the whole line and start again | ||||||||
| D8DB | JR NZ,$D8E2 | If A differs from $18, skip ahead to D8E2 | ||||||||
| D8DD | CALL $D9B7 | Call the routine "Rub out the typed line" (D9B7) | ||||||||
| D8E0 | JR $D8BC | Go back to D8BC | ||||||||
| D8E2 | CP $08 | Compare A with $08 - $08 (DELETE): back one character, unless the line is empty | ||||||||
| D8E4 | JR NZ,$D900 | If A differs from $08, skip ahead to D900 | ||||||||
| D8E6 | BIT 7,B | Test bit 7 of B | ||||||||
| D8E8 | JR NZ,$D8C3 | If bit 7 of B is set, go back to D8C3 | ||||||||
| D8EA | LD A,$08 | Load A with $08 | ||||||||
| D8EC | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||
| D8EF | INC B | Add one to B | ||||||||
| D8F0 | DEC HL | Step HL back one byte | ||||||||
| D8F1 | LD A,(HL) | Read the byte HL points at into A - Rubbing out a quote mark flips the inside-quotes flag back | ||||||||
| D8F2 | CP $22 | Compare A with $22 | ||||||||
| D8F4 | JR NZ,$D8C3 | If A differs from $22, go back to D8C3 | ||||||||
| D8F6 | LD A,($D897) | Read "The line editor's inside-quotes flag" (D897) into A | ||||||||
| D8F9 | XOR $01 | Flip in A the bits that are set in $01 | ||||||||
| D8FB | LD ($D897),A | Store A in "The line editor's inside-quotes flag" (D897) | ||||||||
| D8FE | JR $D8C3 | Go back to D8C3 | ||||||||
| D900 | CP $40 | Compare A with $40 - Letters ($40 up) are always taken | ||||||||
| D902 | JR NC,$D93C | If A is $40 or more, jump on to D93C | ||||||||
| D904 | CP $22 | Compare A with $22 - A quote mark flips the flag; closing a quotation first ends it with a full stop (D968) | ||||||||
| D906 | JR NZ,$D917 | If A differs from $22, skip ahead to D917 | ||||||||
| D908 | LD A,($D897) | Read "The line editor's inside-quotes flag" (D897) into A | ||||||||
| D90B | XOR $01 | Flip in A the bits that are set in $01 | ||||||||
| D90D | LD ($D897),A | Store A in "The line editor's inside-quotes flag" (D897) | ||||||||
| D910 | CALL NZ,$D968 | If the result is not zero, call the routine "End the typed line with a full stop if it has none" (D968) | ||||||||
| D913 | LD A,$22 | Load A with $22 | ||||||||
| D915 | JR $D93C | Skip ahead to D93C | ||||||||
| D917 | CP $20 | Compare A with $20 - Space, ENTER, . , / ` - : are taken... | ||||||||
| D919 | JR Z,$D93C | If A equals $20, skip ahead to D93C | ||||||||
| D91B | CP $0D | Compare A with $0D - Carriage return: end of line (D949) | ||||||||
| D91D | JR Z,$D949 | If A equals $0D, jump on to D949 | ||||||||
| D91F | CP $2E | Compare A with $2E - A '.' ends a word (D93C)... | ||||||||
| D921 | JR Z,$D93C | If A equals $2E, skip ahead to D93C | ||||||||
| D923 | CP $2C | Compare A with $2C - ...and so do ','... | ||||||||
| D925 | JR Z,$D93C | If A equals $2C, skip ahead to D93C | ||||||||
| D927 | CP $2F | Compare A with $2F | ||||||||
| D929 | JR Z,$D93C | If A equals $2F, skip ahead to D93C | ||||||||
| D92B | CP $60 | Compare A with $60 - ...the pound sign ($60)... | ||||||||
| D92D | JR Z,$D93C | If A equals $60, skip ahead to D93C | ||||||||
| D92F | CP $2D | Compare A with $2D | ||||||||
| D931 | JR Z,$D93C | If A equals $2D, skip ahead to D93C | ||||||||
| D933 | CP $3A | Compare A with $3A - ...and ':' | ||||||||
| D935 | JR Z,$D93C | If A equals $3A, skip ahead to D93C | ||||||||
| D937 | CALL $DAE8 | Call the routine "Is A a digit? (carry if not)" (DAE8) - ...and digits (DAE8); anything else is ignored | ||||||||
| D93A | JR C,$D8C3 | If the carry flag is set, go back to D8C3 | ||||||||
| D93C | DEC B | Subtract one from B - Store and print it, if the 128-character line has room | ||||||||
| D93D | INC B | Add one to B | ||||||||
| D93E | JR Z,$D946 | If B has become zero, skip ahead to D946 | ||||||||
| D940 | LD (HL),A | Store A at the address HL points to | ||||||||
| D941 | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||
| D944 | INC HL | Step HL on to the next byte | ||||||||
| D945 | DEC B | Subtract one from B | ||||||||
| D946 | JP $D8C3 | Go back to D8C3 | ||||||||
| D949 | LD A,($D897) | Read "The line editor's inside-quotes flag" (D897) into A - ENTER: close an open quotation (D95C), | ||||||||
| D94C | AND A | Test A for zero (this leaves A as it was and clears carry) | ||||||||
| D94D | CALL Z,$D95C | If A is zero, call the routine "Close a quotation: a full stop if needed, then the..." (D95C) | ||||||||
| D950 | CALL $D968 | Call the routine "End the typed line with a full stop if it has none" (D968) - end with a full stop (D968) and a carriage return | ||||||||
| D953 | LD A,$0D | Load A with $0D | ||||||||
| D955 | LD (HL),A | Store A at the address HL points to | ||||||||
| D956 | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||
| D959 | OR $01 | Make A non-zero, which clears the zero flag, and hand that back to the caller - NZ: a line was typed | ||||||||
| D95B | RET | Return to the caller | ||||||||
| Prev: D898 | Up: Map | Next: D95C |