drive64

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCannotDetectByteswap indicates that a byteswap autodetection has failed
	ErrCannotDetectByteswap = errors.New("cannot detect byteswap format")
	// ErrInvalidBufferForByteswap indicates the the buffer has a length that is invalid for byteswapping
	ErrInvalidBufferForByteswap = errors.New("invalid buffer size for byteswapping")
)
View Source
var (
	ErrNoDevices       = errors.New("no 64drive devices found")
	ErrMultipleDevices = errors.New("multiple 64drive devices found")
	ErrFrozen          = errors.New("64drive seems frozen, please reset it")
	ErrUnsupported     = errors.New("operation is not supported on this 64drive revision")
	ErrInvalidFifoHead = errors.New("invalid FIFO header")
	ErrUnknownDevice   = errors.New("found compatible USB device which cannot be accessed")
)

Functions

This section is empty.

Types

type Bank

type Bank uint8

Bank represents a Nintendo 64 memory bank

const (
	BankCARTROM Bank = 1
	BankSRAM256 Bank = 2
	BankSRAM768 Bank = 3
	BankFLASH   Bank = 4
	BankPOKEMON Bank = 5
	BankEEPROM  Bank = 6
)

Predefined Nintendo64 banks, which can be used as a target for a memory download or upload operation.

func (Bank) String

func (i Bank) String() string

type ByteSwapper

type ByteSwapper uint8

ByteSwapper is a helper for byteswapping memory buffers

const (
	// BSNone is the no-op byteswapper
	BSNone ByteSwapper = 0
	// BSTwo byteswaps groups of 2 consecutive bytes in a buffer
	BSTwo ByteSwapper = 2
	// BSFour byteswaps groups of 4 consecutive bytes in a buffer
	BSFour ByteSwapper = 4
)

func ByteSwapDetect

func ByteSwapDetect(romHeader []byte) (ByteSwapper, error)

ByteSwapDetect detects the correct byteswapping format from a Nintendo 64 ROM header, by peeking at the magic number in the first 4 bytes. If the magic number is not found, ErrCannotDetectByteswap is returned.

func (ByteSwapper) ByteSwap

func (bs ByteSwapper) ByteSwap(buf []byte) error

ByteSwap byteswaps a memory buffer. The memory size must have a length multiple of two or four respectively for BSTwo and BSFour. In case the length is invalid ErrInvalidBufferForByteswap is returned.

func (ByteSwapper) NewReader

func (bs ByteSwapper) NewReader(r io.Reader) io.Reader

func (ByteSwapper) NewWriter

func (bs ByteSwapper) NewWriter(w io.Writer) io.Writer

type CIC

type CIC uint8

CIC is the Nintendo 64 protection chip. This type represents on the several versions that were produced.

const (
	CIC6101 CIC = 0
	CIC6102 CIC = 1
	CIC7101 CIC = 2
	CIC7102 CIC = 3
	CICX103 CIC = 4
	CICX105 CIC = 5
	CICX106 CIC = 6
	CIC5101 CIC = 7
)

Predefined Nintendo 64 CIC types, which 64drive can emulate.

func NewCICFromHeader

func NewCICFromHeader(header []uint8) (CIC, error)

NewCICFromHeader detects a CIC variant from a ROM header

func NewCICFromString

func NewCICFromString(name string) (CIC, error)

NewCICFromString parses a string representing the CIC name (eg. "6103") and returns the corresponding CIC value, or an error if the string doesn't match any known CIC variant.

func (CIC) String

func (i CIC) String() string

type Cmd

type Cmd byte

Cmd is the type of a 64drive command send through USB

const (
	// CmdLoadFromPc loads a bank of data from PC
	CmdLoadFromPc Cmd = 0x20
	// CmdDumpToPc reads the contents of a bank to the PC
	CmdDumpToPc Cmd = 0x30
	// CmdSetCicType sets the CIC emulation
	CmdSetCicType Cmd = 0x72
	// CmdSetSaveType sets the save emulation
	CmdSetSaveType Cmd = 0x70
	// CmdVersionRequest requests the hardware and firmware version
	CmdVersionRequest Cmd = 0x80
	// CmdUpgradeStart starts a firmware upgrade
	CmdUpgradeStart Cmd = 0x84
	// CmdUpgradeReport returns information on the ongoing firmware upgrade
	CmdUpgradeReport Cmd = 0x85
)

func (Cmd) String

func (i Cmd) String() string

type Device

type Device struct {
	// contains filtered or unexported fields
}

func NewDeviceBySerial

func NewDeviceBySerial(serial string) (*Device, error)

NewDeviceBySerial opens a specified 64drive, identified by its serial number. If no device is found, ErrNoDevices is returned.

func NewDeviceSingle

func NewDeviceSingle() (*Device, error)

NewDeviceSingle opens a connected 64drive device, that must be the only one connected to this PC. If multiple devices are found, it returns ErrMultipleDevices. If no devices are found, it returns ErrNoDevices.

func (*Device) Close

func (d *Device) Close() error

Close closes an open 64drive device

func (*Device) CmdDownload

func (d *Device) CmdDownload(ctx context.Context, w io.Writer, n int64, bank Bank, offset uint32) error

func (*Device) CmdFifoRead

func (d *Device) CmdFifoRead(ctx context.Context) (typ uint8, data []byte, err error)

func (*Device) CmdSetCicType

func (d *Device) CmdSetCicType(cic CIC) error

CmdSetCicType configures the 64drive CIC emulation to the specified CIC version. CIC emulation is only available on 64drive HW2/RevB. The function will return ErrUnsupported when executed on HW1/RevA device.

func (*Device) CmdSetSaveType

func (d *Device) CmdSetSaveType(st SaveType) error

func (*Device) CmdUpgradeReport

func (d *Device) CmdUpgradeReport() (UpgradeStatus, error)

CmdUpgradeReport reports the status of an ongoing firmware update

func (*Device) CmdUpgradeStart

func (d *Device) CmdUpgradeStart() error

CmdUpgradeStart triggers a firmware upgrade. The firmware must have been already loaded in BankCARTROM at offset 0. The upgrade happens in background; use CmdUpgradeReport to get a report on the status of the upgrade. NOTE: removing power during an upgrade might brick the 64drive unit.

func (*Device) CmdUpload

func (d *Device) CmdUpload(ctx context.Context, r io.Reader, n int64, bank Bank, offset uint32) error

func (*Device) CmdVersionRequest

func (d *Device) CmdVersionRequest() (hwver Variant, fwver Version, magic [4]byte, err error)

CmdVersionRequest gets the 64drive hardware and firmware version, and a magic ID that identifies the device (it is used during firmware upgrades to make sure that the firmware being uploaded is designed for this device). The result of this call is internally cached, so that it doesn't require a USB communication after the first time it is invoked.

func (*Device) Description

func (d *Device) Description() DeviceDesc

Description returns a DeviceDesc that describes the current device

func (*Device) SendCmd

func (d *Device) SendCmd(cmd Cmd, args []uint32, in []byte, out []byte) error

SendCmd sends a raw command to 64drive. This is a low-level method, most clients should use one of the Cmd* methods.

type DeviceDesc

type DeviceDesc struct {
	Manufacturer string // USB Manufacturer string (should always be "Retroactive")
	Description  string // USB Description string (usually "64drive USB device" or "64drive USB device A")
	Serial       string // Unique serial number of the device
	VendorID     int    // USB vendor ID
	ProductID    int    // USB product ID
}

DeviceDesc describes a 64drive device found attached to the system.

func Enumerate

func Enumerate() ([]DeviceDesc, bool)

Enumerate returns a list of all 64drive devices found attached to this system. It also returns a boolean flag indicating whether unknown compatible devices were found; on Windows, this might indicate a device which has no libusb-compatible drivers.

func (*DeviceDesc) Open

func (d *DeviceDesc) Open() (*Device, error)

Open this 64drive device

type RPK

type RPK struct {
	Metadata struct {
		Format      uint32
		Copyright   string `struct:"[64]byte"`
		Date        string `struct:"[32]byte"`
		File        string `struct:"[64]byte"`
		Type        RPKAssetType
		TypeText    string `struct:"[32]byte"`
		Product     string `struct:"[16]byte"`
		ProductText string `struct:"[64]byte"`
		Device      string `struct:"[32]byte"`
		Magic       string `struct:"[16]byte"`
		Variant     string `struct:"[8]byte"`

		ContentVersion        uint16
		ContentVersionSpecial uint8
		ContentVersionText    string `struct:"[16]byte"`
		Prerequisites         uint32 `struct:"skip=1"`
		PrerequisitesText     string `struct:"[128]byte"`
		ContentNote           string `struct:"[128]byte"`
		ContentChanges        string `struct:"[1024]byte"`
		ContentErrata         string `struct:"[128]byte"`
		ContentExtra          string `struct:"[128]byte"`
	}
	Asset []byte
}

func NewRPKFromReader

func NewRPKFromReader(r io.Reader) (*RPK, error)

func (*RPK) DumpMetadata

func (rpk *RPK) DumpMetadata()

type RPKAssetType

type RPKAssetType uint32

RPKAssetType identifies the type of asset that can be stored within a RPK archive

const (
	// RPKAssetBootloader is a 64drive bootloader
	RPKAssetBootloader RPKAssetType = 1
	// RPKAssetFirmware is a 64drive firmware
	RPKAssetFirmware RPKAssetType = 2
)

type SaveType

type SaveType uint8

Save emulation types supported by 64drive

const (
	SaveNone                   SaveType = 0
	SaveEeprom4Kbit            SaveType = 1
	SaveEeprom16Kbit           SaveType = 2
	SaveSRAM256Kbit            SaveType = 3
	SaveFlashRAM1Mbit          SaveType = 4
	SaveSRAM768Kbit            SaveType = 5
	SaveFlashRAM1Mbit_PokStad2 SaveType = 6
)

func NewSaveTypeFromString

func NewSaveTypeFromString(name string) (SaveType, error)

func (SaveType) String

func (i SaveType) String() string

type UpgradeStatus

type UpgradeStatus uint8

UpgradeStatus represents the current status of the firmware upgrade

const (
	UpgradeReset     UpgradeStatus = 0x0
	UpgradeReady     UpgradeStatus = 0x1
	UpgradeVerifying UpgradeStatus = 0x2
	UpgradeErasing00 UpgradeStatus = 0x3
	UpgradeErasing25 UpgradeStatus = 0x4
	UpgradeErasing50 UpgradeStatus = 0x5
	UpgradeErasing75 UpgradeStatus = 0x6
	UpgradeWriting00 UpgradeStatus = 0x7
	UpgradeWriting25 UpgradeStatus = 0x8
	UpgradeWriting50 UpgradeStatus = 0x9
	UpgradeWriting75 UpgradeStatus = 0xA

	UpgradeSuccess     UpgradeStatus = 0xC
	UpgradeGeneralFail UpgradeStatus = 0xD
	UpgradeBadVariant  UpgradeStatus = 0xE
	UpgradeVerifyFail  UpgradeStatus = 0xF
)

These are the possible upgrade status that can occur during a firwmare upgrade. To read the current upgrade status, use Device.CmdUpgradeReport.

func (UpgradeStatus) IsFinished

func (stat UpgradeStatus) IsFinished() bool

IsFinished returns true if the UpgradeStatus represents the end of the upgrade process.

func (UpgradeStatus) String

func (i UpgradeStatus) String() string

type Variant

type Variant uint16

Variant represent the hardware variant (revision)

const (
	// VarRevA is the HW1, RevA board
	VarRevA Variant = 0x4100
	// VarRevB is the HW2, ReVB board
	VarRevB Variant = 0x4200
)

func (Variant) String

func (v Variant) String() string

type Version

type Version uint16

Version is the FPGA configuration revision number (firmware version)

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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