flat assembler
Message board for the users of flat assembler.

Index > DOS > Delay

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY 16 Apr 2004, 15:58
How to get a delay for a specified number of seconds, I mean wait some seconds to continue the program, for example, 3 seconds?
Thanks.
Post 16 Apr 2004, 15:58
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 16 Apr 2004, 16:37
Code:
macro delay nms
 {
        mov     ah,86h
        if      nms < 10000h
        xor     cx,cx
        else
        mov     cx,nms shr 16
        end if
        mov     dx,nms and 0FFFFh
        int     15h
 }    
Post 16 Apr 2004, 16:37
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY 16 Apr 2004, 16:45
Thanks. But, there isn't a more simple way?
I don't understand that microseconds... and what's on going on the cx and the dx?
Thanks a lot Privalov!!!
Post 16 Apr 2004, 16:45
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 16 Apr 2004, 19:17
dx contains less significent word, cx - more significent. Take a look here: http://www.ctyme.com/intr/rb-1525.htm.
Post 16 Apr 2004, 19:17
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY 24 Apr 2004, 19:37
I've tested this:
Code:
macro delay nms 
{ 
        mov     ah,86h 
        if      nms < 10000h 
        xor     cx,cx 
        else 
        mov     cx,nms shr 16 
        end if 
        mov     dx,nms and 0FFFFh 
        int     15h 
}

org 100h
delay 20000
int 20h
    

And it's not working...
What to do to make it work?
Thanks...
Post 24 Apr 2004, 19:37
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 24 Apr 2004, 23:27
This may not work correctly under Windows, but in pure DOS should be OK.
Post 24 Apr 2004, 23:27
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Apr 2004, 07:52
accurate timing in DOS box under windows is quite impossible, no way, forget it
Post 25 Apr 2004, 07:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Vion



Joined: 26 Apr 2004
Posts: 6
Vion 07 May 2004, 13:01
I normally do something else (in Basic, at least):
I let it do something (e.g.: count) until some seconds have passed, and then use this value & method for timig: if it counts to 20000 in ten secs, then it will count to 200 in 1/10 sec. This, of course, would be a tautology, if you do not know, how to get the time (i don't - sorry), but otherwise it should be a way, though not a perfect one... Confused
Post 07 May 2004, 13:01
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 09 May 2004, 04:26
This code in nasm easy to convert to fasm, Works for none critical time,70 = 1 second.
Code:
BITS 16ORG 100hSECTION .textSTART:        xor ah,ah        int 16h        mov  word[count],0ddf:        call FullVertWait        cmp word [count],70        jne  ddf   ;Do some thing in here        xor ah, ah        int 16h        mov ax, 04c00h        int 21h;**************************FullVertWait:        MOV    DX,3DAhVr:        IN      AL,DX        TEST    AL,8        JNZ    Vr          ;wait until Verticle Retrace startsNvr:        IN      AL,DX        TEST    AL,8        JZ      Nvr        ;wait until Verticle Retrace Ends        ADD    word[count],1        RET;**************************SECTION .datacount    dw 0    


It use the Verticle Retrace for timer.

ASHLEY4.
Post 09 May 2004, 04:26
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 23 Oct 2004, 16:04
Code:
; PIT timer Delay function by Matrix

org 256

call setup_pit_timer ; lets set pit timer to rate generator

; your code goes here
nop
nop
nop
; your code goes here

mov cx,18 ; wait 18*(65536/$1234DD seconds ( in this case it will be approx 1 s)
call pit_tick_delay


call reset_pit_timer ; lets reset pit timer to normal mode

int 20h ; exit

pit_tick_delay:  ; waits cx ticks, destroys: ax bx
cli ;if you need accurate timing uncomment this
  call      read_pit_value
 mov         bx,ax
.below:
  call   read_pit_value
 cmp         ax,bx
   jl   .below
.above:
  call         read_pit_value
 cmp         ax,bx
   jg    .above
 loop       .below
sti ;if you need accurate timing uncomment this
ret

reset_pit_timer:
 mov al,00110110b ; count down twice generator
jmp setupcommon
setup_pit_timer:  ; returns status in al
 mov al,00110100b ; rate generator
setupcommon:
;cli ;if you need accurate timing comment this refer to above
 out 43h,al
 xor al,al
 out $40,al
 out $40,al
.waitlatch:
 mov al,11100010b ; get timer 0 status
  out 43h,al
  in al,40h
shr al,7;bt ax,6
jc .waitlatch
;sti ;if you need accurate timing comment this refer to above
ret

read_pit_value:
;.waitlatch:                                  ; if you have early 8253s comment
; mov al,11100010b ; get timer 0 status       ; this part out
; out 43h,al                                  ; ( wais for latch to be valid )
; in al,40h                                   ;
;bt ax,6                                      ;
;jc .waitlatch                                ;
  mov al,11010010b
;cli ;if you don't need accurate timings, you can use cli sti here instead of above
  out 43h,al
  in al,40h
  mov ah,al
  in al,40h
;sti ;if you don't need accurate timings, you can use cli sti here instead of above
  xchg al,ah
ret
    


Last edited by Matrix on 15 Nov 2004, 23:57; edited 1 time in total
Post 23 Oct 2004, 16:04
View user's profile Send private message Visit poster's website Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth 26 Oct 2004, 11:06
int 15h, ah=86h works in win9x dos box, but not on NT platforms.
I once wrote a Win32 API Sleep emulation function for DOS:

Code:

        .386
i        .MODEL FLAT, stdcall

?USEDOSIDLE                equ 0           ;problems in WinXP
?USEKERNELIDLE    equ 0

        .DATA

public dwIdleProc

dwIdleProc dd 0

        .CODE

GiveupTimeSlice proc private uses ebx
        mov     eax,[dwIdleProc]
        and     eax,eax
        jz      @F
        call    eax
        ret
@@:
if ?USEDOSIDLE
        int     28h
endif
if ?USEKERNELIDLE
        mov     ax,1689h
else
               xor             ebx,ebx
        mov     ax,1680h
endif
        int     2Fh
        ret
GiveupTimeSlice   endp

Sleep proc dwInterval:dword

             mov             ecx,dwInterval
        jecxz noint
               cmp             dwIdleProc,0
        jnz             @F
        mov               eax,1000
        mul         ecx
        push     eax
        pop              dx
        pop               cx
        stc
        mov                ah,86h
        int           15h
        jnc              done                    ;may fail (on NT platform)
@@:        
        mov            eax,dwInterval
        xor           edx,edx
        mov          ecx,55
        div           ecx
        add              eax,@flat:[46ch]
        .while  (eax > @flat:[46ch])
         push    eax
            call GiveupTimeSlice
            pop              eax
        .endw
        jmp             done
noint:        
          call    GiveupTimeSlice
done:        
        ret
        
Sleep endp

   end
    


which works on DOS, win9x/NT/2k/XP and even DOSEMU.
Problem for NT platform is that it consumes CPU, because there seems no way to give up the time slice.
Post 26 Oct 2004, 11:06
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 26 Oct 2004, 12:41
Sad
that function does nothing on my system,
Win98 Win98se WinME WinXP

Code:
   mov             ah,86h 
        int             15h 
    
Post 26 Oct 2004, 12:41
View user's profile Send private message Visit poster's website Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog 29 Oct 2004, 15:02
Ralf Brown's CMOS.TXT has info for port 70h & 71 (read time) stuff.
AH=2Ch INT 21h get time

I like to use the Dword TICK COUNT at 0040:006Ch for a timer.
I think there are about 18 ticks per second.
TICKS SINCE MIDNIGHT, so an asm timer fails at midnight when
the counter is automatically zeroed out by the system.

AH=86h INT 15h requires CX:DX = Dword time in multiples of 976
but since it starts at 0, 975 is the lowest value possible,
then add mutiples of 976 to 975. Or DEC CX:DX after MUL
(it worked for me anyway)

Well, there's some ideas anyway.
Bitdog

KILLSEC: ;proc, call with CX=seconds to kill (18=1 sec)
XOR AX,AX ; call
MOV GS,AX ;keep seg reg GS=0 for BIOS & INT vector addressing?
KS01:
CMP AL,[GS:046Ch]
JZ KS01
MOV AL,[GS:046Ch]
LOOP KS01 ;loops every time TICK byte changes
RET
Post 29 Oct 2004, 15:02
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1398
Location: Piraeus, Greece
Picnic 01 Dec 2007, 12:16
I used this for a simple scrolling text i wrote on DosBox emu, it gave me a small delay i need.
Code:
    mov al,[gs:46Ch]                
    ks01: 
    cmp al,[gs:46Ch]             
    je ks01
    

_________________
Hobby BASIC Interpreter
Post 01 Dec 2007, 12:16
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 01 Dec 2007, 12:57
delay in seconds
two manners.

with keyboard:
Code:
@@:         ;wait a key
in al,60h   ;here the delay is human
or al,al      ;he he
je @b
    


or with RTC port 70h & 71h
Code:
;;;;;;;;set RTC time&date in BINARY;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov al,0bh
out 70h,al
in al,71h
or al,4
ror ax,8
mov al,0bh
out 70h,al
ror ax,8
out 71h,al
;;;;;;;;;;;;;;read seconds;;;;;;;;;;;;;;;;
;;;;;;;;;;;;waiting N seconds;;;;;;;;;;;;;
delays:
;DL=DeLay in second
mov ax,0
out 70h,al
in al,71h
;al = seconds of time
ror ax,8
@@:
out 70h,al
in al,71h
sub al,ah
je @b
dec dl
jne delays
ret
;;;;;;;;;;;;;;;;how to call it;;;;;;;;;
mov dl,10 ;wait 10 seconds
call delays
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    
Post 01 Dec 2007, 12:57
View user's profile Send private message Visit poster's website Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 03 Dec 2007, 06:32
what about useing the time stamp counter? theres not much over head that way. the delay routine would have to be initialized before you could use it ie; you need to find out how many times it increments per second on the machine, then divide that by 10 to find out how many times per milisecond. From there, every time you want to delay just loop through the rdtsc timer until the count is reached.

nb. i'm not good at explaining theese things, but hope you get the idea.

_________________
New User.. Hayden McKay.
Post 03 Dec 2007, 06:32
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 03 Dec 2007, 07:07
Wait for 5 seconds
Code:
     sub ax,ax
     mov es,ax
     mov eax,[es:46ch] ;get the tick count in EAX
     add eax,91        ;5 seconds (18.2 ticks/sec * 5)
.1:  cmp eax,[es:46ch] ;elapsed yet?
     jnb .1            ;not yet
    

Of course, make sure interrupts are enabled, otherwise it will be a loooong 5 seconds.
Post 03 Dec 2007, 07:07
View user's profile Send private message Reply with quote
ATV



Joined: 31 Aug 2004
Posts: 109
Location: Finland
ATV 03 Dec 2007, 09:15
One warning when messing with [46ch], remember day change too.

_________________
6213186413*2^605+1 divides Fermat F(600) and 121531*2^30260+1 divides Fermat F(30256)
Post 03 Dec 2007, 09:15
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 03 Dec 2007, 09:32
Hopefully the "jnb" will take care of that 1-in-a-million certainty Laughing
Post 03 Dec 2007, 09:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.