Prev: EA2F Up: Map Next: EB36
EA4A: Handler: Main Menu
Used by the routine at Game_Loop.
main-menu-cursor
Handler_MainMenu EA4A LD DE,$D874 DE=Score_Digit_01.
EA4D LD HL,$D86F HL=HighScore.
EA50 LD A,(DE) Load the first byte of the current score.
EA51 SUB (HL) Compare it with the first byte of the high score.
EA52 JP M,Print_Score/HighScore Jump to Print_Score/HighScore if the current score digit is less than the high score digit.
It's a new high score! Update what's stored.
EA55 LD A,(DE) Write the first score digit to the first highscore digit.
EA56 LD (HL),A
EA57 INC DE Increment the current score pointer by one.
EA58 INC HL Increment the high score pointer by one.
EA59 JR NZ,UpdateHighScore Jump to UpdateHighScore until the score digit is zero.
EA5B LD A,(DE) Load the second byte of the current score.
EA5C SUB (HL) Compare it with the second byte of the high score.
EA5D JP M,Print_Score/HighScore Jump to Print_Score/HighScore if the current score digit is less than the high score digit.
UpdateHighScore EA60 LD A,(DE) Write the second score digit to the second highscore digit.
EA61 LD (HL),A
Print the score of the last game and the high score.
Print_Score/HighScore EA62 LD B,$13 Set the X co-ordinate for the score display.
EA64 LD C,$0E Set the Y co-ordinate for the score display.
EA66 LD DE,$D874 DE=Score_Digit_01.
EA69 LD A,$06 Set the number of digits to print in A.
EA6B CALL Print_Numbers Call Print_Numbers.
EA6E LD B,$15 Set the X co-ordinate for the high score display.
EA70 LD C,$0E Set the Y co-ordinate for the high score display.
EA72 LD DE,$D86F DE=HighScore.
EA75 LD A,$06 Set the number of digits to print in A.
EA77 CALL Print_Numbers Call Print_Numbers.
Initialise the cursor/ pointer which highlights the currently selected menu item.
EA7A LD IX,($D877) IX=*SelectedMenuItem_ScreenPosition.
EA7E LD HL,$EB38 HL=SelectedMenuItem.
EA81 JR HighlightSelectedMenuItem Jump to HighlightSelectedMenuItem.
Maybe a debounce loop?
Debounce_Loop EA83 XOR A Get the player input from ALL half-rows (i.e. all the keys).
EA84 IN A,($FE)
EA86 CPL Invert the bits in A.
EA87 AND %00011111 Keep only bits 0-4.
EA89 JR NZ,Debounce_Loop Jump to Debounce_Loop if HL is not zero.
Get the player input.
MainMenuInput_Loop EA8B LD A,$F7 Read from the keyboard;
Port Number Bit
0 1 2 3 4
F7 1 2 3 4 5
EA8D IN A,($FE)
EA8F CPL Invert the bits in A.
EA90 AND %00011111 Mask for the key bits.
EA92 JR Z,MainMenuInput_Loop Jump back to MainMenuInput_Loop if no keys are being pressed.
Check which key was pressed and handle accordingly.
Handle "KEYBOARD" being selected.
EA94 RRA Jump to MainMenuInput_Kempston if "1" was not pressed.
EA95 JR NC,MainMenuInput_Kempston
EA97 LD A,$01 Jump back to Debounce_Loop if this menu item is already selected.
EA99 CP (HL)
EA9A JR Z,Debounce_Loop
EA9C CALL ClearSelectedMenuItem Call ClearSelectedMenuItem.
EA9F LD IX,$5843 Set the screen position for this option in IX.
EAA3 LD DE,$EB64 Set the address of the input control routine for this option in DE (InputHandler_Keyboard).
EAA6 JR UpdateMenuSelection Jump to UpdateMenuSelection.
Handle "KEMPSTON" being selected.
MainMenuInput_Kempston EAA8 RRA Jump to MainMenuInput_Cursor if "2" was not pressed.
EAA9 JR NC,MainMenuInput_Cursor
EAAB LD A,$02 Jump back to Debounce_Loop if this menu item is already selected.
EAAD CP (HL)
EAAE JR Z,Debounce_Loop
EAB0 CALL ClearSelectedMenuItem Call ClearSelectedMenuItem.
EAB3 LD IX,$58A3 Set the screen position for this option in IX.
EAB7 LD DE,$EB98 Set the address of the input control routine for this option in DE (InputHandler_Kempston).
EABA JR UpdateMenuSelection Jump to UpdateMenuSelection.
Handle "CURSOR" being selected.
MainMenuInput_Cursor EABC RRA Jump to MainMenuInput_Sinclair if "3" was not pressed.
EABD JR NC,MainMenuInput_Sinclair
EABF LD A,$03 Jump back to Debounce_Loop if this menu item is already selected.
EAC1 CP (HL)
EAC2 JR Z,Debounce_Loop
EAC4 CALL ClearSelectedMenuItem Call ClearSelectedMenuItem.
EAC7 LD IX,$5903 Set the screen position for this option in IX.
EACB LD DE,$EB9E Set the address of the input control routine for this option in DE (InputHandler_Cursor).
EACE JR UpdateMenuSelection Jump to UpdateMenuSelection.
Handle "SINCLAIR" being selected.
MainMenuInput_Sinclair EAD0 RRA Jump to MainMenuInput_StartGame if "4" was not pressed.
EAD1 JR NC,MainMenuInput_StartGame
EAD3 LD A,$04 Jump back to Debounce_Loop if this menu item is already selected.
EAD5 CP (HL)
EAD6 JR Z,Debounce_Loop
EAD8 CALL ClearSelectedMenuItem Call ClearSelectedMenuItem.
EADB LD IX,$5963 Set the screen position for this option in IX.
EADF LD DE,$EBCD Set the address of the input control routine for this option in DE (InputHandler_Sinclair).
Update menu selection.
UpdateMenuSelection EAE2 LD (HL),A Write the selected menu item to *SelectedMenuItem.
EAE3 LD ($EB36),DE Write the address of the input control routine to *Pointer_InputControl.
Point to selected menu item.
HighlightSelectedMenuItem EAE7 LD (IX+$00),$45 Write INK: CYAN, PAPER: BLACK (BRIGHT) to:
Offset Position
*IX+00 Top-left
*IX+01 Top-right
EAEB LD (IX+$01),$45
EAEF LD (IX+$20),$05 Write INK: CYAN, PAPER: BLACK to:
Offset Position
*IX+20 Bottom-left
*IX+21 Bottom-right
EAF3 LD (IX+$21),$05
EAF7 LD ($D877),IX Write IX to SelectedMenuItem_ScreenPosition.
EAFB JR Debounce_Loop Jump to Debounce_Loop.
Clear previous selected menu item.
ClearSelectedMenuItem EAFD LD (IX+$00),$00 Write INK: BLACK, PAPER: BLACK to:
Offset Position
*IX+00 Top-left
*IX+01 Top-right
*IX+20 Bottom-left
*IX+21 Bottom-right
EB01 LD (IX+$01),$00
EB05 LD (IX+$20),$00
EB09 LD (IX+$21),$00
EB0D RET Return.
Note; there's no need for the "not pressed" check, as there are only five options.
Handle "START GAME" being selected.
good-luck
Uncover the "Good Luck" messaging (it's already present, just black on black).
MainMenuInput_StartGame EB0E LD HL,$5A36 HL=5A36 (attribute buffer location).
EB11 LD DE,$0020 DE=0020.
EB14 LD B,$04 Set a counter in B for the number of rows to process.
GoodLuck_OuterLoop EB16 PUSH BC Stash the row counter on the stack.
EB17 LD B,$08 Set a counter in B for the width of the messaging.
EB19 PUSH HL Stash the starting position in the attribute buffer on the stack.
GoodLuck_InnerLoop EB1A LD (HL),$47 Write INK: WHITE, PAPER: BLACK (BRIGHT) to *HL.
EB1C INC HL Increment attribute buffer screen position by one.
EB1D DJNZ GoodLuck_InnerLoop Decrease width counter by one and loop back to GoodLuck_InnerLoop until all the width has been coloured.
EB1F POP HL Restore the attribute buffer starting position from the stack.
EB20 ADD HL,DE HL+=0020 (move down one row).
EB21 POP BC Restore the row counter from the stack.
EB22 DJNZ GoodLuck_OuterLoop Decrease the row counter by one and loop back to GoodLuck_OuterLoop until the row counter is zero.
EB24 LD HL,$EB39 Write 01 to EB39.
EB27 LD (HL),$01
EB29 PUSH HL Stash EB39 on the stack.
EB2A LD HL,$EB3A HL=EB3A.
EB2D LD B,$0E B=0E.
EB2F CALL $EF4A Call EF4A.
EB32 POP HL Restore HL from the stack.
EB33 LD (HL),$00 Write 00 to *HL.
EB35 RET Return.
Prev: EA2F Up: Map Next: EB36