home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / delays / delays.asm next >
Assembly Source File  |  1992-12-13  |  5KB  |  113 lines

  1. ;; DELAYS.ASM - three methods to create delays.
  2. ;;
  3. ;; MILLI_DELAY:  ----------  PORT addressing method.
  4. ;;
  5. ;; BIO_ADDR_DELAY:  -------  BIO's addressing method.
  6. ;;
  7. ;; BIO_INT_DELAY:  --------  BIO's interrupt method.
  8. ;;
  9. ;;
  10. ;; This code is "PUBLIC DOMAIN"
  11. ;;
  12. ;; by William Cravener 12/13/92
  13. ;;
  14. ;;--------------------------------------------------------------------------
  15. ;;
  16. code                    SEGMENT
  17. ASSUME          cs:code, ds:code, es:code, ss:code
  18. ORG             100h                    ; COM files begin here
  19. start:
  20.         call    milli_delay             ; call first delay method
  21.         mov     al, 31h                 ; ascii number 1
  22.         call    writeit                 ; go show it
  23.         call    bio_addr_delay          ; call second delay method
  24.         mov     al, 32h                 ; ascii number 2
  25.         call    writeit                 ; go show it
  26.         call    bio_int_delay           ; call third delay method
  27.         mov     al, 33h                 ; ascii number 3
  28.         call    writeit                 ; go show it
  29.         mov     ah, 1                   ; BIO's keyboard service
  30.         int     16h                     ; see if key was pressed
  31.         jz      start                   ; jump to start if not
  32.         mov     ah, 0                   ; BIO's keyboard service
  33.         int     16h                     ; eat just pressed key
  34.         int     20h                     ; key was pressed - exit
  35. ;----------------------------------
  36. writeit:
  37.         mov     ah, 0eh                 ; BIO's teletype service
  38.         mov     bh, 0                   ; page 0
  39.         int     10h                     ; interrupt
  40.         mov     al, 0dh                 ; do a return
  41.         int     10h                     ; interrupt
  42.         ret
  43. ;---------------------------;
  44. ;  PORT ADDRESSING METHOD.  ;
  45. ;                           ;
  46. ;  The value placed in BX   ;
  47. ;  determines delay period. ;
  48. ;---------------------------;
  49. milli_delay:
  50.         mov     BX, 2850                ; roughly 1 second delay
  51. milli:
  52.         mov     al, 6                   ; binary mode 3 channel 0       
  53.         out     43h, al                 ; to counter command port
  54.         in      al, 40h                 ; retrieve LSB from channel 0
  55.         mov     dl, al                  ; place LSB in DL
  56.         in      al, 40h                 ; retrieve MSB from channel 0
  57.         mov     dh, al                  ; place MSB in DH
  58.         sub     dx, 1193                ; roughly 1 millisec ( 1193180/1000 )
  59. one_ms: 
  60.         mov     al, 6                   ; binary mode 3 channel 0
  61.         out     43h, al                 ; to counter command port
  62.         in      al, 40h                 ; retrieve LSB from channel 0
  63.         mov     cl, al                  ; place LSB in CL
  64.         in      al, 40h                 ; retrieve MSB from channel 0
  65.         mov     ch, al                  ; place MSB in CH
  66.         cmp     cx, dx                  ; CX greater then DX
  67.         ja      one_ms                  ; yes - retrieve new count
  68.         dec     bx                      ; milliseconds counter
  69.         jnz     milli                   ; continue if not finished
  70.         ret
  71. ;;
  72. ;---------------------------;
  73. ;  BIO's ADDRESS METHOD.    ;
  74. ;                           ;
  75. ;  The value placed in CX   ;
  76. ;  determines delay period. ;
  77. ;---------------------------;
  78. bio_addr_delay:
  79.         push    es                      ; save ES
  80.         mov     ax, 40h                 ; BIO's
  81.         mov     es, ax                  ; segment
  82.         mov     bx, 6ch                 ; tick counter address
  83.         mov     ax, es:[bx]             ; place tick count in AX
  84.         mov     CX, 18                  ; roughly 1 second delay
  85. delay_it:
  86.         cmp     ax, es:[bx]             ; are they equal
  87.         je      delay_it                ; yes continue
  88.         mov     ax, es:[bx]             ; no get new count
  89.         loop    delay_it                ; loop for 18 ticks
  90.         pop     es                      ; restore ES
  91.         ret
  92. ;;
  93. ;---------------------------;
  94. ;  BIO's INTERRUPT METHOD.  ;
  95. ;                           ;
  96. ;  The value added to DX    ;
  97. ;  determines delay period. ;
  98. ;---------------------------;
  99. bio_int_delay:
  100.         mov     ah, 0                   ; clock count service
  101.         int     1ah                     ; BIO's date time interrupt
  102.         add     DX, 18                  ; roughly 1 second delay
  103.         mov     bx, dx                  ; move it to BX for compare
  104. delayit:
  105.         int     1ah                     ; get another tick count
  106.         cmp     dx, bx                  ; new tick in DX = BX yet?
  107.         jne     delayit                 ; NO - get next tick count
  108.                                         ; YES - DX = BX
  109.         ret
  110. ;;---------------------------------------------------------------------------
  111. code                  ENDS
  112. END             start
  113.