Prev: 38025 Up: Map Next: 38109
38070: Place Key Pieces
Used by the routine at StartGame.
Chooses which of the eight sets of rooms in KeyPieceRooms will hold the three entities for the A.C.G. key at Initialisation_Key_ACG, using FRAMES and CounterLow, and writes the three rooms to them.
PlaceKeyPieces 38070 LD A,(23672) Fetch FRAMES and keep FRAMES in C.
38073 LD C,A
38074 LD A,(24082) Fetch the counter from CounterLow.
38077 ADD A,C Add FRAMES to the counter.
38078 AND %00000111 Keep only bits 0-2.
38080 LD C,A Keep the number of the set in C.
38081 ADD A,A Multiply the number of the set by 3.
38082 ADD A,C
38083 LD L,A Keep the offset of the set in L.
38084 LD H,0 Clear the high byte of the offset.
38086 LD BC,38109 Point BC at the key piece rooms at KeyPieceRooms.
38089 ADD HL,BC Add the offset to the table, to find the chosen set.
38090 EX DE,HL Keep the set of rooms in DE.
38091 LD HL,24614 Point HL at the room of the first entity at Initialisation_Key_ACG_Room.
38094 LD BC,8 BC=0008 (the distance between the entities).
38097 LD A,3 A=3 (the number of key pieces to place).
PlaceKeyPieces_Loop 38099 EX AF,AF' Save the key piece counter in AF'.
38100 LD A,(DE) Fetch the next room.
38101 LD (HL),A Write it to the entity.
38102 ADD HL,BC Move HL on to the next entity.
38103 INC DE Move DE on to the next room.
38104 EX AF,AF' Restore the key piece counter from AF'.
38105 DEC A Decrease the key piece counter by one and loop back to PlaceKeyPieces_Loop until all three have been placed.
38106 JR NZ,PlaceKeyPieces_Loop
38108 RET Return.
Prev: 38025 Up: Map Next: 38109