Prev: 38487 Up: Map Next: 38603
38537: 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 0
DE Address of the pixel data
HL Screen address of the bottom row
PrepDraw2 38537 CALL FetchActorSprite Fetch the address of the sprite data in DE.
38540 LD L,(IX+1) Fetch the x position of the object into L.
38543 LD H,(IX+3) Fetch the y position of the object into H.
38546 LD A,L Copy the x position to A.
38547 DEC A Subtract one.
38548 RLCA Multiply by two (rotate left).
38549 AND %00001110 Keep only the bits of the pixel offset (bits 1-3).
38551 OR %11110000 Set bits 4-7 to point at the pages 240 to 255.
38553 LD B,A Store the page of the shift table in B.
38554 LD A,L Copy the x position to A.
38555 AND %00000111 Keep only the pixel offset.
38557 LD A,(DE) Fetch the width of the sprite in bytes.
38558 JR Z,PrepDraw2_StoreCells Jump to PrepDraw2_StoreCells if the sprite starts on a character boundary.
38560 INC A Add one for the extra cell that the shifted sprite needs.
PrepDraw2_StoreCells 38561 LD (36582),A Store the number of cells in each row in New_Sprite_Width.
38564 LD A,(DE) Fetch the width of the sprite in bytes.
38565 INC DE Move on to the height of the sprite.
38566 NEG Negate the width.
38568 AND %00001111 Keep only the low four bits.
38570 SUB 7 Subtract 7 (which leaves 9 minus the width, the number of unused pieces of the unrolled code).
38572 ADD A,A Multiply by four.
38573 ADD A,A
38574 LD C,A Store the result in C.
38575 ADD A,A Multiply by two.
38576 ADD A,C Add the result so that it is multiplied by twelve (the size of the code for one byte of the row).
38577 LD C,A Store the offset in C.
38578 LD A,L Copy the x position to A.
38579 AND %00000111 Keep only the pixel offset.
38581 LD A,C Fetch the offset.
38582 JR NZ,PrepDraw2_SetJump Jump to PrepDraw2_SetJump if the sprite does not start on a character boundary.
38584 ADD A,6 Add 6 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 38586 LD (38887),A Change the operand of the jump at DrawNewEntityRow_Jump.
38589 LD A,(DE) Fetch the height of the sprite.
38590 INC DE Move on to the pixel data.
38591 LD (36579),A Store the number of rows of the new sprite in New_Sprite_Row_Count.
38594 LD (36583),A Store the height of the sprite in New_Sprite_Height.
38597 CALL ScreenAddress Convert the position into the screen address.
38600 LD C,0 C=0.
38602 RET Return.
View the equivalent code in;
Prev: 38487 Up: Map Next: 38603