X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Trace-PostClient-IP: 68.147.131.211 From: Brian Inglis Newsgroups: comp.os.msdos.djgpp Subject: Re: Timer inside interrupt handler Organization: Systematic Software Message-ID: References: <01c4b948$Blat.v2.2.2$f034ea00 AT zahav DOT net DOT il> <417bd729$0$173$cc7c7865 AT news DOT luth DOT se> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 87 Date: Sun, 24 Oct 2004 18:51:24 GMT NNTP-Posting-Host: 24.71.223.147 X-Complaints-To: abuse AT shaw DOT ca X-Trace: pd7tw2no 1098643884 24.71.223.147 (Sun, 24 Oct 2004 12:51:24 MDT) NNTP-Posting-Date: Sun, 24 Oct 2004 12:51:24 MDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On 24 Oct 2004 16:24:09 GMT in comp.os.msdos.djgpp, Martin Str|mberg wrote: >Jason Mills wrote: >> I did come across the following on >> the newgroup. Does it implement what you suggest? > >Yes, but... > >> Convert the real mode segment:offset pair to a linear address offset >> (relative to _dos_ds) like this: > >> 0x40 * 16 + 0x6c = 0x460 > >Looks like there's some error here. 0x40 * 16 + 0x6c = 0x46c. Note >"0x46" and a "c". Or the left hand side should read "0x40 * 16 + >0x60". I found the dusty old deck below for HRT, probably from Borland days. AFAICR it disables interrupts, freezes the timer chip count, reads it, picks up the BIOS tick count, enables interrupts, converts the countdown to an elapsed count, ensures the tick count is monotonic WRT previous tick counts and the timer count, and converts it to seconds in a double. For DJGPP, you'd need to change dos.h to cpu.h to pick up the port macros/functions, and stdlib.h to curses.h to pick up MK_FP or use #define MK_FP(seg,ofs) ((((long)(seg)) << 4) + ((long)(ofs))) and add any mapping functions if necessary to access low DOS memory. /* * getclock * * Get Time from BIOS and Timer */ #include #include #define FREQUENCY 1193180L #define TIMERCMD 0x43 #define TIMERDATA 0x40 #define BIOSDATA 0x40 #define BIOSCLOCK 0x6C double getclock( void ) { double time; unsigned long ticks; unsigned short clocklo, clockhi, clocks; static unsigned long far *tickcount = MK_FP( BIOSDATA, BIOSCLOCK); static unsigned long last_ticks = 0; static unsigned short last_clocks = 0; disable(); outportb( TIMERCMD, 0); clocklo = (unsigned)inportb( TIMERDATA ); clockhi = (unsigned)inportb( TIMERDATA ); ticks = *tickcount; enable(); clocks = 0xFFFF - ((clockhi << 8) | clocklo); while (ticks < last_ticks || (ticks == last_ticks && clocks < last_clocks)) ++ticks; last_ticks = ticks; last_clocks = clocks; time = ((double)ticks*65536.0 + (double)clocks) /(double)FREQUENCY; return time; } /* getclock */ -- Thanks. Take care, Brian Inglis Calgary, Alberta, Canada Brian DOT Inglis AT CSi DOT com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca) fake address use address above to reply