File format · .prg
Atari ST .PRG and .TOS Executable File Format
Overview of Atari ST .PRG and .TOS executable formats, structure, corruption causes, and repair options for TOS-based programs.
The Atari ST line of personal computers, introduced in 1985, utilized TOS (The Operating System), a kernel combining GEMDOS, the GEM GUI, and BIOS/XBIOS layers. Software for this platform is distributed as executable files, most commonly identified by the .PRG and .TOS file extensions. These files contain the binary code and data necessary to run applications, games, and system utilities on the Motorola 68000-based hardware. Understanding the internal structure of these executables is essential for diagnosing why software fails to load and for determining if data recovery is possible.
Format Structure and Technical Facts
Atari ST executables follow a specific binary structure designed to be loaded directly into the Motorola 68000's memory space by the GEMDOS kernel.
- Extensions: The primary extensions are
.PRG(Program) and.TOS..PRGfiles are typically GEM applications (utilizing the AES/VDI interface), while.TOSfiles generally denote command-line interface programs that bypass the graphical desktop, similar to.COMor.EXEfiles in MS-DOS. Another extension,.ACC, is used for Desk Accessories, which are small utilities loaded into the system's menu bar. - File Signature (Magic Bytes): The format relies on a fixed 28-byte header at the very beginning of the file. The first field in this header is a 4-byte "branch instruction" (opcode
0x601Aor similar) located at offset 0. This specific sequence serves as the magic number, identifying the file to the OS as a valid executable. - Header Layout: Following the branch instruction, the header contains critical metadata required for loading:
- Text Length: The size of the program's executable code segment.
- Data Length: The size of the initialized data segment.
- BSS Length: The size of the uninitialized data segment (memory to be zeroed at runtime).
- Symbol Table Length: The size of the debugging symbol table (often stripped in release builds).
- Relocation Table Information: Offsets and flags indicating how the code must be adjusted to fit into memory.
- Relocation: Because the Atari ST uses a flat memory model but programs can be loaded at varying memory addresses, the executable includes a relocation table. This table contains a list of offsets pointing to absolute addresses within the code and data segments. During loading, GEMDOS iterates through this table and adds the base load address to the values found at those offsets, ensuring the program runs correctly regardless of where it is placed in RAM.
- MIME Type: There is no standard modern MIME type for these legacy executables, though they are sometimes treated as
application/octet-streamorapplication/x-atari-prgin emulation environments.
Causes of Corruption and Failure
Given the age of the Atari ST platform, most software currently resides on aging floppy disks or has been transferred to modern systems via disk images. Corruption can occur during these storage or transfer processes.
- Bit Rot and Media Decay: The original 3.5-inch floppy disks used by the ST are susceptible to magnetic degradation. If the sectors containing the executable header or the code segments become unreadable, the file will be truncated or contain invalid data.
- Transfer Errors: When moving files from physical media to modern PCs (using serial cables or floppy disk emulators), transmission errors can alter bytes. A single flipped bit in the relocation table or the branch instruction can render the file unlaunchable.
- Invalid Headers: If the file is modified by a non-Atari tool (e.g., a modern text editor or a misconfigured FTP client), the initial 28-byte header may be overwritten or shifted. Without the correct
0x601Abranch instruction, TOS will not recognize the file as executable. - Relocation Damage: If the relocation table is corrupted, the OS may load the program but crash immediately when it attempts to execute an instruction at an incorrect address. This often manifests as a "Bus Error" or "Address Error" bomb alert.
Data Recovery and Repair Potential
Repairing a corrupt Atari ST executable depends heavily on which part of the file is damaged. Because the code consists of compiled Motorola 68000 machine language, manual reconstruction of the logic is impossible without the original source code. However, structural repairs are often feasible.
- Header Reconstruction: If the file signature is missing but the binary data remains intact, a repair tool can often rebuild the 28-byte header by analyzing the file's size and content. This is common when files have been converted to raw binary dumps.
- Relocation Table Repair: If the relocation table is damaged, the file might be converted to a "fixed address" executable if the original load address is known. This involves patching the code to run at a specific memory location, bypassing the need for the table.
- Truncated Files: If the end of the file is missing (e.g., due to a bad floppy disk sector), recovery is limited. If the missing section consists of uninitialized data (BSS) or non-critical resources, the program may run with limited functionality. However, if executable code is missing, the program cannot be recovered.
How Recovery Works
Professional file repair tools for Atari ST executables operate by parsing the binary structure according to the GEMDOS specification.
- Signature Check: The tool reads the first two bytes to verify the presence of the valid branch instruction. If missing, it checks for a raw binary header that might indicate the file was saved without the standard loader.
- Segment Validation: The tool reads the declared lengths of the Text, Data, and BSS segments from the header. It then checks if the physical file size matches the sum of these segments plus the header and relocation table. A mismatch indicates truncation or padding.
- Relocation Table Parsing: The tool locates the relocation table at the end of the file (or where the header specifies). It scans the offsets to ensure they point within the valid range of the loaded segments. Offsets pointing outside the program's memory space are corrected or flagged.
- Patching: If errors are found in non-critical areas, the tool can patch the header or zero-out invalid relocation entries to prevent the OS from crashing during the load process. The goal is to produce a file that TOS can load into memory without throwing an error, allowing the user to see if the program logic remains functional.
FAQ
What is the difference between a .PRG and a .TOS file?
While both are executables, .PRG is the standard extension for programs that may use the GEM graphical interface. .TOS files are typically command-line programs that run directly under GEMDOS without loading the AES (Application Environment Services), similar to a console application.
Can I run these files on a modern PC?
Yes, but you need an Atari ST emulator such as Hatari, Steem, or ARAnyM. These emulators load the .PRG or .TOS files and simulate the TOS operating system environment.
Why does my file show as "Bad Executable" or just crash?
This usually means the file header is corrupt or the relocation table is invalid. The OS attempts to load the file but fails to find the correct entry point or encounters an illegal memory reference during the relocation process.
Are the resources (icons, menus) stored inside the .PRG file?
Often, yes. GEM applications frequently store a resource fork (icons, dialog boxes, menus) embedded within the .PRG file or as a separate .RSC file. If the .PRG is corrupt, it may affect the program's ability to load its interface resources.
If you have an Atari ST executable that fails to load or crashes on startup, we can help. Contact us for a free evaluation of your .PRG or .TOS file, and we will determine if the binary structure can be repaired to restore functionality.
Send us your .prg file for a free evaluation
Our recovery engineers will tell you exactly what can be recovered — at no cost. There is no charge if we cannot recover your data.
Start a free evaluation