nesdev.com
http://forums.nesdev.com/

Chr Bank problems
http://forums.nesdev.com/viewtopic.php?f=3&t=16109
Page 1 of 1

Author:  Anes [ Sun Jun 18, 2017 11:26 am ]
Post subject:  Chr Bank problems

Hi all, i left emu deving but im taking it again.
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:
/* 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;
}


and the .h file is like:

Code:
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);


Where the mem pointers are defined as:
Code:
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;


pu8 is a pointer to char.
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.

Author:  Anes [ Sun Jun 18, 2017 6:25 pm ]
Post subject:  Re: Chr Bank problems

I found the error. As i suspected wasn't in this code. Anyway i wanted to know if it was right.
It seems it's ok.

Thxs in advance.

Author:  AWJ [ Mon Jun 19, 2017 3:15 am ]
Post subject:  Re: Chr Bank problems

You need some way to distinguish between RAM and ROM. ROM shouldn't change when software writes to it through the PPU.

Author:  Anes [ Mon Jun 19, 2017 4:16 am ]
Post subject:  Re: Chr Bank problems

Yes, that's right i know. I only wrote it cos i started from scratch.

Im hanged now in nestest "(indirect,X)" test thats throws me error 0x59 -> "STA didn't store the data where it was supposed to".
I have to clear that error :x I think it should be easy. I did it before, why not now?

Author:  Dwedit [ Mon Jun 19, 2017 5:33 am ]
Post subject:  Re: Chr Bank problems

Addresses defined as being in the zero page will generally stay in the zero page, even if they overflow to 0x100 after adding X or Y.
Full 16-bit addresses that aren't defined as being in the zero page will carry over to 0x100, even if their value is under 0x100.

Author:  Anes [ Mon Jun 19, 2017 5:42 am ]
Post subject:  Re: Chr Bank problems

I have just fixed my cpu core with the thing you have just said.
nestest.nes throws me all OK now, but im worried about Blargg's instruction test now.
I run the rom singles and the only one that gives me OK is implied... WTF

Author:  Dwedit [ Mon Jun 19, 2017 5:56 am ]
Post subject:  Re: Chr Bank problems

zpg,x and zpg,y and (zpg,x) will wrap back to the zero page when doing the addition.
abs,x and abs,y will not, since they are full 16-bit values.
(zpg),y has one addition step where it adds 1 to read the second value of the pointer, that will wrap back to 00 if the value was FF. The part that adds Y is full 16-bit math and does not wrap back anywhere.

Author:  Anes [ Mon Jun 19, 2017 6:19 am ]
Post subject:  Re: Chr Bank problems

Im aware of that Dwedit. My cpu is ok, what i forgot was that Blargg's rom singles also test the unofficial opcodes. Thing im not emulating right now.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/