Prev: 45596 Up: Map Next: 45756
45716: Build Shift Tables
Used by the routine at InitialiseGame.
Builds the lookup tables used to shift sprite bytes right by any number of pixels, and the table used to reverse the bits of a byte. The shift tables occupy 57344 to 61439. For each byte value 0 to 255 and each shift of 0 to 7 bits to the left, the byte is stored as a 16 bit number. The low byte of the number is stored in page 239 for a shift of 0, page 237 for a shift of 1, and so on in steps of two pages. The high byte is stored in the page below it. Both are stored at the offset given by the original value. The table at 61440 gives the value of each byte with its bits reversed, and is used to flip sprites.
BuildShiftTables 45716 LD L,0 Start with the byte value 0.
BuildShiftTables_NextValue 45718 LD D,0 Clear the high byte of the shifted value.
45720 LD E,L Copy the byte value into the low byte of the shifted value.
45721 LD H,239 Point H at the first table page, 239.
45723 LD B,8 There are 8 shifts to tabulate.
BuildShiftTables_Shift 45725 LD A,E Store the low byte of the shifted value.
45726 LD (HL),A
45727 DEC H Move to the page below.
45728 LD A,D Store the high byte of the shifted value.
45729 LD (HL),A
45730 DEC H Move to the next page below.
45731 SLA E Shift the 16 bit value left by one bit.
45733 RL D
45735 DJNZ BuildShiftTables_Shift Loop back until all shifts have been stored.
45737 INC L Move on to the next byte value, and loop back until all 256 have been done.
45738 JR NZ,BuildShiftTables_NextValue
45740 LD HL,61440 Point HL at ReversedBytes.
BuildShiftTables_ReverseByte 45743 LD A,L Take the byte value to reverse.
45744 LD B,8 There are 8 bits to move.
BuildShiftTables_ReverseBit 45746 RRA Move the lowest bit out into the carry flag.
45747 RL E Move the carry flag in at the bottom of E, so the bits end up reversed.
45749 DJNZ BuildShiftTables_ReverseBit Loop back until all 8 bits have been moved.
45751 LD (HL),E Store the reversed byte.
45752 INC L Move on to the next byte value, and loop back until all 256 have been done.
45753 JR NZ,BuildShiftTables_ReverseByte
45755 RET Return.
Prev: 45596 Up: Map Next: 45756