![]() |
Routines |
| Prev: 55044 | Up: Map | Next: 55168 |
|
Used by the routines at PrintLivesGraphic, PrintSprites, DisplayObjectsCarried, DisplaySunMoonFrame and PrintTableSprite.
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 | 55064 | CALL GetSpriteAddress | Find the sprite. | |||||
| 55067 | LD A,(IX+26) | Fetch the pixel x position. | ||||||
| 55070 | AND %00000111 | Keep the bits of the position in the byte. | ||||||
| 55072 | JR Z,PrintSprite_Aligned | Jump to PrintSprite_Aligned if the sprite is on a byte boundary. | ||||||
|
Choose the page of the shift table.
|
||||||||
| 55074 | RLCA | Double it. | ||||||
| 55075 | AND %00001110 | Keep bits 1 to 3. | ||||||
| 55077 | OR %11110000 | Make it the page of the table of shifted bytes. | ||||||
| 55079 | LD H,A | Copy it to H. | ||||||
|
Fetch the width of the sprite, and move on to the height.
|
||||||||
| 55080 | LD A,(DE) | Fetch the width byte of the sprite. | ||||||
| 55081 | INC DE | Increment DE. | ||||||
| 55082 | AND %00000111 | Keep the width. | ||||||
| 55084 | INC A | Add one for the byte that the shifted sprite spills into. | ||||||
| 55085 | LD B,A | Copy it to B. | ||||||
| 55086 | LD (IX+24),A | Set the width in bytes of the object. | ||||||
| 55089 | DEC A | Take one off it to work out the number of pairs, less one. | ||||||
| 55090 | AND %00000111 | Keep bits 0 to 2. | ||||||
| 55092 | ADD A,A | Multiply it by sixteen, which is the size of the code for a pair. | ||||||
| 55093 | ADD A,A | |||||||
| 55094 | ADD A,A | |||||||
| 55095 | ADD A,A | |||||||
| 55096 | NEG | Negate it. | ||||||
| 55098 | ADD A,80 | Add 80. | ||||||
|
Change the jump and the step.
|
||||||||
| PrintSprite_Patch | 55100 | LD (55213),A | Change the offset of the jump into the unrolled code. | |||||
| 55103 | LD A,B | Fetch the width in bytes. | ||||||
| 55104 | CPL | Invert it. | ||||||
| 55105 | ADD A,34 | Add 34. | ||||||
| 55107 | LD (55297),A | Write it to 55297. | ||||||
|
Clip the sprite to the top of the screen.
|
||||||||
| 55110 | LD A,(DE) | Fetch the height of the sprite. | ||||||
| 55111 | INC DE | Increment DE. | ||||||
| 55112 | LD (IX+25),A | Set the height in lines of the object. | ||||||
| 55115 | ADD A,(IX+27) | Add the pixel y position. | ||||||
| 55118 | SUB 192 | Take the number of lines on the screen off it. | ||||||
| 55120 | JR C,PrintSprite_Draw | Jump to PrintSprite_Draw if the sprite does not go off the top of the screen. | ||||||
| 55122 | NEG | Make the number of lines that are off the screen positive. | ||||||
| 55124 | ADD A,(IX+25) | Take it off the height. | ||||||
| 55127 | LD (IX+25),A | Set the height in lines of the object. | ||||||
|
Draw the rows that are on the screen.
|
||||||||
| PrintSprite_Draw | 55130 | LD C,(IX+26) | Fetch the pixel x position. | |||||
| 55133 | LD B,(IX+27) | Fetch the pixel y position. | ||||||
| 55136 | CALL CalculateBufferAddress | Find the address in the screen buffer. | ||||||
| 55139 | LD (23465),SP | Set SavedStackPointer. | ||||||
| 55143 | EX DE,HL | Point the stack pointer at the data of the sprite. | ||||||
| 55144 | LD SP,HL | |||||||
| 55145 | EX DE,HL | |||||||
| 55146 | LD A,(IX+25) | Fetch the number of lines. | ||||||
| 55149 | JR DrawLines | Jump to DrawLines. | ||||||
|
The sprite is aligned, so the bytes do not need to be shifted.
|
||||||||
| PrintSprite_Aligned | 55151 | LD A,(DE) | Fetch the width byte of the sprite. | |||||
| 55152 | INC DE | Increment DE. | ||||||
| 55153 | AND %00001111 | Keep the width. | ||||||
| 55155 | LD (IX+24),A | Set the width in bytes of the object. | ||||||
| 55158 | LD B,A | Copy it to B. | ||||||
| 55159 | ADD A,A | Multiply it by eight, which is the size of the code for a column. | ||||||
| 55160 | ADD A,A | |||||||
| 55161 | ADD A,A | |||||||
| 55162 | NEG | Negate it. | ||||||
| 55164 | SUB 6 | Take 6 off it to get the offset from the end of the unrolled code. | ||||||
| 55166 | JR PrintSprite_Patch | Jump to PrintSprite_Patch. | ||||||
|
View the equivalent code in;
|
||||||||
| Prev: 55044 | Up: Map | Next: 55168 |