registers

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: GPL-3.0, GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package registers implements the three types of registers found in the 6507. The three types are: the program counter, status register and the 8 bit accumulating registers, A, X, Y.

The 8 bit registers, implemented as the Register type, define all the basic operations available to the 6507: load, add, subtract, logical operations and shifts/rotates. In addition it implements the tests required for status updates: is the value zero, is the number negative, is the overflow bit set. Use of decimal mode is possible with the AddDecimal() and SubtractDecimal() functions.

The program counter is 16 bits wide and defines only the load and add operations.

The status register is implemented as a series of flags. Setting of flags is done directly. For instance, in the CPU, we might have this sequence of function calls:

a.Load(10)
a.Subtract(11)
sr.Zero = a.IsZero()

In this case, the zero flag in the status register will be false.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generic

type Generic interface {
	Label() string
	String() string
	BitWidth() int
}

Generic interface defines the minimum requirements for a register/PC to be generally useful. Interface used to facilitate editing of register/PC values.

type ProgramCounter

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

ProgramCounter represents the PC register in the 6507 CPU.

func NewProgramCounter

func NewProgramCounter(val uint16) ProgramCounter

NewProgramCounter is the preferred method of initialisation for ProgramCounter.

func (*ProgramCounter) Add

func (pc *ProgramCounter) Add(val uint16) (carry, overflow bool)

Add a value to the PC.

func (ProgramCounter) Address

func (pc ProgramCounter) Address() uint16

Address returns the current value of the PC as a a value of type uint16.

func (ProgramCounter) BitWidth

func (pc ProgramCounter) BitWidth() int

BitWidth returns the number of bits used to store the program counter value.

func (ProgramCounter) Label

func (pc ProgramCounter) Label() string

Label returns the program counter label (or ID).

func (*ProgramCounter) Load

func (pc *ProgramCounter) Load(val uint16)

Load a value into the PC.

func (ProgramCounter) String

func (pc ProgramCounter) String() string

func (ProgramCounter) Value

func (pc ProgramCounter) Value() uint16

Value returns the current value of the register.

type Register

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

Register is an array of of type bit, used for register representation.

func NewAnonRegister

func NewAnonRegister(val uint8) Register

NewAnonRegister initialises a new register without a name.

func NewRegister

func NewRegister(val uint8, label string) Register

NewRegister creates a new register of a givel size and name, and initialises the value.

func (*Register) AND

func (r *Register) AND(val uint8)

AND value with register.

func (*Register) ASL

func (r *Register) ASL() bool

ASL (arithmetic shift left) shifts register one bit to the left. Returns the most significant bit as it was before the shift. If we think of the ASL operation as a multiply by two then the return value is the carry bit.

func (*Register) Add

func (r *Register) Add(val uint8, carry bool) (rcarry bool, overflow bool)

Add value to register. Returns carry and overflow states.

func (*Register) AddDecimal

func (r *Register) AddDecimal(val uint8, carry bool) (bool, bool, bool, bool)

AddDecimal adds value to register as though both registers are decimal representations. Returns new carry state, zero, overflow, sign bit information.

func (Register) Address

func (r Register) Address() uint16

Address returns the current value of the register /as a uint16/. this is useful when you want to use the register value in an address context.

for example, the stack pointer stores page zero addresses - which can be stored in just 8bits but which are always interpreted as 16bit value.

func (Register) BitWidth

func (r Register) BitWidth() int

BitWidth returns the number of bits used to store the register value.

func (*Register) EOR

func (r *Register) EOR(val uint8)

EOR (exclusive or) value with register.

func (Register) IsBitV

func (r Register) IsBitV() bool

IsBitV returns the state of the second MSB.

func (Register) IsNegative

func (r Register) IsNegative() bool

IsNegative checks the sign bit of the register.

func (Register) IsZero

func (r Register) IsZero() bool

IsZero checks if register is zero.

func (*Register) LSR

func (r *Register) LSR() bool

LSR (logical shift right) shifts register one bit to the right. the least significant bit as it was before the shift. If we think of the ASL operation as a division by two then the return value is the carry bit.

func (Register) Label

func (r Register) Label() string

Label returns the registers label (or ID).

func (*Register) Load

func (r *Register) Load(val uint8)

Load value into register.

func (*Register) ORA

func (r *Register) ORA(val uint8)

ORA (non-exclusive or) value with register.

func (*Register) ROL

func (r *Register) ROL(carry bool) bool

ROL rotates register 1 bit to the left. Returns new carry status.

func (*Register) ROR

func (r *Register) ROR(carry bool) bool

ROR rotates register 1 bit to the right. Returns new carry status.

func (Register) String

func (r Register) String() string

returns value as a string in hexadecimal notation.

func (*Register) Subtract

func (r *Register) Subtract(val uint8, carry bool) (rcarry bool, overflow bool)

Subtract value from register. Returns carry and overflow states.

func (*Register) SubtractDecimal

func (r *Register) SubtractDecimal(val uint8, carry bool) (bool, bool, bool, bool)

SubtractDecimal subtracts value to from as though both registers are decimal representations. Returns new carry state, zero, overflow, sign bit information.

func (Register) Value

func (r Register) Value() uint8

Value returns the current value of the register.

type StatusRegister

type StatusRegister struct {
	Sign             bool
	Overflow         bool
	Break            bool
	DecimalMode      bool
	InterruptDisable bool
	Zero             bool
	Carry            bool
}

StatusRegister is the special purpose register that stores the flags of the CPU.

func NewStatusRegister

func NewStatusRegister() StatusRegister

NewStatusRegister is the preferred method of initialisation for the status register.

func (*StatusRegister) FromValue

func (sr *StatusRegister) FromValue(v uint8)

FromValue converts an 8 bit integer (taken from the stack, for example) to the StatusRegister struct receiver.

func (StatusRegister) Label

func (sr StatusRegister) Label() string

Label returns the canonical name for the status register.

func (*StatusRegister) Reset

func (sr *StatusRegister) Reset()

Reset status flags to initial state.

func (StatusRegister) String

func (sr StatusRegister) String() string

func (StatusRegister) Value

func (sr StatusRegister) Value() uint8

Value converts the StatusRegister struct into a value suitable for pushing onto the stack.

Directories

Path Synopsis
Package test contains functions useful for testing CPU registers.
Package test contains functions useful for testing CPU registers.

Jump to

Keyboard shortcuts

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