home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / TECLADO / KILL_KBD.ZIP / KTIME-AT.ASM next >
Encoding:
Assembly Source File  |  1988-08-10  |  4.8 KB  |  238 lines

  1. title KTIME-AT.ASM ;8-10-88
  2.  
  3. ;BY J.W.G.
  4.  
  5. ;For IBM AT & Wyse 386 and compatible
  6.  
  7. ;If this program is executed without
  8. ;a command line parameter, or an
  9. ;invalid parameter then the
  10. ;time of 2 minutes will be used.
  11.  
  12. ;The optional command line parameter
  13. ;is a number from 1 to 3600
  14. ;representing the number of seconds
  15. ;the keyboard will be disabled.
  16.  
  17. ;Example...  KTIME-AT 105
  18. ;means.. kbd disabled 1 min 45 sec.
  19.  
  20. ;memory resident INT 8 routine
  21. ;Takes up 496 bytes of RAM.
  22. ;INT 8 is "timer tick interrupt"
  23. ;and is executed 18.2 times per sec.
  24. ;
  25. ;Installation routine disables
  26. ;keyboard.
  27. ;
  28. ;Resident routine counts timer
  29. ;ticks up to a value, then
  30. ;re-enables the keyboard.
  31.  
  32. cseg segment para public 'code'
  33. org 100h
  34.  
  35. KILLKBD proc far
  36. assume cs:cseg, ds:cseg
  37. jmp  install
  38. oldint dd 0
  39. counter dw 0
  40. ticks dw 8808h   ;888H / 2160 decimal
  41.                  ;default 2 min time
  42.                  ;delay time if no
  43.                  ;parameter on
  44.                  ;command line.
  45. intloc equ 8h*4
  46.  
  47. newint:
  48. ;NOTE: when time interval is up
  49. ;a JMP 013Bh instruction will be
  50. ;placed here.
  51.   push bx
  52.   push es
  53.   push si
  54.   push ax
  55.   pushf
  56. ;
  57.   xor ax,ax
  58.   mov es,ax
  59.   mov si,offset counter
  60.   mov ax,cs:[si]
  61.   inc ax
  62.   mov cs:[si],ax
  63.   lea si,ticks
  64.   mov bx,cs:[si] ;get compare value ticks
  65.   cmp ax,bx
  66.  
  67. ;int 8 is called 18.2 times per sec.
  68. ;in one minute it is called 1080 times
  69. ;
  70.   jb  return ;jump if count short
  71. ;Now short circuit this routine by
  72. ;installing a JMP at newint:
  73.   mov si,offset newint
  74.   mov ax,2EEBh ;opcodes for JMP 13B
  75.                ;(backwards fashion)
  76.   mov cs:[si],ax  ;install JMP intstr.
  77.                   ;JMP 013Bh at 010B
  78. ;enable keyboard now.
  79.   mov al,0AEh
  80.   out 64h,al ;enable keyboard.
  81. return:
  82.   popf
  83.   pop ax
  84.   pop si
  85.   pop es
  86.   pop bx
  87. ;short circuit will jump to here.!
  88. ;target of JMP 013Bh
  89.   jmp cs:[oldint]
  90. install:
  91.   CALL GET_PARAM
  92.   mov ax,0
  93.   mov es,ax
  94. ;set counter to zero
  95.   mov si,offset counter
  96.   mov cs:[si],ax
  97. ;
  98.   mov di,intloc
  99.   mov ax,es:[di]
  100.   mov bx,es:[di+2]
  101.   mov si,offset oldint
  102.   mov [si],ax
  103.   mov [si+2],bx
  104.   mov ax,0
  105.   mov es,ax
  106.   mov bx,ds
  107.   cli
  108.   mov di,intloc
  109.   mov ax,offset newint
  110.   mov es:[di],ax
  111.   mov es:[di+2],bx
  112.   sti
  113. ;
  114. ;disable keyboard now
  115.   mov al,0ADh
  116.   out 64h,al
  117. ;
  118.   mov dx,offset install
  119.   int 27h ;terminate stay resident
  120. KILLKBD endp
  121.  
  122. GET_PARAM proc near
  123. ;get parameters from command line
  124.    mov  ax,0000h
  125.    mov  al,cs:[0080h] ;byte contains
  126.                       ;length of
  127.                       ;command tail + 1
  128.    cmp  al,00h
  129.    je   QUIT2 ;no param on command line
  130.    dec  al    ;The byte at cs:0080 is
  131.               ;supposed to be the # of
  132.               ;characters making up the
  133.               ;command tail, however it
  134.               ;is really that value + 1
  135.    cmp  al,04h ;more than 4 chars in
  136.    ja   QUIT2  ;com line parameter ?
  137.    push ax
  138.    CALL GET_ONES
  139.    pop  ax
  140.    dec  al
  141.    cmp  al,00h
  142.    je   QUIT
  143.    push ax
  144.    CALL GET_TENS
  145.    pop  ax
  146.    dec  al
  147.    cmp  al,00h
  148.    je   QUIT
  149.    push ax
  150.    CALL GET_HUNDREDS
  151.    pop  ax
  152.    dec  al
  153.    cmp  al,00h
  154.    je   QUIT
  155.    CALL GET_THOUSANDS
  156. QUIT:
  157. ;BX now contains number of seconds
  158. ;of desired wait period.
  159. ;we must multiply it by 18.2 to get
  160. ;value of ticks.
  161.    cmp  bx,0
  162.    je   QUIT2  ;use default time
  163.    cmp  bx,3600  ;too large ?
  164.    ja   QUIT2  ;use default time
  165.    mov  ax,0012h ;18 decimal
  166.    mul  bx
  167. ;AX now contains BX * 18
  168. ;but we needed BX * 18.2 !
  169. ;First we will divide by 10 and then
  170. ;multiply by 2 (by Lshift 1 bit)
  171.    mov  cx,ax  ;save AX in CX
  172.    mov  ax,bx  ;bx = seconds param.
  173.    mov  dx,0   ;will = remainder
  174.    mov  bx,000Ah
  175.    div  bx     ;divide AX by 10 dec.
  176.    cmp  dx,5   ;is remainder > 5
  177.    jb   SKIP
  178.    inc  ax     ;round off if
  179.                ;remainder > 5
  180. SKIP:
  181.    shl  ax,1   ;AX = AX * 2
  182.    add  ax,cx
  183.    mov  ticks,ax ;store valid value
  184. QUIT2:
  185.    ret
  186. GET_PARAM endp
  187.  
  188. GET_ONES proc near
  189. ;parameters start at cs:005Dh
  190. ;reg al contains length command tail
  191.   add  ax,005Ch
  192.   push ax
  193.   pop  si ;si points to rightmost byte
  194.   mov  bx,0
  195.   mov  bl,cs:[si]
  196.   sub  bl,30h  ;convert ASCII number to
  197.                ;decimal number
  198.   ret
  199. GET_ONES endp
  200.  
  201. GET_TENS proc near
  202.   dec  si
  203.   mov  ax,0
  204.   mov  al,cs:[si]
  205.   sub  al,30h
  206.   mov  cx,000Ah
  207.   mul  cx    ;ax = ax * 10 (cx)
  208.   add  bx,ax ;new subtotal
  209.   ret
  210. GET_TENS endp
  211.  
  212. GET_HUNDREDS proc near
  213.   dec  si
  214.   mov  ax,0
  215.   mov  al,cs:[si]
  216.   sub  al,30h
  217.   mov  cx,0064h
  218.   mul  cx    ;ax = ax * 100 (cx)
  219.   add  bx,ax ;new subtotal
  220.   ret
  221. GET_HUNDREDS endp
  222.  
  223. GET_THOUSANDS PROC NEAR
  224.   dec  si
  225.   mov  ax,0
  226.   mov  al,cs:[si]
  227.   sub  al,30h
  228.   mov  cx,03E8h
  229.   mul  cx    ;ax = ax * 1000 (cx)
  230.   add  bx,ax ;final total seconds
  231.   ret
  232. GET_THOUSANDS ENDP
  233.  
  234. cseg ends
  235. end KILLKBD
  236.  
  237.  
  238.