package nes import ( "crecher.net/gones/v2/cart" "crecher.net/gones/v2/cpu" "crecher.net/gones/v2/ppu" ) type Console struct { CPU *cpu.CPU PPU *ppu.PPU Cart *cart.Cartridge RAM [0x800]uint8 // APU, controllers once they exist cycles uint64 } func New(c *cart.Cartridge) *Console { n := &Console{Cart: c} n.PPU = ppu.New(c.Mapper, c.Mirroring) n.CPU = cpu.NewCPU(n) n.CPU.Reset() return n } func (n *Console) Step() int { cycles := n.CPU.Step() n.cycles += uint64(cycles) for i := 0; i < cycles*3; i++ { n.PPU.Tick() if n.PPU.PollNMI() { n.CPU.NMI() } } return cycles } // runs until the PPU finishes a frame, the framebuffer then holds a full picture func (n *Console) StepFrame() { frame := n.PPU.Frame for n.PPU.Frame == frame { n.Step() } }