home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / voc / voc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-24  |  2.2 KB  |  117 lines

  1. // DSP.CPP (Visual C++ 1.00) -- Plays sound on DSP in "direct 8 bit DAC mode"
  2. // Needs Soundblaster-compatible card at 0220h
  3. // original code of dsp.cpp is: go midi, sight and sound, library programer stuff
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <conio.h>
  8. #include <dos.h>
  9. #include <process.h>
  10. #include <io.h>
  11. #include <malloc.h>
  12.  
  13. typedef unsigned char BYTE;
  14. typedef unsigned int  WORD;
  15. typedef unsigned long DWORD;
  16.  
  17. char huge *buf;
  18.  
  19. void write(BYTE output)
  20. {
  21.     asm mov dx,0x220;
  22.     asm add dx,0xc;
  23. loop:
  24.     asm in al,dx;
  25.     asm test al,0x80;
  26.     asm jnz loop
  27.  
  28.     asm mov dx,0x220;
  29.     asm add dx,0xc;
  30.     asm mov al,output
  31.     asm out dx,al;
  32. }
  33.  
  34. void rate(DWORD rate)
  35. { DWORD val;
  36.  
  37. //      if(rate<4000) return;
  38.     val=256-1000000/rate;
  39.     write(0x40);
  40.     write((BYTE)val);
  41. }
  42.  
  43.  
  44. void play(int n)
  45. { //play voc routine
  46.  
  47.     while ( inp(0x022C) & 0x80);  // ready to recieve command?
  48.     outp(0x022C, 0x10);          // direct 8 bit DAC mode 0x10
  49.     while ( inp(0x022C) & 0x80);  // ready to recieve data?
  50.      outp(0x022C, n);             // send data
  51.  
  52.     bdos(0x0C, 0, 0);              // throw away the key
  53. }
  54.  
  55.  
  56. void ini()
  57. { int i;
  58.  
  59.    bdos(0x0D, 0, 0);              // SOS (save our source)
  60.    outp(0x0226, 1);               // reset = 1
  61.  
  62.   for (i = 0; i < 3 * 2; i++)  inp(0x61);   // wait 3 us
  63.   outp(0x0226, 0);               // reset = 0
  64.  
  65.   while ( inp(0x022C) & 0x80);    // ready to recieve command?
  66.   outp(0x022C, 0xD1);            // speaker on
  67.  
  68.   for (i = 0; i < 100; i++) {
  69.     if (inp(0x022E) & 0x80) if(inp(0x022A)==0xAA) return;
  70.       else { printf("DSP reset error\n"); exit(1);    }
  71.   }
  72.  
  73.   printf("DSP not found at 0220h\n");
  74.   exit(1);
  75. }
  76.  
  77.  
  78. int main() { FILE *fp;
  79.          char na[60];
  80.          char i;
  81.          unsigned long lent,l;
  82.          int rat=0;
  83.  
  84.  
  85.  
  86.    printf("VOC Files name ? :");   gets(na);
  87.  
  88.    printf("rate:");scanf("%d",&rat);
  89.  
  90.  
  91.  
  92.  
  93.    if((fp=fopen(na,"rb"))==0) exit(0);
  94.  
  95.    lent = filelength(fileno(fp)) - 0x1a;
  96.    if(lent>64000l) lent=64000l;
  97.  
  98.    buf=(char huge * ) malloc(lent)-0x1a;
  99.  
  100.    fseek(fp,0x1a,SEEK_SET);
  101.    fread(buf,1,(unsigned long) lent,fp);
  102.    fclose(fp);
  103.  
  104.    fseek(fp,0x1a,1);
  105.  
  106.  
  107.    ini();
  108.    rate(rat);
  109.  
  110.    for(l=0;l<lent;l++) play(buf[l]);
  111.  
  112.  
  113.  
  114. free(buf);
  115. return 0;
  116. }
  117.