Version: v0.0.0-...-7cd2a6a Latest Latest

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

Go to latest
Published: Oct 5, 2019 License: Apache-2.0 Imports: 3 Imported by: 0




View Source
const (
	// FlagNegative N
	FlagNegative uint8 = 0x80
	// FlagOverflow V
	FlagOverflow uint8 = 0x40
	// FlagUnused U
	FlagUnused uint8 = 0x20
	// FlagBreak B
	FlagBreak uint8 = 0x10
	// FlagDecimal D
	FlagDecimal uint8 = 0x08
	// FlagInterrupt I
	FlagInterrupt uint8 = 0x04
	// FlagZero Z
	FlagZero uint8 = 0x02
	// FlagCarry C
	FlagCarry uint8 = 0x01

	// Addressing Mode Unknown
	AddrModeUnknown = iota
	// Addressing Mode Implied
	// Addressing Mode Immediate
	// Addressing Mode Zero Page
	// Addressing Mode Zero Page with X Offset
	// Addressing Mode Zero Page with Y Offset
	// Addressing Mode Relative
	// Addressing Mode Absolute
	// Addressing Mode Absolute with X Offset
	// Addressing Mode Absolute with Y Offset
	// Addressing Mode Indirect
	// Addressing Mode Indirect X
	// Addressing Mode Indirect Y


This section is empty.


This section is empty.


type Disassembly

type Disassembly struct {
	// Index contains address list
	Index []uint16
	// Op maps addr to opcode name
	Op map[uint16]string
	// Desc maps addr to opcode addressing mode
	Desc map[uint16]string

Disassembly represents disassembly of an 6502 instruction context

func (*Disassembly) Stringify

func (d *Disassembly) Stringify(addr uint16, length int) string

String implementation

type Instruction

type Instruction struct {
	// contains filtered or unexported fields

Instruction contains information of a 6502 opcode

type MG6502

type MG6502 struct {

	// A accumulator
	A uint8
	// X register
	X uint8
	// Y register
	Y uint8
	// Stack pointer register
	SP uint8
	// Program counter register
	PC uint16
	// Flag status register
	FLAG uint8
	// contains filtered or unexported fields

MG6502 emulates a 6502 cpu from software perspective

func NewMG6502

func NewMG6502() *MG6502

NewMG6502 creates and return a 6502 cpu reference

func (*MG6502) Clock

func (cpu *MG6502) Clock()

Clock perform a clock cycle

func (*MG6502) Complete

func (cpu *MG6502) Complete() bool

Complete indicate the current instruction has completed by returning true. This is a utility function to enable "step-by-step" execution, without manually clocking every cycle

func (*MG6502) Disassemble

func (cpu *MG6502) Disassemble(start, end uint16) *Disassembly

Disassemble a range of memory, with keys equivalent to instruction start locations in memory This is the disassembly function. Its workings are not required for emulation. It is merely a convenience function to turn the binary instruction code into human readable form. Its included as part of the emulator because it can take advantage of many of the CPUs internal operations to do this.

func (*MG6502) GetFlag

func (cpu *MG6502) GetFlag(flag uint8) uint8

GetFlag returns the flag

func (*MG6502) IRQ

func (cpu *MG6502) IRQ()

IRQ Interrupt Request Interrupt requests are a complex operation and only happen if the "disable interrupt" flag is unset. IRQs can happen at any time, but you don't want them to be destructive to the operation of the running program. Therefore the current instruction is allowed to finish and then the current program counter is stored on the stack. When the routine that services the interrupt has finished, the status register and program counter can be restored to how they where before it occurred. This is implemented by the "RTI" instruction. Once the IRQ has happened, in a similar way to a reset, a programmable address is read from hard coded location 0xFFFE, which is subsequently set to the program counter.

func (*MG6502) NMI

func (cpu *MG6502) NMI()

NMI Non-Maskable Interrupt A non-maskable interrupt cannot be ignored. It behaves in exactly the same way as a regular IRQ, but reads the new program counter address form location 0xFFFA

func (*MG6502) Reset

func (cpu *MG6502) Reset()

Reset interrupt Force the 6502 into a known state. This is hard-wired inside the CPU. The registers are set to 0x00, the status register is cleared except for unused bit which remains at 1. An absolute address is read from location 0xFFFC which contains a second address that the program counter is set to. This allows the programmer to jump to a known and programmable location in the memory to start executing from. Typically the programmer would set the value at location 0xFFFC at compile time

func (*MG6502) SetFlag

func (cpu *MG6502) SetFlag(flag uint8, v bool)

SetFlag sets the flag

func (*MG6502) SetReader

func (cpu *MG6502) SetReader(reader Reader)

func (*MG6502) SetWriter

func (cpu *MG6502) SetWriter(writer Writer)

type Reader

type Reader interface {
	CpuRead(addr uint16, readonly bool) (data uint8)

Reader defines an interface for CPU to read data from

type Writer

type Writer interface {
	CpuWrite(addr uint16, data uint8)

Writer defines an interface for CPU to write data to

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL