![]() |
Routines |
| Prev: 39950 | Up: Map | Next: 40030 |
|
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 | 39968 | LD HL,24979 | Point HL at the end of the table of sprite addresses (which is the address of the blank sprite). | |
| 39971 | LD DE,24739 | Point DE at SpritePointers. | ||
| 39974 | AND A | Subtract the start of the table to find its size in bytes. | ||
| 39975 | SBC HL,DE | |||
| 39977 | SRL L | Halve it to find the number of sprites... | ||
| 39979 | LD B,L | ...and use that as the counter. | ||
| DecodeSprites_NextSprite | 39980 | PUSH BC | Save the counter. | |
| 39981 | DEC B | The sprite number is one below the counter. | ||
| 39982 | LD L,B | Use the sprite number as the low byte of the index... | ||
| 39983 | LD H,0 | ...and clear H. | ||
| 39985 | ADD HL,HL | Double it to make an index into the table. | ||
| 39986 | LD DE,24739 | Point DE at SpritePointers. | ||
| 39989 | ADD HL,DE | Add the index. | ||
| 39990 | LD E,(HL) | Fetch the address of the sprite... | ||
| 39991 | INC HL | ...from the table... | ||
| 39992 | LD D,(HL) | ...into DE. | ||
| 39993 | LD A,(DE) | Fetch the first byte of the header (the width, and flags). | ||
| 39994 | BIT 6,A | Jump if the sprite has been decoded already. | ||
| 39996 | JR NZ,DecodeSprites_Next | |||
| 39998 | OR 64 | Mark the sprite as decoded... | ||
| 40000 | LD (DE),A | ...and store the byte. | ||
| 40001 | AND 15 | Extract the width in bytes, and jump if the sprite is blank. | ||
| 40003 | JR Z,DecodeSprites_Next | |||
| 40005 | LD B,A | Use the width as a counter. | ||
| 40006 | INC DE | Move on to the height. | ||
| 40007 | LD A,(DE) | Fetch it... | ||
| 40008 | LD C,A | ...and keep it in C. | ||
| 40009 | AND A | Jump if the sprite is blank. | ||
| 40010 | JR Z,DecodeSprites_Next | |||
| 40012 | 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 | 40013 | ADD A,C | Add the height. | |
| 40014 | DJNZ DecodeSprites_AddHeight | Loop back until done. | ||
| 40016 | EX DE,HL | Point HL at the sprite data. | ||
| 40017 | INC HL | Move on to the first pair of bytes. | ||
| 40018 | LD B,A | Use the number of pairs as a counter. | ||
| DecodeSprites_Pair | 40019 | LD A,(HL) | Fetch the mask. | |
| 40020 | INC HL | Move on to the pixels. | ||
| 40021 | XOR (HL) | Combine the mask with the pixels... | ||
| 40022 | LD (HL),A | ...and store the result. | ||
| 40023 | INC HL | Move on to the next pair. | ||
| 40024 | DJNZ DecodeSprites_Pair | Loop back until every pair has been converted. | ||
| DecodeSprites_Next | 40026 | POP BC | Restore the sprite counter. | |
| 40027 | DJNZ DecodeSprites_NextSprite | Loop back until every sprite has been decoded. | ||
| 40029 | RET | Return. | ||
| Prev: 39950 | Up: Map | Next: 40030 |