Prev: 5D00 Up: Map Next: 5E62
5E00: 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 F512) 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 5E27.
Set up the machine.
GameEntry 5E00 DI Disable interrupts.
5E01 LD SP,$5B70 Put the stack just below the game variables.
5E04 LD ($5CF1),IY Remember IY in SavedIY, as the ROM interrupt routine needs it to point at the system variables.
5E08 XOR A Set the border colour to black.
5E09 OUT ($FE),A
Move the title sequence out of the game data.
5E0B LD DE,$F500 DE is F500 (the destination).
5E0E LD HL,$E5BB Set HL to ScreenBuffer (the source).
5E11 LD BC,$0200 BC is 0200 (the number of bytes to copy).
5E14 LDIR Copy the title sequence code.
5E16 LD DE,$F700 DE is F700 (the destination).
5E19 LD HL,$E696 Set HL to E696 (the source).
5E1C LD BC,$0800 BC is 0800 (the number of bytes to copy).
5E1F LDIR Copy the title sequence graphics.
Run the title sequence.
5E21 CALL ClearScreen Call ClearScreen to clear the pixels of the screen.
5E24 CALL ResetAttributes Call ResetAttributes to set the attributes of the lower two thirds of the screen to bright white on black.
5E27 CALL $F512 Call the title sequence.
Build the bit reversal table at F900.
5E2A LD HL,$F900 HL is F900 (the start of the table).
5E2D LD C,$00 Set the table index in C to 00.
GameEntry_BuildReverseTable 5E2F LD B,$08 Set the bit counter in B to 08.
5E31 LD D,C Copy the table index into D.
5E32 XOR A Clear the reversed value in A.
GameEntry_ReverseBits 5E33 SLA D Shift the top bit of D out into the carry flag.
5E35 RR A Rotate the carry flag into the top of the reversed value.
5E37 DJNZ GameEntry_ReverseBits Decrease the bit counter by one and loop back to GameEntry_ReverseBits until all eight bits have been reversed.
5E39 LD (HL),A Store the reversed value in the table.
5E3A INC HL Move onto the next table entry.
5E3B INC C Move onto the next table index.
5E3C JR NZ,GameEntry_BuildReverseTable Jump back to GameEntry_BuildReverseTable until all 0100 entries have been written.
Build the three pairs of shift tables at FA00 FC00 and FE00. 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.
5E3E LD B,$02 Start with a shift of two pixels.
GameEntry_BuildShiftTables 5E40 LD C,$00 Start with the byte value 00.
GameEntry_BuildShiftEntry 5E42 LD D,C Copy the byte value into D.
5E43 LD E,B Copy the shift count into E.
5E44 XOR A Clear the bits which are shifted out, in A.
GameEntry_ShiftByte 5E45 SRL D Shift D right by one pixel.
5E47 RR A Rotate the bit which fell off into the top of A.
5E49 DEC E Decrease the shift count by one and loop back to GameEntry_ShiftByte until the byte has been shifted.
5E4A JR NZ,GameEntry_ShiftByte
5E4C INC H Move onto the second table of the pair.
5E4D CPL Invert the bits which were shifted out.
5E4E LD (HL),A Store them in the second table.
5E4F DEC H Go back to the first table of the pair.
5E50 LD A,D Fetch the shifted byte.
5E51 CPL Invert it.
5E52 LD (HL),A Store it in the first table.
5E53 INC HL Move onto the next table entry.
5E54 INC C Move onto the next byte value.
5E55 JR NZ,GameEntry_BuildShiftEntry Jump back to GameEntry_BuildShiftEntry until all 0100 byte values have been done.
5E57 INC H Move past the second table of the pair.
5E58 INC B Increase the shift by two pixels.
5E59 INC B
5E5A LD A,B Fetch the shift.
5E5B CP $08 Jump back to GameEntry_BuildShiftTables until the shifts of two, four and six pixels have all been done.
5E5D JR NZ,GameEntry_BuildShiftTables
5E5F JP RunGame Start the game.
Prev: 5D00 Up: Map Next: 5E62