Prev: 52672 Up: Map Next: 52961
52811: 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 52811 LD HL,29369 Point HL at the entity interaction flag (EntityInteractionFlag).
52814 BIT 3,(HL) Is bit 3 of EntityInteractionFlag set? If not, return.
52816 RET Z
52817 RES 3,(HL) Clear bit 3 of EntityInteractionFlag.
52819 LD IX,36725 Point IX at the plant-pot complex entity (StateData_Complex_10).
52823 LD B,3 Load B with 3 as a loop counter.
Scan each ghost slot: idle ones skip; active ones tick their delay or advance a moan frame.
Update_Ghosts_Scan 52825 LD A,(IX+9) Load A with the current entity's direction / state.
52828 OR A Is the current entity's direction / state zero? If so, jump to Update_Ghosts_AdvanceSlot.
52829 JR Z,Update_Ghosts_AdvanceSlot
52831 CP 11 Is the current entity's direction / state less than 11? If not, jump to Update_Ghosts_AdvanceSlot.
52833 JR NC,Update_Ghosts_AdvanceSlot
52835 LD A,(IX+12) Load A with the current entity's extra state.
52838 OR A Is the current entity's extra state zero? If so, jump to Update_Ghosts_AdvanceFrame.
52839 JR Z,Update_Ghosts_AdvanceFrame
52841 DEC (IX+12) Decrease the current entity's extra state.
52844 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 0.
Update_Ghosts_AdvanceFrame 52846 LD A,(IX+9) Load A with the current entity's direction / state.
52849 CP 10 Is the current entity's direction / state less than 10? If so, jump to Update_Ghosts_WriteLayoutFromTable.
52851 JR C,Update_Ghosts_WriteLayoutFromTable
52853 LD C,12 Load C with 12 (vertical offset passed to Update_Plant_Pots).
52855 CALL Update_Plant_Pots Call Update_Plant_Pots to update Plant Pots.
52858 SET 7,(IY+1) Set bit 7 of the referenced entity's flags byte 1.
52862 INC (IY+4) Increment the referenced entity's room index.
52865 LD A,(29363) Load A with the game event flags (GameEventFlags).
52868 SET 0,A Set bit 0 of game event flags.
52870 LD (29363),A Set the game event flags (GameEventFlags).
52873 LD A,10 Load A with 10.
Install the next ghost layout from table 52937; frame 7 uses a fixed moan delay.
Update_Ghosts_WriteLayoutFromTable 52875 INC A Advance the ghost frame index in A by one.
52876 LD (IX+9),A Set the current entity's direction / state.
52879 ADD A,A Double 10 (word index).
52880 LD E,A Keep 10 in E for later.
52881 LD D,0 Clear D (high byte of a pointer/offset).
52883 PUSH HL Stash HL on the stack.
52884 LD HL,52937 Point HL at ghost script/table data (52937).
52887 ADD HL,DE Add the offset in DE to the pointer in HL.
52888 LD A,(HL) Fetch the next byte from 52937.
52889 LD (IX+10),A Set the current entity's graphic layout address (low).
52892 INC HL Advance 52937 by one byte.
52893 LD A,(HL) Fetch the next byte from 52937.
52894 LD (IX+11),A Set the current entity's graphic layout address (high).
52897 POP HL Restore HL from the stack.
52898 LD A,(IX+9) Load A with the current entity's direction / state.
52901 CP 7 Is the current entity's direction / state equal to 7? If not, jump to Update_Ghosts_RandomExtraState.
52903 JR NZ,Update_Ghosts_RandomExtraState
52905 LD A,5 Load A with 5.
52907 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 52909 ADD A,A Double the frame index in A.
52910 ADD A,A Multiply A by 4 to form a table index.
52911 ADD A,A
52912 LD C,A Keep 5 in C for later.
52913 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value and add the saved count in C.
52916 ADD A,C
Arm the ghost's moan delay and queue sound 15 via Queue_Sound.
Update_Ghosts_StoreExtraAndMoan 52917 LD (IX+12),A Set the current entity's extra state.
52920 LD A,15 Load A with 15.
52922 CALL Queue_Sound Call Queue_Sound to queue a sound effect.
Retrigger interaction bit 3 of EntityInteractionFlag so Update_Ghosts will scan again.
Update_Ghosts_RetriggerBit3 52925 SET 3,(HL) Set bit 3 of EntityInteractionFlag.
Advance to the next ghost slot and loop until all 3 are done.
Update_Ghosts_AdvanceSlot 52927 LD DE,14 Each entity record is 0014 bytes long, then load that length into DE.
52930 ADD IX,DE Advance IX to the next entity record.
52932 DEC B Step the loop counter in B back by one.
52933 JP NZ,Update_Ghosts_Scan If the result was non-zero, jump to Update_Ghosts_Scan.
52936 RET Return.
52937 ADD A,D Add D into A while building a 16-bit entity/screen address.
52938 AND B Mask 15 with B.
52939 ADD A,D Add D into A while building a 16-bit entity/screen address.
52940 AND B Mask A with B.
52941 AND B
52942 AND B
52943 XOR C Toggle bits of the flag byte in A using C.
52944 AND B Mask 15 with B.
52945 XOR A Clear A.
52946 AND B Mask 15 with B.
52947 OR L Merge another flag byte into 15.
52948 AND B Mask 15 with B.
52949 CP E Compare 15 with E.
52950 AND B Mask 15 with B.
52951 ADC A,160 Add 160 into A (with carry) for an attribute address.
52953 JP C,58272 If a hit/borrow was signaled, jump to 58272.
52956 AND B Mask 15 with B.
52957 JP P,63648 Jump to Font_MainMenuLogo_0 if the sign flag is reset.
52960 AND B Mask 15 with B.
Prev: 52672 Up: Map Next: 52961