Almost all files created by the Archimedes and stored on disc, RAM disc or Econet are given a so-called File Type. This is a number between zero and 4095 (000-FFF hex) which is used to identify the file, and to determine the way in which it will be treated when it is loaded or run. Table 1 gives a summary of the major file types. Acorn have allocated types in the range &000-&7FF to the user and &800-&DFF to software houses, reserving &E00-&FFF for their own use. The only files which cannot be allocated a file type are those containing pure machine code which must be loaded at an address other than &8000. This is because the part of the disc catalogue entry normally used for storing the file type is needed to store the load address of the machine code.
FFF | Plain ASCII Text |
FFE | Command (or Exec) file |
FFD | Data |
FFC | Transient Utility |
FFB | Tokenised Basic Program |
FFA | Relocatable Module |
FF9 | Sprite or Saved Screen |
FF8 | Absolute Code (to run at &8000) |
FF7 | BBC Font |
FF6 | Fancy Font |
FEC | WIMP Template files |
FEB | Obey Files |
If you only use the Archimedes to run proprietary software, then you will probably not come into direct contact with file types. But they are at work nonetheless. It is the file type of a file which tells the Desktop which icon to display when representing it - and this is of much greater importance with RISC OS, where the Desktop becomes central to the operation of the whole machine. The file type is also used to determine what will happen when you *RUN or *LOAD a given file. If file types are correctly set, then when you attempt to execute (i.e. *RUN) a data file, the corresponding application program will be loaded and run, and the data file will then be loaded into it.
Additionally, file types can be used when writing your own applications. You can assign file types in the range 0 to &7FF, and then set up the machine to respond to these files in any way that you wish. Moreover, you can put a simple file type test into a program to ensure that it does not load in the wrong kind of file when loading user-selected data files.
Proprietary applications on the Arc (including Basic itself) automatically assign appropriate file types when files are saved. For example, when you save a Basic program, it will always be given the type &FFB. In some circumstances it is necessary for the programmer to set file types himself. For example, when writing an RMA module it must be specifically designated as type &FFA. And if you try to *RMLoad a file into the RMA which is not of this type, you will get the message:
This is not a relocatable module
There are two principal ways to set the type of a file. The simplest is to use the command:
*SetType <filename> xxx
where <filename> is the name of any file, and may include a pathname, and xxx is the file type. For example:
*SetType $.WORDPROC.MyData 6FF
This will set the file in directory $.WORDPROC named MyData to type &6FF.
Alternatively, you can save a file and type it at the same time using the following OS call:
SYS "OS_File",10,<filename>,<filetype>,,<startaddr>,<endaddr>
where <filename> is the name under which the file is to be saved, <filetype> is its type, and <startaddr> and <endaddr> are the start and end addresses of the block in RAM where the data resides. For example:
SYS"OS_File",10,"MyData",&6FF,,&A000,&AFFF
This will save the contents of RAM between &A000 and &AFFF under the file name MyData, and assign a file type of &6FF to it.
Unfortunately there is no easy way of reading file types. You must use a SYS call from Basic (or the SWI equivalent from machine code). To make this easier, I have parcelled up the call into a Basic function called FNreadtype. The accompanying program makes use of this, requesting a filename of the user, and displaying the corresponding file type.
The function is very easily incorporated into other programs. It is called with the file name as a single parameter, and returns its file type as a number between 0 and 4095. Additionally, it sets the variable filelen to the length of the target file. As a further example of its use, the following line will check whether the file MyData is of type &6FF:
IF FNreadtype("MyData")=&6FF THEN PRINT"ok"
On both the Arthur operating system and on RISC OS, the user may determine exactly what happens when a given file is *RUN or *LOADed. This is controlled by the Alias$ system variables. For example, if you enter the following:
*RUN MyFile
*MyFile
*MyApp MyFile
It is also possible to set Load Types in a similar way. The following sequence will cause any *Load action on data files of type &6FF to run the application MyApp, and load them into it.
*Set Alias$@LoadType_6FF MyApp %*0
The user may set load and run types for any file type that he wishes. These may even override those set up when the Archimedes initialises. The best place to perform such settings is in a boot file in the root directory of a disc, or in RISC OS !Boot and !Run Obey files in an application directory.
For further details on file types, the reader is referred to the Programmer's Reference Manual (part 1).
10 REM >WotType
20 REM File Type Reader
40 :
50 PRINT'"File Type Reader"
60 *CAT
70 REPEAT
80 INPUT'"Filename",file$
90 type=FNreadtype(file$)
100 PRINT"File type= ";
110 IF type>0 THEN PRINT~type ELSE PRINT"Machine Code"
120 UNTIL FALSE
130 :
140 DEFFNreadtype(name$)
150 SYS "OS_File",5,name$ TO,,loadaddr,,filelen
160 IF (loadaddr>>>20)=&FFF THEN:=&FFF AND loadaddr>>>8 ELSE:=-1