MOS Technology format

Nowadays the MOS Technology format is rarely used. Only people who are into retro computing might use it to get programs across to their KIM-1 or SYM-1 computer, or emulator. Although both the KIM-1 and the SYM-1 don't exactly follow the official syntax of this file format when it comes to the end of file record.

Records

All data lines are called records and each record contains the following 5 fields:

;ccaaaaddssss

;

Every record starts with this identifier.

cc

The byte-count. A 2 digit value (1 byte), counting the actual number of data bytes in the record.

aaaa

The address field. A 4 digit (2 byte) number representing the first address to be used by this record.

dd

The actual data of this record. There can be 1 to 255 data bytes per record (see cc)

ssss

Total Checksum. Covers byte count, address and all the data bytes of this record.

Record Begin

Every record begins with a semicolon ;. Records contain only ASCII characters! No spaces or tabs are allowed in a record. In fact, apart from the 1st semicolon and the End Of Line characters, no other characters than 0..9 and A..F are allowed in a record. Interpretation of a record should ideally be case insensitive, so it should not matter if you use a..f or A..F. However older computers, with very limited ROM memory tended to accept capital characters only.

Byte Count

The byte count cc counts the actual number of data bytes in the current record. Usually records have 24 data bytes, but any number between 1 and 255 is possible. The receiving computer might limit the maximum number of data bytes to any arbitrary number.

A value of $00 for cc indicates the end of the file. Officially the end of file record contains, apart from the 0 byte count value, the number of records in this file (16-bits, big endian), sent twice in a row. Example ;0001230123
The KIM-1 however expects a normal checksum over this record as the second value, like any other record of the file. This is not a problem for files with less than 256 records, because these values would be the same. Things might go wrong when there are more than 255 records though. Officially a file with 291 records would have ;0001230123 as end of file record. The KIM1 however expects ;0001230024 as end of file record. It will complain with an error, but the file would have been read correctly from tape anyway.
The SYM-1 monitor is more forgiving. The tape read routine simply stops parsing as soon as it sees the 0 byte counter.

It is not recommended to send too many data bytes in a record for that may increase the transmission time in case of errors. Also avoid sending only a few data bytes per record because the address overhead will be too heavy in comparison to the payload.

Address Field

This is the address where the first data byte of the record should be stored. After storing that data byte the address is incremented by 1 to point to the address for the next data byte of the record. And so on, until all data bytes are stored.
The address is represented by a 4 digit hex number (2 bytes), with the MSD first.
The order of addresses in the records of a file is not important. The file may also contain address gaps, to skip a portion of unused memory.

Data Field

The payload of the record is formed by the Data field. The number of data bytes expected is given by the Byte Count field. The last record of the file may not contain a Data field.

Checksum

The Checksum is the 16-bit sum of the byte count, both address bytes and all data bytes. Thus all bytes on the data line are added together and the end result is truncated to 16-bits.

Example

;10B000576F77212044696420796F75207265610624
;10B0106C6C7920676F207468726F756768206106B9
;10B0206C6C20746861742074726F75626C652006C6
;0DB030746F207265616420746869733F05A3
;0000040004

In the example above you can see a piece of code in MOS Technology format. The first 3 lines have 16 bytes of data each, which can be seen by the byte count. The 4th line has only 13 bytes, because the program is at its end there.