keyboard_reader.s 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. KEY_SHIFT1 EQU 30
  2. KEY_SHIFT2 EQU 31
  3. KEY_RETURN EQU 59-63
  4. KEY_DELETE EQU 62-63
  5. CURSOR_UP EQU 51-63
  6. CURSOR_DOWN EQU 50-63
  7. CURSOR_LEFT EQU 48-63
  8. CURSOR_RIGHT EQU 49-63
  9. F1_KEY EQU 47-63
  10. F2_KEY EQU 46-63
  11. F3_KEY EQU 45-63
  12. F4_KEY EQU 44-63
  13. F5_KEY EQU 43-63
  14. F6_KEY EQU 42-63
  15. F7_KEY EQU 41-63
  16. F8_KEY EQU 40-63
  17. ************************************************
  18. ** KEYBOARD READING ROUTINE **
  19. ************************************************
  20. Read_Keyboard
  21. clr.l d0
  22. move.b $bfec01,d0
  23. ror.b d0
  24. btst.l #7,d0
  25. beq.s Key_Not_Pressed
  26. andi.b #$7f,d0
  27. tst.w Key_Status
  28. beq.s User_Key_Pressed
  29. cmp.w Last_Key,d0
  30. bne.s User_Key_Pressed
  31. moveq.l #0,d0
  32. rts
  33. Key_Not_Pressed
  34. cmp.w #KEY_SHIFT1,d0
  35. beq.s Shift_Released
  36. cmp.w #KEY_SHIFT2,d0
  37. bne.s Not_Shift_Released
  38. Shift_Released
  39. clr.w Shift_Down
  40. Not_Shift_Released
  41. clr.w Key_Status
  42. moveq.l #0,d0
  43. rts
  44. User_Key_Pressed
  45. cmp.w #KEY_SHIFT1,d0
  46. beq.s Shift_Pressed
  47. cmp.w #KEY_SHIFT2,d0
  48. bne.s Not_Shift_Pressed
  49. Shift_Pressed
  50. move.w #1,Shift_Down
  51. clr.l d0
  52. rts
  53. Not_Shift_Pressed
  54. move.w d0,Last_Key
  55. move.w #1,Key_Status ;key has been pressed
  56. *convert Key code
  57. cmp.w #126,d0
  58. bgt.s Not_Char_Key
  59. key_in_range
  60. sub.w #63,d0 ;start from 0
  61. blt.s Not_Char_Key
  62. tst.w Shift_Down
  63. beq.s Choose_Shift_Up_Chars
  64. move.l #Chars_With_Shift,a0
  65. bra.s Get_Key_Char
  66. Choose_Shift_Up_Chars
  67. move.l #Chars_No_Shift,a0
  68. Get_Key_Char
  69. move.b (a0,d0),d0
  70. rts
  71. Not_Char_Key
  72. rts
  73. Shift_Down
  74. dc.w 0
  75. Key_Status
  76. dc.w 0
  77. Last_Key
  78. dc.w 0
  79. Chars_No_Shift
  80. dc.b " /.,mnbvcxz" ;63-78
  81. dc.b " ';lkjhgfds" ;79-94
  82. dc.b "a poiuytrew" ;95-110
  83. dc.b "q \=-0987654321" ;111-126
  84. Chars_With_Shift
  85. dc.b " ?><MNBVCXZ"
  86. dc.b " :LKJHGFDS"
  87. dc.b "A POIUYTREW"
  88. dc.b "Q |+_)(*&^%$#@!"