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 Generic
- 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) LoadFromUint64(val uint64)
- func (pc ProgramCounter) String() string
- func (pc ProgramCounter) Value() uint16
- type Register
- func (r *Register) AND(val uint8)
- func (r *Register) ASL() bool
- func (r *Register) Add(val uint8, carry bool) (rcarry bool, overflow bool)
- func (r *Register) AddDecimal(val uint8, carry bool) (bool, bool, bool, bool)
- func (r Register) Address() uint16
- func (r Register) BitWidth() int
- func (r *Register) EOR(val uint8)
- func (r Register) IsBitV() bool
- func (r Register) IsNegative() bool
- func (r Register) IsZero() bool
- func (r *Register) LSR() bool
- func (r Register) Label() string
- func (r *Register) Load(val uint8)
- func (r *Register) LoadFromUint64(val uint64)
- func (r *Register) ORA(val uint8)
- func (r *Register) ROL(carry bool) bool
- func (r *Register) ROR(carry bool) bool
- func (r Register) String() string
- func (r *Register) Subtract(val uint8, carry bool) (rcarry bool, overflow bool)
- func (r *Register) SubtractDecimal(val uint8, carry bool) (bool, bool, bool, bool)
- func (r Register) Value() uint8
- type StatusRegister
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generic ¶
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) LoadFromUint64 ¶
func (pc *ProgramCounter) LoadFromUint64(val uint64)
LoadFromUint64 loads a value into the PC but using an int type as the value. It is the responsibility of the caller to keep the value sensible.
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 ¶
NewAnonRegister initialises a new register without a name.
func NewRegister ¶
NewRegister creates a new register of a givel size and name, and initialises the value.
func (*Register) 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 (*Register) AddDecimal ¶
AddDecimal adds value to register as though both registers are decimal representations. Returns new carry state, zero, overflow, sign bit information.
func (Register) 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 (Register) IsNegative ¶
IsNegative checks the sign bit of the register
func (*Register) 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 (*Register) LoadFromUint64 ¶
LoadFromUint64 loads a value into the register but using an int type as the value. It is the responsibility of the caller to keep the value sensible.
func (*Register) SubtractDecimal ¶
SubtractDecimal subtracts value to from as though both registers are decimal representations. Returns new carry state, zero, overflow, sign bit information.
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