🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Port I/O

#7107
From: Remy Lebeau (TeamB)
Date: Fri, 11 Mar 2005 22:04
55 lines
2355 bytes
"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: <423215d9$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4231d1ea$1@newsgroups.borland.com> <4231dc29$1@newsgroups.borland.com> <42320e6a@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
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4231d1ea$1@newsgroups.borland.com> <4231dc29$1@newsgroups.borland.com> <42320e6a@newsgroups.borland.com>
Subject: Re: Port I/O
Date: Fri, 11 Mar 2005 14:04:41 -0800
Lines: 57
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <423215d9$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1110578649 68.69.17.41 (11 Mar 2005 14:04:09 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail