Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeSJIS ¶
DecodeSJIS decodes a byte slice containing Shift-JIS encoded data into a string.
Parameters: - sjis: The byte slice containing the Shift-JIS encoded data.
Returns: - string: The decoded string.
func EncodeSJIS ¶
EncodeSJIS encodes a string into Shift-JIS encoding and returns the byte slice representation.
Parameters: - s: The string to be encoded.
Returns: - []byte: The byte slice representation of the encoded string.
Types ¶
type MDColor ¶
func NewMDColor ¶
func NewMDColor() *MDColor
NewMDColor creates a new instance of MDColor.
It returns a pointer to the newly created MDColor.
func (*MDColor) FromValue ¶
FromValue sets the R, G, B, and A values of an MDColor instance based on a given uint16 value.
Parameters: - v: The uint16 value to extract the R, G, B, and A values from.
Return type: None.
func (*MDColor) ToRGBA ¶
ToRGBA converts an MDColor object to an RGBA color object.
It shifts the R, G, and B values of the MDColor object by 5 bits to the left and assigns the result to the R, G, and B fields of the RGBA color object. The A value of the MDColor object is assigned directly to the A field of the RGBA color object.
Returns: - An RGBA color object with the converted R, G, B, and A values.
func (*MDColor) ToValue ¶
ToValue converts an MDColor object to a uint16 value.
It combines the R, G, and B values of the MDColor object into a single uint16 value by shifting the R value by 1 bit to the left, the G value by 5 bits to the left, and the B value by 9 bits to the left. The A value is not included in the resulting uint16 value.
Returns: - A uint16 value representing the R, G, and B values of the MDColor object.
type MDCompressor ¶
func NewMDCompressor ¶
func NewMDCompressor(algorithm string, rom generic.ROM) MDCompressor
NewMDCompressor creates a new instance of MDCompressor based on the given algorithm and ROM.
Parameters: - algorithm: a string representing the algorithm to use for compression. - rom: a generic.ROM object representing the ROM data.
Returns: - MDCompressor: a pointer to the newly created MDCompressor object, or nil if the algorithm is not recognized.
type MDCompressor_SEGARD ¶
func (*MDCompressor_SEGARD) Marshal ¶
func (segard *MDCompressor_SEGARD) Marshal() []byte
Marshal compresses the ROM data using the SEGARD compression algorithm and returns the compressed data as a byte slice.
It reads the ROM data in chunks of 0x20 bytes and performs the following steps for each chunk: - Counts the occurrences of each byte in the chunk and stores them in the 'stats' map. - Identifies the candidates for compression based on the number of occurrences and stores them in the 'candidates' map. - Calculates the masks for each candidate byte and stores them in the 'masks' map. - Determines the order of occurrence for the candidate bytes and stores it in the 'ocurrenceOrder' byte slice. - Constructs a compression chain by appending the number of candidates, followed by the candidate bytes and their corresponding masks. - Applies the non-repeating mask to the chunk based on the 'nonrepeat' value. - Writes the compression chain to the output buffer.
After processing all the chunks, it appends two 0xFF bytes to the output buffer to ensure even length. Finally, it returns the compressed data as a byte slice.
Returns: - []byte: the compressed data as a byte slice.
func (*MDCompressor_SEGARD) Unmarshal ¶
func (segard *MDCompressor_SEGARD) Unmarshal() []byte
Unmarshal decodes the SEGARD compression format from the ROM and returns the decompressed data.
It reads the ROM byte by byte, decoding the compressed data. The format consists of a series of chunks, each chunk containing a variable number of repeated bytes. The chunks are terminated by a FF byte. Each chunk starts with a byte indicating the number of repeated bytes in the chunk. After that, for each repeated byte, there is a byte indicating the value of the repeated byte, followed by a 32-bit mask indicating which bits of the repeated byte are set. The mask is used to determine which bits of the repeated byte are set in each occurrence of the byte. The mask is constructed by shifting the bits of the repeated byte to the left and setting the bits according to the mask. If the mask is not all ones, there are additional bytes in the chunk that are not repeated. These bytes are read from the ROM and stored in the chunk. The chunks are concatenated into the decompressed data.
Returns: - []byte: the decompressed data.
type MDHeader ¶
type MDHeader struct { Type string Copyright string DomesticTitle string InternationalTitle string SerialNumber string Checksum uint16 Devices string ROMStartAddress uint32 ROMEndAddress uint32 RAMStartAddress uint32 RAMEndAddress uint32 SRAMType [4]byte SRAMStartAddress uint32 SRAMEndAddress uint32 Modem string Reserved1 [40]byte Region string Reserved2 [13]byte }
func (*MDHeader) Marshal ¶
Marshal serializes the MDHeader struct into a byte slice.
It writes the values of the MDHeader struct fields into the byte slice using the BigEndian byte order. The byte slice contains the following data in the following order: - Type (10 bytes) - Copyright (20 bytes) - DomesticTitle (30 bytes) - InternationalTitle (40 bytes) - SerialNumber (14 bytes) - Checksum (2 bytes) - Devices (20 bytes) - ROMStartAddress (4 bytes) - ROMEndAddress (4 bytes) - RAMStartAddress (4 bytes) - RAMEndAddress (4 bytes) - SRAMType (4 bytes) - SRAMStartAddress (4 bytes) - SRAMEndAddress (4 bytes) - Modem (32 bytes) - Reserved1 (40 bytes) - Region (3 bytes) - Reserved2 (13 bytes)
Returns: - []byte: The serialized byte slice.
func (*MDHeader) Unmarshal ¶
Unmarshal unmarshals the given byte slice into the MDHeader struct.
It extracts the values from the byte slice and assigns them to the corresponding fields of the MDHeader struct. The byte slice is expected to contain the following data in the following order: - Type (10 bytes) - Copyright (20 bytes) - DomesticTitle (30 bytes) - InternationalTitle (40 bytes) - SerialNumber (14 bytes) - Checksum (2 bytes) - Devices (20 bytes) - ROMStartAddress (4 bytes) - ROMEndAddress (4 bytes) - RAMStartAddress (4 bytes) - RAMEndAddress (4 bytes) - SRAMType (4 bytes) - SRAMStartAddress (4 bytes) - SRAMEndAddress (4 bytes) - Modem (32 bytes) - Reserved1 (40 bytes) - Region (3 bytes) - Reserved2 (13 bytes)
Parameters: - data: The byte slice containing the data to be unmarshaled.
Returns: - None
type MDPCM ¶
func (*MDPCM) FromWAV ¶
FromWAV converts WAV data to MDPCM format.
It takes in a byte slice `data` representing the WAV data and returns a byte slice representing the MDPCM data and an error if any occurred.
Parameters: - data: The WAV data to convert.
Returns: - []byte: The MDPCM data. - error: An error if any occurred.
func (*MDPCM) ToWAV ¶
ToWAV converts PCM data to WAV format.
It takes in a byte slice `data` representing the PCM data and returns a byte slice representing the WAV data and an error if any occurred.
Parameters: - data: The PCM data to convert.
Returns: - []byte: The WAV data. - error: An error if any occurred.
type MDPalette ¶
type MDPalette struct {
Colors []MDColor
}
func NewMDPalette ¶
NewMDPalette creates a new MDPalette from the provided byte slice.
The data parameter is a byte slice containing the raw data for the palette. The function reads 16 color values from the data using big-endian byte order, creates a new MDColor for each color, and appends it to the palette's Colors slice. The first color's alpha value is set to 0. The function returns a pointer to the newly created MDPalette.
Parameters: - data: a byte slice containing the raw data for the palette.
Returns: - palette: a pointer to the newly created MDPalette.
type MDROM ¶
func NewMDROM ¶
NewMDROM creates a new MDROM object with the given filename.
Parameters: - filename: the name of the file to be opened.
Returns: - mdrom: a pointer to the newly created MDrom object. - err: an error if the file could not be opened.
func (*MDROM) Init ¶
func (rom *MDROM) Init()
Init initializes the MDROM object by unmarshaling the data in the specified range into the Header field.
Parameters: - None
Returns: - None
func (*MDROM) UpdateChecksum ¶
func (rom *MDROM) UpdateChecksum()
UpdateChecksum updates the checksum of the MDROM by iterating over the ROM data starting from offset 0x200 and summing up the values of each 16-bit word. The updated checksum is then stored in the Header.Checksum field.
No parameters. No return values.
func (*MDROM) UpdateHeader ¶
func (rom *MDROM) UpdateHeader()
UpdateHeader updates the header of the MDROM object by replacing the existing header with a new one.
It does this by extracting the data before and after the header, then replacing the header with the marshaled version of the Header field.
Parameters: - None
Returns: - None
type MDRawHeader ¶
type MDRawHeader struct { Type [16]byte Copyright [16]byte DomesticTitle [48]byte InternationalTitle [48]byte SerialNumber [14]byte Checksum [2]byte Devices [16]byte ROMStartAddress [4]byte ROMEndAddress [4]byte RAMStartAddress [4]byte RAMEndAddress [4]byte SRAMType [4]byte SRAMStartAddress [4]byte SRAMEndAddress [4]byte Modem [12]byte Reserved1 [40]byte Region [3]byte Reserved2 [13]byte }
type MDTiles ¶
func NewMDTiles ¶
NewMDTiles creates a new MDTiles object with the given data, width, and bits per pixel.
Parameters: - data: a byte slice containing the tile data. - width: the width of each tile in pixels. - bpp: the number of bits per pixel.
Returns: - a pointer to the newly created MDTiles object.
func (*MDTiles) FromData ¶
FromData converts the given byte slice data into the format required by the MDTiles struct.
Parameters: - data: a byte slice containing the data to be converted.
Returns: None.
func (*MDTiles) ReadPixel ¶
ReadPixel returns the value of a pixel at the given coordinates (x, y) from the MDTiles object.
Parameters: - x: the x-coordinate of the pixel. - y: the y-coordinate of the pixel.
Returns: - value: the value of the pixel as a byte.