![]() |
Routines |
| Prev: 9C0E | Up: Map | Next: 9C5E |
|
Used by the routine at GameEntry.
Converts every sprite from the form in which it is stored, a mask byte and then a pixel byte for each pair of bytes, into the form used by DrawSprite, which is a mask byte followed by the XOR of the mask and the pixels. Sprites that are already marked as decoded (bit 6 of the first byte of the header) are left alone.
|
||||
| DecodeSprites | 9C20 | LD HL,$6193 | Point HL at the end of the table of sprite addresses (which is the address of the blank sprite). | |
| 9C23 | LD DE,$60A3 | Point DE at SpritePointers. | ||
| 9C26 | AND A | Subtract the start of the table to find its size in bytes. | ||
| 9C27 | SBC HL,DE | |||
| 9C29 | SRL L | Halve it to find the number of sprites... | ||
| 9C2B | LD B,L | ...and use that as the counter. | ||
| DecodeSprites_NextSprite | 9C2C | PUSH BC | Save the counter. | |
| 9C2D | DEC B | The sprite number is one below the counter. | ||
| 9C2E | LD L,B | Use the sprite number as the low byte of the index... | ||
| 9C2F | LD H,$00 | ...and clear H. | ||
| 9C31 | ADD HL,HL | Double it to make an index into the table. | ||
| 9C32 | LD DE,$60A3 | Point DE at SpritePointers. | ||
| 9C35 | ADD HL,DE | Add the index. | ||
| 9C36 | LD E,(HL) | Fetch the address of the sprite... | ||
| 9C37 | INC HL | ...from the table... | ||
| 9C38 | LD D,(HL) | ...into DE. | ||
| 9C39 | LD A,(DE) | Fetch the first byte of the header (the width, and flags). | ||
| 9C3A | BIT 6,A | Jump if the sprite has been decoded already. | ||
| 9C3C | JR NZ,DecodeSprites_Next | |||
| 9C3E | OR $40 | Mark the sprite as decoded... | ||
| 9C40 | LD (DE),A | ...and store the byte. | ||
| 9C41 | AND $0F | Extract the width in bytes, and jump if the sprite is blank. | ||
| 9C43 | JR Z,DecodeSprites_Next | |||
| 9C45 | LD B,A | Use the width as a counter. | ||
| 9C46 | INC DE | Move on to the height. | ||
| 9C47 | LD A,(DE) | Fetch it... | ||
| 9C48 | LD C,A | ...and keep it in C. | ||
| 9C49 | AND A | Jump if the sprite is blank. | ||
| 9C4A | JR Z,DecodeSprites_Next | |||
| 9C4C | XOR A | Multiply the height by the width, by adding it up that many times, to find the number of pairs of bytes. | ||
| DecodeSprites_AddHeight | 9C4D | ADD A,C | Add the height. | |
| 9C4E | DJNZ DecodeSprites_AddHeight | Loop back until done. | ||
| 9C50 | EX DE,HL | Point HL at the sprite data. | ||
| 9C51 | INC HL | Move on to the first pair of bytes. | ||
| 9C52 | LD B,A | Use the number of pairs as a counter. | ||
| DecodeSprites_Pair | 9C53 | LD A,(HL) | Fetch the mask. | |
| 9C54 | INC HL | Move on to the pixels. | ||
| 9C55 | XOR (HL) | Combine the mask with the pixels... | ||
| 9C56 | LD (HL),A | ...and store the result. | ||
| 9C57 | INC HL | Move on to the next pair. | ||
| 9C58 | DJNZ DecodeSprites_Pair | Loop back until every pair has been converted. | ||
| DecodeSprites_Next | 9C5A | POP BC | Restore the sprite counter. | |
| 9C5B | DJNZ DecodeSprites_NextSprite | Loop back until every sprite has been decoded. | ||
| 9C5D | RET | Return. | ||
| Prev: 9C0E | Up: Map | Next: 9C5E |