gdi

package
v0.0.0-...-682bba6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package gdi implements parsing of Sega Dreamcast GDI files. Basic checks are performed pre-marshalling or post-unmarshalling to ensure it is valid.

Index

Examples

Constants

View Source
const (
	// Extension is the conventional file extension used
	Extension = ".gdi"
	// SectorSize is the standard sector size used for tracks
	SectorSize = 2352
	// TrackThreeStart is the starting sector for track three, the
	// beginning of the high density area
	TrackThreeStart = 45000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// Count is the number of tracks in the GDI file
	Count int
	// Tracks contains each track
	Tracks []Track
	// Flags manages any additional formatting tweaks
	Flags Flag
}

File represents a GDI file

func (File) Copy

func (f File) Copy() *File

Copy returns a deep copy of the File object

func (File) IsValid

func (f File) IsValid() bool

IsValid checks if the GDI file is valid or not

Example
file := File{
	Count: 3,
	Tracks: []Track{
		{
			Number:     1,
			Start:      0,
			Type:       TypeData,
			SectorSize: SectorSize,
			Name:       "track01.bin",
			Zero:       0,
		},
		{
			Number:     2,
			Start:      756,
			Type:       TypeAudio,
			SectorSize: SectorSize,
			Name:       "track02.raw",
			Zero:       0,
		},
		{
			Number:     3,
			Start:      TrackThreeStart,
			Type:       TypeData,
			SectorSize: SectorSize,
			Name:       "track03.bin",
			Zero:       0,
		},
	},
	Flags: 0,
}

fmt.Println(file.IsValid())
Output:

true

func (File) MarshalText

func (f File) MarshalText() ([]byte, error)

MarshalText encodes the GDI file into textual form

Example
file := File{
	Count: 3,
	Tracks: []Track{
		{
			Number:     1,
			Start:      0,
			Type:       TypeData,
			SectorSize: SectorSize,
			Name:       "track01.bin",
			Zero:       0,
		},
		{
			Number:     2,
			Start:      756,
			Type:       TypeAudio,
			SectorSize: SectorSize,
			Name:       "track02.raw",
			Zero:       0,
		},
		{
			Number:     3,
			Start:      TrackThreeStart,
			Type:       TypeData,
			SectorSize: SectorSize,
			Name:       "track03.bin",
			Zero:       0,
		},
	},
	Flags: 0,
}

gdi, err := file.MarshalText()
if err != nil {
	panic(err)
}

fmt.Println(string(gdi))
Output:

3
1     0 4 2352 track01.bin 0
2   756 0 2352 track02.raw 0
3 45000 4 2352 track03.bin 0

func (*File) UnmarshalText

func (f *File) UnmarshalText(text []byte) error

UnmarshalText decodes the GDI file from textual form

Example
gdi := `3
1     0 4 2352 track01.bin 0
2   756 0 2352 track02.raw 0
3 45000 4 2352 track03.bin 0
`

file := new(File)
if err := file.UnmarshalText([]byte(gdi)); err != nil {
	panic(err)
}

fmt.Println(file)
Output:

&{3 [{1 0 4 2352 track01.bin 0} {2 756 0 2352 track02.raw 0} {3 45000 4 2352 track03.bin 0}] 0}

type Flag

type Flag int

Flag represents additional formatting tweaks

const (
	// TrimWhitespace disables padding/alignment with additional spaces
	TrimWhitespace Flag = 1 << iota
)

type Track

type Track struct {
	// Number is the track number
	Number int
	// Start refers to the first sector of the track
	Start int
	// Type refers to the type of track, audio or data
	Type Type
	// SectorSize is the sector size used by the track
	SectorSize int
	// Name is the filename of the track relative to the GDI file
	Name string
	// Zero is always set to zero
	Zero int
}

Track represents a single track within a GDI file

func (Track) IsAudioTrack

func (t Track) IsAudioTrack() bool

IsAudioTrack returns true if the track is audio

Example
track := Track{
	Number:     2,
	Start:      756,
	Type:       TypeAudio,
	SectorSize: SectorSize,
	Name:       "track02.raw",
	Zero:       0,
}

fmt.Println(track.IsAudioTrack())
Output:

true

func (Track) IsDataTrack

func (t Track) IsDataTrack() bool

IsDataTrack returns true if the track is data

Example
track := Track{
	Number:     1,
	Start:      0,
	Type:       TypeData,
	SectorSize: SectorSize,
	Name:       "track01.bin",
	Zero:       0,
}

fmt.Println(track.IsDataTrack())
Output:

true

type Type

type Type int

Type represents the type of track

const (
	// TypeAudio is used for audio tracks
	TypeAudio Type = iota

	// TypeData is used for data tracks
	TypeData
)

Jump to

Keyboard shortcuts

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