| The Hobbit (v1.0) | Routines |
| Prev: 7225 | Up: Map | Next: 7282 |
|
Polls the keyboard (7B86) until a key is pressed, counting the polls down from the value at $B604. Each poll includes the 1000-iteration delay in 7B6B, so it takes something like 8 ms, and the starting value of 3000 set by 6DCD gives the player roughly 20-25 seconds (my estimate from the instruction timings).
When a key is pressed, 500 is added to what is left of the count, up to a maximum of 3000, so steady typing keeps the time topped up.
If the count runs out, the game takes over: whatever has been typed is erased (6E82), the four characters 'WAIT' from 7288 are put into the input buffer and printed, B is set to $7C (four characters used), the count is reset to 3000, and an ENTER is returned as if the player had pressed it. The line editor then finishes the line and the WAIT command is carried out. This is how time passes in The Hobbit even when the player does nothing, and why the other characters can go off and do things - or attack you - while you are thinking.
|
||||||||||||
| 7240 | PUSH HL | Save HL | ||||||||||
| 7241 | LD HL,($B604) | HL = polls left before WAIT | ||||||||||
| 7244 | CALL $7B86 | Is a key being pressed? | ||||||||||
| 7247 | AND A | Is A zero? | ||||||||||
| 7248 | JR NZ,$726A | If it is not zero, go to 726A | ||||||||||
| 724A | DEC HL | No: count down | ||||||||||
| 724B | LD A,H | A = H | ||||||||||
| 724C | OR L | Combine with L | ||||||||||
| 724D | JR NZ,$7244 | If it is not zero, go to 7244 | ||||||||||
| 724F | POP HL | Restore HL | ||||||||||
| 7250 | PUSH HL | Save HL | ||||||||||
| 7251 | CALL $6E82 | Time up: rub out what has been typed | ||||||||||
| 7254 | LD DE,$7288 | Put WAIT into the buffer and print it | ||||||||||
| 7257 | LD B,$04 | B = 4 | ||||||||||
| 7259 | LD A,(DE) | A = (DE) | ||||||||||
| 725A | LD (HL),A | Store A at (HL) | ||||||||||
| 725B | INC HL | Increment HL | ||||||||||
| 725C | INC DE | Increment DE | ||||||||||
| 725D | CALL $7580 | Print the character in A | ||||||||||
| 7260 | DJNZ $7259 | Loop back until B reaches 0 | ||||||||||
| 7262 | EX (SP),HL | Swap HL with the value on top of the stack | ||||||||||
| 7263 | LD B,$7C | Four characters used; return ENTER | ||||||||||
| 7265 | LD A,$0D | A = 13 | ||||||||||
| 7267 | LD HL,$FE0C | This makes the addition below overflow, so the count is reset to 3000 | ||||||||||
| 726A | PUSH AF | Save AF | ||||||||||
| 726B | XOR A | A = 0 | ||||||||||
| 726C | LD DE,$01F4 | Add 500 to the polls left... | ||||||||||
| 726F | ADC HL,DE | Add HL,DE with carry | ||||||||||
| 7271 | LD DE,$0BB8 | ...but no more than 3000 | ||||||||||
| 7274 | JR C,$727B | If carry is set, go to 727B | ||||||||||
| 7276 | CALL $7282 | Call: Compare HL with DE (7282) | ||||||||||
| 7279 | JR C,$727C | If the routine returned with carry set, go to 727C | ||||||||||
| 727B | EX DE,HL | Swap DE and HL | ||||||||||
| 727C | LD ($B604),HL | Save the new count | ||||||||||
| 727F | POP AF | Restore AF | ||||||||||
| 7280 | POP HL | Restore HL | ||||||||||
| 7281 | RET | Done | ||||||||||
| Prev: 7225 | Up: Map | Next: 7282 |