Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Port I/O

7 views
Skip to first unread message

Tom Jackson

unread,
Mar 11, 2005, 12:16:18 PM3/11/05
to
What happened to inp(), outp() etc?
I just need to read and write to port 61h.
asm fails because it requires protected mode and it seems inp() and outp()
are no longer in conio.h
I can declare the routines myself but it seems that are not in the runtime
either.
Can anyone point me in the right direction?

Remy Lebeau (TeamB)

unread,
Mar 11, 2005, 12:57:59 PM3/11/05
to

"Tom Jackson" <tj...@comcast.net> wrote in message
news:4231d1ea$1...@newsgroups.borland.com...

> What happened to inp(), outp() etc?

They were done away with. The OS protects against direct access to hardware
now. You have to use device drivers to control hardware.

> I just need to read and write to port 61h.

What exactly are you trying to accomplish in the first place?

> asm fails because it requires protected mode and it seems
> inp() and outp() are no longer in conio.h

Correct.


Gambit


Tom Jackson

unread,
Mar 11, 2005, 4:34:23 PM3/11/05
to
Thanks.

I am trying to write a simple sound routine to the built in PC Speaker. This
is for experimental and learning purposes. I must figure out how to talk to
the driver. Can you point me in the right direction?

Tom
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:4231dc29$1...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Mar 11, 2005, 5:04:41 PM3/11/05
to

"Tom Jackson" <tj...@comcast.net> wrote in message
news:4232...@newsgroups.borland.com...

> I am trying to write a simple sound routine to the built in PC Speaker.
> This is for experimental and learning purposes. I must figure out how
> to talk to the driver. Can you point me in the right direction?

You don't need to access a driver for that. In WinNT/2K/XP/2K3, use the
Beep() function. In Win9x/Me, you can gain access to the PC speaker via
inline assembly. For example:

#pragma inline

BYTE inp(WORD Port)
{
asm
{
mov dx, Port
in al, dx
}

void outp(WORD Port, BYTE Value)
{
asm
{
mov dx, Port
mov al, Value
out dx, al
}
}

void setfreq(WORD Hz)
{
Hz = 1193180 / Hz; // clocked at 1.19MHz
outp(0x43, 0xB6); // timer 2, square wave
outp(0x42, Hz);
outp(0x42, Hz >> 8);
}

void Sound(WORD Frequency, WORD Duration)
{
if( Win32Platform == VER_PLATFORM_WIN32_WINDOWS )
{
outp(0x61, inp(0x61) | 0x03); // start speaker going
setfreq(Frequency);
::Sleep(Duration);
outp(0x61, inp(0x61) & ~0x03); // stop that racket!
}
else if( Win32Platform == VER_PLATFORM_WIN32_NT )
::Beep(Frequency, Duration);
}


Gambit


Jonathan Benedicto

unread,
Mar 11, 2005, 5:14:36 PM3/11/05
to
What about a component off torry.net ?

http://www.torry.net/pages.php?id=183

--
Jonathan

"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message

news:423215d9$1...@newsgroups.borland.com...

Tom Jackson

unread,
Mar 11, 2005, 5:57:34 PM3/11/05
to
An asm in or out instruction raises EPriviledge exception. I don't want to
use Beep() because it is not powerful enough for what I want to do.

The components/code from Torry's Delphi Pages uses the in and out
instructions too. Apparently under win9x and me the in and out instruction
are not privileged.

At least under win2k it seems I cannot access the speaker!

"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message

news:423215d9$1...@newsgroups.borland.com...

Tom Jackson

unread,
Mar 11, 2005, 5:58:32 PM3/11/05
to
They all seem to use the asm in and out instructions which are privileged
under win2k

"Jonathan Benedicto" <inco...@no.server> wrote in message
news:4232184a$1...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Mar 11, 2005, 6:05:17 PM3/11/05
to

"Tom Jackson" <tj...@comcast.net> wrote in message
news:42322222$1...@newsgroups.borland.com...

> They all seem to use the asm in and out instructions
> which are privileged under win2k

Bleepint and BTBeeper execute the assembly instructions only under Win9x,
and use Beep() under WinNT.


Gambit


Remy Lebeau (TeamB)

unread,
Mar 11, 2005, 6:10:39 PM3/11/05
to

"Tom Jackson" <tj...@comcast.net> wrote in message
news:4232...@newsgroups.borland.com...

> An asm in or out instruction raises EPriviledge exception.

Only on NT-based systems, which is why you need to use Beep() for those
systems instead.

On Win9x, the instructions are not privileged.

> I don't want to use Beep() because it is not powerful enough for what I
want to do.

What EXACTLY are you trying to accomplish? The PC speaker is not very
powerful to begin with.

> The components/code from Torry's Delphi Pages uses the in
> and out instructions too. Apparently under win9x and me the
> in and out instruction are not privileged.
>
> At least under win2k it seems I cannot access the speaker!

Two of the components at Torry can work fine on both 9x and NT systems.


Gambit


Bruce Salzman

unread,
Mar 11, 2005, 6:26:21 PM3/11/05
to

"Tom Jackson" <tj...@comcast.net> wrote in message
news:4232...@newsgroups.borland.com...
> An asm in or out instruction raises EPriviledge exception. I don't
> want to
> use Beep() because it is not powerful enough for what I want to do.
>

Can you find an old computer running DOS? Seriously, the PC speaker
has always been a problem for Windows. In order to produce sounds, you
need the timer chip, which is being used for other things. That's why
the WinAPI doesn't expose much of an interface for it (Beep() and
MessageBeep(0xFFFF), and those grundgingly). What you want to do was
commonplace 10 or 20 years ago, but the PC has moved on.

Regards,
Bruce


Tom Jackson

unread,
Mar 11, 2005, 10:35:00 PM3/11/05
to
Its simplicity was what I wanted. I hoped to demonstrate some simple DSP and
sound theory in the simplest of environments before moving on to the more
complex.

Back in the pre-dos days, I managed to get the color computer (a z-80 based
machine with a cassette tape drive) to play some pretty complex music. Oh
well, I will just have to re-think it.

Thanks for your efforts!

Tom
" Bruce Salzman" <br...@nospam.org> wrote in message
news:4232291c$1...@newsgroups.borland.com...

0 new messages