Prev: 900A Up: Map Next: 90CC
902B: Test one axis of the player's step against the room's doorways and tables
Used by the routine at TEST_STEP_BOXES.
Called twice a frame from MOVE_PLAYER, through TEST_STEP_BOXES, with the proposed position in E and D and the bit for one axis in A' ($10 for x, $20 for y -- the bits of the player's +$02 that stop APPLY_HEADING moving that way). It walks the player's room's list of door and furniture halves, the same list MAIN_LOOP dispatches, and tests the point against each one's box.
The box is in +$06 (x) and +$07 (y) of the half: the high nibble, signed, times 4 is an offset from the record's own x or y, the low nibble times 4 a size; it runs right from x plus the offset and up from y plus the offset. Inside a box with +$05 bit 3 set -- a shut door -- nothing happens. Inside one with bit 2 set -- a table, the only solid furniture -- the bit is set: the step is refused. Inside any other -- a doorway -- the bit is cleared: the step is allowed although it leaves the room's walk rectangle. So an open door is a channel through the wall, a shut one is wall, and a table is an obstacle.
The lists hold template addresses (INITIAL_STATE onwards) plus ROOM_CONTENTS; taking ROOM_CONTENTS off gives the runtime address, as DISPATCH_FROM_LIST does. An earlier title, "Set up the records that belong to a room", described the walk but not the purpose: nothing is set up.
The check part-way down is the door pairing: if the half named in the list belongs to the other room, eight is added to reach the half in this one.
Input
IX The player
DE The proposed position: E x, D y
A' The axis bit: $10 or $20
TEST_ROOM_BOXES 902B LD C,(IX+$01) The player's room.
902E LD B,$00
9030 LD HL,ROOM_CONTENTS Two bytes per room, into the table.
9033 SLA C
9035 RL B
9037 ADD HL,BC
9038 LD C,(HL) The start of this room's list.
9039 INC HL
903A LD B,(HL)
TEST_ROOM_BOXES_0 903B LD A,(BC) The next entry, and $0000 ends the list.
903C INC BC
903D LD L,A
903E LD A,(BC)
903F INC BC
9040 LD H,A
9041 OR L
9042 RET Z
9043 PUSH BC
9044 LD BC,ROOM_CONTENTS Take the bias off to get the record's real address.
9047 AND A
9048 SBC HL,BC
904A INC HL
904B LD A,(HL) Is this the half that belongs to the player's room?
904C CP (IX+$01)
904F JR Z,TEST_ROOM_BOXES_1 No -- the other half is eight bytes along.
9051 LD BC,$0008
9054 ADD HL,BC
TEST_ROOM_BOXES_1 9055 INC HL
9056 INC HL
9057 LD C,(HL)
9058 INC HL
9059 LD B,(HL)
905A INC HL
905B LD A,(HL)
905C INC HL
905D BIT 2,A
905F JR NZ,TEST_ROOM_BOXES_4
9061 BIT 3,A
9063 JR NZ,TEST_ROOM_BOXES_3
9065 LD A,(HL)
9066 SRA A
9068 SRA A
906A AND $FC
906C ADD A,C
906D SUB E
906E NEG
9070 LD C,A
9071 LD A,(HL)
9072 RLCA
9073 RLCA
9074 AND $3C
9076 INC HL
9077 CP C
9078 JR C,TEST_ROOM_BOXES_3
907A LD A,(HL)
907B SRA A
907D SRA A
907F AND $FC
9081 ADD A,B
9082 SUB D
9083 LD B,A
9084 LD A,(HL)
9085 INC HL
9086 RLCA
9087 RLCA
9088 AND $3C
908A CP B
908B JR C,TEST_ROOM_BOXES_3
908D EX AF,AF'
908E LD C,A
908F EX AF,AF'
9090 LD A,C
9091 CPL
9092 AND (IX+$02)
TEST_ROOM_BOXES_2 9095 LD (IX+$02),A
TEST_ROOM_BOXES_3 9098 POP BC
9099 JR TEST_ROOM_BOXES_0
TEST_ROOM_BOXES_4 909B LD A,(HL)
909C SRA A
909E SRA A
90A0 AND $FC
90A2 ADD A,C
90A3 SUB E
90A4 NEG
90A6 LD C,A
90A7 LD A,(HL)
90A8 RLCA
90A9 RLCA
90AA AND $3C
90AC INC HL
90AD CP C
90AE JR C,TEST_ROOM_BOXES_3
90B0 LD A,(HL)
90B1 SRA A
90B3 SRA A
90B5 AND $FC
90B7 ADD A,B
90B8 SUB D
90B9 LD B,A
90BA LD A,(HL)
90BB INC HL
90BC RLCA
90BD RLCA
90BE AND $3C
90C0 CP B
90C1 JR C,TEST_ROOM_BOXES_3
90C3 EX AF,AF'
90C4 LD C,A
90C5 EX AF,AF'
90C6 LD A,C
90C7 OR (IX+$02)
90CA JR TEST_ROOM_BOXES_2
Prev: 900A Up: Map Next: 90CC