gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > display all background in mode 0

#53179 - daygo - Tue Sep 06, 2005 4:36 pm

hello, i'm a italian boy e i don't speak english very well.....

i have a problem, this code don't draw background 4...why?




Code:

#include <mygba.h>
MULTIBOOT

#include "image1.pal.c"
#include "image1.map.c"
#include "image1.raw.c"
#include "image2.pal.c"
#include "image2.map.c"
#include "image2.raw.c"
#include "image3.pal.c"
#include "image3.map.c"
#include "image3.raw.c"
#include "image4.pal.c"
#include "image4.map.c"
#include "image4.raw.c"

#define REG_DMA3SAD *(volatile unsigned int*)0x40000D4
#define REG_DMA3DAD *(volatile unsigned int*)0x40000D8
#define REG_DMA3CNT *(volatile unsigned int*)0x40000DC
#define DMA_ENABLE 0x80000000
#define DMA_TIMING_IMMEDIAT 0x00000000
#define DMA_16 0x00000000
#define DMA_32 0x04000000
#define DMA_16im (DMA_ENABLE | DMA_TIMING_IMMEDIAT | DMA_16)
#define DMA_32im (DMA_ENABLE | DMA_TIMING_IMMEDIAT | DMA_32)

#define REG_KEYS *(volatile unsigned long*) 0x4000130
#define REG_TOUCHES (~(REG_KEYS) & 0x03FF)
#define TOUCHE_DROITE 0x0010
#define TOUCHE_GAUCHE 0x0020
#define TOUCHE_HAUT 0x0040
#define TOUCHE_BAS 0x0080

volatile unsigned short* scan = (volatile unsigned short*)0x4000006;

#define REG_DISPCNT *(volatile unsigned long*)0x4000000

#define VIDEO_MODE0 0x0
#define VIDEO_MODE1 0x1
#define VIDEO_MODE2 0x2
#define VIDEO_MODE3 0x3
#define VIDEO_MODE4 0x4
#define VIDEO_MODE5 0x5

#define BG0_ENABLED 0x100
#define BG1_ENABLED 0x200
#define BG2_ENABLED 0x400
#define BG3_ENABLED 0x800

#define BG_PRIORITE_0 0x0000
#define BG_PRIORITE_1 0x0001
#define BG_PRIORITE_2 0x0002
#define BG_PRIORITE_3 0x0003

#define BG_CHARBLOCK_0 0x0000
#define BG_CHARBLOCK_1 0x0004
#define BG_CHARBLOCK_2 0x0008
#define BG_CHARBLOCK_3 0x000C

#define BG_EFFET_MOSAIQUE 0x0040

#define BG_1_PALETTE 0x0080
#define BG_16_PALETTES 0x0000

#define BG_WRAP 0x2000

#define BG_TEXTE_256x256 0x0000
#define BG_TEXTE_512x256 0x4000
#define BG_TEXTE_256x512 0x8000
#define BG_TEXTE_512x512 0xC000

#define BG_ROTATION_128x128 0x0000
#define BG_ROTATION_256x256 0x4000
#define BG_ROTATION_512x512 0x8000
#define BG_ROTATION_1024x1024 0xC000

#define REG_BG0CNT *(volatile unsigned short*) 0x4000008
#define REG_BG1CNT *(volatile unsigned short*) 0x400000A
#define REG_BG2CNT *(volatile unsigned short*) 0x400000C
#define REG_BG3CNT *(volatile unsigned short*) 0x400000E

#define REG_BG0HOFS *(volatile unsigned short*) 0x4000010
#define REG_BG0VOFS *(volatile unsigned short*) 0x4000012
#define REG_BG1HOFS *(volatile unsigned short*) 0x4000014
#define REG_BG1VOFS *(volatile unsigned short*) 0x4000016
#define REG_BG2HOFS *(volatile unsigned short*) 0x4000018
#define REG_BG2VOFS *(volatile unsigned short*) 0x400001A
#define REG_BG3HOFS *(volatile unsigned short*) 0x400001C
#define REG_BG3VOFS *(volatile unsigned short*) 0x400001E

#define CharBaseBlock(n) (((n)*0x4000)+0x6000000)
#define ScreenBaseBlock(n) (((n)*0x0800)+0x6000000)

unsigned short int * Palette = (unsigned short int *) 0x5000000;

int main(void)
{
int x, y, c;

REG_DISPCNT = (VIDEO_MODE0|BG0_ENABLED|BG1_ENABLED|BG2_ENABLED|BG3_ENABLED);

REG_BG0CNT = BG_TEXTE_256x256 | BG_1_PALETTE | BG_WRAP | BG_CHARBLOCK_0 | 31<<8  ;
REG_BG1CNT = BG_TEXTE_256x256 | BG_1_PALETTE | BG_WRAP | BG_CHARBLOCK_1 | 30<<8  ;
REG_BG2CNT = BG_TEXTE_256x256 | BG_1_PALETTE | BG_WRAP | BG_CHARBLOCK_2 | 29<<8 ;
REG_BG3CNT = BG_TEXTE_256x256 | BG_1_PALETTE | BG_WRAP | BG_CHARBLOCK_3 | 28<<8 ;

CopieDMA((void*)image1_Palette, (void*)Palette, 256, DMA_16im);

CopieDMA((void*)image1_Tiles, (void*)CharBaseBlock(0), 2816, DMA_16im);
CopieDMA((void*)image1_Map,(void*)ScreenBaseBlock(31),1024, DMA_16im);

CopieDMA((void*)image2_Tiles, (void*)CharBaseBlock(1), 4096, DMA_16im);
CopieDMA((void*)image2_Map,(void*)ScreenBaseBlock(30),1024, DMA_16im);

CopieDMA((void*)image3_Tiles, (void*)CharBaseBlock(2), 12928, DMA_16im);
CopieDMA((void*)image3_Map,(void*)ScreenBaseBlock(29),1024, DMA_16im);

CopieDMA((void*)image4_Tiles, (void*)CharBaseBlock(3), 15104, DMA_32im);
CopieDMA((void*)image4_Map,(void*)ScreenBaseBlock(28),1024, DMA_32im);


   while(1)
   {
REG_BG0VOFS = y;
REG_BG0HOFS = x;
switch(REG_TOUCHES){
case TOUCHE_HAUT:
y--;
break;
case TOUCHE_BAS:
y++;
break;
case TOUCHE_GAUCHE:
x--;
break;
case TOUCHE_DROITE:
x++;
break;
}
//Attendre un peu avant la prochaine action
for(c=0;c<120;c++){
while (*scan<160);;
}
}
return 0;
}

void CopieDMA(void* source, void* dest, unsigned int nbval, unsigned int mode)
{
    if (mode == DMA_16im || mode == DMA_32im)
    {
        REG_DMA3SAD = (unsigned int)source;
        REG_DMA3DAD = (unsigned int)dest;
        REG_DMA3CNT = nbval | mode;
    }
}

#53232 - daygo - Tue Sep 06, 2005 10:54 pm

i don't know where is the error....help me!!!!

#53236 - DiscoStew - Tue Sep 06, 2005 11:33 pm

Now, I'm not quite sure of why the 4th background is not showing up, but one thing that works for me when trying code that does the same thing over multiple pieces is to try each one individually (like have just the 1st layer show, then fix it to just show the 2nd, then 3rd, then 4th). When doing this, try not to have the other layers do anything. I'll try looking at it more when I can...

EDIT:
Quote:

CopieDMA((void*)image1_Tiles, (void*)CharBaseBlock(0), 2816, DMA_16im);

CopieDMA((void*)image2_Tiles, (void*)CharBaseBlock(1), 4096, DMA_16im);

CopieDMA((void*)image3_Tiles, (void*)CharBaseBlock(2), 12928, DMA_16im);

CopieDMA((void*)image4_Tiles, (void*)CharBaseBlock(3), 15104, DMA_32im);


I haven't done much GBA programming in a while, but I have this idea. Now, I understand that the values in Bold are the number of words to copy over (2 bytes per word), but the last one (for the last background 15104 words equals 30208 bytes, I believe) seems rather big, especially since you are copying the MapData for all 4 layers into the last 4 slots. That last line of code shown above would write over the information from MapData slots [24] to [31] of the 2kByte boundaries, as well as trying to write data way past the VRAM boundary. Because of this, I would imagine that you would be having trouble showing ALL the layers. Reduce those values to say 4000, just to check, and see if you are still having problems
_________________
DS - It's all about DiscoStew