Prev: 716D Up: Map Next: 71BC
7170: Mask Sprite
Erases the old sprite and draws the new sprite, a line at a time going up the screen. One line of the old sprite is erased by clearing its bits from the screen, then one line of the new sprite is drawn, and so on until both are done. The old sprite is held in the normal registers and the new sprite in the shadow registers. In each set C holds the number of lines left, DE the sprite data and HL the screen address.
Before After
mask-sprite-before mask-sprite-after
MaskSprite 7170 LD A,C Jump to ActorUpdateSizeNext if there are no more lines of the old sprite.
7171 AND A
7172 JR Z,ActorUpdateSizeNext
7174 DEC C Decrease the number of lines left by one.
7175 PUSH HL Stash the screen address on the stack.
7176 LD A,($5E40) Fetch the number of pixels to shift by (OldSpriteShift) and keep the pixel shift in B.
7179 LD B,A
717A EX DE,HL HL=sprite data and DE=screen address.
717B PUSH DE Stash the screen address on the stack.
717C LD D,(HL) D=the first byte of this line of the sprite.
717D INC HL Increment the sprite data pointer by one.
717E LD E,(HL) E=the second byte of this line of the sprite.
717F INC HL Increment the sprite data pointer by one.
7180 AND A Jump to MaskSprite_Unshifted if the sprite is not shifted.
7181 JR Z,MaskSprite_Unshifted
7183 EX DE,HL HL=sprite data and DE=this line of the sprite.
7184 XOR A A=00.
MaskSprite_ShiftErase 7185 ADD HL,HL Shift the line of the sprite left.
7186 ADC A,A Rotate the bit that was shifted out into A.
7187 DJNZ MaskSprite_ShiftErase Decrease counter by one and loop back to MaskSprite_ShiftErase until counter is zero.
7189 EX DE,HL DE=the shifted line of the sprite and HL=sprite data.
718A EX (SP),HL HL=screen address (the sprite data pointer goes on the stack).
718B CPL Invert the bits of the first byte of the line.
718C AND (HL) Remove the bits from the screen.
718D LD (HL),A Write the byte back to the screen.
718E INC L Move onto the next screen byte.
This entry point is used by the routine at MaskSprite_Unshifted.
MaskSprite_EraseBytes 718F LD A,D A=D.
7190 CPL Invert the bits.
7191 AND (HL) Remove the bits from the screen.
7192 LD (HL),A Write the byte back to the screen.
7193 INC L Move onto the next screen byte.
7194 LD A,E A=E.
7195 CPL Invert the bits.
7196 AND (HL) Remove the bits from the screen.
7197 LD (HL),A Write the byte back to the screen.
7198 POP DE Restore the sprite data pointer from the stack.
7199 POP HL Restore the screen address of the start of the line from the stack.
719A CALL ScreenPosition1PixelAbove Call ScreenPosition1PixelAbove to move up a line.
Now draw one line of the new sprite.
719D EXX Switch to the shadow registers (the new sprite).
719E LD A,C A=C.
719F AND A Jump to MaskSprite_Next if there are no more lines of the new sprite.
71A0 JR Z,MaskSprite_Next
This entry point is used by the routine at ActorUpdateSizeNext.
MaskSprite_Draw 71A2 DEC C Decrease the number of lines left by one.
71A3 PUSH HL Stash the screen address on the stack.
71A4 LD A,($5E41) Fetch the number of pixels to shift by (NewSpriteShift) and keep the pixel shift in B.
71A7 LD B,A
71A8 EX DE,HL HL=sprite data and DE=screen address.
71A9 PUSH DE Stash the screen address on the stack.
71AA LD D,(HL) D=the first byte of this line of the sprite.
71AB INC HL Increment the sprite data pointer by one.
71AC LD E,(HL) E=the second byte of this line of the sprite.
71AD INC HL Increment the sprite data pointer by one.
71AE AND A Jump to MaskSprite_DrawUnshifted if the sprite is not shifted.
71AF JR Z,MaskSprite_DrawUnshifted
71B1 EX DE,HL HL=sprite data and DE=this line of the sprite.
71B2 XOR A A=00.
MaskSprite_ShiftDraw 71B3 ADD HL,HL Shift the line of the sprite left.
71B4 ADC A,A Rotate the bit that was shifted out into A.
71B5 DJNZ MaskSprite_ShiftDraw Decrease counter by one and loop back to MaskSprite_ShiftDraw until counter is zero.
71B7 EX DE,HL DE=the shifted line of the sprite and HL=sprite data.
71B8 EX (SP),HL HL=screen address (the sprite data pointer goes on the stack).
71B9 OR (HL) Merge the first byte of the line with the screen.
71BA LD (HL),A Write the byte back to the screen.
71BB INC L Move onto the next screen byte.
View the equivalent code in;
Prev: 716D Up: Map Next: 71BC