home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / OTSAMPLE.ZIP / playsmp.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  5KB  |  179 lines

  1. Program Play_Rawfile;                   { By Vulture/Outlaw Triad }
  2.  
  3. Uses Crt, Dos;
  4.  
  5. Var F: File;                            { Various variables }
  6.     Temp: Pointer;
  7.     Freq,Data_Length: Word;
  8.     Key: Char;
  9.     Blaster_Reset: Word;                { SB variables }
  10.     Blaster_Read: Word;
  11.     Blaster_Write: Word;
  12.     Blaster_Status: Word;
  13.     Blaster_Data: Word;
  14.  
  15. Function Reset_Blaster(Base: Word): Boolean;
  16. Begin
  17.   Base := Base shl 4;
  18.  
  19.   Blaster_Reset := Base + $206;
  20.   Blaster_Read := Base + $20A;
  21.   Blaster_Write := Base + $20C;
  22.   Blaster_Status := Base + $20C;
  23.   Blaster_Data := Base + $20E;
  24.  
  25.   Port[Blaster_Reset] := 1;
  26.   Delay(5);
  27.   Port[Blaster_Reset] := 0;
  28.   Delay(5);
  29.   If (Port[Blaster_Data] AND 128 = 128) AND
  30.      (Port[Blaster_Read] = $AA) then
  31.      Reset_Blaster := True
  32.   Else
  33.      Reset_Blaster := False;
  34. End;
  35.  
  36. Procedure Write_To_Blaster(Value: Byte); Assembler;
  37. Asm
  38.    mov    dx,Blaster_Status     { Setup port }
  39.  
  40. @NoWrite:
  41.    in     al,dx                 { Read from port }
  42.    and    al,10000000b
  43.    jnz    @NoWrite              { Wait until bit 7 is clear }
  44.  
  45.    mov    dx,Blaster_Write
  46.    mov    al,Value              { Write byte }
  47.    out    dx,al
  48. End;
  49.  
  50. Function Read_From_Blaster: Byte;
  51. Begin
  52.   While (Port[Blaster_Data] AND 128 = 0) Do;
  53.   Read_From_Blaster := Port[Blaster_Read];
  54. End;
  55.  
  56. Procedure Turn_Speaker_On;
  57. Begin
  58.   Write_To_Blaster($D1);
  59. End;
  60.  
  61. Procedure Turn_Speaker_Off;
  62. Begin
  63.   Write_To_Blaster($D3);
  64. End;
  65.  
  66. Procedure Stop_Dma;
  67. Begin
  68.   Write_To_Blaster($D0);
  69. End;
  70.  
  71. Procedure PlaySample(Sound: Pointer; Size: Word; Frequency: Word);
  72. Var Time_constant: Byte;
  73.     Page, Offs: Word;
  74. Begin
  75.   Size := Size + 1;
  76.  
  77.   { Set up the DMA chip }
  78.   Offs := Seg(sound^) shl 4 + Ofs(sound^);
  79.   Page := (Seg(sound^) + Ofs(sound^) shr 4) shr 12;
  80.  
  81.   Asm                             { Program DMA channel 1 for output to SB }
  82.     mov    dx,0ah
  83.     mov    al,05h
  84.     out    dx,al                  { Mask off DMA channel 1 }
  85.  
  86.     mov    dx,0ch
  87.     mov    al,00h
  88.     out    dx,al                  { Clear byte pointer F/F to lower byte }
  89.  
  90.     mov    dx,0bh
  91.     mov    al,49h
  92.     out    dx,al                  { Set transfer mode to DAC }
  93.  
  94.     mov    dx,02h
  95.     mov    ax,Offs
  96.     out    dx,al                  { Write LSB of base adress }
  97.     mov    al,ah
  98.     out    dx,al                  { Write MSB of base adress }
  99.  
  100.     mov    dx,83h
  101.     mov    ax,Page
  102.     out    dx,al                  { Write page number }
  103.  
  104.     mov    dx,03h
  105.     mov    ax,Size
  106.     out    dx,al                  { Write LSB of sample length }
  107.     mov    al,ah
  108.     out    dx,al                  { Write MSB of sample length }
  109.  
  110.     mov    dx,0ah
  111.     mov    al,01h
  112.     out    dx,al                  { Enable DMA channel 1 }
  113.   End;
  114.  
  115.   { Set playback frequency }
  116.   Time_constant := 256 - (1000000 div frequency);
  117.   Write_To_Blaster($40);
  118.   Write_To_Blaster(Time_constant);
  119.  
  120.   { Set playback type to 8-bit }
  121.   Write_To_Blaster($14);
  122.   Write_To_Blaster(Lo(size));
  123.   Write_To_Blaster(Hi(size));
  124. End;
  125.  
  126. Begin
  127.   Writeln('Press 1 - 9 for different frequencies and escape to quit.');
  128.   Writeln('Play the complete sample before resetting the frequency');
  129.   Writeln('(pressing another key) or else your computer will hang!');
  130.  
  131.   If not Reset_Blaster(2) then           { Setup soundblaster }
  132.   Begin
  133.     Writeln('Incorrect base adress!');
  134.     Halt(1);
  135.   End;
  136.  
  137.   Turn_Speaker_On;                       { Guess what? :-) }
  138.  
  139.   Assign(F, 'playsmp.raw');              { Read file into memory }
  140.   Reset(F,1);
  141.   Data_Length := FileSize(F);
  142.   Getmem(Temp, Data_Length);
  143.   Blockread(F, Temp^, Data_length);
  144.   Close(F);
  145.  
  146.   Repeat
  147.     Key := Readkey;
  148.     If (Ord(Key) > 48) AND (Ord(Key) < 58) then  { Allow keys 1 - 9 }
  149.     Begin
  150.       Case Key of                        { Determine frequency }
  151.         '1': Freq := 10000;
  152.         '2': Freq := 11000;
  153.         '3': Freq := 12000;
  154.         '4': Freq := 13000;
  155.         '5': Freq := 14000;
  156.         '6': Freq := 15000;
  157.         '7': Freq := 16000;
  158.         '8': Freq := 17000;
  159.         '9': Freq := 18000;
  160.       End;
  161.     If Key <> #27 then PlaySample(Temp, Data_Length, Freq);
  162.     End;
  163.   Until Key = #27;
  164.  
  165.   ClrScr;
  166.   Freemem(Temp, Data_Length);            { Finish program }
  167.   Turn_Speaker_Off;
  168.   Writeln('▄  ▄▄  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄  ▄▄  ▄');
  169.   Writeln('                    - An Outlaw Triad Production (c) 1996 -');
  170.   Writeln;
  171.   Writeln('                             Code∙∙∙∙∙∙∙∙∙∙Vulture');
  172.   Writeln;
  173.   Writeln('                            -=≡ Outlaw Triad Is ≡=-');
  174.   Writeln;
  175.   Writeln('  Vulture(code) ■ Dazl(artist) ■ Troop(sysop) ■ Xplorer(artist) ■ Inopia(code) ');
  176.   Writeln;
  177.   Writeln('▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄');
  178. End.
  179.