Documentation
¶
Overview ¶
Package io provides I/O channel implementations for the μCAPP emulator. It includes various channel types for bit-level I/O operations including temporary storage (Temp), persistent drum/ring storage (Depot, Drum, Ring), sequential I/O (Tape), and ROM.
Index ¶
- Constants
- Variables
- func ReceiveAsUint8(ch Channel) iter.Seq[uint8]
- func ReceiveAsUint16(ch Channel) iter.Seq[uint16]
- func ReceiveAsUint32(ch Channel) iter.Seq[uint32]
- func SendAsUint8(ch Channel, value uint8) (err error)
- func SendAsUint16(ch Channel, value uint16) (err error)
- func SendAsUint32(ch Channel, value uint32) (err error)
- type Channel
- type CreateFS
- type Depot
- func (depot *Depot) Alert(request uint32, response chan uint32)
- func (depot *Depot) Defines() iter.Seq2[string, string]
- func (depot *Depot) Dirty() bool
- func (depot *Depot) Marshal(filesys CreateFS) (err error)
- func (depot *Depot) Rewind()
- func (depot *Depot) Save(name string, content io.Reader) (err error)
- func (depot *Depot) Unmarshal(filesys fs.FS) (err error)
- type Drum
- func (drum *Drum) Alert(request uint32, response chan uint32)
- func (drum *Drum) Defines() iter.Seq2[string, string]
- func (drum *Drum) Delete(name string) (err error)
- func (drum *Drum) Dirents() iter.Seq[DrumDirent]
- func (drum *Drum) Dirty() bool
- func (drum *Drum) Marshal(filesys CreateFS) (err error)
- func (drum *Drum) Receive() iter.Seq[bool]
- func (drum *Drum) Rewind()
- func (drum *Drum) Save(name string, content io.Reader) (err error)
- func (drum *Drum) Send(value bool) (err error)
- func (drum *Drum) Unmarshal(filesys fs.FS) (err error)
- type DrumDirent
- type Ring
- func (ring *Ring) Alert(request uint32, response chan uint32)
- func (ring *Ring) Defines() iter.Seq2[string, string]
- func (ring *Ring) Dirty() bool
- func (ring *Ring) Marshal(file io.Writer) (err error)
- func (ring *Ring) Receive() iter.Seq[bool]
- func (ring *Ring) Rewind()
- func (ring *Ring) Send(value bool) (err error)
- func (ring *Ring) Unmarshal(file io.Reader) (err error)
- type Rom
- type Tape
- type Temporary
Constants ¶
const ( // DEPOT_OP_MASK masks the depot operation type from an alert request. DEPOT_OP_MASK = (1 << 23) // DEPOT_OP_SELECT indicates a drum selection operation. DEPOT_OP_SELECT = (0 << 23) // DEPOT_OP_DRUM indicates a drum-level operation. DEPOT_OP_DRUM = (1 << 23) // DEPOT_OP_SELECT_MASK masks the drum ID from a select operation. DEPOT_OP_SELECT_MASK = ((1 << 23) - 1) )
const ( // DRUM_OP_MASK masks the drum operation type from an alert request. DRUM_OP_MASK = (1 << 8) // DRUM_OP_SELECT indicates a ring selection operation. DRUM_OP_SELECT = (0 << 8) // DRUM_OP_SELECT_MASK masks the ring ID from a select operation. DRUM_OP_SELECT_MASK = 0xff // DRUM_OP_RING indicates a ring-level operation. DRUM_OP_RING = (1 << 8) )
const ( // RING_OP_MASK masks the ring operation type from an alert request. RING_OP_MASK = (1 << 7) - 1 // RING_OP_REWIND_READ resets the read position to the start. RING_OP_REWIND_READ = 0 // RING_OP_REWIND_WRITE resets the write position to the start. RING_OP_REWIND_WRITE = 1 // RING_DEFAULT_CAPACITY is the default capacity in bits for a new ring. RING_DEFAULT_CAPACITY = 65536 * 8 )
const ( // ARENA_ID_PROGRAM is the arena ID for program memory space. ARENA_ID_PROGRAM = uint32(2 << 30) // ROM_OP_TRAP sets up the trap notification channel for the ROM. ROM_OP_TRAP = uint32(0) )
Variables ¶
var ErrChannelFull = errors.New(f("channel full"))
ErrChannelFull is returned when attempting to write to a full channel.
var ErrDrumMissing = errors.New(f("drum missing"))
ErrDrumMissing is returned when attempting to access a drum that doesn't exist.
var ErrNameRuneInvalid = errors.New(f("name has an unknown rune"))
ErrNameRuneInvalid is returned when the dirent name has invalid characters.
var ErrNameTooLong = errors.New(f("name length too long"))
ErrNameTooLong is returned when the name is too long.
var ErrNameTooShort = errors.New(f("name length too short"))
ErrNameTooShort is returned when the dirent name is empty.
Functions ¶
func ReceiveAsUint8 ¶
ReceiveAsUint8 returns an iterator that reads bits from the channel and yields complete 8-bit unsigned integers, LSB first.
func ReceiveAsUint16 ¶
ReceiveAsUint16 returns an iterator that reads bits from the channel and yields complete 16-bit unsigned integers, LSB first.
func ReceiveAsUint32 ¶
ReceiveAsUint32 returns an iterator that reads bits from the channel and yields complete 32-bit unsigned integers, LSB first.
func SendAsUint8 ¶
SendAsUint8 sends an 8-bit unsigned integer as 8 bits to the channel, LSB first.
func SendAsUint16 ¶
SendAsUint16 sends a 16-bit unsigned integer as 16 bits to the channel, LSB first.
func SendAsUint32 ¶
SendAsUint32 sends a 32-bit unsigned integer as 32 bits to the channel, LSB first.
Types ¶
type Channel ¶
type Channel interface {
// Per-channel defines
Defines() iter.Seq2[string, string]
// Rewind resets the channel to its initial state.
Rewind()
// Receive returns an iterator that yields bits from the channel.
Receive() iter.Seq[bool]
// Send writes a single bit to the channel.
Send(value bool) error
// Alert sends a control message to the channel with a response callback.
Alert(value uint32, response chan uint32)
}
Channel defines the interface for all I/O channels in the μCAPP system. Channels operate at the bit level and support sequential reading, writing, and control operations via alerts.
type CreateFS ¶
type CreateFS interface {
// Sub returns a filesystem for a subdirectory.
Sub(name string) (sub CreateFS, err error)
// Create creates a new file for writing.
Create(name string) (file io.WriteCloser, err error)
// Mkdir creates a new directory with the specified permissions.
Mkdir(name string, filemode fs.FileMode) (err error)
}
CreateFS defines a file system interface that supports creating files and directories. It extends basic file system operations with write capabilities for marshaling depot and drum data structures.
type Depot ¶
Depot represents a collection of drums providing persistent storage. It implements the Channel interface and manages multiple Drum instances, allowing selection between them via Alert operations.
func (*Depot) Alert ¶
Alert handles depot control operations including drum selection and forwarding drum-specific operations to the currently selected drum.
func (*Depot) Marshal ¶
Marshal writes the depot's drums to a file system, creating directories named XXXXXX.ud for each drum.
func (*Depot) Rewind ¶
func (depot *Depot) Rewind()
Rewind resets all drums in the depot to their initial positions.
type Drum ¶
Drum represents a collection of up to 256 rings, providing persistent storage similar to a drum memory device. It implements the Channel interface by forwarding operations to the currently selected ring.
func (*Drum) Alert ¶
Alert handles drum control operations including ring selection and forwarding ring-specific operations to the currently selected ring.
func (*Drum) Dirents ¶
func (drum *Drum) Dirents() iter.Seq[DrumDirent]
Dirents returns the sequence of directory entries from the drum.
func (*Drum) Marshal ¶
Marshal writes the drum's rings to a file system, creating files named XX.ur for each ring.
func (*Drum) Receive ¶
Receive returns an iterator that yields bits from the currently selected ring. If no ring is selected, selects ring 0 by default.
func (*Drum) Rewind ¶
func (drum *Drum) Rewind()
Rewind resets all rings in the drum to their initial positions.
type DrumDirent ¶
DrumDirent is a drum directory entry.
func (*DrumDirent) Deleted ¶
func (dirent *DrumDirent) Deleted() bool
Deleted returns true if the entry is deleted.
func (*DrumDirent) Marshal ¶
func (dirent *DrumDirent) Marshal() (content []uint8, err error)
Marshal converts the dirent to the on-ring representation
func (*DrumDirent) NameIs ¶
func (dirent *DrumDirent) NameIs(name string) bool
NameIs returns true if the name supplied would match the name in the dirent.
func (*DrumDirent) Size ¶
func (dirent *DrumDirent) Size() int
Size returns the on-ring size of the dirent itself in bytes.
func (*DrumDirent) Unmarshal ¶
func (dirent *DrumDirent) Unmarshal(content []uint8) (err error)
Unmarshal converts an on-ring representation of the dirent into the structure.
type Ring ¶
type Ring struct {
Capacity int
Readable bool
Writable bool
Executable bool
WriteIndex int
ReadIndex int
Data []uint8
// contains filtered or unexported fields
}
Ring represents a circular buffer storage device with separate read and write positions. It stores up to 64KB of data and supports sequential bit-level I/O.
func (*Ring) Alert ¶
Alert handles ring control operations including resetting read and write positions.
func (*Ring) Receive ¶
Receive returns an iterator that yields bits from the ring starting at the current read position up to the write position.
func (*Ring) Rewind ¶
func (ring *Ring) Rewind()
Rewind resets the ring's read position to the start and write position to the end of existing data. Initializes the data buffer if not already allocated.
type Rom ¶
type Rom struct {
Data []uint32
// contains filtered or unexported fields
}
Rom represents read-only memory that can issue trap notifications. It contains program data as 32-bit words and supports bit-level reading but not writing (writes return ErrChannelFull).
func (*Rom) Alert ¶
Alert handles ROM control operations, currently only supporting trap channel registration.
func (*Rom) Receive ¶
Receive returns an iterator that yields all bits from the ROM data, reading each 32-bit word LSB first.
func (*Rom) Rewind ¶
func (rc *Rom) Rewind()
Rewind is a no-op for ROM as it is read-only and stateless.
type Tape ¶
Tape provides sequential I/O operations for reading and writing byte streams. It wraps an io.Reader for input and io.Writer for output, converting between bit-level Channel operations and byte-level I/O.
func (*Tape) Alert ¶
Alert returns an error response for all requests as Tape does not support control operations.
type Temporary ¶
type Temporary struct {
Capacity int // Capacity in bits.
ReadIndex int
WriteIndex int
Size int
Data []bool
}
Temporary implements a circular buffer for temporary bit storage. It operates as a FIFO queue with a fixed capacity and separate read/write positions.
func (*Temporary) Alert ¶
Alert returns an error response for all requests as Temporary does not support control operations.
func (*Temporary) Receive ¶
Receive returns an iterator that yields bits from the buffer until empty. The buffer wraps around at the capacity boundary.