![]() |
Routines |
| Prev: 46009 | Up: Map | Next: 46102 |
|
Used by the routine at DrawSprite.
Builds a copy of a sprite in the buffer at 23408 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.
|
||||||||||||||
|
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 | 46027 | RRA | The pattern index is the countdown nibble, less four. | |||||||||||
| 46028 | RRA | |||||||||||||
| 46029 | SUB 4 | |||||||||||||
| 46031 | LD B,A | Keep the index. | ||||||||||||
| 46032 | LD A,(41693) | Read the frame counter. | ||||||||||||
| 46035 | AND %00000011 | Use its low two bits. | ||||||||||||
| 46037 | OR B | Combine them with the index. | ||||||||||||
| 46038 | LD HL,46102 | Look the mask up in the pattern table. | ||||||||||||
| 46041 | CALL AddToAddress | |||||||||||||
| 46044 | LD C,(HL) | Read the mask. | ||||||||||||
| 46045 | EX DE,HL | The sprite is the source. | ||||||||||||
| 46046 | LD A,(41693) | Read the frame counter again. | ||||||||||||
| 46049 | AND %00000001 | Use its low bit. | ||||||||||||
| 46051 | ADD A,A | Turn that bit into a rotate one way or the other. | ||||||||||||
| 46052 | ADD A,A | |||||||||||||
| 46053 | ADD A,A | |||||||||||||
| 46054 | INC A | |||||||||||||
| 46055 | LD (46091),A | Patch the rotate below with it. | ||||||||||||
| 46058 | LD B,(HL) | Remember the sprite's width and height at the front of the buffer. | ||||||||||||
| 46059 | INC HL | |||||||||||||
| 46060 | LD E,(HL) | |||||||||||||
| 46061 | LD A,B | |||||||||||||
| 46062 | LD (23408),A | |||||||||||||
| 46065 | LD A,E | |||||||||||||
| 46066 | LD (23409),A | |||||||||||||
| 46069 | XOR A | Move on to the sprite data and clear the total. | ||||||||||||
| 46070 | INC HL | |||||||||||||
| BuildPatternedSprite_Width | 46071 | ADD A,E | Add the width once for every row. | |||||||||||
| 46072 | DJNZ BuildPatternedSprite_Width | |||||||||||||
| 46074 | LD B,A | The total is the number of byte pairs. | ||||||||||||
| 46075 | LD (23770),SP | Remember the stack and read the sprite through it. | ||||||||||||
| 46079 | LD SP,HL | |||||||||||||
| 46080 | LD HL,23410 | The masked copy is built just after the width and height. | ||||||||||||
| BuildPatternedSprite_Pairs | 46083 | POP DE | Copy one byte and mask its partner. | |||||||||||
| 46084 | LD (HL),E | |||||||||||||
| 46085 | INC HL | |||||||||||||
| 46086 | LD A,D | |||||||||||||
| 46087 | AND C | |||||||||||||
| 46088 | LD (HL),A | |||||||||||||
| 46089 | INC HL | Move on to the next pair. | ||||||||||||
| 46090 | RRC C | Rotate the mask and repeat for the remaining pairs. | ||||||||||||
| 46092 | DJNZ BuildPatternedSprite_Pairs | |||||||||||||
| 46094 | LD SP,(23770) | Restore the stack pointer. | ||||||||||||
| 46098 | LD DE,23408 | Return the buffer, width and height included. | ||||||||||||
| 46101 | RET | Return. | ||||||||||||
| Prev: 46009 | Up: Map | Next: 46102 |