From 780b1e886f6676efedc732b67328f5fbdbe87dc4 Mon Sep 17 00:00:00 2001 From: crecher Date: Mon, 12 Oct 2026 15:44:15 +0200 Subject: waiter waiter more comments please --- nes/bus.go | 21 +++++++++++++++++++-- nes/nes.go | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'nes') diff --git a/nes/bus.go b/nes/bus.go index d9fd521..07bbbf2 100644 --- a/nes/bus.go +++ b/nes/bus.go @@ -1,10 +1,27 @@ package nes +// CPU memory map is: +// Address range | Size | Device +// -------------------------------------------------- +// $0000-$07FF | $0800 | 2 KB internal RAM +// $0800-$0FFF | $0800 | Mirror of $0000-$07FF +// $1000-$17FF | $0800 | Mirror of $0000-$07FF +// $1800-1FFF | $0800 | Mirror of $0000-$07FF +// $2000-2007 | $0008 | PPU registers +// $2008-$3FFF | $1FF8 | Mirrors of $2000-$2007 (repeats every 8 bytes) +// $4000-4017 | $0018 | APU and I/O registers +// $4018-$401F | $0008 | APU and I/O functionality thats normally disabled (CPU test mode) +// $4020-$FFFF | $BFE0 | Unmapped, available for cartridge +// - $6000-$7FFF | $2000 | Usually cartridge RAM (if present) +// - $8000-$FFFF | $8000 | Usually cartridge ROM (if present) + +// wow i put way too much effort into making that table + func (n *Console) Read(addr uint16) uint8 { switch { - case addr < 0x2000: + case addr < 0x2000: // internal RAM and mirrors return n.RAM[addr&0x7FF] - case addr >= 0x4020: + case addr >= 0x4020: // cartridge return n.Cart.Mapper.CPURead(addr) default: return 0 diff --git a/nes/nes.go b/nes/nes.go index 0f2a754..7f36b1a 100644 --- a/nes/nes.go +++ b/nes/nes.go @@ -27,7 +27,11 @@ func (n *Console) Step() int { } func (n *Console) StepFrame() { - const cyclesPerFrame = 29780 // 29780 ~ 1789773 / 60.1 + // 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() } -- cgit v1.2.3