Scratchpad

If you are new to Scratchpad, and want full access as a Scratchpad editor, create an account!
If you already have an account, log in and have fun!!

READ MORE

Scratchpad
Register
Advertisement
This article has been moved or is in the process of being moved to the Sinclair FAQ Wiki, under the "MGT filesystem" article. You may find more complete information there.

The filesystem described here is used with the MGT DISCiPLE, +D and SAM Coupé. There are several DOSes which use this filesystem (and extensions thereof), including:

Floppy-based
  • GDOS (DISCiPLE)
  • G+DOS (+D)
  • SAMDOS (SAM Coupé)
  • UniDOS (DISCiPLE / +D)
  • Beta DOS (DISCiPLE / +D)
  • Master DOS (SAM Coupé)
Hard-disk-based
  • B-DOS (SAM Coupé with Atom)
  • HDOS (SAM Coupé with SD IDE)
  • EDOS (SAM Coupé with Entropy IDE interface — abandoned)
  • +DivIDE (ZX Spectrum with DivIDE)
  • Plus D'lux patched GDOS/Uni-DOS (ZX Spectrum with Plus D'lux)

Disks must be formatted to 10 sectors per track, with 512-byte sectors. Either single-sided or double-sided disks may be used, and up to 80 tracks may be used per side. Sectors are numbered 1..10, and tracks are tagged on disk as 0..79 on both sides. However, within sector addresses stored in the filesystem, the most significant bit of the track number selects the side of the disk to use, meaning that tracks on the first side of the disk are numbered 0..79, and tracks on the second side are numbered 128..207.

The disk is divided in two parts. The first is a root directory (consisting of at least the first four tracks on side one). Each directory entry occupies 256 bytes, which gives a minimum of 80 entries (slots) on a disk. Beta DOS and Master DOS allow the root directory to be extended by up to 35 tracks, giving a maximum of 780 slots in Beta DOS. On the SAM, the first sector of track four is used as a boot sector and is (usually) allocated to the first file written to the disk — for this reason, only 78 additional slots can be used in track 4, giving a maximum of 778 slots in Master DOS.

The remaining space on the disk can be allocated to files. In UniDOS, contiguous sectors can also be allocated to subdirectories which use the directory entry system described above. In almost all cases, the last two bytes in any sector used by a file contain the address (track number, followed by sector number) of the next sector in that file (although this does not apply to UniDOS subdirectories). For the last sector in a file, the track number and address at the end of that sector are set to 0.

Files of certain types include a 9-byte header, and a small amount of special file information is also stored in each file's directory entry. The format of this data varies depending on the file's type.

Some extra information may be stored in the very first directory entry. This includes the number of additional tracks reserved for the directory entry (under Beta DOS and Master DOS), a disk label (Master DOS) and a randomly generated disk ID (Master DOS).

While Beta DOS and Master DOS may read GDOS and SAMDOS disks, it is best to avoid writing to Beta DOS and Master DOS disks under GDOS or SAMDOS. For instance, SAMDOS will judge any additional tracks used for directory entries to be free for allocation to files. Also, when overwriting slot 1, the additional tracks field, disk label and random ID will be erased.

The boot sector on the SAM must contain the text "BOOT" at offset $100 — bits 5 and 7 are ignored when checking this string.

Directory entry format[]

Undefined fields should generally be set to $ff.

Offset Description
0 ($00) Bits 0–4: file type (zero for erased — see below for a list of types), bit 6: protected, bit 7: hidden.
1–10 ($01–$0a) Filename, padded with spaces. If the first byte of the filename is zero, this may be taken as an end-of-directory marker. Note that '/', '\' and '^' are allowed, but are used for directories under Master DOS.
11–12 ($0b–$0c) Number of sectors used by the file, in big-endian format (i.e. MSB first).
13–14 ($0d–$0e) Address of the first sector in the file — track number (0–79, 128–207) followed by sector number (1–10). For a Master DOS subdirectory, the address of the sector holding the directory entry is used.
15–209 ($0f–$d1) Sector address map (195 bytes) — a bit is set in this map if the corresponding sector is allocated to the file. The lsb of byte 0 corresponds to track 4, sector 1. The msb of byte 0 corresponds to track 4, sector 8. The lsb of byte 1 corresponds to track 4, sector 9. The msb of byte 1 corresponds to track 5, sector 6.
210–219 ($d2–$db) DISCiPLE / +D file information, or an 10-character Master DOS disk label (in slot 1) — if the first character in the label is '*', this specifies a blank label. SAMDOS sets these bytes to 0 for SAM CODE files.
220–231 ($dc–$e7) SAM file information. For SAM CODE files, SAMDOS sets these to $20, except for the last byte, which is set to $ff.
220–241 ($dc–$f1) Snapshot register dump: IY, IX, DE', BC', HL', AF', DE, BC, HL, junk, I, SP. On the stack: F indicating IFF, R, AF, PC. If I holds 0 or 63, IM 1 is set, otherwise, IM 2 is set. On the DISCiPLE, there is a bug (a missing EX AF,AF' instruction) that causes AF' not to be saved.
232–235 ($e8–$eb) Spare bytes under SAMDOS, set to $ff.
236–244 ($ec–$f4) SAM file start/length information.
245–249 ($f5–$f9) Master DOS timestamp — day, month, year, hour and minute. $ff under SAMDOS.
250 ($fa) ID of Master DOS subdirectory (1–254). $ff under SAMDOS.
251 ($fb) $ff (unused) under SAMDOS.
252–253 ($fc–$fd) Randomly generated Master DOS disks ID (in slot 1). Possibly used under SAMDOS for some purpose.
254 ($fe) ID of Master DOS directory containing this entry (0 for root directory). Possibly used under SAMDOS for some purpose.
255 ($ff) Number of extra tracks for the root directory (0–35), under Beta DOS and Master DOS (in slot 1). Possibly used under SAMDOS for some purpose.

File types[]

  • 0: Erased
  • 1: ZX BASIC
  • 2: ZX numeric array
  • 3: ZX string array
  • 4: ZX code
  • 5: ZX 48K snapshot
  • 6: ZX Microdrive
  • 7: ZX screen
  • 8: Special
  • 9: ZX 128K snapshot
  • 10: Opentype
  • 11: ZX execute
  • 12: UniDOS subdirectory
  • 13: UniDOS create
  • 16: SAM BASIC program
  • 17: SAM numeric array
  • 18: SAM string array
  • 19: SAM code
  • 20: SAM screen
  • 21: Master DOS subdirectory
  • 22: SAM Driver application
  • 23: SAM Driver bootstrap
  • 24: EDOS NOMEN
  • 25: EDOS system
  • 26: EDOS overlay
  • 28: HDOS Hdos
  • 29: HDOS Hdir
  • 30: HDOS Hdisk
  • 31: HDOS Hfree/Htmp

DISCiPLE and +D file information[]

Information for ZX Spectrum files is stored at offsets 210–219 of a file's directory entry. For snapshot files, a register dump is stored at offsets 220–241. Bytes 211–219 are also saved as the file header for some file types.

Offset Description
210 ($d2) For opentype files, the number of 64K blocks in the file.
211 ($d3) Tape header ID for ZX Spectrum files: 0 for BASIC, 1 for numeric arrays, 2 for string arrays and 3 for code.
212–213 ($d4–$d5) File length. For opentype files, the length of the last block.
214–215 ($d6–$d7) Start address.
216–217 ($d8–$d9) Type-specific.
218–219 ($da–$db) Autostart line/address.

SAM Coupé file information[]

Information for SAM Coupé files is stored at offsets 220–231 ($dc–$e7) and 236–244 ($ec–$f4) of a file's directory entry.

External links[]

Documentation[]

Source code[]

Advertisement