basic ppu background rendering
This commit is contained in:
parent
f9f401c6c0
commit
aef80e42fb
21 changed files with 468 additions and 41 deletions
40
src/Bus.cpp
40
src/Bus.cpp
|
@ -6,16 +6,17 @@
|
|||
#include "controllers/StandardController.hpp"
|
||||
|
||||
Bus::Bus(Screen* screen) :
|
||||
cpu(this), ppu(this, screen), cartridge(this)
|
||||
cpu(this), ppu(this, screen), apu(this), cartridge(this)
|
||||
{
|
||||
LOG_CORE_INFO("Allocating RAM");
|
||||
RAM = std::vector<Byte>(0x800);
|
||||
|
||||
LOG_CORE_INFO("Allocating VRAM");
|
||||
VRAM = std::vector<Byte>(0x800);
|
||||
palettes = std::vector<Byte>(0x20, 0);
|
||||
|
||||
LOG_CORE_INFO("Inserting cartridge");
|
||||
cartridge.Load("roms/donkeykong.nes");
|
||||
cartridge.Load("roms/mario.nes");
|
||||
|
||||
LOG_CORE_INFO("Powering up CPU");
|
||||
cpu.Powerup();
|
||||
|
@ -23,6 +24,9 @@ Bus::Bus(Screen* screen) :
|
|||
LOG_CORE_INFO("Powering up PPU");
|
||||
ppu.Powerup();
|
||||
|
||||
LOG_CORE_INFO("Powering up APU");
|
||||
apu.Powerup();
|
||||
|
||||
controllerPort.PlugInController<StandardController>(0);
|
||||
}
|
||||
|
||||
|
@ -30,12 +34,14 @@ void Bus::Reboot()
|
|||
{
|
||||
cpu.Powerup();
|
||||
ppu.Powerup();
|
||||
apu.Powerup();
|
||||
}
|
||||
|
||||
void Bus::Reset()
|
||||
{
|
||||
cpu.Reset();
|
||||
ppu.Reset();
|
||||
apu.Reset();
|
||||
}
|
||||
|
||||
uint8_t Bus::Tick()
|
||||
|
@ -49,13 +55,20 @@ uint8_t Bus::Tick()
|
|||
ppu.Tick();
|
||||
ppu.Tick();
|
||||
|
||||
// APU is only ticked every 2 cycles, but that logic
|
||||
// is handled inside the APU class
|
||||
apu.Tick();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Bus::PPUTick()
|
||||
{
|
||||
if (ppuClock == 0)
|
||||
{
|
||||
cpu.Tick();
|
||||
apu.Tick();
|
||||
}
|
||||
|
||||
ppu.Tick();
|
||||
ppuClock = (ppuClock + 1) % 3;
|
||||
|
@ -129,13 +142,20 @@ Byte Bus::ReadPPU(Word addr)
|
|||
{
|
||||
return cartridge.ReadPPU(addr);
|
||||
}
|
||||
else if(0x2000 <= addr && addr < 0x4000)
|
||||
else if(0x2000 <= addr && addr < 0x3F00)
|
||||
{
|
||||
if (cartridge.MapCIRAM(addr))
|
||||
return cartridge.ReadVRAM(addr);
|
||||
|
||||
return VRAM[addr & 0xFFF];
|
||||
}
|
||||
else if (0x3F00 <= addr && addr < 0x4000)
|
||||
{
|
||||
if ((addr & 0x3) == 0x00)
|
||||
addr &= 0xF;
|
||||
|
||||
return palettes[addr & 0x1F];
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
@ -159,9 +179,12 @@ void Bus::WriteCPU(Word addr, Byte val)
|
|||
switch (addr)
|
||||
{
|
||||
case 0x4016:
|
||||
case 0x4017:
|
||||
controllerPort.Write(addr, val);
|
||||
break;
|
||||
|
||||
case 0x4017:
|
||||
apu.WriteRegister(addr, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -174,11 +197,18 @@ void Bus::WritePPU(Word addr, Byte val)
|
|||
{
|
||||
cartridge.WritePPU(addr, val);
|
||||
}
|
||||
else if (0x2000 <= addr && addr < 0x4000)
|
||||
else if (0x2000 <= addr && addr < 0x3F00)
|
||||
{
|
||||
if(cartridge.MapCIRAM(addr))
|
||||
cartridge.WriteVRAM(addr, val);
|
||||
|
||||
VRAM[addr & 0xFFF] = val;
|
||||
}
|
||||
else if (0x3F00 <= addr && addr < 0x4000)
|
||||
{
|
||||
if ((addr & 0x3) == 0x00)
|
||||
addr &= 0xF;
|
||||
|
||||
palettes[addr & 0x1F] = val;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue