BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Port I/O

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Tom Jackson
Guest





PostPosted: Fri Mar 11, 2005 5:16 pm    Post subject: Port I/O Reply with quote



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?



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 11, 2005 5:57 pm    Post subject: Re: Port I/O Reply with quote




"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote


Quote:
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.

Quote:
I just need to read and write to port 61h.

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

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

Correct.


Gambit



Back to top
Tom Jackson
Guest





PostPosted: Fri Mar 11, 2005 9:34 pm    Post subject: Re: Port I/O Reply with quote



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.spam (AT) no (DOT) spam.com> wrote

Quote:

"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote in message
news:4231d1ea$1 (AT) newsgroups (DOT) 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





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 11, 2005 10:04 pm    Post subject: Re: Port I/O Reply with quote


"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote


Quote:
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 >> Cool;
}

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



Back to top
Jonathan Benedicto
Guest





PostPosted: Fri Mar 11, 2005 10:14 pm    Post subject: Re: Port I/O Reply with quote

What about a component off torry.net ?

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

--
Jonathan

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

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:



Back to top
Tom Jackson
Guest





PostPosted: Fri Mar 11, 2005 10:57 pm    Post subject: Re: Port I/O Reply with quote

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.spam (AT) no (DOT) spam.com> wrote

Quote:

"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote in message
news:42320e6a (AT) newsgroups (DOT) 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 >> Cool;
}

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





Back to top
Tom Jackson
Guest





PostPosted: Fri Mar 11, 2005 10:58 pm    Post subject: Re: Port I/O Reply with quote

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

"Jonathan Benedicto" <incorrect (AT) no (DOT) server> wrote

Quote:
What about a component off torry.net ?

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

--
Jonathan

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:423215d9$1 (AT) newsgroups (DOT) borland.com...

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:





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 11, 2005 11:05 pm    Post subject: Re: Port I/O Reply with quote


"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote


Quote:
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



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 11, 2005 11:10 pm    Post subject: Re: Port I/O Reply with quote


"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote


Quote:
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.

Quote:
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.

Quote:
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



Back to top
Bruce Salzman
Guest





PostPosted: Fri Mar 11, 2005 11:26 pm    Post subject: Re: Port I/O Reply with quote


"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote

Quote:
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



Back to top
Tom Jackson
Guest





PostPosted: Sat Mar 12, 2005 3:35 am    Post subject: Re: Port I/O Reply with quote

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" <bruce (AT) nospam (DOT) org> wrote

Quote:

"Tom Jackson" <tjax (AT) comcast (DOT) net> wrote in message
news:423221e8 (AT) newsgroups (DOT) 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





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.