Prev: C91A Up: Map Next: CA7C
C92C: Build a room's object records from the room directory
Used by the routine at ENTER_ROOM.
Clears every object record but the player's two, finds the player's room in ROOMS, and sets the room's colour (ROOM_ATTR) and its half-sizes and floor (ROOM_EXTENT, from ROOM_SIZES). Then fills the records from the top, ROOM_FIRST, downwards: first the scenery, then the objects. Nothing checks that the 48 records are enough.
Scenery: each entry is a template number and one more byte, up to an $FF. A scenery template (SCENERY_TABLE) is a list of 8-byte pieces -- graphic, U, V, Z, the three half-sizes, flags -- ended by a zero, each piece its own record. Every piece of the entry takes the entry's second byte as its +$08: for a doorway that is the room it leads to (FIRST_PILLAR).
Objects: groups, each a header byte (bits 0-2 how many less one, bits 3-7 the template) and a position byte for each. An object template (OBJECT_TABLE) is a list of 5-byte pieces -- graphic, the three half-sizes, flags -- ended by a zero, each piece its own record, all at the same place. A position byte gives U = 72 + 16 times bits 0-2, V = 72 + 16 times bits 3-5, and Z = the floor + 12 times bits 6-7; the object's +$08 is this room.
Template 31 in a header is not a template: it moves TEMPLATES_AT on 64 bytes, to a second page of templates, and the byte after it is skipped. No room uses it (it never ran). PLACE_NUDGE would add 8 to U (bit 0), 8 to V (bit 1) and the rest to Z; it is cleared here and nothing sets it but the unreached code at SET_PLACE_NUDGE.
The count at +1 of the room's record, of the bytes from there to the end, is what stops the build, not the end of the data: the scenery can use it up, or a group be cut short.
Input
IX The player's legs, whose +$08 is the room
BUILD_ROOM C92C CALL CLEAR_OBJECTS Clear the other object records
C92F LD HL,OBJECT_TABLE The first page of object templates, and no nudge
C932 LD (TEMPLATES_AT),HL
C935 XOR A
C936 LD (PLACE_NUDGE),A
C939 LD DE,ROOM_FIRST The first record to fill, the scenery table, the directory
C93C LD BC,SCENERY_TABLE
C93F LD HL,ROOMS
BUILD_ROOM_0 C942 LD A,(HL) This room?
C943 INC HL
C944 CP (IX+$08)
C947 JR Z,BUILD_ROOM_1
C949 LD A,(HL) No: on by the count
C94A CALL ADD_HL_A
C94D AND A A comparison with the scenery table, whose result nothing uses: the room is assumed to be there
C94E SBC HL,BC
C950 ADD HL,BC
C951 JR BUILD_ROOM_0 Next room
BUILD_ROOM_1 C953 LD B,(HL) B = the count
C954 INC HL The room's ink, BRIGHT, on black
C955 LD A,(HL)
C956 AND $07
C958 OR $40
C95A LD (ROOM_ATTR),A
C95D PUSH DE The room's size, bits 3-7 of the same byte
C95E EX DE,HL
C95F LD A,(DE)
C960 INC DE
C961 RRCA
C962 RRCA
C963 RRCA
C964 AND $1F
C966 LD C,A
C967 ADD A,A Three bytes of ROOM_SIZES: the half-sizes in U and V, and the floor
C968 ADD A,C
C969 LD HL,ROOM_SIZES
C96C CALL ADD_HL_A
C96F LD A,(HL)
C970 INC HL
C971 LD (ROOM_EXTENT),A
C974 LD A,(HL)
C975 INC HL
C976 LD ($A71E),A
C979 LD A,(HL)
C97A LD ($A71F),A
C97D DEC B Two of the count used; HL on the scenery, DE the record
C97E DEC B
C97F EX DE,HL
C980 POP DE
BUILD_ROOM_2 C981 LD A,(HL) The scenery ends at an $FF
C982 INC HL
C983 CP $FF
C985 JR Z,BUILD_ROOM_4
C987 PUSH BC HL = the scenery template, the entry kept on the stack
C988 PUSH HL
C989 LD L,A
C98A LD H,$00
C98C ADD HL,HL
C98D LD BC,SCENERY_TABLE
C990 ADD HL,BC
C991 LD A,(HL)
C992 INC HL
C993 LD H,(HL)
C994 LD L,A
BUILD_ROOM_3 C995 LD BC,$0008 A piece: graphic, U, V, Z, half-sizes, flags
C998 LDIR
C99A EX (SP),HL +$08: the entry's second byte
C99B LD A,(HL)
C99C EX (SP),HL
C99D LD (DE),A
C99E INC DE
C99F LD B,$17 +$09 to +$1F cleared
C9A1 CALL CLEAR_BYTES
C9A4 PUSH HL The record below
C9A5 LD HL,$FFC0
C9A8 ADD HL,DE
C9A9 EX DE,HL
C9AA POP HL
NEXT_PIECE C9AB LD A,(HL) Another piece?
C9AC AND A
C9AD JR NZ,BUILD_ROOM_3
C9AF POP HL Past the entry's second byte; two of the count, and on to the next entry
C9B0 POP BC
C9B1 INC HL
C9B2 DEC B
C9B3 DJNZ BUILD_ROOM_2
C9B5 RET The count ran out
BUILD_ROOM_4 C9B6 DEC B The $FF counted
C9B7 PUSH IY IY = the next record
C9B9 PUSH DE
C9BA POP IY
NEXT_GROUP C9BC LD A,(HL) C = how many in this group
C9BD AND $07
C9BF INC A
C9C0 LD C,A
C9C1 LD A,(HL) The header counted; D = the first position
C9C2 INC HL
C9C3 DEC B
C9C4 LD D,(HL)
C9C5 INC HL
C9C6 PUSH HL
C9C7 RRCA The template number, doubled; 31 moves to the second page
C9C8 RRCA
C9C9 AND $3E
C9CB CP $3E
C9CD JP Z,TEMPLATE_PAGE
C9D0 LD HL,(TEMPLATES_AT) HL = the object template
C9D3 CALL ADD_HL_A
C9D6 LD A,(HL)
C9D7 INC HL
C9D8 LD H,(HL)
C9D9 LD L,A
BUILD_ROOM_5 C9DA PUSH HL Kept for the next object of the group
BUILD_ROOM_6 C9DB LD A,(HL) A piece: graphic, half-sizes, flags
C9DC INC HL
C9DD LD (IY+$00),A
C9E0 LD A,(HL)
C9E1 INC HL
C9E2 LD (IY+$04),A
C9E5 LD A,(HL)
C9E6 INC HL
C9E7 LD (IY+$05),A
C9EA LD A,(HL)
C9EB INC HL
C9EC LD (IY+$06),A
C9EF LD A,(HL)
C9F0 INC HL
C9F1 LD (IY+$07),A
C9F4 LD A,(IX+$08) This room
C9F7 LD (IY+$08),A
C9FA LD A,(PLACE_NUDGE) U from bits 0-2 of the position
C9FD RLCA
C9FE RLCA
C9FF RLCA
CA00 AND $08
CA02 LD E,A
CA03 LD A,D
CA04 RLCA
CA05 RLCA
CA06 RLCA
CA07 RLCA
CA08 AND $70
CA0A ADD A,E
CA0B ADD A,$48
CA0D LD (IY+$01),A
CA10 LD A,(PLACE_NUDGE) V from bits 3-5
CA13 RLCA
CA14 RLCA
CA15 AND $08
CA17 LD E,A
CA18 LD A,D
CA19 RLCA
CA1A AND $70
CA1C ADD A,E
CA1D ADD A,$48
CA1F LD (IY+$02),A
CA22 LD A,D Z from bits 6-7, 12 a level, on the floor
CA23 RLCA
CA24 RLCA
CA25 AND $03
CA27 ADD A,A
CA28 ADD A,A
CA29 LD E,A
CA2A ADD A,A
CA2B ADD A,E
CA2C LD E,A
CA2D LD A,(PLACE_NUDGE)
CA30 ADD A,E
CA31 AND $FC
CA33 LD E,A
CA34 LD A,($A71F)
CA37 ADD A,E
CA38 LD (IY+$03),A
CA3B PUSH BC +$09 to +$1F cleared
CA3C LD BC,$0009
CA3F ADD IY,BC
CA41 LD B,$17
BUILD_ROOM_7 CA43 LD (IY+$00),$00
CA47 INC IY
CA49 DJNZ BUILD_ROOM_7
CA4B LD BC,$FFC0 The record below
CA4E ADD IY,BC
CA50 POP BC
CA51 LD A,(HL) Another piece?
CA52 AND A
CA53 JR NZ,BUILD_ROOM_6
CA55 POP DE The position counted; the end of the count ends the room
CA56 POP HL
CA57 DEC B
CA58 JR Z,BUILD_ROOM_8
CA5A DEC C The end of the group
CA5B JP Z,NEXT_GROUP
CA5E LD A,(HL) The next position, the same template
CA5F INC HL
CA60 PUSH HL
CA61 EX DE,HL
CA62 LD D,A
CA63 JP BUILD_ROOM_5
BUILD_ROOM_8 CA66 PUSH IY DE = the next free record
CA68 POP DE
CA69 POP IY
CA6B RET
TEMPLATE_PAGE CA6C LD HL,(TEMPLATES_AT) Template 31: the next page of templates
CA6F LD A,$40
CA71 CALL ADD_HL_A
CA74 LD (TEMPLATES_AT),HL
CA77 DEC B The byte after it counted and skipped
CA78 POP HL
CA79 JP NEXT_GROUP
Prev: C91A Up: Map Next: CA7C