Sherlock: annotated disassembly

Routines

Prev: E497 Up: Map Next: E506
E4C9: Action record: put a train in a room (internal verb 140, RUN at $F2A7)
Addresses named in the title: F2A7, verb 140: F2A5.
The direct object is a room number. The train (the actor) is moved there (DD0E) and the room record at DCFF gets bit 6 cleared. If the room is 2, 3 or 4 (the stretch between stations) 'THE TRAIN PULLS OUT OF THE STATION.' is printed first. In the sampled runs (the first three of each kind) each of the train things 37 to 41 went from room 2 to a room of its own (30, 26, 21, 27 and 31) with its +5 bit 7 set; the timetable's later moves (F278, F28D) were not sampled.
How it works:
1. The direct object is a room number. If it is Lestrade, Watson or Straker (things 2, 3, 4), print 'THE TRAIN PULLS OUT OF THE STATION.' and use the routine that clears the revealed flag (9C60); otherwise the one that sets it (9C56).
2. Run that routine on the train, move the train to the room (DD0E) and clear the visited bit of the room's record.
Input
$A034 The room number
Output
F NZ; the train moved there and the room's visited bit cleared
E4C9 DEFB $04,$00 Action record header: flags $04; byte 1 $00
E4CB LD HL,$9C56 HL = 9C56
E4CE LD A,($A034) Read $A034 in "Game variables" into A - The direct object ($A034)
E4D1 PUSH AF Save AF on the stack
E4D2 CP $02 Compare A with $02 - Thing 2, 3 or 4 (Lestrade, Watson, Straker)? Otherwise E4E7
E4D4 JR Z,$E4DE If A equals $02, skip ahead to E4DE
E4D6 CP $03 Compare A with $03
E4D8 JR Z,$E4DE If A equals $03, skip ahead to E4DE
E4DA CP $04 Compare A with $04
E4DC JR NZ,$E4E7 If A differs from $04, skip ahead to E4E7
E4DE LD HL,$7611 "THE TRAIN PULLS OUT OF THE STATION."
E4E1 CALL $A59F Print the message in HL (A59F)
E4E4 LD HL,$9C60 HL = 9C60, a routine to run
E4E7 LD A,($A036) Read $A036 in "Game variables" into A - Keep the current actor
E4EA PUSH AF Save AF on the stack
E4EB CALL $E4FB Call (HL) (E4FB)
E4EE POP AF Restore AF from the stack - Restore the actor
E4EF POP BC Restore BC from the stack
E4F0 CALL $DD0E Reset the actor's state (DD0E)
E4F3 LD HL,($DCFF) Read DCFF in "Pre-check for moving in a direction (verbs..." into HL - Clear bit 6 of the record at (DCFF)
E4F6 RES 6,(HL) Clear bit 6 of the byte HL points at
E4F8 OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller - Return NZ
E4FA RET Return to the caller
E4FB JP (HL) Jump to the address in HL
E4FC LD A,($A034) Read $A034 in "Game variables" into A - (Next record) the direct object ($A034): is anything held by it (E619)?
E4FF CALL $E619 Call E619 (inside "Action record: RUN at E08F; RUN at E46B;...")
E502 JP Z,$DC15 If the zero flag is set, go back to the routine "Fail: A = 0, HL = 0, Z set" (DC15) - None: fail
E505 RET Return to the caller
Prev: E497 Up: Map Next: E506