Prev: 9652 Up: Map Next: 9689
9657: Prepare Draw 2/ 3 Byte Sprite
Used by the routines at RemoveEntity and DisplayEntity.
Gets the registers ready to draw the sprite at its old position, which was stored by StoreEntity.
The shift table page is put in B, the screen address of the bottom row is put in HL, and the pointer to the pixel data is put in DE. The operand of the jump at DrawOldEntityRow_Jump is changed so that the unrolled code at DrawOldEntityRow draws the right number of bytes for each row, and the number of rows is stored in Old_Sprite_Row_Count.
Output
B Page of the shift table
C 00
DE Address of the pixel data
HL Screen address of the bottom row
PrepDraw23 9657 CALL GetSpriteA Fetch the address of the sprite data in DE.
965A LD HL,($8EE4) Fetch the old x position into L and the old y position into H.
965D LD A,L Copy the x position to A.
965E DEC A Subtract one.
965F RLCA Multiply by two (rotate left).
9660 AND %00001110 Keep only the bits of the pixel offset (bits 1-3).
9662 OR %11110000 Set bits 4-7 to point at the pages F0 to FF.
9664 LD B,A Store the page of the shift table in B.
9665 LD A,(DE) Fetch the width of the sprite in bytes.
9666 INC DE Move on to the height of the sprite.
9667 NEG Negate the width.
9669 AND %00001111 Keep only the low four bits.
966B SUB $07 Subtract 07 (which leaves 09 minus the width, the number of unused pieces of the unrolled code).
966D ADD A,A Multiply by four.
966E ADD A,A
966F LD C,A Store the result in C.
9670 ADD A,A Multiply by two.
9671 ADD A,C Add the result so that it is multiplied by twelve (the size of the code for one byte of the row).
9672 LD C,A Store the offset in C.
9673 LD A,L Copy the x position to A.
9674 AND %00000111 Keep only the pixel offset.
9676 LD A,C Fetch the offset.
9677 JR NZ,PrepDraw23_SetJump Jump to PrepDraw23_SetJump if the sprite does not start on a character boundary.
9679 ADD A,$06 Add 06 to the offset to skip the first six bytes of the code for the first byte of the row, as no cell to the left is needed.
PrepDraw23_SetJump 967B LD ($9761),A Change the operand of the jump at DrawOldEntityRow_Jump.
967E LD A,(DE) Fetch the height of the sprite.
967F INC DE Move on to the pixel data.
9680 LD ($8EE2),A Store the number of rows of the old sprite in Old_Sprite_Row_Count.
9683 CALL ScreenAddress Convert the position into the screen address.
9686 LD C,$00 C=00.
9688 RET Return.
View the equivalent code in;
Prev: 9652 Up: Map Next: 9689