Prev: E0EE Up: Map Next: E148
E0FB: Build the drawing tables
Used by the routine at NEW_GAME.
Run at every new game (NEW_GAME). Fills the six pages from MIRROR_TABLES, the six from SHIFT_TABLES, and REVERSE_TABLE with the tables the drawing of sprites and tiles reads to put a byte at any even pixel.
The six pages from SHIFT_TABLES up are every byte value shifted right two, four and six places, in pairs: page $FA holds a byte shifted right two, the part that stays in its own byte, and page $FB the two bits that fall out into the next byte; $FC and $FD the same for four places, $FE and $FF for six. The loop builds them the other way about: it shifts each value left across two bytes, two places at a time, and stores the pair after each shift from the top page down, so the high byte of a shift left by eight less s is the shift right by s. The six from MIRROR_TABLES are the same for every value with its bits reversed first, for tiles drawn mirrored; and REVERSE_TABLE is every value reversed, for mirroring sprites (TURN_SPRITE) and tiles on a byte boundary.
Only even shifts are built because nothing is drawn at an odd pixel: the drawing ignores bit 0 of x. Knight Lore, Alien 8 and Pentagram build seven shifts, complemented; these are three, and plain. Checked in the simulator: after this routine every byte of the thirteen pages is as described, and the page between them, UNUSED_F800, is not touched.
MAKE_TABLES E0FB LD L,$00 For each value L: DE = L, starting at the top page
MAKE_TABLES_0 E0FD LD D,$00
E0FF LD E,L
E100 LD H,$FF
E102 LD B,$03
MAKE_TABLES_1 E104 SLA E Shift DE left two places; the low byte to page H and the high to the page below; three times, for pages $FF down to $FA
E106 RL D
E108 SLA E
E10A RL D
E10C LD (HL),E
E10D DEC H
E10E LD (HL),D
E10F DEC H
E110 DJNZ MAKE_TABLES_1
E112 INC L The next value
E113 JR NZ,MAKE_TABLES_0
E115 LD L,$00 Again with the value's bits reversed first: C = L back to front
MAKE_TABLES_2 E117 LD D,$00
E119 LD B,$08
E11B LD A,L
MAKE_TABLES_3 E11C RRCA
E11D RL C
E11F DJNZ MAKE_TABLES_3
E121 LD E,C
E122 LD H,$F7 ...shifted and stored the same way on pages $F7 down to $F2
E124 LD B,$03
MAKE_TABLES_4 E126 SLA E
E128 RL D
E12A SLA E
E12C RL D
E12E LD (HL),E
E12F DEC H
E130 LD (HL),D
E131 DEC H
E132 DJNZ MAKE_TABLES_4
E134 INC L The next value
E135 JR NZ,MAKE_TABLES_2
E137 LD HL,REVERSE_TABLE Page $F9: each value's bits in reverse order
MAKE_TABLES_5 E13A LD D,L
E13B LD B,$08
MAKE_TABLES_6 E13D SRL D
E13F RL E
E141 DJNZ MAKE_TABLES_6
E143 LD (HL),E
E144 INC L
E145 JR NZ,MAKE_TABLES_5
E147 RET Done
Prev: E0EE Up: Map Next: E148