home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n20.zip / DELM.ZIP / DELM.ASM next >
Assembly Source File  |  1991-08-13  |  8KB  |  161 lines

  1.               PAGE  96,132
  2. ;**********************************************************************
  3. ; DELM.ASM                       Clipper UDF to delay n timer ticks
  4. ; Author..: Sal Ricciardi
  5. ;
  6. ; Use this file for program delays that are the same regardless
  7. ; of CPU type and speed.  Relies on the BIOS timer tick count.
  8. ; Maximum delay is 65535 ticks (about 1 hr).  Does not validate
  9. ; passed parameters.
  10. ;
  11. ; This version should work better under multitasking systems like
  12. ; Desqview or Microsoft Windows.
  13. ;
  14. ; Create with:   TASM delm  (Borland Turbo Assembler 2.5)
  15. ;                TLINK delm
  16. ;                EXE2BIN delm
  17. ;                DEL DELM.OBJ
  18. ;                DEL DELM.MAP
  19. ;                DEL DELM.EXE
  20. ;
  21. ; Usage:  (dBASE III Plus, FoxBASE+, dBASE IV)
  22. ;
  23. ; .LOAD DELM
  24. ; .ticks = 10 * 18.2                   && for 10 seconds
  25. ; .CALL DELM WITH STR(ticks)           && Don't forget the parameter
  26. ; .RELEASE DELM
  27. ;
  28. ;**********************************************************************
  29.               .MODEL SMALL
  30.               .CODE
  31.  
  32. Timerhigh     EQU   WORD PTR ds:[06eh]
  33. Timerlow      EQU   WORD PTR ds:[06ch]
  34.  
  35. delay         PROC  FAR                         ;entry point
  36.               push  ax                          ;save registers
  37.               push  bx                          ;
  38.               push  cx                          ;
  39.               push  dx                          ;
  40.               push  es                          ;
  41.               push  ds                          ;
  42.  
  43.               call  asc2bin                     ;convert parameter to binary
  44.               mov   cx,ax                       ;put it in cx
  45.               jcxz  d999                        ;skip if cx==0
  46.               mov   ax,040h                     ;
  47.               mov   ds,ax                       ;ds == 040h
  48. ;
  49. ; Get current timer count.  Make sure we get both low and high at the same time.
  50. ;
  51.               cli                               ;interrupts off
  52.               mov   ax,Timerlow                 ;get current tick count low
  53.               mov   dx,Timerhigh                ;get current tick count high
  54.               sti                               ;interrupts on
  55. ;
  56. ; Add the delay value to form the target timer count.
  57. ;
  58.               add   ax,cx                       ;add ticks parameter to form
  59.               adc   dx,0                        ;target
  60.                                                 ;
  61.               cmp   dx,018h                     ;q. target past midnight?
  62.               jb    d500                        ;a. no, handle normally
  63.               ja    d400                        ;a. yes, go handle special case
  64.                                                 ;
  65.               cmp   ax,0B0h                     ;q. target past midnight?
  66.               jb    d500                        ;a. no, handle normally
  67. ;
  68. ; Target is past midnight.  Adjust target and wait for midnight.
  69. ;
  70. d400:
  71.               sub   ax,0B0h                     ;subtract max to adjust the
  72.               sbb   dx,018h                     ;target
  73. d410:                                           ;is past midnight
  74.               cmp   Timerhigh,016h              ;q. cross midnight yet?
  75.               jae   d410                        ;a. no,loop
  76. ;
  77. ; Delay until target time.  This is where we attempt some level of insulation
  78. ; from multitasker interruption.
  79. ;
  80. d500:
  81.               cmp   Timerhigh,dx                ;q. timerhigh reach the target?
  82.               je    d510                        ;a. yes, check timerlow
  83. ;
  84. ; Timerhigh could be greater than target if a multitasker had
  85. ; control for awhile, and we just returned
  86. ;
  87.               ja    d999                        ;a. greater than, we're done
  88. ;
  89. ; Could be less than by more than one if multitasker had control for awhile,
  90. ; and during that time midnight passed
  91.                                                 ;a. timerhigh is less than target
  92.               mov   bx,dx                       ;get target in bx
  93.               sub   bx,Timerhigh                ;subtract current timerhigh
  94.                                                 ;
  95.               cmp   bx,1                        ;q. more than one less?
  96.               jne   d999                        ;a. yes, must be done
  97.  
  98.               jmp   d500                        ;a. go check again
  99. d510:                                           ;
  100.               cmp   Timerlow,ax                 ;q. timerlow less than target?
  101.               jb    d510                        ;a. yes, loop
  102. ;
  103. ; Clean up and return to caller
  104. ;
  105. d999:                                           ;
  106.               pop   ds                          ;restore ds
  107.               pop   es                          ;restore registers
  108.               pop   dx                          ;
  109.               pop   cx                          ;
  110.               pop   bx                          ;
  111.               pop   ax                          ;
  112.               ret                               ;return to caller
  113. delay         ENDP
  114.  
  115. ;----------------------------------------------------------------------
  116. ; asc2bin     Convert ascii decimal string to 16-bit unsigned binary
  117. ;
  118. ; Entry:  DS:BX --> ascii string
  119. ; Exit:   AX = 16-bit number
  120. ;
  121. ; Ignores leading blanks, then conversion stops at null or first
  122. ; non numeric.
  123. ;----------------------------------------------------------------------
  124. asc2bin       PROC
  125.               push  bx                          ;Save bx and dx
  126.               push  dx                          ;
  127.               mov   si,bx                       ;Get offset in si
  128.               xor   ax,ax                       ;Clear ax
  129.               xor   bx,bx                       ;and bx
  130.               xor   dx,dx                       ;and dx
  131. a00001:                                         ;
  132.               cmp   BYTE PTR ds:[si],' '        ;q. leading blanks?
  133.               jne   a00010                      ;a. no.. move on
  134.               inc   si                          ;a. yes.. ignore leading blanks
  135.               jmp   a00001                      ;(so we can use STR() function)
  136.                                                 ;
  137. a00010:       lodsb                             ;Get next ascii byte
  138.               or    al,al                       ;q. is it zero?
  139.               jz    a00090                      ;a. yes .. finished
  140.               cmp   al,'9'                      ;q. is > 9?
  141.               ja    a00090                      ;a. yes .. finished
  142.               cmp   al,'0'                      ;q. is it < 0?
  143.               jb    a00090                      ;a. yes .. finished
  144. a00020:                                         ;Multiply current answer by 10
  145.               mov   dx,bx                       ;Save in dx
  146.               shl   bx,1                        ;* 2
  147.               shl   bx,1                        ;* 4
  148.               add   bx,dx                       ;* 5
  149.               shl   bx,1                        ;* 10
  150.               and   ax,0fh                      ;Mask off ascii
  151.               add   bx,ax                       ;Add to result
  152.               jmp   a00010                      ;go get next byte
  153. a00090:                                         ;
  154.               mov   ax,bx                       ;Put result in ax
  155.               pop   dx                          ;Restore registers
  156.               pop   bx                          ;
  157.               ret                               ;return to caller
  158. asc2bin       ENDP
  159.  
  160.               END
  161.