Prev: 28728 Up: Map Next: 28823
28747: Colourise Sprite
Used by the routine at HandlerCar.
Sets the attributes under a sprite to the attribute of the actor. The sprite is coloured from the bottom upwards and the attributes of the top row of the screen and of the border (118) are left alone. Entering at ColouriseSprite_Position (D is the attribute and HL is the position of the bottom left of the sprite in pixels) or at ColouriseSprite_Block (B is the width and C is the height in attribute cells, D is the attribute and HL is the attribute buffer address of the bottom left) uses the normal registers instead of the shadow registers.
Input
IX Actor entity
ColouriseSprite 28747 EXX Switch to the shadow registers.
28748 LD HL,(24103) Fetch the position of the sprite (ActorScreenPosition).
28751 LD D,(IX+3) D'=the attribute of the actor.
This entry point is used by the routine at PlaceObject.
Work out the size of the sprite in attribute cells.
ColouriseSprite_Position 28754 CALL AttributeAddress Call AttributeAddress to convert the pixel co-ordinates into an attribute buffer address.
28757 LD A,(24100) A=WidthBytes (the width of the sprite in bytes).
28760 LD B,A Keep the width in B.
28761 LD A,(24099) A=HeightPixels (the height of the sprite in pixels).
28764 RRCA A=A / 4.
28765 RRCA
28766 INC A Increment A by one.
28767 RRCA A=A / 2.
28768 AND %00011111 Keep only bits 0-4.
28770 INC A Increment A by one.
28771 LD C,A C=A (the number of rows).
This entry point is used by the routine at HandlerPlayer.
Colour each of the rows, going upwards.
ColouriseSprite_Block 28772 LD E,B Keep the width in E.
ColouriseSprite_Loop1 28773 PUSH HL Stash the address of the start of the row on the stack.
ColouriseSprite_Loop2 28774 LD A,H A=H.
28775 CP 91 Jump to ColouriseSprite_NextRow if the address is beyond the end of the attribute buffer.
28777 JR NC,ColouriseSprite_NextRow
28779 PUSH HL Stash HL and BC on the stack.
28780 PUSH BC
28781 LD BC,22560 BC=22560 (the start of the second row of attributes).
28784 AND A HL=HL - BC.
28785 SBC HL,BC
28787 POP BC Restore BC and HL from the stack.
28788 POP HL
28789 JR C,ColouriseSprite_NextRow Jump to ColouriseSprite_NextRow if the address is in the top row of attributes.
28791 LD A,(HL) Fetch the current attribute of the cell.
28792 CP 118 Jump to ColouriseSprite_NextColumn if this is a border attribute (118).
28794 JR Z,ColouriseSprite_NextColumn
28796 LD (HL),D Write the attribute of the actor.
ColouriseSprite_NextColumn 28797 INC L Move onto the next column.
28798 LD A,L A=L.
28799 AND %00011111 Keep only bits 0-4.
28801 JR NZ,ColouriseSprite_Next Jump to ColouriseSprite_Next if the address is still in the same row.
28803 LD A,L Move back to the start of the row (this is for when the actor is partly off the right of the screen).
28804 SUB 32
28806 LD L,A
ColouriseSprite_Next 28807 DJNZ ColouriseSprite_Loop2 Decrease the column counter by one and loop back to ColouriseSprite_Loop2 until the whole row has been coloured.
ColouriseSprite_NextRow 28809 POP HL Restore the address of the start of the row from the stack.
28810 PUSH BC Stash BC on the stack.
28811 AND A Clear the carry flag.
28812 LD BC,32 Set the size of a row, 0032.
28815 SBC HL,BC Move up a row.
28817 POP BC Restore BC from the stack.
28818 LD B,E Reset the width counter.
28819 DEC C Decrease the row counter by one.
28820 JR NZ,ColouriseSprite_Loop1 Loop back to ColouriseSprite_Loop1 until all of the rows have been coloured.
28822 RET Return.
View the equivalent code in;
Prev: 28728 Up: Map Next: 28823