Prev: D616 Up: Map Next: D771
D647: Goldfish Game: Print Shifted Sprite
Used by the routines at GoldfishGame_UpdatePlayer and Handler_SeaCreatures.
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 used in the main game is at PrintShiftedSprite.
Input
IX Sprite data
Clear the working shift buffer to blank tiles.
GoldfishGame_PrintShiftedSprite D647 LD DE,$A0EC Copy 80 blank tiles from Graphics_MaskSprite to Working_Shift_Buffer.
D64A LD HL,$A06C
D64D LD BC,$0080
D650 LDIR
Set the print colour and keep the current character set.
D652 LD A,$10 Set INK from the sprite attribute.
D654 RST $10
D655 LD A,(IX+$09)
D658 RST $10
D659 LD HL,($5C36) HL=*CHARS.
D65C PUSH HL Stash the character set, IY and the sprite slot on the stack.
D65D PUSH IY
D65F PUSH IX
Point HL at this frame's source UDGs.
D661 LD E,(IX+$06) DE=the sprite frame ID*08.
D664 LD D,$00
D666 SLA E
D668 RL D
D66A SLA E
D66C RL D
D66E SLA E
D670 RL D
D672 ADD HL,DE Add that offset to the current character set.
Count how many bit-pairs to rotate (horizontal offset+01).
D673 LD B,(IX+$02) Write the pixel-shift count to *GoldfishGame_SpriteShiftWork.
D676 INC B
D677 LD C,$00
D679 LD ($DB38),BC
Fetch the sprite size.
D67D LD E,(IX+$07) E=the sprite width.
D680 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.
D683 LD A,D Point IY at the overflow column in the shift buffer.
D684 INC A
D685 SLA A
D687 SLA A
D689 SLA A
D68B LD C,A
D68C LD B,$00
D68E LD IY,$A0F4
D692 ADD IY,BC
Byte width of one source pixel-row, for stepping HL.
D694 LD C,E Write the source row stride to *GoldfishGame_SpriteRowStride.
D695 SLA C
D697 SLA C
D699 SLA C
D69B LD B,$00
D69D LD ($DB36),BC
D6A1 LD IX,$A0F4 IX=Working_Shift_Output.
For each source column, rotate 08 pixel rows into the current and next buffer columns.
GoldfishGame_PrintShiftedSprite_ColumnLoop D6A5 PUSH HL Stash the source-column pointer and the remaining size on the stack.
D6A6 PUSH DE
GoldfishGame_PrintShiftedSprite_RowLoop D6A7 PUSH HL Stash the source pointer on the stack.
D6A8 LD B,$08 B=08 (pixel rows).
GoldfishGame_PrintShiftedSprite_CopyLoop D6AA PUSH BC Stash the pixel-row counter on the stack.
D6AB LD A,(HL) Fetch the source byte and the pixel-shift count.
D6AC LD BC,($DB38)
Rotate two pixels per pass into the overflow byte.
GoldfishGame_PrintShiftedSprite_ShiftLoop D6B0 SLA A Shift two pixels from the source byte into the overflow byte.
D6B2 RL C
D6B4 SLA A
D6B6 RL C
D6B8 DJNZ GoldfishGame_PrintShiftedSprite_ShiftLoop Decrease the shift count and loop back to GoldfishGame_PrintShiftedSprite_ShiftLoop until the rotation is complete.
D6BA LD (IY+$00),A Write the overflow pixels to the next column.
D6BD LD A,C Merge the shifted pixels into the current column.
D6BE OR (IX+$00)
D6C1 LD (IX+$00),A
D6C4 INC HL Advance the source and both column pointers.
D6C5 INC IX
D6C7 INC IY
D6C9 POP BC Restore the pixel-row counter from the stack.
D6CA DJNZ GoldfishGame_PrintShiftedSprite_CopyLoop Decrease the pixel-row counter and loop back to GoldfishGame_PrintShiftedSprite_CopyLoop until all 08 rows are copied.
D6CC POP HL Restore the source pointer from the stack.
D6CD LD BC,($DB36) Advance it by one sprite row and loop back to GoldfishGame_PrintShiftedSprite_RowLoop until every character row is done.
D6D1 ADD HL,BC
D6D2 DEC D
D6D3 JR NZ,GoldfishGame_PrintShiftedSprite_RowLoop
D6D5 POP DE Restore the remaining size from the stack.
D6D6 LD BC,$0008 Step both buffer pointers on to the next character column.
D6D9 ADD IX,BC
D6DB ADD IY,BC
D6DD POP HL Restore the source-column pointer from the stack.
D6DE ADD HL,BC Step it on and loop back to GoldfishGame_PrintShiftedSprite_ColumnLoop until every column is done.
D6DF DEC E
D6E0 JR NZ,GoldfishGame_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.
D6E2 LD HL,$9FEC HL=Graphics_GoldfishGamePlayer.
D6E5 POP IX Restore the sprite slot from the stack.
D6E7 LD A,(IX+$03) Point the character set at the working buffer, offset by the vertical sub-cell position.
D6EA INC A
D6EB SLA A
D6ED LD E,A
D6EE LD D,$00
D6F0 ADD HL,DE
D6F1 LD ($5C36),HL
Print one extra column or row unless the sprite is already on the last sub-cell (03).
D6F4 LD D,(IX+$08) DE=the sprite height and width.
D6F7 LD E,(IX+$07)
D6FA LD A,(IX+$02) Jump to GoldfishGame_PrintShiftedSprite_AdjustRow if the horizontal offset is already 03.
D6FD CP $03
D6FF JR Z,GoldfishGame_PrintShiftedSprite_AdjustRow
D701 INC E Add one extra printed column.
GoldfishGame_PrintShiftedSprite_AdjustRow D702 INC D Add one extra printed row.
D703 LD A,D Store the tile-to-tile character step in *GoldfishGame_SpriteShiftWork.
D704 LD ($DB38),A
D707 LD A,$03 Jump to GoldfishGame_PrintShiftedSprite_LoadHeight if the vertical offset is not 03.
D709 CP (IX+$03)
D70C JR NZ,GoldfishGame_PrintShiftedSprite_LoadHeight
D70E DEC D Keep the original printed height (no extra row).
GoldfishGame_PrintShiftedSprite_LoadHeight D70F LD B,(IX+$01) BC=the sprite row and column.
D712 LD C,(IX+$00)
D715 LD A,D This load is unused; the next instruction overwrites A.
D716 LD A,$20 A=20 (first shifted-buffer character).
D718 POP IY Restore IY from the stack.
D71A LD A,$20 A=20 (first shifted-buffer character).
Print the shifted buffer row by row.
GoldfishGame_PrintShiftedSprite_PrintRow D71C PUSH AF Stash the character code, remaining size and print position on the stack.
D71D PUSH DE
D71E PUSH BC
D71F LD D,A D=the starting character code.
D720 LD A,C Jump to GoldfishGame_PrintShiftedSprite_NextRow if the print column is off the left of the screen.
D721 CP $22
D723 JR NC,GoldfishGame_PrintShiftedSprite_NextRow
GoldfishGame_PrintShiftedSprite_PrintTile D725 PUSH DE Stash the character code and remaining width on the stack.
Set the co-ordinates of where we're going to PRINT AT.
D726 CALL $0DD9 Call CL_SET.
D729 POP DE Restore the character code, remaining width and print position from the stack.
D72A POP BC
D72B PUSH BC Stash the print position on the stack.
D72C LD A,D A=the character code.
GoldfishGame_PrintShiftedSprite_PrintTileLoop D72D CALL GoldfishGame_PrintColourUDG Print this colour UDG using GoldfishGame_PrintColourUDG.
D730 LD A,C Call GoldfishGame_PrintShiftedSprite_SkipColumn if the print column is the right-edge column (02).
D731 CP $02
D733 CALL Z,GoldfishGame_PrintShiftedSprite_SkipColumn
D736 DEC C Move one column right.
D737 LD A,($DB38) Advance the character code by one printed column.
D73A ADD A,D
D73B LD D,A
D73C DEC E Decrease the remaining width and loop back to GoldfishGame_PrintShiftedSprite_PrintTileLoop until this row is done.
D73D JR NZ,GoldfishGame_PrintShiftedSprite_PrintTileLoop
D73F POP BC Restore the print position, remaining size and character code from the stack.
D740 POP DE
D741 POP AF
D742 DEC B Move one row down.
D743 INC A Advance the starting character code.
D744 DEC D Decrease the remaining printed height and loop back to GoldfishGame_PrintShiftedSprite_PrintRow until every row is printed.
D745 JR NZ,GoldfishGame_PrintShiftedSprite_PrintRow
Restore the original character set and return.
GoldfishGame_PrintShiftedSprite_RestoreSource D747 POP HL Restore the original character set pointer from the stack.
D748 LD ($5C36),HL Write it back to *CHARS.
D74B RET Return.
The print column has reached the right-hand screen edge; skip the rest of this row.
GoldfishGame_PrintShiftedSprite_SkipColumn D74C DEC E Return if this was the last tile in the row.
D74D PUSH AF
D74E INC E
D74F POP AF
D750 RET Z
D751 DEC E Skip one remaining tile and loop back to GoldfishGame_PrintShiftedSprite_SkipColumn.
D752 LD A,($DB38)
D755 ADD A,D
D756 LD D,A
D757 JR GoldfishGame_PrintShiftedSprite_SkipColumn
The print column is off the left of the screen; skip tiles until it is back on-screen.
GoldfishGame_PrintShiftedSprite_NextRow D759 LD A,($DB38) Advance the character code and consume one tile.
D75C ADD A,D
D75D LD D,A
D75E DEC E
D75F JP Z,GoldfishGame_PrintShiftedSprite_RestoreRegisters Jump to GoldfishGame_PrintShiftedSprite_RestoreRegisters if no tiles remain.
D762 DEC C Move one column right.
D763 LD A,C Jump to GoldfishGame_PrintShiftedSprite_NextRow if the print column is still off the left.
D764 CP $22
D766 JR NC,GoldfishGame_PrintShiftedSprite_NextRow
D768 JP GoldfishGame_PrintShiftedSprite_PrintTile Jump to GoldfishGame_PrintShiftedSprite_PrintTile.
Discard the stacked print state and restore the character set.
GoldfishGame_PrintShiftedSprite_RestoreRegisters D76B POP BC Discard the stacked character code, size and print position.
D76C POP BC
D76D POP BC
D76E JP GoldfishGame_PrintShiftedSprite_RestoreSource Jump to GoldfishGame_PrintShiftedSprite_RestoreSource.
Prev: D616 Up: Map Next: D771