1. dos wait loop

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?

new topic     » topic index » view message » categorize

2. Re: dos wait loop

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?
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: dos wait loop

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: dos wait loop

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.

new topic     » goto parent     » topic index » view message » categorize

5. Re: dos wait loop

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

new topic     » goto parent     » topic index » view message » categorize

6. Re: dos wait loop

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

new topic     » goto parent     » topic index » view message » categorize

7. Re: dos wait loop

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.

new topic     » goto parent     » topic index » view message » categorize

8. Re: dos wait loop

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 message » categorize

9. Re: dos wait loop

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).

new topic     » goto parent     » topic index » view message » categorize

10. Re: dos wait loop

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.

new topic     » goto parent     » topic index » view message » categorize

11. Re: dos wait loop

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.

new topic     » goto parent     » topic index » view message » categorize

12. Re: dos wait loop

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 ?

new topic     » goto parent     » topic index » view message » categorize

13. Re: dos wait loop

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

new topic     » goto parent     » topic index » view message » categorize

14. Re: dos wait loop

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

new topic     » goto parent     » topic index » view message » categorize

15. Re: dos wait loop

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.

new topic     » goto parent     » topic index » view message » categorize

16. Re: dos wait loop

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu