Prev: 57582 Up: Map Next: 57672
57595: 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 255, and the high byte is in the second). 250 to 255 hold the shifts of the bytes as they are, and 242 to 247 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 57595 LD L,0 Start with the byte at 0.
Start with the byte as a 16-bit number, and point HL at the first page of the tables.
BuildShiftTables_Normal 57597 LD D,0 Make the word the byte.
57599 LD E,L
57600 LD H,255 Start at page 255.
57602 LD B,3 Set a count of 3 pairs.
Shift the word left by two bits and store it.
BuildShiftTables_NormalLoop 57604 SLA E Shift the word left by two bits.
57606 RL D
57608 SLA E
57610 RL D
57612 LD (HL),E Store the pair in the next two pages.
57613 DEC H
57614 LD (HL),D
57615 DEC H
57616 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.
57618 INC L Move on to the next byte.
57619 JR NZ,BuildShiftTables_Normal Jump to BuildShiftTables_Normal if there are any left.
Build the tables for the bytes with their bits reversed.
57621 LD L,0 Start with the byte at 0.
BuildShiftTables_Reversed 57623 LD D,0 Clear the high byte of the word.
57625 LD B,8 Set a count of 8 bits, and copy the byte into A.
57627 LD A,L
Turn the bits of the byte round.
BuildShiftTables_Reverse 57628 RRCA Move the next bit into C from the other end.
57629 RL C
57631 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.
57633 LD E,C Make the low byte the reversed byte.
57634 LD H,247 Start at page 247.
57636 LD B,3 Set a count of 3 pairs.
Shift the word left by two bits and store it.
BuildShiftTables_ReversedLoop 57638 SLA E Shift the word left by two bits.
57640 RL D
57642 SLA E
57644 RL D
57646 LD (HL),E Store the pair in the next two pages.
57647 DEC H
57648 LD (HL),D
57649 DEC H
57650 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.
57652 INC L Move on to the next byte.
57653 JR NZ,BuildShiftTables_Reversed Jump to BuildShiftTables_Reversed if there are any left.
Build the table of reversed bytes.
57655 LD HL,63744 Point HL at ReverseBitsTable.
BuildShiftTables_ReverseTable 57658 LD D,L Start with the byte, and count eight bits.
57659 LD B,8
BuildShiftTables_ReverseBits 57661 SRL D Move the lowest bit of the byte into the other end of E.
57663 RL E
57665 DJNZ BuildShiftTables_ReverseBits Jump to BuildShiftTables_ReverseBits if there are any left.
57667 LD (HL),E Store the byte turned round.
57668 INC L Move on to the next byte.
57669 JR NZ,BuildShiftTables_ReverseTable Jump to BuildShiftTables_ReverseTable if there are any left.
57671 RET Return.
View the equivalent code in;
Prev: 57582 Up: Map Next: 57672