I have problems with chr rom, i don't know why. I think my cpu emulation is ok (i checked against nestest.log).
Anyway here i go:
My chr c code emulation is like this:
Code: Select all
/* PPU */
PPUMEMMAP g_PpuMemMap;
PPUDATAMEMMAP g_PpuData;
pu8 g_ChrMem;
void MapPpuMem(int from, int to, pReadMemory pfReadMemory, pWriteMemory pfWriteMemory)
{
int f = from >> 10, t = to >> 10;
for (int i = f; i <= t; i++)
{
g_PpuMemMap.pReadPpuMemory[i] = pfReadMemory;
g_PpuMemMap.pWritePpuMemory[i] = pfWriteMemory;
}
}
/* SWAP MEMORY */
void SwapPpuMemory(int where, int to, int bank, int bank_size)
{
pu8 chr_data = g_ChrMem + bank * bank_size;
for (int i = where >> 10; i <= to >> 10; i++)
{
g_PpuData.pPpuDataMemory[i] = chr_data;
chr_data += 0x0400;
}
}
/* MEMORY REDIRECTION*/
u8 ReadPpuMemData(u16 addr)
{
int index = addr >> 10;
u8 data = g_PpuData.pPpuDataMemory[index][addr & 0x03FF];
return data;
}
void WritePpuMemData(u16 addr, u8 data)
{
g_PpuData.pPpuDataMemory[addr >> 10][addr & 0x03FF] = data;
}
u8 ReadPpuMem(u16 addr)
{
u8 data = g_PpuMemMap.pReadPpuMemory[addr >> 10](addr);
return data;
}
void WritePpuMem(u16 addr, u8 data)
{
g_PpuMemMap.pWritePpuMemory[addr >> 10](addr, data);
}
void SetMemoryChrMem(pu8 chr_mem)
{
g_ChrMem = chr_mem;
}
Code: Select all
typedef struct tagPPUMEMMAP
{
pReadMemory pReadPpuMemory[16];
pWriteMemory pWritePpuMemory[16];
} PPUMEMMAP, *PPPUMEMMAP;
typedef struct tagPPUDATAMEMMAP
{
pu8 pPpuDataMemory[16];
} PPUDATAMEMMAP, *PPPUDATAMEMMAP;
void MapPpuMem(int from, int to, pReadMemory pfReadMemory, pWriteMemory pfWriteMemory);
void SwapPpuMemory(int where, int to, int bank, int bank_size);
ReadMemory ReadPpuMemData;
WriteMemory WritePpuMemData;
ReadMemory ReadPpuMem;
WriteMemory WritePpuMem;
void SetMemoryChrMem(pu8 chr_mem);
Code: Select all
typedef unsigned __int8 u8;
typedef u8 * pu8;
typedef unsigned __int16 u16;
typedef u16 * pu16;
typedef void WriteMemory (u16,u8);
typedef WriteMemory * pWriteMemory;
typedef u8 ReadMemory(u16);
typedef ReadMemory * pReadMemory;
Of course i call SetMemoryChrMem() with the appropiate pointer got it from the .nes rom.
I call SwapPpuMemory(0x0000, 0x1FFF, 0, 0x2000); i don't care now about mem swaping since it will get the beggining of chr rom of the ines file. That should be ok (i think).
I just want someone tell me if im doing something wrong, i load nestest.nes and shows me garbage on the screen.
Maybe im doing something wrong in rendering, i doing it pixel by pixel.
Anyway if someone can help me.