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

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