Prev: 31767 Up: Map Next: 31888
31769: Game Initialisation
Used by the routine at SecurityCheck.
Clears the first 16 bytes of the game variables, selects the main font and then runs the game selection menu. The menu is drawn by GameMenu and the keyboard is scanned for the keys "1" to "6" and "0" until "0" is pressed. Each key changes the control method or the character stored in GameOptions and moves the highlight on the menu, and "0" starts the game at StartGame. The entry point at Game_Restart is also used to return to the menu when a game ends.
Clear the first 16 bytes of the game variables.
GameInitialisation 31769 LD HL,24064 Point HL at the game options at GameOptions.
31772 LD B,16 B=16 (the number of bytes to clear).
GameInitialisation_Loop 31774 LD (HL),0 Clear a byte of the game variables.
31776 INC HL Move HL on to the next byte of the game variables.
31777 DJNZ GameInitialisation_Loop Decrease the byte counter by one and loop back to GameInitialisation_Loop until all 16 bytes have been cleared.
31779 LD HL,48716 Write 48716 (the main font, see MainFont) to FontPointer.
31782 LD (24065),HL
This entry point is used by the routine at GameOver.
Clear the screen and draw the icons for the menu.
Game_Restart 31785 CALL ClearScreen Call ClearScreen to clear the screen.
31788 CALL MenuIcons Call MenuIcons to draw the icons of the menu.
Each pass of this loop draws the menu and handles one scan of the keyboard.
GameSelect_Loop 31791 CALL GameMenu Call GameMenu to show the game selection menu.
31794 LD A,247 Read from the keyboard;
Port Number Bit
0 1 2 3 4
247 1 2 3 4 5
31796 OUT (253),A
31798 IN A,(254)
31800 CPL Flip the bits, so that a set bit is a key which is pressed.
31801 LD E,A Keep the keys that are pressed in E.
31802 LD A,(24064) Fetch the game options.
Handle "Keyboard" selection.
31805 BIT 0,E Jump to GameSelect_CheckKempston if key "1" is not being pressed ("KEYBOARD").
31807 JR Z,GameSelect_CheckKempston
31809 AND %11111001 Keep only bits 0 and 3-7, so the control method is the keyboard (0).
Handle "Kempston Joystick" selection.
GameSelect_CheckKempston 31811 BIT 1,E Jump to GameSelect_CheckCursor if key "2" is not being pressed ("KEMPSTON JOYSTICK").
31813 JR Z,GameSelect_CheckCursor
31815 AND %11111001 Keep only bits 0 and 3-7.
31817 OR %00000010 Set the control method to Kempston joystick (2).
Handle "Cursor Joystick" selection.
GameSelect_CheckCursor 31819 BIT 2,E Jump to GameSelect_CheckKnight if key "3" is not being pressed ("CURSOR JOYSTICK").
31821 JR Z,GameSelect_CheckKnight
31823 AND %11111001 Keep only bits 0 and 3-7.
31825 OR %00000100 Set the control method to cursor joystick (4).
Handle "Knight" selection.
GameSelect_CheckKnight 31827 BIT 3,E Jump to GameSelect_CheckWizard if key "4" is not being pressed ("KNIGHT").
31829 JR Z,GameSelect_CheckWizard
31831 AND %11100111 Keep only bits 0-2 and 5-7, so the character is the knight (0).
Handle "Wizard" selection.
GameSelect_CheckWizard 31833 BIT 4,E Jump to GameSelect_SecondRow if key "5" is not being pressed ("WIZARD").
31835 JR Z,GameSelect_SecondRow
31837 AND %11100111 Keep only bits 0-2 and 5-7.
31839 OR %00001000 Set the character to the wizard (8).
Save the options so far and read the second row of keys.
GameSelect_SecondRow 31841 LD D,A Keep the options so far in D.
31842 LD A,239 Read from the keyboard;
Port Number Bit
0 1 2 3 4
239 0 9 8 7 6
31844 OUT (253),A
31846 IN A,(254)
31848 CPL Flip the bits, so that a set bit is a key which is pressed.
31849 LD E,A Keep the keys that are pressed in E.
31850 LD A,D Fetch the options so far.
Handle "Serf" selection.
GameSelect_CheckSerf 31851 BIT 4,E Jump to GameSelect_StoreOptions if key "6" is not being pressed ("SERF").
31853 JR Z,GameSelect_StoreOptions
31855 AND %11100111 Keep only bits 0-2 and 5-7.
31857 OR %00010000 Set the character to the serf (16).
Write the options back and keep a copy in C.
GameSelect_StoreOptions 31859 LD (24064),A Write the options back to GameOptions.
31862 LD C,A Keep a copy of the options in C.
Handle starting a new game.
GameSelect_Start 31863 BIT 0,E Jump to StartGame if key "0" is being pressed ("START GAME").
31865 JP NZ,StartGame
Highlight the selected control method, then the selected character.
31868 LD HL,31978 Point HL at the game select attribute table at GameSelection_Attributes.
31871 LD B,3 B=3 (the number of control method entries).
31873 LD A,C Fetch the options.
31874 CALL FlashSelection Call FlashSelection to highlight the selected menu entry.
31877 LD B,3 B=3 (the number of character entries).
31879 LD A,C Fetch the options.
31880 RRCA Rotate A right twice, which brings the character bits into position.
31881 RRCA
31882 CALL FlashSelection Call FlashSelection to highlight the selected menu entry.
31885 JP GameSelect_Loop Jump back to GameSelect_Loop to run the menu again.
View the equivalent code in;
Prev: 31767 Up: Map Next: 31888