Prev: 9657 Up: Map Next: 96CB
9689: Prepare Draw 2 Byte Sprite
Gets the registers ready to draw the sprite of the object that IX points at, at its current position.
It does what PrepDraw23 does for the old sprite, but it uses the position and the type of the object, patches the jump at DrawNewEntityRow_Jump (used by the unrolled code at DrawNewEntityRow), and stores the number of rows in New_Sprite_Row_Count and New_Sprite_Height. The number of character cells that the sprite covers in each row (one more than the width if the sprite is not aligned to a character boundary) is stored in New_Sprite_Width.
Input
IX Object record
Output
B Page of the shift table
C 00
DE Address of the pixel data
HL Screen address of the bottom row
PrepDraw2 9689 CALL FetchActorSprite Fetch the address of the sprite data in DE.
968C LD L,(IX+$01) Fetch the x position of the object into L.
968F LD H,(IX+$03) Fetch the y position of the object into H.
9692 LD A,L Copy the x position to A.
9693 DEC A Subtract one.
9694 RLCA Multiply by two (rotate left).
9695 AND %00001110 Keep only the bits of the pixel offset (bits 1-3).
9697 OR %11110000 Set bits 4-7 to point at the pages F0 to FF.
9699 LD B,A Store the page of the shift table in B.
969A LD A,L Copy the x position to A.
969B AND %00000111 Keep only the pixel offset.
969D LD A,(DE) Fetch the width of the sprite in bytes.
969E JR Z,PrepDraw2_StoreCells Jump to PrepDraw2_StoreCells if the sprite starts on a character boundary.
96A0 INC A Add one for the extra cell that the shifted sprite needs.
PrepDraw2_StoreCells 96A1 LD ($8EE6),A Store the number of cells in each row in New_Sprite_Width.
96A4 LD A,(DE) Fetch the width of the sprite in bytes.
96A5 INC DE Move on to the height of the sprite.
96A6 NEG Negate the width.
96A8 AND %00001111 Keep only the low four bits.
96AA SUB $07 Subtract 07 (which leaves 09 minus the width, the number of unused pieces of the unrolled code).
96AC ADD A,A Multiply by four.
96AD ADD A,A
96AE LD C,A Store the result in C.
96AF ADD A,A Multiply by two.
96B0 ADD A,C Add the result so that it is multiplied by twelve (the size of the code for one byte of the row).
96B1 LD C,A Store the offset in C.
96B2 LD A,L Copy the x position to A.
96B3 AND %00000111 Keep only the pixel offset.
96B5 LD A,C Fetch the offset.
96B6 JR NZ,PrepDraw2_SetJump Jump to PrepDraw2_SetJump if the sprite does not start on a character boundary.
96B8 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.
PrepDraw2_SetJump 96BA LD ($97E7),A Change the operand of the jump at DrawNewEntityRow_Jump.
96BD LD A,(DE) Fetch the height of the sprite.
96BE INC DE Move on to the pixel data.
96BF LD ($8EE3),A Store the number of rows of the new sprite in New_Sprite_Row_Count.
96C2 LD ($8EE7),A Store the height of the sprite in New_Sprite_Height.
96C5 CALL ScreenAddress Convert the position into the screen address.
96C8 LD C,$00 C=00.
96CA RET Return.
View the equivalent code in;
Prev: 9657 Up: Map Next: 96CB