It is currently Fri Oct 20, 2017 4:42 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat Sep 14, 2013 8:36 pm 
Offline
User avatar

Joined: Sun Jul 29, 2012 10:13 am
Posts: 38
Location: Chicago, IL
So I'm in the midst of refactoring my emulator to not be so naive about copying memory while doing a bank switch, and I'm running into some trouble with a limited number of mappers (haven't reworked MMC2/3/5 yet) in certain cases. For MMC1, any game that does 4k CHR swaps runs totally fine but if the game uses 8k CHR swaps you get the effects seen below in Zelda and Bionic Commando. Duck Tales (and other UNROM games) also show the behavior.

ImageImageImage

Digging in it looks like Zelda doesn't even trigger a bank switch for a while when it starts up (or at least not that I can see), so that says to me that the startup bank is wrong but I'm pointing the lower CHR bank (where it has sprites stored) to 0 which worked fine before I refactored. What I'm thinking is that I broke something in how the the sprite pattern tables are filled, but I'm lost at what these games do differently from others that might make those patterns fill incorrectly.

A little abstract, but any thoughts? I can provide relevant code if necessary.


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 8:39 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2257
Post some code to get more replies. But on 8KB switching, are you ignoring the lowest bit?


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 8:41 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6288
Location: Seattle
Looks like you're fetching some things from the wrong pattern table.
e.g. with Duck Tales, Scrooge McDuck should be from the left pattern table (PPU $0xxx), but you're drawing him from the right pattern table (PPU $1xxx)


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 8:45 pm 
Offline
User avatar

Joined: Sun Jul 29, 2012 10:13 am
Posts: 38
Location: Chicago, IL
lidnariq wrote:
Looks like you're fetching some things from the wrong pattern table.
e.g. with Duck Tales, Scrooge McDuck should be from the left pattern table (PPU $0xxx), but you're drawing him from the right pattern table (PPU $1xxx)


Exactly what I thought but I verified the address coming in is certainly the appropriate one.

CHR banks are stored in 4k arrays, here's the relevant code to read from that address space and to fetch a tile:

Code:
func (m *Mmc1) ReadVram(a int) Word {
   if a >= 0x1000 {
      return m.VromBanks[m.ChrUpperBank][a&0xFFF]
   }

   return m.VromBanks[m.ChrLowerBank][a&0xFFF]
}

func (m *Mmc1) ReadTile(a int) []Word {
   if a >= 0x1000 {
      return m.VromBanks[m.ChrUpperBank][a&0xFFF : a&0xFFF+16]
   }

   return m.VromBanks[m.ChrLowerBank][a&0xFFF : a&0xFFF+16]
}


3gengames wrote:
Post some code to get more replies. But on 8KB switching, are you ignoring the lowest bit?


Shifting it out, yeah:

Code:
      switch m.ChrBankSize {
      case Size8k:
         // Swap 8k VROM (in 8k mode, ignore first bit D0)
         bank := v & 0xF
         bank %= len(m.VromBanks)

         if v&0x10 == 0x10 {
            bank = (len(m.VromBanks) / 2) + (v & 0xF)
         } else {
            bank = v & 0xF
         }

         m.ChrUpperBank = (bank >> 1) + 1
         m.ChrLowerBank = (bank >> 1)
      case Size4k:
         // Swap 4k VROM
         var bank int

         if v&0x10 == 0x10 {
            bank = (len(m.VromBanks) / 2) + (v & 0xF)
         } else {
            bank = v & 0xF
         }
         m.ChrLowerBank = bank
      }


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 8:52 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2257
Why not just do an & 0xFE? Shifting it makes it "wrong" because 8KB banks are the same as 4K except the bank value swapped is +1'd for the 2nd bank.5


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 8:57 pm 
Offline
User avatar

Joined: Sun Jul 29, 2012 10:13 am
Posts: 38
Location: Chicago, IL
3gengames wrote:
Why not just do an & 0xFE? Shifting it makes it "wrong" because 8KB banks are the same as 4K except the bank value swapped is +1'd for the 2nd bank.5

Good point, made the change. Problem I'm seeing though is that the bank swap never occurs before the Zelda title screen appears. I see the lower bank get filled but it's clearly the wrong data (or I'm reading it wrong in the mapper).


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 9:05 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2257
Is the reset bit written to? I'm going to assume reset sets CHR to 0, but that's just guessing. Anyone know for sure? If I had a working compiler on Linux that wasn't 10 years to set up, I'd write a test ROM and run it on hardware, but don't have one.


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 9:10 pm 
Offline
User avatar

Joined: Sun Jul 29, 2012 10:13 am
Posts: 38
Location: Chicago, IL
3gengames wrote:
Is the reset bit written to? I'm going to assume reset sets CHR to 0, but that's just guessing. Anyone know for sure? If I had a working compiler on Linux that wasn't 10 years to set up, I'd write a test ROM and run it on hardware, but don't have one.

Been a while since I wrote this mapper, but I only have the PRG banks as being reset when the reset bit gets set (and the mapper received a write):

Code:
        // If reset bit is set
   if v&0x80 != 0 {
      m.BufferCounter = 0
      m.Buffer = 0x0

      m.PrgSwapBank = BankLower
      m.PrgBankSize = Size16k
   }


Top
 Profile  
 
PostPosted: Sat Sep 14, 2013 9:30 pm 
Offline
User avatar

Joined: Sun Jul 29, 2012 10:13 am
Posts: 38
Location: Chicago, IL
Ha, I found it. Silly lack of a return after writing the to the high banks so it would write to both banks.

Thanks for the quick responses guys.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 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