Documentation ¶
Index ¶
- Constants
- func DecodeOp(in byte) (OpCode, AddressMode, AddressMode)
- func EncodeOp(op OpCode, m1, m2 AddressMode) byte
- func LogIOError(format string, a ...interface{})
- func RegisterSDLHandlers(m *IODispatcher)
- type AddressMode
- type ByteSliceMemory
- func (m *ByteSliceMemory) BytesReaderAt(addr uint16) *bytes.Reader
- func (m *ByteSliceMemory) GetByte(addr uint16) byte
- func (m *ByteSliceMemory) GetWord(addr uint16) uint16
- func (m *ByteSliceMemory) PutByte(addr uint16, b byte)
- func (m *ByteSliceMemory) PutWord(addr uint16, w uint16)
- func (m *ByteSliceMemory) ReadZString(addr uint16) string
- type Encoding
- type Flags
- type IODispatcher
- func (d *IODispatcher) BytesReaderAt(addr uint16) *bytes.Reader
- func (d *IODispatcher) GetByte(addr uint16) byte
- func (d *IODispatcher) GetWord(addr uint16) uint16
- func (d *IODispatcher) PutByte(addr uint16, b byte)
- func (d *IODispatcher) PutWord(addr uint16, w uint16)
- func (d *IODispatcher) ReadZString(addr uint16) string
- func (d *IODispatcher) RegisterIOHandler(id int, h IOHandler)
- func (d *IODispatcher) StatusRegister() Memory
- type IOHandler
- type Machine
- type Memory
- type OpCode
- type RNG
- type Register
- func (r Register) BytesReaderAt(addr uint16) *bytes.Reader
- func (r *Register) Get() uint16
- func (r *Register) GetByte(addr uint16) byte
- func (r *Register) GetWord(addr uint16) uint16
- func (r *Register) PutByte(addr uint16, b byte)
- func (r *Register) PutWord(addr uint16, w uint16)
- func (r Register) ReadZString(addr uint16) string
- func (r *Register) Set(w uint16)
- type SdlClearHandler
- type SdlDrawLineHandler
- type SdlDrawRectHandler
- type SdlFillRectHandler
- type SdlInitAudioHandler
- type SdlInitHandler
- type SdlLoadWavHandler
- type SdlPlayWavHandler
- type SdlPollHandler
- type SdlPresentHandler
- type SdlSetColorHandler
- type SdlTicksHandler
- type StdoutWriteHandler
Constants ¶
const ( SdlDeviceId = 0x0200 SdlInit = 1 SdlPoll = 2 SdlPresent = 3 SdlClear = 4 SdlSetColor = 5 SdlDrawLine = 6 SdlDrawRect = 7 SdlFillRect = 8 SdlTicks = 9 SdlInitAudio = 0x0a SdlLoadWav = 0x0b SdlPlayWav = 0x0c )
const ( ErrNoErr uint16 = iota ErrInvalidHandler ErrIOError )
const ( PCAddr = 0 // Program counter SPAddr = 2 // Stack pointer, points to last byte written FPAddr = 4 // Frame pointer IOReqAddr = 6 // Address of I/O commands are written here to execute IOStatAddr = 8 // I/O status of last command, 0 = success, != 0 error RandAddr = 10 // Writes are ignored, reads return random uint8/uint16 )
const ( StdoutDeviceId = 0x0100 StdoutCommandWrite = 1 )
const BaseDirEnv = "MPU_BASE_DIR"
BaseDirEnv is the key for an environment variable to use for loading relative files.
Variables ¶
This section is empty.
Functions ¶
func DecodeOp ¶
func DecodeOp(in byte) (OpCode, AddressMode, AddressMode)
func EncodeOp ¶
func EncodeOp(op OpCode, m1, m2 AddressMode) byte
func LogIOError ¶
func LogIOError(format string, a ...interface{})
func RegisterSDLHandlers ¶
func RegisterSDLHandlers(m *IODispatcher)
Types ¶
type AddressMode ¶
type AddressMode byte
const ( Implied AddressMode = iota Absolute Immediate ImmediateByte OffsetByte Indirect Relative RelativeIndirect )
func (AddressMode) String ¶
func (m AddressMode) String() string
type ByteSliceMemory ¶
type ByteSliceMemory struct {
// contains filtered or unexported fields
}
ByteSliceMemory contains a set of (continuous) memory-mapped regions and a raw byte slice. The memory mapped area must be contiguous, and start at offset zero, and must consist of all word-sized memory.
func NewByteSliceMemory ¶
func NewByteSliceMemory(registers []Memory, raw []byte) *ByteSliceMemory
func (*ByteSliceMemory) BytesReaderAt ¶
func (m *ByteSliceMemory) BytesReaderAt(addr uint16) *bytes.Reader
func (*ByteSliceMemory) GetByte ¶
func (m *ByteSliceMemory) GetByte(addr uint16) byte
func (*ByteSliceMemory) GetWord ¶
func (m *ByteSliceMemory) GetWord(addr uint16) uint16
func (*ByteSliceMemory) PutByte ¶
func (m *ByteSliceMemory) PutByte(addr uint16, b byte)
func (*ByteSliceMemory) PutWord ¶
func (m *ByteSliceMemory) PutWord(addr uint16, w uint16)
func (*ByteSliceMemory) ReadZString ¶
func (m *ByteSliceMemory) ReadZString(addr uint16) string
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
Encoding defines the opcode and two address modes for each instruction. TODO It might be easier to both define and lookup at runtime by using bitfields want an int, rather than fields want a struct. If each operand mode is a flag then the combos can be too ... AbsAbs. Add | AbsAbs, Sub | AbsAbs, Mul | AbsAbs, ... may be worth a microbenchmark to see the runtime performance variations.
type IODispatcher ¶
type IODispatcher struct {
// contains filtered or unexported fields
}
IODispatcher implements Memory, to map to an address, and provides another Memory object to view the status of the last IO request.
func NewDefaultDispatcher ¶
func NewDefaultDispatcher() *IODispatcher
func NewDispatcher ¶
func NewDispatcher() *IODispatcher
func (*IODispatcher) BytesReaderAt ¶
func (d *IODispatcher) BytesReaderAt(addr uint16) *bytes.Reader
func (*IODispatcher) GetByte ¶
func (d *IODispatcher) GetByte(addr uint16) byte
func (*IODispatcher) GetWord ¶
func (d *IODispatcher) GetWord(addr uint16) uint16
func (*IODispatcher) PutByte ¶
func (d *IODispatcher) PutByte(addr uint16, b byte)
func (*IODispatcher) PutWord ¶
func (d *IODispatcher) PutWord(addr uint16, w uint16)
func (*IODispatcher) ReadZString ¶
func (d *IODispatcher) ReadZString(addr uint16) string
func (*IODispatcher) RegisterIOHandler ¶
func (d *IODispatcher) RegisterIOHandler(id int, h IOHandler)
func (*IODispatcher) StatusRegister ¶
func (d *IODispatcher) StatusRegister() Memory
type IOHandler ¶
IOHandler represents a single command handler within a device. Handlers must be registered via RegisterIOHandler. When invoked, machine will use encoding/binary to unmarshall the data pointed to into the handler and then call its Handle() method.
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
Machine implements MPU ... memory processing unit. It supports 27 instructions and 6 addressing modes.
func NewMachine ¶
func NewMachineWithDevices ¶
func NewMachineWithDevices(d *IODispatcher, image []byte) *Machine
func (*Machine) ReadInt8 ¶
ReadInt8 reads the given addr from memory as a byte and casts it to a signed int8 (as an int).
type Memory ¶
type Memory interface { PutByte(addr uint16, b byte) GetByte(addr uint16) byte PutWord(addr uint16, w uint16) GetWord(addr uint16) uint16 ReadZString(addr uint16) string BytesReaderAt(addr uint16) *bytes.Reader }
Memory defines the basic abstraction of reading/writing words and bytes to random access memory OR to memory-mapped registers.
type RNG ¶
type RNG struct {
// contains filtered or unexported fields
}
RNG exposes a random number generator as a Memory unit. Writes are ignored. Both bytes and words can be read.
func (*RNG) ReadZString ¶
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
Register defines uint16 which is mapped to memory and therefore supports the put/get byte/word primitives.
func (Register) ReadZString ¶
type SdlClearHandler ¶
type SdlClearHandler struct {
Id uint16
}
type SdlDrawLineHandler ¶
type SdlDrawRectHandler ¶
type SdlFillRectHandler ¶
type SdlInitAudioHandler ¶
type SdlInitAudioHandler struct {
Id uint16
}