1 /* 2 */ 3 4 #ifdef GO32 5 #include <pc.h> 6 #define outb(x,y) outportb(x,y) 7 #define ioperm(x...) /**/ 8 #else 9 #include <asm/io.h> 10 #endif 11 #include <unistd.h> 12 #include <signal.h> 13 #define CNT 16 14 15 int BASE=0x388; 16 17 18 void writereg(int reg, int val) 19 { 20 int i; 21 outb(reg,BASE); 22 for (i=0;i<=5;i++) { inb(BASE); } 23 outb(val,BASE+1); 24 for (i=0;i<=34;i++) { inb(BASE); } 25 } 26 27 void playnote(int freq,int oct) 28 { 29 writereg(0x20,0x7); /* Set modulator's multiple to 0x7*/ 30 writereg(0x40,0xff); 31 writereg(0x60,0xf0); 32 writereg(0x60,0xf0); 33 writereg(0xa0,freq); 34 writereg(0x23,0xf); 35 writereg(0x43,0x0); 36 writereg(0x63,0xf0); 37 writereg(0x83,0xff); 38 writereg(0xb0,0x20+oct); 39 writereg(0xe0,0x0); 40 } 41 42 void handleC(void) 43 { 44 writereg(0xb0,0x0); 45 exit(0); 46 } 47 48 49 int main(int argc, char **argv) 50 { 51 int val[7]; 52 int i,m,g; 53 if (argc==2) { 54 BASE=atoi(argv[1]); 55 } 56 ioperm(BASE,CNT,1); 57 signal(SIGINT,(void *)handleC); 58 59 for (g=0;g<16;g++) { 60 for (i=0;i<255;i++) { 61 playnote(i,g); 62 usleep(100000); 63 } 64 } 65 #if 0 66 while(1) { 67 srand(getpid()+rand()); 68 /* 69 for (i=1;i<40;i++) { playnote(121+((rand()%40)),(int) (i/3)); usleep(rand()%100000); } 70 for (i=40;i>0;i--) { playnote(121+((rand()%40)),(int) (i/3)); usleep(rand()%100000); } 71 playnote(4,16); 72 usleep(rand()%40000); 73 */ 74 playnote(1+(rand()%254),rand()%16); 75 usleep(rand()%2000); 76 } 77 sleep(-1); 78 #endif 79 #if 0 80 while (1) { 81 82 } 83 #endif 84 85 handleC(); 86 return 0; 87 } |