Documentation ¶
Index ¶
- func TimeTrack(start time.Time)
- type AddressingMode
- type Bus
- func (b *Bus) CheckForNestestErrors()
- func (b *Bus) Clock()
- func (b *Bus) CpuRead(addr uint16) byte
- func (b *Bus) CpuWrite(addr uint16, data byte)
- func (b *Bus) DrawDebugPanel()
- func (b *Bus) InsertCartridge(cart *Cartridge)
- func (b *Bus) Load(filepath string)
- func (b *Bus) LoadBytes(rom []byte)
- func (b *Bus) Reset()
- func (b *Bus) Run()
- type Cartridge
- type CartridgeHeader
- type Controller
- type Cpu6502
- type Display
- func (d *Display) DrawDebugPixel(x, y int, c color.RGBA)
- func (d *Display) DrawDebugRGBA(x, y int, img *image.RGBA)
- func (d *Display) DrawPixel(x, y int, c color.RGBA)
- func (d *Display) UpdateScreen()
- func (d *Display) WriteControllerDebugString(t string)
- func (d *Display) WriteInstDebugString(t string)
- func (d *Display) WriteRegDebugString(t string)
- type Instruction
- type Mapper
- type Mapper000
- type MirrorMode
- type Ppu
- type PpuLoopyReg
- type PpuReg
- type PpuRegFlag
- type SF6502
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TimeTrack ¶
Function time tracking thanks to: https://stackoverflow.com/questions/45766572/is-there-an-efficient-way-to-calculate-execution-time-in-golang
Types ¶
type AddressingMode ¶
type AddressingMode int
const ( IMP AddressingMode = iota IMM REL ZP0 ZPX ZPY ABS ABX ABY IND IZX IZY )
type Bus ¶
type Bus struct { Cpu *Cpu6502 // NES CPU. Ppu *Ppu // Picture processing unit. Ram [8 * 1024]byte // 8KiB RAM. Cart *Cartridge // NES Cartridge. Controller [2]*Controller // NES Controller. ControllerState [2]byte // 8 bit shifter representing each button's state Disp *Display ClockCount int // contains filtered or unexported fields }
Main bus used by the CPU.
func (*Bus) CheckForNestestErrors ¶
func (b *Bus) CheckForNestestErrors()
Used for testing the emulator with nestest.
func (*Bus) DrawDebugPanel ¶
func (b *Bus) DrawDebugPanel()
TODO: move this out of Bus, and into main or something. Also, rewrite this.
func (*Bus) InsertCartridge ¶
Load a cartridge to the NES. The cartridge is connected to both the CPU and PPU.
type Cartridge ¶
type Cartridge struct {
// contains filtered or unexported fields
}
NES Cartridge. Connected to both main bus and PPU bus. The cartridges consist of program (PRG) memory and character (CHR) memory.
func NewCartridge ¶
Creates a new NES Cartridge using the file at the given path.
type CartridgeHeader ¶
type CartridgeHeader struct { Name [4]byte // Constant "NES" followed by MS-DOS end of file PrgRomChunks byte // Program memory size in 16KB chunks ChrRomChunks byte // Character memory size in 8KB chunks Mapper1 byte // Flags 6 Mapper2 byte // Flags 7 PrgRamSize byte // Flags 8 TvSystem1 byte // Flags 9 TvSystem2 byte // Flags 10 Unused [5]byte // Unused padding }
iNES file header reference: https://wiki.nesdev.com/w/index.php/INES
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
func NewController ¶
func NewController() *Controller
func (*Controller) GetState ¶
func (c *Controller) GetState() byte
GetState returns a byte, with each bit representing the state of a button on the controller.
type Cpu6502 ¶
type Cpu6502 struct { Pc uint16 // Program Counter Sp byte // Stack Pointer: low 8 bits of next free location on stack. A byte // Accumulator Register X byte // X Register Y byte // Y Register Status byte // Processor Status Flags // Internal variables Cycles byte // Remaining cycles for current insturction Opcode byte // Opcode representing next instruction to be executed AddrAbs uint16 // Set by addressing mode functions, used by instructions AddrRel uint16 // Relative displacement address used for branching Fetched byte // Byte of memory used by CPU instructions CycleCount uint32 // Total # of cycles executed by the CPU // Used for printing disassembly in debug mode Disassembly map[uint16]string PrevInstructions [15]string PrevInstIdx int InstLookup [16 * 16]Instruction // Instruction operation lookup AddrModeFns map[AddressingMode]func() byte // Addressing mode name -> function map Logger *log.Logger // CPU logging // contains filtered or unexported fields }
func NewCpu6502 ¶
func (*Cpu6502) ConnectBus ¶
Connect the CPU to a 16-bit address bus.
func (*Cpu6502) Disassemble ¶
Disassemble the loaded 6502 program into human-readable CPU instructions mapped to their respective memory address.
Much help from https://github.com/OneLoneCoder/olcNES
type Display ¶
type Display struct {
// contains filtered or unexported fields
}
func NewDisplay ¶
func (*Display) DrawDebugRGBA ¶
DrawDebugRGBA draws a given image to an (x, y) offset within the debug image.
func (*Display) UpdateScreen ¶
func (d *Display) UpdateScreen()
UpdateScreen updates both the game display and the debug display using the display's current image.RGBA representation of each.
func (*Display) WriteControllerDebugString ¶
Write a string of text to the controller status section of the debug panel.
func (*Display) WriteInstDebugString ¶
Write a string of text to the isntruction disassembly section of the debug panel.
func (*Display) WriteRegDebugString ¶
Write a string of text to the CPU register section of the debug panel.
type Instruction ¶
type Instruction struct { Name string Execute func() byte AddrMode AddressingMode Cycles byte }
////////////////////////////////////////////////////////////// Instructions
type Mapper ¶
type Mapper interface {
// contains filtered or unexported methods
}
Mapper functions return whether or not the given address was successfully mapped.
type Mapper000 ¶
func NewMapper000 ¶
type MirrorMode ¶
type MirrorMode int
type Ppu ¶
type Ppu struct { Cart *Cartridge // contains filtered or unexported fields }
References: http://wiki.nesdev.com/w/index.php/PPU_registers https://www.youtube.com/watch?v=xdzOvpYPmGE (javidx9)
func (*Ppu) Clock ¶
func (p *Ppu) Clock()
PPU clock cycle. 1 frame = 262 scanlines (-1 - 260) 1 scanline = 341 PPU clock cycles (0 - 340)
func (*Ppu) ConnectCartridge ¶
func (*Ppu) ConnectDisplay ¶
type PpuLoopyReg ¶
type PpuLoopyReg uint16
Loopy registers are 15 bit internal PPU registers used for implementing scrolling. Loopy register layout:
yyy NN YYYYY XXXXX yyy - fine Y scroll NN - nametable select YYYYY - coarse Y scroll XXXXX - coarse X scroll
type PpuRegFlag ¶
type PpuRegFlag byte