Prev: 45688 Up: Map Next: 45765
45722: Build Lookup Tables
Used by the routine at RunGame.
Builds the tables that the sprite drawing and flipping code uses. ReverseTable gets the reversed bits of each byte value. The shift tables fill the pages from ShiftTables to 65535: for each of the seven shifts, one page holds the low byte and the page below it holds the high byte of every byte value shifted left by that number of bits, with all the bits inverted.
Build the shift tables, one pair of pages for each shift of one to seven bits.
BuildLookupTables 45722 LD L,0 Start with the byte value 0 in L.
BuildLookupTables_NextValue 45724 LD D,0 Clear D, the high byte of the shifted value.
45726 LD E,L Copy the byte value to E, the low byte of the shifted value.
45727 LD H,255 Point H at the top page, 255.
45729 LD B,7 Set a counter in B of seven shifts.
BuildLookupTables_NextShift 45731 SLA E Shift the value left by one bit more.
45733 RL D
45735 LD A,E Fetch the low byte of the value.
45736 CPL Invert the low byte of the shifted value.
45737 LD (HL),A Write the inverted low byte to the shift table.
45738 DEC H Move down to the next page.
45739 LD A,D Fetch the high byte of the value.
45740 CPL Invert the high byte of the shifted value.
45741 LD (HL),A Write the inverted high byte to the shift table.
45742 DEC H Move down to the next page.
45743 DJNZ BuildLookupTables_NextShift Decrease the shift counter and loop until all seven shifts are done.
45745 INC L Move on to the next byte value.
45746 JR NZ,BuildLookupTables_NextValue Jump to BuildLookupTables_NextValue until all 256 byte values are done.
Build the table of bytes with the order of their bits reversed.
45748 LD HL,61696 Start the table of reversed bytes at ReverseTable.
BuildLookupTables_Reverse 45751 LD D,L Fetch the byte value to be reversed in D.
45752 LD B,8 Set a counter in B of eight bits.
BuildLookupTables_ReverseBit 45754 SRL D Shift the lowest bit of D out into the carry flag.
45756 RL E Shift it into E, so the bits arrive in the opposite order.
45758 DJNZ BuildLookupTables_ReverseBit Decrease the bit counter and loop until all eight bits are done.
45760 LD (HL),E Write the reversed value to the table.
45761 INC L Move on to the next byte value.
45762 JR NZ,BuildLookupTables_Reverse Jump to BuildLookupTables_Reverse until all 256 values are done.
45764 RET Return once both tables are built.
View the equivalent code in;
Prev: 45688 Up: Map Next: 45765