Prev: B8F5 Up: Map Next: B919
B902: Build Shift Table
Used by the routine at GameInitialisation.
Builds a lookup table in the top 1000 bytes of memory (F000 to FFFF) which the sprite drawing routines use to position a sprite at any pixel.
For every byte value, and for each of the eight possible pixel offsets, the value shifted left by that many bits is stored as a 16-bit number. The low byte is written to the page at FF - (02 * offset) and the high byte to the page below it, both at the position given by the byte value.
Work through each byte value in turn, starting with 00.
BuildShiftTable B902 LD L,$00 L=00 (the byte value).
Start with no shift (E holds the low byte and D the high byte of the shifted value).
BuildShiftTable_Value B904 LD D,$00 D=00.
B906 LD E,L E=L.
B907 LD H,$FF H=FF (the page for the first low byte).
B909 LD B,$08 B=08 (counter, one for each pixel offset).
Store the low and the high byte, then shift the 16-bit value left by one bit for the next offset.
BuildShiftTable_Offset B90B LD (HL),E Write the low byte.
B90C DEC H Move down a page.
B90D LD (HL),D Write the high byte.
B90E DEC H Move down a page.
B90F SLA E Shift E left one bit (bit 7 goes into the carry flag).
B911 RL D Rotate D left one bit, bringing in the carry flag.
B913 DJNZ BuildShiftTable_Offset Decrease counter by one and loop back to BuildShiftTable_Offset until zero.
B915 INC L Move onto the next byte value.
B916 JR NZ,BuildShiftTable_Value Jump back to BuildShiftTable_Value until every byte value has been done.
B918 RET Return.
View the equivalent code in;
Prev: B8F5 Up: Map Next: B919