Prev: D67C Up: Map Next: D6C9
D69E: Build Lookup Tables
Used by the routine at InitialiseGame.
Builds the two tables that the sprite routines use. The first is the set of tables of shifted bytes in pages F2 to FF: for each shift of one to seven bits to the right there is a page with the inverse of every byte shifted, and a page after it with the inverse of the bits that are pushed out into the next byte. The second is the table at ReversedByteTable of every byte with its bits reversed.
Build the shifted-byte tables, then the reversed-byte table.
BuildLookupTables D69E LD L,$00 Start with the byte zero.
BuildLookupTables_Shift D6A0 LD D,$00 Clear the high byte of the shifted value.
D6A2 LD E,L Set the low byte of the shifted value to the byte.
D6A3 LD H,$FF Point H at the last page of the table.
D6A5 LD B,$07 Set the number of shifts to 07.
BuildLookupTables_Shift_Step D6A7 SLA E Shift the value left one bit.
D6A9 RL D Shift the carry into the high byte.
D6AB LD A,E Fetch the low byte.
D6AC CPL Invert it.
D6AD LD (HL),A Store it in the table.
D6AE DEC H Go to the page before.
D6AF LD A,D Fetch the high byte.
D6B0 CPL Invert it.
D6B1 LD (HL),A Store it in the table.
D6B2 DEC H Go to the page before.
D6B3 DJNZ BuildLookupTables_Shift_Step Jump to BuildLookupTables_Shift_Step until all of the shifts are done.
D6B5 INC L Go on to the next byte.
D6B6 JR NZ,BuildLookupTables_Shift Jump to BuildLookupTables_Shift until all of the bytes are done.
D6B8 LD HL,$F100 Point HL at ReversedByteTable.
Reverse the bits of every byte into ReversedByteTable.
BuildLookupTables_Reverse D6BB LD D,L Take the byte that is to be reversed.
D6BC LD B,$08 Set the number of bits to 08.
BuildLookupTables_Reverse_Bit D6BE SRL D Shift a bit out of the byte.
D6C0 RL E Shift it into the reversed byte.
D6C2 DJNZ BuildLookupTables_Reverse_Bit Jump to BuildLookupTables_Reverse_Bit until all of the bits are done.
D6C4 LD (HL),E Store the reversed byte in the table.
D6C5 INC L Go on to the next byte.
D6C6 JR NZ,BuildLookupTables_Reverse Jump to BuildLookupTables_Reverse until all of the bytes are done.
D6C8 RET Return.
View the equivalent code in;
Prev: D67C Up: Map Next: D6C9