Prev: 953F Up: Map Next: 9589
954D: Is it too dark for Bilbo to see?
Returns with the carry flag set (and HL pointing at the message 'it is dark.') if the player is acting and cannot see. Characters are never affected: they can always see.
Bilbo can see if he is inside something (9DC8) or if his room is lit (bit 7 of the first byte of its record). Otherwise he can only see if the short strong sword (object 14, record at C00B + $1E9 = C1F4) is with him (9D86) and its flags have bit 2 set, bit 3 (broken) clear and bit 4 ('on') set. In other words, the sword is the game's only lamp: it glows, as Sting does in the book. The sword starts with these bits set, so carrying it lights up every dark place.
Output
F Carry set if it is too dark
HL "it is dark."
954D LD A,($B5DB) Is the current actor Bilbo?
9550 AND A
9551 RET NZ No (a character): they can always see - return with no carry
9552 PUSH IX Yes: save IX and BC
9554 PUSH BC
9555 LD IX,$C00B IX = Bilbo's own record
9559 CALL $9DC8 Is he shut inside something closed, or out in the open (or inside something open)?
955C INC A ($FF, "loose", becomes 0 here)
955D JR NZ,$9568 Shut away: check the sword instead, below
955F CALL $9C8C Out in the open: IX = his own room's record
9562 BIT 7,(IX+$00) Is the room lit?
9566 JR NZ,$9582 Yes: he can see (no carry)
9568 PUSH IY No, or shut away: save IY
956A LD IY,$C1F4 IY = the short strong sword's own record
956E CALL $9D86 Is the sword near Bilbo?
9571 POP IY Restore IY
9573 JR Z,$957E It is not: dark, below
9575 LD A,($C1FB) It is near: A = the sword's own flags
9578 XOR $F7 Flip every flag bit except "broken"...
957A AND $1C ...then keep just "full", "broken" and "on": zero here means full=1, broken=0, on=1 - the sword is glowing
957C JR Z,$9586 If so, he can see
957E LD HL,$AD12 "it is dark."
9581 SCF Set the carry flag: it is too dark
9582 POP BC Restore BC and IX
9583 POP IX
9585 RET
9586 AND A Clear the carry flag: he can see after all
9587 JR $9582
Prev: 953F Up: Map Next: 9589