Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.5KB

  1. ; kbd - implement GetC for PS/2 keyboard
  2. ;
  3. ; Status: Work in progress. See recipes/rc2014/ps2
  4. ;
  5. ; *** Defines ***
  6. ; The port of the device where we read scan codes. See recipe rc2014/ps2.
  7. ; KBD_PORT
  8. ; *** Variables ***
  9. .equ KBD_SKIP_NEXT KBD_RAMSTART
  10. .equ KBD_RAMEND KBD_SKIP_NEXT+1
  11. kbdInit:
  12. xor a
  13. ld (KBD_SKIP_NEXT), a
  14. ret
  15. kbdGetC:
  16. in a, (KBD_PORT)
  17. or a
  18. jr z, .nothing
  19. ; scan code not zero, maybe we have something.
  20. ; Do we need to skip it?
  21. push af ; <|
  22. ld a, (KBD_SKIP_NEXT) ;|
  23. or a ; |
  24. jr nz, .skip ; |
  25. pop af ; <|
  26. cp 0x80
  27. jr nc, .outOfBounds
  28. ; No need to skip, code within bounds, we have something! Let's see if
  29. ; there's a ASCII code associated to it.
  30. push hl ; <|
  31. ld hl, kbdScanCodes ; |
  32. call addHL ; |
  33. ld a, (hl) ; |
  34. pop hl ; <|
  35. or a
  36. jp z, unsetZ ; no code. Keep A at 0, but unset Z
  37. ; We have something!
  38. cp a ; ensure Z
  39. ret
  40. .outOfBounds:
  41. ; A scan code over 0x80 is out of bounds. Ignore.
  42. ; If F0 (break code) or E0 (extended code), we also skip the next code
  43. cp 0xf0
  44. jr z, .skipNext
  45. cp 0xe0
  46. jr z, .skipNext
  47. xor a
  48. jp unsetZ
  49. .skipNext:
  50. ld (KBD_SKIP_NEXT), a
  51. xor a
  52. jp unsetZ
  53. .skip:
  54. pop af ; equilibrate stack
  55. xor a
  56. ld (KBD_SKIP_NEXT), a
  57. jp unsetZ
  58. .nothing:
  59. ; We have nothing. Before we go further, we'll wait a bit to give our
  60. ; device the time to "breathe". When we're in a "nothing" loop, the z80
  61. ; hammers the device really fast and continuously generates interrupts
  62. ; on it and it interferes with its other task of reading the keyboard.
  63. push bc
  64. ld b, 0
  65. .wait:
  66. nop
  67. djnz .wait
  68. pop bc
  69. jp unsetZ
  70. ; A list of the values associated with the 0x80 possible scan codes of the set
  71. ; 2 of the PS/2 keyboard specs. 0 means no value. That value is a character than
  72. ; can be read in a GetC routine. No make code in the PS/2 set 2 reaches 0x80.
  73. kbdScanCodes:
  74. ; 0x00 1 2 3 4 5 6 7 8 9 a b c d e f
  75. .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,'`', 0
  76. ; 0x10 9 = TAB
  77. .db 0, 0, 0, 0, 0,'q','1', 0, 0, 0,'z','s','a','w','2', 0
  78. ; 0x20 32 = SPACE
  79. .db 0,'c','x','d','e','4','3', 0, 0, 32,'v','f','t','r','5', 0
  80. ; 0x30
  81. .db 0,'n','b','h','g','y','6', 0, 0, 0,'m','j','u','7','8', 0
  82. ; 0x40 59 = ;
  83. .db 0,',','k','i','o','0','9', 0, 0,'.','/','l', 59,'p','-', 0
  84. ; 0x50 13 = RETURN 39 = '
  85. .db 0, 0, 39, 0,'[','=', 0, 0, 0, 0, 13,']', 0,'\', 0, 0
  86. ; 0x60 8 = BKSP
  87. .db 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0
  88. ; 0x70 27 = ESC
  89. .db 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0