Mail Archives: djgpp/2004/10/24/15:00:09
On 24 Oct 2004 16:24:09 GMT in comp.os.msdos.djgpp, Martin Str|mberg
<ams AT speedy DOT ludd DOT ltu DOT se> wrote:
>Jason Mills <jmills AT cs DOT mun DOT ca> 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 <stdlib.h>
#include <dos.h>
#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
- Raw text -