i really cant get working the method of "catch up" the ppu or cpu i dont remember, what it says that ppu should run x number of cycles until something that changes the ppu (drawing, etc) happens.
My question is (and i know have been answered to me before and is written in docs) how to make a simple ppu timing routine, i mean without catch up and those things (which are better becouse speed up emulation).
Tell me please if what i know is correctly:
- 1 cpu cycles == 3 ppu cycles
So when an instructions that takes 2 cycles the ppu should run for 2 * 3 = 6 cycles. Is that right?
- a scanline takes 341 ppu cycles which equals 341/3 = 113.6~ cpu cycles. So we have 256 / 3 = 85.3 cpu cycles for scanline pixels and we have more or less 28 cycles for hblank. again is that right?
Now i will write the code how i implement my ppu emu and want someone please tell me which points im failing or someting:
void EmulatePPU(int CurrentCPUCycle)
{
static WORD cc_ppu = 0;
static WORD sl_number = 0;
int i;
BYTE BkPixel, BYTE SprPixel;
for (i = 0; i < CurrentCPUCycle * 3; i++)
{
if (cc_ppu == 340)
{
//what i do here is increment the scanline number
//since ppu cc has reached the end
if (scanline == 242)
{
SetVBlankFlag()
if (bNMIEnable)
SetNMIPending();
}
if (scanline == 261)
scanline = 0;
else
scanline++;
//when it is the last scanline pixel i clock V Counters
ClockVCounters();
//reset ppu cc
cc_ppu = 0;
}
else
{
if (sl_number == 0)
{
ReloadFromPPUTemp(); // -> Counters
Clear2002Bits();
}
else if (sl_number >= 1 && sl_number <= 240)
{
//Render 239 scanlines, here i have a GetBKPixel() func
//that gets the current scanline and ppu cc pixel
//I have here too a GetSprPixel which get the current spr pixel
//and i have a EmulateMultiplexer() func that takes both pixels
//and emulate sprite 0 hit too
if (SprVisible)
SprPixel = GetSprPixel(...);
else
SprPixel = 0;
if (BkVisible)
BkPixel = GetBKPixel(...);
else
BkPixel = 0;
EmulateMultiplexer(BkPixel, SprPixel, ...);
//and a func that clocks the H counters
ClockHCounters();
}
cc_ppu++;
}
}
}
Well its not everything what i do in that EmulatePPU() func, but that gives the idea how im implementing it. Please tell me what is wrong/bad, etc with this method. If someone has a simple method for emulating please let me know.
Thanks in advance.
My question is (and i know have been answered to me before and is written in docs) how to make a simple ppu timing routine, i mean without catch up and those things (which are better becouse speed up emulation).
Tell me please if what i know is correctly:
- 1 cpu cycles == 3 ppu cycles
So when an instructions that takes 2 cycles the ppu should run for 2 * 3 = 6 cycles. Is that right?
- a scanline takes 341 ppu cycles which equals 341/3 = 113.6~ cpu cycles. So we have 256 / 3 = 85.3 cpu cycles for scanline pixels and we have more or less 28 cycles for hblank. again is that right?
Now i will write the code how i implement my ppu emu and want someone please tell me which points im failing or someting:
Code:
void EmulatePPU(int CurrentCPUCycle)
{
static WORD cc_ppu = 0;
static WORD sl_number = 0;
int i;
BYTE BkPixel, BYTE SprPixel;
for (i = 0; i < CurrentCPUCycle * 3; i++)
{
if (cc_ppu == 340)
{
//what i do here is increment the scanline number
//since ppu cc has reached the end
if (scanline == 242)
{
SetVBlankFlag()
if (bNMIEnable)
SetNMIPending();
}
if (scanline == 261)
scanline = 0;
else
scanline++;
//when it is the last scanline pixel i clock V Counters
ClockVCounters();
//reset ppu cc
cc_ppu = 0;
}
else
{
if (sl_number == 0)
{
ReloadFromPPUTemp(); // -> Counters
Clear2002Bits();
}
else if (sl_number >= 1 && sl_number <= 240)
{
//Render 239 scanlines, here i have a GetBKPixel() func
//that gets the current scanline and ppu cc pixel
//I have here too a GetSprPixel which get the current spr pixel
//and i have a EmulateMultiplexer() func that takes both pixels
//and emulate sprite 0 hit too
if (SprVisible)
SprPixel = GetSprPixel(...);
else
SprPixel = 0;
if (BkVisible)
BkPixel = GetBKPixel(...);
else
BkPixel = 0;
EmulateMultiplexer(BkPixel, SprPixel, ...);
//and a func that clocks the H counters
ClockHCounters();
}
cc_ppu++;
}
}
}
Well its not everything what i do in that EmulatePPU() func, but that gives the idea how im implementing it. Please tell me what is wrong/bad, etc with this method. If someone has a simple method for emulating please let me know.
Thanks in advance.