CPC Guide - Disk Formats and Directory StructureAmstrad Disk Formats There are 3 formats recognised by AMSDOS. Other formats may be defined by patching the Expanded Disk Parameter Block (XDPB). But, the XDPB must be initialised before those disc are used otherwise AMSDOS will not recognise them. The following disk formats are supported: DATA 40 tracks 9 sectors per track (&c1, &c6, &c2, &c7, &c3, &c8, &c4, &c9, &c5) 512 bytes per sector 64 directory entries directory on track 0 sector &c1 SYSTEM/VENDOR 40 tracks 9 sectors per track (&41, &46, &42, &47, &43, &48, &44, &49, &45) 512 bytes per sector 64 directory entries directory on track 2 sector &41 IBM 40 tracks 8 sectors per track (&1, &2, &3, &4, &5, &6, &7, &8) 512 bytes per sector 64 directory entries directory on track 1 sector &1 Directory Structure This directory structure applies to standard AMSDOS format disks. Other disk formats such as RAMDOS, ROMDOS, RODOS differ. The directory stores the information to tell AMSDOS where the file is located on the disk. Directory Entry Structure Each directory entry occupies 32 bytes. Each byte is assigned as follows. Offset Function from start of directory entry 00 User A file can be put into any user from 0..255. However, it is important to note that, AMSDOS only supports users 0..15. (i.e. you can only select users 0..15, by using |USER,x command) If you want to use another user, you can do this by: POKE &A701,x where x is the user number you want. This address may change if expansion roms are connected. You can have two different files with exactly the same names, as long as they are in different users. If a file has a user number of &E5 (229) then it has been marked as a deleted file. It is possible to un-erase/move a file by changing it's user number. A file will not be un-erased successfully if the clusters are used by another file, or some of the directory entries have been deleted. 01...08 Main part of filename (8 characters) A file has the same format as a file in DOS. The filename must consist of valid characters, otherwise AMSDOS will not recognise it and will not be able to load it. Valid characters are: A-Z 0-9 ! " # $ & ' + - @ ^ { } ~ The name must ALWAYS be in upper case. 10...11 Extension part of filename (3 characters) (the extension part must consist of valid characters as listed above) Bytes 10 and 11, also have an added function. Bit 7 of byte 10, is used to indicate if the file is READ ONLY or READ/WRITE. If bit 7 is set to 1, the file is READ ONLY, If bit 7 is set to 0, the file is READ/WRITE. Bit 7 of byte 11, is used to indicate if the file is SYSTEM or DIRECTORY. If bit 7 is set to 1, the file is SYSTEM, If bit 7 is set to 0, the file is DIRECTORY. (If a file is marked as SYSTEM it will not be displayed when the disk is catalogued. If a file is marked as DIRECTORY, it WILL be displayed when the disk is catalogued. So, using this function it is possible to hide files.) 12 16K block number If the file is greater than 16k in size, it uses more directory entries. A directory entry is needed for each 16k of the file. This byte is used to tell AMSDOS the order of the blocks, because the directory entries can be in any position in the directory and may not be in order. Blocks are numbered from 0. 0 is the first block of a file. If the file is less than 16k in size, there will only be one block and this byte will be set to 0. 13,14 Not used. (always 0) There may be a function for these bytes, but I do not know what. These bytes are always set to 0. One utility in Amstrad Action used these extra bytes to allow long filenames. 15 Size of block in 128byte sections This byte gives an approximate size of the block in 128byte chunks. So, if this byte equals &80, or the file is roughly 16384 bytes in length, there is a possibility that another block exists, so AMSDOS must search for the next directory entry to load the next block of the file. 16...31 Ordered list of clusters occupied by block of file This list defines which clusters are occupied by this file block. The first number in the list is the first cluster used by the file block, and the last number in the list is the last cluster used by the file block. If there are less than 16 clusters in the block, then the remaining entries are 0. NOTE A cluster is a group of sectors. (Usually this is 2, but this can be defined in the XDPB it is possible to produce a message on the screen when the disc is catalogued by using control characters. When CAT is used all the directory entries are sorted into alphabetical order before being displayed. When DIR is used, they are displayed in the order they appear in the directory. So if we enter data so that it is in alphabetical order, then the message should appear the same when a CAT and DIR command is done. The control characters used are ACK and NAK to switch text printing on and off (so that we dont need to use locate control characters and so the number of K is not printed. BS which is used to move the text cursor back over the dot so we can put a character there. And using other control characters we can clear the screen and set pen colours. Directories with text can be seen on Voyage '93 Megademo and Logon System "The Demo". How a file is stored Binary files The first cluster of the file contains a 128 byte header. The rest of the cluster contains the data for the file. The remaining clusters hold the data for the file. ASCII Most ASCII files or data files do not have any header. The first sector starts with the data in the file, and the remaining sectors hold the rest of the data. Binary file Header in First Sector AMSDOS will attempt to detect if there is a header for the file by adding together bytes 00..66 and check to see if they match the checksum value. If a data file is stored and the first 68 bytes are zero, but the rest of the file contains data, then AMSDOS will think the file has length of 0, and will mistakenly stop you reading bytes from the file. So if you will have data like this, you must make a header for this and write it at the start of the file. (Write file as data and not binary). Byte Offset 0 User number (0..256) 1..8 Main part of filename (padded with spaces) 9..11 Extension part of filename (padded with spaces) No "." is stored. 12..17 $00 18 File type (as for cassette) 19..20 Data length 21..22 Data start 23 $ff 24..25 Logical length 26..27 Execution address 28..63 **not used** 64..66 Length of file in bytes, excluding this header. 64 contains the lower byte, 65 the middle byte, and 66 the upper byte 67..68 Checksum (bytes 0..66 added together) 69..127 **not used** NOTE: All words are stored low-byte first and then high-byte.