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.

103 lines
1.7KB

  1. ; kbd - implement FetchKC for SMS PS/2 adapter
  2. ;
  3. ; Implements KBD_FETCHKC for the adapter described in recipe sms/kbd. It does
  4. ; so for both Port A and Port B (you hook whichever you prefer).
  5. ; FetchKC on Port A
  6. smskbdFetchKCA:
  7. ; Before reading a character, we must first verify that there is
  8. ; something to read. When the adapter is finished filling its '164 up,
  9. ; it resets the latch, which output's is connected to TL. When the '164
  10. ; is full, TL is low.
  11. ; Port A TL is bit 4
  12. in a, (0xdc)
  13. and 0b00010000
  14. jr nz, .nothing
  15. push bc
  16. in a, (0x3f)
  17. ; Port A TH output, low
  18. ld a, 0b11011101
  19. out (0x3f), a
  20. nop
  21. nop
  22. in a, (0xdc)
  23. ; bit 3:0 are our dest bits 3:0. handy...
  24. and 0b00001111
  25. ld b, a
  26. ; Port A TH output, high
  27. ld a, 0b11111101
  28. out (0x3f), a
  29. nop
  30. nop
  31. in a, (0xdc)
  32. ; bit 3:0 are our dest bits 7:4
  33. rlca \ rlca \ rlca \ rlca
  34. and 0b11110000
  35. or b
  36. ex af, af'
  37. ; Port A/B reset
  38. ld a, 0xff
  39. out (0x3f), a
  40. ex af, af'
  41. pop bc
  42. ret
  43. .nothing:
  44. xor a
  45. ret
  46. ; FetchKC on Port B
  47. smskbdFetchKCB:
  48. ; Port B TL is bit 2
  49. in a, (0xdd)
  50. and 0b00000100
  51. jr nz, .nothing
  52. push bc
  53. in a, (0x3f)
  54. ; Port B TH output, low
  55. ld a, 0b01110111
  56. out (0x3f), a
  57. nop
  58. nop
  59. in a, (0xdc)
  60. ; bit 7:6 are our dest bits 1:0
  61. rlca \ rlca
  62. and 0b00000011
  63. ld b, a
  64. in a, (0xdd)
  65. ; bit 1:0 are our dest bits 3:2
  66. rlca \ rlca
  67. and 0b00001100
  68. or b
  69. ld b, a
  70. ; Port B TH output, high
  71. ld a, 0b11110111
  72. out (0x3f), a
  73. nop
  74. nop
  75. in a, (0xdc)
  76. ; bit 7:6 are our dest bits 5:4
  77. rrca \ rrca
  78. and 0b00110000
  79. or b
  80. ld b, a
  81. in a, (0xdd)
  82. ; bit 1:0 are our dest bits 7:6
  83. rrca \ rrca
  84. and 0b11000000
  85. or b
  86. ex af, af'
  87. ; Port A/B reset
  88. ld a, 0xff
  89. out (0x3f), a
  90. ex af, af'
  91. pop bc
  92. ret
  93. .nothing:
  94. xor a
  95. ret