home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sound Sensations!
/
sound_sensations.iso
/
covox
/
port
/
port.c
< prev
Wrap
Text File
|
1990-06-01
|
1KB
|
88 lines
#include <stdlib.h>
#include <conio.h>
typedef unsigned int Boolean;
enum { False, True };
unsigned int ports[4] = { 0x220, 0x240, 0x280, 0x2c0 };
Boolean PortSearch(void);
void WriteRegister(unsigned int, unsigned char, unsigned char);
unsigned char ReadRegister(unsigned int, unsigned char);
main()
{
PortSearch();
}
Boolean PortSearch(void)
{
int i, j;
for(i = 3; i >= 0; i--)
{
printf("Checking port %x\n", ports[i]);
// use the 16 bit tone period registers to write a specific pattern of data
for(j = 0; j <= 5; j++)
{
WriteRegister(ports[i], j, j);
}
for(j = 0; j <= 5; j++)
{
if(ReadRegister(ports[i], j) != j)
{
break;
}
}
if(j == 6)
{
printf("Port found %x\n", ports[i]);
break;
}
else
{
printf("Port %x detection failed\n", ports[i]);
}
}
}
void WriteRegister(port, reg, data)
unsigned int port;
unsigned char reg;
unsigned char data;
{
int i;
// select register
outp(port, reg);
// write and verify register
for(i = 0; i < 10; i++)
{
outp(port + 1, data);
if(inp(port + 1) == data)
{
break;
}
}
}
unsigned char ReadRegister(port, reg)
unsigned int port;
unsigned char reg;
{
outp(port, reg);
return(inp(port + 1));
}