Prev: B21C Up: Map Next: B2BC
B294: 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 E000 to EFFF. For each byte value 00 to FF and each shift of 00 to 07 bits to the left, the byte is stored as a 10 bit number. The low byte of the number is stored in page EF for a shift of 00, page ED for a shift of 01, 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 F000 gives the value of each byte with its bits reversed, and is used to flip sprites.
BuildShiftTables B294 LD L,$00 Start with the byte value 00.
BuildShiftTables_NextValue B296 LD D,$00 Clear the high byte of the shifted value.
B298 LD E,L Copy the byte value into the low byte of the shifted value.
B299 LD H,$EF Point H at the first table page, EF.
B29B LD B,$08 There are 08 shifts to tabulate.
BuildShiftTables_Shift B29D LD A,E Store the low byte of the shifted value.
B29E LD (HL),A
B29F DEC H Move to the page below.
B2A0 LD A,D Store the high byte of the shifted value.
B2A1 LD (HL),A
B2A2 DEC H Move to the next page below.
B2A3 SLA E Shift the 10 bit value left by one bit.
B2A5 RL D
B2A7 DJNZ BuildShiftTables_Shift Loop back until all shifts have been stored.
B2A9 INC L Move on to the next byte value, and loop back until all 0100 have been done.
B2AA JR NZ,BuildShiftTables_NextValue
B2AC LD HL,$F000 Point HL at ReversedBytes.
BuildShiftTables_ReverseByte B2AF LD A,L Take the byte value to reverse.
B2B0 LD B,$08 There are 08 bits to move.
BuildShiftTables_ReverseBit B2B2 RRA Move the lowest bit out into the carry flag.
B2B3 RL E Move the carry flag in at the bottom of E, so the bits end up reversed.
B2B5 DJNZ BuildShiftTables_ReverseBit Loop back until all 08 bits have been moved.
B2B7 LD (HL),E Store the reversed byte.
B2B8 INC L Move on to the next byte value, and loop back until all 0100 have been done.
B2B9 JR NZ,BuildShiftTables_ReverseByte
B2BB RET Return.
Prev: B21C Up: Map Next: B2BC