Documentation ¶
Overview ¶
Package bus provides a mappable 16-bit addressable 8-bit data bus for go6502. Different Memory backends can be attached at different base addresses.
Package cpu implements the MOS 6502 processor.
Cpu requires a Bus to read/write 8-bit data to 16-bit addresses.
Cpu also provides a monitor hook, allowing external code to observe and block on instructions before they're executed.
ROM & RAM for go6502; 16-bit address, 8-bit data.
Index ¶
- Constants
- type Bus
- type Cpu
- func (c *Cpu) ADC(in Instruction)
- func (c *Cpu) AND(in Instruction)
- func (c *Cpu) ASL(in Instruction)
- func (c *Cpu) AttachMonitor(m Monitor)
- func (c *Cpu) BCC(in Instruction)
- func (c *Cpu) BCS(in Instruction)
- func (c *Cpu) BEQ(in Instruction)
- func (c *Cpu) BIT(in Instruction)
- func (c *Cpu) BMI(in Instruction)
- func (c *Cpu) BNE(in Instruction)
- func (c *Cpu) BPL(in Instruction)
- func (c *Cpu) BRA(in Instruction)
- func (c *Cpu) BRK(in Instruction)
- func (c *Cpu) BVC(in Instruction)
- func (c *Cpu) BVS(in Instruction)
- func (c *Cpu) CLC(in Instruction)
- func (c *Cpu) CLD(in Instruction)
- func (c *Cpu) CLI(in Instruction)
- func (c *Cpu) CMP(in Instruction)
- func (c *Cpu) CPX(in Instruction)
- func (c *Cpu) CPY(in Instruction)
- func (c *Cpu) DEC(in Instruction)
- func (c *Cpu) DEX(in Instruction)
- func (c *Cpu) DEY(in Instruction)
- func (c *Cpu) EOR(in Instruction)
- func (c *Cpu) INC(in Instruction)
- func (c *Cpu) INX(in Instruction)
- func (c *Cpu) INY(in Instruction)
- func (c *Cpu) JMP(in Instruction)
- func (c *Cpu) JSR(in Instruction)
- func (c *Cpu) LDA(in Instruction)
- func (c *Cpu) LDX(in Instruction)
- func (c *Cpu) LDY(in Instruction)
- func (c *Cpu) LSR(in Instruction)
- func (c *Cpu) NOP(in Instruction)
- func (c *Cpu) ORA(in Instruction)
- func (c *Cpu) PHA(in Instruction)
- func (c *Cpu) PHP(in Instruction)
- func (c *Cpu) PHX(in Instruction)
- func (c *Cpu) PHY(in Instruction)
- func (c *Cpu) PLA(in Instruction)
- func (c *Cpu) PLP(in Instruction)
- func (c *Cpu) PLX(in Instruction)
- func (c *Cpu) PLY(in Instruction)
- func (c *Cpu) ROL(in Instruction)
- func (c *Cpu) ROR(in Instruction)
- func (c *Cpu) RTS(in Instruction)
- func (c *Cpu) Reset()
- func (c *Cpu) SBC(in Instruction)
- func (c *Cpu) SEC(in Instruction)
- func (c *Cpu) SED(in Instruction)
- func (c *Cpu) SEI(in Instruction)
- func (c *Cpu) STA(in Instruction)
- func (c *Cpu) STX(in Instruction)
- func (c *Cpu) STY(in Instruction)
- func (c *Cpu) STZ(in Instruction)
- func (c *Cpu) Shutdown()
- func (c *Cpu) Step() int
- func (c *Cpu) StepCycles(cc int) int
- func (c *Cpu) String() string
- func (c *Cpu) TAX(in Instruction)
- func (c *Cpu) TAY(in Instruction)
- func (c *Cpu) TRB(in Instruction)
- func (c *Cpu) TSB(in Instruction)
- func (c *Cpu) TSX(in Instruction)
- func (c *Cpu) TXA(in Instruction)
- func (c *Cpu) TXS(in Instruction)
- func (c *Cpu) TYA(in Instruction)
- type Instruction
- type Memory
- type Monitor
- type OffsetMemory
- type OpType
- type Ram
- type Rom
Constants ¶
const StackBase = 0x0100
StackBase is the base address of the stack, which begins at StackBase+0xFF and grows downwards towards this address.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is a 16-bit address, 8-bit data bus, which maps reads and writes at different locations to different backend Memory. For example the lower 32K could be RAM, the upper 8KB ROM, and some I/O in the middle.
func (*Bus) Attach ¶
Attach maps a bus address range to a backend Memory implementation, which could be RAM, ROM, I/O device etc.
func (*Bus) Read ¶
Read returns the byte from memory mapped to the given address. e.g. if ROM is mapped to 0xC000, then Read(0xC0FF) returns the byte at 0x00FF in that RAM device.
func (*Bus) Read16 ¶
Read16 returns the 16-bit value stored in little-endian format with the low byte at address, and the high byte at address+1.
func (*Bus) Shutdown ¶
func (b *Bus) Shutdown()
Shutdown tells the address bus a shutdown is occurring, and to pass the message on to subordinates.
type Cpu ¶
type Cpu struct { // Program counter. PC uint16 // Accumulator register. AC byte // X general purpose / index register. X byte // Y general purpose / index register. Y byte // Stack pointer (low byte of 0x0100..0x01FF). SP byte // Status register; carry, zero, interrupt, bcd, brk, _, overflow, sign. SR byte // Bus is the system address bus, mapping 64K of address space to // different back-end devices. Bus *Bus ExitChan chan int // contains filtered or unexported fields }
Cpu represents the internal state of the CPU.
func (*Cpu) AttachMonitor ¶
AttachMonitor sets the given Monitor to observe instructions before they execute, in a blocking manner. This allows for logging, analysis, and interactive debugging.
func (*Cpu) Reset ¶
func (c *Cpu) Reset()
Reset the CPU, emulating triggering the RESB line. From 65C02 manual: All Registers are initialized by software except the Decimal and Interrupt disable mode select bits of the Processor Status Register (P) are initialized by hardware. ... The program counter is loaded with the reset vector from locations FFFC (low byte) and FFFD (high byte).
func (*Cpu) SBC ¶
func (c *Cpu) SBC(in Instruction)
SBC: Subtract memory with borrow from accumulator.
func (*Cpu) Shutdown ¶
func (c *Cpu) Shutdown()
Shutdown tells the CPU to shut-down, and to pass the message on to subordinates such as the address bus.
func (*Cpu) Step ¶
Step will single instruction step the CPU and return the number of machine cycles the instruction took.
func (*Cpu) StepCycles ¶
StepCycles will step the processor until *at least* cycles machine cycles have run. Since Cycle halts on an instruction boundary the actual number of cycles may be greater than requested. Returns the actual number of machine cycles executed.
func (*Cpu) TSX ¶
func (c *Cpu) TSX(in Instruction)
TSX: Transfer stack pointer to index register X.
func (*Cpu) TXS ¶
func (c *Cpu) TXS(in Instruction)
TXS: Transfer index register X to stack pointer.
type Instruction ¶
type Instruction struct { OpType // The single-byte operand, for 2-byte instructions. Op8 uint8 // The 16-bit operand, for 3-byte instructions. Op16 uint16 }
Instruction is an OpType plus its operand. One or both of the operand types will be zero. This is determined by (ot.Bytes - 1) / 8
func ReadInstruction ¶
func ReadInstruction(pc uint16, bus *Bus) Instruction
ReadInstruction reads an instruction from the bus starting at the given address. An instruction may be 1, 2 or 3 bytes long, including its optional 8 or 16 bit operand.
func (Instruction) String ¶
func (in Instruction) String() (s string)
type Memory ¶
Memory is a general interface for reading and writing bytes to and from 16-bit addresses.
type Monitor ¶
type Monitor interface { BeforeExecute(Instruction) Shutdown() }
A Monitor is a blocking observer of instruction execution.
type OffsetMemory ¶
OffsetMemory wraps a Memory object, rewriting read/write addresses by the given offset. This makes it possible to mount memory into a larger address space at a given base address.
func (OffsetMemory) Read ¶
func (om OffsetMemory) Read(a uint16) byte
Read returns a byte from the underlying Memory after rewriting the address using the offset.
func (OffsetMemory) String ¶
func (om OffsetMemory) String() string
func (OffsetMemory) Write ¶
func (om OffsetMemory) Write(a uint16, value byte)
Write stores a byte in the underlying Memory after rewriting the address using the offset.
type OpType ¶
type OpType struct { // Opcode is a byte representing an instruction and its addressing mode. Opcode byte // Bytes is the size of the instruction with its operand. // Opcodes with implicit/null operand are 1 byte. // Opcodes with immediate or zeropage operand are 2 bytes. // Opcodes with adddress operands are 3 bytes. Bytes uint8 // Cycles is the number of times the system clock signal will rise and fall // before the instruction is complete. Cycles uint8 // contains filtered or unexported fields }
OpType represents a 6502 op-code instruction, including the addressing mode encoded into the op-code, but not the operand value following the opcode in memory.
func (OpType) IsAbsolute ¶
type Ram ¶
type Ram [0x8000]byte
Ram (32 KiB)
type Rom ¶
type Rom struct {
// contains filtered or unexported fields
}
A Rom provides read-only memory, with data generally pre-loaded from a file.
func RomFromFile ¶
Create a new ROM, loading the contents from a file. The size of the ROM is determined by the size of the file.
Directories ¶
Path | Synopsis |
---|---|
Package cli provides command line support for go6502.
|
Package cli provides command line support for go6502. |
Package debugger provides an interactive stepping debugger for go6502 with breakpoints on instruction type, register values and memory location.
|
Package debugger provides an interactive stepping debugger for go6502 with breakpoints on instruction type, register values and memory location. |
Emulates 240x320 TFT color display with SPI interface.
|
Emulates 240x320 TFT color display with SPI interface. |
Package SD emulates an SD/MMC card.
|
Package SD emulates an SD/MMC card. |
Package spi implements parts of Serial Peripheral Interface Bus.
|
Package spi implements parts of Serial Peripheral Interface Bus. |
Emulates a 128x32 pixel monochrome OLED display with SPI interface.
|
Emulates a 128x32 pixel monochrome OLED display with SPI interface. |
Package via6522 emulates MOS Technology 6522, or the modern WDC 65C22.
|
Package via6522 emulates MOS Technology 6522, or the modern WDC 65C22. |