Prev: D013 Up: Map Next: D08F
D027: Print Sprite
Used by the routines at PrintSprites, DisplayObjectsCarried and PrintTableSprite.
Draws the sprite of an object into ScreenBuffer, at the pixel position of the object. A sprite has a width byte (the vertical flip in bit 7, the horizontal flip in bit 6 and the width in columns in the low bits), a height byte, and then the data for each line from the top. Each column of a line is a pair of bytes: a mask byte, then a data byte. The mask clears the bits of the background and the data sets bits. A sprite that does not start on a byte boundary has each pair shifted across two bytes of the buffer, with the tables built by BuildLookupTables. The routine copies the sprite with unrolled code, which it enters part of the way along, so that it does as many columns as the sprite has. To do this it changes the code, and it uses the stack pointer to read the data of the sprite.
Input
IX The address of the object
Find the sprite and choose the draw path.
PrintSprite D027 CALL GetSpriteAddress Call GetSpriteAddress.
D02A LD A,(IX+$1A) Fetch the pixel x position.
D02D AND %00000111 Keep bits 0 to 2.
D02F JR Z,PrintSprite_Aligned Jump to PrintSprite_Aligned if it is zero.
Choose the page of the shift table.
D031 RLCA Double it.
D032 AND %00001110 Keep bits 1 to 3.
D034 OR %11110000 Set bits 4 to 7.
D036 LD H,A Copy it to H.
D037 LD A,(DE) Fetch the width byte of the sprite.
D038 INC DE Increment DE.
D039 AND %00000111 Keep bits 0 to 2.
D03B INC A Increment A.
D03C LD B,A Copy it to B.
D03D LD (IX+$18),A Set the width in bytes of the object.
D040 DEC A Decrement A.
D041 AND %00000111 Keep bits 0 to 2.
D043 ADD A,A Multiply it by sixteen.
D044 ADD A,A
D045 ADD A,A
D046 ADD A,A
D047 NEG Negate it.
D049 ADD A,$50 Add 50.
Change the jump and the step.
PrintSprite_Patch D04B LD ($D0BC),A Write it to D0BC.
D04E LD A,B Fetch B.
D04F CPL Invert it.
D050 ADD A,$22 Add 22.
D052 LD ($D110),A Write it to D110.
Clip the sprite to the top of the screen.
D055 LD A,(DE) Fetch the height of the sprite.
D056 INC DE Increment DE.
D057 LD (IX+$19),A Set the height in lines of the object.
D05A ADD A,(IX+$1B) Add the pixel y position.
D05D SUB $C0 Subtract C0.
D05F JR C,PrintSprite_Draw Jump to PrintSprite_Draw if carry is set.
D061 NEG Negate A.
D063 ADD A,(IX+$19) Add the height in lines.
D066 LD (IX+$19),A Set the height in lines of the object.
Draw the rows that are on the screen.
PrintSprite_Draw D069 LD C,(IX+$1A) Fetch the pixel x position.
D06C LD B,(IX+$1B) Fetch the pixel y position.
D06F CALL CalculateBufferAddress Call CalculateBufferAddress.
D072 LD ($5B09),SP Set SavedStackPointer.
D076 EX DE,HL Point the stack at the sprite data.
D077 LD SP,HL
D078 EX DE,HL
D079 LD A,(IX+$19) Fetch the number of lines.
D07C JR DrawLines Jump to DrawLines.
The sprite is aligned, so the bytes do not need to be shifted.
PrintSprite_Aligned D07E LD A,(DE) Fetch the width byte of the sprite.
D07F INC DE Increment DE.
D080 AND %00001111 Keep bits 0 to 3.
D082 LD (IX+$18),A Set the width in bytes of the object.
D085 LD B,A Copy it to B.
D086 ADD A,A Multiply it by eight.
D087 ADD A,A
D088 ADD A,A
D089 NEG Negate it.
D08B SUB $06 Subtract 06.
D08D JR PrintSprite_Patch Jump to PrintSprite_Patch.
View the equivalent code in;
Prev: D013 Up: Map Next: D08F