home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n20.zip / DELAY.ZIP / DELAY.ASM next >
Assembly Source File  |  1991-10-28  |  5KB  |  102 lines

  1. ;**********************************************************************
  2. ; DELAY.ASM                         .BIN file to delay n timer ticks
  3. ; Author..: Sal Ricciardi
  4. ;
  5. ; Use this file for program delays that are the same irregardless
  6. ; of CPU type and speed.  Relies on the BIOS timer tick count.
  7. ; Maximum delay is 65535 ticks (about 1 hr).  Does not validate
  8. ; passed parameters.
  9. ;
  10. ; Create with:   TASM delay  (Borland Turbo Assembler 2.5)
  11. ;                TLINK delay
  12. ;                EXE2BIN delay
  13. ;                DEL DELAY.OBJ
  14. ;                DEL DELAY.MAP
  15. ;                DEL DELAY.EXE
  16. ;
  17. ; Usage:  (dBASE III Plus, FoxBASE+, dBASE IV)
  18. ;
  19. ; .LOAD DELAY
  20. ; .ticks = 10 * 18.2                    && for 10 seconds
  21. ; .CALL DELAY WITH STR(ticks)           && Don't forget the parameter
  22. ; .RELEASE DELAY
  23. ;
  24. ;**********************************************************************
  25.               .MODEL SMALL
  26.               .CODE
  27.  
  28. Timerlow      EQU   WORD PTR ds:[06ch]
  29.  
  30. delay         PROC  FAR                         ;entry point
  31.               push  ax                          ;save registers
  32.               push  cx                          ;
  33.               push  ds                          ;
  34.               push  es                          ;
  35.               push  si                          ;
  36.                                                 ;
  37.               call  asc2bin                     ;convert parameter to binary
  38.               mov   cx,ax                       ;get ticks in cx
  39.               jcxz  d999                        ;if cx==0, skip it
  40.               mov   ax,040h                     ;
  41.               mov   ds,ax                       ;ds == 040h
  42. d010:                                           ;
  43.               mov   ax,Timerlow                 ;get timer tick count low
  44. d020:                                           ;
  45.               cmp   ax,Timerlow                 ;watch for it to change
  46.               je    d020                        ;keep watching until it does
  47.               loop  d010                        ;keep looping until cx == 0
  48. d999:                                           ;
  49.               pop   si                          ;restore registers
  50.               pop   es                          ;
  51.               pop   ds                          ;
  52.               pop   cx                          ;
  53.               pop   ax                          ;
  54.               ret                               ;return to caller
  55. delay         ENDP
  56.  
  57. ;----------------------------------------------------------------------
  58. ; asc2bin     Convert ascii decimal string to 16-bit unsigned binary
  59. ;
  60. ; Entry:  DS:BX --> ascii string
  61. ; Exit:   AX = 16-bit number
  62. ;
  63. ; Ignores leading blanks, then conversion stops at null or first
  64. ; non numeric.
  65. ;----------------------------------------------------------------------
  66. asc2bin       PROC
  67.               push  bx                          ;Save bx and dx
  68.               push  dx                          ;
  69.               mov   si,bx                       ;Get offset in si
  70.               xor   ax,ax                       ;Clear ax
  71.               xor   bx,bx                       ;and bx
  72.               xor   dx,dx                       ;and dx
  73. a00001:                                         ;
  74.               cmp   BYTE PTR ds:[si],' '        ;q. leading blanks?
  75.               jne   a00010                      ;a. no.. move on
  76.               inc   si                          ;a. yes.. ignore leading blanks
  77.               jmp   a00001                      ;(so we can use STR() function)
  78.                                                 ;
  79. a00010:       lodsb                             ;Get next ascii byte
  80.               or    al,al                       ;q. is it zero?
  81.               jz    a00090                      ;a. yes .. finished
  82.               cmp   al,'9'                      ;q. is > 9?
  83.               ja    a00090                      ;a. yes .. finished
  84.               cmp   al,'0'                      ;q. is it < 0?
  85.               jb    a00090                      ;a. yes .. finished
  86. a00020:                                         ;Multiply current answer by 10
  87.               mov   dx,bx                       ;Save in dx
  88.               shl   bx,1                        ;* 2
  89.               shl   bx,1                        ;* 4
  90.               add   bx,dx                       ;* 5
  91.               shl   bx,1                        ;* 10
  92.               and   ax,0fh                      ;Mask off ascii
  93.               add   bx,ax                       ;Add to result
  94.               jmp   a00010                      ;go get next byte
  95. a00090:                                         ;
  96.               mov   ax,bx                       ;Put result in ax
  97.               pop   dx                          ;Restore registers
  98.               pop   bx                          ;
  99.               ret                               ;return to caller
  100. asc2bin       ENDP
  101.               END   delay
  102.