Prev: CF85 Up: Map Next: CFD2
CFA7: 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 (ShiftedByteTables) in pages F2 to FF: for each shift of one to seven bits 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 of every byte with its bits reversed (ReversedByteTable).
Build the tables of shifted bytes.
BuildLookupTables CFA7 LD L,$00 Set L to 00.
BuildLookupTables_Shift CFA9 LD D,$00 Set D to 00.
CFAB LD E,L Copy L to E.
CFAC LD H,$FF Set H to FF.
CFAE LD B,$07 Set B to 07.
BuildLookupTables_ShiftStep CFB0 SLA E Shift E left.
CFB2 RL D Rotate D left.
CFB4 LD A,E Fetch E.
CFB5 CPL Invert it.
CFB6 LD (HL),A Write it.
CFB7 DEC H Decrement H.
CFB8 LD A,D Fetch D.
CFB9 CPL Invert it.
CFBA LD (HL),A Write it.
CFBB DEC H Decrement H.
CFBC DJNZ BuildLookupTables_ShiftStep Jump to BuildLookupTables_ShiftStep until B is zero.
CFBE INC L Increment L.
CFBF JR NZ,BuildLookupTables_Shift Jump to BuildLookupTables_Shift if L is not zero.
Build the table of reversed bytes.
CFC1 LD HL,$F100 Point HL at ReversedByteTable.
BuildLookupTables_Reverse CFC4 LD D,L Copy L to D.
CFC5 LD B,$08 Set B to 08.
BuildLookupTables_ReverseBit CFC7 SRL D Shift D right.
CFC9 RL E Rotate E left.
CFCB DJNZ BuildLookupTables_ReverseBit Jump to BuildLookupTables_ReverseBit until B is zero.
CFCD LD (HL),E Write E.
CFCE INC L Increment L.
CFCF JR NZ,BuildLookupTables_Reverse Jump to BuildLookupTables_Reverse if L is not zero.
CFD1 RET Return.
View the equivalent code in;
Prev: CF85 Up: Map Next: CFD2