keyboard_reader.s 1.7 KB

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