Prev: B280 Up: Map Next: B2E9
B28C: Draw Wide Sprite
Used by the routine at DrawWideSprites.
Draws a sprite which is eight rows high and four bytes wide into a buffer which has twenty four bytes in each row. The pixels are combined with what is already in the buffer. The horizontal pixel position is in SpriteHorizontalPosition: if it is not a multiple of eight, the sprite data is a list of indexes into the tables which shift a byte by two, four or six pixels, and the sprite takes five bytes in each row of the buffer. The routine takes the data from the stack to make it faster.
Input
A The number of the sprite
HL The address in the buffer
Find the data of the sprite.
DrawWideSprite B28C EX DE,HL Swap the address in the buffer into DE.
B28D LD BC,$6AC6 Point BC at PosterImagePointers.
B290 CALL GetTableEntry Point HL at the data of the sprite.
B293 LD ($A21D),SP Save the stack pointer.
B297 LD SP,HL Point the stack pointer at the data.
B298 EX DE,HL Swap the address in the buffer back into HL.
B299 LD A,($A220) Fetch the horizontal pixel position.
B29C AND %00000110 Keep the offset within the byte.
B29E JR Z,DrawWideSprite_Aligned Jump to DrawWideSprite_Aligned if the sprite is on a byte boundary.
The sprite is not on a byte boundary, so shift it using the shift tables.
B2A0 OR %11111000 Make the offset the high byte of the address of a shift table.
B2A2 LD D,A Point D at the shift table.
B2A3 LD A,$08 Set the number of rows to eight.
DrawWideSprite_ShiftedRow B2A5 EX AF,AF' Keep the number of rows in the alternate accumulator.
B2A6 POP BC Fetch the indexes for the first two bytes of a row.
B2A7 LD E,C Copy the first index into E.
B2A8 LD A,(DE) Fetch the shifted first byte.
B2A9 OR (HL) Combine it with the buffer.
B2AA LD (HL),A Write it to the buffer.
B2AB INC HL Move on to the second byte.
B2AC INC D Point D at the overflow table.
B2AD LD A,(DE) Fetch the overflow of the first byte.
B2AE DEC D Point D back at the shift table.
B2AF LD E,B Copy the second index into E.
B2B0 EX DE,HL Swap the buffer address into DE.
B2B1 OR (HL) Combine the overflow with the shifted second byte.
B2B2 LD (DE),A Write it to the buffer.
B2B3 INC DE Move on to the third byte.
B2B4 INC H Point H at the overflow table.
B2B5 LD A,(HL) Fetch the overflow of the second byte.
B2B6 DEC H Point H back at the shift table.
B2B7 POP BC Fetch the indexes for the next two bytes of the row.
B2B8 LD L,C Copy the third index into L.
B2B9 OR (HL) Combine the third byte with the buffer.
B2BA LD (DE),A Write it to the buffer.
B2BB INC DE Move on to the fourth byte.
B2BC INC H Point H at the overflow table.
B2BD LD A,(HL) Fetch the overflow of the third byte.
B2BE DEC H Point H back at the shift table.
B2BF LD L,B Copy the fourth index into L.
B2C0 OR (HL) Combine it with the shifted fourth byte.
B2C1 LD (DE),A Write it to the buffer.
B2C2 INC DE Move on to the fifth byte.
B2C3 INC H Point H at the overflow table.
B2C4 EX DE,HL Swap the buffer address into HL.
B2C5 LD A,(DE) Fetch the overflow of the fourth byte.
B2C6 OR (HL) Combine it with the buffer.
B2C7 LD (HL),A Write it to the buffer.
B2C8 DEC D Point D back at the shift table.
B2C9 LD BC,$0014 Set the distance to the next row of the buffer.
B2CC ADD HL,BC Move on to the next row.
B2CD EX AF,AF' Fetch the number of rows.
B2CE DEC A Count down the rows.
B2CF JR NZ,DrawWideSprite_ShiftedRow Loop back until all eight rows have been drawn.
DrawWideSprite_Done B2D1 LD SP,($A21D) Restore the stack pointer.
B2D5 RET Return.
The sprite is on a byte boundary, so copy the bytes straight to the buffer.
DrawWideSprite_Aligned B2D6 LD B,$08 Set the number of rows to eight.
DrawWideSprite_AlignedRow B2D8 POP DE Fetch two bytes of the row.
B2D9 LD (HL),E Write the first to the buffer.
B2DA INC HL Move on to the second byte.
B2DB LD (HL),D Write the second to the buffer.
B2DC INC HL Move on to the third byte.
B2DD POP DE Fetch two more bytes of the row.
B2DE LD (HL),E Write the third to the buffer.
B2DF INC HL Move on to the fourth byte.
B2E0 LD (HL),D Write the fourth to the buffer.
B2E1 LD DE,$0015 Set the distance to the next row of the buffer.
B2E4 ADD HL,DE Move on to the next row.
B2E5 DJNZ DrawWideSprite_AlignedRow Loop back until all eight rows have been drawn.
B2E7 JR DrawWideSprite_Done Jump to DrawWideSprite_Done.
Prev: B280 Up: Map Next: B2E9