Prev: E0EE Up: Map Next: E148
E0FB: Build Shift Tables
Used by the routine at StartGame.
Builds the tables that the sprite drawing routines use to shift graphics sideways, and the table that reverses the bits in a byte.
There are three pairs of 256-byte pages for shifting a byte by two, four and six pixels (the low byte of the shifted result is in the first page of each pair, counting down from FF, and the high byte is in the second). FA to FF hold the shifts of the bytes as they are, and F2 to F7 hold the shifts of the bytes with their bits reversed. The page at ReverseBitsTable holds the bytes with their bits reversed.
Build the tables for the bytes as they are.
BuildShiftTables E0FB LD L,$00 Start with the byte at 00.
Start with the byte as a 16-bit number, and point HL at the first page of the tables.
BuildShiftTables_Normal E0FD LD D,$00 Make the word the byte.
E0FF LD E,L
E100 LD H,$FF Start at page FF.
E102 LD B,$03 Set a count of 03 pairs.
Shift the word left by two bits and store it.
BuildShiftTables_NormalLoop E104 SLA E Shift the word left by two bits.
E106 RL D
E108 SLA E
E10A RL D
E10C LD (HL),E Store the pair in the next two pages.
E10D DEC H
E10E LD (HL),D
E10F DEC H
E110 DJNZ BuildShiftTables_NormalLoop Jump to BuildShiftTables_NormalLoop if there are any left.
Move on to the next byte, and loop back until all 256 have been done.
E112 INC L Move on to the next byte.
E113 JR NZ,BuildShiftTables_Normal Jump to BuildShiftTables_Normal if there are any left.
Build the tables for the bytes with their bits reversed.
E115 LD L,$00 Start with the byte at 00.
BuildShiftTables_Reversed E117 LD D,$00 Clear the high byte of the word.
E119 LD B,$08 Set a count of 08 bits, and copy the byte into A.
E11B LD A,L
Turn the bits of the byte round.
BuildShiftTables_Reverse E11C RRCA Move the next bit into C from the other end.
E11D RL C
E11F DJNZ BuildShiftTables_Reverse Jump to BuildShiftTables_Reverse if there are any left.
Start with the reversed byte as a 16-bit number, and point HL at the first page of the reversed tables.
E121 LD E,C Make the low byte the reversed byte.
E122 LD H,$F7 Start at page F7.
E124 LD B,$03 Set a count of 03 pairs.
Shift the word left by two bits and store it.
BuildShiftTables_ReversedLoop E126 SLA E Shift the word left by two bits.
E128 RL D
E12A SLA E
E12C RL D
E12E LD (HL),E Store the pair in the next two pages.
E12F DEC H
E130 LD (HL),D
E131 DEC H
E132 DJNZ BuildShiftTables_ReversedLoop Jump to BuildShiftTables_ReversedLoop if there are any left.
Move on to the next byte, and loop back until all 256 have been done.
E134 INC L Move on to the next byte.
E135 JR NZ,BuildShiftTables_Reversed Jump to BuildShiftTables_Reversed if there are any left.
Build the table of reversed bytes.
E137 LD HL,$F900 Point HL at ReverseBitsTable.
BuildShiftTables_ReverseTable E13A LD D,L Start with the byte, and count eight bits.
E13B LD B,$08
BuildShiftTables_ReverseBits E13D SRL D Move the lowest bit of the byte into the other end of E.
E13F RL E
E141 DJNZ BuildShiftTables_ReverseBits Jump to BuildShiftTables_ReverseBits if there are any left.
E143 LD (HL),E Store the byte turned round.
E144 INC L Move on to the next byte.
E145 JR NZ,BuildShiftTables_ReverseTable Jump to BuildShiftTables_ReverseTable if there are any left.
E147 RET Return.
View the equivalent code in;
Prev: E0EE Up: Map Next: E148