Prev: 47417 Up: Map Next: 47529
47465: Prepare Draw 2 Byte Sprite
Used by the routines at DrawEntity and DisplayEntity.
Gets the registers ready to draw the sprite of the entity that IX points at, at its current position.
It does what PrepDraw23 does for the old sprite, but it uses the position and the sprite of the entity, changes the operand of the jump at DrawNewEntityRow_0 (used by the 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 Actor record
Output
B Page of the shift table
C 0
DE Address of the pixel data
HL Screen address of the bottom row
PrepDraw2 47465 CALL FetchActorSprite Fetch the address of the sprite data in DE.
47468 LD L,(IX+3) Fetch the X position of the entity into L.
47471 LD H,(IX+4) Fetch the Y position of the entity into H.
47474 LD A,L A=L.
47475 DEC A Subtract one.
47476 RLCA Multiply by two (rotate left).
47477 AND %00001110 Keep only bits 1-3.
47479 OR %11110000 Set bits 4-7 to point at the pages 240 to 255.
47481 LD B,A Store the page of the shift table in B.
47482 LD A,L A=L.
47483 AND %00000111 Keep only the pixel offset (bits 0-2).
47485 LD A,(DE) Fetch the width of the sprite in bytes.
47486 JR Z,PrepDraw2_StoreCells Jump to PrepDraw2_StoreCells if the sprite starts on a character boundary.
47488 INC A Add one for the extra cell that the shifted sprite needs.
PrepDraw2_StoreCells 47489 LD (38566),A Write the number of cells in each row to New_Sprite_Width.
47492 LD A,(DE) Fetch the width of the sprite in bytes.
47493 INC DE Move on to the height of the sprite.
47494 NEG Negate the width.
47496 AND %00000111 Keep only bits 0-2.
47498 ADD A,A Multiply by four.
47499 ADD A,A
47500 LD C,A Store the result in C.
47501 ADD A,A Multiply by two.
47502 ADD A,C Add the result so that it is multiplied by twelve (the size of the code for one byte of the row).
47503 LD C,A Store the offset in C.
47504 LD A,L A=L.
47505 AND %00000111 Keep only the pixel offset (bits 0-2).
47507 LD A,C Fetch the offset.
47508 JR NZ,PrepDraw2_SetJump Jump to PrepDraw2_SetJump if the sprite does not start on a character boundary.
47510 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 47512 LD (47762),A Change the operand of the jump at DrawNewEntityRow_0.
47515 LD A,(DE) Fetch the height of the sprite.
47516 INC DE Move on to the pixel data.
47517 LD (38564),A Write the number of rows of the new sprite to New_Sprite_Row_Count.
47520 LD (38565),A Write the height of the sprite to New_Sprite_Height.
47523 CALL ScreenAddress Convert the position into the screen address.
47526 LD C,0 C=0.
47528 RET Return.
View the equivalent code in;
Prev: 47417 Up: Map Next: 47529