![]() |
Routines |
| Prev: 46134 | Up: Map | Next: 46272 |
|
Used by the routine at DrawEntityItem.
Draws the sprite of an entity into the screen buffer, which is 24 bytes wide. The sprite data is read by using the stack pointer, and the sprite is drawn by one of the row routines in the table at RowRoutineTable, which is chosen using the width of the sprite and whether it is shifted by the low bits of the column. The addresses of the row routine and the step to the previous row are written into the drawing code before it is entered. If the sprite goes beyond the top of the screen buffer, the rows that are not needed are skipped.
|
||||||||
| DrawSprite | 46140 | CALL FindSpriteFrame | Find the sprite. | |||||
| 46143 | LD A,(IX+22) | Read the width byte. | ||||||
| 46146 | AND %11110000 | Use the countdown nibble. | ||||||
| 46148 | CALL NZ,BuildPatternedSprite | Build a patterned copy when that nibble is set. | ||||||
| 46151 | LD (23770),SP | Remember the stack pointer. | ||||||
| 46155 | LD HL,44519 | Use the row-routine table. | ||||||
| 46158 | LD A,(IX+14) | Read the column. | ||||||
| 46161 | AND %00000110 | Use bits 1-2 as the shift. | ||||||
| 46163 | LD C,A | Keep the shift. | ||||||
| 46164 | LD A,(DE) | Read the sprite's width. | ||||||
| 46165 | LD (46247),A | Give the width to the skip loop. | ||||||
| 46168 | LD B,A | Keep the width. | ||||||
| 46169 | JR Z,DrawSprite_Index | A shifted sprite uses the next routine and one more byte. | ||||||
| 46171 | ADD A,4 | |||||||
| 46173 | INC B | |||||||
| DrawSprite_Index | 46174 | ADD A,A | Double the width to make a table index. | |||||
| 46175 | CALL AddToAddress | Look the row routine up. | ||||||
| 46178 | LD A,(HL) | Read the routine's address. | ||||||
| 46179 | INC HL | |||||||
| 46180 | LD H,(HL) | |||||||
| 46181 | LD L,A | |||||||
| 46182 | LD (46266),HL | Give the routine and the row step to the drawers. | ||||||
| 46185 | LD (46270),HL | |||||||
| 46188 | LD (46305),HL | |||||||
| 46191 | LD (46388),HL | |||||||
| 46194 | LD (46393),HL | |||||||
| 46197 | INC DE | Move on to the sprite data. | ||||||
| 46198 | LD A,B | The step back across a row is the width plus 23. | ||||||
| 46199 | ADD A,23 | |||||||
| 46201 | LD (46384),A | |||||||
| 46204 | NEG | The other step is the opposite of that width. | ||||||
| 46206 | LD (46300),A | |||||||
| 46209 | LD L,(IX+24) | Fetch the screen address. | ||||||
| 46212 | LD H,(IX+25) | |||||||
| 46215 | EX DE,HL | Keep the sprite address aside. | ||||||
| 46216 | LD A,(HL) | Read how many rows the sprite has. | ||||||
| 46217 | LD B,A | |||||||
| 46218 | EX AF,AF' | Remember that count. | ||||||
| 46219 | LD A,(IX+15) | The first row to draw is one past the entity's row. | ||||||
| 46222 | INC A | |||||||
| 46223 | INC HL | Read the sprite through the stack. | ||||||
| 46224 | LD SP,HL | |||||||
| 46225 | CP B | Clip the sprite when its rows end above the view. | ||||||
| 46226 | JP NC,DrawSprite_Clip | |||||||
| 46229 | LD B,A | The row count is that first row. | ||||||
| 46230 | EX AF,AF' | Bring the sprite's row count back. | ||||||
| 46231 | JP DrawSprite_2 | Draw the sprite. | ||||||
| DrawSprite_Clip | 46234 | SUB 128 | A count below 128 is drawn whole. | |||||
| 46236 | JP C,DrawSprite_2 | |||||||
| 46239 | JP Z,DrawSprite_2 | A count of exactly 128 is drawn whole. | ||||||
| 46242 | LD B,A | The rows above the view are the excess. | ||||||
| 46243 | EX AF,AF' | Bring the sprite's row count back. | ||||||
| 46244 | SUB B | Drop the rows that are off the view. | ||||||
| 46245 | EX AF,AF' | |||||||
| DrawSprite_0 | 46246 | LD B,0 | Skip one row of the sprite. | |||||
| DrawSprite_1 | 46248 | POP HL | Skip the bytes of that row. | |||||
| 46249 | DJNZ DrawSprite_1 | |||||||
| 46251 | DEC A | Repeat for the remaining rows above the view. | ||||||
| 46252 | JR NZ,DrawSprite_0 | |||||||
| 46254 | EX AF,AF' | Bring the rows that are in view back. | ||||||
| 46255 | LD B,A | Use that as the row count. | ||||||
| 46256 | EX AF,AF' | |||||||
| DrawSprite_2 | 46257 | LD A,C | Read the shift. | |||||
| 46258 | AND A | An unshifted sprite is drawn directly. | ||||||
| 46259 | JR Z,DrawSprite_4 | |||||||
| 46261 | ADD A,248 | A shifted sprite uses the page selected by the shift. | ||||||
| 46263 | LD H,A | |||||||
| 46264 | LD A,(DE) | |||||||
| DrawSprite_3 | 46265 | JP DrawSprite_3 | Draw the shifted rows. The target is patched. | |||||
| DrawSprite_4 | 46268 | EX DE,HL | Put the screen address in HL. | |||||
| DrawSprite_5 | 46269 | JP DrawSprite_5 | Draw the unshifted rows. The target is patched. | |||||
| Prev: 46134 | Up: Map | Next: 46272 |