It is currently Sun Jun 17, 2018 3:22 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Jun 04, 2018 9:17 am 
Offline

Joined: Mon Jun 04, 2018 8:56 am
Posts: 3
I decided to work on an NES emulator to understand hardware better, but it's not working right.

I think it has to do with some misunderstanding I have with mappers. I'm using cpu_dummy_reads.nes as my test rom. My loading process; I read the ROM, read the 16 byte header, the (in this case) 32767 bit long program, the CHR, and I do nothing with the rest of the file because I've reached the end of it.

Because I'm using C#, I decided to be lazy and just have one 64 KB byte[0xFFFF] as all readable memory. I load my PRG into 0x8000 to 0xFFFF and set my program counter to 0x8000 (The addresses that mapper five says the PRG should go). I hit the run button and expect to start programming some opcodes. The opcodes are invalid, though. I'm running into 24576 empty opcodes (00), on top of some other strange things.

I also tried with donkey kong and I get some other problem with reading invalid opcodes.

Source https://pastebin.com/sCVFPcuY

And if I look at the actual hex data for cpu_dummy_reads.nes, after the header there are tons of 00's. I'm pointing my emulator to this code to start executing right off. Is this right?


Attachments:
File comment: The output I'm getting
broke.PNG
broke.PNG [ 25.79 KiB | Viewed 391 times ]
Top
 Profile  
 
PostPosted: Mon Jun 04, 2018 10:18 am 
Offline

Joined: Sat Mar 08, 2014 12:59 pm
Posts: 17
You need to start execution at $FFFC, not $8000. In other words, the value stored at $FFFC tells you where to set your program counter to start execution. See http://wiki.nesdev.com/w/index.php/CPU_memory_map.


Top
 Profile  
 
PostPosted: Mon Jun 04, 2018 10:35 am 
Offline

Joined: Mon Jun 04, 2018 8:56 am
Posts: 3
I get invalid opcodes at FFFC

Am I loading it incorrectly?


Attachments:
broke2.PNG
broke2.PNG [ 13.06 KiB | Viewed 370 times ]
Top
 Profile  
 
PostPosted: Mon Jun 04, 2018 10:50 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 7209
Location: Seattle
isosceles wrote:
In other words, the value stored at $FFFC tells you where to set your program counter to start execution.
This is the important part.

The first sentence (which I haven't quoted) was misleading.


Top
 Profile  
 
PostPosted: Mon Jun 04, 2018 10:51 am 
Offline
User avatar

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 257
Location: Rio de Janeiro - Brazil
You're not supposed to execute those bytes. That's two bytes representing the address for the reset vector location. Take those two bytes and bring the program counter to the address they represent and start executing the code there. I think it means go to address 0xE57F in that case.
viewtopic.php?t=3677

_________________
http://nesrocks.com/blog/superpitfall30th/


Top
 Profile  
 
PostPosted: Mon Jun 04, 2018 11:35 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20157
Location: NE Indiana, USA (NTSC)
Or if the bytes at $FFFC are $EF $CD, execution begins with PC at $CDEF. So to put it another way: Treat reset as if it does SEI followed by an indirect JMP ($FFFC) and you'll be 99% correct.


Top
 Profile  
 
PostPosted: Mon Jun 04, 2018 8:46 pm 
Offline

Joined: Mon Jun 04, 2018 8:56 am
Posts: 3
That seemed to do the trick, I think it's all working as far as I can tell. Thank you. :)


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 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