![]() |
Routines |
| Prev: 53267 | Up: Map | Next: 53391 |
|
Draws the sprite of an object into ScreenBuffer, at the pixel position of the object. A sprite has a width byte (the vertical flip in bit 7, the horizontal flip in bit 6 and the width in columns in the low bits), a height byte, and then the data for each line from the top. Each column of a line is a pair of bytes: a mask byte, then a data byte. The mask clears the bits of the background and the data sets bits. A sprite that does not start on a byte boundary has each pair shifted across two bytes of the buffer, with the tables built by BuildLookupTables. The routine copies the sprite with unrolled code, which it enters part of the way along, so that it does as many columns as the sprite has. To do this it changes the code, and it uses the stack pointer to read the data of the sprite.
|
||||||||
|
Find the sprite and choose the draw path.
|
||||||||
| PrintSprite | 53287 | CALL GetSpriteAddress | Call GetSpriteAddress. | |||||
| 53290 | LD A,(IX+26) | Fetch the pixel x position. | ||||||
| 53293 | AND %00000111 | Keep bits 0 to 2. | ||||||
| 53295 | JR Z,PrintSprite_Aligned | Jump to PrintSprite_Aligned if it is zero. | ||||||
|
Choose the page of the shift table.
|
||||||||
| 53297 | RLCA | Double it. | ||||||
| 53298 | AND %00001110 | Keep bits 1 to 3. | ||||||
| 53300 | OR %11110000 | Set bits 4 to 7. | ||||||
| 53302 | LD H,A | Copy it to H. | ||||||
| 53303 | LD A,(DE) | Fetch the width byte of the sprite. | ||||||
| 53304 | INC DE | Increment DE. | ||||||
| 53305 | AND %00000111 | Keep bits 0 to 2. | ||||||
| 53307 | INC A | Increment A. | ||||||
| 53308 | LD B,A | Copy it to B. | ||||||
| 53309 | LD (IX+24),A | Set the width in bytes of the object. | ||||||
| 53312 | DEC A | Decrement A. | ||||||
| 53313 | AND %00000111 | Keep bits 0 to 2. | ||||||
| 53315 | ADD A,A | Multiply it by sixteen. | ||||||
| 53316 | ADD A,A | |||||||
| 53317 | ADD A,A | |||||||
| 53318 | ADD A,A | |||||||
| 53319 | NEG | Negate it. | ||||||
| 53321 | ADD A,80 | Add 80. | ||||||
|
Change the jump and the step.
|
||||||||
| PrintSprite_Patch | 53323 | LD (53436),A | Write it to 53436. | |||||
| 53326 | LD A,B | Fetch B. | ||||||
| 53327 | CPL | Invert it. | ||||||
| 53328 | ADD A,34 | Add 34. | ||||||
| 53330 | LD (53520),A | Write it to 53520. | ||||||
|
Clip the sprite to the top of the screen.
|
||||||||
| 53333 | LD A,(DE) | Fetch the height of the sprite. | ||||||
| 53334 | INC DE | Increment DE. | ||||||
| 53335 | LD (IX+25),A | Set the height in lines of the object. | ||||||
| 53338 | ADD A,(IX+27) | Add the pixel y position. | ||||||
| 53341 | SUB 192 | Subtract 192. | ||||||
| 53343 | JR C,PrintSprite_Draw | Jump to PrintSprite_Draw if carry is set. | ||||||
| 53345 | NEG | Negate A. | ||||||
| 53347 | ADD A,(IX+25) | Add the height in lines. | ||||||
| 53350 | LD (IX+25),A | Set the height in lines of the object. | ||||||
|
Draw the rows that are on the screen.
|
||||||||
| PrintSprite_Draw | 53353 | LD C,(IX+26) | Fetch the pixel x position. | |||||
| 53356 | LD B,(IX+27) | Fetch the pixel y position. | ||||||
| 53359 | CALL CalculateBufferAddress | Call CalculateBufferAddress. | ||||||
| 53362 | LD (23305),SP | Set SavedStackPointer. | ||||||
| 53366 | EX DE,HL | Point the stack at the sprite data. | ||||||
| 53367 | LD SP,HL | |||||||
| 53368 | EX DE,HL | |||||||
| 53369 | LD A,(IX+25) | Fetch the number of lines. | ||||||
| 53372 | JR DrawLines | Jump to DrawLines. | ||||||
|
The sprite is aligned, so the bytes do not need to be shifted.
|
||||||||
| PrintSprite_Aligned | 53374 | LD A,(DE) | Fetch the width byte of the sprite. | |||||
| 53375 | INC DE | Increment DE. | ||||||
| 53376 | AND %00001111 | Keep bits 0 to 3. | ||||||
| 53378 | LD (IX+24),A | Set the width in bytes of the object. | ||||||
| 53381 | LD B,A | Copy it to B. | ||||||
| 53382 | ADD A,A | Multiply it by eight. | ||||||
| 53383 | ADD A,A | |||||||
| 53384 | ADD A,A | |||||||
| 53385 | NEG | Negate it. | ||||||
| 53387 | SUB 6 | Subtract 6. | ||||||
| 53389 | JR PrintSprite_Patch | Jump to PrintSprite_Patch. | ||||||
|
View the equivalent code in;
|
||||||||
| Prev: 53267 | Up: Map | Next: 53391 |