Prev: 955F Up: Map Next: 96D8
9572: Update Crystal Stack
Used by the routine at UpdateMapObjects.
Purpose not yet known. It builds a stack of objects in the slot at CrystalStackSlot, one for each of the crystals counted at F602 and takes different action when the player's ship is in the right place on the map. Called once a frame.
UpdateCrystalStack 9572 XOR A Clear 8D3C.
9573 LD ($8D3C),A
9576 LD A,($96AB) Fetch the flag from 96AB.
9579 AND A Test it.
957A JR NZ,UpdateCrystalStack_Count Jump to UpdateCrystalStack_Count if it is set.
957C LD HL,($CE57) Fetch the map position from MapPosition.
957F LD A,L Fetch the map column.
9580 CP $51 Jump to UpdateCrystalStack_Zone if it is 51.
9582 JR Z,UpdateCrystalStack_Zone
9584 CP $52 Is it 52?
9586 RET NZ Return if not.
UpdateCrystalStack_Zone 9587 LD A,H Fetch the map zone.
9588 CP $09 Jump to UpdateCrystalStack_Count if it is 09.
958A JR Z,UpdateCrystalStack_Count
958C CP $0A Is it 0A?
958E RET NZ Return if not.
UpdateCrystalStack_Count 958F LD A,($F602) Fetch the number of crystals from F602.
9592 AND A Test it.
9593 RET Z Return if there are none.
9594 INC A Add one.
9595 SRL A Halve it.
9597 LD ($8D3C),A Store the result in 8D3C.
959A LD IX,$9A4C Use the slot at CrystalStackSlot.
959E LD (IX+$13),$00 Clear the first state byte of the object.
95A2 LD A,($96AB) Fetch the flag from 96AB.
95A5 AND A Test it.
95A6 JR Z,UpdateCrystalStack_Next Jump to UpdateCrystalStack_Next if it is clear.
95A8 LD A,($9A64) Fetch the frame counter from FrameCounter.
95AB AND %00000011 Keep the bottom two bits.
95AD CALL PlayPatternedNoise Play a sound.
95B0 CALL SetObjectPosition Set the position of the object.
95B3 LD A,($CCBA) Fetch the speed from VerticalSpeed.
95B6 NEG Negate it.
95B8 LD (IX+$09),A Set the vertical speed of the object.
95BB LD A,($CE58) Fetch the map zone from CE58.
95BE AND A Test it.
95BF JR NZ,UpdateCrystalStack_Move Jump to UpdateCrystalStack_Move if it is not zero.
95C1 LD (IX+$09),$FC Otherwise set the vertical speed of the object to FC.
UpdateCrystalStack_Move 95C5 CALL MoveObject Update the position of the object.
95C8 LD L,(IX+$02) Store the horizontal position of the object in 96AC.
95CB LD H,(IX+$01)
95CE LD ($96AC),HL
95D1 LD L,(IX+$05) Store the vertical position of the object in 96AE.
95D4 LD H,(IX+$04)
95D7 LD ($96AE),HL
UpdateCrystalStack_Next 95DA CALL SetObjectPosition Set the position of the object.
95DD LD A,(IX+$13) Fetch the first state byte of the object and keep it in B.
95E0 LD B,A
95E1 ADD A,A Multiply it by five.
95E2 ADD A,A
95E3 ADD A,B
95E4 LD HL,$96B0 Use the table at UpdateCrystalStack_Table.
95E7 CALL AddAToHL Add the offset to the address.
95EA LD DE,$9A5C Use the data at CrystalStackSlot_Flags.
95ED LD BC,$0003 Set the length to three.
95F0 LDIR Copy the three bytes.
95F2 LD A,(HL) Fetch the next byte of the table.
95F3 LD (IX+$07),A Set the horizontal speed of the object.
95F6 INC HL Fetch the next byte of the table.
95F7 LD A,(HL) Set the vertical speed of the object.
95F8 LD (IX+$09),A
95FB CALL MoveObject Update the position of the object.
95FE LD (IX+$07),$00 Clear the horizontal speed.
9602 LD (IX+$09),$00 Clear the vertical speed.
9606 LD A,(IX+$13) Fetch the first state byte of the object.
9609 CP $06 Jump to UpdateCrystalStack_Draw if it is not six.
960B JR NZ,UpdateCrystalStack_Draw
960D LD (IX+$13),$08 Set the first state byte to eight.
UpdateCrystalStack_Draw 9611 CALL ResetSprites Reset the collision state.
9614 BIT 7,(IX+$10) Test bit 7 of the flags of the object.
9618 CALL NZ,PrepareErase Call PrepareErase if it is set.
961B RES 6,(IX+$10) Clear bit 6 of the flags of the object.
961F EXX Switch registers.
9620 CALL ProcessObjectFlags Process the flags of the object.
9623 CALL DrawObject Call DrawObject.
9626 CALL SetObjectAttributes Call SetObjectAttributes.
9629 LD IX,$9A4C Use the slot at CrystalStackSlot.
962D LD A,(IX+$13) Fetch the first state byte of the object.
9630 CP $08 Jump to UpdateCrystalStack_Copy if it is not eight.
9632 JR NZ,UpdateCrystalStack_Copy
9634 LD A,$06 Use six instead.
9636 LD (IX+$13),A Store it.
UpdateCrystalStack_Copy 9639 LD B,A Keep the state in B.
963A ADD A,A Multiply it by five.
963B ADD A,A
963C ADD A,B
963D LD HL,$96B0 Use the table at UpdateCrystalStack_Table.
9640 CALL AddAToHL Add the offset to the address.
9643 LD DE,$9A5C Use the data at CrystalStackSlot_Flags.
9646 EX DE,HL Swap the pointers.
9647 LD BC,$0003 Set the length to three.
964A LDIR Copy the three bytes back.
964C INC (IX+$13) Move on to the next state.
964F LD A,($F602) Fetch the number of crystals from F602.
9652 CP (IX+$13) Compare it with the state.
9655 JP NZ,UpdateCrystalStack_Next Jump to UpdateCrystalStack_Next if they are different.
9658 LD A,($F602) Fetch the number of crystals again.
965B CP $08 Are there eight?
965D RET NZ Return if not.
965E LD A,($96AB) Fetch the flag from 96AB.
9661 AND A Test it.
9662 JR Z,UpdateCrystalStack_Docked Jump to UpdateCrystalStack_Docked if it is clear.
9664 CALL DrawMainFlame Call DrawMainFlame.
9667 LD A,($96B0) Fetch the value from UpdateCrystalStack_Table.
966A AND %10000000 Keep bit 7.
966C RET NZ Return if it is set.
966D DEC A Decrease it.
966E LD ($96AB),A Store it in 96AB.
9671 RET Return.
UpdateCrystalStack_Docked 9672 LD HL,($C8E6) Fetch the map column and horizontal position of the player from C8E6.
9675 LD A,L Fetch the map column.
9676 CP $52 Is it 52?
9678 RET NZ Return if not.
9679 LD A,H Fetch the horizontal position.
967A CP $5C Is it 5C?
967C RET NZ Return if not.
967D LD HL,($C8E9) Fetch the map zone and vertical position of the player from C8E9.
9680 LD A,L Fetch the map zone.
9681 CP $0A Is it 0A?
9683 RET NZ Return if not.
9684 LD A,H Fetch the vertical position.
9685 CP $63 Is it lower than 63?
9687 RET C Return if so.
9688 LD ($96AB),A Set the flag at 96AB.
968B LD A,$0A Set the explosion counter at 8F53 to 0A.
968D LD ($8F53),A
9690 CALL RunFrame_Ship Call RunFrame_Ship.
9693 CALL DrawShipTop Call DrawShipTop.
9696 XOR A Clear the explosion counter.
9697 LD ($8F53),A
969A LD A,$80 Set C27A to 80.
969C LD ($C27A),A
969F CALL CheckItemDelivery Call CheckItemDelivery.
96A2 LD HL,$0000 Clear C8FE.
96A5 LD ($C8FE),HL
96A8 JP PlayHitSound Play the explosion sound.
96AB DEFB $00
96AC DEFW $5268
96AE DEFW $0A73
UpdateCrystalStack_Table 96B0 DEFB $00,$00,$00,$00,$00
96B5 DEFB $00,$00,$00,$00,$F7
96BA DEFB $00,$00,$00,$00,$EE
96BF DEFB $00,$00,$00,$00,$DE
96C4 DEFB $00,$00,$00,$F2,$E2
96C9 DEFB $00,$00,$00,$16,$E2
96CE DEFB $00,$00,$00,$00,$D1
96D3 DEFB $00,$00,$00,$00,$C1
Prev: 955F Up: Map Next: 96D8