diff --git a/examples/animate.pas b/examples/animate.pas index 1ed379e..6bf834c 100644 --- a/examples/animate.pas +++ b/examples/animate.pas @@ -35,8 +35,7 @@ var pic:PictData; procedure WaitVSync; external; function readAudioFile(fname:string):SndBufPtr; -var i,size:integer; - c:char; +var size:integer; buf:SndBufPtr; f:file; begin @@ -44,13 +43,8 @@ begin size := FileSize(f); new(buf, size); - buf^ := ''; - write('Reading ', size, ' bytes from ', fname); - for i := 1 to size do - begin - read(f,c); - AppendChar(buf^,c); - end; + ReadSample(f, buf); + writeln; close(f); readAudioFile := buf; diff --git a/lib/pcmaudio.inc b/lib/pcmaudio.inc index dc1dbba..bda29a9 100644 --- a/lib/pcmaudio.inc +++ b/lib/pcmaudio.inc @@ -1,6 +1,7 @@ type SndBuf = string[32768]; type SndBufPtr = ^SndBuf; +procedure ReadSample(aFile:file;buf:SndBufPtr); external; procedure PlaySample(buf:SndBufPtr;sampleRate:integer); external; procedure SampleQStart(buf:SndBufPtr;loop:boolean;sampleRate:integer); external; procedure SampleQStop; external; diff --git a/lib/pcmaudio.s b/lib/pcmaudio.s index ebe812a..1c3fecf 100644 --- a/lib/pcmaudio.s +++ b/lib/pcmaudio.s @@ -302,3 +302,22 @@ SMPLQ_I_XT2: DROP LOADREG IR ; jump via interrupt return register JUMP + +; args: file ptr, ptr to SndBuf (i.e. a String) +READSAMPLE: + ; buf ptr + 0: addr of cur size header field + ; buf ptr + 4: addr of max size header field + ; buf ptr + 8: start of raw data + + ; copy max size to current size header field of SndBuf + INC.S1.X2Y 4 ; [ file ptr, buf ptr, buf ptr+4 ] + LOADI ; [ file ptr, buf ptr, max size ] + STOREI 8 ; [ file ptr, buf ptr+8 ] + ; put max size back on ToS + DUP ; [ file ptr, buf ptr+8, buf ptr+8] + DEC 4 ; [ file ptr, buf ptr+8, buf ptr+4] + LOADI ; [ file ptr, buf ptr+8, max size ] + + LOADCP READFS + CALL + RET