Prev: 23808 Up: Map Next: 24162
24064: Game Entry
The entry point of the game, started by the loader. It moves the title sequence code and graphics out of the way, runs the title sequence and then builds three lookup tables for the sprite routines before handing over to the game proper at RunGame.
The title sequence (the code at 62738) does not return by itself: when a key is pressed it leaves through WipeViewOut, which ends by returning to the instruction after the call at 24103.
Set up the machine.
GameEntry 24064 DI Disable interrupts.
24065 LD SP,23408 Put the stack just below the game variables.
24068 LD (23793),IY Remember IY in SavedIY, as the ROM interrupt routine needs it to point at the system variables.
24072 XOR A Set the border colour to black.
24073 OUT (254),A
Move the title sequence out of the game data.
24075 LD DE,62720 DE is 62720 (the destination).
24078 LD HL,58811 Set HL to ScreenBuffer (the source).
24081 LD BC,512 BC is 512 (the number of bytes to copy).
24084 LDIR Copy the title sequence code.
24086 LD DE,63232 DE is 63232 (the destination).
24089 LD HL,59030 Set HL to 59030 (the source).
24092 LD BC,2048 BC is 2048 (the number of bytes to copy).
24095 LDIR Copy the title sequence graphics.
Run the title sequence.
24097 CALL ClearScreen Call ClearScreen to clear the pixels of the screen.
24100 CALL ResetAttributes Call ResetAttributes to set the attributes of the lower two thirds of the screen to bright white on black.
24103 CALL 62738 Call the title sequence.
Build the bit reversal table at 63744.
24106 LD HL,63744 HL is 63744 (the start of the table).
24109 LD C,0 Set the table index in C to 0.
GameEntry_BuildReverseTable 24111 LD B,8 Set the bit counter in B to 8.
24113 LD D,C Copy the table index into D.
24114 XOR A Clear the reversed value in A.
GameEntry_ReverseBits 24115 SLA D Shift the top bit of D out into the carry flag.
24117 RR A Rotate the carry flag into the top of the reversed value.
24119 DJNZ GameEntry_ReverseBits Decrease the bit counter by one and loop back to GameEntry_ReverseBits until all eight bits have been reversed.
24121 LD (HL),A Store the reversed value in the table.
24122 INC HL Move onto the next table entry.
24123 INC C Move onto the next table index.
24124 JR NZ,GameEntry_BuildReverseTable Jump back to GameEntry_BuildReverseTable until all 256 entries have been written.
Build the three pairs of shift tables at 64000 64512 and 65024. For every byte value, the first table of a pair holds the byte shifted right and inverted, and the second table holds the inverted bits which were shifted out. The shifts are two, four and six pixels.
24126 LD B,2 Start with a shift of two pixels.
GameEntry_BuildShiftTables 24128 LD C,0 Start with the byte value 0.
GameEntry_BuildShiftEntry 24130 LD D,C Copy the byte value into D.
24131 LD E,B Copy the shift count into E.
24132 XOR A Clear the bits which are shifted out, in A.
GameEntry_ShiftByte 24133 SRL D Shift D right by one pixel.
24135 RR A Rotate the bit which fell off into the top of A.
24137 DEC E Decrease the shift count by one and loop back to GameEntry_ShiftByte until the byte has been shifted.
24138 JR NZ,GameEntry_ShiftByte
24140 INC H Move onto the second table of the pair.
24141 CPL Invert the bits which were shifted out.
24142 LD (HL),A Store them in the second table.
24143 DEC H Go back to the first table of the pair.
24144 LD A,D Fetch the shifted byte.
24145 CPL Invert it.
24146 LD (HL),A Store it in the first table.
24147 INC HL Move onto the next table entry.
24148 INC C Move onto the next byte value.
24149 JR NZ,GameEntry_BuildShiftEntry Jump back to GameEntry_BuildShiftEntry until all 256 byte values have been done.
24151 INC H Move past the second table of the pair.
24152 INC B Increase the shift by two pixels.
24153 INC B
24154 LD A,B Fetch the shift.
24155 CP 8 Jump back to GameEntry_BuildShiftTables until the shifts of two, four and six pixels have all been done.
24157 JR NZ,GameEntry_BuildShiftTables
24159 JP RunGame Start the game.
Prev: 23808 Up: Map Next: 24162