Re: dos wait loop

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu