It is currently Sun Dec 17, 2017 9:49 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Fri Sep 09, 2016 5:12 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
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?


Top
 Profile  
 
PostPosted: Fri Sep 09, 2016 8:03 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5899
Location: Canada
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.


Top
 Profile  
 
PostPosted: Fri Sep 09, 2016 8:12 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
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


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

All times are UTC - 7 hours


Who is online

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