Advertisement
Guest User

KB.BAT

a guest
May 27th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; goto label
  2.     .model tiny
  3.     .386
  4.     .code
  5.     org 100h
  6. start: 
  7.     pusha
  8.    
  9.     lea dx, start_msg
  10.     mov ah, 09h
  11.     int 21h
  12.  
  13.     push 40h
  14.     pop es
  15.   mlp: 
  16.     mov di, es:[1Ah]    ;DI <- BEGIN
  17.     mov dx, es:[1Ch]    ;DX <- END
  18.     l:  cmp dx, di
  19.     je mlp
  20.     call reader
  21.     cmp EXIT_FLAG, 01h
  22.     jne mlp
  23.  
  24.     popa
  25.     ret
  26.  
  27. start_msg db "PRESS ANY KEY", '$'
  28. EXIT_FLAG db 0
  29.  
  30. KB_BEGIN equ 1Eh
  31. KB_END   equ 1Eh + 20h
  32. reader: ;READ KB BUFFER [DI, DX), DX != DI
  33.     mov bx, es:[di]
  34.     mov ax, 03
  35.     int 10h
  36.     call process
  37.     call print_shift
  38.     add di, 2
  39.         cmp di, KB_END  ;eobuffer
  40.         jne skip
  41.         mov di, KB_BEGIN    
  42.         skip:
  43.     cmp dx, di
  44.     jne reader
  45.     mov es:[1Ah], di
  46.    
  47.     ret
  48.  
  49.  
  50. L_0 equ 0FAh
  51. L_1 equ 0FEh
  52. msg db  "INSERT LOCKED              ", "_", 13, 10,\
  53.     "CAPS LOCK LOCKED           ", "_", 13, 10,\
  54.         "NUM LOCK LOCKED            ", "_", 13, 10,\
  55.         "SCROLL LOCK LOCKED         ", "_", 13, 10,\
  56.         "ALT KEY IS PRESSED         ", "_", 13, 10,\
  57.     "CTRL KEY IS PRESSED        ", "_", 13, 10,\
  58.         "LEFT SHIFT KEY IS PRESSED  ", "_", 13, 10,\
  59.         "RIGHT SHIFT KEY IS PRESSED ", "_", 13, 10, '$'
  60. print_shift:
  61.     push bx
  62.     push di
  63.     push dx
  64.     push es
  65.    
  66.     mov bx, es:[17h]
  67.  
  68.     push cs
  69.     pop es
  70.     lea di, msg
  71.     add di, 27 + 7 * 30
  72.  
  73.     mov cx, 8
  74.   fill:
  75.     mov ax, 1
  76.     and ax, bx
  77.     ror bx, 1
  78.     cmp al, 1
  79.     je c1
  80.     c0: mov al, L_0
  81.     jmp ce
  82.     c1: mov al, L_1
  83.     ce: stosb  
  84.     sub di, 31
  85.     loop fill
  86.    
  87.     lea dx, msg
  88.     mov ah, 09h
  89.     int 21h
  90.  
  91.     pop es
  92.     pop dx
  93.     pop di
  94.     pop bx
  95.     ret
  96.  
  97. output db "SCAN CODE: __; ASCII: _", 13, 10, 13, 10, '$'
  98. process:
  99.     push di
  100.     push dx
  101.     push es
  102.    
  103.     push cs
  104.     pop es
  105.  
  106.     lea di, output
  107.     add di, 11
  108.     ror bx, 8
  109.     call h2
  110.     add di, 9
  111.     mov byte ptr [di], bh
  112.    
  113.     lea dx, output
  114.     mov ah, 09h
  115.     int 21h
  116.  
  117.     mov EXIT_FLAG, bl      
  118.  
  119.     pop es
  120.     pop dx
  121.     pop di
  122.     ret
  123.  
  124. h4:             ;ES:DI <- hex of BX
  125.     ror bx, 8
  126.     call h2
  127.     ror bx, 8
  128. h2:             ;ES:DI <- hex of BL
  129.     mov al, bl
  130.     shr al, 4
  131.     cmp al, 10
  132.     sbb al, 69h
  133.     das         ;AL = hex of BL (h)
  134.     cld         ;DF = 0 (DI++, SI++ on str ops)
  135.     stosb           ;ES:DI <- AL
  136.     mov al, bl
  137.     and al, 0Fh
  138.     cmp al, 10
  139.     sbb al, 69h
  140.     das         ;AL = hex of BL (l)
  141.     stosb           ;ES:DI <- AL           
  142.     ret
  143.     end start  
  144. ; :label
  145. ; tasm /m5 kb.bat
  146. ; tlink /x/t kb.obj
  147. ; del kb.obj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement