home *** CD-ROM | disk | FTP | other *** search
- {$M 16384,0,231072}
- {Don't need overly large main memory amounts}
- { Hatched via Pascal24 - MM'92 }
- program SB;
- {
- This Program Uses the Sound Blaster & XMS memory to load and play a
- .VOC file. However, it has some problems....
- }
-
- uses SBV,XMS; {Ask on Fido for XMS.PAS source.}
- {
- SBVoice -=- Voice Driver
- XMS -=- XMS memory Driver
- }
-
- CONST
- BUFSIZ = 32768; {Voice driver and XMS block size}
- MTRIAL = 6;
-
- TYPE
- PLHType = ^LHType; {Pointer to Linked list of XMS handles}
- LHType = Record
- Handle : Word;
- Size : Word; {Need this in case EOF or different
- BUFSIZ}
- Next : PLHType;
- END;
- PBufType = ^BufType; {Pointer to Buffer Type}
- BufType = Array [1..BUFSIZ+32] of Byte; {Buffer Type}
-
- Function LoadFile : PLHType;
- {
- This function returns the root pointer to a list of XMS memory handles
- for the file in paramstr(1).
- }
-
- TYPE
- PBufType = ^BufType; {Don't need as large of a buffer for
- this}
- BufType = Array [1..BUFSIZ] of Char;
-
- VAR {Sorry about VAR names}
- PLHRoot : PLHType;
- TPLH1,TPLH2 : PLHType;
- InFile : File;
- BFile : File of Byte;
- FSize : Word;
- Buffer : PBufType;
- NumRead : Word;
- Order : Integer;
-
- BEGIN
- PLHRoot := NIL;
- Assign(InFile,ParamStr(1));
- Reset(InFile,1);
- New(Buffer);FSize := BUFSIZ;Seek(InFile,1);
- Repeat
- blockread(InFile,Buffer^,FSize,NumRead);
- If PLHRoot = NIL Then
- BEGIN
- New(PLHRoot);
- PLHRoot^.Handle := EMBGetMem((NumRead DIV 1024)+1);
- MoveToEMB(Buffer^,PLHRoot^.Handle,NumRead);
- PLHRoot^.Next := NIL;PLHRoot^.Size := NumRead;
- END Else
- BEGIN
- TPLH1 := PLHRoot;
- While TPLH1^.Next <> NIL Do
- TPLH1 := TPLH1^.Next;
- New(TPLH2);
- TPLH1^.Next := TPLH2;
- TPLH2^.Next := NIL;TPLH2^.Size := NumRead;
- TPLH2^.Handle := EMBGetMem((NumRead DIV 1024)+1);
- If XMSError <> 0 Then
- Writeln(XMSErrorString(XMSError));
- MovetoEMB(Buffer^,TPLH2^.Handle,NumRead);
- END;
- Until NumRead <> BUFSIZ;
- LoadFile := PLHRoot;
- Close(InFile);Dispose(Buffer);
- END;
-
- Procedure SetSize(pntr:Pointer;SBSize:LongInt);
- {
- This procedure modifies the array(buffer) pointed to by pntr so the
- voice driver will know how long the buffer is
- }
-
- VAR
- ptr : PBufType;
- BEGIN
- ptr := Pntr;
- Ptr^[28] := SBSize MOD 256; {Low Byte}
- Ptr^[29] := ((SBSize - (Ptr^[28])) DIV 256) MOD 256;{Mid Byte}
- Ptr^[30] := SBSize DIV 65536; {High Byte}
- END;
-
- Procedure PlayFile(Root:PLHType);
- {
- This procedure plays the voice file pointed to by the linked list of
- XMS memory handles
- }
-
- VAR
- TPLH1 : PLHType; {Need two buffers}
- Buffer : Array [0..1] of PBufType;
- Preserved : PBufType;
- Index : Integer; {Which buffer currently in use}
- SoundBlock : Pointer; {Pointer to block to play}
- First : Boolean; {Is this the first block?}
- SBSize : LongInt; {Size of current block}
-
- Procedure Common;
- CONST
- Count : Integer = 0;
- {
- This procedure is common routines for each buffer after the first block
- is played.
- }
- BEGIN
- SBSize := Root^.Size;
- SetSize(Buffer[Index],SBSize-30);
- Inc(Count);Writeln(Count,' ',SBSize,' ',Root^.Handle,'
- ',Index);
- EMBFreeMem(Root^.Handle);
- Dispose(Root);
- Root := TPLH1;
- SoundBlock := Buffer[Index];
- Repeat
- asm
- NOP
- END;
- Until StatusWord = 0;
- Repeat
- asm
- NOP
- END;
- Until StatusWord = 0;
- asm
- NOP
- NOP
-
- END;
- sb_Output(MemW[seg(SoundBlock):ofs(SoundBlock)+2],MemW[seg(SoundBlock):ofs(
- oundBlock)]+26);
- Index := 1 - Index;
- END;
-
- BEGIN
- New(Buffer[0]);New(Buffer[1]);Index := 0; {Smaller .EXE file by using}
- New(Preserved);
- First := True; {create on
- the fly VARS}
-
- Repeat
- If Root <> NIL Then
- If Index = 0 Then
- BEGIN
- TPLH1 := Root^.Next;
- If First Then
- BEGIN
- MoveFromEMB(Root^.Handle,Buffer[0]^,Root^.Size);
- MoveFromEMB(Root^.Handle,Buffer[1]^,32); {Get
- header info}
- MoveFromEMB(Root^.Handle,Preserved^,32)
- END
- Else
- MoveFromEMB(Root^.Handle, {preserve header
- info}
- Ptr(MemW[seg(Buffer[Index]):ofs(Buffer[Index])+2],
- MemW[seg(Buffer[Index]):ofs(Buffer[Index])]+32)^,Root^.Size);
- First := False;
- Common;
- END Else {Index = 1}
- BEGIN
- TPLH1 := Root^.Next;
- MoveFromEMB(Root^.Handle,
- Ptr(MemW[seg(Buffer[Index]):ofs(Buffer[Index])+2],
- MemW[seg(Buffer[Index]):ofs(Buffer[Index])]+32)^,Root^.Size);
- Common;
- END;
- Until Root = NIL;
-
- Dispose(Buffer[0]);Dispose(Buffer[1]);
- END;
-
- {
- Main program. This program has little or no file error checking.
- }
-
- BEGIN
- TRIAL := MTRIAL;
- If SBFound Then
- BEGIN
- If ParamCount>0 Then
- PlayFile(LoadFile)
- Else
- Writeln('Usage: SB [d:\path\]filename.voc');
- END Else
- Writeln('SoundBlaster Init Error. SoundBlaster not Found.');
- END.
-