It is currently Sun May 28, 2017 7:02 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Vram banking in CGB
PostPosted: Mon Apr 18, 2016 8:46 pm 
Offline

Joined: Sat Jun 27, 2015 1:09 pm
Posts: 68
Hi, I've been trying to add color support to my GB emulator. DMG compatibility is very high now (some window issues mostly), but I'm having a hard time with color GB.

I already emulated the palette registers for bg and obj, but I can't draw anything yet.

This document for example (http://gbdev.gg8.se/wiki/articles/Video_Display), says:

BG Map Attributes (CGB Mode only)
In CGB Mode, an additional map of 32x32 bytes is stored in VRAM Bank 1 (each byte defines attributes for the corresponding tile-number map entry in VRAM Bank 0):
Bit 0-2 Background Palette number (BGP0-7)
Bit 3 Tile VRAM Bank number (0=Bank 0, 1=Bank 1)
Bit 4 Not used
Bit 5 Horizontal Flip (0=Normal, 1=Mirror horizontally)
Bit 6 Vertical Flip (0=Normal, 1=Mirror vertically)
Bit 7 BG-to-OAM Priority (0=Use OAM priority bit, 1=BG Priority)

I've just reached a tile in vram bank 1, which has a value of 0x08, that would be bit 3, but I can't get the meaning of "Tile VRAM Bank Number". What should I do with this bit ? If it's ON, it's bank 1, but I don't understand what should I do with it.

So I have my VRAM bank 0, which I guess is exactly the same as the DMG one, and this new VRAM bank 1 which has just attributes (metadata) for all the bank 0 tiles ?

What am I missing here ?

Thanks,


Top
 Profile  
 
 Post subject: Re: Vram banking in CGB
PostPosted: Mon Apr 18, 2016 11:20 pm 
Offline

Joined: Sun Jan 26, 2014 9:31 am
Posts: 237
Keep in mind, all of VRAM (0x8000 to 0x9FFF) will be on two banks. On the GBC, Background Map data is found on VRAM Bank 0 at 0x9800 through 0x9FFF. The attributes for each map entry are located in that same space on Bank 1. You seem to have gotten that much sorted out, so let's move on.

0x8000 through 0x97FF is where you find the actual tile data (i.e. the "dot data" that makes up the paletted tiles). Now, whenever you have to look up a map entry, and it tells you to look at VRAM Bank 0 or 1, every time you read from 0x8000 through 0x97FF, read from the specified VRAM Bank. It works like this:

Assume we are using 0x8000 through 0x8FFF as our Tile Pattern Table (keep it simple by using unsigned tile numbers...) and then say we start reading some random map entry. The map entry itself (found on VRAM Bank 0) is just a number (0 - 255) that will point us to the right address somewhere between 0x8000 through 0x8FFF. Say we pull the first map entry at 0x9800 and it was something like 0x17 from VRAM Bank 0. Now we need to look at 0x9800 in VRAM Bank 1 to get the BG attributes. Let's just assume the attributes flag tells us to look at VRAM Bank 1 for this example

Going forward, we have the map entry (0x17) and the VRAM Bank (0x1). We calculate the VRAM address to pull the tile data from by using the map entry, e.g. this formula:

Code:
address = 0x8000 + (0x17 * 16)


Unsurprisingly, this is the same stuff you'd do on a regular DMG. So to pull the tile data from VRAM, we need start looking at 0x8170. But wait, remember that VRAM Bank bit from the BG attributes? That tells us which VRAM bank to look at when we access 0x8170 - 0x817F for the tile data. If it's 1, you read bytes VRAM Bank 1. If not, VRAM Bank 0. Pretty simple when you see what it's doing. Hope this clears it up for you :wink:


Top
 Profile  
 
 Post subject: Re: Vram banking in CGB
PostPosted: Tue Apr 19, 2016 5:20 am 
Offline

Joined: Sat Jun 27, 2015 1:09 pm
Posts: 68
Brilliant ! I managed to make the CGB bios to work perfectly. Time to move to those new DMA features.

Thanks !


Top
 Profile  
 
 Post subject: Re: Vram banking in CGB
PostPosted: Wed Apr 20, 2016 8:46 am 
Offline

Joined: Sun Jan 26, 2014 9:31 am
Posts: 237
Getting GBC VRAM banking correct is very important. In Pokemon Gold/Silver, for example, if done improperly, you end up turning Ecruteak City's famous Kimono Girls into something else entirely, like a dance troupe of middle-aged men. :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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