home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / speaker / speaker.pas < prev    next >
Pascal/Delphi Source File  |  1995-08-07  |  3KB  |  74 lines

  1. uses crt,dos;
  2. const voclast:Byte=0;           {last value}
  3.       trigger=5;                {sensitivity}
  4.       finished:Boolean=false;   {finished ?}
  5. var   oldint8:Pointer;          {old IRQ 0 handler}
  6.       Voc:Pointer;              {pointer to sample data in memory}
  7.       VocFile:File;             {Voc file}
  8.       timvalue,                 {Value for timer chip}
  9.       vocpos,                   {current offset in Voc file}
  10.       voclen,                   {length of Voc file}
  11.       Hz:Word;                  {Sample frequency}
  12.  
  13. Procedure Play;interrupt;assembler;
  14. {plays back Voc in the interrupt}
  15. asm
  16.   mov dx,61h                    {read contents of control port}
  17.   in al,dx
  18.   mov cl,al                     {and store in cl}
  19.   les di,voc                    {load es:di with pointer to sample data}
  20.   inc vocpos                    {increment position by 1}
  21.   mov ax,vocpos                 {load in ax}
  22.   add di,ax                     {and add to memory offset}
  23.   cmp ax,voclen                 {end of sample reached ?}
  24.   jne @ok                       {yes,}
  25.   mov finished,1                  {then set flag}
  26. @ok:
  27.   mov al,es:[di]                {otherwise get value}
  28.   mov bl,al                     {store in bl}
  29.   sub al,voclast                {obtain difference to last value}
  30.   mov voclast,bl                {and record value as last value}
  31.   cmp al,trigger                {distance greater than trigger/pickup ?}
  32.   jg @set                       {then set speaker to high}
  33.   cmp al,-trigger               {distance less than negative trigger/pickup ?}
  34.   jg @end                       {no, then dann finished}
  35.   mov al,cl                     {old contents of control port}
  36.   and al,not 2                  {clear bit 1}
  37.   out dx,al                     {and write}
  38.   jmp @end                      {finished}
  39. @set:
  40.   mov al,cl                     {old contents of control port}
  41.   or al,2                       {set bit 1}
  42.   out dx,al                     {and write}
  43. @end:
  44.   pushf                         {call old handler}
  45.   call [oldint8]
  46. End;
  47.  
  48. begin
  49.   Assign(VocFile,'sekt.voc');  {open file}
  50.   Reset(VocFile,1);             {reset}
  51.   Voclen:=FileSize(VocFile);    {determine length}
  52.   GetMem(Voc,Voclen);           {allocate corresponding memory}
  53.   BlockRead(VocFile,Voc^,FileSize(VocFile));
  54.                                 {read in Voc file (max. 64kB)}
  55.   Close(VocFile);               {and close}
  56.   Hz:=1000000 div               {get sample frequency from file}
  57.     (256-Byte(Ptr(Seg(Voc^),Ofs(Voc^)+$1f)^));
  58.  
  59.   GetIntVec($8,OldInt8);        {store vector IRQ 0}
  60.   SetIntVec($8,@Play);          {bend/deflect IRQ 0 to handler}
  61.  
  62.    timvalue := 1193180 DIV Hz;  {calculate timer start from sampling frequency}
  63.   Port[$43]:=$36;               {program this to counter 0}
  64.    Port[$40]:=Lo(timvalue);
  65.    Port[$40]:=Hi(timvalue);
  66.  
  67.   Repeat Until KeyPressed or finished;  {wait until end or key pressed}
  68.  
  69.   SetIntVec($8,OldInt8);        {restore vector}
  70.   Port[$43]:=$36;               {reset timer}
  71.    Port[$40]:=0;                {(18.2 Hz)}
  72.    Port[$40]:=0;
  73. End.
  74.