vm

package
v0.0.0-...-d61683a Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RR0 ~ RR7 are general purpose reg
	RR0 uint16 = iota
	RR1
	RR2
	RR3
	RR4
	RR5
	RR6
	RR7
	RPC   /* Program Counter */
	RCOND /* Condition Flags, program can check logical conditions. */
	RCOUNT
)

Register ID

View Source
const (
	OPBR   uint16 = iota /* branch */
	OPADD                /* add  */
	OPLD                 /* load */
	OPST                 /* store */
	OPJSR                /* jump register */
	OPAND                /* bitwise and */
	OPLDR                /* load register */
	OPSTR                /* store register */
	OPRTI                /* RTI (unused) */
	OPNOT                /* bitwise not */
	OPLDI                /* load indirect */
	OPSTI                /* store indirect */
	OPJMP                /* jump */
	OPRES                /* reserved (unused) */
	OPLEA                /* load effective address */
	OPTRAP               /* execute trap */
)

OpsCode ID

View Source
const (
	FLPOS uint16 = 1 << 0 /* P */
	FLZRO uint16 = 1 << 1 /* Z */
	FLNEG uint16 = 1 << 2 /* N */
)

Flag ID for RCOND

View Source
const (
	MRKBSR uint16 = 0xFE00 // Keyboard Status
	MRKBDR uint16 = 0xFE02 // Keyboard Data
)

Special Memory Addr ID

View Source
const (
	TRAPGETC  uint16 = 0x20 /* Get character from keyboard, not echoed onto the terminal */
	TRAPOUT   uint16 = 0x21 /* Output a character */
	TRAPPUTS  uint16 = 0x22 /* Output a word string */
	TRAPIN    uint16 = 0x23 /* Get character from keyboard, echoed onto the terminal */
	TRAPPUTSP uint16 = 0x24 /* Output a byte string */
	TRAPHALT  uint16 = 0x25 /* Halt the program */
)

Trap ID

View Source
const (
	PCSTART uint16 = 0x3000
)

set the PC to starting position 0x3000 is the default

Variables

This section is empty.

Functions

This section is empty.

Types

type CPU

type CPU struct {
	IsRunning bool
	// contains filtered or unexported fields
}

CPU define the CPU

func NewCPU

func NewCPU(mem *Memory) *CPU

NewCPU return a CPU

func (*CPU) Execute

func (c *CPU) Execute(instruction uint16)

Execute the opcode

func (*CPU) Load

func (c *CPU) Load(addr uint16, val uint16)

Load data into memory

func (*CPU) NextInstruction

func (c *CPU) NextInstruction() uint16

NextInstruction return next instruction

type Memory

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

Memory is define the memory

func NewMemory

func NewMemory() *Memory

NewMemory return Memory

func (*Memory) MemoryRead

func (m *Memory) MemoryRead(addr uint16) uint16

MemoryRead return the value of storage[addr]

func (*Memory) MemoryWrite

func (m *Memory) MemoryWrite(addr uint16, val uint16)

MemoryWrite set the value of storage[addr] to val

Jump to

Keyboard shortcuts

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