📄 bob.c
字号:
/*bob.c*/
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include<process.h>
unsigned char selection;
void play_dport(void)
{
static unsigned char a;
/*repeat till a key is pressed*/
while(!kbhit())
{
outportb(0x378, a);
printf("\nDATA port = %X",a);
a++;
sleep(1);
}
getch();
}
void play_cport(void)
{
static unsigned char c;
while(!kbhit())
{
outportb(0x37a, c);
printf("\nCONTROL port = %X",c);
c++;
sleep(1);
}
getch();
}
void dout_cin(void)
{
static unsigned char dout, cin;
outportb(0x37a, 0x04);
while(!kbhit())
{
outportb(0x378, dout);
cin=inportb(0x37a) & 0x0f;
printf("\nDATA port = %X, CONTROL port raw = %X, CONTROL port corrected = %X", dout & 0x0f, cin, 0x0b ^ cin);
dout++;
sleep(1);
}
getch();
}
void dout_sin(void)
{
static unsigned char dout, sin;
while(!kbhit())
{
outportb(0x378, dout);
sin=inportb(0x379) & 0xf8;
printf("\nDATA port = %X, STATUS port = %X, STATUS port corrected = %X", (dout & 0xf8)>>3, sin>>3, 0x80 & (sin>>3));
dout=dout+8;
sleep(1);
}
getch();
}
unsigned char get_selection(void)
{
puts( "\nPlay with DATA Port\t\t\tD\n" );
puts( "DATA port output, CONTROL port input\tC\n" );
puts( "DATA port output, STATUS port input\tS\n" );
puts( "CONTROL port output\t\t\tO\n" );
puts( "Exit \t\t\t\t\tX\n" );
printf( "Enter selection: " );
gets( &selection );
selection |= 0x20;
return selection;
}
main()
{
for(;;){
get_selection();
switch (selection) {
case 'd': printf("\nCase D\n");
play_dport();
break;
case 'c': printf("\nCase C\n");
dout_cin();
break;
case 's': printf("\nCase S\n");
dout_sin();
break;
case 'o': printf("\nCase O\n");
play_cport();
break;
case 'x': printf("\nBye... Play me again!\n");
exit(0);
default: printf("\nError\n");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -