vm

package
v0.0.0-...-04bb2d0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RESET_CURSOR      = 0x00
	MOVE_CURSOR_RIGHT = 0x10
	MOVE_CURSOR_LEFT  = 0x11
	MOVE_CURSOR_DOWN  = 0x12
	MOVE_CURSOR_UP    = 0x13
	FRAMES_PER_SECOND = 5
)
View Source
const (
	STOP = 0x00 // Halts the machine. No further instructions will be executed.
	WAIT = 0x01 // Wait for an interruption. Effectively pauses the machine.
)
View Source
const (
	LOAD_BYTE              = 0x11
	LOAD_ADDRESS           = 0x12
	LOAD_OFFSET            = 0x13
	LOAD_POINTER           = 0x14
	STORE_BYTE_ADDRESS     = 0x15
	STORE_BYTE_OFFSET      = 0x16
	STORE_BYTE_POINTER     = 0x17
	STORE_REGISTER_ADDRESS = 0x18
	STORE_REGISTER_OFFSET  = 0x19
	STORE_REGISTER_POINTER = 0x1A
	COPY_REGISTER          = 0x1B
	COPY_ADDRESS_ADDRESS   = 0x1C
	COPY_ADDRESS_OFFSET    = 0x1D
	COPY_ADDRESS_POINTER   = 0x1E
	COPY_OFFSET_ADDRESS    = 0x1F
	COPY_OFFSET_OFFSET     = 0x20
	COPY_OFFSET_POINTER    = 0x21
	COPY_POINTER_ADDRESS   = 0x22
	COPY_POINTER_OFFSET    = 0x23
	COPY_POINTER_POINTER   = 0x24
)
View Source
const (
	INCREMENT byte = 0x80 // Increment register
	DECREMENT byte = 0x81 // Decrement register
)
View Source
const (
	ADD      byte = 0x82
	SUBTRACT byte = 0x83
	MULTIPLY byte = 0x84
	DIVIDE   byte = 0x85
)
View Source
const (
	AND byte = 0x86
	OR  byte = 0x87
	XOR byte = 0x88
	NOT byte = 0x89
)
View Source
const (
	JUMP_ADDRESS               byte = 0x90
	JUMP_OFFSET                byte = 0x91
	JUMP_POINTER               byte = 0x92
	JUMP_EQUAL_ADDRESS         byte = 0x93
	JUMP_EQUAL_OFFSET          byte = 0x94
	JUMP_EQUAL_POINTER         byte = 0x95
	JUMP_NOT_EQUAL_ADDRESS     byte = 0x96
	JUMP_NOT_EQUAL_OFFSET      byte = 0x97
	JUMP_NOT_EQUAL_POINTER     byte = 0x98
	JUMP_GREATER_ADDRESS       byte = 0x99
	JUMP_GREATER_OFFSET        byte = 0x9A
	JUMP_GREATER_POINTER       byte = 0x9B
	JUMP_GREATER_EQUAL_ADDRESS byte = 0x9C
	JUMP_GREATER_EQUAL_OFFSET  byte = 0x9D
	JUMP_GREATER_EQUAL_POINTER byte = 0x9E
	JUMP_LESS_ADDRESS          byte = 0x9F
	JUMP_LESS_OFFSET           byte = 0xA0
	JUMP_LESS_POINTER          byte = 0xA1
	JUMP_LESS_EQUAL_ADDRESS    byte = 0xA2
	JUMP_LESS_EQUAL_OFFSET     byte = 0xA3
	JUMP_LESS_EQUAL_POINTER    byte = 0xA4
)

Branching instructions

View Source
const (
	INPUT  byte = 0xB0
	OUTPUT byte = 0xC0
)
View Source
const (
	COMPARE_REGISTER_REGISTER = 0xD0
	COMPARE_REGISTER_VALUE    = 0xD1
	COMPARE_REGISTER_ABSOLUTE = 0xD2
	COMPARE_REGISTER_OFFSET   = 0xD3
	COMPARE_REGISTER_POINTER  = 0xD4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinate

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

type Device

type Device interface {
	Read() byte
	Write(value byte)
}

type Display

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

func NewDisplay

func NewDisplay(cols int, rows int) *Display

func (*Display) Init

func (d *Display) Init()

func (Display) Read

func (display Display) Read() byte

func (Display) Write

func (display Display) Write(value byte)

type Fifo

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

First-input first-output device

func NewFifo

func NewFifo(size int) *Fifo

func (Fifo) Read

func (fifo Fifo) Read() byte

func (Fifo) Write

func (fifo Fifo) Write(value byte)

type Flags

type Flags struct {
	Zero    bool
	Equal   bool
	Greater bool
	Less    bool
}

type Instruction

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

type Machine

type Machine struct {
	Name           string
	Registers      [16]Register
	Memory         []byte
	ProgramCounter uint16
	Flags          Flags

	Devices [255]Device
	// contains filtered or unexported fields
}

func NewMachine

func NewMachine(name string, memorySize int, display bool) Machine

func (*Machine) DumpFlags

func (m *Machine) DumpFlags()

func (*Machine) DumpMemory

func (m *Machine) DumpMemory()

func (*Machine) DumpRegisters

func (m *Machine) DumpRegisters()

func (*Machine) DumpStatus

func (m *Machine) DumpStatus()

func (*Machine) Explain

func (m *Machine) Explain()

func (*Machine) Jump

func (m *Machine) Jump(address uint16)

func (*Machine) Load

func (m *Machine) Load(memory []byte)

func (*Machine) ReadAddress

func (m *Machine) ReadAddress(address uint16) uint16

func (*Machine) ReadAddressFromNextOffset

func (m *Machine) ReadAddressFromNextOffset() uint16

Assumes that the next memory location is an offset from the current program counter.

func (*Machine) ReadAddressFromNextPointer

func (m *Machine) ReadAddressFromNextPointer() uint16

Assumes that the next memory location contains a pointer to a memory location that holds an address

func (*Machine) ReadAddressOffset

func (m *Machine) ReadAddressOffset(offset uint16) uint16

func (*Machine) ReadByteAddress

func (m *Machine) ReadByteAddress(address uint16) byte

func (*Machine) ReadByteOffset

func (m *Machine) ReadByteOffset(offset uint16) byte

func (*Machine) ReadBytePointer

func (m *Machine) ReadBytePointer(pointer uint16) byte

func (*Machine) ReadNextAddress

func (m *Machine) ReadNextAddress() uint16

func (*Machine) ReadNextByte

func (m *Machine) ReadNextByte() byte

func (*Machine) Run

func (m *Machine) Run()
Before executing an instruction, we try to get a lock on the machine, in order to

simulate hardware interrupts. This works for the time being, but we must dive deeper...

func (*Machine) Stop

func (m *Machine) Stop()

type Register

type Register struct {
	Name  string
	Value byte
}

type Surface

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

Jump to

Keyboard shortcuts

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