Advertisement
Guest User

Show scancodes pressed

a guest
May 4th, 2016
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BITS 16
  2. ORG 100h
  3.  
  4.  call init
  5.  
  6.  mov ax, 03h
  7.  int 10h
  8.  
  9.  
  10. _main:
  11.  call wait_for_scancode
  12.  call draw_scancodes
  13.  
  14. _wait_for_keystroke:
  15.  mov ah, 01h
  16.  int 16h
  17. jz _main
  18.  
  19.  xor ah, ah
  20.  int 16h
  21.  
  22.  cmp al, 27d
  23. jne _main
  24.  
  25.  call dispose
  26.  
  27.  mov ax, 4c00h
  28.  int 21h
  29.  
  30.  
  31. draw_scancodes:
  32.  push es
  33.  push di
  34.  push si
  35.  push ax
  36.  push bx
  37.  push cx
  38.  
  39.  mov si, strHeader
  40.  xor di, di
  41.  push 0b800h
  42.  pop es
  43.  
  44.  mov ah, 07h
  45.  xor bx, bx
  46.  call store_string
  47.  
  48.  mov di, 160d
  49.  mov bx, 158d
  50.  call store_string
  51.  
  52.  xor cx, cx
  53.  mov di, 166d
  54.  
  55. _ds_draw:
  56.  push di
  57.  
  58.  mov bx, cx
  59.  shl bx, 04h
  60.  
  61. __ds_scancode:
  62.  
  63.   mov al, 'X'
  64.   and al, BYTE [scancode_status + bx]
  65.  
  66.   stosw
  67.   add di, 02h
  68.  
  69.   inc bx
  70.   test bl, 0fh
  71.  jnz __ds_scancode
  72.  
  73.  pop di
  74.  add di, 160d
  75.  
  76.  inc cx
  77.  cmp cx, 08h
  78. jb _ds_draw
  79.  
  80.  pop cx
  81.  pop bx
  82.  pop ax
  83.  pop si
  84.  pop di
  85.  pop es
  86.  ret
  87.  
  88. strHeader db "   0 1 2 3 4 5 6 7 8 9 a b c d e f", 0
  89. strLeft   db "01234567", 0  
  90.  
  91. store_string:
  92.  lodsb
  93.  stosw
  94.  add di, bx
  95.  test al, al
  96.  jnz store_string
  97.  ret
  98.  
  99. init:
  100.   push ax  
  101.  
  102.   mov ax, cs
  103.   mov WORD [old_isr_15 + 02h], ax
  104.   call swap_isr_15
  105.  
  106.   pop ax
  107.   ret
  108.  
  109. dispose:
  110.   call swap_isr_15
  111.    
  112.   ret  
  113.  
  114. swap_isr_15:
  115.   push eax
  116.   push es
  117.  
  118.   xor ax, ax
  119.   mov es, ax
  120.  
  121.   cli
  122.  
  123.   mov eax, DWORD [es: 15h*4]
  124.   xchg eax, DWORD [old_isr_15]
  125.   mov DWORD [es: 15h*4], eax
  126.  
  127.   sti
  128.  
  129.   pop es
  130.   pop eax
  131.  
  132.   ret  
  133.  
  134. wait_for_scancode:
  135.  cli
  136.  
  137.  cmp WORD [new_scancode], 0
  138.  jne _wfs_found
  139.  
  140.  sti
  141. jmp wait_for_scancode
  142.  
  143. _wfs_found:
  144.  dec WORD [new_scancode]
  145.  sti
  146.  
  147.  ret
  148.  
  149. ;al = scancode  
  150. ;ZF clear is pressed
  151. is_scancode_pressed:
  152.   push bx
  153.   movzx bx, al
  154.   cmp BYTE [scancode_status + bx], 0
  155.   pop bx
  156.   ret
  157.  
  158. ;AL = scancode
  159. new_isr_15:
  160.  cmp ah, 4fh
  161.  jne _ni15_legacy
  162.  
  163.  push bx
  164.  push ax
  165.  
  166.  movzx bx, al
  167.  and bl, 7fh
  168.  
  169.  sar al, 07h
  170.  not al
  171.  
  172.  mov BYTE [cs:bx + scancode_status], al
  173.  inc WORD [cs:new_scancode]
  174.  
  175.  pop ax
  176.  pop bx
  177.  
  178. _ni15_legacy:  
  179.  push WORD [cs: old_isr_15 + 02h]
  180.  push WORD [cs: old_isr_15]
  181.  retf
  182.    
  183. old_isr_15                      dw new_isr_15, 0  
  184. scancode_status     TIMES 128   db 0
  185. new_scancode                    dw 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement