diff options
| author | crecher <crecher@crecher.net> | 2026-10-12 22:08:09 +0200 |
|---|---|---|
| committer | crecher <crecher@crecher.net> | 2026-10-12 22:08:09 +0200 |
| commit | 96ff6d8eda2ba434682909f4ff4ce350d78b2273 (patch) | |
| tree | fc1982c54420254ef82c588b742d7ecacfbe7d48 /nes/nes.go | |
| parent | 84801d18b9885c6d70914c67a76d8ac8e3b2b20d (diff) | |
| download | gones-96ff6d8eda2ba434682909f4ff4ce350d78b2273.tar.gz gones-96ff6d8eda2ba434682909f4ff4ce350d78b2273.zip | |
ppu: add background rendering
cmd/gones: add sdl2 frontend
Diffstat (limited to 'nes/nes.go')
| -rw-r--r-- | nes/nes.go | 20 |
1 files changed, 4 insertions, 16 deletions
@@ -23,15 +23,6 @@ func New(c *cart.Cartridge) *Console { return n } -// Step runs one CPU instruction and the PPU dots (3 per CPU cycle) that -// elapse alongside it, firing NMI on a PPUCTRL/vblank edge. PPU state seen -// by bus accesses mid-instruction still lags behind by up to one -// instruction's worth of dots, since the CPU isn't cycle-stepped yet (see -// README: "CPU stall hook and proper IRQ/NMI line (polled between -// instructions)") - timing-sensitive register logic (the $2002 race window, -// NMI edge detection) is implemented to the real dot granularity and is -// exercised directly in the ppu package's tests, but end-to-end precision -// against real games/test ROMs needs that CPU work to land too. func (n *Console) Step() int { cycles := n.CPU.Step() n.cycles += uint64(cycles) @@ -44,13 +35,10 @@ func (n *Console) Step() int { return cycles } +// runs until the PPU finishes a frame, the framebuffer then holds a full picture func (n *Console) StepFrame() { - // 29780 is roughly one frame: - // ~ 1789773 cycles per sec - // ~ 60.1 fps - // 1789773 / 60.1 = 29779.916... - const cyclesPerFrame = 29780 - for done := 0; done < cyclesPerFrame; { - done += n.Step() + frame := n.PPU.Frame + for n.PPU.Frame == frame { + n.Step() } } |