I am trying to read a pcx file and then display it as a tiled background. It works fine on emulators (DeSmuME & No$gba) but the display is corrupted on my DSL and DSi. This should be simple but I am surely doing something stupid.
The image is 128x128 pixels, 256 col. I am trying to display it in the top left corner of the text background (Mode 0, layer 0). I use the gfx and palette data from the pcx file but I create my own map in code (a simple incrementing tile counter in the area I want the image). On the real DS hardware the last tile is missing plus some (between around 5 to 10 for the DSL and DSi respectively) at the start.
My test code is here, why does this not work on real hardware but is good on emulators?
Code: Select all
/* PCX display test */
#include <nds.h>
#include <filesystem.h>
#include <stdio.h>
int main(int argc, char **argv) {
// setup video
videoSetMode(MODE_0_2D);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankE(VRAM_E_BG_EXT_PALETTE);
// init nitro
nitroFSInit();
// init background for our pcx
s16 bg = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0, 1);
// load the PCX file from filesystem (the file length is hardcoded here as this is a test)
u16 pcxSize = 7944;
FILE* file = fopen("yoshi.pcx", "rb");
u8* pcxData = (u8*)malloc(pcxSize);
fread(pcxData, pcxSize, 1, file);
fclose(file);
// 'load' the PCX
sImage image;
loadPCX(pcxData, &image);
// make it into tiles
imageTileData(&image);
// copy tiles to vram (skip 1st tile as this is the background tile)
dmaCopy(image.image.data16, bgGetGfxPtr(bg)+32, image.height*image.width);
// copy palette to vram
dmaCopy(image.palette, BG_PALETTE, 512);
// create a map to show the image at TLC od screen
u16 mapSize = 2048;
u16* mapData = (u16*)malloc(mapSize);
memset(mapData, 0, mapSize);
u16 i, j;
for(j=0; j<16; j++) {
for(i=0; i< 16; i++) {
mapData[(j*32)+i] = (j*16)+i+1;
}
}
// copy map to vram
dmaCopy(mapData, bgGetMapPtr(bg), mapSize);
while(true);
return 0;
}