From: kunst AT prl DOT philips DOT nl Subject: Re: Unix itimer -> Dos itimer? To: faratinp AT cs DOT man DOT ac DOT uk (Peyman Faratin) Date: Wed, 13 Jul 1994 11:55:32 +0100 (METDST) Cc: djgpp AT sun DOT soe DOT clarkson DOT edu (DJGPP users list) > > Does anybody know if djgpp has a Unix struct equivalent to itimerval? > > I'm trying to time intervals in millisecs on the system. > Basically, I'm writting a software for human reaction time testing. > The time between successive stimuli should be a variable in milliseconds. > I managed to solve the problem on Unix by using setitimer() to fill in > struct itimerval (in sys/time.h). But when I transported the code to a PC > I get djgpp error about itimerval. > > Is there such a struct and if not can anybody be kind enough to moot a > possible suggestion of alternative solutions? > Christopher Christensen (cnc AT netcom DOT com) has posted the following code to this list. Works fine for me. Expect some variations when running inside a Windows DOS-box. To be exact on the micro-second level, you'd better run outside Windows (i.e. using plain DOS). /* * File : hrtimer.s * Author : Christopher Christensen (cnc AT netcom DOT com) * Address: Huntington Beach California, USA * * You can read the timer register directly. The following code should work * assuming that the timer hasn't been reprogrammed to interrupt at more than * 18.2 Hz. The timer runs at 1193180 Hz (65536 times faster than the 18.2 * Hz timer tick). If you have problems with this code, let me know and I will * try to fix it. */ /* short timer16() -- return 16-bit timer value */ /* timer resolution is 0.8381 microseconds (1193180 Hz clock) */ /* rolls over 18.2 times per second */ .align 2 .globl _timer16 _timer16: cli movb $0xc2,%al # read back cmd (status+count) outb %al,$0x43 .byte 0xeb,0 # jmp delay inb $0x40,%al # get status (msb=out pin) movb %al,%cl .byte 0xeb,0 # jmp delay inb $0x40,%al # get LSB movb %al,%ah .byte 0xeb,0 # jmp delay inb $0x40,%al # get MSB sti xchgb %ah,%al orw %ax,%ax jz _timer16 # zero is problematic shlb $1,%cl # carry=out status rcrw $1,%ax negw %ax ret /* unsigned int timer32() -- return 32-bit timer value */ /* returns a timer with 0.8381 microsecond resolution that rolls over about once an hour */ .align 2 .globl _timer32 _timer32: call __go32_conventional_mem_selector movw %ax,%gs xorl %eax,%eax movl %gs:0x046c,%edx # read timer tick count in dos memory call _timer16 cmpl %gs:0x046c,%edx # has timer advanced? je Ldone4 testb $0x80,%ah # if msbit==0 inc %edx jnz Ldone4 incl %edx Ldone4: shll $16,%edx orl %edx,%eax ret ============================================================================== Pieter Kunst (kunst AT prl DOT philips DOT nl)