Prev: CDC0 Up: Map Next: CEE1
CE4B: Update Ghosts
Used by the routine at Update_Task_Four_Entities.
Update the ghost entities: clear their interaction latch, walk their scripts and queue a moan if one is active.
Update_Ghosts CE4B LD HL,$72B9 Point HL at the entity interaction flag (EntityInteractionFlag).
CE4E BIT 3,(HL) Is bit 03 of EntityInteractionFlag set? If not, return.
CE50 RET Z
CE51 RES 3,(HL) Clear bit 03 of EntityInteractionFlag.
CE53 LD IX,$8F75 Point IX at the plant-pot complex entity (StateData_Complex_10).
CE57 LD B,$03 Load B with 03 as a loop counter.
Scan each ghost slot: idle ones skip; active ones tick their delay or advance a moan frame.
Update_Ghosts_Scan CE59 LD A,(IX+$09) Load A with the current entity's direction / state.
CE5C OR A Is the current entity's direction / state zero? If so, jump to Update_Ghosts_AdvanceSlot.
CE5D JR Z,Update_Ghosts_AdvanceSlot
CE5F CP $0B Is the current entity's direction / state less than 0B? If not, jump to Update_Ghosts_AdvanceSlot.
CE61 JR NC,Update_Ghosts_AdvanceSlot
CE63 LD A,(IX+$0C) Load A with the current entity's extra state.
CE66 OR A Is the current entity's extra state zero? If so, jump to Update_Ghosts_AdvanceFrame.
CE67 JR Z,Update_Ghosts_AdvanceFrame
CE69 DEC (IX+$0C) Decrease the current entity's extra state.
CE6C JR Update_Ghosts_RetriggerBit3 Jump to Update_Ghosts_RetriggerBit3 to mark this ghost slot done.
Advance the ghost frame; at the end spawn a plant shoot via Update_Plant_Pots and raise game-event bit 00.
Update_Ghosts_AdvanceFrame CE6E LD A,(IX+$09) Load A with the current entity's direction / state.
CE71 CP $0A Is the current entity's direction / state less than 0A? If so, jump to Update_Ghosts_WriteLayoutFromTable.
CE73 JR C,Update_Ghosts_WriteLayoutFromTable
CE75 LD C,$0C Load C with 0C (vertical offset passed to Update_Plant_Pots).
CE77 CALL Update_Plant_Pots Call Update_Plant_Pots to update Plant Pots.
CE7A SET 7,(IY+$01) Set bit 07 of the referenced entity's flags byte 1.
CE7E INC (IY+$04) Increment the referenced entity's room index.
CE81 LD A,($72B3) Load A with the game event flags (GameEventFlags).
CE84 SET 0,A Set bit 00 of game event flags.
CE86 LD ($72B3),A Set the game event flags (GameEventFlags).
CE89 LD A,$0A Load A with 0A.
Install the next ghost layout from table CEC9; frame 07 uses a fixed moan delay.
Update_Ghosts_WriteLayoutFromTable CE8B INC A Advance the ghost frame index in A by one.
CE8C LD (IX+$09),A Set the current entity's direction / state.
CE8F ADD A,A Double 0A (word index).
CE90 LD E,A Keep 0A in E for later.
CE91 LD D,$00 Clear D (high byte of a pointer/offset).
CE93 PUSH HL Stash HL on the stack.
CE94 LD HL,$CEC9 Point HL at ghost script/table data (CEC9).
CE97 ADD HL,DE Add the offset in DE to the pointer in HL.
CE98 LD A,(HL) Fetch the next byte from CEC9.
CE99 LD (IX+$0A),A Set the current entity's graphic layout address (low).
CE9C INC HL Advance CEC9 by one byte.
CE9D LD A,(HL) Fetch the next byte from CEC9.
CE9E LD (IX+$0B),A Set the current entity's graphic layout address (high).
CEA1 POP HL Restore HL from the stack.
CEA2 LD A,(IX+$09) Load A with the current entity's direction / state.
CEA5 CP $07 Is the current entity's direction / state equal to 07? If not, jump to Update_Ghosts_RandomExtraState.
CEA7 JR NZ,Update_Ghosts_RandomExtraState
CEA9 LD A,$05 Load A with 05.
CEAB JR Update_Ghosts_StoreExtraAndMoan Jump to Update_Ghosts_StoreExtraAndMoan to store the ghost's extra state.
Pick a random extra-state delay from the current frame index.
Update_Ghosts_RandomExtraState CEAD ADD A,A Double the frame index in A.
CEAE ADD A,A Multiply A by 04 to form a table index.
CEAF ADD A,A
CEB0 LD C,A Keep 05 in C for later.
CEB1 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value and add the saved count in C.
CEB4 ADD A,C
Arm the ghost's moan delay and queue sound 0F via Queue_Sound.
Update_Ghosts_StoreExtraAndMoan CEB5 LD (IX+$0C),A Set the current entity's extra state.
CEB8 LD A,$0F Load A with 0F.
CEBA CALL Queue_Sound Call Queue_Sound to queue a sound effect.
Retrigger interaction bit 03 of EntityInteractionFlag so Update_Ghosts will scan again.
Update_Ghosts_RetriggerBit3 CEBD SET 3,(HL) Set bit 03 of EntityInteractionFlag.
Advance to the next ghost slot and loop until all 03 are done.
Update_Ghosts_AdvanceSlot CEBF LD DE,$000E Each entity record is 000E bytes long, then load that length into DE.
CEC2 ADD IX,DE Advance IX to the next entity record.
CEC4 DEC B Step the loop counter in B back by one.
CEC5 JP NZ,Update_Ghosts_Scan If the result was non-zero, jump to Update_Ghosts_Scan.
CEC8 RET Return.
CEC9 ADD A,D Add D into A while building a 16-bit entity/screen address.
CECA AND B Mask 0F with B.
CECB ADD A,D Add D into A while building a 16-bit entity/screen address.
CECC AND B Mask A with B.
CECD AND B
CECE AND B
CECF XOR C Toggle bits of the flag byte in A using C.
CED0 AND B Mask 0F with B.
CED1 XOR A Clear A.
CED2 AND B Mask 0F with B.
CED3 OR L Merge another flag byte into 0F.
CED4 AND B Mask 0F with B.
CED5 CP E Compare 0F with E.
CED6 AND B Mask 0F with B.
CED7 ADC A,$A0 Add A0 into A (with carry) for an attribute address.
CED9 JP C,$E3A0 If a hit/borrow was signaled, jump to E3A0.
CEDC AND B Mask 0F with B.
CEDD JP P,$F8A0 Jump to Font_MainMenuLogo_0 if the sign flag is reset.
CEE0 AND B Mask 0F with B.
Prev: CDC0 Up: Map Next: CEE1