Prev: 30156 Up: Map Next: 30234
30160: Draw Sprite Rows
Used by the routines at SetUpPreviousSprite and DrawSprite.
Erases the previous sprite and draws the new one, one pixel row at a time, working up the screen from the bottom row. The main registers hold the previous sprite and the shadow registers hold the new sprite. A row of the previous sprite is cleared by ANDing the screen with the inverted sprite data. A row of the new sprite is ORed onto the screen.
The first pass handles the rows where only one of the two sprites has any data. The heights at 24080 and 24081 then give the rows both sprites have in common, which are done on the second pass.
Input
B Sprite width in bytes
C Number of rows left to process
DE Address into a sprite
HL Address in the screen buffer
MaskSprite 30160 LD A,C A=the number of rows left of the previous sprite.
30161 AND A Set the flags.
30162 JR Z,MaskSprite_NewOnly Jump to MaskSprite_NewOnly if there are no more rows of the previous sprite.
30164 DEC C Decrease the row counter by one.
30165 PUSH BC Stash the counter and the screen address on the stack.
30166 PUSH HL
Clear one row of the previous sprite from the screen.
MaskSprite_Erase 30167 LD A,(DE) Fetch a byte of the sprite.
30168 CPL Invert it.
30169 AND (HL) Remove the sprite pixels from the screen.
30170 LD (HL),A Write the result back to the screen.
30171 INC DE Move onto the next byte of the sprite.
30172 INC L Move onto the next column.
30173 DJNZ MaskSprite_Erase Decrease the width counter by one and loop back to MaskSprite_Erase until the whole row of the sprite has been erased.
30175 POP HL Restore the screen address from the stack.
30176 CALL ScreenPosition1PixelAbove Move up one pixel row.
30179 POP BC Restore the counter from the stack.
Switch to the new sprite.
MaskSprite_Draw 30180 EXX Switch to the shadow registers.
30181 LD A,C A=the number of rows left of the new sprite.
30182 AND A Set the flags.
30183 JR Z,MaskSprite_Next Jump to MaskSprite_Next if there are no more rows of the new sprite.
MaskSprite_Draw_Row 30185 DEC C Decrease the row counter by one.
30186 PUSH BC Stash the counter and the screen address on the stack.
30187 PUSH HL
Draw one row of the new sprite onto the screen.
MaskSprite_Draw_Loop 30188 LD A,(DE) Fetch a byte of the sprite.
30189 OR (HL) Combine it with the screen.
30190 LD (HL),A Write the result back to the screen.
30191 INC DE Move onto the next byte of the sprite.
30192 INC L Move onto the next column.
30193 DJNZ MaskSprite_Draw_Loop Decrease the width counter by one and loop back to MaskSprite_Draw_Loop until the whole row of the sprite has been drawn.
30195 POP HL Restore the screen address from the stack.
30196 CALL ScreenPosition1PixelAbove Move up one pixel row.
30199 POP BC Restore the counter from the stack.
MaskSprite_Next 30200 EXX Switch back to the previous sprite.
30201 JR MaskSprite Jump back to MaskSprite to do the next pair of rows.
There are no more rows of the previous sprite, so only the new sprite is left to draw.
MaskSprite_NewOnly 30203 EXX Switch to the new sprite.
30204 LD A,C A=the number of rows left of the new sprite.
30205 AND A Set the flags.
30206 JR NZ,MaskSprite_Draw_Row Jump to MaskSprite_Draw_Row if there are rows to draw.
This entry point is used by the routine at SetUpPreviousSprite.
Both sprites have been drawn as far as their rows go.
MaskSprite_Finish 30208 EXX Switch back to the previous sprite.
This entry point is used by the routine at SetUpPreviousSprite.
MaskSprite_Finish_Previous 30209 LD A,(24080) Fetch the remaining row count of the previous sprite from 24080 and keep it in C.
30212 LD C,A
30213 LD A,(24081) Fetch the remaining row count of the new sprite from 24081.
30216 OR C Combine them.
30217 RET Z Return if there are no rows left on either sprite.
30218 XOR A Clear 24080 so that it is only used once.
30219 LD (24080),A
30222 EXX Switch to the new sprite.
30223 LD A,(24081) Fetch the remaining row count from 24081 and keep the remaining row count of the new sprite in C.
30226 LD C,A
30227 XOR A A=0.
This entry point is used by the routine at SetUpPreviousSprite.
MaskSprite_Finish_ClearNew 30228 LD (24081),A Write 0 to 24081 so that it is only used once.
30231 EXX Switch back to the previous sprite.
30232 JR MaskSprite Jump to MaskSprite to process the rows both sprites have.
Prev: 30156 Up: Map Next: 30234