Prev: 29922 Up: Map Next: 30004
29934: Colour Sprite
Colours the character cells covered by the actor sprite prepared by PrepareActorSprite, using the colour in byte 3 of the actor. Cells outside of the attribute buffer, or to the right of the play area, are left alone.
Input
IX Actor
Fetch the address of the first attribute cell, and the size of the area to colour.
ColourSprite 29934 EXX Switch to the shadow registers.
29935 LD HL,(24351) Fetch the position of the actor sprite (ActorSprite_Position).
29938 CALL AttributeAddress Calculate the attribute buffer address using AttributeAddress.
29941 LD A,(24344) Fetch the width of the actor sprite (ActorSprite_Width).
29944 LD B,A
29945 LD A,(24343) Fetch the number of rows of the actor sprite (ActorSprite_Rows).
29948 RRCA Divide by 4 (rotating the bits).
29949 RRCA
29950 INC A Increment A by one.
29951 RRCA Divide by 2 (rotating the bits).
29952 AND %00011111 Keep only bits 0-4.
29954 INC A Increment A by one.
29955 LD C,A Store the number of attribute rows to colour in C.
29956 LD D,(IX+3) Fetch the actor colour.
29959 LD E,B Store the number of columns in E.
ColourSprite_Row 29960 PUSH HL Stash the address of the start of the row on the stack.
ColourSprite_Column 29961 LD A,H Fetch the high byte of the attribute address.
29962 CP 91 Jump to ColourSprite_NextRow if the address is beyond the end of the attribute buffer (91 or higher).
29964 JR NC,ColourSprite_NextRow
29966 CP 88 Jump to ColourSprite_NextRow if the address is before the start of the attribute buffer.
29968 JR C,ColourSprite_NextRow
29970 LD A,L Fetch the low byte of the attribute address.
29971 AND %00011111 Keep only bits 0-4.
Self modifying code; the operand of this command is written by 24566 and 27977, and sets the column which the colouring stops at.
29973 CP 26 Jump to ColourSprite_NextRow if the column is beyond the right edge.
29975 JR NC,ColourSprite_NextRow
29977 LD (HL),D Write the colour to the attribute cell.
29978 INC L Move onto the next column.
29979 LD A,L Fetch the low byte of the attribute address.
29980 AND %00011111 Keep only bits 0-4.
29982 JR NZ,ColourSprite_NextColumn Jump to ColourSprite_NextColumn if the row has not wrapped.
29984 LD A,L Move back to the start of the row so it doesn't wrap onto the next one.
29985 SUB 32
29987 LD L,A
ColourSprite_NextColumn 29988 DJNZ ColourSprite_Column Decrease the column counter by one and loop back to ColourSprite_Column until all of the columns have been done.
ColourSprite_NextRow 29990 POP HL Retrieve the address of the start of the row.
29991 PUSH BC Stash the row counter on the stack.
29992 AND A Clear the carry flag.
29993 LD BC,32 Set the size of a row of attributes to 32.
29996 SBC HL,BC Move up one row.
29998 POP BC Restore the row counter.
29999 LD B,E Restore the column counter.
30000 DEC C Decrease the row counter by one.
30001 JR NZ,ColourSprite_Row Loop back to ColourSprite_Row until all of the rows have been done.
30003 RET Return.
Prev: 29922 Up: Map Next: 30004