Prev: E570 Up: Map Next: E69D
E622: Handle Stalactite
Handler for the object types 3C 3D 55 56 and 57 the stalactites that hang from the ceiling of a cave room. They are made by Build_Stalactite from the templates at Stalactite_Templates. A stalactite does not move.
It is drawn once, when bit 0 of its redraw flags is set. At the same time, if bit 3 of byte 06 is set, the stalactite has a gem in it. The gem is made as a copy of the record of the stalactite in the record that is 20 bytes on, with the type 64 plus the two low bits of the sum of the room x, the room y and byte 06 (so there are four kinds of gem). Its y position is that of the stalactite less the height of the stalactite (byte 0C), its attribute is 45 (cyan) and it is handled by Handle_Collectable. Byte 06 of the stalactite is then cleared, so that only one gem is made.
The attributes of the cells that the stalactite covers are copied from the colour data on every call (see Colour_Data), which keeps the stalactite coloured whatever passes in front of it. The colour data is chosen by the two low bits of the type, using the pointers at Stalactite_Colour_Pointers.
Input
IX Object record of the stalactite
Handle_Stalactite E622 CALL PrepDraw2 Prepare the sprite of the stalactite.
E625 BIT 0,(IX+$0F) Jump to Handle_Stalactite_Colour if the stalactite has been drawn already.
E629 JR Z,Handle_Stalactite_Colour
E62B BIT 3,(IX+$06) Jump to Handle_Stalactite_Draw if the stalactite has no gem in it.
E62F JR Z,Handle_Stalactite_Draw
E631 PUSH IX Copy the address of the record of the stalactite to DE.
E633 POP DE
E634 LD HL,$0020 Set HL to 20.
E637 ADD HL,DE Point HL at the record that is 20 bytes on.
E638 LD BC,$0010 Set a counter of 10 bytes.
E63B EX DE,HL Swap the addresses, so that DE points at the other record.
E63C PUSH DE Stash the address of the other record.
E63D LDIR Copy the record of the stalactite to the other record.
E63F POP HL Restore the address of the other record to HL.
E640 LD A,(IX+$02) Fetch the room x.
E643 ADD A,(IX+$04) Add the room y.
E646 ADD A,(IX+$06) Add byte 06.
E649 AND %00000011 Keep only the two low bits.
E64B ADD A,$64 Add 64 to make the type of one of the four gems.
E64D LD (HL),A Set the type of the gem.
E64E INC HL Move on to the y position of the gem.
E64F INC HL
E650 INC HL
E651 LD A,(HL) Fetch the y position of the gem.
E652 SUB (IX+$0C) Subtract the height of the stalactite.
E655 LD (HL),A Set the y position of the gem.
E656 INC HL Move on to the attribute of the gem.
E657 INC HL
E658 LD (HL),$45 Set the attribute of the gem to 45 (cyan).
E65A LD (IX+$06),$00 Clear byte 06 of the stalactite.
Handle_Stalactite_Draw E65E RES 0,(IX+$0F) Reset bit 0 of the redraw flags.
E662 CALL DrawEntity Draw the stalactite.
Handle_Stalactite_Colour E665 LD D,$00 Clear the high byte of the offset.
E667 LD A,(IX+$00) Fetch the type of the stalactite.
E66A AND %00000011 Keep only the two low bits.
E66C LD E,A Store the colour type in E.
E66D LD HL,$E69D Point HL at Stalactite_Colour_Pointers.
E670 ADD HL,DE Add the result twice, to point at the pointer for the type.
E671 ADD HL,DE
E672 LD E,(HL) Fetch the low byte of the pointer.
E673 INC HL Move on to the high byte.
E674 LD D,(HL) Fetch the high byte of the pointer, which makes DE point at the colour data.
This entry point is used by the routine at Handle_Coloured_Decoration.
Handle_Stalactite_Colour_Copy E675 LD L,(IX+$01) Fetch the x position of the object.
E678 LD H,(IX+$03) Fetch the y position of the object.
E67B CALL AttributeAddress Get the attribute address of the bottom left cell of the sprite in HL.
E67E LD A,($8EE6) Fetch the number of cells in each row of the sprite.
E681 LD B,A Store it in B.
E682 LD A,($8EE7) Fetch the height of the sprite in pixels.
E685 RRCA Divide it by eight.
E686 RRCA
E687 RRCA
E688 AND %00011111 Keep only the low five bits.
E68A LD C,A Store the number of rows in C.
Handle_Stalactite_Colour_Row E68B PUSH BC Stash the number of rows and the number of cells in each row.
E68C PUSH HL Stash the attribute address of the start of the row.
Handle_Stalactite_Colour_Cell E68D LD A,(DE) Fetch an attribute from the colour data.
E68E LD (HL),A Set the attribute of the cell.
E68F INC HL Move on to the next cell.
E690 INC DE Move on to the next attribute in the colour data.
E691 DJNZ Handle_Stalactite_Colour_Cell Decrease the cell counter and loop back for the rest of the cells in the row.
E693 POP HL Restore the attribute address of the start of the row.
E694 LD BC,$FFE0 Set BC to FFE0 which is minus the number of cells in a row of the screen.
E697 ADD HL,BC Move up to the row above.
E698 POP BC Restore the number of rows and the number of cells in each row.
E699 DEC C Decrease the row counter and loop back until all of the rows have been done.
E69A JR NZ,Handle_Stalactite_Colour_Row
E69C RET Return.
Prev: E570 Up: Map Next: E69D