home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / SETKEYS.ASM < prev    next >
Assembly Source File  |  1992-10-17  |  6KB  |  146 lines

  1. ; File......: SETKEYS.ASM
  2. ; Author....: Ted Means
  3. ; CIS ID....: 73067,3332
  4. ; Date......: $Date:   17 Oct 1992 16:27:42  $
  5. ; Revision..: $Revision:   1.1  $
  6. ; Log file..: $Logfile:   C:/nanfor/src/setkeys.asv  $
  7. ; This is an original work by Ted Means and is placed in the
  8. ; public domain.
  9. ;
  10. ; Modification history:
  11. ; ---------------------
  12. ;
  13. ; $Log:   C:/nanfor/src/setkeys.asv  $
  14. ;  
  15. ;     Rev 1.1   17 Oct 1992 16:27:42   GLENN
  16. ;  Leo cleaned up documentation blocks.
  17. ;  
  18. ;     Rev 1.0   16 Oct 1992 00:02:42   GLENN
  19. ;  Initial revision.
  20.  
  21. ;  $DOC$
  22. ;  $FUNCNAME$
  23. ;     FT_SETKEYS()
  24. ;  $CATEGORY$
  25. ;     Keyboard/Mouse
  26. ;  $ONELINER$
  27. ;     Get array of keys redirected via the SetKey() or SET KEY
  28. ;  $SYNTAX$
  29. ;     FT_SetKeys() --> aKeyValues
  30. ;  $ARGUMENTS$
  31. ;     None
  32. ;  $RETURNS$
  33. ;     An array from 0 to n elements, where n is the number of keys that
  34. ;     have been redirected via SetKey().  Each element in the array contains
  35. ;     the Inkey() value of a key that has been redirected.
  36. ;  $DESCRIPTION$
  37. ;     Nantucket encourages Clipper programmers to write modular code -- black
  38. ;     boxes that do not modify any global settings without resetting them
  39. ;     on exit.  In the past, this has proven cumbersome where SetKey() is
  40. ;     concerned, because the only way to see if a key had been redirected
  41. ;     was to call SetKey() and see if it returned NIL or a code block.  To
  42. ;     check every possible key value was unacceptably slow.
  43. ;
  44. ;     This function attempts to alleviate this problem by returning an array
  45. ;     that contains only those keys that have been redirected.  It is
  46. ;     substantially faster than the method mentioned above because it
  47. ;     directly accesses Clipper's internal table of redirected keys.
  48. ;
  49. ;     Some highly unorthodox programming techniques, not to mention rather
  50. ;     strange use of Clipper internals, was necessary to make this function
  51. ;     work.  If this makes you uncomfortable, then don't use this function,
  52. ;     you snivelling coward.
  53. ;
  54. ;  $EXAMPLES$
  55. ;     local aKeys := FT_SetKeys()    // Get the key table
  56. ;     local aBlox := {}              // Create a parallel array
  57. ;     local i
  58. ;
  59. ;     for i := 1 to len( aKeys )
  60. ;       // Nullify all redirections, while saving code block
  61. ;       // for later restoration
  62. ;
  63. ;       aadd( aBlox, setkey( aKeys[ i ], NIL )
  64. ;     next
  65. ;
  66. ;     // Do some stuff
  67. ;
  68. ;     for i := 1 to len( aKeys )
  69. ;       // Restore the redirections
  70. ;
  71. ;       setkey( aKeys[ i ], aBlox[ i ] )
  72. ;     next
  73. ;  $END$
  74. ;
  75.  
  76. IDEAL
  77.  
  78. Public   FT_SetKeys
  79.  
  80. VRefSize EQU       14
  81. Counter  EQU       Word Ptr BP - 2
  82.  
  83. Extrn    __RetNI:Far
  84. Extrn    __Keyboard:Far                      ; INTERNAL!
  85. Extrn    _ArrayNew:Far                       ; INTERNAL!
  86. Extrn    __Eval:Word                         ; INTERNAL!
  87. Extrn    __TOS:Word                          ; INTERNAL!
  88. Extrn    __cAtPut:Far                        ; INTERNAL!
  89. Extrn    __PutLN:Far                         ; INTERNAL!
  90.  
  91. Segment  _Nanfor   Word      Public    "CODE"
  92.          Assume    CS:_Nanfor
  93.  
  94. Proc     FT_SetKeys          Far
  95.  
  96.          Push      BP                        ; Preserve BP
  97.          Mov       BP,SP                     ; Set up stack reference
  98.          Sub       SP,2                      ; Allocate a local
  99.          Mov       [Counter],0               ; Initialize it to zero
  100.  
  101.          Mov       DX,Seg __Keyboard         ; Load segment of known symbol
  102.          Mov       BX,Offset __Keyboard      ; Load offset of known symbol
  103.          Add       BX,1Bh                    ; Calc offset into code segment
  104.          Mov       ES,DX                     ; Load segment register
  105.          Mov       BX,[Word Ptr ES:BX]       ; Lift address from machine code
  106.          Mov       CX,[Word Ptr BX]          ; Get size
  107.          LES       BX,[DWord Ptr BX + 2]     ; Get address of table
  108.          JCXZ      @@Save                    ; If table empty, skip next part
  109.  
  110. @@Top:   Mov       AX,[Word Ptr ES:BX]       ; Load key value
  111.          Or        AX,[Word Ptr ES:BX + 2]   ; See if it's null
  112.          JZ        @@Bottom                  ; If so, skip it
  113.          Inc       [Counter]                 ; Increment counter
  114.          Push      [Word Ptr ES:BX + 2]      ; Put key value on stack
  115.          Push      [Word Ptr ES:BX]
  116. @@Bottom:Add       BX,4                      ; Adjust offset
  117.          Loop      @@Top                     ; Check next value
  118.  
  119. @@Save:  Push      [Counter]                 ; Put key count on stack
  120.          Call      _ArrayNew                 ; Create Clipper array
  121.          
  122. @@Store: Cmp       [Counter],0               ; Reached end yet?
  123.          JE        @@Done                    ; If so, quit
  124.          Call      __PutLN                   ; Create entry on eval stack
  125.          Add       SP,4                      ; Remove entry from CPU stack
  126.          Push      [__TOS]                   ; Source VREF pointer on stack
  127.          Push      [Counter]                 ; Element # on stack
  128.          Push      [__Eval]                  ; Target VREF pointer on stack
  129.          Call      __cAtPut                  ; Store array element
  130.          Add       SP,6                      ; Realign stack
  131.          Sub       [__TOS],VRefSize          ; Remove entry from eval stack
  132.          Dec       [Counter]                 ; Decrement counter
  133.          Jmp       Short @@Store             ; Do next element
  134.  
  135. @@Done:  Mov       SP,BP                     ; Realign stack
  136.          Pop       BP
  137.          Ret
  138.  
  139. Endp     FT_SetKeys
  140. Ends     _Nanfor
  141. End
  142.  
  143.  
  144.