home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / 300 / 294 / capsunlk.asm < prev    next >
Assembly Source File  |  1985-09-24  |  4KB  |  87 lines

  1.         name    capslk
  2.         page    55,96
  3.         title   'CAPSLK - a CapsLock unlatcher'
  4.  
  5. ; This install and stay resident program releases the keyboard from
  6. ; the CapsLock state whenever a letter key is pressed while a shift
  7. ; key also depressed.  tHIS ELIMINATES A WELL KNOWN ANNOYANCE.
  8. ;
  9. ; Note that keyboards with CapsLock indicator lights may get out of
  10. ; synchronization since they have no way of knowing when the caplock bit
  11. ; in KB_FLAG is changed.
  12. ;
  13. ; This source based on a disassembly of CAPSLOCK.BAS in the Oct 15 '85
  14. ; issue of PC Magazine.  Annotation and some minor changes in code to
  15. ; shorten program and reduce the number of execution clocks, implementation
  16. ; of function call 31h vs INT 27h by Herb Shear, SVCS Librarian.
  17.  
  18. cseg    segment         para public 'CODE'
  19.  
  20.         assume          cs:cseg, ds:cseg, es:cseg
  21.  
  22.         org     100h                ;start of com program
  23.  
  24.  
  25. begin:  jmp     short sta_res       ;proceed to stay resident code
  26. vector: dd      ?                   ;storage for next code in daisychain
  27.  
  28. start   proc near
  29.         sti                         ;enable interrupts
  30.         push    ax                  ;save registers
  31.         push    cx
  32.         push    di
  33.         push    es
  34.         pushf
  35.         xor     ax,ax               ;clear ax register
  36.         mov     es,ax               ;ES =  seg 0
  37.         mov     di,417h             ;set a pointer to KB_FLAG
  38.         mov     ah,es:[di]          ;load KB_FLAG
  39.         test    ah,03h              ;see if a shift key is pressed
  40.         jz      exit                ;exit if not pressed
  41.         in      al,60h              ;get keyboard scan code from port
  42.         cmp     al,10h              ;compare to Q key position
  43.         jb      exit                ;lower numbered position than Q key
  44.         cmp     al,19h              ;compare to P key position
  45.         jna     unlock              ;key in Q..P range
  46.         cmp     al,1eh              ;compare to A key position
  47.         jb      exit                ;non-alpha key position
  48.         cmp     al,26h              ;compare to L key position
  49.         jna     unlock              ;key in A..L range
  50.         cmp     al,2ch              ;compare to Z key position
  51.         jb      exit                ;non-alpha key position
  52.         cmp     al,32h              ;compare to M key position
  53.         ja      exit                ;key not in Z..M range
  54. unlock: and     ah,0bfh             ;clear CapsLock bit
  55.         mov     es:[di],ah          ;reset KB_FLAG
  56. exit:   popf                        ;restore registers
  57.         pop     es
  58.         pop     di
  59.         pop     cx
  60.         pop     ax
  61.         jmp     dword ptr cs:[vector]  ;follow the INT 9 daisychain
  62.  
  63. sta_res:
  64.         xor     ax,ax               ;zero ax register
  65.         mov     es,ax               ;zero es register
  66.         mov     di,9h * 4h          ;interrupt 9 address
  67.         mov     ax,es:[di]          ;get the interrupt vector
  68.         mov     bx,es:[di+2]
  69.         mov     si, offset vector   ;pointer to vector storage
  70.         mov     [si],ax             ;save the interrupt vector
  71.         mov     [si+2],bx
  72.         mov     bx,ds               ;get seg of resident code
  73.         cli                         ;turn off interrupts
  74.         mov     ax,offset start     ;get offset of resident code
  75.         mov     es:[di],ax          ;store as new INT 9 vector
  76.         mov     es:[di+2],bx
  77.         sti                         ;turn interrupts back on
  78.         mov     dx,offset sta_res   ;end of resident code + 1
  79.         mov     cl,4                ;prepare for shift
  80.         shr     dx,cl               ;convert to paragraphs
  81.         inc     dx                  ;roundup to full paragraph
  82.         mov     ax,3100h            ;set exit code = zero
  83.         int     21h                 ;terminate & stay resident
  84. start   endp
  85. cseg    ends
  86.         end    begin
  87.