DS graphics notes ~~~~~~~~~~~~~~~~~ /Mic, 2005 This is a brief summary of the knowledge I've gathered so far about the various graphics modes on the DS. Don't take these claims for absolute truths, but as guidance in (hopefully) the right direction. MODE 3,4,5 ~~~~~~~~~~ Applicable on both cores. BG0 can be used as a text BG or for 3D. BG1 is always a text BG. BG2 and BG3 work as follows: Mode 3: BG2 = text, BG3 = extended rotoscale Mode 4: BG2 = rotoscale, BG3 = extended rotoscale Mode 5: BG2 = extended rotoscale, BG3 = extended rotoscale There are three types of extended rotoscale BGs, controlled through bits 2 and 7 of BG*CNT: Type 00: rotoscale bg with extended palette (16 palettes x 256 colors) Type 10: 256-color bitmap Type 11: direct color bitmap (ABGR, *not* xBGR) Type 00 (bit 2 clear, bit 7 clear) ---------------------------------- These work much like the rotoscale BGs on the GBA, except the screen data is two bytes per entry instead of a single byte. In case the proper extended palette set has been enabled, bits 12..15 of each screen entry will be used to select one of the 16 256-color palettes. Otherwise the normal BG palette is used. There are four sets of extended palettes - each set holding 16 palettes of 256 colors for a total of 4096 colors. Thus the size of each set is 8kB. You must use a matching set number for the BG (i.e. set 2 for BG2 and set 3 for BG3). You can either map VRAM bank E as extended palettes to enable all palette slots, or you can enable just slots 0+1 or 2+3 using banks F or G. For the sub core you must use VRAM bank H for the extended palettes. This will fit all four sets. The procedure for loading your palette data into set 3 of VRAM bank E would be as follows: Map bank E to LCDC at 0x06880000 (VRAMCNT_E = 0x80) Write your data starting at 0x06886000 (each set is 0x2000 bytes, 0x2000*3 = 0x6000) Map bank E as extended palettes (VRAMCNT_E = 0x84) Similarly for banks F and G, except the VRAMCNT values and the data address would differ. You also need to set bit 30 of DISPCNT to enable extended palettes. Type 10 (bit 2 clear, bit 7 set) -------------------------------- The selectable sizes (bit 14..15 of BG*CNT) are 128x128, 256x256, 512x256, 512x512. Each screen base block is 16kB, meaning you can map the screen to any offset up to 31*16kB = 496kB. Thus for the main core you can use any of VRAM banks A..D for the screen data, except for when the screen size is 512x512 pixels, which requires two VRAM banks to hold the screen data. For the sub core you are a bit more limited in which banks you can use. An example of setting BG2 as a 256x256 bitmap at offset 0x4000 for the main core would be: Map bank A to main BG at 0x06000000 (VRAMCNT_A = 0x81) Set 256x256 size, 256-color mode, screen base 0x4000 (BG2CNT = 0x4180) Type 11 (bit 2 set, bit 7 set) ------------------------------ The selectable sizes (bit 14..15 of BG*CNT) are 128x128, 256x256, 512x256, 512x512. Each screen base block is 16kB, meaning you can map the screen to any offset up to 31*16kB = 496kB. Thus for the main core you can use any of VRAM banks A..D for the screen data, except for when the screen size is 512x256 or 512x512 pixels, which requires at least two VRAM banks to hold the screen data. For the sub core you are a bit more limited in which banks you can use. Note that the color format for the direct color BGs uses bit 15 of the color as an alpha bit. This is to allow for transparency when using more than one layer. For all three types, bit 13 of BG*CNT controls wrapping. MODE 6 ~~~~~~ Only applicable on the main core. BG0 can be used for 3D. BG2 holds a large 256-color bitmap. BG1 and BG3 are unused (?) Bit 14 of BG2CNT controls the size of the bitmap as follows: 0: 512x1024 pixels 1: 1024x512 pixels Since the bitmap uses 512kB of VRAM either way you need to allocate VRAM banks A..D to the main BG. This is done by writing 0x81, 0x89, 0x91, 0x99 to VRAMCNT_A, B, C, D respectively. With this setup the bitmap will start at address 0x06000000. Bit 13 of BG2CNT controls wrapping. "Common" pitfalls ~~~~~~~~~~~~~~~~~ * Used xBGR colors instead of ABGR for the direct color bitmaps. You need to set bit 15 to 1 or the pixel will be invisible. * Forgot to set up the rotoscaling parameters properly. For a normal display, BG*X and BG*Y should be zero, while BG*PA..PD should be set to 0x100, 0, 0, 0x100. * Forgot to set bit 30 of DISPCNT (or DISPCNT_SUB) to enable the extended palettes. * Mapped VRAM banks incorrectly. * Forgot to enable the screens and/or VRAM banks in POWERCNT.