started work on sprite rendering

This commit is contained in:
Lauchmelder 2022-03-06 23:31:52 +01:00
parent 6fe829d66c
commit ca729613c7
No known key found for this signature in database
GPG key ID: C2403C69D78F011D
10 changed files with 417 additions and 22 deletions

View file

@ -48,7 +48,17 @@ uint8_t Bus::Tick()
{
controllerPort.Tick();
uint8_t result = cpu.Tick();
uint8_t result = 0x00;
if (DMACyclesLeft == 0)
{
result = cpu.Tick();
}
else
{
DMATick();
result = DMACyclesLeft;
}
// 3 ppu ticks per cpu tick
ppu.Tick();
@ -62,6 +72,25 @@ uint8_t Bus::Tick()
return result;
}
void Bus::DMATick()
{
if (preDMACycles > 0)
{
preDMACycles--;
return;
}
if (DMALatch != 0)
{
Byte data = ReadCPU(((Word)DMAPage << 8) | (0xFF - DMACyclesLeft));
ppu.WriteRegister(0x2004, data);
DMACyclesLeft--;
}
DMALatch = 1 - DMALatch;
}
void Bus::PPUTick()
{
if (ppuClock == 0)
@ -125,6 +154,9 @@ Byte Bus::ReadCPU(Word addr)
{
switch (addr)
{
case 0x4014:
return 0x00;
case 0x4016:
case 0x4017:
return controllerPort.Read(addr);
@ -180,6 +212,12 @@ void Bus::WriteCPU(Word addr, Byte val)
{
switch (addr)
{
case 0x4014:
DMAPage = val;
DMACyclesLeft = 0xFF;
preDMACycles = 1 + (cpu.GetTotalCycles() % 2);
return;
case 0x4016:
controllerPort.Write(addr, val);
break;
@ -201,12 +239,9 @@ void Bus::WritePPU(Word addr, Byte val)
}
else if (0x2000 <= addr && addr < 0x3F00)
{
if(cartridge.MapCIRAM(addr))
if (cartridge.MapCIRAM(addr))
cartridge.WriteVRAM(addr, val);
if (val != 0x00)
volatile int jfkd = 3;
VRAM[addr & 0xFFF] = val;
}
else if (0x3F00 <= addr && addr < 0x4000)