![]() |
Routines |
| Prev: 53615 | Up: Map | Next: 53772 |
|
Used by the routines at TitleScreen and Restart_SetUserDefinedKeys.
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| SetUserDefinedKeys | 53640 | LD A,0 | Reset *Current_UserDefinedKey to 0. | |||||||||||||||||||||||||||||||||||
| 53642 | LD (53772),A | |||||||||||||||||||||||||||||||||||||
| 53645 | LD A,36 | Write Keyboard Input (36) to *ControlMethod. | ||||||||||||||||||||||||||||||||||||
| 53647 | LD (23530),A | |||||||||||||||||||||||||||||||||||||
|
Don't clear the whole screen. Leave the header from the title screen.
|
||||||||||||||||||||||||||||||||||||||
| 53650 | LD B,18 | Clear the bottom 18 lines using CL_LINE. | ||||||||||||||||||||||||||||||||||||
| 53652 | CALL 3652 | |||||||||||||||||||||||||||||||||||||
| UserDefinedKeys_Loop | 53655 | LD DE,56011 | DE=Messaging_DefineKeys. | |||||||||||||||||||||||||||||||||||
| 53658 | CALL PrintString | Call PrintString. | ||||||||||||||||||||||||||||||||||||
|
Pause to let the message sink in...
|
||||||||||||||||||||||||||||||||||||||
| 53661 | LD B,10 | B=10 (pause loops). | ||||||||||||||||||||||||||||||||||||
| UserDefinedKeys_PauseLoop | 53663 | PUSH BC | Stash BC on the stack. | |||||||||||||||||||||||||||||||||||
| 53664 | CALL SmallPause | Call SmallPause. | ||||||||||||||||||||||||||||||||||||
| 53667 | POP BC | Restore BC from the stack. | ||||||||||||||||||||||||||||||||||||
| 53668 | DJNZ UserDefinedKeys_PauseLoop | Decrease counter by one and loop back to UserDefinedKeys_PauseLoop until counter is zero. | ||||||||||||||||||||||||||||||||||||
|
Display each (current) user-defined key, and the relevant messaging.
|
||||||||||||||||||||||||||||||||||||||
| 53670 | LD A,0 | Call PrintUserDefinedKey using key position: 0. | ||||||||||||||||||||||||||||||||||||
| 53672 | CALL PrintUserDefinedKey | |||||||||||||||||||||||||||||||||||||
| 53675 | LD A,1 | Call PrintUserDefinedKey using key position: 1. | ||||||||||||||||||||||||||||||||||||
| 53677 | CALL PrintUserDefinedKey | |||||||||||||||||||||||||||||||||||||
| 53680 | LD A,2 | Call PrintUserDefinedKey using key position: 2. | ||||||||||||||||||||||||||||||||||||
| 53682 | CALL PrintUserDefinedKey | |||||||||||||||||||||||||||||||||||||
| 53685 | LD A,3 | Call PrintUserDefinedKey using key position: 3. | ||||||||||||||||||||||||||||||||||||
| 53687 | CALL PrintUserDefinedKey | |||||||||||||||||||||||||||||||||||||
| 53690 | LD A,4 | Call PrintUserDefinedKey using key position: 4. | ||||||||||||||||||||||||||||||||||||
| 53692 | CALL PrintUserDefinedKey | |||||||||||||||||||||||||||||||||||||
|
Fetch the user input.
|
||||||||||||||||||||||||||||||||||||||
| UserDefinedKeys_InputLoop | 53695 | CALL 654 | Call KEY_SCAN. | |||||||||||||||||||||||||||||||||||
| 53698 | LD A,E | Loop back to UserDefinedKeys_InputLoop until any key has been pressed. | ||||||||||||||||||||||||||||||||||||
| 53699 | CP 255 | |||||||||||||||||||||||||||||||||||||
| 53701 | JR Z,UserDefinedKeys_InputLoop | |||||||||||||||||||||||||||||||||||||
| 53703 | CP 32 | Jump to CheckForDuplicates if "SPACE" has been pressed (32). | ||||||||||||||||||||||||||||||||||||
| 53705 | JP Z,CheckForDuplicates | |||||||||||||||||||||||||||||||||||||
| 53708 | PUSH AF | Stash the keypress on the stack briefly. | ||||||||||||||||||||||||||||||||||||
|
Create an offset for the currently in-focus key position using DE.
|
||||||||||||||||||||||||||||||||||||||
| 53709 | LD A,(53772) | E=*Current_UserDefinedKey. | ||||||||||||||||||||||||||||||||||||
| 53712 | LD E,A | |||||||||||||||||||||||||||||||||||||
| 53713 | POP AF | Restore the keypress from the stack. | ||||||||||||||||||||||||||||||||||||
| 53714 | LD D,0 | D=0 (to finish creating the offset for the current key position using DE). | ||||||||||||||||||||||||||||||||||||
| 53716 | LD HL,23531 | HL=UserDefinedKeys_Left+DE. | ||||||||||||||||||||||||||||||||||||
| 53719 | ADD HL,DE | |||||||||||||||||||||||||||||||||||||
| 53720 | LD (HL),A | Write the keypress code to the appropriate position in the user-defined keys table held by *HL. | ||||||||||||||||||||||||||||||||||||
|
A small pause loop to give the user a chance to release the key.
|
||||||||||||||||||||||||||||||||||||||
| 53721 | LD B,2 | B=2 (pause loops). | ||||||||||||||||||||||||||||||||||||
| UserDefinedKeys_Debounce | 53723 | PUSH BC | Stash BC on the stack. | |||||||||||||||||||||||||||||||||||
| 53724 | CALL SmallPause | Call SmallPause. | ||||||||||||||||||||||||||||||||||||
| 53727 | POP BC | Restore BC from the stack. | ||||||||||||||||||||||||||||||||||||
| 53728 | DJNZ UserDefinedKeys_Debounce | Decrease counter by one and loop back to UserDefinedKeys_Debounce until counter is zero. | ||||||||||||||||||||||||||||||||||||
|
Move onto the next key position.
|
||||||||||||||||||||||||||||||||||||||
| 53730 | LD A,(53772) | Increment *Current_UserDefinedKey by one. | ||||||||||||||||||||||||||||||||||||
| 53733 | INC A | |||||||||||||||||||||||||||||||||||||
| 53734 | LD (53772),A | |||||||||||||||||||||||||||||||||||||
| 53737 | CP 5 | Loop back to UserDefinedKeys_Loop until all 5 keys have been defined. | ||||||||||||||||||||||||||||||||||||
| 53739 | JP NZ,UserDefinedKeys_Loop | |||||||||||||||||||||||||||||||||||||
|
Each value is checked against other values ahead of it. It doesn't need to check "behind" as e.g. consider the following table:
On the 1st cycle; 1 is checked against 2 3 4 and 5.
So on the 2nd cycle, there's no need to check 2 against 1 as this already happened in the 1st cycle.
And so on...
|
||||||||||||||||||||||||||||||||||||||
| CheckForDuplicates | 53742 | LD B,4 | Set a counter; there are 4 other keys to check at the beginning of the cycle. | |||||||||||||||||||||||||||||||||||
| 53744 | LD HL,23531 | Set a pointer in HL to the beginning of the key storage: UserDefinedKeys_Left. | ||||||||||||||||||||||||||||||||||||
| CheckForDuplicates_Loop | 53747 | PUSH BC | Stash the current key map counter on the stack (this is reduced by one on each cycle). | |||||||||||||||||||||||||||||||||||
| 53748 | LD A,(HL) | Does nothing, this is immediately overwritten in the loop below. | ||||||||||||||||||||||||||||||||||||
|
Clone HL into DE to prepare for the checking loop.
|
||||||||||||||||||||||||||||||||||||||
| 53749 | PUSH HL | DE=HL (using the stack). | ||||||||||||||||||||||||||||||||||||
| 53750 | POP DE | |||||||||||||||||||||||||||||||||||||
|
Process this cycle. *HL points to the current "checking" key map value, and DE is incremented on each cycle to check against it.
|
||||||||||||||||||||||||||||||||||||||
| CheckForDuplicates_CheckLoop | 53751 | INC DE | *DE will contain the comparison key map value, so increment DE by one. | |||||||||||||||||||||||||||||||||||
| 53752 | LD A,(DE) | If there's a match between *DE and *HL, jump to Restart_SetUserDefinedKeys and get the user to try again. | ||||||||||||||||||||||||||||||||||||
| 53753 | CP (HL) | |||||||||||||||||||||||||||||||||||||
| 53754 | JP Z,Restart_SetUserDefinedKeys | |||||||||||||||||||||||||||||||||||||
| 53757 | DJNZ CheckForDuplicates_CheckLoop | Decrease the key map counter by one and loop back to CheckForDuplicates_CheckLoop until all key map values have been checked. | ||||||||||||||||||||||||||||||||||||
|
This cycle is finished, so prepare for the next one.
|
||||||||||||||||||||||||||||||||||||||
| 53759 | POP BC | Restore the key map counter from the stack. | ||||||||||||||||||||||||||||||||||||
| 53760 | INC HL | Move the value pointer to the next value. | ||||||||||||||||||||||||||||||||||||
| 53761 | DEC B | Decrease the key map counter by one, each cycle checks one less key value. | ||||||||||||||||||||||||||||||||||||
| 53762 | JR NZ,CheckForDuplicates_Loop | Jump to CheckForDuplicates_Loop until all key map values have been checked. | ||||||||||||||||||||||||||||||||||||
|
We are good! Clear the screen and move back to the title screen.
|
||||||||||||||||||||||||||||||||||||||
| 53764 | LD B,18 | Clear the bottom 18 lines using CL_LINE. | ||||||||||||||||||||||||||||||||||||
| 53766 | CALL 3652 | |||||||||||||||||||||||||||||||||||||
| 53769 | JP Print_TitleScreen | Jump to Print_TitleScreen. | ||||||||||||||||||||||||||||||||||||
| Prev: 53615 | Up: Map | Next: 53772 |