flat assembler
Message board for the users of flat assembler.
Index
> DOS > Delay |
Author |
|
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. |
|||
16 Apr 2004, 15:58 |
|
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 } |
|||
16 Apr 2004, 16:37 |
|
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!!! |
|||
16 Apr 2004, 16:45 |
|
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.
|
|||
16 Apr 2004, 19:17 |
|
Tomasz Grysztar 24 Apr 2004, 23:27
This may not work correctly under Windows, but in pure DOS should be OK.
|
|||
24 Apr 2004, 23:27 |
|
vid 25 Apr 2004, 07:52
accurate timing in DOS box under windows is quite impossible, no way, forget it
|
|||
25 Apr 2004, 07:52 |
|
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... |
|||
07 May 2004, 13:01 |
|
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. |
|||
09 May 2004, 04:26 |
|
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 |
|||
23 Oct 2004, 16:04 |
|
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. |
|||
26 Oct 2004, 11:06 |
|
Matrix 26 Oct 2004, 12:41
that function does nothing on my system, Win98 Win98se WinME WinXP Code: mov ah,86h int 15h |
|||
26 Oct 2004, 12:41 |
|
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 |
|||
29 Oct 2004, 15:02 |
|
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 |
|||
01 Dec 2007, 12:16 |
|
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|||
01 Dec 2007, 12:57 |
|
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. |
|||
03 Dec 2007, 06:32 |
|
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. |
|||
03 Dec 2007, 07:07 |
|
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) |
|||
03 Dec 2007, 09:15 |
|
sinsi 03 Dec 2007, 09:32
Hopefully the "jnb" will take care of that 1-in-a-million certainty
|
|||
03 Dec 2007, 09:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.