Prev: 28564 Up: Map Next: 28745
28570: Collect User-Defined Keys
Used by the routine at TitleScreen_DefineKeysSelected.
CollectUserDefinedKeys 28570 LD A,1 Write 1 to *CurrentIndexUserDefinedKey.
28572 LD (28745),A
28575 LD HL,28525 HL=KeyboardKeymap.
Blank the first entry of all five user-defined key sets.
28578 LD B,5 B=5.
BlankUserDefinedKeys_Loop 28580 LD (HL),0 Write 0 to *HL.
28582 INC HL Increment HL by two.
28583 INC HL
28584 DJNZ BlankUserDefinedKeys_Loop Decrease counter by one and loop back to BlankUserDefinedKeys_Loop until counter is zero.
Debounce Loop.
UserDefinedKeyDebounce_Loop 28586 CALL 654 Call KEY_SCAN.
In all instances the E register is returned with a value in the range of +0 to +39 the value being different for each of the forty keys of the keyboard, or the value +255 for no-key.
28589 INC E Increment E by one.
28590 JR NZ,UserDefinedKeyDebounce_Loop Jump to UserDefinedKeyDebounce_Loop until E is zero (e.g. no keys are being pressed).
Get ready to collect keypresses.
28592 XOR A Write 0 to LAST-K (last key pressed).
28593 LD (23560),A
UserDefinedKeyCollectInput_Loop 28596 LD C,5 C=INK: CYAN, PAPER: BLACK .
28598 CALL FindUserDefinedKeyAttribute Call FindUserDefinedKeyAttribute.
UserDefinedKeyCollectInput 28601 CALL 703 Call KEYBOARD.
28604 BIT 5,(IY+1) Jump to UserDefinedKeyCollectInput if no key was pressed.
28608 JR Z,UserDefinedKeyCollectInput
28610 LD A,(23560) A=*LAST-K (last key pressed).
28613 CP 13 Jump to FindExistingKeyboardKeymap if A is equal to 13.
28615 JR Z,FindExistingKeyboardKeymap
28617 CP 32 Jump to FindExistingKeyboardKeymap if A is equal to 32.
28619 JR Z,FindExistingKeyboardKeymap
28621 CP 48 Jump to UserDefinedKeyCollectInput if A is lower than 48.
28623 JR C,UserDefinedKeyCollectInput
28625 CP 91 Jump to UserDefinedKeyCollectInput if A is higher than 91.
28627 JR NC,UserDefinedKeyCollectInput
28629 CP 65 Jump to FindExistingKeyboardKeymap if A is higher than 65.
28631 JR NC,FindExistingKeyboardKeymap
28633 CP 58 Jump to UserDefinedKeyCollectInput if A is higher than 58.
28635 JR NC,UserDefinedKeyCollectInput
Check if the key which has been pressed already exists for any other key.
FindExistingKeyboardKeymap 28637 LD HL,28525 HL=KeyboardKeymap.
28640 LD D,A Store the keypress in D.
28641 LD B,5 Set a counter in B as there are 5 keys to check in total.
FindExistingKeyboardKeymap_Loop 28643 LD A,(HL) Jump to UserDefinedKeyCollectInput if the current keypress already exists in the user-defined keymap table.
28644 CP D
28645 JR Z,UserDefinedKeyCollectInput
28647 INC HL Increment HL by two.
28648 INC HL
28649 DJNZ FindExistingKeyboardKeymap_Loop Decrease the keymap counter by one and loop back to FindExistingKeyboardKeymap_Loop until all keymaps have been checked.
The keypress is good, so find the keyboard keymap position we need to update.
28651 LD A,(28745) Set a counter in B of *CurrentIndexUserDefinedKey.
28654 LD B,A
28655 LD HL,28523 HL=28523 (e.g. KeyboardKeymap-2).
FindCurrentKeyboardKeymap_Loop 28658 INC HL Increment HL by two.
28659 INC HL
28660 DJNZ FindCurrentKeyboardKeymap_Loop Decrease counter by one and loop back to FindCurrentKeyboardKeymap_Loop until counter is zero.
28662 LD (HL),D Write the keypress to *HL and also stash it on the stack.
28663 PUSH DE
Calculate the screen co-ordinates.
B, the row, is a simple calculation of: 24-*CurrentIndexUserDefinedKey.
C, the column, will always be 11.
28664 LD B,A Calculate the screen co-ordinates for the index currently in-focus and store them in BC.
28665 LD A,24
28667 SUB B
28668 LD B,A
28669 LD C,11
Convert the screen co-ordinates into a screen buffer location pointer.
28671 CALL 3554 Call 3554 (CL_SET).
28674 POP DE Fetch the keypress from the stack and store it in A.
28675 LD A,D
Handle printing keywords for control keys (which are still valid as choose-able keys).
28676 CP 13 Jump to Print_Enter if "enter" is the keypress.
28678 JR Z,Print_Enter
28680 CP 32 Jump to Print_Space if "space" is the keypress.
28682 JR Z,Print_Space
Else, it's a printable character so display it.
28684 RST 16 Print the character to the screen.
PrintWhitespace 28685 LD B,4 Set a counter in B to print 4 ASCII spaces.
PrintWhitespace_Loop 28687 LD A,32 Print an ASCII space " ".
28689 RST 16
28690 DJNZ PrintWhitespace_Loop Decrease the space counter by one and loop back to PrintWhitespace_Loop until the counter is zero.
28692 LD C,7 C=INK: WHITE, PAPER: BLACK .
28694 CALL FindUserDefinedKeyAttribute Call FindUserDefinedKeyAttribute.
Move to the next user-defined key index.
28697 LD A,(28745) A=*CurrentIndexUserDefinedKey.
28700 INC A Increment A by one.
28701 LD (28745),A Write A to *CurrentIndexUserDefinedKey.
28704 CP 6 Keep jumping back to UserDefinedKeyCollectInput_Loop until all user-defined keys have been collected.
28706 JR NZ,UserDefinedKeyCollectInput_Loop
28708 RET Return.
Prints the word "SPACE".
Print_Space 28709 LD HL,31297 HL=Messaging_Space.
28712 CALL 6269 Call OUT_LINE2.
28715 JR PrintWhitespace Jump to PrintWhitespace.
Prints the word "ENTER".
Print_Enter 28717 LD HL,31303 HL=Messaging_Enter.
28720 CALL 6269 Call OUT_LINE2.
28723 JR PrintWhitespace Jump to PrintWhitespace.
22539+(32*CurrentIndexUserDefinedKey) to find the attribute buffer address for the user-defined key currently being processed.
FindUserDefinedKeyAttribute 28725 LD HL,22539 HL=22539 (attribute buffer location).
28728 LD DE,32 DE=0032.
28731 LD A,(28745) A=*CurrentIndexUserDefinedKey.
FindUserDefinedKeyAttribute_Loop 28734 ADD HL,DE HL+=0032.
28735 DEC A Decrease the index by one.
28736 JR NZ,FindUserDefinedKeyAttribute_Loop Keep jumping back to FindUserDefinedKeyAttribute_Loop until the index is zero.
HL now holds a pointer to the attribute line for the user-defined key currently being processed.
28738 LD B,20 Set a counter in B for 20 character blocks to "paint".
SetUserDefinedKeyAttribute_Loop 28740 LD (HL),C Write the attribute byte held by C to *HL.
28741 INC HL Increment HL by one.
28742 DJNZ SetUserDefinedKeyAttribute_Loop Decrease counter by one and loop back to SetUserDefinedKeyAttribute_Loop until counter is zero.
28744 RET Return.
Prev: 28564 Up: Map Next: 28745