Prev: B3B9 Up: Map Next: B416
B3CB: Build Patterned Sprite
Used by the routine at DrawSprite.
Builds a copy of a sprite in the buffer at 5B70 for an entity whose sprite has a pattern. The pattern is chosen by the entity and by the frame counter at FrameCounter, taken from the table at PatternTable, and each pair of bytes of the sprite is combined with a rotating mask from the table.
Input
A Bits 4-7 of field 16 of the entity, shifted
DE The address of the sprite
Output
DE The address of the buffer
The countdown nibble, already shifted down, selects the pattern. The low bits of the frame counter choose which mask, and which way it rotates.
BuildPatternedSprite B3CB RRA The pattern index is the countdown nibble, less four.
B3CC RRA
B3CD SUB $04
B3CF LD B,A Keep the index.
B3D0 LD A,($A2DD) Read the frame counter.
B3D3 AND %00000011 Use its low two bits.
B3D5 OR B Combine them with the index.
B3D6 LD HL,$B416 Look the mask up in the pattern table.
B3D9 CALL AddToAddress
B3DC LD C,(HL) Read the mask.
B3DD EX DE,HL The sprite is the source.
B3DE LD A,($A2DD) Read the frame counter again.
B3E1 AND %00000001 Use its low bit.
B3E3 ADD A,A Turn that bit into a rotate one way or the other.
B3E4 ADD A,A
B3E5 ADD A,A
B3E6 INC A
B3E7 LD ($B40B),A Patch the rotate below with it.
B3EA LD B,(HL) Remember the sprite's width and height at the front of the buffer.
B3EB INC HL
B3EC LD E,(HL)
B3ED LD A,B
B3EE LD ($5B70),A
B3F1 LD A,E
B3F2 LD ($5B71),A
B3F5 XOR A Move on to the sprite data and clear the total.
B3F6 INC HL
BuildPatternedSprite_Width B3F7 ADD A,E Add the width once for every row.
B3F8 DJNZ BuildPatternedSprite_Width
B3FA LD B,A The total is the number of byte pairs.
B3FB LD ($5CDA),SP Remember the stack and read the sprite through it.
B3FF LD SP,HL
B400 LD HL,$5B72 The masked copy is built just after the width and height.
BuildPatternedSprite_Pairs B403 POP DE Copy one byte and mask its partner.
B404 LD (HL),E
B405 INC HL
B406 LD A,D
B407 AND C
B408 LD (HL),A
B409 INC HL Move on to the next pair.
B40A RRC C Rotate the mask and repeat for the remaining pairs.
B40C DJNZ BuildPatternedSprite_Pairs
B40E LD SP,($5CDA) Restore the stack pointer.
B412 LD DE,$5B70 Return the buffer, width and height included.
B415 RET Return.
Prev: B3B9 Up: Map Next: B416