| The Hobbit (v1.0) | Routines |
| Prev: 6C00 | Up: Map | Next: 6D0A |
|
This is where the game begins, and where it comes back to after 'you are dead' (see 903C). It is the reverse of 6C00: the backed-up copies of the object table, room table, variables and timer tables are copied back over the live ones, so every object, character, door and timer returns to its starting state.
It then sets the border to black, waits for a key press (the IN A,($FE) loop at 6C6E: keys read as 0 bits, so the loop continues while all five bits are 1), sets up the text window variables used by the printer (75AD), clears a 200-byte work area at B628, and seeds the random number generator from the Z80's R (refresh) register at 6C9E. Because R counts instructions, the seed depends on exactly how long the player took to press a key, which is why every game plays out differently.
The routine then clears the screen (6FCA), draws the bar that separates the story window from the input window (a 5-line pattern from 6DC3, repeated across the screen at $5140), sets the line counter used by the story window's pause (7694) to 17, and, if this is a fresh start (the frame count at $B5F7 is $FF, as it always is after the variables are restored), makes the game's random choices (970B), puts the first command, LOOK, into the input buffer (copied from 6FEB to 6FF0), and drops into the main loop at 6D0A.
|
||||
| 6C27 | DI | Disable interrupts | ||
| 6C28 | LD SP,$5EFF | SP = $5EFF | ||
| 6C2B | LD IX,$CC00 | IX = the picture index | ||
| 6C2F | LD A,$05 | A = 5 | ||
| 6C31 | CALL $9D12 | Call: Search a table of 3-byte entries (9D12) | ||
| 6C34 | LD L,(IX+$01) | L = the low byte of the address of the table entry | ||
| 6C37 | LD H,(IX+$02) | H = the high byte of the address of the table entry | ||
| 6C3A | LD (HL),$00 | Store $00 at (HL) | ||
| 6C3C | INC HL | Increment HL | ||
| 6C3D | LD (HL),$00 | Store $00 at (HL) | ||
| 6C3F | LD HL,$F400 | Restore objects, rooms, variables and timers from the backups | ||
| 6C42 | LD DE,$C00B | DE = the object table (Bilbo's record) | ||
| 6C45 | LD BC,$0614 | BC = $0614 | ||
| 6C48 | LDIR | Copy BC bytes from HL to DE | ||
| 6C4A | LD DE,$B97A | DE = the address of room 0's flags | ||
| 6C4D | LD BC,$05D9 | BC = $05D9 | ||
| 6C50 | LDIR | Copy BC bytes from HL to DE | ||
| 6C52 | LD HL,$5F00 | HL = $5F00 | ||
| 6C55 | LD DE,$B5DC | DE = the address of the saved variables | ||
| 6C58 | LD BC,$001C | BC = 28 | ||
| 6C5B | LDIR | Copy BC bytes from HL to DE | ||
| 6C5D | LD DE,$C973 | DE = the timer table | ||
| 6C60 | LD BC,$00BF | BC = 191 | ||
| 6C63 | LDIR | Copy BC bytes from HL to DE | ||
| 6C65 | XOR A | A = 0 | ||
| 6C66 | OUT ($FE),A | Write to the port (border colour, beeper or printer) | ||
| 6C68 | LD A,$38 | A = 56 | ||
| 6C6A | LD ($5C48),A | Store A at $5C48 | ||
| 6C6D | XOR A | A = 0 | ||
| 6C6E | IN A,($FE) | Wait until a key is pressed | ||
| 6C70 | AND $1F | Keep only the bits of $1F | ||
| 6C72 | CP $1F | Compare with 31 | ||
| 6C74 | JR Z,$6C6D | If yes, go to 6C6D | ||
| 6C76 | LD HL,$50E0 | HL = $50E0 | ||
| 6C79 | LD ($75A9),HL | Store HL in the lower window print position | ||
| 6C7C | LD A,$2B | A = 43 | ||
| 6C7E | LD ($75AB),A | Store A at $75AB | ||
| 6C81 | LD HL,$5020 | HL = $5020 | ||
| 6C84 | LD ($768F),HL | Store HL in the story window print position | ||
| 6C87 | LD A,$01 | A = 1 | ||
| 6C89 | LD ($7691),A | Store A in the pixel offset | ||
| 6C8C | LD A,$20 | A = 32 | ||
| 6C8E | LD ($75A8),A | Store A in the columns left in the lower window | ||
| 6C91 | LD A,$2A | A = 42 | ||
| 6C93 | LD ($768E),A | Store A in the characters left on the line | ||
| 6C96 | LD B,$C8 | B = 200 | ||
| 6C98 | LD HL,$B628 | HL = the orders buffer | ||
| 6C9B | CALL $70D9 | Call: Clear a block of memory (70D9) | ||
| 6C9E | LD A,R | Seed the random number generator from R | ||
| 6CA0 | LD ($B5FE),A | Store A in the random seed | ||
| 6CA3 | XOR A | A = 0 | ||
| 6CA4 | LD ($7692),A | Store A in the indent | ||
| 6CA7 | LD ($7693),A | Store A at $7693 | ||
| 6CAA | LD ($B60A),A | Store A in the "unfinished command" flag | ||
| 6CAD | LD ($B5F1),A | Store A in the drunkenness flag | ||
| 6CB0 | LD ($B5E3),A | Store A in the printer flag | ||
| 6CB3 | LD A,$01 | A = 1 | ||
| 6CB5 | LD ($B5F3),A | Store A in the "visible to Bilbo" output flag | ||
| 6CB8 | LD ($B5EB),A | Store A in the "really do it" flag | ||
| 6CBB | LD ($B5F5),A | Store A in the capitalisation flag | ||
| 6CBE | LD HL,$0000 | HL = 0 | ||
| 6CC1 | LD ($B5E8),HL | Store HL in the score | ||
| 6CC4 | CALL $6FCA | Call: Clear the screen (6FCA) | ||
| 6CC7 | LD HL,$5140 | HL = $5140 | ||
| 6CCA | LD DE,$6DC3 | DE = Window separator pattern (6DC3) | ||
| 6CCD | LD C,$05 | C = 5 | ||
| 6CCF | LD B,$10 | B = 16 | ||
| 6CD1 | PUSH HL | Save HL | ||
| 6CD2 | LD A,(DE) | A = (DE) | ||
| 6CD3 | LD (HL),A | Store A at (HL) | ||
| 6CD4 | INC HL | Increment HL | ||
| 6CD5 | INC DE | Increment DE | ||
| 6CD6 | LD A,(DE) | A = (DE) | ||
| 6CD7 | LD (HL),A | Store A at (HL) | ||
| 6CD8 | INC HL | Increment HL | ||
| 6CD9 | DEC DE | Decrement DE | ||
| 6CDA | DJNZ $6CD2 | Loop back until B reaches 0 | ||
| 6CDC | INC DE | Increment DE | ||
| 6CDD | INC DE | Increment DE | ||
| 6CDE | POP HL | Restore HL | ||
| 6CDF | INC H | Increment H | ||
| 6CE0 | DEC C | Decrement C | ||
| 6CE1 | JR NZ,$6CCF | If the routine returned with Z reset, go to 6CCF | ||
| 6CE3 | LD A,$11 | A = 17 | ||
| 6CE5 | LD ($B606),A | Store A in the lines left before pausing | ||
| 6CE8 | LD A,($B5F7) | A = the number of command frames | ||
| 6CEB | INC A | Increment A | ||
| 6CEC | JR NZ,$6D0A | If the routine returned with Z reset, go to Main command loop (6D0A) | ||
| 6CEE | CALL $970B | Call: Choose the random features of a new game (970B) | ||
| 6CF1 | LD HL,$6FE9 | HL = Initial prompt and command (6FE9) | ||
| 6CF4 | LD A,(HL) | A = (HL) | ||
| 6CF5 | CALL $75AD | Call: Print a character in the lower (input) window (75AD) | ||
| 6CF8 | INC HL | Increment HL | ||
| 6CF9 | CP $0D | Compare with 13 | ||
| 6CFB | JR NZ,$6CF4 | If no, go to 6CF4 | ||
| 6CFD | LD HL,$6FEB | Prime the input buffer with "LOOK" | ||
| 6D00 | LD DE,$6FF0 | DE = Input buffer (6FF0) | ||
| 6D03 | LD BC,$0005 | BC = 5 | ||
| 6D06 | LDIR | Copy BC bytes from HL to DE | ||
| 6D08 | JR $6D19 | Continue at 6D19 | ||
| Prev: 6C00 | Up: Map | Next: 6D0A |