![]() |
Routines |
| Prev: B278 | Up: Map | Next: B2C5 |
|
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 FFFF: 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 | B29A | LD L,$00 | Start with the byte value 00 in L. | |
| BuildLookupTables_NextValue | B29C | LD D,$00 | Clear D, the high byte of the shifted value. | |
| B29E | LD E,L | Copy the byte value to E, the low byte of the shifted value. | ||
| B29F | LD H,$FF | Point H at the top page, FF. | ||
| B2A1 | LD B,$07 | Set a counter in B of seven shifts. | ||
| BuildLookupTables_NextShift | B2A3 | SLA E | Shift the value left by one bit more. | |
| B2A5 | RL D | |||
| B2A7 | LD A,E | Fetch the low byte of the value. | ||
| B2A8 | CPL | Invert the low byte of the shifted value. | ||
| B2A9 | LD (HL),A | Write the inverted low byte to the shift table. | ||
| B2AA | DEC H | Move down to the next page. | ||
| B2AB | LD A,D | Fetch the high byte of the value. | ||
| B2AC | CPL | Invert the high byte of the shifted value. | ||
| B2AD | LD (HL),A | Write the inverted high byte to the shift table. | ||
| B2AE | DEC H | Move down to the next page. | ||
| B2AF | DJNZ BuildLookupTables_NextShift | Decrease the shift counter and loop until all seven shifts are done. | ||
| B2B1 | INC L | Move on to the next byte value. | ||
| B2B2 | JR NZ,BuildLookupTables_NextValue | Jump to BuildLookupTables_NextValue until all 0100 byte values are done. | ||
|
Build the table of bytes with the order of their bits reversed.
|
||||
| B2B4 | LD HL,$F100 | Start the table of reversed bytes at ReverseTable. | ||
| BuildLookupTables_Reverse | B2B7 | LD D,L | Fetch the byte value to be reversed in D. | |
| B2B8 | LD B,$08 | Set a counter in B of eight bits. | ||
| BuildLookupTables_ReverseBit | B2BA | SRL D | Shift the lowest bit of D out into the carry flag. | |
| B2BC | RL E | Shift it into E, so the bits arrive in the opposite order. | ||
| B2BE | DJNZ BuildLookupTables_ReverseBit | Decrease the bit counter and loop until all eight bits are done. | ||
| B2C0 | LD (HL),E | Write the reversed value to the table. | ||
| B2C1 | INC L | Move on to the next byte value. | ||
| B2C2 | JR NZ,BuildLookupTables_Reverse | Jump to BuildLookupTables_Reverse until all 0100 values are done. | ||
| B2C4 | RET | Return once both tables are built. | ||
|
View the equivalent code in;
|
||||
| Prev: B278 | Up: Map | Next: B2C5 |