home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / MFKASM.ZIP / KB-RATE.ASM < prev    next >
Assembly Source File  |  1992-07-29  |  7KB  |  206 lines

  1. ;---------------------------------------------------------------------------;
  2. ; M.F.Kaplon  Begun:Mon  07-27-1992   Revised:Wed  07-29-1992
  3. ; Title : kb-rate.asm
  4. ;
  5. ; Set the Keyboard Typematic Rate - Passed In at KB if not Passed in
  6. ; uses Default Values if none passed in
  7. ; Category 4 function 54h.
  8. ;
  9. ; Call as kb-rate delay rate
  10. ;
  11. ; delay = 5 and rate = 14 are good default values
  12. ;
  13. ; For System Function Calls
  14. ;
  15. ; 1 - Must use the C Calling Convention which means
  16. ;     Arguments Pushed on Stack in Reverse Order than declared in function
  17. ; 2 - Using .MODEL FLAT when using a pointer, all you have to do is push
  18. ;     the offset of the variable since in FLAT model everyting is NEAR
  19. ;     in the 32 bit space
  20. ; 3 - Uses a 16K stack
  21. ;
  22. ; cmd file to assemble and link is named mlc-w386
  23. ; and should be called as   :  mlc-w386 filename
  24. ; The cmd file assumes that "filename" is in d:\os2_asm
  25. ; Content of mlc-link386
  26. ;
  27. ; ml /c d:\os2_asm\%1.asm
  28. ; IF errorlevel 1  goto errexit
  29. ; link386 /PM:PM /ALIGN:16 /E %1.obj ;
  30. ; del *.obj
  31. ; quit
  32. ; :errexit
  33. ; Echo Compile Error NO Link
  34. ; --------------------------
  35. ;
  36. ; My source files are in D:\os2_asm and I make my calls from the C:
  37. ; root directory so that the EXE files and the OBJ file are in C:\
  38. ; and the EXE file has same name as the source file.
  39. ; If you are assembling and linking more than one then you have to
  40. ; make appropriate changes. The above does not make a map or list file
  41. ;
  42. ; I get one warning message
  43. ;
  44. ; LINK : warning L4036: no automatic data segment
  45. ;
  46. ; This message has to do with no DGROUP being defined
  47. ; It can be suppressed with DATA NONE in a "DEF" file
  48. ;
  49. ;---------------------------------------------------------------------------;
  50. ;
  51.  
  52. .386             ;preceeding .MODEL makes USE32 default
  53. .MODEL           FLAT,SYSCALL,OS_OS2
  54. ;---------- Conditionally required equates -------------
  55.  
  56. NUMBUFS             equ  1     ; Uncomment if need number routines
  57. ;
  58.  
  59. NOWIN               equ  1     ;Not a PM application
  60.  
  61. INCLUDE        c:\toolkt20\asm\os2inc\os2def.inc ;structure defns includes POINTL
  62. INCLUDELIB     c:\toolkt20\os2lib\os2386.lib     ;Library
  63.  
  64. INCLUDE        d:\os2_asm\equs386.inc       ;equates : MFK
  65. INCLUDE        d:\os2_asm\386_dos.mac       ;macros using DOS calls : MFK
  66.  
  67. .STACK    8096   ;8K stack
  68.  
  69. .DATA
  70.  
  71. IFDEF NUMBUFS                      ;To use  UNCOMMENT NUMBUFS equate above
  72.    $DefineNumBufs
  73. ENDIF
  74. nwritten        DWORD   ?
  75.  
  76. ;Command Line data
  77. ppTIB           DWORD   ?        ;Address of pointer to TIB
  78. ppPIB           DWORD   ?        ;Address of pointer to PIB
  79. parm1            BYTE  10 dup(0)  ;ASCII typematic dealy in milliseconds
  80. parm2            BYTE  10 dup(0)  ;ASCII typematic rate in chars per sec
  81. parmerr          BYTE  cr,lf,"No Parameters Passed - Call Program as  KB-Rate kbd kbr  where Typematic",cr,lf,\
  82.                       "Delay in Milliseconds = kbd and  Rate in characters per second = kbr",cr,lf,\
  83.                       "Delay = 5 and Rate = 13 are good default parameter values.",cr,lf
  84. parmerrLen      equ $ - parmerr
  85. parmerr1         BYTE     cr,lf,"Incorrect Codes Passed to Program",cr,lf
  86. ;parmerr1Len     equ $ - parmerr1
  87.  
  88.  
  89. ; data for DosOpen Call
  90. KBDdevice        BYTE   "KBD$",0    ; Keyboard
  91. KBDhandle        DWORD  ?         ; KBD handle returned by call
  92. KBDactcode       DWORD  ?         ; action code returned by call
  93. KBDsize          DWORD  0         ; file size for KBD
  94. KBDattr          DWORD  0         ; file attribute for KBD
  95. KBDopenflag      DWORD  1         ; open flag for KBD
  96. KBDopenmode      DWORD  0042h     ; open mode for KBD
  97. KBDexta          DWORD  0         ; extended attributes for KBD
  98.  
  99.  
  100. Category         DWORD  4         ;category
  101. Function         DWORD 54h        ;function -assign session mgr hot key
  102. ParmList         WORD   ?         ;Delay
  103.                  WORD   ?         ;Rate
  104. ParmLnthMax      DWORD  4         ;length of Bytes to be returned
  105. ParmLnthInOut    DWORD  4         ;Length in bytes of parms passed
  106. DataPkt          DWORD  0         ;No Data Packet
  107. DataPktLnthMax   DWORD  0         ;Nothing to be returned
  108. DataPktLnthInOut DWORD  0         ;Nothing Passed
  109.  
  110. .CODE
  111.  
  112. startup:                         ;need to do this way with flat model
  113.  
  114. ;----------- get command line ------------
  115. push    offset ppPIB
  116. push    offset ppTIB
  117. call    DosGetInfoBlocks
  118. add     esp,8          ;reset stack pointer
  119. ; Address of command line is 4-th DWORD field in PIB
  120. ; to access it must be offset as 12
  121. ; The command line is 0 terminated
  122. mov     ebx,[ppPIB]    ;ebx = address of the PIB
  123. ;add     ebx,12         ;ebx now has address of command line
  124. mov     edi,0          ;initialize to zero
  125. mov     esi,[ebx+12]   ;esi is offset of command line
  126. mov     ecx,0          ;use as counter
  127.  
  128. .WHILE (byte ptr [esi] != 32)  ;read command line up to first space
  129.         inc     esi
  130. .ENDW
  131.  
  132. ;------------ get # of commands on command line -------------
  133. inc    esi                     ;now points to  1st space after command name
  134. .WHILE  byte ptr [esi] != 0    ;go to end of command line
  135.      .WHILE byte ptr [esi] == ' '
  136.           inc   esi
  137.      .ENDW
  138.      .IF byte ptr [esi] != ' ' && byte ptr [esi] != 0; if a space
  139.          inc    esi
  140.          inc    ecx
  141.          .WHILE byte ptr [esi] != ' ' && byte ptr [esi] != 0
  142.               inc   esi
  143.          .ENDW
  144.      .ENDIF
  145. .ENDW
  146.  
  147. ;------------ if no parameters passed sound alarm -display message and exit
  148. .IF  ecx != 2
  149.     $Alarm
  150.     $DosWrite  parmerrlen,offset parmerr,stdout
  151.     $DosExit
  152. .ENDIF
  153.  
  154. ;----------- now convert parms to numbers ---------------
  155.  
  156. ;----------- first copy to buffer, then convert ---------
  157. mov     esi,[ebx+12]        ;point to start of command line
  158. ;------------- get to start of params
  159. .WHILE (byte ptr [esi] != 32)  ;read command line up to first space
  160.         inc     esi
  161. .ENDW
  162.  
  163. .WHILE (byte ptr [esi] == 32)  ;skip spaces to first parm
  164.         inc     esi
  165. .ENDW
  166.  
  167. ;------------- esi now at start of params -------------
  168.  
  169. mov     edi,offset parm1    ;destination to store
  170. .WHILE (byte ptr [esi] != ' ')  ;read command line up to next space
  171.         movsb
  172. .ENDW
  173.  
  174. ;------------- skip over intervening spaces --------------
  175. .WHILE (byte ptr [esi] == ' ')  ;read command line up to next space
  176.         inc    esi
  177. .ENDW
  178.  
  179. mov     edi, offset parm2   ;repeat for next parm
  180. .WHILE (byte ptr [esi] != 0)  ;read command line up to end
  181.         movsb
  182. .ENDW
  183.  
  184. ;------------- now convert to numerics
  185. $ASCIIToDWord parm1        ; result returned in eax
  186. mov      word ptr ParmList,ax         ;ParmList is a WORD
  187. $ASCIIToDWord parm2        ; result returned in eax
  188. mov      ebx,eax             ;save in ebx
  189. mov      word ptr ParmList[2],ax
  190.  
  191. ;----------- get handle for KBD device ---------------
  192. $DosOpen offset KBDdevice,offset KBDhandle,offset KBDactcode,KBDsize,KBDattr,KBDopenflag,KBDopenmode,KBDexta
  193.  
  194. ;------ set typematic rate via Function 54h
  195.  
  196. $DosDevIOCtl KBDhandle,Category,Function,offset ParmList,ParmLnthMax,offset ParmLnthInOut,DataPkt,DataPktLnthMax,offset DataPktLnthInOut
  197.  
  198.  
  199.  
  200. $DosExit
  201.  
  202. END   startup                    ;required
  203.  
  204.  
  205.  
  206.