3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 void delay(unsigned msec
)
36 // BIOS - WAIT (AT,PS)
39 // CX:DX = interval in microseconds
41 // CF clear if successful (wait interval elapsed)
42 // CF set on error or AH=83h wait already in progress
43 // AH = status (see #00496)
45 // Note: The resolution of the wait period is 977 microseconds on
46 // many systems because many BIOSes use the 1/1024 second fast
47 // interrupt from the AT real-time clock chip which is available on INT 70;
48 // because newer BIOSes may have much more precise timers available, it is
49 // not possible to use this function accurately for very short delays unless
50 // the precise behavior of the BIOS is known (or found through testing)
61 usec
= msec_this
* 1000;
64 Regs
.w
.cx
= usec
>> 16;
65 Regs
.w
.dx
= usec
& 0xffff;
66 Int386(0x15, &Regs
, &Regs
);
78 WRITE_PORT_UCHAR((PUCHAR
)0x61, READ_PORT_UCHAR((PUCHAR
)0x61) & ~3);
82 scale
= 1193046 / freq
;
83 WRITE_PORT_UCHAR((PUCHAR
)0x43, 0xb6);
84 WRITE_PORT_UCHAR((PUCHAR
)0x42, scale
& 0xff);
85 WRITE_PORT_UCHAR((PUCHAR
)0x42, scale
>> 8);
86 WRITE_PORT_UCHAR((PUCHAR
)0x61, READ_PORT_UCHAR((PUCHAR
)0x61) | 3);