It is currently Tue Oct 17, 2017 9:08 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Wed Aug 03, 2005 12:28 am 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
The first thing that stands out is that you're using char for your ROM. A compiler can implement this as signed or unsigned, but it's usually signed so this is probably a source of problems. I recommend adding some printf() calls in the future to look at intermediate data. It also doesn't look like this is the code you ran, since it has errors.

I coded up the following and it prints $8000 for the reset vector (I changed it to read 32K of ROM). I put in error checking because without it any errors would appear as an incorrect vector. I also made the rom data static since my compiler didn't like having so much data on the stack; in an emulator it should be allocated dynamically with malloc() or similar.

Code:
void print_vector()
{
    static unsigned char rom [32 * 1024L];
    FILE* file = fopen( "rom.nes", "rb" );
    if ( !file )
        return;
   
    if ( fseek( file, 16, SEEK_SET ) )
        goto error;
   
    if ( !fread( rom, 1, sizeof rom, file ) )
        goto error;
   
    {
        unsigned offset = 0x8000;
        unsigned reset = rom [0xfffd - offset] * 0x100 +
                rom [0xfffc - offset];
       
        printf( "Reset vector: $%04x\n", reset );
    }
   
error:
    fclose( file );
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 7:11 am 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
Albeit wrote:
Is the first bank loaded into $C000 and the second loaded into $8000? Do the banks actually come after one another in the cartridge rom? Am I doing something wrong?


For mapper 0 ROMs with 32k PRG (like Super Mario Bros), the first 16k goes at $8000 and the second 16k goes at $C000.

To add to some things blargg said and for a few more things:

- 'char' may be signed, which you don't want. Use 'unsigned char' or a typedef of that ('BYTE' perhaps?). You want unsigned 8-bit vars.

- fread() is much much better for reading large chunks of data. fscanf() isn't the best way to go (if you even just want an individual byte -- fgetc() would even be better than fscanf() -- but for this use fread())

- don't be afraid to use hex in your code. I see a lot of hex->dec conversions... some of which are errornerous. Instead of "16384" for 16k, why not "0x4000"? you know the reset vector is at $FFFC, so why not use "0xFFFC"? the conversion to "16302" is not only harder to read... but also wrong (even after the subtraction)

- the PRG comes before the CHR in the .nes file... so you've got the right idea.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

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