Prev: 61094 Up: Map Next: 61441
61143: 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 61143 LD DE,41196 Copy 128 blank tiles from Graphics_MaskSprite to Working_Shift_Buffer.
61146 LD HL,41068
61149 LD BC,128
61152 LDIR
Set the print colour and keep the current character set.
61154 LD A,16 Set INK from the sprite attribute.
61156 RST 16
61157 LD A,(IX+9)
61160 RST 16
61161 LD HL,(23606) HL=*CHARS.
61164 PUSH HL Stash the character set, IY and the sprite slot on the stack.
61165 PUSH IY
61167 PUSH IX
Point HL at this frame's source UDGs.
61169 LD E,(IX+6) DE=the sprite frame ID*8.
61172 LD D,0
61174 SLA E
61176 RL D
61178 SLA E
61180 RL D
61182 SLA E
61184 RL D
61186 ADD HL,DE Add that offset to the current character set.
Count how many bit-pairs to rotate (horizontal offset+1).
61187 LD B,(IX+2) Write the pixel-shift count to *SpritePixelShift.
61190 INC B
61191 LD C,0
61193 LD (62258),BC
Fetch the sprite size.
61197 LD E,(IX+7) E=the sprite width.
61200 LD D,(IX+8) 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.
61203 LD A,D Point IY at the overflow column in the shift buffer.
61204 INC A
61205 SLA A
61207 SLA A
61209 SLA A
61211 LD C,A
61212 LD B,0
61214 LD IY,41204
61218 ADD IY,BC
Byte width of one source pixel-row, for stepping HL.
61220 LD C,E Write the source row stride to *SpriteShiftWidth.
61221 SLA C
61223 SLA C
61225 SLA C
61227 LD B,0
61229 LD (62268),BC
61233 LD IX,41204 IX=Working_Shift_Output.
For each source column, rotate 8 pixel rows into the current and next buffer columns.
PrintShiftedSprite_ColumnLoop 61237 PUSH HL Stash the source-column pointer and the remaining size on the stack.
61238 PUSH DE
PrintShiftedSprite_RowLoop 61239 PUSH HL Stash the source pointer on the stack.
61240 LD B,8 B=8 (pixel rows).
PrintShiftedSprite_CopyLoop 61242 PUSH BC Stash the pixel-row counter on the stack.
61243 LD A,(HL) Fetch the source byte and the pixel-shift count.
61244 LD BC,(62258)
Rotate two pixels per pass into the overflow byte.
PrintShiftedSprite_ShiftLoop 61248 SLA A Shift two pixels from the source byte into the overflow byte.
61250 RL C
61252 SLA A
61254 RL C
61256 DJNZ PrintShiftedSprite_ShiftLoop Decrease the shift count and loop back to PrintShiftedSprite_ShiftLoop until the rotation is complete.
61258 LD (IY+0),A Write the overflow pixels to the next column.
61261 LD A,C Merge the shifted pixels into the current column.
61262 OR (IX+0)
61265 LD (IX+0),A
61268 INC HL Advance the source and both column pointers.
61269 INC IX
61271 INC IY
61273 POP BC Restore the pixel-row counter from the stack.
61274 DJNZ PrintShiftedSprite_CopyLoop Decrease the pixel-row counter and loop back to PrintShiftedSprite_CopyLoop until all 8 rows are copied.
61276 POP HL Restore the source pointer from the stack.
61277 LD BC,(62268) Advance it by one sprite row and loop back to PrintShiftedSprite_RowLoop until every character row is done.
61281 ADD HL,BC
61282 DEC D
61283 JR NZ,PrintShiftedSprite_RowLoop
61285 POP DE Restore the remaining size from the stack.
61286 LD BC,8 Step both buffer pointers on to the next character column.
61289 ADD IX,BC
61291 ADD IY,BC
61293 POP HL Restore the source-column pointer from the stack.
61294 ADD HL,BC Step it on and loop back to PrintShiftedSprite_ColumnLoop until every column is done.
61295 DEC E
61296 JR NZ,PrintShiftedSprite_ColumnLoop
Character 32 is 256 bytes after Graphics_GoldfishGamePlayer, which lands on Working_Shift_Buffer. Add twice the vertical offset plus 2 so printing starts on the correct scanline.
61298 LD HL,40940 HL=Graphics_GoldfishGamePlayer.
61301 POP IX Restore the sprite slot from the stack.
61303 LD A,(IX+3) Point the character set at the working buffer, offset by the vertical sub-cell position.
61306 INC A
61307 SLA A
61309 LD E,A
61310 LD D,0
61312 ADD HL,DE
61313 LD (23606),HL
Print one extra column or row unless the sprite is already on the last sub-cell (3).
61316 LD D,(IX+8) DE=the sprite height and width.
61319 LD E,(IX+7)
61322 LD A,(IX+2) Jump to PrintShiftedSprite_AdjustRow if the horizontal offset is already 3.
61325 CP 3
61327 JR Z,PrintShiftedSprite_AdjustRow
61329 INC E Add one extra printed column.
PrintShiftedSprite_AdjustRow 61330 INC D Add one extra printed row.
61331 LD A,D Store the tile-to-tile character step in *SpriteShiftRow.
61332 LD (62270),A
61335 LD A,3 Jump to PrintShiftedSprite_LoadHeight if the vertical offset is not 3.
61337 CP (IX+3)
61340 JR NZ,PrintShiftedSprite_LoadHeight
61342 DEC D Keep the original printed height (no extra row).
PrintShiftedSprite_LoadHeight 61343 LD B,(IX+1) BC=the sprite row and column.
61346 LD C,(IX+0)
61349 LD A,D This load is unused; the next instruction overwrites A.
61350 LD A,32 A=32 (first shifted-buffer character).
61352 POP IY Restore IY from the stack.
61354 LD A,32 A=32 (first shifted-buffer character).
Print the shifted buffer row by row.
PrintShiftedSprite_PrintRow 61356 PUSH AF Stash the character code, remaining size and print position on the stack.
61357 PUSH DE
61358 PUSH BC
61359 LD D,A D=the starting character code.
61360 LD A,C Jump to PrintShiftedSprite_NextRow if the print column is off the left of the screen.
61361 CP 34
61363 JR NC,PrintShiftedSprite_NextRow
PrintShiftedSprite_PrintTile 61365 PUSH DE Stash the character code and remaining width on the stack.
Set the co-ordinates of where we're going to PRINT AT.
61366 CALL 3545 Call CL_SET.
61369 POP DE Restore the character code, remaining width and print position from the stack.
61370 POP BC
61371 PUSH BC Stash the print position on the stack.
61372 LD A,D A=the character code.
PrintShiftedSprite_PrintTileLoop 61373 CALL PrintColourCharacter Print this colour character using PrintColourCharacter.
61376 LD A,C Call PrintShiftedSprite_SkipColumn if the print column is the right-edge column (2).
61377 CP 2
61379 CALL Z,PrintShiftedSprite_SkipColumn
61382 DEC C Move one column right.
61383 LD A,(62270) Advance the character code by one printed column.
61386 ADD A,D
61387 LD D,A
61388 DEC E Decrease the remaining width and loop back to PrintShiftedSprite_PrintTileLoop until this row is done.
61389 JR NZ,PrintShiftedSprite_PrintTileLoop
61391 POP BC Restore the print position, remaining size and character code from the stack.
61392 POP DE
61393 POP AF
61394 DEC B Move one row down.
61395 INC A Advance the starting character code.
61396 DEC D Decrease the remaining printed height and loop back to PrintShiftedSprite_PrintRow until every row is printed.
61397 JR NZ,PrintShiftedSprite_PrintRow
Restore the original character set and return.
PrintShiftedSprite_RestoreSource 61399 POP HL Restore the original character set pointer from the stack.
61400 LD (23606),HL Write it back to *CHARS.
61403 RET Return.
The print column has reached the right-hand screen edge; skip the rest of this row.
PrintShiftedSprite_SkipColumn 61404 DEC E Return if this was the last tile in the row.
61405 PUSH AF
61406 INC E
61407 POP AF
61408 RET Z
61409 DEC E Skip one remaining tile and loop back to PrintShiftedSprite_SkipColumn.
61410 LD A,(62270)
61413 ADD A,D
61414 LD D,A
61415 JR PrintShiftedSprite_SkipColumn
The print column is off the left of the screen; skip tiles until it is back on-screen.
PrintShiftedSprite_NextRow 61417 LD A,(62270) Advance the character code and consume one tile.
61420 ADD A,D
61421 LD D,A
61422 DEC E
61423 JP Z,PrintShiftedSprite_RestoreRegisters Jump to PrintShiftedSprite_RestoreRegisters if no tiles remain.
61426 DEC C Move one column right.
61427 LD A,C Jump to PrintShiftedSprite_NextRow if the print column is still off the left.
61428 CP 34
61430 JR NC,PrintShiftedSprite_NextRow
61432 JP PrintShiftedSprite_PrintTile Jump to PrintShiftedSprite_PrintTile.
Discard the stacked print state and restore the character set.
PrintShiftedSprite_RestoreRegisters 61435 POP BC Discard the stacked character code, size and print position.
61436 POP BC
61437 POP BC
61438 JP PrintShiftedSprite_RestoreSource Jump to PrintShiftedSprite_RestoreSource.
Prev: 61094 Up: Map Next: 61441