Sherlock: annotated disassembly

Routines

Prev: E022 Up: Map Next: E08D
E03A: Set the worn state of the actor (A = 1 wear, 0 take off)
Called by the shared WEAR (with A = 1) and TAKE OFF (with A = 0) actions. Finds the actor's compact record via CC0E, writes A into its byte 0, then re-resolves the actor and refreshes the cached record pointer at $A017.
Input
A 1 to wear, 0 to take off
Output
$A017 The actor's new record
IX That record
E03A LD C,A C = 1 to wear, 0 to take off
E03B LD A,($A036) The actor's id
E03E CALL $CC0E Find their compact record
E041 LD (IY+$00),C Record whether they are wearing it
E044 LD IY,($A017) Read $A017 in "Game variables" into IY
E048 LD A,C Copy C into A
E049 CALL $D237 Re-resolve the actor...
E04C LD ($A017),IX ...and refresh the cached pointer
E050 LD A,(IY+$01) Read byte +1 of the record at IY into A - The new body takes over the old one's holder (+1) and room (+15)
E053 LD (IX+$01),A Store A in byte +1 of the record at IX
E056 LD (IY+$01),$FF Set byte +1 of the record at IY to $FF - The old body is held by nothing ($FF) and in no room
E05A LD A,(IY+$0F) Read byte +15 of the record at IY into A
E05D LD (IX+$0F),A Store A in byte +15 of the record at IX
E060 LD (IY+$0F),$00 Set byte +15 of the record at IY to $00
E064 LD B,$00 Load B with $00 - For everything from 1 to $6D: if the old actor holds it...
E066 INC B Add one to B
E067 LD A,B Copy B into A
E068 CP $6E Compare A with $6E
E06A JR Z,$E07C If A equals $6E, skip ahead to E07C
E06C CALL $D237 Call the routine "Resolve an id (in A) to its full entity record" (D237)
E06F LD A,($A036) Read $A036 in "Game variables" into A
E072 CP (IX+$01) Compare A with byte +1 of the record at IX
E075 JR NZ,$E066 If A differs from byte +1 of the record at IX, go back to E066
E077 LD (IX+$01),C Store C in byte +1 of the record at IX - ...the new body holds it
E07A JR $E066 Go back to E066
E07C CALL $CFB6 Call CFB6 (inside "Save a sub-script call frame") - Walk (CFB6) the records it yields and set their +0 to C, until it returns Z
E07F JR Z,$E086 If the zero flag is set, skip ahead to E086
E081 LD (IX+$00),C Store C in the first byte of the record at IX
E084 JR $E07C Go back to E07C
E086 LD A,C Copy C into A - The current actor ($A036) is now the new body
E087 LD ($A036),A Store A in $A036 in "Game variables"
E08A OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller
E08C RET Return to the caller
Prev: E022 Up: Map Next: E08D