Prev: EEA6 Up: Map Next: F001
EED7: Print Shifted Sprite
Copies the blank tiles from Graphics_MaskSprite into Working_Shift_Buffer, bit-rotates the sprite into that buffer by its sub-cell offsets, then prints the result. Clone of GoldfishGame_PrintShiftedSprite.
Input
IX Sprite data
Clear the working shift buffer to blank tiles.
PrintShiftedSprite EED7 LD DE,$A0EC Copy 80 blank tiles from Graphics_MaskSprite to Working_Shift_Buffer.
EEDA LD HL,$A06C
EEDD LD BC,$0080
EEE0 LDIR
Set the print colour and keep the current character set.
EEE2 LD A,$10 Set INK from the sprite attribute.
EEE4 RST $10
EEE5 LD A,(IX+$09)
EEE8 RST $10
EEE9 LD HL,($5C36) HL=*CHARS.
EEEC PUSH HL Stash the character set, IY and the sprite slot on the stack.
EEED PUSH IY
EEEF PUSH IX
Point HL at this frame's source UDGs.
EEF1 LD E,(IX+$06) DE=the sprite frame ID*08.
EEF4 LD D,$00
EEF6 SLA E
EEF8 RL D
EEFA SLA E
EEFC RL D
EEFE SLA E
EF00 RL D
EF02 ADD HL,DE Add that offset to the current character set.
Count how many bit-pairs to rotate (horizontal offset+01).
EF03 LD B,(IX+$02) Write the pixel-shift count to *SpritePixelShift.
EF06 INC B
EF07 LD C,$00
EF09 LD ($F332),BC
Fetch the sprite size.
EF0D LD E,(IX+$07) E=the sprite width.
EF10 LD D,(IX+$08) D=the sprite height.
Point IY one character column beyond the sprite so the bits rotated out of the current column land in the next one.
EF13 LD A,D Point IY at the overflow column in the shift buffer.
EF14 INC A
EF15 SLA A
EF17 SLA A
EF19 SLA A
EF1B LD C,A
EF1C LD B,$00
EF1E LD IY,$A0F4
EF22 ADD IY,BC
Byte width of one source pixel-row, for stepping HL.
EF24 LD C,E Write the source row stride to *SpriteShiftWidth.
EF25 SLA C
EF27 SLA C
EF29 SLA C
EF2B LD B,$00
EF2D LD ($F33C),BC
EF31 LD IX,$A0F4 IX=Working_Shift_Output.
For each source column, rotate 08 pixel rows into the current and next buffer columns.
PrintShiftedSprite_ColumnLoop EF35 PUSH HL Stash the source-column pointer and the remaining size on the stack.
EF36 PUSH DE
PrintShiftedSprite_RowLoop EF37 PUSH HL Stash the source pointer on the stack.
EF38 LD B,$08 B=08 (pixel rows).
PrintShiftedSprite_CopyLoop EF3A PUSH BC Stash the pixel-row counter on the stack.
EF3B LD A,(HL) Fetch the source byte and the pixel-shift count.
EF3C LD BC,($F332)
Rotate two pixels per pass into the overflow byte.
PrintShiftedSprite_ShiftLoop EF40 SLA A Shift two pixels from the source byte into the overflow byte.
EF42 RL C
EF44 SLA A
EF46 RL C
EF48 DJNZ PrintShiftedSprite_ShiftLoop Decrease the shift count and loop back to PrintShiftedSprite_ShiftLoop until the rotation is complete.
EF4A LD (IY+$00),A Write the overflow pixels to the next column.
EF4D LD A,C Merge the shifted pixels into the current column.
EF4E OR (IX+$00)
EF51 LD (IX+$00),A
EF54 INC HL Advance the source and both column pointers.
EF55 INC IX
EF57 INC IY
EF59 POP BC Restore the pixel-row counter from the stack.
EF5A DJNZ PrintShiftedSprite_CopyLoop Decrease the pixel-row counter and loop back to PrintShiftedSprite_CopyLoop until all 08 rows are copied.
EF5C POP HL Restore the source pointer from the stack.
EF5D LD BC,($F33C) Advance it by one sprite row and loop back to PrintShiftedSprite_RowLoop until every character row is done.
EF61 ADD HL,BC
EF62 DEC D
EF63 JR NZ,PrintShiftedSprite_RowLoop
EF65 POP DE Restore the remaining size from the stack.
EF66 LD BC,$0008 Step both buffer pointers on to the next character column.
EF69 ADD IX,BC
EF6B ADD IY,BC
EF6D POP HL Restore the source-column pointer from the stack.
EF6E ADD HL,BC Step it on and loop back to PrintShiftedSprite_ColumnLoop until every column is done.
EF6F DEC E
EF70 JR NZ,PrintShiftedSprite_ColumnLoop
Character 20 is 0100 bytes after Graphics_GoldfishGamePlayer, which lands on Working_Shift_Buffer. Add twice the vertical offset plus 02 so printing starts on the correct scanline.
EF72 LD HL,$9FEC HL=Graphics_GoldfishGamePlayer.
EF75 POP IX Restore the sprite slot from the stack.
EF77 LD A,(IX+$03) Point the character set at the working buffer, offset by the vertical sub-cell position.
EF7A INC A
EF7B SLA A
EF7D LD E,A
EF7E LD D,$00
EF80 ADD HL,DE
EF81 LD ($5C36),HL
Print one extra column or row unless the sprite is already on the last sub-cell (03).
EF84 LD D,(IX+$08) DE=the sprite height and width.
EF87 LD E,(IX+$07)
EF8A LD A,(IX+$02) Jump to PrintShiftedSprite_AdjustRow if the horizontal offset is already 03.
EF8D CP $03
EF8F JR Z,PrintShiftedSprite_AdjustRow
EF91 INC E Add one extra printed column.
PrintShiftedSprite_AdjustRow EF92 INC D Add one extra printed row.
EF93 LD A,D Store the tile-to-tile character step in *SpriteShiftRow.
EF94 LD ($F33E),A
EF97 LD A,$03 Jump to PrintShiftedSprite_LoadHeight if the vertical offset is not 03.
EF99 CP (IX+$03)
EF9C JR NZ,PrintShiftedSprite_LoadHeight
EF9E DEC D Keep the original printed height (no extra row).
PrintShiftedSprite_LoadHeight EF9F LD B,(IX+$01) BC=the sprite row and column.
EFA2 LD C,(IX+$00)
EFA5 LD A,D This load is unused; the next instruction overwrites A.
EFA6 LD A,$20 A=20 (first shifted-buffer character).
EFA8 POP IY Restore IY from the stack.
EFAA LD A,$20 A=20 (first shifted-buffer character).
Print the shifted buffer row by row.
PrintShiftedSprite_PrintRow EFAC PUSH AF Stash the character code, remaining size and print position on the stack.
EFAD PUSH DE
EFAE PUSH BC
EFAF LD D,A D=the starting character code.
EFB0 LD A,C Jump to PrintShiftedSprite_NextRow if the print column is off the left of the screen.
EFB1 CP $22
EFB3 JR NC,PrintShiftedSprite_NextRow
PrintShiftedSprite_PrintTile EFB5 PUSH DE Stash the character code and remaining width on the stack.
Set the co-ordinates of where we're going to PRINT AT.
EFB6 CALL $0DD9 Call CL_SET.
EFB9 POP DE Restore the character code, remaining width and print position from the stack.
EFBA POP BC
EFBB PUSH BC Stash the print position on the stack.
EFBC LD A,D A=the character code.
PrintShiftedSprite_PrintTileLoop EFBD CALL PrintColourCharacter Print this colour character using PrintColourCharacter.
EFC0 LD A,C Call PrintShiftedSprite_SkipColumn if the print column is the right-edge column (02).
EFC1 CP $02
EFC3 CALL Z,PrintShiftedSprite_SkipColumn
EFC6 DEC C Move one column right.
EFC7 LD A,($F33E) Advance the character code by one printed column.
EFCA ADD A,D
EFCB LD D,A
EFCC DEC E Decrease the remaining width and loop back to PrintShiftedSprite_PrintTileLoop until this row is done.
EFCD JR NZ,PrintShiftedSprite_PrintTileLoop
EFCF POP BC Restore the print position, remaining size and character code from the stack.
EFD0 POP DE
EFD1 POP AF
EFD2 DEC B Move one row down.
EFD3 INC A Advance the starting character code.
EFD4 DEC D Decrease the remaining printed height and loop back to PrintShiftedSprite_PrintRow until every row is printed.
EFD5 JR NZ,PrintShiftedSprite_PrintRow
Restore the original character set and return.
PrintShiftedSprite_RestoreSource EFD7 POP HL Restore the original character set pointer from the stack.
EFD8 LD ($5C36),HL Write it back to *CHARS.
EFDB RET Return.
The print column has reached the right-hand screen edge; skip the rest of this row.
PrintShiftedSprite_SkipColumn EFDC DEC E Return if this was the last tile in the row.
EFDD PUSH AF
EFDE INC E
EFDF POP AF
EFE0 RET Z
EFE1 DEC E Skip one remaining tile and loop back to PrintShiftedSprite_SkipColumn.
EFE2 LD A,($F33E)
EFE5 ADD A,D
EFE6 LD D,A
EFE7 JR PrintShiftedSprite_SkipColumn
The print column is off the left of the screen; skip tiles until it is back on-screen.
PrintShiftedSprite_NextRow EFE9 LD A,($F33E) Advance the character code and consume one tile.
EFEC ADD A,D
EFED LD D,A
EFEE DEC E
EFEF JP Z,PrintShiftedSprite_RestoreRegisters Jump to PrintShiftedSprite_RestoreRegisters if no tiles remain.
EFF2 DEC C Move one column right.
EFF3 LD A,C Jump to PrintShiftedSprite_NextRow if the print column is still off the left.
EFF4 CP $22
EFF6 JR NC,PrintShiftedSprite_NextRow
EFF8 JP PrintShiftedSprite_PrintTile Jump to PrintShiftedSprite_PrintTile.
Discard the stacked print state and restore the character set.
PrintShiftedSprite_RestoreRegisters EFFB POP BC Discard the stacked character code, size and print position.
EFFC POP BC
EFFD POP BC
EFFE JP PrintShiftedSprite_RestoreSource Jump to PrintShiftedSprite_RestoreSource.
Prev: EEA6 Up: Map Next: F001