Prev: B934 Up: Map Next: B969
B939: Prepare Draw 2/ 3 Byte Sprite
Used by the routines at RemoveEntity and DisplayEntity.
Gets the registers ready to draw the sprite of an entity at its old position, which was saved 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_0 is changed so that the unrolled code that follows it 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 B939 CALL GetSpriteA Fetch the address of the sprite data in DE.
B93C LD HL,($96A0) Fetch the old X position into L and the old Y position into H from Previous_X_Position.
B93F LD A,L A=L.
B940 DEC A Subtract one.
B941 RLCA Multiply by two (rotate left).
B942 AND %00001110 Keep only bits 1-3.
B944 OR %11110000 Set bits 4-7 to point at the pages F0 to FF.
B946 LD B,A Store the page of the shift table in B.
B947 LD A,(DE) Fetch the width of the sprite in bytes.
B948 INC DE Move on to the height of the sprite.
B949 NEG Negate the width.
B94B AND %00000111 Keep only bits 0-2.
B94D ADD A,A Multiply by four.
B94E ADD A,A
B94F LD C,A Store the result in C.
B950 ADD A,A Multiply by two.
B951 ADD A,C Add the result so that it is multiplied by twelve (the size of the code for one byte of the row).
B952 LD C,A Store the offset in C.
B953 LD A,L A=L.
B954 AND %00000111 Keep only the pixel offset (bits 0-2).
B956 LD A,C Fetch the offset.
B957 JR NZ,PrepDraw23_SetJump Jump to PrepDraw23_SetJump if the sprite does not start on a character boundary.
B959 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 B95B LD ($BA13),A Change the operand of the jump at DrawOldEntityRow_0.
B95E LD A,(DE) Fetch the height of the sprite.
B95F INC DE Move on to the pixel data.
B960 LD ($96A3),A Write the number of rows of the old sprite to Old_Sprite_Row_Count.
B963 CALL ScreenAddress Convert the position into the screen address.
B966 LD C,$00 C=00.
B968 RET Return.
View the equivalent code in;
Prev: B934 Up: Map Next: B969