background and text

Post Reply
OdnetninI
Posts: 19
Joined: Sat Nov 20, 2010 12:38 pm

background and text

Post by OdnetninI » Sat Jul 02, 2011 9:04 pm

hello, it is my first post, and i have two serius problems(sorry for my English, I'm Spanish).
I need to put text with a bg and this is my code:

Code: Select all

Map=NULL;
	text="OLA";
	u16 value = 0;	
	u16 tsize = strlen(text);
	u8* string = (u8*) calloc (tsize, sizeof(u8));
	for (i = 0; i < tsize; i ++) {
		value = ((int)(text[i])) - 32;
		if (value < 0) value = 0;
		string[i] = value;
	}
	for(i=0;i<tsize;i++){
		Map[x+y*32]=string[i];
		x++;
		if(x>32)y++;
	}
	free(string);
	memcpy((void*)((((0)*0x800) + 0x06000000)), Map, 1024);
before, i load the pal and tiles of bg, and a bg named wood.
when i compile and execute, nosgba shows this:
Image
and the second problem is using my fuction to load bg, the bg0 doesn't shows palette:

Code: Select all

void ODI_Crear_Fondo(u8 pantalla, u8 capa, int slot,int ancho, int alto){
	
	s32 bg;

	if ((ancho == 256) && (alto == 256)) {
		bg = BG_32x32;
	}
	if ((ancho == 512) && (alto == 256)) {
		bg = BG_64x32;
	}
	if ((ancho == 256) && (alto == 512)) {
		bg = BG_32x64;
	}
	if ((ancho == 512) && (alto == 512)) {
		bg = BG_64x64;
	}
	
	if(pantalla==1){
		switch (capa){
			case 0:
				REG_BG0CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1) | BG_PRIORITY(0);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((1)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((0)*0x800) + 0x06000000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06880000) + (0 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
				
			case 1:
				REG_BG1CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(2) | BG_PRIORITY(1);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((2)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((1)*0x800) + 0x06000000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06880000) + (1 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
				
			case 2:
				REG_BG2CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(2) | BG_TILE_BASE(3) | BG_PRIORITY(2);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((3)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((2)*0x800) + 0x06000000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06880000) + (2 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
				
			case 3:
				REG_BG3CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(3) | BG_TILE_BASE(4) | BG_PRIORITY(3);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((4)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)((((3)*0x800) + 0x06000000)+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x05000000)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
		}
	}
	if(pantalla==0){
		switch (capa){
			case 0:
				REG_BG0CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((1)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((0)*0x800) + 0x06200000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06898000) + (0 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
				
			case 1:
				REG_BG1CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(2) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((2)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((1)*0x800) + 0x06200000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06898000) + (1 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
				
			case 2:
				REG_BG2CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(2) | BG_TILE_BASE(3) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((3)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((2)*0x800) + 0x06200000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06898000) + (2 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
				
			case 3:
				REG_BG3CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(3) | BG_TILE_BASE(4) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((4)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)((((3)*0x800) + 0x06200000)+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x05000400)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
		}
	}
	ODI_Scroll_Fondo(pantalla,capa,0,0);
}
help please
Attachments
Sin título.png
(37.22 KiB) Not downloaded yet

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: background and text

Post by zeromus » Sun Jul 03, 2011 2:54 am

1a. you are very confused. you set MAP to NULL, and then write values into the map. all this is going to do is make your program crash eventually.
1b. you have not posted enough code. we dont know how your BG is setup, we dont know how your tiles are setup, we dont know how MAP is declared. you probably don't know how much stuff to paste. it would be better if you cleaned your entire project and zipped it up.
2. why did you comment out the lines that switch the vram banks back to palettes instead of LCDC? With no vram assigned to extended palettes, the extended palettes are all black

OdnetninI
Posts: 19
Joined: Sat Nov 20, 2010 12:38 pm

Re: background and text

Post by OdnetninI » Sun Jul 03, 2011 11:15 am

The variables are:

Code: Select all

char* TILES[2][16];char* MAP[2][16];char* PAL[2][16];
u32 tiles_size[2][16];u32 map_size[2][16];u32 pal_size[2][16];
char* Map;
int i;
char* text;
int x,y;
I coment that lines because I put then after, and if is necesary I put then again.
I load the tiles and bg:

Code: Select all

DI_CargarFondosSencillos(1,3,1,"wood",256,256);
	ODI_CargarPalNitroFs(1,"textFont", 0);
	ODI_CargarTilesNitroFs(1,"textFont", 0);
	ODI_Crear_Fondo(1,0,0,256,256);
whith:

Code: Select all

void ODI_Crear_Fondo(u8 pantalla, u8 capa, int slot,int ancho, int alto){
	
	s32 bg;

	if ((ancho == 256) && (alto == 256)) {
		bg = BG_32x32;
	}
	if ((ancho == 512) && (alto == 256)) {
		bg = BG_64x32;
	}
	if ((ancho == 256) && (alto == 512)) {
		bg = BG_32x64;
	}
	if ((ancho == 512) && (alto == 512)) {
		bg = BG_64x64;
	}
	
	if(pantalla==1){
		switch (capa){
			case 0:
				REG_BG0CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1) | BG_PRIORITY(0);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((1)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((0)*0x800) + 0x06000000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06880000) + (0 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
				
			case 1:
				REG_BG1CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(2) | BG_PRIORITY(1);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((2)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((1)*0x800) + 0x06000000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06880000) + (1 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
				
			case 2:
				REG_BG2CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(2) | BG_TILE_BASE(3) | BG_PRIORITY(2);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((3)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((2)*0x800) + 0x06000000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06880000) + (2 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
				
			case 3:
				REG_BG3CNT = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(3) | BG_TILE_BASE(4) | BG_PRIORITY(3);
				vramSetBankE(VRAM_E_LCD);
				memcpy((void*)((((4)*0x4000) + 0x06000000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06000000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)((((3)*0x800) + 0x06000000)+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x05000000)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankE(VRAM_E_BG_EXT_PALETTE);
				break;
		}
	}
	if(pantalla==0){
		switch (capa){
			case 0:
				REG_BG0CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((1)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((0)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((0)*0x800) + 0x06200000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06898000) + (0 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
				
			case 1:
				REG_BG1CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(2) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((2)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((1)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((1)*0x800) + 0x06200000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06898000) + (1 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
				
			case 2:
				REG_BG2CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(2) | BG_TILE_BASE(3) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((3)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((2)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)(((((2)*0x800) + 0x06200000))+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x06898000) + (2 << 13)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
				
			case 3:
				REG_BG3CNT_SUB = BgType_Text8bpp | bg | BG_COLOR_256 | BG_MAP_BASE(3) | BG_TILE_BASE(4) | BG_PRIORITY(0);
				vramSetBankH(VRAM_H_LCD);
				memcpy((void*)((((4)*0x4000) + 0x06200000)), TILES[pantalla][slot], tiles_size[pantalla][slot]);
				if(ancho==256&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], map_size[pantalla][slot]);
				}
				if(ancho==512&&alto==256){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==256&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
				}
				if(ancho==512&&alto==512){
					memcpy((void*)((((3)*0x800) + 0x06200000)), MAP[pantalla][slot], 4096);
					u16 siguiente;
					siguiente = ((((ancho - 1) >> 8) + 1) << 11);
					memcpy((void*)((((3)*0x800) + 0x06200000)+4096), MAP[pantalla][slot]+siguiente, 4096);
				}
				memcpy((void*)((0x05000400)), PAL[pantalla][slot], pal_size[pantalla][slot]);
				//vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
				break;
		}
	}
	ODI_Scroll_Fondo(pantalla,capa,0,0);
}
void ODI_CargarTilesNitroFs(u8 pantalla,const char* archivo, int slot){

	sprintf(filename, "%s/%s_Tiles.bin", Carpeta,archivo);
	file_id = fopen(filename, "rb");
	if (file_id) {
		fseek(file_id, 0, SEEK_END);
		tiles_size[pantalla][slot] = ftell(file_id);
		rewind(file_id);
		TILES[pantalla][slot] = (char*) calloc (tiles_size[pantalla][slot], sizeof(char));
		fread(TILES[pantalla][slot], 1, tiles_size[pantalla][slot], file_id);
	}
	fclose(file_id);
}
void ODI_CargarMapNitroFs(u8 pantalla,const char* archivo, int slot){

	sprintf(filename, "%s/%s_Map.bin", Carpeta,archivo);
	file_id = fopen(filename, "rb");
	if (file_id) {
		fseek(file_id, 0, SEEK_END);
		map_size[pantalla][slot] = ftell(file_id);
		rewind(file_id);
		MAP[pantalla][slot] = (char*) calloc (map_size[pantalla][slot], sizeof(char));
		fread(MAP[pantalla][slot], 1, map_size[pantalla][slot], file_id);
	}
	fclose(file_id);
}
void ODI_CargarPalNitroFs(u8 pantalla,const char* archivo, int slot){

	sprintf(filename, "%s/%s_Pal.bin", Carpeta,archivo);
	file_id = fopen(filename, "rb");
	if (file_id) {
		fseek(file_id, 0, SEEK_END);
		pal_size[pantalla][slot] = ftell(file_id);
		rewind(file_id);
		PAL[pantalla][slot] = (char*) calloc (pal_size[pantalla][slot], sizeof(char));
		fread(PAL[pantalla][slot], 1, pal_size[pantalla][slot], file_id);
	}
	fclose(file_id);
}
void ODI_CargarFondosSencillos(u8 pantalla,u8 capa,int slot,const char* archivo,int ancho, int alto){
	ODI_Cargar_Fondos_NitroFs(pantalla,archivo, slot);
	ODI_Crear_Fondo(pantalla,capa,slot,ancho,alto);	
}

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: background and text

Post by zeromus » Sun Jul 03, 2011 9:47 pm

Not good enough. Now I need to see what parameters you passed to ODI_CargarFondosSencillos(). Not to mention, the source art.
Quit wasting time and zip up your project.

OdnetninI
Posts: 19
Joined: Sat Nov 20, 2010 12:38 pm

Re: background and text

Post by OdnetninI » Sun Jul 03, 2011 10:31 pm

take the code, there are two rar, since one is the library and the other is the draft text, is the library I'm DEVELOPING
http://www.mediafire.com/?ccfsi24ss1il0p5
http://www.mediafire.com/?app8fxdztmssu8z

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: background and text

Post by zeromus » Tue Jul 05, 2011 8:19 am

BgType_Text8bpp maps such as what youre using are not char. they are u16. you are writing garbage to your map.

OdnetninI
Posts: 19
Joined: Sat Nov 20, 2010 12:38 pm

Re: background and text

Post by OdnetninI » Tue Jul 05, 2011 3:52 pm

I modificate the declaration of Map, but i alrady have a problem. The letters are separated whith a tile but space should not be.
The new code:

Code: Select all

/*---------------------------------------------------------------------------------
								ODILib
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <fat.h>
#include <filesystem.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <dirent.h>
#include <odi.h>
/*---------------------------------------------------------------------------------
								Variables
---------------------------------------------------------------------------------*/
u16* Map[1024]={};
int i;
char* text;
int x,y;
/*---------------------------------------------------------------------------------
								Defines
---------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------------
								Funciones
---------------------------------------------------------------------------------*/

//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	ODI_Init();
	//Iniciar Sprites
		oamInit(&oamMain, SpriteMapping_1D_128, true);
		oamInit(&oamSub, SpriteMapping_1D_128, true);
	//Iniciar nitrofs	
		if(nitroFSInit());
		sprintf(Carpeta, "%s", "");
		
	ODI_CargarFondosSencillos(1,3,1,"wood",256,256);
	ODI_CargarPalNitroFs(1,"textFont", 0);
	ODI_CargarTilesNitroFs(1,"textFont", 0);
	ODI_Crear_Fondo(1,0,0,256,256);
	
	text="OLA";
	u16 value = 0;	
	u16 tsize = strlen(text);
	u8* string = (u8*) calloc (tsize, sizeof(u8));
	for (i = 0; i < tsize; i ++) {
		value = ((int)(text[i])) - 32;
		if (value < 0) value = 0;
		string[i] = value;
	}
	for(i=0;i<tsize;i++){
		Map[x+y*32]=string[i];
		x++;
		if(x>32)y++;
	}
	free(string);
	 swiCopy(Map,(u16*)((((0)*0x800) + 0x06000000)), 1024);
	
	while(1) {
		
		ODI_Esperar60frames();
		//no tocar
		 if(ODI_HELD_DOWN){}
	}
}
Image
Image
Attachments
2.png
tiles
(42.45 KiB) Not downloaded yet
1.png
error build
(20.87 KiB) Not downloaded yet

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: background and text

Post by zeromus » Tue Jul 05, 2011 6:47 pm

post buildable sources.
what does x start off equal to?
if youre tired of posting buildable sources you might consider using a public source code repository

OdnetninI
Posts: 19
Joined: Sat Nov 20, 2010 12:38 pm

Re: background and text

Post by OdnetninI » Tue Jul 05, 2011 10:47 pm

but, how i can solve the problem?

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests