Prev: 67AB Up: Map Next: 6DCC
6C00: The game's entry point
Reached by the BASIC loader's PRINT USR, and never left: it runs on into MAIN_LOOP at MAIN_LOOP, which is the game. It first copies the whole of the game's changeable state aside -- the objects to WORLD_COPY, the rooms straight after them, the variables at SAVED_STATE and the TIMERS block to $5F00 -- and every new game at NEW_GAME copies it back, which is how dying and starting again restores the world as it was loaded.
START 6C00 DI
6C01 LD DE,WORLD_COPY The objects and the rooms, to WORLD_COPY onwards
6C04 LD HL,PLAYER
6C07 LD BC,$0615
6C0A LDIR
6C0C LD HL,ROOM0
6C0F LD BC,$05D9
6C12 LDIR
6C14 LD DE,$5F00 The variables and the timers, to $5F00 onwards
6C17 LD HL,SAVED_STATE
6C1A LD BC,$001D
6C1D LDIR
6C1F LD HL,TIMERS
6C22 LD BC,$00BF
6C25 LDIR
This entry point is used by the routines at DO_QUIT, LOAD_BLOCK and PLAYER_DIES.
NEW_GAME 6C27 DI A new game starts here
6C28 LD SP,$5EFF
6C2B LD IX,PICTURE_TABLE The trolls' clearing's picture back to night: its border and starting attribute, the first two bytes of its stream, to black (TROLLS_TURN_TO_STONE sets the day's)
6C2F LD A,$05
6C31 CALL FIND_RECORD
6C34 LD L,(IX+$01)
6C37 LD H,(IX+$02)
6C3A LD (HL),$00
6C3C INC HL
6C3D LD (HL),$00
6C3F LD HL,WORLD_COPY Copy the saved state back
6C42 LD DE,PLAYER
6C45 LD BC,$0615
6C48 LDIR
6C4A LD DE,ROOM0
6C4D LD BC,$05D9
6C50 LDIR
6C52 LD HL,$5F00
6C55 LD DE,SAVED_STATE
6C58 LD BC,$001D
6C5B LDIR
6C5D LD DE,TIMERS
6C60 LD BC,$00BF
6C63 LDIR
6C65 XOR A Black border for now; but BORDCR is given $38 -- a white border, black ink on white paper -- which is the colour the ROM puts back after each tape block (measured: SA/LD-RET writes 7 after every SAVE block)
6C66 OUT ($FE),A
6C68 LD A,$38
6C6A LD ($5C48),A
TITLE_WAIT 6C6D XOR A The title screen: wait for a key
6C6E IN A,($FE)
6C70 AND $1F
6C72 CP $1F
6C74 JR Z,TITLE_WAIT
6C76 LD A,$7F N held down: no pictures (PICTURES_ON)
6C78 IN A,($FE)
6C7A AND $08
6C7C LD (PICTURES_ON),A
6C7F LD HL,$50E0 Both windows' cursors to the start
6C82 LD (INPUT_CURSOR),HL
6C85 LD A,$2B
6C87 LD (CURSOR_CHAR),A
6C8A LD HL,$5020
6C8D LD (STORY_CURSOR),HL
6C90 LD A,$01
6C92 LD (STORY_PIXEL),A
6C95 LD A,$20
6C97 LD (INPUT_COLUMNS),A
6C9A LD A,$2A
6C9C LD (STORY_COLUMNS),A
6C9F LD B,$C8 No orders waiting
6CA1 LD HL,ORDERS
6CA4 CALL CLEAR_BYTES
6CA7 LD A,R Seed RANDOM from R
6CA9 LD (RANDOM_LAST),A
6CAC XOR A The rest of the variables: sober, no printer, printing on, a capital first, no score
6CAD LD (INDENT),A
6CB0 LD (MID_LINE),A
6CB3 LD (QUESTION_WAITING),A
6CB6 LD (DRUNK),A
6CB9 LD (TO_PRINTER),A
6CBC LD A,$01
6CBE LD (PRINTING_ON),A
6CC1 LD (DOING_IT),A
6CC4 LD (CAPITAL_NEXT),A
6CC7 LD HL,$0000
6CCA LD (SCORE),HL
6CCD CALL CLEAR_SCREEN Clear the screen and draw the divider
6CD0 LD HL,$5140
6CD3 LD DE,DIVIDER
6CD6 LD C,$05
START_0 6CD8 LD B,$10
6CDA PUSH HL
START_1 6CDB LD A,(DE)
6CDC LD (HL),A
6CDD INC HL
6CDE INC DE
6CDF LD A,(DE)
6CE0 LD (HL),A
6CE1 INC HL
6CE2 DEC DE
6CE3 DJNZ START_1
6CE5 INC DE
6CE6 INC DE
6CE7 POP HL
6CE8 INC H
6CE9 DEC C
6CEA JR NZ,START_0
6CEC LD A,$11 The first 17 lines of story without a pause
6CEE LD (NO_PAUSE_LINES),A
6CF1 LD A,(COMMAND_FRAMES) Unless COMMAND_FRAMES is $FF, straight to the main loop -- never: it is $FF on the tape and was copied back from there just above
6CF4 INC A
6CF5 JR NZ,MAIN_LOOP
6CF7 CALL NEW_GAME_CHOICES Shut a road and choose a riddle
6CFA LD HL,FIRST_COMMAND The first turn: "> LOOK" printed and put in the line
START_2 6CFD LD A,(HL)
6CFE CALL INPUT_CHAR_A
6D01 INC HL
6D02 CP $0D
6D04 JR NZ,START_2
6D06 LD HL,LOOK_COMMAND
6D09 LD DE,INPUT_LINE
6D0C LD BC,$0005
6D0F LDIR
6D11 JR START_3
MAIN_LOOP 6D13 LD A,$01 The main loop: a new line; nine lines of story before a pause
6D15 LD (MORE_COMMANDS),A
6D18 LD A,$09
6D1A LD (NO_PAUSE_LINES),A
6D1D CALL READ_LINE Read it; @ reruns the last
6D20 JR Z,START_7
START_3 6D22 LD HL,TOKENS Tokenise it into TOKENS
6D25 LD B,$40
6D27 CALL CLEAR_BYTES
6D2A LD HL,INPUT_LINE
6D2D LD IY,TOKENS
START_4 6D31 CALL TOKENISE The next word; unknown: say so
6D34 CP $D0
6D36 JR Z,UNKNOWN_WORD
6D38 CP $90 An opening quote: an order to someone
6D3A JR NZ,START_6
6D3C LD A,B
6D3D AND $0F
6D3F OR C
6D40 JR NZ,START_6
6D42 LD A,(IS_ORDER)
6D45 AND A
6D46 JR NZ,START_5
6D48 INC A
6D49 LD (IS_ORDER),A
6D4C JR START_6
START_5 6D4E DEC A A closing quote: end the order, as if with THEN
6D4F LD (IS_ORDER),A
6D52 LD A,(IY-$02)
6D55 AND $F0
6D57 CP $B0
6D59 JR Z,START_6
6D5B CP $A0
6D5D JR Z,START_6
6D5F LD A,$B0
6D61 LD (IY+$00),A
6D64 XOR A
6D65 LD (IY+$01),A
6D68 INC IY
6D6A INC IY
START_6 6D6C LD (IY+$00),B Keep the token, to the end of the line
6D6F LD (IY+$01),C
6D72 INC IY
6D74 INC IY
6D76 LD A,D
6D77 CP $C0
6D79 JR NZ,START_4
6D7B LD A,(IS_ORDER) A quote left open: "what ?"
6D7E AND A
6D7F JR Z,START_7
6D81 XOR A
6D82 LD (IS_ORDER),A
6D85 CALL QUOTE_LEFT_OPEN
6D88 JR MAIN_LOOP
START_7 6D8A LD HL,TOKENS Parse from the start of TOKENS
6D8D LD (TOKEN_POINTER),HL
START_8 6D90 CALL PARSE_COMMAND The next command in it
6D93 JP NZ,MAIN_LOOP
6D96 CALL OBEY Obey it, and on while there are more
6D99 LD A,(MORE_COMMANDS)
6D9C AND A
6D9D JR NZ,START_8
6D9F JP MAIN_LOOP
UNKNOWN_WORD 6DA2 LD HL,MSG_I_DO_NOT_KNOW "i do not know the word "...
6DA5 LD A,$01
6DA7 LD (INPUT_STYLE),A
6DAA CALL RUN_MESSAGE_HL
6DAD LD HL,(VARIABLES) ...and the word itself, in quotes
START_9 6DB0 LD A,(HL)
6DB1 CP $0D
6DB3 JR Z,START_10
6DB5 CP $22
6DB7 JR Z,START_10
6DB9 CALL PRINT_CHAR
6DBC INC HL
6DBD CP $20
6DBF JR NZ,START_9
START_10 6DC1 LD A,$22
6DC3 CALL PRINT_CHAR
6DC6 CALL NEW_LINE
6DC9 JP MAIN_LOOP
Prev: 67AB Up: Map Next: 6DCC