Prev: 29037 Up: Map Next: 29116
29040: 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 29040 LD A,C Jump to ActorUpdateSizeNext if there are no more lines of the old sprite.
29041 AND A
29042 JR Z,ActorUpdateSizeNext
29044 DEC C Decrease the number of lines left by one.
29045 PUSH HL Stash the screen address on the stack.
29046 LD A,(24128) Fetch the number of pixels to shift by (OldSpriteShift) and keep the pixel shift in B.
29049 LD B,A
29050 EX DE,HL HL=sprite data and DE=screen address.
29051 PUSH DE Stash the screen address on the stack.
29052 LD D,(HL) D=the first byte of this line of the sprite.
29053 INC HL Increment the sprite data pointer by one.
29054 LD E,(HL) E=the second byte of this line of the sprite.
29055 INC HL Increment the sprite data pointer by one.
29056 AND A Jump to MaskSprite_Unshifted if the sprite is not shifted.
29057 JR Z,MaskSprite_Unshifted
29059 EX DE,HL HL=sprite data and DE=this line of the sprite.
29060 XOR A A=0.
MaskSprite_ShiftErase 29061 ADD HL,HL Shift the line of the sprite left.
29062 ADC A,A Rotate the bit that was shifted out into A.
29063 DJNZ MaskSprite_ShiftErase Decrease counter by one and loop back to MaskSprite_ShiftErase until counter is zero.
29065 EX DE,HL DE=the shifted line of the sprite and HL=sprite data.
29066 EX (SP),HL HL=screen address (the sprite data pointer goes on the stack).
29067 CPL Invert the bits of the first byte of the line.
29068 AND (HL) Remove the bits from the screen.
29069 LD (HL),A Write the byte back to the screen.
29070 INC L Move onto the next screen byte.
This entry point is used by the routine at MaskSprite_Unshifted.
MaskSprite_EraseBytes 29071 LD A,D A=D.
29072 CPL Invert the bits.
29073 AND (HL) Remove the bits from the screen.
29074 LD (HL),A Write the byte back to the screen.
29075 INC L Move onto the next screen byte.
29076 LD A,E A=E.
29077 CPL Invert the bits.
29078 AND (HL) Remove the bits from the screen.
29079 LD (HL),A Write the byte back to the screen.
29080 POP DE Restore the sprite data pointer from the stack.
29081 POP HL Restore the screen address of the start of the line from the stack.
29082 CALL ScreenPosition1PixelAbove Call ScreenPosition1PixelAbove to move up a line.
Now draw one line of the new sprite.
29085 EXX Switch to the shadow registers (the new sprite).
29086 LD A,C A=C.
29087 AND A Jump to MaskSprite_Next if there are no more lines of the new sprite.
29088 JR Z,MaskSprite_Next
This entry point is used by the routine at ActorUpdateSizeNext.
MaskSprite_Draw 29090 DEC C Decrease the number of lines left by one.
29091 PUSH HL Stash the screen address on the stack.
29092 LD A,(24129) Fetch the number of pixels to shift by (NewSpriteShift) and keep the pixel shift in B.
29095 LD B,A
29096 EX DE,HL HL=sprite data and DE=screen address.
29097 PUSH DE Stash the screen address on the stack.
29098 LD D,(HL) D=the first byte of this line of the sprite.
29099 INC HL Increment the sprite data pointer by one.
29100 LD E,(HL) E=the second byte of this line of the sprite.
29101 INC HL Increment the sprite data pointer by one.
29102 AND A Jump to MaskSprite_DrawUnshifted if the sprite is not shifted.
29103 JR Z,MaskSprite_DrawUnshifted
29105 EX DE,HL HL=sprite data and DE=this line of the sprite.
29106 XOR A A=0.
MaskSprite_ShiftDraw 29107 ADD HL,HL Shift the line of the sprite left.
29108 ADC A,A Rotate the bit that was shifted out into A.
29109 DJNZ MaskSprite_ShiftDraw Decrease counter by one and loop back to MaskSprite_ShiftDraw until counter is zero.
29111 EX DE,HL DE=the shifted line of the sprite and HL=sprite data.
29112 EX (SP),HL HL=screen address (the sprite data pointer goes on the stack).
29113 OR (HL) Merge the first byte of the line with the screen.
29114 LD (HL),A Write the byte back to the screen.
29115 INC L Move onto the next screen byte.
View the equivalent code in;
Prev: 29037 Up: Map Next: 29116