Prev: 38681 Up: Map Next: 38747
38696: XOR Sprite Loop
Used by the routines at DrawEntity, RemoveEntity and DisplayEntity.
Draws the old sprite and the new sprite a row at a time, alternating between the two, until every row of both has been drawn. The set of registers that is current on entry belongs to the old sprite, which is drawn by DrawOldEntityRow. The other set belongs to the new sprite, which is drawn by DrawNewEntityRow.
In each set HL is the screen address of the next row (the sprites are drawn from the bottom row upwards), DE points at the pixel data and B is the page of the shift table. C counts the rows that remain.
When both counts reach zero, the counts that are held in Old_Sprite_Row_Count (old sprite) and New_Sprite_Row_Count (new sprite) are loaded and the whole process repeats. The routine returns when those are zero as well. This allows the rows that have no partner to be drawn first (see DisplayEntity).
Draw a row of the old sprite, if it has any rows left.
XORSpriteLoop 38696 LD A,C Fetch the row count of the old sprite.
38697 AND A Jump to XORSpriteLoop_NewOnly if there are no rows left.
38698 JR Z,XORSpriteLoop_NewOnly
38700 DEC C Decrease the row count.
38701 CALL DrawOldEntityRow Draw a row of the old sprite.
Draw a row of the new sprite, if it has any rows left.
38704 EXX Switch to the registers of the new sprite.
38705 LD A,C Fetch the row count of the new sprite.
38706 AND A Jump to XORSpriteLoop_OldRow if there are no rows left.
38707 JR Z,XORSpriteLoop_OldRow
XORSpriteLoop_NewRow 38709 DEC C Decrease the row count.
38710 CALL DrawNewEntityRow Draw a row of the new sprite.
XORSpriteLoop_OldRow 38713 EXX Switch to the registers of the old sprite.
38714 JR XORSpriteLoop Jump back to XORSpriteLoop to draw the next pair of rows.
XORSpriteLoop_NewOnly 38716 EXX Switch to the registers of the new sprite.
38717 LD A,C Fetch the row count of the new sprite.
38718 AND A Jump to XORSpriteLoop_NewRow if there are rows left.
38719 JR NZ,XORSpriteLoop_NewRow
This entry point is used by the routine at DisplayEntity_NewLower.
XORSpriteLoop_Done 38721 EXX Switch to the registers of the old sprite.
This entry point is used by the routine at DisplayEntity.
Both of the counts are zero. Load the row counts that were stored by the preparation routines and go round again, unless they are zero too.
XORSpriteLoop_Reload 38722 LD A,(36578) Fetch the number of rows of the old sprite from Old_Sprite_Row_Count.
38725 LD C,A Copy the number of rows to C.
38726 LD A,(36579) Fetch the number of rows of the new sprite from New_Sprite_Row_Count.
38729 OR C Combine it with the number of rows of the old sprite.
38730 RET Z Return if there are no rows left to draw.
38731 XOR A Write 0 to Old_Sprite_Row_Count.
38732 LD (36578),A
38735 EXX Switch to the registers of the new sprite.
38736 LD A,(36579) Fetch the number of rows of the new sprite from New_Sprite_Row_Count.
38739 LD C,A Copy the number of rows to C.
38740 XOR A Set the number of rows to store to 0.
This entry point is used by the routine at DisplayEntity_NewLower.
XORSpriteLoop_StoreNew 38741 LD (36579),A Store A in New_Sprite_Row_Count.
38744 EXX Switch to the registers of the old sprite.
38745 JR XORSpriteLoop Jump back to XORSpriteLoop to start drawing rows.
View the equivalent code in;
Prev: 38681 Up: Map Next: 38747