Prev: 58736 Up: Map Next: 59037
58914: Handle Stalactite
Handler for the object types 60 61 85 86 and 87 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 6 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 32 bytes on, with the type 100 plus the two low bits of the sum of the room x, the room y and byte 6 (so there are four kinds of gem). Its y position is that of the stalactite less the height of the stalactite (byte 12), its attribute is 69 (cyan) and it is handled by Handle_Collectable. Byte 6 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 58914 CALL PrepDraw2 Prepare the sprite of the stalactite.
58917 BIT 0,(IX+15) Jump to Handle_Stalactite_Colour if the stalactite has been drawn already.
58921 JR Z,Handle_Stalactite_Colour
58923 BIT 3,(IX+6) Jump to Handle_Stalactite_Draw if the stalactite has no gem in it.
58927 JR Z,Handle_Stalactite_Draw
58929 PUSH IX Copy the address of the record of the stalactite to DE.
58931 POP DE
58932 LD HL,32 Set HL to 32.
58935 ADD HL,DE Point HL at the record that is 32 bytes on.
58936 LD BC,16 Set a counter of 16 bytes.
58939 EX DE,HL Swap the addresses, so that DE points at the other record.
58940 PUSH DE Stash the address of the other record.
58941 LDIR Copy the record of the stalactite to the other record.
58943 POP HL Restore the address of the other record to HL.
58944 LD A,(IX+2) Fetch the room x.
58947 ADD A,(IX+4) Add the room y.
58950 ADD A,(IX+6) Add byte 6.
58953 AND %00000011 Keep only the two low bits.
58955 ADD A,100 Add 100 to make the type of one of the four gems.
58957 LD (HL),A Set the type of the gem.
58958 INC HL Move on to the y position of the gem.
58959 INC HL
58960 INC HL
58961 LD A,(HL) Fetch the y position of the gem.
58962 SUB (IX+12) Subtract the height of the stalactite.
58965 LD (HL),A Set the y position of the gem.
58966 INC HL Move on to the attribute of the gem.
58967 INC HL
58968 LD (HL),69 Set the attribute of the gem to 69 (cyan).
58970 LD (IX+6),0 Clear byte 6 of the stalactite.
Handle_Stalactite_Draw 58974 RES 0,(IX+15) Reset bit 0 of the redraw flags.
58978 CALL DrawEntity Draw the stalactite.
Handle_Stalactite_Colour 58981 LD D,0 Clear the high byte of the offset.
58983 LD A,(IX+0) Fetch the type of the stalactite.
58986 AND %00000011 Keep only the two low bits.
58988 LD E,A Store the colour type in E.
58989 LD HL,59037 Point HL at Stalactite_Colour_Pointers.
58992 ADD HL,DE Add the result twice, to point at the pointer for the type.
58993 ADD HL,DE
58994 LD E,(HL) Fetch the low byte of the pointer.
58995 INC HL Move on to the high byte.
58996 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 58997 LD L,(IX+1) Fetch the x position of the object.
59000 LD H,(IX+3) Fetch the y position of the object.
59003 CALL AttributeAddress Get the attribute address of the bottom left cell of the sprite in HL.
59006 LD A,(36582) Fetch the number of cells in each row of the sprite.
59009 LD B,A Store it in B.
59010 LD A,(36583) Fetch the height of the sprite in pixels.
59013 RRCA Divide it by eight.
59014 RRCA
59015 RRCA
59016 AND %00011111 Keep only the low five bits.
59018 LD C,A Store the number of rows in C.
Handle_Stalactite_Colour_Row 59019 PUSH BC Stash the number of rows and the number of cells in each row.
59020 PUSH HL Stash the attribute address of the start of the row.
Handle_Stalactite_Colour_Cell 59021 LD A,(DE) Fetch an attribute from the colour data.
59022 LD (HL),A Set the attribute of the cell.
59023 INC HL Move on to the next cell.
59024 INC DE Move on to the next attribute in the colour data.
59025 DJNZ Handle_Stalactite_Colour_Cell Decrease the cell counter and loop back for the rest of the cells in the row.
59027 POP HL Restore the attribute address of the start of the row.
59028 LD BC,65504 Set BC to 65504 which is minus the number of cells in a row of the screen.
59031 ADD HL,BC Move up to the row above.
59032 POP BC Restore the number of rows and the number of cells in each row.
59033 DEC C Decrease the row counter and loop back until all of the rows have been done.
59034 JR NZ,Handle_Stalactite_Colour_Row
59036 RET Return.
Prev: 58736 Up: Map Next: 59037