Prev: 34561 Up: Map Next: 34684
34611: Colourise Sprite
Write the actor's attribute bytes into the buffer using AttributeAddress.
Input
IX Actor slot
Before After DrawSprite After ColouriseSprite
jetman-before jetman-drawn jetman-coloured
Write the actor colour into the attribute rectangle.
ColouriseSprite 34611 LD L,(IX+1) Fetch the screen column and actor Y.
34614 LD H,(IX+4)
34617 LD D,(IX+7) Fetch the actor colour from *IX+7.
34620 LD A,(24151) Return if SpriteWidth is zero.
34623 AND A
34624 RET Z
34625 LD B,A Set the column counter from SpriteWidth.
34626 CALL AttributeAddress Call AttributeAddress.
34629 LD A,(24152) Turn SpriteHeight into an attribute-row count.
34632 RRCA
34633 RRCA
34634 INC A
34635 RRCA
34636 AND %00011111 Keep only bits 0-4.
34638 INC A Store the row count.
34639 LD C,A
Paint one attribute row, then step up to the next.
ColouriseSprite_Loop 34640 PUSH BC Stash the counters and attribute address.
34641 PUSH HL
34642 LD A,H Jump to ColouriseSprite_NextRow if the address is below 22528.
34643 CP 88
34645 JR C,ColouriseSprite_NextRow
34647 PUSH BC Skip this row if the address is at or past 23232.
34648 PUSH HL
34649 LD BC,23232
34652 AND A
34653 SBC HL,BC
34655 POP HL
34656 POP BC
34657 JR NC,ColouriseSprite_NextRow
Write the actor colour along the row, skipping empty attributes.
ColouriseSprite_WriteInk 34659 LD A,(HL) Jump to ColouriseSprite_NextColumn if this attribute is empty.
34660 AND A
34661 JR Z,ColouriseSprite_NextColumn
34663 LD (HL),D Write the actor colour.
ColouriseSprite_NextColumn 34664 INC L Move onto the next attribute column.
34665 LD A,L
34666 AND %00011111 Keep only bits 0-4.
34668 JR Z,ColouriseSprite_NextRow Jump to ColouriseSprite_NextRow if the row wrapped, else loop back to ColouriseSprite_WriteInk.
34670 DJNZ ColouriseSprite_WriteInk
Step up one attribute row and repeat until every row is painted.
ColouriseSprite_NextRow 34672 POP HL Restore the start of this attribute row.
34673 LD BC,32 Move up one attribute row.
34676 AND A
34677 SBC HL,BC
34679 POP BC
34680 DEC C Decrease the row counter and loop back to ColouriseSprite_Loop until every row is painted.
34681 JR NZ,ColouriseSprite_Loop
34683 RET Return.
View the equivalent code in;
Prev: 34561 Up: Map Next: 34684