home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / keylock.zip / KEYLOCK.ASM next >
Assembly Source File  |  1988-08-25  |  8KB  |  217 lines

  1. ;    Title:    KEYLOCK.ASM
  2. ;    Author:   F. Ho 
  3. ;    Date:     28th May 1986
  4. ;    Syntax:   LOCKSTAT()
  5. ;    Note:     returns current status of the 4 "lock" keys in the form - ICNS
  6. ;              Clipper Function.
  7. ;
  8. ;    Revised:
  9. ;    P. Baenziger, pbprograms, 1215 Lane, Kalamzoo, MI 49001
  10. ;    (616) 349-9720 (Evenings), 323-7392 (Days, 8-4:30 EDT)
  11. ;
  12. ;       Calling syntax:  1) ? LOCKSTAT()
  13. ;                        2) X = LOCKSTAT()
  14. ;
  15. ;       Returns a character type string in the form: "icns"
  16. ;
  17. ;       where:  i = insert lock key
  18. ;               c = caps lock key
  19. ;               n = num lock key
  20. ;               s = scroll lock key
  21. ;
  22. ;       If the returned string ("icns") displays any letters in upper
  23. ;       case, it means that that lock key has been "activated".
  24. ;
  25. ;       example:
  26. ;       - if the function returns: iCnS
  27. ;       it means that the Caps Lock and the Scroll Lock keys are ON
  28. ;
  29. ;    Revised:
  30. ;    by Craig Steinberg, 8/30/87 CompuServe 70166,337 Source NA2606
  31. ;              INSTOGG(): toggles insert status
  32. ;              CAPTOGG(): toggles caps lock status
  33. ;              NUMTOGG(): toggles number lock status
  34. ;              SCRTOGG(): toggles scroll lock status
  35. ;
  36. ;    Revised:
  37. ;    by Alex Feldstein, August 1988, Compuserve 72237,2150
  38. ;    Converted to Clipper Summer 87.
  39. ;
  40. ;
  41. public LOCKSTAT, NUMTOGG, CAPTOGG, SCRTOGG, INSTOGG
  42. ;
  43. ;
  44. extrn  __RETC:far                       ; Clipper return character
  45. ;
  46. ;==================================================
  47. DGROUP    GROUP     DATASG
  48. datasg segment PUBLIC  'DATA'
  49. ;==================================================
  50. ;    
  51. ;
  52. ; Table for following lock status:
  53. LOCKTABLE   DB 'icns',0 ; All off: Insert, Caps, Numlock, Scroll
  54.             DB 'icnS',0 ;
  55.             DB 'icNs',0 ;
  56.             DB 'icNS',0 ;
  57.             DB 'iCns',0 ;
  58.             DB 'iCnS',0 ;
  59.             DB 'iCNs',0 ;
  60.             DB 'iCNS',0 ;
  61.             DB 'Icns',0 ;
  62.             DB 'IcnS',0 ;
  63.             DB 'IcNs',0 ;
  64.             DB 'IcNS',0 ;
  65.             DB 'ICns',0 ;
  66.             DB 'ICnS',0 ;
  67.             DB 'ICNs',0 ;
  68.             DB 'ICNS',0 ; All on
  69. ;
  70. ;
  71. ;==================================================
  72. datasg ends
  73. ;==================================================
  74. ;
  75. ;
  76. ;==================================================
  77. _prog  segment byte                     ; byte aligned
  78. assume cs:_prog,ds:DGROUP,es:NOTHING    ; original ->datasg
  79. ;==================================================
  80. ;
  81. LOCKSTAT  proc far            ; far process for Clipper
  82.           push bp             ; save BP on stack
  83.                     
  84.           mov  ah,02          ; request current shift status (into AL)
  85.           int  16h            ; issue keyboard input ROM BIOS interrupt
  86.  
  87.           ;Returns shift state in AL in upper nibble
  88.           ; 80h - Insert state
  89.           ; 40h - Caps Lock state
  90.           ; 20h - Num Lock state
  91.           ; 10h - Scroll Lock state
  92.  
  93.           ; The index value of the KEYBOARD FLAG is in the upper
  94.           ; nibble of AL.  To use it as a pointer, we have to divide it
  95.           ; by 16 (or shift it right 4 times, move it into the lower
  96.           ; nibble.  However, LOCKTABLE has 5 byte steps, so we have
  97.           ; to multiply back by 5.  One way to do it is:
  98.           ;    1 - Clear out the lower nibble, extend the returned
  99.           ;        byte to a word
  100.           ;    2 - shift right 2 times (divide by 4).  This is
  101.           ;        the same as dividing by 16, then multiplying
  102.           ;        by 4.  This is all that would be needed for a 
  103.           ;        4 byte step table. 
  104.           ;    3 - save this intermediate value in BL (or wherever)
  105.           ;    4 - shift right 2 more times for a total of 4
  106.           ;        right shifts (divided by 16)
  107.           ;    5 - add in the saved value from step 3.  This gives
  108.           ;        use the 5 byte step index in AX
  109.           ;    6 - add the value to the base offset of LOCKTABLE
  110.           ;        BX is now pointing to the correct entry,
  111.           ;        ready for transfer back to CLIPPER after pushing
  112.           ;        it and the segment value
  113.  
  114.           SUB AH, AH          ; Make a word value out of AL
  115.           AND AL, 0F0H        ; Clear out lower nibble
  116.           MOV CL, 2           ; Divide by 4 - 2 shift right
  117.           SHR AL, CL
  118.           MOV BL, AL          ; Save the divided by 4 value
  119.           SHR AL, CL          ; Divide by 4 - a total of 16
  120.           ADD AL, BL          ; Now we have the 5 byte a step index
  121.                               ; into LOCKTABLE in AX
  122.           LEA BX, LOCKTABLE   ; Get the base offset
  123.           ADD BX, AX          ; Now points to correct entry
  124.           MOV AX, DGROUP      ; And also the right segment
  125.           
  126.           ; restore stack to original position
  127.           pop  bp             ; restore stack base pointer
  128.  
  129.           push ax             ; push AX (segment)
  130.           push bx             ; push BX (offset)
  131.           call __RETC         ; call Clipper return for type CHAR
  132.           ADD SP, 4           ; quicker
  133.  
  134.           ret                 ; far return
  135.  
  136. LOCKSTAT  endp                ; end of process
  137. ;
  138. ;
  139. ;==================================================
  140. ; TOGGLE NUMBER LOCK
  141. ;==================================================
  142. ;  status is in memory location 0417h
  143. ;  XOR 0417h with  to toggle
  144. ;                80h - Insert state
  145. ;                40h - Caps Lock state
  146. ;                20h - Num Lock state
  147. ;                10h - Scroll Lock state
  148. ;
  149. NUMTOGG   proc far  ; far process
  150.           push bp
  151.           mov  AX,DS               ; put data seg into AX
  152.           push AX                  ; put it onto stack to remember it
  153.           mov  AX,0040h            ; make a new data seg
  154.           mov  DS,AX               ;
  155.           mov  BX,0017h            ; offset into seg
  156.           xor  BYTE PTR [BX],20h   ; toggle the byte pointed to by BX
  157.           pop  AX                  ; get data seg back
  158.           mov  DS,AX               ; restore the data seg
  159.           pop  bp                  ; restore stack base pointer
  160.           ret                      ; far return
  161. NUMTOGG   endp                     ; end of process
  162.  
  163. ;==================================================
  164. ; TOGGLE CAPS LOCK
  165. ;==================================================
  166. CAPTOGG   proc far
  167.           push bp
  168.           mov  AX,DS
  169.           push AX
  170.           mov  AX,0040h
  171.           mov  DS,AX
  172.           mov  BX,0017h
  173.           xor  BYTE PTR [BX],40h
  174.           pop  AX
  175.           mov  DS,AX
  176.           pop  bp
  177.           ret
  178. CAPTOGG   endp
  179.  
  180. ;==================================================
  181. ; TOGGLE SCROLL LOCK
  182. ;==================================================
  183. SCRTOGG   proc far
  184.           push bp
  185.           mov  AX,DS
  186.           push AX
  187.           mov  AX,0040h
  188.           mov  DS,AX
  189.           mov  BX,0017h
  190.           xor  BYTE PTR [BX],10h
  191.           pop  AX
  192.           mov  DS,AX
  193.           pop  bp
  194.           ret
  195. SCRTOGG   endp
  196.  
  197. ;==================================================
  198. ; TOGGLE INSERT
  199. ;==================================================
  200. INSTOGG   proc far
  201.           push bp
  202.           mov  AX,DS
  203.           push AX
  204.           mov  AX,0040h
  205.           mov  DS,AX
  206.           mov  BX,0017h
  207.           xor  BYTE PTR [BX],80h
  208.           pop  AX
  209.           mov  DS,AX
  210.           pop  bp
  211.           ret
  212. INSTOGG   endp
  213.  
  214. _prog     ends                          ; end of segment
  215.           end                           ; end of programme
  216.  
  217.