Re: dos wait loop

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

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu