Prev: 6A27 Up: Map Next: 6AB5
6A35: Set-up room
This first wipes the visible tiles array then sets up interior doors, gets the room definition pointer then uses that to setup boundaries, set up interior masks and finally plot all objects into the visible tile array.
setup_room 6A35 CALL wipe_visible_tiles Wipe the visible tiles array
Form the address of rooms_and_tunnels[room_index - 1] in HL.
6A38 LD A,($68A0) Fetch the global current room index
6A3B ADD A,A Double it so we can index rooms_and_tunnels[]
6A3C LD HL,$6BAB Point HL at rooms_and_tunnels rooms_and_tunnels[-1]
6A3F ADD A,L HL + A
6A40 LD L,A
6A41 JR NC,setup_room_0
6A43 INC H
setup_room_0 6A44 LD A,(HL) Fetch room pointer in HL
6A45 INC HL
6A46 LD H,(HL)
6A47 LD L,A
6A48 PUSH HL Push it
6A49 CALL setup_doors Setup interior doors
6A4C POP HL Pop it
Copy the count of boundaries into state.
6A4D LD DE,$81BE Point DE at roomdef_bounds_index roomdef_bounds_index
6A50 LDI Copy first byte of roomdef into roomdef_bounds_index. (DE, HL incremented).
DE now points to roomdef_object_bounds_count
Copy all boundary structures into state, if any.
6A52 LD A,(HL) Fetch count of boundaries
6A53 AND A Is it zero?
6A54 LD (DE),A Store it irrespectively
6A55 JR NZ,setup_room_1 No, jump to copying step
6A57 INC HL Skip roomdef count of boundaries
6A58 JR setup_room_2 Jump to mask copying
setup_room_1 6A5A ADD A,A Multiply A by four (size of boundary structures) then add one (skip current counter) == size of boundary structures
6A5B ADD A,A
6A5C INC A
6A5D LD C,A Copy all boundary structures
6A5E LD B,$00
6A60 LDIR
Copy interior mask into interior_mask_data.
setup_room_2 6A62 LD DE,$81DA Point DE at interior_mask_data
6A65 LD A,(HL) Get count of interior masks
6A66 INC HL Step
6A67 LD (DE),A Write it out
6A68 AND A Is the count non-zero?
6A69 JR Z,setup_room_4 Jump if not
6A6B INC DE Skip over the written count
6A6C LD B,A B is our loop counter
Start loop
interior_mask_data holds indices into interior_mask_data_source[].
setup_room_3 6A6D PUSH BC
6A6E PUSH HL
6A6F LD L,(HL) Fetch an index (from roomdef?)
6A70 LD H,$00
6A72 LD B,H BC = HL
6A73 LD C,L
6A74 ADD HL,HL Multiply it by eight
6A75 ADD HL,HL
6A76 ADD HL,HL
6A77 AND A Clear the carry flag
6A78 SBC HL,BC Final offset is index * 7
6A7A LD BC,$EA7C Point at interior_mask_data_source
6A7D ADD HL,BC Form the address of the mask data
6A7E LD BC,$0007 Width of mask data
6A81 LDIR Copy it
6A83 LD A,$20 Constant final byte is always 32
6A85 LD (DE),A
6A86 INC DE
6A87 POP HL
6A88 INC HL
6A89 POP BC
6A8A DJNZ setup_room_3 ...loop
Plot all objects (as tiles).
setup_room_4 6A8C LD B,(HL) Count of objects
6A8D LD A,B
6A8E AND A Is it zero?
6A8F RET Z Return if so
6A90 INC HL Skip the count
Start loop: for every object in the roomdef
setup_room_5 6A91 PUSH BC
6A92 LD C,(HL) Fetch the object index
6A93 INC HL
6A94 LD A,(HL) Fetch the column
6A95 INC HL
6A96 PUSH HL
6A97 LD L,(HL)
Plot the object into the visible tiles array
6A98 LD H,$00 DE = $F0F8 + row * 24 + column.
6A9A ADD HL,HL
6A9B ADD HL,HL
6A9C ADD HL,HL
6A9D LD E,L
6A9E LD D,H
6A9F ADD HL,HL
6AA0 ADD HL,DE
6AA1 ADD A,L
6AA2 LD L,A
6AA3 JR NC,setup_room_6
6AA5 INC H
setup_room_6 6AA6 LD DE,$F0F8
6AA9 ADD HL,DE
6AAA EX DE,HL
6AAB LD A,C
6AAC CALL expand_object Expand RLE-encoded object out to a set of tile references
6AAF POP HL
6AB0 POP BC
6AB1 INC HL
6AB2 DJNZ setup_room_5 ...loop
6AB4 RET Return
Prev: 6A27 Up: Map Next: 6AB5