cdgo

package module
v0.0.0-...-663a9a7 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

README

cdgo

Compact Disc plus Graphics (Karoke file) format library for Go (Golang).

Example

The example below will load a file and print the first instruction packet

file, _ := os.Open("path/to/cdg_file.cdg")
cdgFile := cdgo.NewFile(file)

packet, _ := cdgFile.NextPacket()

packet.Print()
cmd
cdg2images: Write each frame of a CDG file
go run cmd/cdg2images/main.go test.cdg
cdg2text: Debugging tool. Will print human readable instructions of a CDG
go run cmd/cdg2text/main.go test.cdg
References:

https://jbum.com/cdg_revealed.html

https://goughlui.com/2019/03/31/tech-flashback-the-cdgraphics-format-cdg/

Documentation

Index

Constants

View Source
const BorderPresetCode = 2

BorderPresetCode is the instruction code for a border preset

View Source
const CDGMask = 0x3F

CDGMask is a mask for each byte instruction in a package

View Source
const LoadColorTableHightCode = 31

LoadColorTableHightCode is the instruction code to load the last 8 colors

View Source
const LoadColorTableLowCode = 30

LoadColorTableLowCode is the instruction code to load the first 8 colors

View Source
const MemoryPresetCode = 1

MemoryPresetCode is the instruction code for a memeory preset

View Source
const PacketSize = 24

PacketSize is the size of each cdg packet

View Source
const ScrollCopyCode = 24

ScrollCopyCode is the instruction code for a scroll copy

View Source
const ScrollPresetCode = 20

ScrollPresetCode is the instruction code for a scroll preset

View Source
const TileBlockCode = 6

TileBlockCode is the instruction code for a tile block

View Source
const TileBlockXorCode = 38

TileBlockXorCode is the instruction code for a tile block

View Source
const TransparentColorCode = 28

TransparentColorCode is the instruction code for a transpaarent color

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorTable

type ColorTable struct {
	Offset int // if it's low 0 high 8
	Colors []color.Color
}

ColorTable represents a memory preset packge information

type File

type File struct {
	Reader io.Reader
	// contains filtered or unexported fields
}

File is a wrapper around byte array to help parsing a CDG file

func NewFile

func NewFile(reader io.Reader) *File

NewFile given a byte array will return a new file

func (File) NextPacket

func (f File) NextPacket() (*Packet, error)

NextPacket will return the next cdg packet or return an error

func (File) ReadInto

func (f File) ReadInto(packet *Packet) error

ReadInto take a packet and replace its contents with the contents of the next packet or returns error

type MemoryPreset

type MemoryPreset struct {
	Color  uint8
	Repeat uint8
}

MemoryPreset represents a memory preset package information

type Packet

type Packet struct {
	Command     byte
	Instruction byte
	ParityQ     []byte
	Data        []byte
	ParityP     []byte
}

Packet is 24 bytes of the cdg file

func (Packet) InstructionCode

func (p Packet) InstructionCode() byte

InstructionCode returns the cdg instruction code

func (Packet) IsCgdCommand

func (p Packet) IsCgdCommand() bool

IsCgdCommand test if the packet is a cdg command

func (Packet) LoadColorTable

func (p Packet) LoadColorTable() *ColorTable

LoadColorTable will load the colors and return the offset

func (Packet) MemoryPreset

func (p Packet) MemoryPreset() *MemoryPreset

MemoryPreset returns the data as a memory preset

func (Packet) Print

func (p Packet) Print()

Print will print out a "pretty" versin of the bytes

func (Packet) ScrollCopy

func (p Packet) ScrollCopy() *Scroll

ScrollCopy will return the scoll data from the packet

func (Packet) ScrollPreset

func (p Packet) ScrollPreset() *Scroll

ScrollPreset will return the scoll data from the packet

func (Packet) TileBlock

func (p Packet) TileBlock(xor bool) *TileBlock

TileBlock will give back a tileblock with indexed colors

type Screen

type Screen struct {
	Pixels   []uint8
	ColorMap []color.Color
	Dirty    bool
}

Screen is a map of pixels to colors for a cdg

func NewScreen

func NewScreen() *Screen

NewScreen Will create a new screen with blank values

func (*Screen) LoadColorTable

func (s *Screen) LoadColorTable(packet *Packet)

LoadColorTable updates the color map with the given packet

func (*Screen) MemoryPreset

func (s *Screen) MemoryPreset(packet *Packet)

MemoryPreset updates the screen with the memory preset package

func (*Screen) TileBlock

func (s *Screen) TileBlock(packet *Packet)

TileBlock will update the screen with the given tile

func (*Screen) TileBlockXOR

func (s *Screen) TileBlockXOR(packet *Packet)

TileBlockXOR will update the screen with the given tile

func (*Screen) UpdateWithPacket

func (s *Screen) UpdateWithPacket(packet *Packet) error

UpdateWithPacket takes a packet the screen should be updated with

func (Screen) WriteJPEG

func (s Screen) WriteJPEG(filename string) error

WriteJPEG writes a jpeg

type Scroll

type Scroll struct {
	Copy    bool
	Color   uint8
	HScroll uint8
	VScroll uint8
	HSCmd   uint8
	HOffset uint8
	VSCmd   uint8
	VOffset uint8
}

Scroll represents data for ScrollPreset and ScrollCopy

type TileBlock

type TileBlock struct {
	Color0 uint8
	Color1 uint8
	Row    uint16
	Column uint16
	XOR    bool
	Pixels []uint8
}

TileBlock is the data of a given tile

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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