registers

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: 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 Data added in v0.40.0

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

Data implements the 6507 8bit register

func NewData added in v0.40.0

func NewData(val uint8, label string) Data

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

func (*Data) AND added in v0.40.0

func (r *Data) AND(val uint8)

AND value with register.

func (*Data) ASL added in v0.40.0

func (r *Data) 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 (*Data) Add added in v0.40.0

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

Add value to register. Returns carry and overflow states.

func (*Data) AddDecimal added in v0.40.0

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

func (Data) Address added in v0.40.0

func (r Data) 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 (Data) BitWidth added in v0.40.0

func (r Data) BitWidth() int

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

func (*Data) EOR added in v0.40.0

func (r *Data) EOR(val uint8)

EOR (exclusive or) value with register.

func (Data) IsBitV added in v0.40.0

func (r Data) IsBitV() bool

IsBitV returns the state of the second MSB.

func (Data) IsNegative added in v0.40.0

func (r Data) IsNegative() bool

IsNegative checks the sign bit of the register.

func (Data) IsZero added in v0.40.0

func (r Data) IsZero() bool

IsZero checks if register is zero.

func (*Data) LSR added in v0.40.0

func (r *Data) 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 (Data) Label added in v0.40.0

func (r Data) Label() string

Label returns the registers label (or ID).

func (*Data) Load added in v0.40.0

func (r *Data) Load(val uint8)

Load value into register.

func (*Data) ORA added in v0.40.0

func (r *Data) ORA(val uint8)

ORA (non-exclusive or) value with register.

func (*Data) ROL added in v0.40.0

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

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

func (*Data) ROR added in v0.40.0

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

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

func (*Data) SetOnLoad added in v0.40.0

func (r *Data) SetOnLoad(onLoad func(uint8))

SetOnLoad sets the callback function for a load register event.

func (Data) String added in v0.40.0

func (r Data) String() string

returns value as a string in hexadecimal notation.

func (*Data) Subtract added in v0.40.0

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

Subtract value from register. Returns carry and overflow states.

func (*Data) SubtractDecimal added in v0.40.0

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

func (Data) Value added in v0.40.0

func (r Data) Value() uint8

Value returns the current value of the register.

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 StackPointer added in v0.21.0

type StackPointer struct {
	Data
}

StackPointer is a special purpose Register. It can be treated as a register if required through the Register field.

func NewStackPointer added in v0.21.0

func NewStackPointer(val uint8) StackPointer

NewStackPointer creates a new stack pointer register.

func (StackPointer) Address added in v0.21.0

func (sp StackPointer) Address() uint16

The stack is hardwired to page one addresses. Note that the VCS stack actually appears in page zero but this is a consequence of how the memory bus is wired.

type Status added in v0.40.0

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

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

func NewStatus added in v0.40.0

func NewStatus() Status

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

func (Status) Label added in v0.40.0

func (sr Status) Label() string

Label returns the canonical name for the status register.

func (*Status) Load added in v0.40.0

func (sr *Status) Load(v uint8)

Load sets the status register flags from an 8 bit integer (which has been taken from the stack, for example)

func (Status) String added in v0.40.0

func (sr Status) String() string

func (Status) Value added in v0.40.0

func (sr Status) 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