1. dos wait loop
- Posted by Tone Škoda <tskoda at email.si> Mar 28, 2005
- 591 views
- Last edited Mar 29, 2005
how can i in dos program make it so that following loop won't slow the system down: while 1 do -- on every half a second check something end while in windows i can use timer to achieve this functionality, is there something similar in dos? btw, does anyone know of a library for communication between dos and windows program? or how it can be done, besides via a file?
2. Re: dos wait loop
- Posted by Tone Škoda <tskoda at email.si> Mar 29, 2005
- 504 views
i mean it has to be possible. how does wait_key() do it? i want for dos (console) program to wait for a message from windows program. it would work perfectly if i could simulate keypress, then i could use getc(0) which would do all three things: 1) wait for a "message" 2) it wouldn slow the operating system down 3) it would pause its program execution. Tone Škoda wrote: > > how can i in dos program make it so that following loop won't slow the system > down: > > while 1 do > -- on every half a second check something > end while > > in windows i can use timer to achieve this functionality, is there something > similar > in dos? > > > btw, does anyone know of a library for communication between dos and windows > program? > or how it > > can be done, besides via a file? >
3. Re: dos wait loop
- Posted by jacques deschênes <desja at globetrotter.net> Mar 29, 2005
- 501 views
Hi Tone, The clipboard is available to DOS shell via a virtual driver I did use it some years ago. For that I written clipbrd.e in 1997 If you can't find it in euphoria archives I could e-mail it to you. regards, Jacques deschenes
4. Re: dos wait loop
- Posted by jacques deschênes <desja at globetrotter.net> Mar 29, 2005
- 516 views
Hi Tone, By DOS program, do you really means MS-DOS program or a windows console,There is a big difference between the 2? Are you using windows 9x or windows 2000/xp? If you are talking about windows console application all win32 API functions are available to your console application, So you can create a new process using CreateProcess() that return to you application immedialely. Creating a new process means starting a new application. regards Jacques D.
5. Re: dos wait loop
- Posted by Alexander Toresson <alexander.toresson at gmail.com> Mar 29, 2005
- 507 views
Tone *koda wrote: > > i mean it has to be possible. how does wait_key() do it? > i want for dos (console) program to wait for a message from windows program. > > it would work perfectly if i could simulate keypress, then i could use getc(0) > which > would do all three things: 1) wait for a "message" 2) it wouldn slow the > operating > system down 3) it would pause its program execution. > > > Tone *koda wrote: > > > > how can i in dos program make it so that following loop won't slow the > > system down: > > > > while 1 do > > -- on every half a second check something > > end while > > > > in windows i can use timer to achieve this functionality, is there something > > similar > > in dos? > > > > > > btw, does anyone know of a library for communication between dos and windows > > program? > > or how it > > > > can be done, besides via a file? > > > AFAIK, it's not possible to pause a dos program so it doesn't use any cpu, because dos is not a multitasking os. You'd have to "contact" windows in some way, but I dunno how you'd do that. What you want is to tell windows to do something that it normally just does for windows programs. Regards, Alexander Toresson
6. Re: dos wait loop
- Posted by Alexander Toresson <alexander.toresson at gmail.com> Mar 29, 2005
- 497 views
Tone *koda wrote: > > i mean it has to be possible. how does wait_key() do it? > i want for dos (console) program to wait for a message from windows program. > > it would work perfectly if i could simulate keypress, then i could use getc(0) > which > would do all three things: 1) wait for a "message" 2) it wouldn slow the > operating > system down 3) it would pause its program execution. > > > Tone *koda wrote: > > > > how can i in dos program make it so that following loop won't slow the > > system down: > > > > while 1 do > > -- on every half a second check something > > end while > > > > in windows i can use timer to achieve this functionality, is there something > > similar > > in dos? > > > > > > btw, does anyone know of a library for communication between dos and windows > > program? > > or how it > > > > can be done, besides via a file? > > > Forgot to answer your second question -- You could do it with tcp/ip. Regards, Alexander Toresson
7. Re: dos wait loop
- Posted by Tone Škoda <tskoda at email.si> Mar 29, 2005
- 536 views
- Last edited Mar 30, 2005
jacques deschênes wrote: > > > Hi Tone, > By DOS program, do you really means MS-DOS program or a windows console,There > is a big difference between the 2? Are you using windows 9x or windows > 2000/xp? > If you are talking about windows console application all win32 API functions > are available to your console application, So you can create a new process > using > CreateProcess() that return to you application immedialely. Creating a new > process > means starting a new application. > > regards > Jacques D. > by dos program i mean program which is run with ex.exe. i'm using winxp, but it has to work on all versions of Windows. i found clipbrd.e. now i have already written communication library which uses a file to communicate. i'll use clipboard if something doesnt work with this lib i wrote, but i dont like the idea that what user has put into clipboard gets deleted.
8. Re: dos wait loop
- Posted by "Kat" <gertie at visionsix.com> Mar 30, 2005
- 503 views
On 29 Mar 2005, at 2:05, Alexander Toresson wrote: > > > posted by: Alexander Toresson <alexander.toresson at gmail.com> > > Tone *koda wrote: > > > > i mean it has to be possible. how does wait_key() do it? > > i want for dos (console) program to wait for a message from windows program. > > > > it would work perfectly if i could simulate keypress, then i could use > > getc(0) > > which would do all three things: 1) wait for a "message" 2) it wouldn slow > > the > > operating system down 3) it would pause its program execution. > > > > > > Tone *koda wrote: > > > > > > how can i in dos program make it so that following loop won't slow the > > > system down: > > > > > > while 1 do > > > -- on every half a second check something > > > end while > > > > > > in windows i can use timer to achieve this functionality, is there > > > something > > > similar in dos? > > > > > > > > > btw, does anyone know of a library for communication between dos and > > > windows > > > program? or how it > > > > > > can be done, besides via a file? > > > > > > AFAIK, it's not possible to pause a dos program so it doesn't use any cpu, > because dos is not a multitasking os. Win95 is a preemptive multitasking os, so the dos program cannot use 100% of the cpu (take it away from other tasks) even if it wanted to. In windows before win95, it could hog the cpu and prevent other tasks from running. To make it run and not use cpu, hook the clock interrupt and just don't go back to your task for a bit of no ops. This won't accomplish anything, but your task won't do anything either. I tend to use something along these lines for dos apps with win95 if i need the task to wait, but do things periodically while waiting: sleeptime = 60 temp = 0 junk = 1 -- 1 = sleep ; 0 = return to OS while temp < sleeptime do sleep(junk) temp += 1 -- do other stuff once a sec here end while Or just sleep(time_in_seconds). Kat
9. Re: dos wait loop
- Posted by Tone Škoda <tskoda at email.si> Mar 30, 2005
- 493 views
Kat wrote: > I tend to use something along these lines for dos apps with win95 if i need > the task to wait, but do things periodically while waiting: > > sleeptime = 60 > temp = 0 > junk = 1 -- 1 = sleep ; 0 = return to OS > while temp < sleeptime do > sleep(junk) > temp += 1 > -- do other stuff once a sec here > end while > this works! the only problem is that sleep() takes only whole numbers (i want interval smaller than one second).
10. Re: dos wait loop
- Posted by jacques deschênes <desja at globetrotter.net> Mar 31, 2005
- 501 views
Tone wrote, >this works! the only problem is that sleep() takes only whole numbers (i want >interval >smaller than one second). maybe this code I wrote in 1996 could help you with delay smaller than 1 second. just call delay() like you would call sleep() with an integer but this parameter is not seconds but a fraction of a second see comments to know how to compute the delay -- delay.e -- Creation date: September 20th, 1996 -- By: Jacques Deschenes, Baie-Comeau, PQ, Canada, e-mail desja at quebectel.com -- -- PC's timer chip (Intel 8253) contain 3 16 bits counters. Used by the system -- for intervals timing. -- timer 0 of this chip is running at a frequency of 1.193180MHz -- As timer 0 is a 16 bits counter it takes about .054 seconds to cycle the -- counter. (an interrupt is generate at this interval) -- delay read the counter of timer 0 and base it's interval on the count. -- This timer chip uses 4 I/O ports: -- control register at #43 -- timer 0 count read/write at #40 -- timer 1 count read/write at #41 -- timer 2 count read/write at #42 include machine.e -- constant TMR_CTRL = #43, TMR0_COUNT = #40 constant sReadCtr={ #B8, 0,0,0,0, -- MOV EAX, 0 #E6, #43, -- OUT #43, AL #E4, #40, -- IN AL, #40 #86, #C4, -- XCHG AL, AH #E4, #40, -- IN AL, #40 #86, #C4, -- XCHG AL,AH #A3,0,0,0,0, -- MOV [Storage], EAX #C3, -- RET 0,0,0,0 -- DW ;storage } integer CodeOK atom cReadCtr, CtrAddr function InitDelay() cReadCtr = allocate(length(sReadCtr)) if cReadCtr = 0 then return 0 end if poke(cReadCtr,sReadCtr) CtrAddr = cReadCtr+length(sReadCtr)-4 poke(cReadCtr+16,int_to_bytes(CtrAddr)) lock_memory(cReadCtr,length(sReadCtr)) return 1 end function --InitDelay() global procedure delay(atom sec) -- parameter: sec is delay in seconds -- The timer 0 runs in mode 3, in which it counts down by twos, -- so delay(1193180) will only delay half a second, therefore one should -- double that number: -- clocks = sec * 2386360 -- theorical resolution is .41 microsecond -- practical resolution is reduce due to overhead and depend on computer speed atom last, next, tmp integer clocks sequence ctr if not CodeOK then return end if clocks = floor(sec*2386360) -- Read the counter value. call(cReadCtr) ctr = peek({CtrAddr,2}) last=ctr[1]+ctr[2]*#100 while clocks > 0 do -- Read the counter value. call(cReadCtr) ctr = peek({CtrAddr,2}) next=ctr[1]+ctr[2]*#100 tmp = last - next if tmp < 0 then tmp = tmp + 65536 end if clocks = clocks - tmp last = next end while -- clocks > 0 end procedure --delay() CodeOK = InitDelay() ---------------------------- -- end of code ---------------------------- regards, jacques d.
11. Re: dos wait loop
- Posted by jacques deschênes <desja at globetrotter.net> Mar 31, 2005
- 504 views
Tone, I made a mistake the parameter of delay() is in seconds but can be a fraction of it. it's not an integer but an atom so delay(0.01) is permitted. regards, Jacques D.
12. Re: dos wait loop
- Posted by Tone Škoda <tskoda at email.si> Apr 01, 2005
- 501 views
jacques deschênes wrote: > > > maybe this code I wrote in 1996 could help you with delay smaller than 1 > second. > just call delay() like you would call sleep() it doesn't seem to work right: task manager shows 100% CPU usage. what i basically need is doEvents() version for dos. some asm command? i was searching web, maybe asm hlt ?
13. Re: dos wait loop
- Posted by Derek Parnell <ddparnell at bigpond.com> Apr 01, 2005
- 506 views
Tone Škoda wrote: > > jacques deschênes wrote: > > > > > > maybe this code I wrote in 1996 could help you with delay smaller than 1 > > second. > > just call delay() like you would call sleep() > > > it doesn't seem to work right: task manager shows 100% CPU usage. > > what i basically need is doEvents() version for dos. some asm command? i was > searching > web, maybe asm hlt ? > MS-DOS is not designed to know that other programs may also be running at the same time. What are you trying to achieve by 'waiting'? Anyhow, if you really must, I recommend trapping INT 1C, and when you want to 'wait', just count the appropriate number of ticks (65535 per hour) and when not waiting, just ignore the interrupts. -- Derek Parnell Melbourne, Australia irc://irc.sorcery.net:9000/euphoria
14. Re: dos wait loop
- Posted by "Kat" <gertie at visionsix.com> Apr 01, 2005
- 498 views
On 31 Mar 2005, at 18:27, Derek Parnell wrote: > > > posted by: Derek Parnell <ddparnell at bigpond.com> > > Tone =8Akoda wrote: > >=20 > > jacques desch=EAnes wrote: > > >=20 > > >=20 > > > maybe this code I wrote in 1996 could help you with delay smaller tha= n 1 > > > second. just call delay() like you would call sleep() > >=20 > >=20 > > it doesn't seem to work right: task manager shows 100% CPU usage. > >=20 > > what i basically need is doEvents() version for dos. some asm command? = i was > > searching web, maybe asm hlt ? > >=20 > > MS-DOS is not designed to know that other programs may also be running at= the > same time. What are you trying to achieve by 'waiting'? > > Anyhow, if you really must, I recommend trapping INT 1C, and when you > want to 'wait', just count the appropriate number of ticks (65535 per hou= r) and > when not waiting, just ignore the interrupts. Right, this was the basis for making multitasking dos OSs. Just trap the= clock and save cpu registers, and load the registers saved from the next= shell to execute in. This method works fine on the Commodore 64. Kat
15. Re: dos wait loop
- Posted by Tone Škoda <tskoda at email.si> Apr 01, 2005
- 499 views
Derek Parnell wrote: > MS-DOS is not designed to know that other programs may also be running at the > same time. What are you trying to achieve by 'waiting'? i want to SendMessage() a message from euphoria program run in exw.exe to euphoria program run in ex.exe. ex.exe program has to be notified that message has arrived, and then it sends a message back to exw.exe program. i communicate via files. just like i can communicate between two Windows programs with SendMessage(). basically i want an OS-independant communication-between-two-programs system. > > Anyhow, if you really must, I recommend trapping INT 1C, and when you > want to 'wait', just count the appropriate number of ticks (65535 per hour) > and when not waiting, just ignore the interrupts. sorry, dont understand this.
16. Re: dos wait loop
- Posted by Alexander Toresson <alexander.toresson at gmail.com> Apr 01, 2005
- 484 views
Tone *koda wrote: > > Derek Parnell wrote: > > > MS-DOS is not designed to know that other programs may also be running at > > the > > same time. What are you trying to achieve by 'waiting'? > > i want to SendMessage() a message from euphoria program run in exw.exe to > euphoria > program run in ex.exe. ex.exe program has to be notified that message has > arrived, > and then it sends a message back to exw.exe program. i communicate via files. > > > just like i can communicate between two Windows programs with SendMessage(). > > basically i want an OS-independant communication-between-two-programs system. Why do you put so much effort into this, and why not just write both programs for windows? I mean, those two programs will depend on windows nevertheless! If you really wish to do this anyway, I recommend looking at the source of DS4QB, or DirectSound for QuickBasic, in which they do exactly what you want. Or maybe you could try communicating through tcp between the programs. Regards, Alexander Toresson