Prev: 54506 Up: Map Next: 54602
54525: Build Shift Tables
Used by the routine at InitialiseGame.
Builds ShiftTables, ReversedShiftTables and ReverseTable, which the routines for drawing sprites use. Each table is a page, which has an entry for each value of a byte at the low byte of the address. For a byte which is moved to the right along a row by six pixels, page 254 has the part which stays in the byte and page 255 has the part which moves into the next byte. Pages 252 and 253 are the same for four pixels, and pages 250 and 251 for two. Pages 246 and 247 244 and 245 and 242 and 243 are the same for the byte with its bits turned round, which is used for sprites which are reflected. ReverseTable has each byte with its bits turned round.
Build ShiftTables.
BuildShiftTables 54525 LD L,0 Start with the byte at 0.
BuildShiftTables_Normal 54527 LD D,0 Make the word the byte.
54529 LD E,L
54530 LD H,255 Start at page 255.
54532 LD B,3 Set a count of 3 pairs.
Shift the word left by two bits and store it.
BuildShiftTables_NormalLoop 54534 SLA E Shift the word left by two bits.
54536 RL D
54538 SLA E
54540 RL D
54542 LD (HL),E Store the pair in the next two pages.
54543 DEC H
54544 LD (HL),D
54545 DEC H
54546 DJNZ BuildShiftTables_NormalLoop Jump to BuildShiftTables_NormalLoop if there are any left.
54548 INC L Move on to the next byte.
54549 JR NZ,BuildShiftTables_Normal Jump to BuildShiftTables_Normal if there are any left.
54551 LD L,0 Start with the byte at 0.
BuildShiftTables_Reversed 54553 LD D,0 Clear the high byte of the word.
54555 LD B,8 Set a count of 8 bits, and copy the byte into A.
54557 LD A,L
Turn the bits of the byte round.
BuildShiftTables_Reverse 54558 RRCA Move the next bit into C from the other end.
54559 RL C
54561 DJNZ BuildShiftTables_Reverse Jump to BuildShiftTables_Reverse if there are any left.
54563 LD E,C Make the low byte the reversed byte.
54564 LD H,247 Start at page 247.
54566 LD B,3 Set a count of 3 pairs.
Shift the word left by two bits and store it.
BuildShiftTables_ReversedLoop 54568 SLA E Shift the word left by two bits.
54570 RL D
54572 SLA E
54574 RL D
54576 LD (HL),E Store the pair in the next two pages.
54577 DEC H
54578 LD (HL),D
54579 DEC H
54580 DJNZ BuildShiftTables_ReversedLoop Jump to BuildShiftTables_ReversedLoop if there are any left.
54582 INC L Move on to the next byte.
54583 JR NZ,BuildShiftTables_Reversed Jump to BuildShiftTables_Reversed if there are any left.
Build ReverseTable.
54585 LD HL,63744 Point HL at ReverseTable.
BuildShiftTables_ReverseTable 54588 LD D,L Copy the byte into D, and set a count of 8 bits.
54589 LD B,8
BuildShiftTables_ReverseBits 54591 SRL D Move the lowest bit of the byte into the other end of E.
54593 RL E
54595 DJNZ BuildShiftTables_ReverseBits Jump to BuildShiftTables_ReverseBits if there are any left.
54597 LD (HL),E Store the byte turned round.
54598 INC L Move on to the next byte.
54599 JR NZ,BuildShiftTables_ReverseTable Jump to BuildShiftTables_ReverseTable if there are any left.
54601 RET Return.
View the equivalent code in;
Prev: 54506 Up: Map Next: 54602