XDEF Keypad XREF __SEG_END_SSTACK,Debounce,KVS,pressed_key,pressed_num,PORT_U,SEQUENCE,PORT_S,await_key_release,keypad_timeout,await_key_press Variables: Section Constants: Section Code: Section Keypad: ;push register and accumulator values for retention PSHA PSHB PSHD PSHX PSHY ;do not go to the task at the end of the array ;when first starting i.e. ckip ArrayEnd for now BRA InitSequence ArrayEnd: ;check the flag to await or not (await for passwords) LDAB await_key_press CMPB #$00 ;await is false BEQ Return ;don't do anything else (do not await a keypress) ;otherwise re-initialze the sequence InitSequence: LDX #SEQUENCE ;load the sequence into the X register ReadKeypress: ;check wether or not to await LDAA 1,X+ ;load the value at address in reg X to A CMPA #$00 ;check the value of A to zero BEQ ArrayEnd ;this is the end of the array ; ; ; ;given in instructions STAA PORT_U ;output to port U JSR Debounce ;delay 1 ms LDAA PORT_U ;read port U back into acc. A STAA pressed_key ;save the value of acc. A into memory (the value of the KVS array) ANDA #$0F ;mask the upper nibble CMPA #$0F ;check if masked A == #$0F (no key pressed) BEQ ReadKeypress ;send the next item in the sequence ; ; ; ;skip the release wait if the variable is set LDAA await_key_release CMPA #$00 BEQ InitLookup AwaitRelease: ;a key is pressed LDAA PORT_U ;read port U ANDA #$0F ;mask the upper nibble CMPA #$0F ;check if masked A == #$0F (no key pressed) BNE AwaitRelease ;wait for the key to be released InitLookup: ;check for a match in the lookup table LDY #KVS ;load the initital value of KVS array LDAB #$00 ;iteration counter Lookup: LDAA 1,Y+ ;load a value from the lookup table into A CMPA pressed_key ;compare the LUT value to the pressed key BEQ Found ;pressed key reached/found within LUT INCB ;increment the counter BRA Lookup ;check the value at the next index Found: STAB pressed_num ;the index of the PRESSED value (the numeral of the pressed key) in the KVS/LUT from B -> memory ;AwaitPress: ; LDAB await_key_press ; CMPB #$FF ; BEQ InitSequence Return: ;clear the keypad timeout ;CLR keypad_timeout ;restore registers and accumulators PULY PULX PULD PULB PULA RTS