generic

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileBuffer

type FileBuffer struct {
	Buffer bytes.Buffer
	Offset int
}

func NewFileBuffer

func NewFileBuffer() *FileBuffer

NewFileBuffer creates a new instance of the FileBuffer struct.

It returns a pointer to the newly created FileBuffer.

func (*FileBuffer) Bytes

func (fb *FileBuffer) Bytes() []byte

Bytes returns the underlying byte slice of the FileBuffer.

It returns a byte slice that represents the contents of the FileBuffer.

Returns: - []byte: a byte slice containing the contents of the FileBuffer.

func (*FileBuffer) Close

func (fb *FileBuffer) Close() error

Close closes the FileBuffer.

It returns nil as there are no resources to close.

func (*FileBuffer) Reader

func (fb *FileBuffer) Reader() io.Reader

Reader returns an io.Reader that reads from the FileBuffer.

It returns a bytes.Reader that reads from the bytes of the FileBuffer's Buffer. The bytes.Reader is created using the Bytes method of the FileBuffer's Buffer.

Returns: - io.Reader: an io.Reader that reads from the FileBuffer's Buffer.

func (*FileBuffer) Seek

func (fb *FileBuffer) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next read or write on the FileBuffer.

Parameters: - offset: the offset in bytes from the origin. - whence: the origin from which to calculate the offset. It can be one of:

  • io.SeekStart: the offset is relative to the start of the buffer.
  • io.SeekCurrent: the offset is relative to the current position in the buffer.
  • io.SeekEnd: the offset is relative to the end of the buffer.

Returns: - int64: the new offset. - error: an error if the new offset is negative.

func (*FileBuffer) Size

func (fb *FileBuffer) Size() int

Size returns the size of the FileBuffer.

It calculates the size of the buffer by calling the Len method of the underlying Buffer.

Returns: - int: the size of the FileBuffer.

func (*FileBuffer) Tell

func (fb *FileBuffer) Tell() int

Tell returns the current offset of the FileBuffer.

It returns the current offset of the FileBuffer.

Returns: - int: the current offset of the FileBuffer.

func (*FileBuffer) Write

func (fb *FileBuffer) Write(p []byte) (n int, err error)

Write writes the contents of the byte slice p to the FileBuffer.

It returns the number of bytes written and any error encountered. The function first checks if there is any extra space between the current offset and the end of the buffer. If so, it writes zeros to fill that space. Then it checks if the current offset is within the buffer's length. If so, it copies as much of the input as possible to the buffer starting from the current offset. The remaining input is then written to the buffer. Finally, the function updates the offset and returns the number of bytes written and any error encountered.

Parameters: - p: a byte slice containing the data to be written to the FileBuffer.

Returns: - n: the number of bytes written to the FileBuffer. - err: any error encountered during the write operation.

type ROM

type ROM struct {
	Filename string
	Data     []byte
	Size     int
	Offset   int
}

func NewROM

func NewROM(filename string) (rom *ROM, err error)

NewROM creates a new ROM object with the given filename.

Parameters: - filename: the name of the file to be opened.

Returns: - rom: a pointer to the newly created ROM object. - err: an error if the file could not be opened.

func (*ROM) Init

func (rom *ROM) Init() error

Init initializes the ROM object by opening the ROM file, getting the file info, reading the ROM data, and storing it in the object.

Returns an error if any of the operations fail.

func (*ROM) Read16

func (rom *ROM) Read16() (value uint16, err error)

Read16 reads a 16-bit value from the ROM.

It returns the read value and an error if the end of the ROM is reached.

Parameters: - rom: a pointer to a ROM object.

Returns: - value: a uint16 representing the read value. - err: an error if the end of the ROM is reached.

func (*ROM) Read32

func (rom *ROM) Read32() (value uint32, err error)

Read32 reads a 32-bit value from the ROM.

It returns the read value and an error if the end of the ROM is reached.

Parameters: - rom: a pointer to a ROM object.

Returns: - value: a uint32 representing the read value. - err: an error if the end of the ROM is reached.

func (*ROM) Read8

func (rom *ROM) Read8() (value uint8, err error)

Read8 reads an 8-bit value from the ROM.

It returns the read value and an error if the end of the ROM is reached.

func (*ROM) ReadString

func (rom *ROM) ReadString() (value string, err error)

ReadString reads a string from the ROM starting at the current offset.

It returns the read string and an error if the end of the ROM is reached.

Parameters: - rom: a pointer to a ROM object.

Returns: - value: a string representing the read value. - err: an error if the end of the ROM is reached.

func (*ROM) Seek

func (rom *ROM) Seek(offset int)

Seek sets the offset for the next read or write on the ROM.

Parameters: - offset: the offset in bytes from the start of the ROM.

Returns: - None.

func (*ROM) Tell

func (rom *ROM) Tell() (offset int)

Tell returns the current offset of the ROM.

No parameters. Returns an integer representing the current offset.

Jump to

Keyboard shortcuts

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