simulator

package
v0.0.0-...-0243302 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_ADDRESS = 1048576 // 2^20

	A Register = iota
	X
	L
	B
	S
	T
	F

	PC
	SW

	// Opcodes
	ADD    Opcode = 0x18
	ADDF   Opcode = 0x58
	ADDR   Opcode = 0x90
	AND    Opcode = 0x40
	CLEAR  Opcode = 0xB4
	COMP   Opcode = 0x28
	COMPF  Opcode = 0x88
	COMPR  Opcode = 0xA0
	DIV    Opcode = 0x24
	DIVF   Opcode = 0x64
	DIVR   Opcode = 0x9C
	FIX    Opcode = 0xC4
	FLOAT  Opcode = 0xC0
	HIO    Opcode = 0xF4
	J      Opcode = 0x3C
	JEQ    Opcode = 0x30
	JGT    Opcode = 0x34
	JLT    Opcode = 0x38
	JSUB   Opcode = 0x48
	LDA    Opcode = 0x00
	LDB    Opcode = 0x68
	LDCH   Opcode = 0x50
	LDF    Opcode = 0x70
	LDL    Opcode = 0x08
	LDS    Opcode = 0x6C
	LDT    Opcode = 0x74
	LDX    Opcode = 0x04
	LPS    Opcode = 0xD0
	MUL    Opcode = 0x20
	MULF   Opcode = 0x60
	MULR   Opcode = 0x98
	NORM   Opcode = 0xC8
	OR     Opcode = 0x44
	RD     Opcode = 0xD8
	RMO    Opcode = 0xAC
	RSUB   Opcode = 0x4C
	SHIFTL Opcode = 0xA4
	SHIFTR Opcode = 0xA8
	SIO    Opcode = 0xF0
	SSK    Opcode = 0xEC
	STA    Opcode = 0x0C
	STB    Opcode = 0x78
	STCH   Opcode = 0x54
	STF    Opcode = 0x80
	STI    Opcode = 0xD4
	STL    Opcode = 0x14
	STS    Opcode = 0x7C
	STSW   Opcode = 0xE8
	STT    Opcode = 0x84
	STX    Opcode = 0x10
	SUB    Opcode = 0x1C
	SUBF   Opcode = 0x5C
	SUBR   Opcode = 0x94
	SVC    Opcode = 0xB0
	TD     Opcode = 0xE0
	TIO    Opcode = 0xF8
	TIX    Opcode = 0x2C
	TIXR   Opcode = 0xB8
	WD     Opcode = 0xDC
)

Variables

View Source
var (
	InstrF1   = []Opcode{FIX, FLOAT, HIO, NORM, SIO, TIO}
	InstrF2   = []Opcode{ADDR, CLEAR, COMPR, DIVR, MULR, RMO, SHIFTL, SHIFTR, SUBR, SVC, TIXR}
	InstrF3F4 = []Opcode{ADD, ADDF, AND, COMP, COMPF, DIV, DIVF, J, JEQ, JGT, JLT, JSUB, LDA,
		LDB, LDCH, LDF, LDL, LDS, LDT, LDX, LPS, MUL, MULF, OR, RD, RSUB, SSK, STA, STB, STCH,
		STF, STI, STL, STS, STSW, STT, STX, SUB, SUBF, TD, TIX, WD}
)

Opcodes by type

Functions

func IsAddress

func IsAddress(val float64) bool

IsAddress checks if the value is a valid SIC/XE address

func IsByte

func IsByte(val float64) bool

IsByte checks if the value fits in a SIC/XE byte (8 bits)

func IsFloat

func IsFloat(val float64) bool

IsFloat checks if the value fits in a SIC/XE float (6 bytes)

func IsWord

func IsWord(val float64) bool

IsWord checks if the value fits in a SIC/XE word (3 bytes)

func Start

func Start(isDebug bool, inputFile string)

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

func InitDevice

func InitDevice(t DeviceType) (*Device, error)

InitDevice initializes a device for reading or writing

func (*Device) Read

func (d *Device) Read() (float64, error)

Read reads a byte from the device

func (*Device) Test

func (d *Device) Test() bool

Test checks if a device is initialized for reading or writing

func (*Device) Write

func (d *Device) Write(val float64) error

Write writes a byte to the device

type DeviceType

type DeviceType uint8
const (
	Unknown DeviceType = iota
	Reader
	Writer
)

type ErrorType

type ErrorType = string
const (
	NotImplementedError    ErrorType = "%s is not implemented"
	InvalidOpcodeError     ErrorType = "%s is not a valid opcode"
	InvalidAddressingError ErrorType = "%s is not a valid addressing mode"
)

type Machine

type Machine struct {
	Registers map[Register]float64
	Memory    [MAX_ADDRESS]byte
	Devices   map[uint8]*Device
}

func (*Machine) Byte

func (m *Machine) Byte(addr float64) (byte, error)

Byte returns a SIC/XE byte (8 bits) value from memory at address addr

func (*Machine) Execute

func (m *Machine) Execute() error

Execute decodes an instruction and executes it

func (*Machine) Float

func (m *Machine) Float(addr float64) (float64, error)

Float returns a SIC/XE float (6 bytes) from memory at address addr

func (*Machine) Init

func (m *Machine) Init()

func (*Machine) Register

func (m *Machine) Register(name Register) float64

Register returns the value of the register

func (*Machine) SetByte

func (m *Machine) SetByte(addr float64, val byte) error

SetByte sets a SIC/XE byte (8 bits) value in memory at address addr

func (*Machine) SetFloat

func (m *Machine) SetFloat(addr float64, val float64) error

SetFloat sets a SIC/XE float (6 bytes) value in memory at address addr

func (*Machine) SetRegister

func (m *Machine) SetRegister(name Register, val float64) error

SetRegister sets the value of the register

func (*Machine) SetRegisterLow

func (m *Machine) SetRegisterLow(name Register, val float64) error

SetRegisterLow sets the lowest byte of the register

func (*Machine) SetWord

func (m *Machine) SetWord(addr float64, val float64) error

SetWord sets a SIC/XE word (3 bytes) value in memory at address addr

func (*Machine) Word

func (m *Machine) Word(addr float64) (float64, error)

Word returns a SIC/XE word (3 bytes) value from memory at address addr

type Opcode

type Opcode byte

type Register

type Register uint8

Jump to

Keyboard shortcuts

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