cartridgeloader

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: GPL-3.0, GPL-3.0 Imports: 12 Imported by: 4

Documentation

Overview

Package cartridgeloader is used to specify the data that is to be attached to the emulated VCS.

When the cartridge is ready to be loaded into the emulator, the Load() function should be used. The Load() function handles loading of data from a different sources. Currently on local-file and data over HTTP is supported.

As well as the filename, the Loader type allows the cartridge mapping to be specified, if required.

The simplest instance of the Loader type:

cl := cartridgeloader.Loader{
	Filename: "roms/Pitfall.bin",
}

It is preferred however that the NewLoader() function is used. The NewLoader() function will set the mapping field automatically according to the filename extension.

Instances of Loader should be closed with Close() when it is no longer required.

Streaming

For some cartridge types it is necessary to stream bytes from the file rather than load them all at once. For these types of cartridges the Load() function will leave the file open. Data can be read into a buffer with the Stream() function. The Stream() function allows the data to be read from a particular offset. It is the responsibility of the user of the interface to manage the current offset.

The NumChunks() function can be used to predict the number of Stream() calls required to read all the data.

Currently, only streaming from a file-system is supported. This interface may change in the future to allow for more transparency and more consistency.

Index

Constants

This section is empty.

Variables

View Source
var FileExtensions = [...]string{".BIN", ".ROM", ".A26", ".2k", ".4k", ".F8", ".F6", ".F4", ".2k+", ".4k+", ".F8+", ".F6+", ".F4+", ".FA", ".FE", ".E0", ".E7", ".3F", ".AR", ".DF", "3E", "3E+", "SB", ".DPC", ".DP+", "CDF", ".WAV", ".MP3", ".MVC"}

FileExtensions is the list of file extensions that are recognised by the cartridgeloader package.

Functions

This section is empty.

Types

type Loader

type Loader struct {
	// filename of cartridge to load.
	Filename string

	// empty string or "AUTO" indicates automatic fingerprinting
	Mapping string

	// expected hash of the loaded cartridge. empty string indicates that the
	// hash is unknown and need not be validated. after a load operation the
	// value will be the hash of the loaded data
	//
	// in the case of sound data (IsSoundData is true) then the hash is of the
	// original binary file not he decoded PCM data
	Hash string

	// copy of the loaded data. subsequenct calls to Load() will return a copy
	// of this data
	Data []byte

	// does the Data field consist of sound (PCM) data
	IsSoundData bool

	// callback function when cartridge has been successfully inserted/loaded.
	// not all cartridge formats support this
	//
	// !!TODO: all cartridge formats to support OnLoaded() callback (for completeness)
	OnLoaded func(cart mapper.CartMapper) error
	// contains filtered or unexported fields
}

Loader is used to specify the cartridge to use when Attach()ing to the VCS. it also permits the called to specify the mapping of the cartridge (if necessary. fingerprinting is pretty good).

func NewLoader added in v0.3.1

func NewLoader(filename string, mapping string) Loader

NewLoader is the preferred method of initialisation for the Loader type.

The mapping argument will be used to set the Mapping field, unless the argument is either "AUTO" or the empty string. In which case the file extension is used to set the field.

File extensions should be the same as the ID of the intended mapper, as defined in the cartridge package. The exception is the DPC+ format which requires the file extension "DP+"

File extensions ".BIN" and "A26" will set the Mapping field to "AUTO".

Alphabetic characters in file extensions can be in upper or lower case or a mixture of both.

func (*Loader) Close added in v0.10.1

func (cl *Loader) Close() error

Close ends a cartridge loader session.

func (Loader) HasLoaded

func (cl Loader) HasLoaded() bool

HasLoaded returns true if Load() has been successfully called.

func (*Loader) Load

func (cl *Loader) Load() error

Load the cartridge data and return as a byte array. Loader filenames with a valid schema will use that method to load the data. Currently supported schemes are HTTP and local files.

func (Loader) ShortName

func (cl Loader) ShortName() string

ShortName returns a shortened version of the CartridgeLoader filename.

func (Loader) Stream added in v0.10.1

func (cl Loader) Stream(offset int64, buffer []byte) (int, error)

Stream enough data to fill buffer from position offset.

type Streamer added in v0.10.1

type Streamer interface {
	Stream(offset int64, buffer []byte) (int, error)
}

Streamer exposes only the Stream() function for use.

Jump to

Keyboard shortcuts

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