| The Hobbit (v1.0) | Routines |
| Prev: 6C27 | Up: Map | Next: 6DC3 |
|
This is the heart of the game. Each pass round the loop is one line of input from the player:
1. 6DCD prints the '>' prompt and reads a line of text into the input buffer at 6FF0. If the player types nothing for a while, 7240 types WAIT on their behalf, so time passes in The Hobbit even if you do not.
2. The token buffer at 7093 is cleared (70D9), and then 6E8E is called repeatedly to turn the line into tokens, one per word. Each token is two bytes, stored high byte first: the high byte is the word's class (see 6040) in its top four bits plus the top four bits of the word's 12-bit dictionary offset; the low byte is the bottom eight bits of the offset.
3. Double quotes get special treatment (from 6D2F). A quote comes back from 6E8E as class $90 with an offset of 0. The flag at $B60B records whether we are inside a quotation. At an opening quote the flag is set. At a closing quote the flag is cleared and, unless the previous token was already a comma ($A0) or full stop ($B0), a full-stop token is inserted before the quote token, so that whatever was said to a character ends like a complete sentence.
4. Tokens are stored until the end-of-line token ($C0). A token of class $D0 means the word was not in the dictionary: the game jumps to 6D99, which prints a message saying it does not know the word and quotes the word back from the input line (up to the next space or quote, using the pointer at B5CB). If the line ends with a quotation still open, 7FF9 is called to complain and the line is thrown away.
|
||||
| 6D0A | LD A,$01 | A = 1 | ||
| 6D0C | LD ($B5F6),A | Store A in the "more commands" flag | ||
| 6D0F | LD A,$09 | A = 9 | ||
| 6D11 | LD ($B606),A | Store A in the lines left before pausing | ||
| 6D14 | CALL $6DCD | Read a line of input | ||
| 6D17 | JR Z,$6D81 | Z set: repeat the previous command | ||
|
This entry point is used by the routine at 6C27.
|
||||
| 6D19 | LD HL,$7093 | HL = Token buffer (7093) | ||
| 6D1C | LD B,$40 | B = 64 | ||
| 6D1E | CALL $70D9 | Clear the token buffer | ||
| 6D21 | LD HL,$6FF0 | HL = Input buffer (6FF0) | ||
| 6D24 | LD IY,$7093 | IY = Token buffer (7093) | ||
| 6D28 | CALL $6E8E | Turn the next word into a token | ||
| 6D2B | CP $D0 | End of line? | ||
| 6D2D | JR Z,$6D99 | If yes, go to 6D99 | ||
| 6D2F | CP $90 | A quote? | ||
| 6D31 | JR NZ,$6D63 | If no, go to 6D63 | ||
| 6D33 | LD A,B | A = B | ||
| 6D34 | AND $0F | Keep only the bits of $0F | ||
| 6D36 | OR C | Combine with C | ||
| 6D37 | JR NZ,$6D63 | If it is not zero, go to 6D63 | ||
| 6D39 | LD A,($B60B) | Opening or closing quote? | ||
| 6D3C | AND A | Is A zero? | ||
| 6D3D | JR NZ,$6D45 | If it is not zero, go to 6D45 | ||
| 6D3F | INC A | Increment A | ||
| 6D40 | LD ($B60B),A | Store A in the quotation level | ||
| 6D43 | JR $6D63 | Continue at 6D63 | ||
| 6D45 | DEC A | Decrement A | ||
| 6D46 | LD ($B60B),A | Store A in the quotation level | ||
| 6D49 | LD A,(IY-$02) | Closing quote: was the previous token a comma or full stop? | ||
| 6D4C | AND $F0 | Keep only the bits of $F0 | ||
| 6D4E | CP $B0 | Compare with 176 | ||
| 6D50 | JR Z,$6D63 | If yes, go to 6D63 | ||
| 6D52 | CP $A0 | Compare with 160 | ||
| 6D54 | JR Z,$6D63 | If yes, go to 6D63 | ||
| 6D56 | LD A,$B0 | No: insert a full stop token | ||
| 6D58 | LD (IY+$00),A | Store A at (IY+0) | ||
| 6D5B | XOR A | A = 0 | ||
| 6D5C | LD (IY+$01),A | Store A at (IY+1) | ||
| 6D5F | INC IY | Increment IY | ||
| 6D61 | INC IY | Increment IY | ||
| 6D63 | LD (IY+$00),B | Store the token | ||
| 6D66 | LD (IY+$01),C | Store C at (IY+1) | ||
| 6D69 | INC IY | Increment IY | ||
| 6D6B | INC IY | Increment IY | ||
| 6D6D | LD A,D | Loop until the end-of-line token ($C0) | ||
| 6D6E | CP $C0 | Compare with 192 | ||
| 6D70 | JR NZ,$6D28 | If no, go to 6D28 | ||
| 6D72 | LD A,($B60B) | Quote still open at the end of the line? | ||
| 6D75 | AND A | Is A zero? | ||
| 6D76 | JR Z,$6D81 | If it is zero, go to 6D81 | ||
| 6D78 | XOR A | A = 0 | ||
| 6D79 | LD ($B60B),A | Store A in the quotation level | ||
| 6D7C | CALL $7FF9 | Yes: complain and start again | ||
| 6D7F | JR $6D0A | Continue at Main command loop (6D0A) | ||
| 6D81 | LD HL,$7093 | Parse the tokens | ||
| 6D84 | LD ($B5CD),HL | Store HL in the token pointer | ||
| 6D87 | CALL $7C4F | Call: Parse the command (7C4F) | ||
| 6D8A | JP NZ,$6D0A | If the routine returned with Z reset, go to Main command loop (6D0A) | ||
| 6D8D | CALL $8351 | Execute the command and run the rest of the turn | ||
| 6D90 | LD A,($B5F6) | More commands on this line? | ||
| 6D93 | AND A | Is A zero? | ||
| 6D94 | JR NZ,$6D87 | If it is not zero, go to 6D87 | ||
| 6D96 | JP $6D0A | Finish by jumping to Main command loop (6D0A) | ||
| 6D99 | LD HL,$AC87 | Unknown word: complain and quote it | ||
| 6D9C | LD A,$01 | A = 1 | ||
| 6D9E | LD ($B5F2),A | Store A in the lower-window flag | ||
| 6DA1 | CALL $72D4 | Print the message at HL | ||
| 6DA4 | LD HL,($B5CB) | HL = the start of the current word | ||
| 6DA7 | LD A,(HL) | A = (HL) | ||
| 6DA8 | CP $0D | Compare with 13 | ||
| 6DAA | JR Z,$6DB8 | If yes, go to 6DB8 | ||
| 6DAC | CP $22 | Is it """? | ||
| 6DAE | JR Z,$6DB8 | If yes, go to 6DB8 | ||
| 6DB0 | CALL $7580 | Print the character in A | ||
| 6DB3 | INC HL | Increment HL | ||
| 6DB4 | CP $20 | Is it " "? | ||
| 6DB6 | JR NZ,$6DA7 | If no, go to 6DA7 | ||
| 6DB8 | LD A,$22 | A = 34 | ||
| 6DBA | CALL $7580 | Print the character in A | ||
| 6DBD | CALL $7578 | Print a new line | ||
| 6DC0 | JP $6D0A | Finish by jumping to Main command loop (6D0A) | ||
| Prev: 6C27 | Up: Map | Next: 6DC3 |