samfile

package module
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: MIT Imports: 6 Imported by: 0

README

samfile

Build Status GoDoc Coverage Status License

samfile is a tool for manipulating individual files inside SAM Coupé floppy disk images.

For reading, writing, creating and converting entire SAM disk images (and other disk formats), see the excellent samdisk utility.

$ samfile --help
samfile 2.1.1

Manipulate files in SAM Coupé floppy disk images.

  Usage:
    samfile add -i IMAGE -f FILE -c -l LOAD_ADDRESS [-e EXECUTION_ADDRESS]
    samfile basic-to-text
    samfile cat -i IMAGE -f FILE
    samfile extract -i IMAGE [-t TARGET]
    samfile ls -i IMAGE
    samfile --help
    samfile --version

  Targets:
    add                   Adds a file from the host file system to the SAM Disk
                          image file.
    basic-to-text         Read a SAM Basic encoded file from stdin and output
                          plain text listing to stdout.
    cat                   Output a single file from a SAM Disk image file to
                          stdout.
    extract               Extracts all files from a SAM Disk image file to a
                          local directory.
    ls                    Lists files on SAM Disk image file.

  Options:
    -i IMAGE              The raw floppy disk image (.mgt format / 819200 bytes)
                          On linux a floppy disk image can be created by running
                            dd if=/dev/fd0u800 of=image.mgt conv=noerror,sync
                          If /dev/fd0u800 does not exist it can be created with
                            sudo mknod /dev/fd0u800 b 2 120
    -t TARGET             An existing directory to write all files to. Defaults
                          to current directory.
    -f FILE               A single file inside the disk image.
    -c                    File is a code file.
    -l LOAD_ADDRESS       Load address of code file on the SAM Disk image.
    -e EXECUTION_ADDRESS  Execution address of code file on the SAM Disk image.
    --help                Display this help text.
    --version             Display the release version of samfile.

  Examples:

    Extract SAM Basic file 'SCREENS' from disk image 'fred27.mgt' and write to
    file 'SCREENS.basic' as plain text listing:

    $ samfile cat -i fred27.mgt -f SCREENS | samfile basic-to-text > SCREENS.basic

  SAMFile source code:
    https://github.com/petemoore/samfile

Installing

Download from https://github.com/petemoore/samfile/releases

Building from source

go install github.com/petemoore/samfile/v2/cmd/samfile@v2.1.1

Documentation

Overview

See https://www.worldofsam.org/products/samdos and https://sam.speccy.cz/systech/sam-coupe_tech-man_v3-0.pdf for details of the disk format

Index

Constants

View Source
const (
	FT_ERASED      = FileType(0)
	FT_ZX_SNAPSHOT = FileType(5)
	FT_SAM_BASIC   = FileType(16)
	FT_NUM_ARRAY   = FileType(17)
	FT_STR_ARRAY   = FileType(18)
	FT_CODE        = FileType(19)
	FT_SCREEN      = FileType(20)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskImage

type DiskImage [819200]byte

func Load

func Load(filename string) (*DiskImage, error)

func (*DiskImage) AddCodeFile

func (di *DiskImage) AddCodeFile(name string, data []byte, loadAddress, executionAddress uint32) error

func (*DiskImage) DiskJournal

func (i *DiskImage) DiskJournal() *DiskJournal

func (*DiskImage) File

func (di *DiskImage) File(filename string) (*File, error)

func (*DiskImage) Save

func (di *DiskImage) Save(filename string) error

func (*DiskImage) SectorData

func (i *DiskImage) SectorData(sector *Sector) (*SectorData, error)

func (*DiskImage) WriteFileEntry

func (di *DiskImage) WriteFileEntry(dj *DiskJournal, index int)

func (*DiskImage) WriteSector

func (di *DiskImage) WriteSector(sector *Sector, sd *SectorData)

type DiskJournal

type DiskJournal [80]*FileEntry

func (*DiskJournal) CombinedSectorMap

func (dj *DiskJournal) CombinedSectorMap() *SectorAddressMap

func (*DiskJournal) FreeFileEntries

func (dj *DiskJournal) FreeFileEntries() []int

func (*DiskJournal) Output

func (dj *DiskJournal) Output()

func (*DiskJournal) UsedFileEntries

func (dj *DiskJournal) UsedFileEntries() []int

type File

type File struct {
	Header *FileHeader
	Body   []byte
}

func (*File) Output

func (file *File) Output()

func (*File) Raw

func (file *File) Raw() []byte

type FileEntry

type FileEntry struct {
	Type                   FileType
	Name                   Filename
	Sectors                uint16
	FirstSector            *Sector
	SectorAddressMap       *SectorAddressMap
	FileTypeInfo           [11]byte
	StartAddressPage       uint8
	StartAddressPageOffset uint16
	Pages                  uint8
	LengthMod16K           uint16
	ExecutionAddressDiv16K uint8
	ExecutionAddressMod16K uint16
	SAMBASICStartLine      uint16
	MGTFlags               uint8
	MGTFutureAndPast       [10]byte
	ReservedA              [4]byte
	ReservedB              [11]byte
}

func FileEntryFrom

func FileEntryFrom(data [0x100]byte) *FileEntry

func (*FileEntry) CreateHeader

func (fe *FileEntry) CreateHeader() *FileHeader

func (*FileEntry) ExecutionAddress

func (fe *FileEntry) ExecutionAddress() uint32

func (*FileEntry) GapSize

func (fe *FileEntry) GapSize() uint32

GapSize is the size in bytes of the gap that SAM BASIC leaves between the numeric variables and the string/array variables.

func (*FileEntry) Length

func (fe *FileEntry) Length() uint32

func (*FileEntry) NumericVariablesSize

func (fe *FileEntry) NumericVariablesSize() uint32

NumericVariablesSize is the size in bytes of the numeric variables section that immediately follows the program text.

func (*FileEntry) Output

func (fe *FileEntry) Output() error

func (*FileEntry) ProgramLength

func (fe *FileEntry) ProgramLength() uint32

ProgramLength is the size in bytes of the SAM BASIC program text, excluding any variables.

func (*FileEntry) Raw

func (fe *FileEntry) Raw() [0x100]byte

func (*FileEntry) StartAddress

func (fe *FileEntry) StartAddress() uint32

func (*FileEntry) StringArrayVariablesSize

func (fe *FileEntry) StringArrayVariablesSize() uint32

StringArrayVariablesSize is the size in bytes of the string and array variables section, which occupies the remainder of the file after the gap.

func (*FileEntry) Used

func (fe *FileEntry) Used() bool

type FileHeader

type FileHeader struct {
	Type         FileType
	LengthMod16K uint16
	PageOffset   uint16
	Pages        uint8
	StartPage    uint8
}

func (*FileHeader) Length

func (fileHeader *FileHeader) Length() uint32

func (*FileHeader) Raw

func (fh *FileHeader) Raw() [9]byte

func (*FileHeader) Start

func (fileHeader *FileHeader) Start() uint32

type FilePart

type FilePart struct {
	Data       [510]byte
	NextSector *Sector
}

type FileType

type FileType uint8

func (FileType) String

func (ft FileType) String() string

type Filename

type Filename [10]byte

func (Filename) String

func (filename Filename) String() string

type SAMBasic

type SAMBasic struct {
	Data []byte
}

func NewSAMBasic

func NewSAMBasic(data []byte) *SAMBasic

func (*SAMBasic) Output

func (basic *SAMBasic) Output()

type Sector

type Sector struct {
	// 0-79 or 128-207
	Track uint8
	// 1-10
	Sector uint8
}

func (*Sector) Offset

func (sector *Sector) Offset() int

func (*Sector) SAMMask

func (sector *Sector) SAMMask() (offset uint8, mask uint8)

func (*Sector) String

func (sector *Sector) String() string

type SectorAddressMap

type SectorAddressMap [195]byte

func (*SectorAddressMap) FreeSectors

func (sam *SectorAddressMap) FreeSectors() []*Sector

func (*SectorAddressMap) Merge

func (sam *SectorAddressMap) Merge(s *SectorAddressMap)

func (*SectorAddressMap) String

func (sam *SectorAddressMap) String() string

func (*SectorAddressMap) UsedSectors

func (sam *SectorAddressMap) UsedSectors() []*Sector

type SectorData

type SectorData [512]byte

func (*SectorData) FilePart

func (data *SectorData) FilePart() *FilePart

Directories

Path Synopsis
cmd
samfile command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL