Documentation ¶
Overview ¶
Package m65go2 simulates the MOS 6502 CPU
Index ¶
- Constants
- func SamePage(addr1 uint16, addr2 uint16) bool
- type BadOpCodeError
- type BasicMemory
- type BrkOpCodeError
- type Index
- type Instruction
- type InstructionStatus
- type InstructionTable
- type Interrupt
- type M6502
- func (cpu *M6502) Adc(address uint16)
- func (cpu *M6502) Alr(address uint16)
- func (cpu *M6502) Anc(address uint16)
- func (cpu *M6502) And(address uint16)
- func (cpu *M6502) Arr(address uint16)
- func (cpu *M6502) Asl(address uint16)
- func (cpu *M6502) AslA()
- func (cpu *M6502) Axs(address uint16)
- func (cpu *M6502) Bcc(address uint16, status *InstructionStatus)
- func (cpu *M6502) Bcs(address uint16, status *InstructionStatus)
- func (cpu *M6502) Beq(address uint16, status *InstructionStatus)
- func (cpu *M6502) Bit(address uint16)
- func (cpu *M6502) Bmi(address uint16, status *InstructionStatus)
- func (cpu *M6502) Bne(address uint16, status *InstructionStatus)
- func (cpu *M6502) Bpl(address uint16, status *InstructionStatus)
- func (cpu *M6502) Brk()
- func (cpu *M6502) Bvc(address uint16, status *InstructionStatus)
- func (cpu *M6502) Bvs(address uint16, status *InstructionStatus)
- func (cpu *M6502) Clc()
- func (cpu *M6502) Cld()
- func (cpu *M6502) Cli()
- func (cpu *M6502) Clv()
- func (cpu *M6502) Cmp(address uint16)
- func (cpu *M6502) Cpx(address uint16)
- func (cpu *M6502) Cpy(address uint16)
- func (cpu *M6502) Dcp(address uint16)
- func (cpu *M6502) Dec(address uint16)
- func (cpu *M6502) Dex()
- func (cpu *M6502) Dey()
- func (cpu *M6502) DisableDecimalMode()
- func (cpu *M6502) EnableDecode()
- func (cpu *M6502) Eor(address uint16)
- func (cpu *M6502) Execute() (cycles uint16, error error)
- func (cpu *M6502) GetInterrupt(which Interrupt) (state bool)
- func (cpu *M6502) Inc(address uint16)
- func (cpu *M6502) IndexToRegister(which Index) uint8
- func (cpu *M6502) Interrupt(which Interrupt, state bool)
- func (cpu *M6502) InterruptLine(which Interrupt) func(state bool)
- func (cpu *M6502) Inx()
- func (cpu *M6502) Iny()
- func (cpu *M6502) Isb(address uint16)
- func (cpu *M6502) Jmp(address uint16)
- func (cpu *M6502) Jsr(address uint16)
- func (cpu *M6502) Lax(address uint16)
- func (cpu *M6502) Lda(address uint16)
- func (cpu *M6502) Ldx(address uint16)
- func (cpu *M6502) Ldy(address uint16)
- func (cpu *M6502) Lsr(address uint16)
- func (cpu *M6502) LsrA()
- func (cpu *M6502) Nop()
- func (cpu *M6502) NopAddress(address uint16)
- func (cpu *M6502) Ora(address uint16)
- func (cpu *M6502) PerformInterrupts() (cycles uint16)
- func (cpu *M6502) PerformIrq()
- func (cpu *M6502) PerformNmi()
- func (cpu *M6502) PerformRst()
- func (cpu *M6502) Pha()
- func (cpu *M6502) Php()
- func (cpu *M6502) Pla()
- func (cpu *M6502) Plp()
- func (cpu *M6502) Reset()
- func (cpu *M6502) Rla(address uint16)
- func (cpu *M6502) Rol(address uint16)
- func (cpu *M6502) RolA()
- func (cpu *M6502) Ror(address uint16)
- func (cpu *M6502) RorA()
- func (cpu *M6502) Rra(address uint16)
- func (cpu *M6502) Rti()
- func (cpu *M6502) Rts()
- func (cpu *M6502) Run() (err error)
- func (cpu *M6502) Sax(address uint16)
- func (cpu *M6502) Sbc(address uint16)
- func (cpu *M6502) Sec()
- func (cpu *M6502) Sed()
- func (cpu *M6502) Sei()
- func (cpu *M6502) Shx(address uint16)
- func (cpu *M6502) Shy(address uint16)
- func (cpu *M6502) Slo(address uint16)
- func (cpu *M6502) Sre(address uint16)
- func (cpu *M6502) Sta(address uint16)
- func (cpu *M6502) Stx(address uint16)
- func (cpu *M6502) Sty(address uint16)
- func (cpu *M6502) Tax()
- func (cpu *M6502) Tay()
- func (cpu *M6502) ToggleDecode() bool
- func (cpu *M6502) Tsx()
- func (cpu *M6502) Txa()
- func (cpu *M6502) Txs()
- func (cpu *M6502) Tya()
- type Memory
- type OpCode
- type Registers
- type Status
Constants ¶
const (
DefaultMemorySize uint32 = 65536
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BadOpCodeError ¶
type BadOpCodeError OpCode
Error type used to indicate that the CPU attempted to execute an invalid opcode
func (BadOpCodeError) Error ¶
func (b BadOpCodeError) Error() string
type BasicMemory ¶
Represents the 6502 CPU's memory using a static array of uint8's.
func NewBasicMemory ¶
func NewBasicMemory(size uint32) *BasicMemory
Returns a pointer to a new BasicMemory with all memory initialized to zero.
func (*BasicMemory) Fetch ¶
func (mem *BasicMemory) Fetch(address uint16) (value uint8)
Returns the value stored at the given memory address
type BrkOpCodeError ¶
type BrkOpCodeError OpCode
Error type used to indicate that the CPU executed a BRK instruction
func (BrkOpCodeError) Error ¶
func (b BrkOpCodeError) Error() string
type Instruction ¶
type Instruction struct { Mneumonic string OpCode OpCode Exec func(*M6502) (status InstructionStatus) }
Represents an instruction for the 6502 CPU. The Exec field implements the instruction and returns the total clock cycles to be consumed by the instruction.
type InstructionStatus ¶
type InstructionStatus uint16
const ( PageCross InstructionStatus = 1 << iota Branched )
type InstructionTable ¶
type InstructionTable struct {
// contains filtered or unexported fields
}
Stores instructions understood by the 6502 CPU, indexed by opcode.
func NewInstructionTable ¶
func NewInstructionTable() InstructionTable
Returns a new, empty InstructionTable
func (InstructionTable) AddInstruction ¶
func (instructions InstructionTable) AddInstruction(inst *Instruction)
Adds an instruction to the InstructionTable
func (InstructionTable) Execute ¶
func (instructions InstructionTable) Execute(cpu *M6502, opcode OpCode) (cycles uint16)
Executes an instruction in the InstructionTable, returns number of cycles taken to execute
func (InstructionTable) InitInstructions ¶
func (instructions InstructionTable) InitInstructions()
Adds the 6502 CPU's instruction set to the InstructionTable.
func (InstructionTable) RemoveInstruction ¶
func (instructions InstructionTable) RemoveInstruction(opcode OpCode)
Removes any instruction with the given opcode
type M6502 ¶
type M6502 struct { Nmi bool Irq bool Rst bool Registers Registers `json:"M6502Registers"` Memory Memory `json:"M6502Memory"` Instructions InstructionTable `json:"-"` // contains filtered or unexported fields }
Represents the 6502 CPU.
func (*M6502) Adc ¶
This instruction adds the contents of a memory location to the accumulator together with the carry bit. If overflow occurs the carry bit is set, this enables multiple byte addition to be performed.
C Carry Flag Set if overflow in bit 7 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Set if sign bit is incorrect N Negative Flag Set if bit 7 set
func (*M6502) And ¶
A logical AND is performed, bit by bit, on the accumulator contents using the contents of a byte of memory.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 set
func (*M6502) Asl ¶
This operation shifts all the bits of the memory contents one bit left. Bit 0 is set to 0 and bit 7 is placed in the carry flag. The effect of this operation is to multiply the memory contents by 2 (ignoring 2's complement considerations), setting the carry if the result will not fit in 8 bits.
C Carry Flag Set to contents of old bit 7 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) AslA ¶
func (cpu *M6502) AslA()
This operation shifts all the bits of the accumulator one bit left. Bit 0 is set to 0 and bit 7 is placed in the carry flag. The effect of this operation is to multiply the memory contents by 2 (ignoring 2's complement considerations), setting the carry if the result will not fit in 8 bits.
C Carry Flag Set to contents of old bit 7 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Bcc ¶
func (cpu *M6502) Bcc(address uint16, status *InstructionStatus)
If the carry flag is clear then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Bcs ¶
func (cpu *M6502) Bcs(address uint16, status *InstructionStatus)
If the carry flag is set then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Beq ¶
func (cpu *M6502) Beq(address uint16, status *InstructionStatus)
If the zero flag is set then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Bit ¶
This instructions is used to test if one or more bits are set in a target memory location. The mask pattern in A is ANDed with the value in memory to set or clear the zero flag, but the result is not kept. Bits 7 and 6 of the value from memory are copied into the N and V flags.
C Carry Flag Not affected Z Zero Flag Set if the result if the AND is zero I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Set to bit 6 of the memory value N Negative Flag Set to bit 7 of the memory value
func (*M6502) Bmi ¶
func (cpu *M6502) Bmi(address uint16, status *InstructionStatus)
If the negative flag is set then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Bne ¶
func (cpu *M6502) Bne(address uint16, status *InstructionStatus)
If the zero flag is clear then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Bpl ¶
func (cpu *M6502) Bpl(address uint16, status *InstructionStatus)
If the negative flag is clear then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Brk ¶
func (cpu *M6502) Brk()
The BRK instruction forces the generation of an interrupt request. The program counter and processor status are pushed on the stack then the IRQ interrupt vector at $FFFE/F is loaded into the PC and the break flag in the status set to one.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Set to 1 V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Bvc ¶
func (cpu *M6502) Bvc(address uint16, status *InstructionStatus)
If the overflow flag is clear then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Bvs ¶
func (cpu *M6502) Bvs(address uint16, status *InstructionStatus)
If the overflow flag is set then add the relative displacement to the program counter to cause a branch to a new location.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Clc ¶
func (cpu *M6502) Clc()
Set the carry flag to zero.
C Carry Flag Set to 0 Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Cld ¶
func (cpu *M6502) Cld()
Set the decimal mode flag to zero.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Set to 0 B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Cli ¶
func (cpu *M6502) Cli()
Clears the interrupt disable flag allowing normal interrupt requests to be serviced.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Set to 0 D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Clv ¶
func (cpu *M6502) Clv()
Clears the interrupt disable flag allowing normal interrupt requests to be serviced.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Set to 0 N Negative Flag Not affected
func (*M6502) Cmp ¶
This instruction compares the contents of the accumulator with another memory held value and sets the zero and carry flags as appropriate.
C Carry Flag Set if A >= M Z Zero Flag Set if A = M I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Cpx ¶
This instruction compares the contents of the X register with another memory held value and sets the zero and carry flags as appropriate.
C Carry Flag Set if X >= M Z Zero Flag Set if X = M I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Cpy ¶
This instruction compares the contents of the Y register with another memory held value and sets the zero and carry flags as appropriate.
C Carry Flag Set if Y >= M Z Zero Flag Set if Y = M I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Dec ¶
Subtracts one from the value held at a specified memory location setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if result is zero I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Dex ¶
func (cpu *M6502) Dex()
Subtracts one from the X register setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if X is zero I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of X is set
func (*M6502) Dey ¶
func (cpu *M6502) Dey()
Subtracts one from the Y register setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if Y is zero I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of Y is set
func (*M6502) DisableDecimalMode ¶
func (cpu *M6502) DisableDecimalMode()
func (*M6502) EnableDecode ¶
func (cpu *M6502) EnableDecode()
func (*M6502) Eor ¶
An exclusive OR is performed, bit by bit, on the accumulator contents using the contents of a byte of memory.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 set
func (*M6502) Execute ¶
Executes the instruction pointed to by the PC register in the number of cycles as returned by the instruction's Exec function. Returns the number of cycles executed and any error (such as BadOpCodeError).
func (*M6502) GetInterrupt ¶
func (*M6502) Inc ¶
Adds one to the value held at a specified memory location setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if result is zero I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) IndexToRegister ¶
func (*M6502) InterruptLine ¶
func (*M6502) Inx ¶
func (cpu *M6502) Inx()
Adds one to the X register setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if X is zero I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of X is set
func (*M6502) Iny ¶
func (cpu *M6502) Iny()
Adds one to the Y register setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if Y is zero I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of Y is set
func (*M6502) Jmp ¶
Sets the program counter to the address specified by the operand.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Jsr ¶
The JSR instruction pushes the address (minus one) of the return point on to the stack and then sets the program counter to the target memory address.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Lax ¶
Unofficial
Loads a byte of memory into the accumulator and X setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of A is set
func (*M6502) Lda ¶
Loads a byte of memory into the accumulator setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of A is set
func (*M6502) Ldx ¶
Loads a byte of memory into the X register setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if X = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of X is set
func (*M6502) Ldy ¶
Loads a byte of memory into the Y register setting the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if Y = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of Y is set
func (*M6502) Lsr ¶
Each of the bits in M is shift one place to the right. The bit that was in bit 0 is shifted into the carry flag. Bit 7 is set to zero.
C Carry Flag Set to contents of old bit 0 Z Zero Flag Set if result = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) LsrA ¶
func (cpu *M6502) LsrA()
Each of the bits in A is shift one place to the right. The bit that was in bit 0 is shifted into the carry flag. Bit 7 is set to zero.
C Carry Flag Set to contents of old bit 0 Z Zero Flag Set if result = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Nop ¶
func (cpu *M6502) Nop()
The NOP instruction causes no changes to the processor other than the normal incrementing of the program counter to the next instruction.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) NopAddress ¶
Unofficial
The NOP instruction causes no changes to the processor other than the normal incrementing of the program counter to the next instruction.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Ora ¶
An inclusive OR is performed, bit by bit, on the accumulator contents using the contents of a byte of memory.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 set
func (*M6502) PerformInterrupts ¶
func (*M6502) PerformIrq ¶
func (cpu *M6502) PerformIrq()
func (*M6502) PerformNmi ¶
func (cpu *M6502) PerformNmi()
func (*M6502) PerformRst ¶
func (cpu *M6502) PerformRst()
func (*M6502) Pha ¶
func (cpu *M6502) Pha()
Pushes a copy of the accumulator on to the stack.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Php ¶
func (cpu *M6502) Php()
Pushes a copy of the status flags on to the stack.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Pla ¶
func (cpu *M6502) Pla()
Pulls an 8 bit value from the stack and into the accumulator. The zero and negative flags are set as appropriate.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of A is set
func (*M6502) Plp ¶
func (cpu *M6502) Plp()
Pulls an 8 bit value from the stack and into the processor flags. The flags will take on new states as determined by the value pulled.
C Carry Flag Set from stack Z Zero Flag Set from stack I Interrupt Disable Set from stack D Decimal Mode Flag Set from stack B Break Command Set from stack V Overflow Flag Set from stack N Negative Flag Set from stack
func (*M6502) Reset ¶
func (cpu *M6502) Reset()
Resets the CPU by resetting both the registers and memory.
func (*M6502) Rol ¶
Move each of the bits in A one place to the left. Bit 0 is filled with the current value of the carry flag whilst the old bit 7 becomes the new carry flag value.
C Carry Flag Set to contents of old bit 7 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) RolA ¶
func (cpu *M6502) RolA()
Move each of the bits in A one place to the left. Bit 0 is filled with the current value of the carry flag whilst the old bit 7 becomes the new carry flag value.
C Carry Flag Set to contents of old bit 7 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Ror ¶
Move each of the bits in M one place to the right. Bit 7 is filled with the current value of the carry flag whilst the old bit 0 becomes the new carry flag value.
C Carry Flag Set to contents of old bit 0 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) RorA ¶
func (cpu *M6502) RorA()
Move each of the bits in A one place to the right. Bit 7 is filled with the current value of the carry flag whilst the old bit 0 becomes the new carry flag value.
C Carry Flag Set to contents of old bit 0 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of the result is set
func (*M6502) Rti ¶
func (cpu *M6502) Rti()
The RTI instruction is used at the end of an interrupt processing routine. It pulls the processor flags from the stack followed by the program counter.
C Carry Flag Set from stack Z Zero Flag Set from stack I Interrupt Disable Set from stack D Decimal Mode Flag Set from stack B Break Command Set from stack V Overflow Flag Set from stack N Negative Flag Set from stack
func (*M6502) Rts ¶
func (cpu *M6502) Rts()
The RTS instruction is used at the end of a subroutine to return to the calling routine. It pulls the program counter (minus one) from the stack.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Sbc ¶
This instruction subtracts the contents of a memory location to the accumulator together with the not of the carry bit. If overflow occurs the carry bit is clear, this enables multiple byte subtraction to be performed.
C Carry Flag Clear if overflow in bit 7 Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Set if sign bit is incorrect N Negative Flag Set if bit 7 set
func (*M6502) Sec ¶
func (cpu *M6502) Sec()
Set the carry flag to one.
C Carry Flag Set to 1 Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Sed ¶
func (cpu *M6502) Sed()
Set the decimal mode flag to one.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Set to 1 B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Sei ¶
func (cpu *M6502) Sei()
Set the interrupt disable flag to one.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Set to 1 D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Sta ¶
Stores the contents of the accumulator into memory.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Stx ¶
Stores the contents of the X register into memory.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Sty ¶
Stores the contents of the Y register into memory.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Tax ¶
func (cpu *M6502) Tax()
Copies the current contents of the accumulator into the X register and sets the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if X = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of X is set
func (*M6502) Tay ¶
func (cpu *M6502) Tay()
Copies the current contents of the accumulator into the Y register and sets the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if Y = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of Y is set
func (*M6502) ToggleDecode ¶
func (*M6502) Tsx ¶
func (cpu *M6502) Tsx()
Copies the current contents of the stack register into the X register and sets the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if X = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of X is set
func (*M6502) Txa ¶
func (cpu *M6502) Txa()
Copies the current contents of the X register into the accumulator and sets the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of A is set
func (*M6502) Txs ¶
func (cpu *M6502) Txs()
Copies the current contents of the X register into the stack register.
C Carry Flag Not affected Z Zero Flag Not affected I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Not affected
func (*M6502) Tya ¶
func (cpu *M6502) Tya()
Copies the current contents of the Y register into the accumulator and sets the zero and negative flags as appropriate.
C Carry Flag Not affected Z Zero Flag Set if A = 0 I Interrupt Disable Not affected D Decimal Mode Flag Not affected B Break Command Not affected V Overflow Flag Not affected N Negative Flag Set if bit 7 of A is set
type Memory ¶
type Memory interface { Reset() // Sets all memory locations to zero Fetch(address uint16) (value uint8) // Returns the value stored at the given memory address Store(address uint16, value uint8) (oldValue uint8) // Stores the value at the given memory address }
Represents the RAM memory available to the 6502 CPU. Stores 8-bit values using a 16-bit address for a total of 65,536 possible 8-bit values.
type Registers ¶
type Registers struct { A uint8 // accumulator X uint8 // index register X Y uint8 // index register Y P Status // processor status SP uint8 // stack pointer PC uint16 // program counter }
The 6502's registers, all registers are 8-bit values except for PC which is 16-bits.
func NewRegisters ¶
func NewRegisters() (reg Registers)
Creates a new set of Registers. All registers are initialized to 0.