Prev: 42366 Up: Map Next: 42537
42399: Draw Sprites Directly
Used by the routines at DrawPiece, RunFrame, DrawShipTop, DrawSideFlames and DrawMainFlame.
Erases one sprite and draws another straight on the screen instead of using a buffer. The rows of the two sprites are dealt with one at a time, alternating between an erased row and a drawn row, so that they stay in step. The sprite that is lower on the screen starts first, as the rows of a sprite go up the screen, and its first rows are done by themselves until the other sprite starts. The sprites are set up by SetSecondRowGroup and SetFirstRowGroup, which store the number of rows at 23580 and 23581. The first sprite is erased using the alternate registers and the second sprite is drawn using the main registers.
Input
DE Address of the data of the second sprite
DE' Address of the data of the first sprite
HL Screen address of the second sprite
HL' Screen address of the first sprite
IX Routine that draws the second sprite
IY Routine that erases the first sprite
DrawSpritesDirectly 42399 LD A,L Fetch the low byte of the screen address of the second sprite.
42400 LD (23593),A Store it as the start of a row.
42403 EXX Switch to the first sprite.
42404 LD A,L Fetch the low byte of its screen address.
42405 LD (23592),A Store it as the start of a row.
42408 EXX Switch back to the second sprite.
42409 LD A,(23581) Fetch the number of rows of the second sprite.
42412 EX AF,AF' Keep it in the alternate accumulator.
42413 LD A,(23580) Fetch the number of rows of the first sprite.
42416 AND A Test it.
42417 JP Z,DrawSpritesDirectly_Row Jump to DrawSpritesDirectly_Row if the first sprite has no rows.
42420 LD A,(23581) Fetch the number of rows of the second sprite.
42423 AND A Test it.
42424 JP Z,DrawSpritesDirectly_Row Jump to DrawSpritesDirectly_Row if the second sprite has no rows.
42427 LD A,(41609) Fetch the vertical position of the first sprite.
42430 LD C,A Store it in C.
42431 LD A,(41610) Fetch the vertical position of the second sprite.
42434 SUB C Subtract the position of the first sprite.
42435 JP Z,DrawSpritesDirectly_Row Jump to DrawSpritesDirectly_Row if they start on the same row.
42438 JR NC,DrawSpritesDirectly_Second Jump to DrawSpritesDirectly_Second if the second sprite is the lower one.
The first sprite is the lower one, so do its first rows by themselves.
42440 NEG Make the difference positive.
42442 LD C,A Store it in C.
42443 LD A,(23580) Fetch the number of rows of the first sprite.
42446 SUB C Take off the difference.
42447 LD (41609),A Store it for later.
42450 JR C,DrawSpritesDirectly_First Jump to DrawSpritesDirectly_First if the first sprite has fewer rows than that.
42452 LD A,C Otherwise use the difference as the number of rows to do.
42453 LD (23580),A Store it.
DrawSpritesDirectly_First 42456 XOR A Clear A.
42457 EX AF,AF' Make the second sprite have no rows for now.
42458 CALL DrawSpritesDirectly_Row Do the rows of the first sprite.
42461 EXX Switch to the second sprite.
42462 LD A,(41609) Fetch the number of rows that are left for the first sprite.
42465 LD (23580),A Store it.
42468 LD A,(23581) Fetch the number of rows of the second sprite.
42471 EX AF,AF' Restore it.
42472 JP DrawSpritesDirectly_Row Jump to DrawSpritesDirectly_Row to do the rows of both sprites.
The second sprite is the lower one, so do its first rows by themselves.
DrawSpritesDirectly_Second 42475 LD C,A Store the difference in C.
42476 LD A,(23581) Fetch the number of rows of the second sprite.
42479 SUB C Take off the difference.
42480 LD (41610),A Store it for later.
42483 JR C,DrawSpritesDirectly_SecondRows Jump to DrawSpritesDirectly_SecondRows if the second sprite has fewer rows than that.
42485 LD A,C Otherwise use the difference as the number of rows to do.
42486 EX AF,AF' Store it.
DrawSpritesDirectly_SecondRows 42487 LD A,(23580) Fetch the number of rows of the first sprite.
42490 LD (41609),A Keep it.
42493 XOR A Clear A.
42494 LD (23580),A Make the first sprite have no rows for now.
42497 CALL DrawSpritesDirectly_Row Do the rows of the second sprite.
42500 LD A,(41609) Fetch the number of rows of the first sprite.
42503 LD (23580),A Restore it.
42506 LD A,(41610) Fetch the number of rows that are left for the second sprite.
42509 EX AF,AF' Store it.
42510 JP DrawSpritesDirectly_Row Jump to DrawSpritesDirectly_Row to do the rows of both sprites.
This entry point is used by the routine at DrawNextRow.
DrawSpritesDirectly_SecondRow 42513 EX AF,AF' Switch to the count of the second sprite.
42514 LD A,(23580) Fetch the number of rows of the first sprite.
42517 DEC A Take one off.
42518 RET M Return if there are none left.
42519 LD (23580),A Store it.
42522 JP (IY) Erase a row of the first sprite.
This entry point is used by the routine at DrawAlignedRowDirectly.
DrawSpritesDirectly_Row 42524 LD A,(23580) Fetch the number of rows of the first sprite.
42527 DEC A Take one off.
42528 JP M,NextRowOfSecondSprite Jump to NextRowOfSecondSprite if there are none left.
42531 LD (23580),A Store it.
42534 EXX Switch to the first sprite.
42535 JP (IY) Erase a row of the first sprite.
Prev: 42366 Up: Map Next: 42537