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 ¶
- type Data
- func (r *Data) AND(val uint8)
- func (r *Data) ASL() bool
- func (r *Data) Add(val uint8, carry bool) (rcarry bool, overflow bool)
- func (r *Data) AddDecimal(val uint8, carry bool) (bool, bool, bool, bool)
- func (r Data) Address() uint16
- func (r Data) BitWidth() int
- func (r *Data) EOR(val uint8)
- func (r Data) IsBitV() bool
- func (r Data) IsNegative() bool
- func (r Data) IsZero() bool
- func (r *Data) LSR() bool
- func (r Data) Label() string
- func (r *Data) Load(val uint8)
- func (r *Data) ORA(val uint8)
- func (r *Data) ROL(carry bool) bool
- func (r *Data) ROR(carry bool) bool
- func (r *Data) SetOnLoad(onLoad func(uint8))
- func (r Data) String() string
- func (r *Data) Subtract(val uint8, carry bool) (rcarry bool, overflow bool)
- func (r *Data) SubtractDecimal(val uint8, carry bool) (bool, bool, bool, bool)
- func (r Data) Value() uint8
- type ProgramCounter
- func (pc *ProgramCounter) Add(val uint16) (carry, overflow bool)
- func (pc ProgramCounter) Address() uint16
- func (pc ProgramCounter) BitWidth() int
- func (pc ProgramCounter) Label() string
- func (pc *ProgramCounter) Load(val uint16)
- func (pc ProgramCounter) String() string
- func (pc ProgramCounter) Value() uint16
- type StackPointer
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data implements the 6507 8bit register
func (*Data) ASL ¶
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) Address ¶
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) IsNegative ¶
IsNegative checks the sign bit of the register.
func (*Data) LSR ¶
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) SubtractDecimal ¶
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) String ¶
func (pc ProgramCounter) String() string
func (ProgramCounter) Value ¶
func (pc ProgramCounter) Value() uint16
Value returns the current value of the register.
type StackPointer ¶
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 ¶
func NewStackPointer(val uint8) StackPointer
NewStackPointer creates a new stack pointer register.
func (StackPointer) Address ¶
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 ¶
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 ¶
func NewStatus() Status
NewStatus is the preferred method of initialisation for the status register.