Prev: 7447 Up: Map Next: 748F
7450: Colourise Sprite
Writes the colour of an actor into the attribute buffer, covering the character cells that its sprite has just been drawn over. The pixels are drawn first (see DisplayEntity), so until this routine runs the sprite is drawn in the attribute that was already there.
Input
IX Actor object
Before After
colourise-before colourise-after
ColouriseSprite 7450 EXX Switch to the shadow registers.
7451 LD HL,($5E1A) Fetch the screen position of the sprite from SpritePosition.
7454 CALL AttributeAddress Convert it to an attribute buffer address using AttributeAddress.
7457 LD A,($5E0F) Set the column counter in B' to the sprite width, from NewSprite_Width.
745A LD B,A
745B LD A,($5E0E) Fetch the sprite height in pixels from 5E0E.
745E RRCA Divide the height by 04 add 01 then divide by 02.
745F RRCA
7460 INC A
7461 RRCA
7462 AND %00011111 Keep only bits 0-4.
7464 INC A Increment A by one.
7465 LD C,A Set the row counter in C' to the result.
7466 LD D,(IX+$03) Fetch the colour attribute from *IX+03.
7469 LD E,B Remember the sprite width in E' so that the column counter can be reset for each row.
Colour one row of attribute cells.
ColouriseSprite_Loop1 746A PUSH HL Stash the address of the start of the row on the stack.
ColouriseSprite_Loop2 746B LD A,H Fetch the MSB of the attribute buffer address.
746C CP $5B Jump to ColouriseSprite_NextRow if the address is beyond the attribute buffer (H is at least 5B).
746E JR NC,ColouriseSprite_NextRow
7470 CP $58 Jump to ColouriseSprite_NextRow if the address is before the attribute buffer (H is less than 58).
7472 JR C,ColouriseSprite_NextRow
7474 LD (HL),D Write the colour to the attribute buffer.
7475 INC L Move onto the next column.
7476 LD A,L Fetch the low byte of the address.
7477 AND %00011111 Keep only bits 0-4 (the column).
7479 JR NZ,ColouriseSprite_NextColumn Jump to ColouriseSprite_NextColumn if the column has not wrapped onto the next row.
747B LD A,L Move back to the start of the same row of attribute cells.
747C SUB $20
747E LD L,A
ColouriseSprite_NextColumn 747F DJNZ ColouriseSprite_Loop2 Decrease the column counter by one and loop back to ColouriseSprite_Loop2 until it is zero.
Move up one row of attribute cells.
ColouriseSprite_NextRow 7481 POP HL Restore the address of the start of the row from the stack.
7482 PUSH BC Subtract 20 from HL, preserving BC.
7483 AND A
7484 LD BC,$0020
7487 SBC HL,BC
7489 POP BC
748A LD B,E Reset the column counter from E'.
748B DEC C Decrease the row counter by one and loop back to ColouriseSprite_Loop1 until it is zero.
748C JR NZ,ColouriseSprite_Loop1
748E RET Return.
View the equivalent code in;
Prev: 7447 Up: Map Next: 748F