Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Paste Description for PS/2 driver

The PS/2 driver of the ToasterOS.
Includes keyboard driver and mouse driver.

PS/2 driver
Friday, July 27th, 2007 at 3:16:32am MDT 

  1. ; **********************************************************
  2.  
  3. ;       Name: PS/2 Keyboard & Mouse driver
  4. ;       Type: Virtual Device Driver
  5. ;       Autor: Peter Kleissner
  6. ;       Version: 1.00
  7.  
  8. ; **********************************************************
  9.  
  10. [bits 32]
  11. CPU 386
  12.  
  13. %define Type_User
  14. %include "interface.asm"
  15.  
  16. %define Char(number2)    number2
  17. %define Param(number)    [ebp+16 + 4*(number-1)]
  18. %define Param1   [ebp+16 + 4*0]
  19. %define Param2   [ebp+16 + 4*1]
  20. %define Param3   [ebp+16 + 4*2]
  21. %define Param4   [ebp+16 + 4*3]
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. ; function splitter
  29. ;   
  30. ;    API invoke_driver, driver, function, Param1, Param2, ...
  31.  
  32. Enter_System
  33.  
  34.  
  35. ; Initialize?
  36. cmp Param2,dword 0
  37. je initialize
  38.  
  39. ; set address
  40. call Get_address
  41.  
  42. ; Switch Key Table?
  43. cmp Param2,dword 1
  44. je Switch_Key_Table
  45.  
  46. ; Set Scroll Led?
  47. cmp Param2,dword 2
  48. je Set_Scroll_led
  49.  
  50. ; Get Key states?
  51. cmp Param2,dword 3
  52. je Get_Key_states
  53.  
  54. ; Return last Key?
  55. cmp Param2,dword 4
  56. je Return_last_key
  57.  
  58. ; Resend last Key?
  59. cmp Param2,dword 5
  60. je Resend_last_key
  61.  
  62. ; Retrieve last Key?
  63. cmp Param2,dword 6
  64. je Retrieve_last_key
  65.  
  66.  
  67. Leave_System  Invalid_Function, 1
  68.  
  69. ret
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. initialize:
  79.  
  80. ; Param3 = base of vxd
  81.  
  82. Enter_nonInterruption
  83.  
  84. mov edx,Param3
  85. mov [edx + Get_address + 1],edx
  86.  
  87.  
  88.  
  89. ; ---- keyboard control ----
  90. Keyboard_Control:
  91.  
  92. ; link the IRQ 1 with the Keyboard Handler
  93. mov ebx,Param3
  94. add ebx,Keyboard_Handler
  95. API Set_IRQ, 1, ebx
  96.  
  97.  
  98. ; set the Scancode Set
  99. kb_comm_low  Keyboard_init_abort, 0f0h
  100. kb_write Keyboard_init_abort, 0
  101.  
  102.  
  103. ; set the leds
  104. call Set_leds
  105. jc Keyboard_init_abort
  106.  
  107.  
  108. ; set the Typematic rate
  109. kb_comm_low  Keyboard_init_abort, 0f3h
  110. kb_write Keyboard_init_abort, [edx + Typematic_rate]
  111.  
  112.  
  113. ; enable the Keyboard and start scanning
  114. ;kb_comm  Keyboard_init_abort, 0f4h
  115. kb_comm_low  Keyboard_init_abort, 0f4h
  116.  
  117.  
  118. ; set default key values
  119. mov [edx + CapsLock],byte 0
  120. mov [edx + NumLock],byte 0
  121. mov [edx + Rollen],byte 0
  122. mov [edx + PressedKeys],byte 0
  123. mov [edx + Extended_key],byte 0
  124. mov [edx + Keyboard],dword 1
  125.  
  126.  
  127.  
  128.  
  129. ; ---- mouse control ----
  130. Mouse_Control:
  131. %if 0 = 1
  132. ; link the IRQ 12 with the Mouse Handler
  133. mov ebx,Param3
  134. add ebx,Mouse_Handler
  135. API Set_IRQ, 12, ebx
  136.  
  137.  
  138. ; deactivate the Keyboard
  139. kb_comm  Mouse_abort, 0adh
  140.  
  141.  
  142. ; enable the mouse port
  143. kb_comm  Mouse_abort, 0a8h
  144. ;kb_read  Mouse_abort
  145. m_read
  146.  
  147.  
  148. ; enable the device
  149. kb_comm  Mouse_abort, 020h
  150. kb_read  Mouse_abort
  151. ;m_read
  152. or al,3
  153. push ax
  154. kb_comm  Mouse_abort, 060h
  155. pop ax
  156. kb_write Mouse_abort, al
  157.  
  158.  
  159. ; reset the mouse (100 samples/sec, 4 counts/mm, 1:1)
  160. kb_comm  Mouse_abort, 0d4h
  161. kb_comm_low  Mouse_abort, 0f6h
  162.  
  163.  
  164. ; enable data reporting
  165. kb_comm  Mouse_abort, 0d4h
  166. kb_comm_low  Mouse_abort, 0f4h
  167. kb_read  Mouse_abort
  168. ;m_read
  169.  
  170.  
  171. ; activate the Keyboard
  172. kb_comm  Mouse_abort, 0aeh
  173.  
  174.  
  175. ; mark the Mouse as available
  176. mov [edx+Mouse],dword 1
  177.  
  178. %endif
  179.  
  180.  
  181. ; ---- external mouse control ----
  182. %if 0 = 1
  183. ; link the IRQ 12 with the Mouse Handler
  184. mov ebx,Param3
  185. add ebx,Mouse_Handler
  186. API Set_IRQ, 12, ebx
  187.  
  188. call PS2_External_Mouse_Control
  189. jmp PS2_Main_Control
  190. PS2_External_Mouse_Control:
  191. incbin "PS2Mouse.bin"
  192. PS2_Main_Control:
  193. %endif
  194.  
  195. ; ---- PS/2 main control ----
  196.  
  197. ; input 3 bytes, else the driver wouldn't work (???)
  198. in al,60h
  199.  
  200.  
  201.  
  202. Leave_nonInterruption
  203. Connect_Exit:
  204. Leave_System
  205.  
  206. ret
  207.  
  208.  
  209.  
  210.  
  211. Keyboard_init_abort:
  212. ;  create a timer
  213.  
  214. ; resume the mouse mounting
  215. jmp Mouse_Control
  216.  
  217.  
  218. Mouse_abort:
  219. ;  create a timer
  220.  
  221. ; activate the Keyboard (it may be left in a deactivated state)
  222. kb_comm  Connect_Exit, 0aeh
  223.  
  224. Leave_nonInterruption
  225. jmp Connect_Exit
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. Switch_Key_Table:
  239.  
  240. ; SPI Set_Keyboard_Layout, Table
  241.  
  242. ; Table = "eu" for europe, "us" for american keyboard layout
  243.  
  244.  
  245. cmp Param3,dword 'eu'
  246. je Switch_Key_Table_eu
  247.  
  248. cmp Param3,dword 'us'
  249. je Switch_Key_Table_us
  250.  
  251. jmp Switch_Key_Table_Exit
  252.  
  253.  
  254. Switch_Key_Table_eu:
  255. mov [edx + Take_Key_Table],dword 0
  256. jmp Switch_Key_Table_Exit
  257.  
  258.  
  259. Switch_Key_Table_us:
  260. mov [edx + Take_Key_Table],dword 1
  261.  
  262.  
  263. Switch_Key_Table_Exit:
  264. Leave_System
  265.  
  266. ret
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. Set_Scroll_led:
  277.  
  278. ; undocumented
  279.  
  280.  
  281. ; clear the led bit (default)
  282. clear_bit [edx + Led_locks], 1
  283.  
  284. ; only bit 0 is significant in the Param3
  285. mov eax,Param3
  286. or eax,1
  287. or [edx + Led_locks],eax
  288.  
  289. ; set the (maybe) new leds
  290. call Set_leds
  291.  
  292.  
  293. Leave_System
  294.  
  295. ret
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305. Get_Key_states:
  306.  
  307. ; SPI Get_Key_states
  308.  
  309. ; return = record of
  310. ;   {
  311. ;      PressedKeys
  312. ;         bit 0: shift left
  313. ;         bit 1: ctrl left
  314. ;         bit 2: alt (unused)
  315. ;         bit 3: del (unused)
  316. ;         bit 4: caps lock
  317. ;         bit 5: ctrl right
  318. ;         bit 6: ctrl (unused)
  319. ;         bit 7: shift right
  320. ;         bit 8: shift (unused)
  321. ;         bit 9: rollen
  322. ;         bit 10: num lock
  323. ;     
  324. ;      CapsLock (key state)
  325. ;      NumLock (key state)
  326. ;      Rollen (key state)
  327. ;      Alt_Gr (key state)
  328. ;     
  329. ;      Led_locks
  330. ;      Typematic_rate
  331. ;   }
  332.  
  333.  
  334. API New, 6
  335. mov edi,eax
  336.  
  337. mov ax,[edx + PressedKeys]
  338. stosw
  339.  
  340. mov al,[edx + CapsLock]
  341. stosb
  342.  
  343. mov al,[edx + NumLock]
  344. stosb
  345.  
  346. mov al,[edx + Rollen]
  347. stosb
  348.  
  349. mov al,[edx + Alt_Gr]
  350. stosb
  351.  
  352. mov al,[edx + Led_locks]
  353. stosb
  354.  
  355. mov al,[edx + Typematic_rate]
  356. stosb
  357.  
  358.  
  359. mov eax,edi
  360. sub eax,6
  361. Leave_System
  362.  
  363. ret
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373. Return_last_key:
  374.  
  375. ; SPI Return_last_key
  376.  
  377. ; return = record of
  378. ;   {
  379. ;     
  380. ;      LastKey
  381. ;      LastKeyExt
  382. ;      LastKeyEvent
  383. ;     
  384. ;   }
  385.  
  386.  
  387. API New, 12
  388. mov edi,eax
  389.  
  390. mov eax,[edx + LastKey]
  391. stosd
  392. mov eax,[edx + LastKeyExt]
  393. stosd
  394. mov eax,[edx + LastKeyEvent]
  395. stosd
  396.  
  397.  
  398. mov eax,edi
  399. sub eax,12
  400. Leave_System
  401.  
  402. ret
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412. Resend_last_key:
  413.  
  414. ; SPI Resend_last_key
  415.  
  416. ; resends the last key to the user, as it was
  417.  
  418.  
  419. ; send the key to the top (active) window
  420. mov esi,Top_Window
  421. mov edi,TWC_link.Handle(esi)
  422. API Send_Message, TWC_link.ProcessHandle(esi), edi, [edx + LastKeyEvent], [edx + LastKey], [edx + LastKeyExt]
  423.  
  424.  
  425. Leave_System
  426.  
  427. ret
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437. Retrieve_last_key:
  438.  
  439. ; SPI Retrieve_last_key
  440.  
  441. ; given direct to the keyboard, resend last scancode
  442.  
  443.  
  444. ; Keyboard command
  445. ;   FEh  sngl   resend last scancode
  446.  
  447. kb_comm_low  Public_Keyboard_Error, 0feh
  448.  
  449.  
  450. xor eax,eax
  451. Leave_System
  452.  
  453. ret
  454.  
  455.  
  456.  
  457.  
  458.  
  459. Public_Keyboard_Error:
  460.  
  461. mov eax,Keyboard_abort
  462.  
  463. Leave_System
  464.  
  465. ret
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476. Get_address:
  477.  
  478. mov edx,dword 0FFFF00FFh
  479.  
  480. ; other method:
  481. ;    set the start address
  482. ;    mov edx,[Global_Offset_Table + 1*16 + 7]
  483.  
  484. ret
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500. Keyboard_Handler:
  501.  
  502. ; define the variables
  503. %define ScanCode  [ebp-4]
  504. %define KeyEvent  [ebp-8]
  505. %define ExtCode      [ebp-12]
  506. %define System_Stack          12
  507.  
  508. Enter_driver
  509. call Get_address
  510.  
  511.  
  512. xor eax,eax
  513. mov KeyEvent,dword 0
  514. mov ScanCode,dword 0
  515. mov ExtCode,dword 0
  516.  
  517.  
  518. ; check if there is a scancode
  519. in al,64h
  520. test al,00000001b
  521. jz Keyboard_Handler_Exit
  522.  
  523. ; input the scancode
  524. in al,60h
  525.  
  526.  
  527. ; are one (E0h) or two (E1h) scancodes following ?
  528. cmp al,0E0h
  529. je Keyboard_Handler_E?h
  530. cmp al,0E1h
  531. je Keyboard_Handler_E?h
  532. cmp al,0FAh
  533. je Keyboard_Handler_Exit
  534.  
  535. ; if extended jump
  536. cmp [edx + Extended_key],byte 1
  537. je Take_Extended_Key_Table
  538.  
  539.  
  540.  
  541. ; set the KeyEvent
  542. ;    If EventCode = 0 then
  543. ;      KeyEvent = KEY_DOWN
  544. ;    Else
  545. ;      KeyEvent = KEY_UP
  546. Set_Key_Event:
  547. test al,10000000b
  548. jz Keyboard_Handler_down
  549.  
  550. Keyboard_Handler_up:
  551. mov KeyEvent,dword WM_KEYUP
  552. jmp Keyboard_Handler_ok
  553.  
  554. Keyboard_Handler_down:
  555. mov KeyEvent,dword WM_KEYDOWN
  556.  
  557. Keyboard_Handler_ok:
  558. ; only the scancode is significant
  559. and eax,01111111b
  560.  
  561.  
  562.  
  563.  
  564. ; take the correct Key Tables for ascii keys
  565. cmp [edx + Take_Key_Table],byte 0
  566. jne Take_Key_Table_american
  567.  
  568.  
  569.  
  570. Take_Key_Table_europe:
  571.  
  572. ; sort out ascii keys
  573. check_bounds 2, 13, 2, Take_Key_Table_europe_ascii
  574. check_bounds 16, 27, 2+2, Take_Key_Table_europe_ascii
  575. check_bounds 30, 41, 2+2+2, Take_Key_Table_europe_ascii
  576. check_bounds 43, 53, 2+2+2+1, Take_Key_Table_europe_ascii
  577. check_bounds 86, 86, 2+2+2+1+32, Take_Key_Table_europe_ascii
  578.  
  579. ; sort out imm keys
  580. check_bounds 0, 1, 0, Take_Key_Table_imm
  581. check_bounds 14, 15, 12, Take_Key_Table_imm
  582. check_bounds 28, 28, 12*2, Take_Key_Table_imm
  583. check_bounds 57, 57, 12*2+28, Take_Key_Table_imm
  584. check_bounds 59, 68, 12*2+28+1, Take_Key_Table_imm
  585. check_bounds 87, 88, 12*2+28+1+18, Take_Key_Table_imm
  586.  
  587. ; sort out numblock keys
  588. check_bounds 69, 69, 0, Take_Key_Table_num_lock
  589. check_bounds 71, 83, 71, Take_Key_Table_numblock
  590. check_bounds 55, 55, 0, Take_Key_Table_numblock_mul
  591.  
  592. ; sort out direct translation keys
  593. check_bounds 58, 58, 0, Take_Key_Table_caps_lock
  594. check_bounds 29, 29, 0, Take_Key_Table_ctrl_left
  595. check_bounds 42, 42, 0, Take_Key_Table_shift_left
  596. check_bounds 54, 54, 0, Take_Key_Table_shift_right
  597. check_bounds 56, 56, 0, Take_Key_Table_alt_left
  598. check_bounds 70, 70, 0, Take_Key_Table_rollen
  599.  
  600. ; store the unknown key for intelli genuine ToasterOS use
  601. mov [edx + UnknownKey],al
  602. mov bl,KeyEvent
  603. mov [edx + UnknownKey + 1],bl
  604. jmp Keyboard_Handler_Exit
  605.  
  606.  
  607.  
  608.  
  609. Take_Key_Table_american:
  610.  
  611. ; sort out ascii keys
  612. check_bounds 2, 13, 2, Take_Key_Table_american_ascii
  613. check_bounds 16, 27, 2+2, Take_Key_Table_american_ascii
  614. check_bounds 30, 41, 2+2+2, Take_Key_Table_american_ascii
  615. check_bounds 43, 53, 2+2+2+1, Take_Key_Table_american_ascii
  616. check_bounds 86, 86, 2+2+2+1+32, Take_Key_Table_american_ascii
  617.  
  618. ; sort out imm keys
  619. check_bounds 0, 1, 0, Take_Key_Table_imm
  620. check_bounds 14, 15, 12, Take_Key_Table_imm
  621. check_bounds 28, 28, 12*2, Take_Key_Table_imm
  622. check_bounds 57, 57, 12*2+28, Take_Key_Table_imm
  623. check_bounds 59, 68, 12*2+28+1, Take_Key_Table_imm
  624. check_bounds 87, 88, 12*2+28+1+18, Take_Key_Table_imm
  625.  
  626. ; sort out numblock keys
  627. check_bounds 69, 69, 0, Take_Key_Table_num_lock
  628. check_bounds 71, 83, 71, Take_Key_Table_numblock
  629. check_bounds 55, 55, 0, Take_Key_Table_numblock_mul
  630.  
  631. ; sort out direct translation keys
  632. check_bounds 58, 58, 0, Take_Key_Table_caps_lock
  633. check_bounds 29, 29, 0, Take_Key_Table_ctrl_left
  634. check_bounds 42, 42, 0, Take_Key_Table_shift_left
  635. check_bounds 54, 54, 0, Take_Key_Table_shift_right
  636. check_bounds 56, 56, 0, Take_Key_Table_alt_left
  637. check_bounds 70, 70, 0, Take_Key_Table_rollen
  638.  
  639. ; store the unknown key for intelli genuine ToasterOS use
  640. mov [edx + UnknownKey],al
  641. mov bl,KeyEvent
  642. mov [edx + UnknownKey + 1],bl
  643. jmp Keyboard_Handler_Exit
  644.  
  645.  
  646.  
  647.  
  648. Take_Extended_Key_Table:
  649. mov [edx + Extended_key],byte 0
  650.  
  651. ; sort out (extra) break codes, AAh and 2Ah are not significant
  652. check_bounds 170, 170, 0, Keyboard_Handler_Exit
  653. check_bounds 42, 42, 0, Keyboard_Handler_Exit
  654.  
  655.  
  656. ; suppose make code
  657. mov KeyEvent,dword WM_KEYDOWN
  658.  
  659. ; sort out middle block keys
  660. check_bounds 71, 73, 71, Take_Key_Table_middle_block
  661. check_bounds 75, 75, 71+1, Take_Key_Table_middle_block
  662. check_bounds 77, 77, 71+1+1, Take_Key_Table_middle_block
  663. check_bounds 79, 83, 71+1+1+1, Take_Key_Table_middle_block
  664.  
  665. ; sort out direct translation keys
  666. check_bounds 53, 53, 0, Take_Key_Table_numblock_div
  667. check_bounds 55, 55, 0, Take_Key_Table_print_screen
  668. check_bounds 56, 56, 0, Take_Key_Table_alt_gr
  669. check_bounds 84, 84, 0, Take_Key_Table_print_screen
  670. check_bounds 86, 86, 0, Set_Key_Event
  671. check_bounds 91, 91, 0, Take_Key_Table_left_win
  672. check_bounds 92, 92, 0, Take_Key_Table_right_win
  673. check_bounds 93, 93, 0, Take_Key_Table_popup
  674.  
  675.  
  676. ; suppose break code
  677. mov KeyEvent,dword WM_KEYUP
  678.  
  679. ; sort out middle block keys
  680. check_bounds 198, 198, 0, Take_Key_Table_pause
  681. check_bounds 199, 201, 199, Take_Key_Table_middle_block
  682. check_bounds 203, 203, 199+1, Take_Key_Table_middle_block
  683. check_bounds 205, 205, 199+1+1, Take_Key_Table_middle_block
  684. check_bounds 207, 211, 199+1+1+1, Take_Key_Table_middle_block
  685.  
  686. ; sort out direct translation keys
  687. check_bounds 181, 181, 0, Take_Key_Table_numblock_div
  688. check_bounds 183, 183, 0, Take_Key_Table_print_screen
  689. check_bounds 184, 184, 0, Take_Key_Table_alt_gr
  690. check_bounds 212, 212, 0, Take_Key_Table_print_screen
  691. check_bounds 214, 214, 0, Set_Key_Event
  692. check_bounds 219, 219, 0, Take_Key_Table_left_win
  693. check_bounds 220, 220, 0, Take_Key_Table_right_win
  694. check_bounds 221, 221, 0, Take_Key_Table_popup
  695.  
  696.  
  697. ; the most special pause key
  698. Test_Key_Pause_scan_code1:
  699. cmp al,01Dh
  700. jne Test_Key_Pause_scan_code3
  701. mov [edx + Extended_key],byte 1
  702. jmp Keyboard_Handler_Exit
  703.  
  704. ; the 2nd code 45h won't be test, because if its one of the make code, the next e0h
  705. ; activates this handler by default
  706.  
  707. Test_Key_Pause_scan_code3:
  708. cmp al,09Dh
  709. jne Test_Key_Pause_scan_code4
  710. mov [edx + Extended_key],byte 1
  711. jmp Keyboard_Handler_Exit
  712.  
  713. Test_Key_Pause_scan_code4:
  714. cmp al,197
  715. je Take_Key_Table_pause
  716.  
  717.  
  718. ; store the unknown key for intelli genuine ToasterOS use
  719. mov [edx + UnknownKey],al
  720. mov bl,KeyEvent
  721. mov [edx + UnknownKey + 1],bl
  722. jmp Keyboard_Handler_Exit
  723.  
  724.  
  725.  
  726.  
  727.  
  728. Take_Key_Table_europe_ascii:
  729. ; ascii means keys which are visible
  730.  
  731. cmp [edx + Alt_Gr],byte 1
  732. je Take_Key_Table_europe_ascii_alt_gr
  733.  
  734. cmp [edx + CapsLock],byte 1
  735. je Take_Key_Table_europe_ascii_shift
  736.  
  737.  
  738. Take_Key_Table_europe_ascii_normal:
  739. movzx ebx,byte [edx + Key_Table_europe_ascii + eax]
  740. jmp Send_Key
  741.  
  742.  
  743. Take_Key_Table_europe_ascii_shift:
  744. movzx ebx,byte [edx + Key_Table_europe_ascii_shift + eax]
  745. jmp Send_Key
  746.  
  747.  
  748. Take_Key_Table_europe_ascii_alt_gr:
  749. check_bounds 3, 4, 3, Take_Key_Table_europe_ascii_alt_gr_set
  750. check_bounds 8, 12, 3*2, Take_Key_Table_europe_ascii_alt_gr_set
  751. check_bounds 16, 16, 3*3, Take_Key_Table_europe_ascii_alt_gr_set
  752. check_bounds 18, 18, 3*3+1, Take_Key_Table_europe_ascii_alt_gr_set
  753. check_bounds 27, 27, 3*3+1+8, Take_Key_Table_europe_ascii_alt_gr_set
  754. check_bounds 50, 50, 3*3+1+8+22, Take_Key_Table_europe_ascii_alt_gr_set
  755. check_bounds 86, 86, 3*3+1+8+22+35, Take_Key_Table_europe_ascii_alt_gr_set
  756. jmp Keyboard_Handler_Exit
  757.  
  758.  
  759. Take_Key_Table_europe_ascii_alt_gr_set:
  760. movzx ebx,byte [edx + Key_Table_europe_ascii_alt_gr + eax]
  761. jmp Send_Key
  762.  
  763.  
  764.  
  765.  
  766. Take_Key_Table_american_ascii:
  767. ; ascii means keys which are visible
  768.  
  769. cmp [edx + CapsLock],byte 1
  770. je Take_Key_Table_american_ascii_shift
  771.  
  772. Take_Key_Table_american_ascii_normal:
  773. movzx ebx,byte [edx + Key_Table_american_ascii + eax]
  774. jmp Send_Key
  775.  
  776. Take_Key_Table_american_ascii_shift:
  777. movzx ebx,byte [edx + Key_Table_american_ascii_shift + eax]
  778. jmp Send_Key
  779.  
  780.  
  781.  
  782.  
  783. Take_Key_Table_imm:
  784. ; imm means keys which are immediately to translate and send
  785.  
  786. movzx ebx,byte [edx + Key_Table_imm + eax]
  787. jmp Send_Key
  788.  
  789.  
  790.  
  791. Take_Key_Table_numblock:
  792. ; numblock means keys of the numblock
  793.  
  794. cmp [edx + NumLock],byte 1
  795. je Take_Key_Table_numblock_num
  796.  
  797. cmp [edx + NumLock],byte 2
  798. je Take_Key_Table_numblock_tec
  799.  
  800. movzx ecx,byte [edx + Key_Table_numblock_tec + eax]
  801. mov ExtCode,ecx
  802. movzx ebx,byte [edx + Key_Table_numblock + eax]
  803. jmp Send_Key
  804.  
  805. Take_Key_Table_numblock_tec:
  806. movzx ebx,byte [edx + Key_Table_numblock_tec + eax]
  807. mov ExtCode,ebx
  808. jmp Send_Key
  809.  
  810. Take_Key_Table_numblock_num:
  811. movzx ecx,byte [edx + Key_Table_numblock_tec + eax]
  812. mov ExtCode,ecx
  813. movzx ebx,byte [edx + Key_Table_numblock_num + eax]
  814. jmp Send_Key
  815.  
  816.  
  817.  
  818. Take_Key_Table_numblock_mul:
  819. ; key = mul (some part of the direct translation keys)
  820.  
  821. mov ebx,'*'
  822. mov ExtCode,dword VK_MULTIPLY
  823. jmp Send_Key
  824.  
  825.  
  826.  
  827. Take_Key_Table_numblock_div:
  828. ; key = div (part of the direct translation keys)
  829.  
  830. mov ebx,'/'
  831. mov ExtCode,dword VK_DIVIDE
  832. jmp Send_Key
  833.  
  834.  
  835.  
  836. Take_Key_Table_num_lock:
  837. ; key = num lock (some part of the direct translation keys)
  838.  
  839. ; if key event != key first then exit
  840. cmp KeyEvent,word WM_KEYDOWN
  841. jne Take_Key_Table_num_lock_clearbit
  842. key_press 10000000000b
  843.  
  844. invert_bool byte [edx + NumLock]
  845. invert_bit [edx + Led_locks], 10b
  846. call Set_leds
  847. jmp Keyboard_Handler_Exit
  848.  
  849. Take_Key_Table_num_lock_clearbit:
  850. clear_bit [edx + PressedKeys], 10000000000b
  851. jmp Keyboard_Handler_Exit
  852.  
  853.  
  854.  
  855. Take_Key_Table_caps_lock:
  856. ; key = caps lock (part of the direct translation keys)
  857.  
  858. ; if key event != key first then exit
  859. cmp KeyEvent,word WM_KEYDOWN
  860. jne Take_Key_Table_caps_lock_clearbit
  861. key_press 10000b
  862.  
  863. invert_bool byte [edx + CapsLock]
  864. invert_bit [edx + Led_locks], 100b
  865. call Set_leds
  866. jmp Keyboard_Handler_Exit
  867.  
  868.  
  869. Take_Key_Table_caps_lock_clearbit:
  870. clear_bit [edx + PressedKeys], 10000b
  871. jmp Keyboard_Handler_Exit
  872.  
  873.  
  874.  
  875. Take_Key_Table_rollen:
  876. ; rollen = scroll lock
  877.  
  878. ; if key event <> key first then exit
  879. cmp KeyEvent,word WM_KEYDOWN
  880. jne Take_Key_Table_rollen_clearbit
  881. key_press 1000000000b
  882.  
  883. invert_bool byte [edx + Rollen]
  884. invert_bit [edx + Led_locks], 1b
  885. call Set_leds
  886. jmp Keyboard_Handler_Exit
  887.  
  888. Take_Key_Table_rollen_clearbit:
  889. clear_bit [edx + PressedKeys], 1000000000b
  890. jmp Keyboard_Handler_Exit
  891.  
  892.  
  893.  
  894. Take_Key_Table_ctrl_left:
  895. ; key = ctrl left (part of the direct translation keys)
  896. ;   make and break code (bit 1: ctrl left)
  897.  
  898. key_press 10b
  899. mov ExtCode,dword VK_LCONTROL
  900. mov ebx,VK_CONTROL
  901. jmp Send_Key
  902.  
  903.  
  904.  
  905. Take_Key_Table_shift_left:
  906. ; key = shift left (part of the direct translation keys)
  907. ;   make and break code (bit 0: shift left)
  908.  
  909. key_press 1b
  910. invert_bool byte [edx + CapsLock]
  911. mov ExtCode,dword VK_LSHIFT
  912. mov ebx,VK_SHIFT
  913. jmp Send_Key
  914.  
  915.  
  916.  
  917. Take_Key_Table_shift_right:
  918. ; key = shift right (part of the direct translation keys)
  919. ;   make and break code (bit 7: shift right)
  920.  
  921. key_press 10000000b
  922. invert_bool byte [edx + CapsLock]
  923. mov ExtCode,dword VK_RSHIFT
  924. mov ebx,VK_SHIFT
  925. jmp Send_Key
  926.  
  927.  
  928.  
  929. Take_Key_Table_alt_left:
  930. ; key = alt left (part of the direct translation keys)
  931. ;   make and break code (bit 2: alt left)
  932.  
  933. key_press 100b
  934. mov ExtCode,dword VK_LMENU
  935. mov ebx,VK_MENU
  936. jmp Send_Key
  937.  
  938.  
  939.  
  940. Take_Key_Table_alt_gr:
  941. ;   only make code
  942.  
  943. ; alt gr = alt (for american)
  944. cmp [edx + Take_Key_Table],byte 0
  945. jne Take_Key_Table_alt_left
  946.  
  947. invert_bool byte [edx + Alt_Gr]
  948. jmp Keyboard_Handler_Exit
  949.  
  950.  
  951.  
  952. Take_Key_Table_print_screen:
  953.  
  954. ; copy screen to clipboard
  955. ;   - ?
  956.  
  957. mov ebx,VK_SNAPSHOT
  958. jmp Send_Key
  959.  
  960.  
  961.  
  962. Take_Key_Table_left_win:
  963.  
  964. ; show the win 3.1 Toolbar/menu
  965. ;   - ?
  966.  
  967. mov ebx,VK_LWIN
  968. jmp Send_Key
  969.  
  970.  
  971.  
  972. Take_Key_Table_right_win:
  973.  
  974. ; show the win 3.1 Toolbar/menu
  975. ;   - ?
  976.  
  977. mov ebx,VK_RWIN
  978. jmp Send_Key
  979.  
  980.  
  981.  
  982. Take_Key_Table_popup:
  983.  
  984. mov ebx,VK_APPS
  985. jmp Send_Key
  986.  
  987.  
  988.  
  989. Take_Key_Table_pause:
  990.  
  991. ; idle the system
  992. ;   - ?
  993.  
  994. mov ebx,VK_PAUSE
  995. jmp Send_Key
  996.  
  997.  
  998.  
  999. Take_Key_Table_middle_block:
  1000. ; middle block = keys of the middle block
  1001.  
  1002. movzx ebx,byte [edx + Key_Table_middle_block + eax]
  1003. jmp Send_Key
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009. Send_Key:
  1010. mov ScanCode,ebx
  1011. mov [edx + LastKey],ebx
  1012. mov ecx,ExtCode
  1013. mov [edx + LastKeyExt],ecx
  1014. mov ecx,KeyEvent
  1015. mov [edx + LastKeyEvent],ecx
  1016.  
  1017. ; if key <> 0 then send_key
  1018. or ebx,ebx
  1019. jz Keyboard_Handler_Exit
  1020.  
  1021. ; send the key to the topmost (active) window - if available
  1022. mov esi,Top_Window
  1023. or esi,esi
  1024. jnz Send_Key_process_known
  1025.  
  1026. Send_Key_process_unknown:
  1027. API Send_Message, 0, 0, KeyEvent, ScanCode, ExtCode
  1028.  
  1029. jmp Keyboard_Handler_Exit
  1030.  
  1031. Send_Key_process_known:
  1032. mov edi,TWC_link.Handle(esi)
  1033. API Send_Message, TWC_link.ProcessHandle(esi), edi, KeyEvent, ScanCode, ExtCode
  1034.  
  1035. jmp Keyboard_Handler_Exit
  1036.  
  1037.  
  1038.  
  1039. Keyboard_Handler_E?h:
  1040.   mov [edx + Extended_key],byte 1
  1041. jmp Keyboard_Handler_Exit
  1042.  
  1043.  
  1044.  
  1045. Keyboard_Handler_Exit:
  1046. Leave_driver
  1047. EOI_Master
  1048. EOI_Slave
  1049.  
  1050. iret
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057. Set_leds:
  1058.  
  1059.  
  1060. ; sets the leds by means of the led locks
  1061. kb_comm_low Set_leds_Exit, 0edh
  1062. kb_write    Set_leds_Exit, [edx + Led_locks]
  1063.  
  1064.  
  1065. Set_leds_Exit:
  1066.  
  1067. ret
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076. ; /* Public Keyboard Help Functions */
  1077.  
  1078.  
  1079.  
  1080. kbWrite:
  1081.  
  1082. ; a public OS developer routine to write something to the Keyboard
  1083. ; input(ah) = byte to send
  1084. ; return = 0 if successful, otherwise error (abort)
  1085.  
  1086.  
  1087. ; test for a transmit timeout
  1088. mov ecx,0FFFFh
  1089.  
  1090. Test_loop_1:
  1091. in al,64h
  1092. test al,00100000b
  1093. jz Test_loop_1_ok
  1094. loop Test_loop_1
  1095.  
  1096. stc
  1097. jmp kbWrite_Exit
  1098.  
  1099. Test_loop_1_ok:
  1100.  
  1101.  
  1102. ; ???
  1103. ;in al,60h
  1104.  
  1105.  
  1106. ; test if the input buffer is full
  1107. mov ecx,0FFFFh
  1108.  
  1109. Test_loop_2:
  1110. in al,64h
  1111. test al,00000010b
  1112. jz Test_loop_2_ok
  1113. loop Test_loop_2
  1114.  
  1115. stc
  1116. jmp kbWrite_Exit
  1117.  
  1118. Test_loop_2_ok:
  1119.  
  1120.  
  1121. ; send the byte out to port 60h
  1122. mov al,ah
  1123. out 60h,al
  1124. clc
  1125.  
  1126.  
  1127. kbWrite_Exit:
  1128.  
  1129. ret
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137. kbCommand_low:
  1138.  
  1139. ; a public OS developer routine to send a command to the Keyboard
  1140. ; input(ah) = command to send to port 60h instead of 64h
  1141.  
  1142.  
  1143. ; test if the input buffer is full
  1144. mov ecx,0FFFFh
  1145.  
  1146. Test_loop_6:
  1147. in al,64h
  1148. test al,00000010b
  1149. jz Test_loop_6_ok
  1150. loop Test_loop_6
  1151.  
  1152. stc
  1153. jmp kbWrite_Exit
  1154.  
  1155. Test_loop_6_ok:
  1156.  
  1157.  
  1158. ; send the command (at this time to port 60h)
  1159. mov al,ah
  1160. out 60h,al
  1161.  
  1162.  
  1163. ; test if the command acceptation
  1164. mov ecx,0FFFFh
  1165.  
  1166. Test_loop_7:
  1167. in al,64h
  1168. test al,00000010b
  1169. jz Test_loop_7_ok
  1170. loop Test_loop_7
  1171.  
  1172. stc
  1173. jmp kbWrite_Exit
  1174.  
  1175. Test_loop_7_ok:
  1176. clc
  1177.  
  1178.  
  1179. ret
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187. kbRead:
  1188.  
  1189. ; a public OS developer routine to read something of the Keyboard
  1190. ; return = read byte
  1191.  
  1192.  
  1193. ; test if the output buffer is full
  1194. mov ecx,0FFFFh
  1195.  
  1196. Test_loop_3:
  1197. in al,64h
  1198. test al,00000001b
  1199. jnz Test_loop_3_ok
  1200. loop Test_loop_3
  1201.  
  1202. stc
  1203. ret
  1204.  
  1205. Test_loop_3_ok:
  1206.  
  1207.  
  1208. ; delay for a short time
  1209. delay 32
  1210.  
  1211.  
  1212. ; input the byte
  1213. in al,60h
  1214.  
  1215. clc
  1216. ret
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224. kbCommand:
  1225.  
  1226. ; a public OS developer routine to send a command to the Keyboard
  1227. ; input(ah) = command to send
  1228.  
  1229.  
  1230. ; test if the input buffer is full
  1231. mov ecx,0FFFFh
  1232.  
  1233. Test_loop_4:
  1234. in al,64h
  1235. test al,00000010b
  1236. jz Test_loop_4_ok
  1237. loop Test_loop_4
  1238.  
  1239. stc
  1240. ret
  1241.  
  1242. Test_loop_4_ok:
  1243.  
  1244.  
  1245. ; send the command
  1246. mov al,ah
  1247. out 64h,al
  1248.  
  1249.  
  1250. ; test if the command has been accepted
  1251. mov ecx,0FFFFh
  1252.  
  1253. Test_loop_5:
  1254. in al,64h
  1255. test al,00000010b
  1256. jz Test_loop_5_ok
  1257. loop Test_loop_5
  1258.  
  1259. stc
  1260. ret
  1261.  
  1262. Test_loop_5_ok:
  1263. clc
  1264.  
  1265.  
  1266. ret
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275. Mouse_Handler:
  1276.  
  1277. ; define the variables
  1278. %define Buttons      [ebp-1]
  1279. %define Movement_X              [ebp-2]
  1280. %define Movement_Y              [ebp-3]
  1281. %define System_Stack          3
  1282.  
  1283. Enter_driver
  1284. call Get_address
  1285.  
  1286.  
  1287. ; store the 3 bytes (Buttons, X Movement, Y Movement)
  1288. in al,60h
  1289. mov Buttons,al
  1290. in al,60h
  1291. mov Movement_X,al
  1292. in al,60h
  1293. mov Movement_Y,al
  1294.  
  1295.  
  1296. ; update the position
  1297. API Update_Cursor_Position, Buttons, Movement_X, Movement_Y
  1298.  
  1299.  
  1300. Leave_driver
  1301. EOI_Slave
  1302.  
  1303. iret
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311. Mouse_Handler_intelli:
  1312.  
  1313. ; currently not supported
  1314.  
  1315. iret
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323. ; Keyboard and Mouse are boolean values if they are available
  1324. Keyboard        dd      0
  1325. Mouse      dd 0
  1326.  
  1327. ; Keyboard state
  1328. Typematic_rate  dd        00101000b
  1329. Led_locks       dd     000b
  1330.  
  1331. ; key states
  1332. CapsLock        dd      0
  1333. NumLock  dd       0
  1334. Rollen    dd        0
  1335. Alt_Gr    dd        0
  1336.  
  1337. PressedKeys     dd   0
  1338. UnknownKey      dd    0
  1339. Extended_key    dd  0
  1340. LastKey  dd       0
  1341. LastKeyExt      dd    0
  1342. LastKeyEvent    dd  0
  1343.  
  1344. ; 0 = europe, 1 = american
  1345. Take_Key_Table  dd        0
  1346.  
  1347.  
  1348. ; the Key tables (for Europe keyboards)
  1349. Key_Table_europe_ascii    db        '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 'ü', '+', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '^', '#', 'y', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '-', '<'
  1350. Key_Table_europe_ascii_shift    db  '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '`', 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'Ü', '*', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '°', 27h, 'Y', 'X', 'C', 'V', 'B', 'N', 'M', ';', ':', '_', '>'
  1351. Key_Table_europe_ascii_alt_gr   db '²', '³', '{', '[', ']', '}', '\', '@', '€', '~', 'µ', '|'
  1352.  
  1353. ; the Key tables (for switzer keyboards, thanks to noooooooos)
  1354. Key_Table_switzer_ascii  db       '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'ß', '´', 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 'ü', '+', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '^', '#', 'y', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '-', '<'
  1355. Key_Table_switzer_ascii_shift   db '+', '"', '*', 'ç', '%', '&', '/', '(', ')', '=', '?', '`', 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'Ü', '*', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ö', 'Ä', '°', 27h, 'Y', 'X', 'C', 'V', 'B', 'N', 'M', ';', ':', '_', '>'
  1356. Key_Table_switzer_ascii_alt_gr  db        '|', '@', '#', '?', '¦', '?', '´', '?', '€', '', ''
  1357.  
  1358. ; the Key tables (for American keyboards)
  1359. Key_Table_american_ascii        db      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '-', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 27h, '`', '\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '\'
  1360. Key_Table_american_ascii_shift  db        '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 'Q', 'W', 'E', 'R', 'T', 'Y', 'I', 'I', 'O', 'P', '{', '}', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '|'
  1361.  
  1362. ; the Key tables (for Europe & American keyboards)
  1363. Key_Table_imm         db VK_NULL, VK_ESCAPE, VK_BACK, VK_TAB, VK_RETURN, VK_SPACE, VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12
  1364. Key_Table_numblock            db    VK_HOME, VK_UP, VK_PRIOR, '-', VK_LEFT, VK_NUMPAD5, VK_RIGHT, '+', VK_END, VK_DOWN, VK_NEXT, VK_INSERT, VK_DELETE
  1365. Key_Table_numblock_num    db        '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', VK_DELETE
  1366. Key_Table_numblock_tec    db        VK_NUMPAD7, VK_NUMPAD8, VK_NUMPAD9, VK_SUBTRACT, VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_ADD, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3, VK_NUMPAD0, VK_DELETE
  1367. Key_Table_middle_block    db        VK_HOME, VK_UP, VK_PRIOR, VK_LEFT, VK_RIGHT, VK_END, VK_DOWN, VK_NEXT, VK_INSERT, VK_DELETE
  1368.  
  1369.  
  1370.  
  1371.  
  1372. ; bits of Led_locks (0=Off 1=On):
  1373. ;   0 = Scroll Lock
  1374. ;   1 = Num Lock
  1375. ;   2 = Caps Lock
  1376. ;   rest = 0
  1377.  
  1378.  
  1379. ; bits of Typematic_rate
  1380. ;   bit 0 -> 4: rate. Timings:
  1381. ;     0: 30 keys/sec   10: 10
  1382. ;     1: 26.7          13: 9
  1383. ;     2: 24            16: 7.5
  1384. ;     4: 20            20: 5
  1385. ;     8: 15            31: 2
  1386. ;     
  1387. ;   bit 5 & 6: pause before repeat:
  1388. ;     0: 250 ms
  1389. ;     1: 500
  1390. ;     2: 750
  1391. ;     4: 1000
  1392. ;     
  1393. ;   bit 7: Always 0
  1394.  
  1395.  
  1396. ; PressedKeys
  1397. ;   bit 0: shift left
  1398. ;   bit 1: ctrl left
  1399. ;   bit 2: alt (unused)
  1400. ;   bit 3: del (unused)
  1401. ;   bit 4: caps lock
  1402. ;   bit 5: ctrl right
  1403. ;   bit 6: ctrl (unused)
  1404. ;   bit 7: shift right
  1405. ;   bit 8: shift (unused)
  1406. ;   bit 9: rollen
  1407. ;   bit 10: num lock

Paste Details

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right
fantasy-obligation