ogkeypad.asm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ;
  2. ;keypad.asm
  3. ;
  4. XDEF Keypad
  5. XREF __SEG_END_SSTACK,OneMSDelay,KVS,PRESSED,PRESSED_VAL,PORT_U,SEQUENCE
  6. Variables: Section
  7. Constants: Section
  8. Code: Section
  9. Keypad: ;push register and accumulator values for retention
  10. PSHA
  11. PSHB
  12. PSHX
  13. PSHY
  14. InitSequence:
  15. LDX #SEQUENCE ;load the sequence into the X register
  16. ReadKeypress:
  17. LDAA 1,X+ ;load the value at address in reg X to A
  18. CMPA #$00 ;reached the last value in the sequence
  19. BEQ InitSequence ;re-initialize X
  20. STAA PORT_U ;output to port U
  21. JSR OneMSDelay ;delay 1 ms
  22. LDAA PORT_U ;read port U back into acc. A
  23. STAA PRESSED ;save the value of acc. A into memory (the value of the KVS array)
  24. ANDA #$0F ;mask the upper nibble
  25. CMPA #$0F ;check if masked A == #$0F (no key pressed)
  26. BEQ ReadKeypress ;send the next item in the sequence
  27. AwaitRelease: ;a key is pressed
  28. LDAA PORT_U ;read port U
  29. ANDA #$0F ;mask the upper nibble
  30. CMPA #$0F ;check if masked A == #$0F (no key pressed)
  31. BNE AwaitRelease ;wait for the key to be released
  32. InitLookup: ;check for a match in the lookup table
  33. LDY #KVS ;load the initital value of KVS array
  34. LDAB #$00 ;iteration counter
  35. Lookup:
  36. LDAA 1,Y+ ;load a value from the lookup table into A
  37. CMPA PRESSED ;compare the LUT value to the pressed key
  38. BEQ Found ;pressed key reached/found within LUT
  39. INCB ;increment the counter
  40. BRA Lookup ;check the value at the next index
  41. Found:
  42. STAB PRESSED_VAL ;the index of the PRESSED value (the numeral of the pressed key) in the KVS/LUT from B -> memory
  43. Close: ;restore registers and accumulators
  44. PULY
  45. PULX
  46. PULB
  47. PULA
  48. RTS