Advertisement
Guest User

Untitled

a guest
Mar 7th, 2020
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. ;KBDINIT - initializes 8042/8242 PS/2 keyboard controller
  2. ;Affects: A, B, C, Z
  3. ;Returns result code in B:
  4. ;0x00 - OK
  5. ;0x01 - Controller self test failed
  6. ;0x02 - CLK stuck low
  7. ;0x03 - CLK stuck high
  8. ;0x04 - KBD DATA stuck low
  9. ;0x05 - KBD DATA stuck high
  10. ;0x06 - Interface didn't pass the test
  11. ;0x07 - Keyboard reset failure/no keyboard present
  12. KBDINIT:
  13. ;1. Disable devices
  14. CALL KBDWAITINBUF ;Send 0xAD command to the PS/2 controller
  15. MVI A, 0ADH
  16. OUT KBD_CMD
  17. ;2. Flush The Output Buffer
  18. IN KBD_STATUS
  19. ANI 01H ;Check if there is data to flush
  20. JZ KBDCRTLSET ;No? Next step then
  21. IN KBD_DATA ;Yes? Get the data byte
  22. KBDCRTLSET:
  23. ;3. Set the Controller Configuration Byte (temp)
  24. CALL KBDWAITINBUF ;Send 0x60 command to the PS/2 controller
  25. MVI A, 60H
  26. OUT KBD_CMD
  27. CALL KBDWAITINBUF ;Send actual configuration byte
  28. MVI A, 08H ;Interrupts disabled, system flag set, first port clock enabled
  29. OUT KBD_DATA ;second port clock disabled, first port translation disabled
  30. ;4. Controller self test
  31. CALL KBDWAITINBUF
  32. MVI A, 0AAH ;Send 0xAA command to the PS/2 controller
  33. OUT KBD_CMD
  34. CALL KBDWAITOUTBUF ;Wait for response
  35. IN KBD_DATA ;Get byte
  36. CPI 55H ;Is it 0x55?
  37. MVI B, 01H ;Return result code if not
  38. RNZ ;No? Return then
  39. ;5. Interface test
  40. CALL KBDWAITINBUF
  41. MVI A, 0ABH ;Send 0xAB command
  42. OUT KBD_CMD
  43. CALL KBDWAITOUTBUF ;Wait for response
  44. IN KBD_DATA ;Get byte
  45. CPI 01H ;Check if it is CLK stuck low error
  46. MVI B, 02H ;Return result code if it is
  47. RZ
  48. CPI 02H ;Check if it is CLK stuck high error
  49. MVI B, 03H ;Return result code if it is
  50. RZ
  51. CPI 03H ;Check if it is KBD DATA stuck low error
  52. MVI B, 04H ;Return result code if it is
  53. RZ
  54. CPI 04H ;Check if it is KBD DATA stuck high error
  55. MVI B, 05H ;Return result code if it is
  56. RZ
  57. CPI 00H ;Is it 0x00? Did it pass the test?
  58. MVI B, 06H ;Return result code if not
  59. RNZ ;No? Return then
  60. ;6. Enable Devices
  61. CALL KBDWAITINBUF
  62. MVI A, 0AEH ;Send 0xAE command
  63. OUT KBD_CMD
  64. ;7. Reset Device
  65. CALL KBDWAITINBUF ;Wait untill ready to send
  66. MVI A, 0FFH ;Send 0xFF to device
  67. OUT KBD_DATA ;Send it to device, not the controller
  68. MVI C, 130 ;Setup DELAY routine
  69. CALL DELAY ;This is required to avoid freeze
  70. CALL KBDWAITOUTBUF ;Wait for response
  71. IN KBD_DATA ;Get byte
  72. CPI 0FAH ;Is it 0xFA? 0xFC means failure. No response means no device present.
  73. MVI B, 07H ;Return result code if not
  74. RNZ ;No? Return then
  75. ;8. Set the Controller Configuration Byte (final)
  76. CALL KBDWAITINBUF ;Send 0x60 command to the PS/2 controller
  77. MVI A, 60H
  78. OUT KBD_CMD
  79. CALL KBDWAITINBUF ;Send actual configuration byte
  80. MVI A, 09H ;Interrupts enabled, system flag set, first port clock enabled
  81. OUT KBD_DATA ;second port clock disabled, first port translation disabled
  82. ;9. Zero out buffer
  83. MVI A, 00H
  84. STA KBDDATA ;Zero KBDDATA
  85. STA KBDKRFL ;Zero key release flag
  86. STA KBDSFFL ;Zero shift flag
  87. STA KBDOLD ;Zero old data
  88. STA KBDNEW ;Zero new data
  89. MVI B, 00H ;Return result code
  90. RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement