nesdev.com
http://forums.nesdev.com/

Dynamite Batman (SFX).nsf
http://forums.nesdev.com/viewtopic.php?f=3&t=14793
Page 2 of 2

Author:  Zepper [ Fri Sep 09, 2016 5:12 pm ]
Post subject:  Re: Dynamite Batman (SFX).nsf

OK, it's optional, but let me recap. If the NSF brings eight zeroes for bankswitching values and the NSF file is bigger than $8000, the bankswitching values should be changed into 0 1 2 3 4 5 6 7, correct?

Author:  rainwarrior [ Fri Sep 09, 2016 8:03 pm ]
Post subject:  Re: Dynamite Batman (SFX).nsf

Zepper wrote:
OK, it's optional, but let me recap. If the NSF brings eight zeroes for bankswitching values and the NSF file is bigger than $8000, the bankswitching values should be changed into 0 1 2 3 4 5 6 7, correct?

It's an invalid NSF, so there's no obligation for your player to handle it. What should happen is the file should get 0 1 2 3 4 5 6 7 placed in its bank values, to fix the file.

What may happen is that your player can allow bankswitching anyway. (So, yes that would equivalently replace 0 0 0 0 0 0 0 0 with 0 1 2 3 4 5 6 7, but you would do the same for everything, bankswitching or not.)

I would not recommend using the file size < or > 32k as any kind of indicator here. Just always allow banskwitching or not. Lots of NSFs do not use the entire address space, so it's very common to see bankswitching with <32k. Similarly, if NSF2 ever happens, it's quite possible for a non-bankswitcing NSF to have extra data at the end.


The LOAD address should behave one way if the bank bytes are 0 0 0 0 0 0 0 0, and another way if they are not. (Always.) This is separate from whether or not to allow the banking registers to work always.

Author:  Disch [ Fri Sep 09, 2016 8:12 pm ]
Post subject:  Re: Dynamite Batman (SFX).nsf

Loaders can be tricky, especially for FDS tunes, since they can load into the $6000-7FFF range even without bankswitching.

Here's what I've always done for loading:

Code:
byte bankbyte[10];      // 10 bankswitch registers ($5FF6 - $5FFF)

bool all_bank_bytes_are_zero = true;
for(i = 0; i < 8; ++i)
{
    bankbyte[i+2] = bankswitch_byte_from_header[i];
    if(bankbyte[i+2] != 0)
        all_bank_bytes_are_zero = false;
}
bankbyte[0] = bankbyte[8];
bankbyte[1] = bankbyte[9];


// bytes needed to hold the entire file
datasize = filesize - 0x80;

// number of banks needed to hold the file (round up)
num_banks = (datasize + (load_addr & 0x0FFF) + 0x0FFF) / 0x1000;

if( all_bank_bytes_are_zero )
{
    if( is_fds_tune )
    {
        // no bankswitching, FDS
        if(num_banks < 10)
            num_banks = 10;             // 2 extra banks for the $6000-7FFF region
       
        for(i = 0; i < 10; ++i)
            bankbyte[i] = i;            // set bankswitch to 0,1,2,3,4,5,6,7,8,9
                                        //  so banks 0,1 get loaded into 6000-7FFF
                                       
        if(load_addr < 0x6000)      throw Error;
       
        load_addr -= 0x6000;
    }
    else
    {
        // no bankswitching, not FDS
        if(num_banks < 8)
            num_banks = 8;
       
        bankbyte[0] = 0;
        bankbyte[1] = 0;
        for(i = 0; i < 8; ++i)
            bankbyte[i+2] = i;          // set bankswitch to 0,0,0,1,2,3,4,5,6,7
                                        //   so 0,1 gets loaded into $8000-9FFF
                                        //   first two values don't matter because they'll be
                                        //   unswappable RAM
           
        if(load_addr < 0x8000)      throw Error;
       
        load_addr -= 0x8000;
    }
}
else
{
    // there IS bankswitching
    load_addr &= 0x0FFF;
}


rom.resize( num_banks * 0x1000 );
file.read( &rom[ load_addr ], datasize );




EDIT: better FDS handler

Page 2 of 2 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/