It is currently Mon Oct 23, 2017 1:02 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 74 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
PostPosted: Tue Aug 20, 2013 6:04 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
How do you know it's "filling VRAM correctly?" Did you take a PPU RAM dump from FCEUX and compare it to a dump from your emulator? I've attached a PPU RAM dump for Donkey Kong so you can compare the two (fc /b, vimdiff, etc.) and see what's going on. The PPU RAM dump was taken at the Donkey Kong title screen.

The number of things wrong in your shot are almost infinite.

I would recommend you run your emulator through blargg's CPU tests first. My gut feeling is that your 6502 code may be doing the wrong thing.

Also a good starting ROM is Mario Brothers (not Super, just standard Mario Brothers).


Attachments:
donkey_kong_ppu_ram.bin [16 KiB]
Downloaded 59 times
Top
 Profile  
 
PostPosted: Tue Aug 20, 2013 10:24 am 
Offline
User avatar

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
Dartht33bagger wrote:
So I've spent about 8 hours debugging now and I'm kind of stuck. I'm currently just trying to render the background before I move onto sprites, and everything looks like it *should* be working correctly in my code. The screen shows a different story, though. I'm using Donkey Kong as a test game and I'm getting black, orange and gray bars on the screen. Does anyone have any idea why this is happening? I can't seem to pinpoint the issue since my cpu seems to be filling VRAM correctly, and my PPU is reading from valid addresses.


It's like the nametables are incorrectly being rendered, or incorrectly written into VRAM. Checking that bin koitsu posted against your VRAM will narrow that down. Or yeah, maybe the CPU. CPU emulation can be very hard if this is your first try. Another starter ROM you might want to try is Lode Runner. It's one of the first I got working in my emu.


Top
 Profile  
 
PostPosted: Wed Aug 21, 2013 8:35 pm 
Offline
User avatar

Joined: Sat Jan 03, 2009 3:28 pm
Posts: 59
Location: Oregon
It seems that my CPU was off a little bit. I corrected two small errors and then decided I would add in all of the illegal opcodes as well so that I could complete the nestest.nes test. I wasn't able to find Blarg's test anywhere, though.

I'm using this document to code my illegal opcodes and I've ran into a roadblock. I cannot get my DCP (opcode $C3) instruction to output the correct status flags after an operation. In the document I've been using, it says that DCP only changes the carry flag. However, the nestest log seems to change the zero flag and negative flag as well.

For example, at PC = $E92E in the nestest.log the DCP instruction doesn't change the processor status flags at all, even though the result of the instruction should set the negative flag. A few instruction down at PC = $E949, the same DCP instruction is ran, and the negative flag and zero flag are turned off. I can't figure how to replicate this result.

So I'm wondering: is there a better document out there that explains the illegal opcodes like this site does for the legal opcodes? The illegal opcodes page on the wiki tells me nothing and I can't find any other document on the net that goes into detail about the instructions.


Top
 Profile  
 
PostPosted: Wed Aug 21, 2013 9:45 pm 
Offline
User avatar

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
What are you doing computation wise for DCP? My CPU passes all of the nestest.nes illegal ops. For DCP I just do a DEC followed by a CMP operation, then move to the next instruction. That's where DCP gets it's mnemonic. It's a concatenation of the two.


Top
 Profile  
 
PostPosted: Wed Aug 21, 2013 11:50 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
Dartht33bagger wrote:
It seems that my CPU was off a little bit. I corrected two small errors and then decided I would add in all of the illegal opcodes as well so that I could complete the nestest.nes test. I wasn't able to find Blarg's test anywhere, though.

Relevant links:

viewtopic.php?p=111810#p111810
viewtopic.php?f=3&t=3966

In general you can find his test suites here: http://blargg.8bitalley.com/nes-tests/

I recommend you stay away from implementing illegal opcodes for the time being -- focus on getting your 6502 CPU core with legal/documented opcodes working correctly first. Worry about illegal opcodes later (there's only one commercial game that I know of which uses an illegal opcode anyway). You're going to spend a lot more time dealing with emulating the PPU and/or mappers anyway. :-)


Top
 Profile  
 
PostPosted: Thu Aug 22, 2013 2:26 am 
Offline
User avatar

Joined: Sat Jan 03, 2009 3:28 pm
Posts: 59
Location: Oregon
It looks like I'll have to implement MMC1 to use Blarg's official opcode test from looking at the header. That's going to take some time...and I don't really understand how the output at $6004 works. Do I just dump a range of memory after a while to see what opcodes I missed?

As for how I was doing DCP, I originally was just decrementing the memory value since that's all the document I was using said it was. Now that I'm using a compare as well, the zero and carry flags are set correctly, but my negative flag is still being set when it shouldn't be. I need my processor status to be $64 and I'm getting $E4. Right now I'm comparing the original data to the original data minus one.


Top
 Profile  
 
PostPosted: Thu Aug 22, 2013 8:16 am 
Offline
User avatar

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
I agree with koitsu about the illegal ops, but if you really want to have a look at this:
http://wiki.nesdev.com/w/index.php/Prog ... al_opcodes

That explains what they do pretty well. All of the useful ones are essentially just existing opcodes combined like DCP is. Here's how I handle them:

Code:
//undocumented instructions
#ifdef UNDOCUMENTED
    static void lax() {
        lda();
        ldx();
    }

    static void sax() {
        sta();
        stx();
        putvalue(a & x);
    }

    static void dcp() {
        dec();
        cmp();
    }

    static void isb() {
        inc();
        sbc();
    }

    static void slo() {
        asl();
        ora();
    }

    static void rla() {
        rol();
        and();
    }

    static void sre() {
        lsr();
        eor();
    }

    static void rra() {
        ror();
        adc();
    }
#else
    #define lax nop
    #define sax nop
    #define dcp nop
    #define isb nop
    #define slo nop
    #define rla nop
    #define sre nop
    #define rra nop
#endif


Pretty straightforward, really. putvalue just writes a value into the destination operand.


Top
 Profile  
 
PostPosted: Thu Aug 22, 2013 11:21 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Dartht33bagger wrote:
It looks like I'll have to implement MMC1 to use Blarg's official opcode test from looking at the header. That's going to take some time...and I don't really understand how the output at $6004 works. Do I just dump a range of memory after a while to see what opcodes I missed?

There should be individual test ROMs that don't need any mapper. As for output, just dump $6000-$7FFF to a text file after running the test ROM for say a minute (you could run your emulator as fast as it can go so this happens more quickly). Then examine the text file.


Top
 Profile  
 
PostPosted: Thu Aug 22, 2013 9:55 pm 
Offline
User avatar

Joined: Sat Jan 03, 2009 3:28 pm
Posts: 59
Location: Oregon
So I've been trying to get my output to dump correctly. My RAM is of type unsigned char and I'm having a hard time figuring out how to print out the output text. If I don't cast the data as (int), gedit refuses to open the output txt document because of "invalid UTF-8 input". So I've outputted the data as hex values, but I'm not sure how to read the output as hex values.

For example, my output from $6000 to $6016 looks like this right now(all hex values):

6000 - 0
6001 - de
6002 - b0
6003 - 61
6004 - a
6005 - 30
6006 - 31
6007 - 2d
6008 - 62
6009 - 61
600a - 73
600b - 69
600c - 63
600d - 73
600e - a
600f - a
6010 - 50
6011 - 61
6012 - 73
6013 - 73
6014 - 65
6015 - 64
6016 - a

Then there are zeros until another set of values start around $60F1.


Top
 Profile  
 
PostPosted: Thu Aug 22, 2013 10:09 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
It's a null-terminated string at $6004:
readme.txt wrote:
Output at $6000
---------------
All text output is written starting at $6004, with a zero-byte terminator at the end. As more text is written, the terminator is moved forward, so an emulator can print the current text at any time.

The test status is written to $6000. $80 means the test is running, $81 means the test needs the reset button pressed, but delayed by at least 100 msec from now. $00-$7F means the test has completed and given that result code.

To allow an emulator to know when one of these tests is running and the data at $6000+ is valid, as opposed to some other NES program, $DE $B0 $G1 is written to $6001-$6003.


Top
 Profile  
 
PostPosted: Thu Aug 22, 2013 10:47 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19116
Location: NE Indiana, USA (NTSC)
$G1? G?

I see "basics" and "Passed" while trying to decode ASCII in my head.


Top
 Profile  
 
PostPosted: Fri Aug 23, 2013 1:50 am 
Offline
User avatar

Joined: Sat Jan 03, 2009 3:28 pm
Posts: 59
Location: Oregon
I passed 01-basics and 02-implied. 03-immediate failed but only on illegal opcodes, so I moved on. Now 04-zero_page is really burning me. I'm not even getting a failed message, just a string of easy opcodes...

Output for 04-zero_page:

A6 LDX z, A4 LDY z, 85 STA z, 86 STX z, 84 STY z, E6 INC z, C6 DEC z, 06 ASL z, 46 LSR z
26 ROL z, 66 ROR z, 65 ADC z, E5 SBC z, 05 ORA z, 25 AND z, 45 EOR z, 24 BIT z, C5 CMP z
E4 CPX z, C4 CPY z, 04 DOP z, 44 DOP z, 64 DOP z, 07 SLO z

I don't understand how I'm missing $A6 LDX (or most of the others) since they seem so simple:
Code:
case 0xA6:   //Zeropage load X
         temp1 = memory->readRAM(PC, ppu);
         X = memory->readRAM(temp1, ppu);
         Z = !(X);
         N = X & 0x80;
         cycles =  3;
         PC++;
         break;


Top
 Profile  
 
PostPosted: Fri Aug 23, 2013 9:05 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Something else broken? Odd that the earlier tests don't fail. They do catch your unofficial instructions not being right, so it doesn't look like whatever's broken is something the tests rely on. What's your code for LDX immediate, to see how it differs from LDX zero-page?


Top
 Profile  
 
PostPosted: Fri Aug 23, 2013 1:33 pm 
Offline
User avatar

Joined: Sat Jan 03, 2009 3:28 pm
Posts: 59
Location: Oregon
05-zp_xy gives the same results as 04-zero_page does. The same opcodes are showing up that showed up in the zeropage test.

Here is my code for $A2 immediate LDX:

Code:
case 0xA2:   //Immediate load X
         X = memory->readRAM(PC, ppu);
         Z = !(X);
         N = X & 0x80;
         cycles =  2;
         PC++;
         break;


Top
 Profile  
 
PostPosted: Fri Aug 23, 2013 4:41 pm 
Offline
User avatar

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
Dartht33bagger wrote:
05-zp_xy gives the same results as 04-zero_page does. The same opcodes are showing up that showed up in the zeropage test.

Here is my code for $A2 immediate LDX:

Code:
case 0xA2:   //Immediate load X
         X = memory->readRAM(PC, ppu);
         Z = !(X);
         N = X & 0x80;
         cycles =  2;
         PC++;
         break;


The logic looks right to me, but what is "ppu" for in readRAM? You're not reading the value from VRAM are you?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 74 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

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