Routines
| Prev: C863 | Up: Map | Next: C898 |
C86E: Follow an object's containment chain to its root
|
Resolves an id via D237, then repeatedly follows a 'next id' held at the resolved record's own offset +1 (not a memory address - another id, resolved the same way each time), continuing while bit 5 or bit 3 of the new record's offset +5 is set, and stopping either when +1 is $FF or when bit 7 of +5 is clear. Read as 'find what ultimately contains this thing, walking up through however many levels of nesting' - a room contains a container, which contains an item, which an actor might be carrying.
That makes this routine's bit-5 check read naturally: keep following the chain (i.e. treat what's inside as reachable) only while each container along the way is open.
How it works:
1. Start with the thing's holder (+1). If it is $FF nothing holds it, and the answer is the last holder reached.
2. Otherwise move up to the holder's record, but only climb further when the holder's +5 bit 7 is set and it also has bit 5 or bit 3 set (it lets what is inside be seen).
3. Return the highest holder reached.
|
||||||||||||||
| C86E | PUSH IX | Save IX on the stack - A = the holder number so far ($FF at the start); IX = the thing | ||||||||||||
| C870 | EX AF,AF' | Swap AF with the shadow copy | ||||||||||||
| C871 | LD A,$FF | Load A with $FF | ||||||||||||
| C873 | EX AF,AF' | Swap AF with the shadow copy | ||||||||||||
| C874 | LD A,(IX+$01) | Read byte +1 of the record at IX into A - Held by nothing ($FF): stop with A = the last holder | ||||||||||||
| C877 | CP $FF | Compare A with $FF | ||||||||||||
| C879 | JR Z,$C895 | If A equals $FF, skip ahead to C895 | ||||||||||||
| C87B | EX AF,AF' | Swap AF with the shadow copy | ||||||||||||
| C87C | LD A,(IX+$01) | Read byte +1 of the record at IX into A - Otherwise A' = its holder, and IX = the holder's record (D237) | ||||||||||||
| C87F | CALL $D237 | Call the routine "Resolve an id (in A) to its full entity record" (D237) | ||||||||||||
| C882 | BIT 7,(IX+$05) | Test bit 7 of byte +5 of the record at IX - Keep climbing only if the holder has +5 bit 7 set... | ||||||||||||
| C886 | JR Z,$C894 | If bit 7 of byte +5 of the record at IX is clear, skip ahead to C894 | ||||||||||||
| C888 | BIT 5,(IX+$05) | Test bit 5 of byte +5 of the record at IX - ...and bit 5 or bit 3 (it lets what is inside be seen) | ||||||||||||
| C88C | JR NZ,$C873 | If bit 5 of byte +5 of the record at IX is set, go back to C873 | ||||||||||||
| C88E | BIT 3,(IX+$05) | Test bit 3 of byte +5 of the record at IX | ||||||||||||
| C892 | JR NZ,$C873 | If bit 3 of byte +5 of the record at IX is set, go back to C873 | ||||||||||||
| C894 | EX AF,AF' | Swap AF with the shadow copy - Return the highest holder reached | ||||||||||||
| C895 | POP IX | Restore IX from the stack | ||||||||||||
| C897 | RET | Return to the caller | ||||||||||||
| Prev: C863 | Up: Map | Next: C898 |