Home » Archimedes archive » Micro User » MU 1992-08.adf » PD » !CompUtils/Example

!CompUtils/Example

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Micro User » MU 1992-08.adf » PD
Filename: !CompUtils/Example
Read OK:
File size: 0896 bytes
Load address: 0000
Exec address: 0000
File contents
   10REM > !CompUtils.Example
   20
   30in$=":0.$.InFile"
   40out$=":0.$.OutFile"
   50dir$="!CompUtils"
   60
   70REM --- load utility ---
   80SYS "OS_File",5,dir$+".Expand" TO ,,,,l% ;f%
   90DIM code% l%
  100SYS "OS_File",255,dir$+".Expand",code%,0 TO ;f%
  110
  120REM --- set up first buffers ---
  130sourcelen%=1024*10
  140DIM sourcebuffer% sourcelen%
  150DIM tempbuffer% 1
  160
  170REM --- set up pointers ---
  180code%!12=sourcebuffer%
  190code%!16=sourcelen%
  200code%!20=tempbuffer%
  210code%!24=1
  220
  230REM --- reset reason code and set output flags ---
  240code%!32=0
  250code%!36=%00
  260REM ie. VIDC format, no enhancement
  270
  280REM --- open source file and load first buffer ---
  290TIME=0
  300handle%=OPENIN(in$)
  310SYS "OS_GBPB",4,handle%,sourcebuffer%,sourcelen%
  320REM source buffer must be completely full!
  330REM       (unless it is last buffer)
  340
  350finished%=FALSE
  360REPEAT
  370CALL code%
  380reasoncode%=code%!32
  390CASE reasoncode% OF
  400   WHEN 0
  410      REM   all finished
  420      finished%=TRUE
  430   WHEN 1
  440      REM   more source data needed
  450      SYS "OS_GBPB",4,handle%,sourcebuffer%,sourcelen%
  460      REM   no need to alter buffer pointers in header as buffer's
  470      REM   position and length is unchanged
  480   WHEN 2
  490      REM   destination buffer full
  500      REM   Oh dear!!! Something has gone terribly wrong!
  510      PRINT "Destination buffer not long enough"
  520      CLOSE #handle%
  530      END
  540   WHEN 3
  550      REM   initialisation complete
  560      REM   find length of sample and create a proper
  570      REM   destination buffer
  580      destlen%=code%!40
  590      REM   note destlen% includes sample rate byte
  600      REM   but I want raw sample data so...
  610      IF (code%!36 AND 1)<>0 THEN destlen%-=1
  620      DIM destbuff% destlen%
  630      code%!20=destbuff%
  640      code%!24=destlen%
  650OTHERWISE
  660   PRINT"An error has occured - ";reasoncode%
  670   CLOSE #handle%
  680   END
  690ENDCASE
  700UNTIL finished%
  710PRINT"Time taken: ";INT(TIME/50+0.5)/2;" secs"
  720CLOSE#handle%
  730
  740REM --- save destination buffer to disc ---
  750REM offset +28 contains length of data in buffer
  760SYS "OS_File",10,out$,&FFD,,destbuff%,destbuff%+code%!28
  770
  780REM   All done, so end
  790
  800REM   If you want to check the output file load it
  810REM   into an editor as logarithmic data
  820
  830REM   That's all folks!!!
  840END

� > !CompUtils.Example

in$=":0.$.InFile"
(out$=":0.$.OutFile"
2dir$="!CompUtils"
<
F� --- load utility ---
P.ș "OS_File",5,dir$+".Expand" � ,,,,l% ;f%
Z� code% l%
d1ș "OS_File",255,dir$+".Expand",code%,0 � ;f%
n
x"� --- set up first buffers ---
�sourcelen%=1024*10
�� sourcebuffer% sourcelen%
�� tempbuffer% 1
�
�� --- set up pointers ---
�code%!12=sourcebuffer%
�code%!16=sourcelen%
�code%!20=tempbuffer%
�code%!24=1
�
�4� --- reset reason code and set output flags ---
�code%!32=0
�code%!36=%00
%� ie. VIDC format, no enhancement

4� --- open source file and load first buffer ---
"�=0
,handle%=�(in$)
63ș "OS_GBPB",4,handle%,sourcebuffer%,sourcelen%
@,� source buffer must be completely full!
J&�       (unless it is last buffer)
T
^finished%=�
h�
r� code%
|reasoncode%=code%!32
�Ȏ reasoncode% �
�
   � 0
�      �   all finished
�      finished%=�
�
   � 1
�%      �   more source data needed
�9      ș "OS_GBPB",4,handle%,sourcebuffer%,sourcelen%
�D      �   no need to alter buffer pointers in header as buffer's
�.      �   position and length is unchanged
�
   � 2
�%      �   destination buffer full
�;      �   Oh dear!!! Something has gone terribly wrong!
�0      � "Destination buffer not long enough"
      � #handle%
      �

   � 3
&%      �   initialisation complete
07      �   find length of sample and create a proper
:       �   destination buffer
D      destlen%=code%!40
N5      �   note destlen% includes sample rate byte
X.      �   but I want raw sample data so...
b+      � (code%!36 � 1)<>0 � destlen%-=1
l      � destbuff% destlen%
v      code%!20=destbuff%
�      code%!24=destlen%
�
�-   �"An error has occured - ";reasoncode%
�   � #handle%
�   �
��
�� finished%
�)�"Time taken: ";�(�/50+0.5)/2;" secs"
�
�#handle%
�
�-� --- save destination buffer to disc ---
�2� offset +28 contains length of data in buffer
�;ș "OS_File",10,out$,&FFD,,destbuff%,destbuff%+code%!28

�   All done, so end

 4�   If you want to check the output file load it
**�   into an editor as logarithmic data
4
>�   That's all folks!!!
H�
�
00000000  0d 00 0a 1a f4 20 3e 20  21 43 6f 6d 70 55 74 69  |..... > !CompUti|
00000010  6c 73 2e 45 78 61 6d 70  6c 65 0d 00 14 04 0d 00  |ls.Example......|
00000020  1e 15 69 6e 24 3d 22 3a  30 2e 24 2e 49 6e 46 69  |..in$=":0.$.InFi|
00000030  6c 65 22 0d 00 28 17 6f  75 74 24 3d 22 3a 30 2e  |le"..(.out$=":0.|
00000040  24 2e 4f 75 74 46 69 6c  65 22 0d 00 32 15 64 69  |$.OutFile"..2.di|
00000050  72 24 3d 22 21 43 6f 6d  70 55 74 69 6c 73 22 0d  |r$="!CompUtils".|
00000060  00 3c 04 0d 00 46 1a f4  20 2d 2d 2d 20 6c 6f 61  |.<...F.. --- loa|
00000070  64 20 75 74 69 6c 69 74  79 20 2d 2d 2d 0d 00 50  |d utility ---..P|
00000080  2e c8 99 20 22 4f 53 5f  46 69 6c 65 22 2c 35 2c  |... "OS_File",5,|
00000090  64 69 72 24 2b 22 2e 45  78 70 61 6e 64 22 20 b8  |dir$+".Expand" .|
000000a0  20 2c 2c 2c 2c 6c 25 20  3b 66 25 0d 00 5a 0e de  | ,,,,l% ;f%..Z..|
000000b0  20 63 6f 64 65 25 20 6c  25 0d 00 64 31 c8 99 20  | code% l%..d1.. |
000000c0  22 4f 53 5f 46 69 6c 65  22 2c 32 35 35 2c 64 69  |"OS_File",255,di|
000000d0  72 24 2b 22 2e 45 78 70  61 6e 64 22 2c 63 6f 64  |r$+".Expand",cod|
000000e0  65 25 2c 30 20 b8 20 3b  66 25 0d 00 6e 04 0d 00  |e%,0 . ;f%..n...|
000000f0  78 22 f4 20 2d 2d 2d 20  73 65 74 20 75 70 20 66  |x". --- set up f|
00000100  69 72 73 74 20 62 75 66  66 65 72 73 20 2d 2d 2d  |irst buffers ---|
00000110  0d 00 82 16 73 6f 75 72  63 65 6c 65 6e 25 3d 31  |....sourcelen%=1|
00000120  30 32 34 2a 31 30 0d 00  8c 1e de 20 73 6f 75 72  |024*10..... sour|
00000130  63 65 62 75 66 66 65 72  25 20 73 6f 75 72 63 65  |cebuffer% source|
00000140  6c 65 6e 25 0d 00 96 13  de 20 74 65 6d 70 62 75  |len%..... tempbu|
00000150  66 66 65 72 25 20 31 0d  00 a0 04 0d 00 aa 1d f4  |ffer% 1.........|
00000160  20 2d 2d 2d 20 73 65 74  20 75 70 20 70 6f 69 6e  | --- set up poin|
00000170  74 65 72 73 20 2d 2d 2d  0d 00 b4 1a 63 6f 64 65  |ters ---....code|
00000180  25 21 31 32 3d 73 6f 75  72 63 65 62 75 66 66 65  |%!12=sourcebuffe|
00000190  72 25 0d 00 be 17 63 6f  64 65 25 21 31 36 3d 73  |r%....code%!16=s|
000001a0  6f 75 72 63 65 6c 65 6e  25 0d 00 c8 18 63 6f 64  |ourcelen%....cod|
000001b0  65 25 21 32 30 3d 74 65  6d 70 62 75 66 66 65 72  |e%!20=tempbuffer|
000001c0  25 0d 00 d2 0e 63 6f 64  65 25 21 32 34 3d 31 0d  |%....code%!24=1.|
000001d0  00 dc 04 0d 00 e6 34 f4  20 2d 2d 2d 20 72 65 73  |......4. --- res|
000001e0  65 74 20 72 65 61 73 6f  6e 20 63 6f 64 65 20 61  |et reason code a|
000001f0  6e 64 20 73 65 74 20 6f  75 74 70 75 74 20 66 6c  |nd set output fl|
00000200  61 67 73 20 2d 2d 2d 0d  00 f0 0e 63 6f 64 65 25  |ags ---....code%|
00000210  21 33 32 3d 30 0d 00 fa  10 63 6f 64 65 25 21 33  |!32=0....code%!3|
00000220  36 3d 25 30 30 0d 01 04  25 f4 20 69 65 2e 20 56  |6=%00...%. ie. V|
00000230  49 44 43 20 66 6f 72 6d  61 74 2c 20 6e 6f 20 65  |IDC format, no e|
00000240  6e 68 61 6e 63 65 6d 65  6e 74 0d 01 0e 04 0d 01  |nhancement......|
00000250  18 34 f4 20 2d 2d 2d 20  6f 70 65 6e 20 73 6f 75  |.4. --- open sou|
00000260  72 63 65 20 66 69 6c 65  20 61 6e 64 20 6c 6f 61  |rce file and loa|
00000270  64 20 66 69 72 73 74 20  62 75 66 66 65 72 20 2d  |d first buffer -|
00000280  2d 2d 0d 01 22 07 d1 3d  30 0d 01 2c 12 68 61 6e  |--.."..=0..,.han|
00000290  64 6c 65 25 3d 8e 28 69  6e 24 29 0d 01 36 33 c8  |dle%=.(in$)..63.|
000002a0  99 20 22 4f 53 5f 47 42  50 42 22 2c 34 2c 68 61  |. "OS_GBPB",4,ha|
000002b0  6e 64 6c 65 25 2c 73 6f  75 72 63 65 62 75 66 66  |ndle%,sourcebuff|
000002c0  65 72 25 2c 73 6f 75 72  63 65 6c 65 6e 25 0d 01  |er%,sourcelen%..|
000002d0  40 2c f4 20 73 6f 75 72  63 65 20 62 75 66 66 65  |@,. source buffe|
000002e0  72 20 6d 75 73 74 20 62  65 20 63 6f 6d 70 6c 65  |r must be comple|
000002f0  74 65 6c 79 20 66 75 6c  6c 21 0d 01 4a 26 f4 20  |tely full!..J&. |
00000300  20 20 20 20 20 20 28 75  6e 6c 65 73 73 20 69 74  |      (unless it|
00000310  20 69 73 20 6c 61 73 74  20 62 75 66 66 65 72 29  | is last buffer)|
00000320  0d 01 54 04 0d 01 5e 0f  66 69 6e 69 73 68 65 64  |..T...^.finished|
00000330  25 3d a3 0d 01 68 05 f5  0d 01 72 0b d6 20 63 6f  |%=...h....r.. co|
00000340  64 65 25 0d 01 7c 18 72  65 61 73 6f 6e 63 6f 64  |de%..|.reasoncod|
00000350  65 25 3d 63 6f 64 65 25  21 33 32 0d 01 86 14 c8  |e%=code%!32.....|
00000360  8e 20 72 65 61 73 6f 6e  63 6f 64 65 25 20 ca 0d  |. reasoncode% ..|
00000370  01 90 0a 20 20 20 c9 20  30 0d 01 9a 1a 20 20 20  |...   . 0....   |
00000380  20 20 20 f4 20 20 20 61  6c 6c 20 66 69 6e 69 73  |   .   all finis|
00000390  68 65 64 0d 01 a4 15 20  20 20 20 20 20 66 69 6e  |hed....      fin|
000003a0  69 73 68 65 64 25 3d b9  0d 01 ae 0a 20 20 20 c9  |ished%=.....   .|
000003b0  20 31 0d 01 b8 25 20 20  20 20 20 20 f4 20 20 20  | 1...%      .   |
000003c0  6d 6f 72 65 20 73 6f 75  72 63 65 20 64 61 74 61  |more source data|
000003d0  20 6e 65 65 64 65 64 0d  01 c2 39 20 20 20 20 20  | needed...9     |
000003e0  20 c8 99 20 22 4f 53 5f  47 42 50 42 22 2c 34 2c  | .. "OS_GBPB",4,|
000003f0  68 61 6e 64 6c 65 25 2c  73 6f 75 72 63 65 62 75  |handle%,sourcebu|
00000400  66 66 65 72 25 2c 73 6f  75 72 63 65 6c 65 6e 25  |ffer%,sourcelen%|
00000410  0d 01 cc 44 20 20 20 20  20 20 f4 20 20 20 6e 6f  |...D      .   no|
00000420  20 6e 65 65 64 20 74 6f  20 61 6c 74 65 72 20 62  | need to alter b|
00000430  75 66 66 65 72 20 70 6f  69 6e 74 65 72 73 20 69  |uffer pointers i|
00000440  6e 20 68 65 61 64 65 72  20 61 73 20 62 75 66 66  |n header as buff|
00000450  65 72 27 73 0d 01 d6 2e  20 20 20 20 20 20 f4 20  |er's....      . |
00000460  20 20 70 6f 73 69 74 69  6f 6e 20 61 6e 64 20 6c  |  position and l|
00000470  65 6e 67 74 68 20 69 73  20 75 6e 63 68 61 6e 67  |ength is unchang|
00000480  65 64 0d 01 e0 0a 20 20  20 c9 20 32 0d 01 ea 25  |ed....   . 2...%|
00000490  20 20 20 20 20 20 f4 20  20 20 64 65 73 74 69 6e  |      .   destin|
000004a0  61 74 69 6f 6e 20 62 75  66 66 65 72 20 66 75 6c  |ation buffer ful|
000004b0  6c 0d 01 f4 3b 20 20 20  20 20 20 f4 20 20 20 4f  |l...;      .   O|
000004c0  68 20 64 65 61 72 21 21  21 20 53 6f 6d 65 74 68  |h dear!!! Someth|
000004d0  69 6e 67 20 68 61 73 20  67 6f 6e 65 20 74 65 72  |ing has gone ter|
000004e0  72 69 62 6c 79 20 77 72  6f 6e 67 21 0d 01 fe 30  |ribly wrong!...0|
000004f0  20 20 20 20 20 20 f1 20  22 44 65 73 74 69 6e 61  |      . "Destina|
00000500  74 69 6f 6e 20 62 75 66  66 65 72 20 6e 6f 74 20  |tion buffer not |
00000510  6c 6f 6e 67 20 65 6e 6f  75 67 68 22 0d 02 08 14  |long enough"....|
00000520  20 20 20 20 20 20 d9 20  23 68 61 6e 64 6c 65 25  |      . #handle%|
00000530  0d 02 12 0b 20 20 20 20  20 20 e0 0d 02 1c 0a 20  |....      ..... |
00000540  20 20 c9 20 33 0d 02 26  25 20 20 20 20 20 20 f4  |  . 3..&%      .|
00000550  20 20 20 69 6e 69 74 69  61 6c 69 73 61 74 69 6f  |   initialisatio|
00000560  6e 20 63 6f 6d 70 6c 65  74 65 0d 02 30 37 20 20  |n complete..07  |
00000570  20 20 20 20 f4 20 20 20  66 69 6e 64 20 6c 65 6e  |    .   find len|
00000580  67 74 68 20 6f 66 20 73  61 6d 70 6c 65 20 61 6e  |gth of sample an|
00000590  64 20 63 72 65 61 74 65  20 61 20 70 72 6f 70 65  |d create a prope|
000005a0  72 0d 02 3a 20 20 20 20  20 20 20 f4 20 20 20 64  |r..:       .   d|
000005b0  65 73 74 69 6e 61 74 69  6f 6e 20 62 75 66 66 65  |estination buffe|
000005c0  72 0d 02 44 1b 20 20 20  20 20 20 64 65 73 74 6c  |r..D.      destl|
000005d0  65 6e 25 3d 63 6f 64 65  25 21 34 30 0d 02 4e 35  |en%=code%!40..N5|
000005e0  20 20 20 20 20 20 f4 20  20 20 6e 6f 74 65 20 64  |      .   note d|
000005f0  65 73 74 6c 65 6e 25 20  69 6e 63 6c 75 64 65 73  |estlen% includes|
00000600  20 73 61 6d 70 6c 65 20  72 61 74 65 20 62 79 74  | sample rate byt|
00000610  65 0d 02 58 2e 20 20 20  20 20 20 f4 20 20 20 62  |e..X.      .   b|
00000620  75 74 20 49 20 77 61 6e  74 20 72 61 77 20 73 61  |ut I want raw sa|
00000630  6d 70 6c 65 20 64 61 74  61 20 73 6f 2e 2e 2e 0d  |mple data so....|
00000640  02 62 2b 20 20 20 20 20  20 e7 20 28 63 6f 64 65  |.b+      . (code|
00000650  25 21 33 36 20 80 20 31  29 3c 3e 30 20 8c 20 64  |%!36 . 1)<>0 . d|
00000660  65 73 74 6c 65 6e 25 2d  3d 31 0d 02 6c 1e 20 20  |estlen%-=1..l.  |
00000670  20 20 20 20 de 20 64 65  73 74 62 75 66 66 25 20  |    . destbuff% |
00000680  64 65 73 74 6c 65 6e 25  0d 02 76 1c 20 20 20 20  |destlen%..v.    |
00000690  20 20 63 6f 64 65 25 21  32 30 3d 64 65 73 74 62  |  code%!20=destb|
000006a0  75 66 66 25 0d 02 80 1b  20 20 20 20 20 20 63 6f  |uff%....      co|
000006b0  64 65 25 21 32 34 3d 64  65 73 74 6c 65 6e 25 0d  |de%!24=destlen%.|
000006c0  02 8a 05 7f 0d 02 94 2d  20 20 20 f1 22 41 6e 20  |.......-   ."An |
000006d0  65 72 72 6f 72 20 68 61  73 20 6f 63 63 75 72 65  |error has occure|
000006e0  64 20 2d 20 22 3b 72 65  61 73 6f 6e 63 6f 64 65  |d - ";reasoncode|
000006f0  25 0d 02 9e 11 20 20 20  d9 20 23 68 61 6e 64 6c  |%....   . #handl|
00000700  65 25 0d 02 a8 08 20 20  20 e0 0d 02 b2 05 cb 0d  |e%....   .......|
00000710  02 bc 0f fd 20 66 69 6e  69 73 68 65 64 25 0d 02  |.... finished%..|
00000720  c6 29 f1 22 54 69 6d 65  20 74 61 6b 65 6e 3a 20  |.)."Time taken: |
00000730  22 3b a8 28 91 2f 35 30  2b 30 2e 35 29 2f 32 3b  |";.(./50+0.5)/2;|
00000740  22 20 73 65 63 73 22 0d  02 d0 0d d9 23 68 61 6e  |" secs".....#han|
00000750  64 6c 65 25 0d 02 da 04  0d 02 e4 2d f4 20 2d 2d  |dle%.......-. --|
00000760  2d 20 73 61 76 65 20 64  65 73 74 69 6e 61 74 69  |- save destinati|
00000770  6f 6e 20 62 75 66 66 65  72 20 74 6f 20 64 69 73  |on buffer to dis|
00000780  63 20 2d 2d 2d 0d 02 ee  32 f4 20 6f 66 66 73 65  |c ---...2. offse|
00000790  74 20 2b 32 38 20 63 6f  6e 74 61 69 6e 73 20 6c  |t +28 contains l|
000007a0  65 6e 67 74 68 20 6f 66  20 64 61 74 61 20 69 6e  |ength of data in|
000007b0  20 62 75 66 66 65 72 0d  02 f8 3b c8 99 20 22 4f  | buffer...;.. "O|
000007c0  53 5f 46 69 6c 65 22 2c  31 30 2c 6f 75 74 24 2c  |S_File",10,out$,|
000007d0  26 46 46 44 2c 2c 64 65  73 74 62 75 66 66 25 2c  |&FFD,,destbuff%,|
000007e0  64 65 73 74 62 75 66 66  25 2b 63 6f 64 65 25 21  |destbuff%+code%!|
000007f0  32 38 0d 03 02 04 0d 03  0c 18 f4 20 20 20 41 6c  |28.........   Al|
00000800  6c 20 64 6f 6e 65 2c 20  73 6f 20 65 6e 64 0d 03  |l done, so end..|
00000810  16 04 0d 03 20 34 f4 20  20 20 49 66 20 79 6f 75  |.... 4.   If you|
00000820  20 77 61 6e 74 20 74 6f  20 63 68 65 63 6b 20 74  | want to check t|
00000830  68 65 20 6f 75 74 70 75  74 20 66 69 6c 65 20 6c  |he output file l|
00000840  6f 61 64 20 69 74 0d 03  2a 2a f4 20 20 20 69 6e  |oad it..**.   in|
00000850  74 6f 20 61 6e 20 65 64  69 74 6f 72 20 61 73 20  |to an editor as |
00000860  6c 6f 67 61 72 69 74 68  6d 69 63 20 64 61 74 61  |logarithmic data|
00000870  0d 03 34 04 0d 03 3e 1b  f4 20 20 20 54 68 61 74  |..4...>..   That|
00000880  27 73 20 61 6c 6c 20 66  6f 6c 6b 73 21 21 21 0d  |'s all folks!!!.|
00000890  03 48 05 e0 0d ff                                 |.H....|
00000896