Prev: 47349 Up: Map Next: 47385
47362: Build Shift Table
Used by the routine at GameInitialisation.
Builds a lookup table in the top 4096 bytes of memory (61440 to 65535) 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 255 - (2 * 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 0.
BuildShiftTable 47362 LD L,0 L=0 (the byte value).
Start with no shift (E holds the low byte and D the high byte of the shifted value).
BuildShiftTable_Value 47364 LD D,0 D=0.
47366 LD E,L E=L.
47367 LD H,255 H=255 (the page for the first low byte).
47369 LD B,8 B=8 (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 47371 LD (HL),E Write the low byte.
47372 DEC H Move down a page.
47373 LD (HL),D Write the high byte.
47374 DEC H Move down a page.
47375 SLA E Shift E left one bit (bit 7 goes into the carry flag).
47377 RL D Rotate D left one bit, bringing in the carry flag.
47379 DJNZ BuildShiftTable_Offset Decrease counter by one and loop back to BuildShiftTable_Offset until zero.
47381 INC L Move onto the next byte value.
47382 JR NZ,BuildShiftTable_Value Jump back to BuildShiftTable_Value until every byte value has been done.
47384 RET Return.
View the equivalent code in;
Prev: 47349 Up: Map Next: 47385