It is currently Fri Dec 15, 2017 10:33 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Chr Bank problems
PostPosted: Sun Jun 18, 2017 11:26 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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.

_________________
ANes


Top
 Profile  
 
 Post subject: Re: Chr Bank problems
PostPosted: Sun Jun 18, 2017 6:25 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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.

_________________
ANes


Top
 Profile  
 
 Post subject: Re: Chr Bank problems
PostPosted: Mon Jun 19, 2017 3:15 am 
Offline

Joined: Mon Nov 10, 2008 3:09 pm
Posts: 431
You need some way to distinguish between RAM and ROM. ROM shouldn't change when software writes to it through the PPU.


Top
 Profile  
 
 Post subject: Re: Chr Bank problems
PostPosted: Mon Jun 19, 2017 4:16 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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?

_________________
ANes


Top
 Profile  
 
 Post subject: Re: Chr Bank problems
PostPosted: Mon Jun 19, 2017 5:33 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3969
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.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
 Post subject: Re: Chr Bank problems
PostPosted: Mon Jun 19, 2017 5:42 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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

_________________
ANes


Top
 Profile  
 
 Post subject: Re: Chr Bank problems
PostPosted: Mon Jun 19, 2017 5:56 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3969
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.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
 Post subject: Re: Chr Bank problems
PostPosted: Mon Jun 19, 2017 6:19 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
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.

_________________
ANes


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group