Exemple #1
0
func (n *NES) LoadRom(r rom.ROM) {
	mirror := r.Pages() == 1
	for i, v := range r.ProgramRom() {
		*n.Cartridge[i] = *v
		if mirror {
			*n.Cartridge[i+0x4000] = *v
		}
	}
}
Exemple #2
0
func NewPPU(n *nes.NES, sync chan int, rom rom.ROM, renderer Renderer) *PPU {
	tm := make([]byte, 0x4000)
	m := make([]*byte, 0x4000)

	for i := range m {
		m[i] = &tm[i]
	}

	chrRom := rom.CharRom()
	for i := range chrRom {
		m[i] = chrRom[i]
	}

	// Mirror some Memory
	for i := 0x2000; i < 0x2F00; i++ {
		m[i+0x1000] = m[i]
	}
	for i := 0x3F00; i < 0x3F20; i++ {
		m[i+0x0020] = m[i]
	}

	toam := make([]byte, 0x100)
	oam := make([]*byte, 0x100)

	for i := range oam {
		oam[i] = &toam[i]
	}

	ppu := &PPU{
		nes:       n,
		sync:      sync,
		Memory:    m,
		OAM:       oam,
		renderer:  renderer,
		rom:       rom,
		Registers: &Registers{},
	}

	n.MemoryMap = nes.MemoryMap{
		0x2000: &MappedRegister{func(debug bool) byte { return ppu.PPUCTRL }, func(val byte) { ppu.PPUCTRL = val }},
		0x2001: &MappedRegister{func(debug bool) byte { return ppu.PPUMASK }, func(val byte) { ppu.PPUMASK = val }},
		0x2002: &MappedRegister{ppu.ReadPPUStatus, func(val byte) { ppu.PPUSTATUS = val }},
		0x2003: &MappedRegister{func(debug bool) byte { return ppu.OAMADDR }, func(val byte) { ppu.OAMADDR = val }},
		0x2004: &MappedRegister{ppu.ReadOAMDATA, ppu.WriteOAMDATA},
		0x2005: &MappedRegister{func(debug bool) byte { return ppu.PPUSCROLL }, ppu.WritePPUSCROLL},
		0x2006: &MappedRegister{func(debug bool) byte { return ppu.PPUADDR }, ppu.WritePPUADDR},
		0x2007: &MappedRegister{ppu.ReadPPUDATA, ppu.WritePPUDATA},
		0x4014: &MappedRegister{func(debug bool) byte { return ppu.OAMDMA }, ppu.WriteOAMDMA},
	}

	return ppu
}