🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7109

Re: Port I/O

#7109
From: Tom Jackson
Date: Fri, 11 Mar 2005 22:57
68 lines
2976 bytes
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@no.spam.com> wrote in message
news:423215d9$1@newsgroups.borland.com...
>
> "Tom Jackson" <tjax@comcast.net> wrote in message
> news:42320e6a@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
>
>
Technical Details
Message-ID: <423221e8@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4231d1ea$1@newsgroups.borland.com> <4231dc29$1@newsgroups.borland.com> <42320e6a@newsgroups.borland.com> <423215d9$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,dfd1a77f2aeefe74
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Tom Jackson" <tjax@comcast.net>
From: "Tom Jackson" <tjax@comcast.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4231d1ea$1@newsgroups.borland.com> <4231dc29$1@newsgroups.borland.com> <42320e6a@newsgroups.borland.com> <423215d9$1@newsgroups.borland.com>
Subject: Re: Port I/O
Date: Fri, 11 Mar 2005 17:57:34 -0500
Lines: 70
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 69.240.187.199
Message-ID: <423221e8@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1110581736 69.240.187.199 (11 Mar 2005 14:55:36 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail