It is currently Sat Dec 16, 2017 2:24 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Strange debug problem
PostPosted: Thu Aug 11, 2005 10:14 am 
Doing some debugging and I came across this:

In debugging why Who_Framed_Roger_Rabbit_(U).nes crashes
The game stats are:

NES Game Size: 131088 bytes
Number of 16K Program Banks: 8
Number of 8K CHR Banks: 0
Mapper number: 7
SRAM Enabled: 0
Vertical Mirroring: 0

I found:

emulation starts:

The code loads bank 0 32K into 0x8000
The code loads bank 3 32k into 0x8000
First NMI occurs
Crash on first opcode of 0xe3 with pc of 0xFFA1 (NMI vector).

I assume the rom is bad, but Ubernes plays the rom fine. How could a bad opcode exist in the game if it is not corrupted? How does Ubernes (or any emulator) play a corrupted game? If I ignore the bad opcode (pc++) the game will load, but works strangely.



Any ideas?


Top
  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 12:23 pm 
Offline

Joined: Sat Nov 13, 2004 6:25 am
Posts: 96
As you state, NMI vector points to address 0xFFA1, but the opcode there is not 0x3E, but 0x85 (0x85 0x43 (STA $43), to be exact). May your NMI handler be the problem? Check it.


Top
 Profile  
 
PostPosted: Thu Aug 11, 2005 1:40 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19348
Location: NE Indiana, USA (NTSC)
Emugalaxy wrote:
I assume the rom is bad, but Ubernes plays the rom fine. How could a bad opcode exist in the game if it is not corrupted?

Apart from the "KIL"/"JAM"/"HLT" opcodes, most of which have $2 as the least significant digit, there are no "bad" opcodes, just undocumented opcodes.


Top
 Profile  
 
PostPosted: Thu Aug 11, 2005 2:32 pm 
Offline

Joined: Sat Nov 13, 2004 6:25 am
Posts: 96
tepples wrote:
Emugalaxy wrote:
I assume the rom is bad, but Ubernes plays the rom fine. How could a bad opcode exist in the game if it is not corrupted?

Apart from the "KIL"/"JAM"/"HLT" opcodes, most of which have $2 as the least significant digit, there are no "bad" opcodes, just undocumented opcodes.

I guess by "bad" here he meant "corrupted" in the sense of a byte dumped incorrectly..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 7:31 am 
Here is my NMI handler:

sPush(pc >> 8);
sPush(pc & 0xFF);
//N V * B D I Z C
//- - 1 0 - - - -
status = 0;
status = (negative_flag << 7) |
(overflow_flag << 6) |
(1 << 5) |
(0 << 4) |
(decimal_flag << 3) |
(interrupt_disabled_flag << 2) |
(zero_flag << 1) | carry_flag;
sPush(status);
interrupt_disabled_flag = 1;
pc = NMI;

Should I add anything? My IRQ handler is virtually identical.

Then I do the switch(cpu_mem[pc]) etc....

The pc is 0xFFA1. The value there is 0x3E. Anyone know the if the game actually does load bank 0 and then 3? Maybe I have an error in my core that is causing the wrong bank number to be calculated? Thanks for the replys


Top
  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 10:25 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1393
If you're doing what I think you're doing, you're reading the NMI vector upon loading the ROM and leaving it as-is, even when the upper PRG bank changes.

If this is the case, this is INCORRECT behaviour - the CPU fetches the appropriate interrupt vector from memory on EVERY INTERRUPT, so it is very much possible to redefine the interrupt vectors at runtime (in this case, by bank switching).

The reason it's failing is because every bank in that game has a different NMI vector, and when the interrupt comes along, it's not in the same bank as you started out with.

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 11:50 am 
That was it. Thanks!

I have one other question. I pass all of the nestest.nes tests except for indirect, X. I get a code code 59: 059h - STA didn't store the data where it was supposed to

my STA code is:

case 0x81: STA(indirectX()); count+=6; pc+=2; break;

My indirectX function is:

unsigned short indirectX() {
unsigned short temp = getMem(pc + 1);
temp = (temp + x) & 0xFF;
unsigned short newAddressLSB = getMem(temp);
unsigned short newAddressMSB = getMem(temp+1);
newAddressMSB = newAddressMSB << 8;
return newAddressMSB | newAddressLSB;
}

I can't find anything wrong with this. Any ideas?


Top
  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 12:17 pm 
Nevermind . Fixed it. I wasn't wrapping on zero page.


Top
  
 
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 7 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