| The Hobbit (v1.0) | Routines |
| Prev: 6DC3 | Up: Map | Next: 6E46 |
|
This is The Hobbit's line editor. It starts by setting the idle timer at $B604 to 3000 (see 7240), and setting $B5F2 and $B5EB to 1, then prints the '>' prompt and a space.
Characters are collected into the input buffer at 6FF0. B counts the space left, starting at 128 ($80), so bit 7 of B being set means that nothing has been typed yet. C is 0 until the first key has been handled.
Keys are fetched by 7240, which also types WAIT for the player if they are idle for too long. Each key is then handled as follows:
An accepted character is stored in $B5F5 (the printer uses this to remember the last punctuation mark), echoed to the screen via 7580, and put in the buffer, as long as there is room (B not 0). ENTER ($0D) ends the line: it is stored like any other character, and the routine returns with the Z flag reset.
Note that letters are not converted to upper case here. They do not need to be: the tokeniser keeps only the low five bits of each letter (6F3E), and that is the same for 'a' and 'A'.
|
||||||||
| 6DCD | LD HL,$0BB8 | Allow 3000 key polls before WAIT is typed automatically | ||||||
| 6DD0 | LD ($B604),HL | Store HL in the idle counter | ||||||
| 6DD3 | LD A,$01 | A = 1 | ||||||
| 6DD5 | LD ($B5F2),A | Store A in the lower-window flag | ||||||
| 6DD8 | LD ($B5EB),A | Store A in the "really do it" flag | ||||||
| 6DDB | LD A,$3E | Print the prompt "> " | ||||||
| 6DDD | CALL $7580 | Print the character in A | ||||||
| 6DE0 | LD A,$20 | A = 32 | ||||||
| 6DE2 | CALL $7580 | Print the character in A | ||||||
| 6DE5 | LD HL,$6FF0 | HL = input buffer, B = 128 characters of space, C = 0 (no keys yet) | ||||||
| 6DE8 | LD B,$80 | B = 128 | ||||||
| 6DEA | LD C,$00 | C = 0 | ||||||
|
This entry point is used by the routine at 6E71.
|
||||||||
| 6DEC | CALL $7240 | Wait for a key | ||||||
| 6DEF | BIT 7,B | First character of the line? | ||||||
| 6DF1 | JR Z,$6DF8 | If the bit is clear, go to 6DF8 | ||||||
| 6DF3 | CP $40 | "@" as the first key: repeat the last command | ||||||
| 6DF5 | JP Z,$6E71 | If yes, go to Repeat the last command (6E71) | ||||||
| 6DF8 | BIT 0,C | First key of the line: check for cursor-key shortcuts | ||||||
| 6DFA | CALL Z,$6E46 | If zero/equal: call: Cursor-key shortcuts (6E46) | ||||||
| 6DFD | LD C,$01 | C = 1 | ||||||
| 6DFF | CP $18 | SYMBOL SHIFT + 0: delete the whole line | ||||||
| 6E01 | JR NZ,$6E08 | If no, go to 6E08 | ||||||
| 6E03 | CALL $6E82 | Call: Delete the whole input line (6E82) | ||||||
| 6E06 | JR $6DEA | Continue at 6DEA | ||||||
| 6E08 | CP $08 | Backspace? | ||||||
| 6E0A | JR NZ,$6E19 | If no, go to 6E19 | ||||||
| 6E0C | BIT 7,B | Ignore it if the line is empty | ||||||
| 6E0E | JR NZ,$6DEC | If the bit is set, go to 6DEC | ||||||
| 6E10 | LD A,$08 | Otherwise rub out the last character | ||||||
| 6E12 | CALL $7580 | Print the character in A | ||||||
| 6E15 | INC B | Increment B | ||||||
| 6E16 | DEC HL | Decrement HL | ||||||
| 6E17 | JR $6DEC | Continue at 6DEC | ||||||
| 6E19 | CP $40 | Accept letters... | ||||||
| 6E1B | JR NC,$6E31 | If A >= 64, go to 6E31 | ||||||
| 6E1D | CP $22 | ...double quote, space, ENTER, full stop and comma | ||||||
| 6E1F | JR Z,$6E31 | If yes, go to 6E31 | ||||||
| 6E21 | CP $20 | Is it " "? | ||||||
| 6E23 | JR Z,$6E31 | If yes, go to 6E31 | ||||||
| 6E25 | CP $0D | Compare with 13 | ||||||
| 6E27 | JR Z,$6E31 | If yes, go to 6E31 | ||||||
| 6E29 | CP $2E | Is it "."? | ||||||
| 6E2B | JR Z,$6E31 | If yes, go to 6E31 | ||||||
| 6E2D | CP $2C | Is it ","? | ||||||
| 6E2F | JR NZ,$6DEC | If no, go to 6DEC | ||||||
| 6E31 | LD ($B5F5),A | Remember the character for the printer | ||||||
| 6E34 | DEC B | Buffer full? | ||||||
| 6E35 | INC B | Increment B | ||||||
| 6E36 | JR Z,$6E3E | If Z is set, go to 6E3E | ||||||
| 6E38 | CALL $7580 | Echo the character and store it | ||||||
| 6E3B | LD (HL),A | Store A at (HL) | ||||||
| 6E3C | INC HL | Increment HL | ||||||
| 6E3D | DEC B | Decrement B | ||||||
| 6E3E | CP $0D | Loop until ENTER | ||||||
| 6E40 | JP NZ,$6DEC | If no, go to 6DEC | ||||||
| 6E43 | OR $01 | Return with Z reset | ||||||
| 6E45 | RET | Done | ||||||
| Prev: 6DC3 | Up: Map | Next: 6E46 |