#111081 - spagnutty - Mon Dec 04, 2006 12:28 am
For part of my program I'm working on drawing a number pad on the DS for id entry. I'm having a problem drawing more than 8 sprites. Each button is a 64x64 sprite loaded from a pcx file. They share the same color palette. The first 8 sprites draw correctly, but sprites 9 and 0 incorrectly show up as 1 and 2.
I'm pretty sure that the problem is that I am using up all of my sprite memory space. From what I've gathered on the forums you can get around the memory limitation by enabling DISPLAY_SPR_1D_SIZE_256. Unfortunately when I try to put that into videoSetMode, my images mess up. Only part of the sprite is drawn and pieces of other sprites are drawn with it.
What exactly do I need to do to so I can show more sprites?
Here's my hopefully relevant code:
Thank you!
Last edited by spagnutty on Mon Dec 04, 2006 5:15 pm; edited 1 time in total
I'm pretty sure that the problem is that I am using up all of my sprite memory space. From what I've gathered on the forums you can get around the memory limitation by enabling DISPLAY_SPR_1D_SIZE_256. Unfortunately when I try to put that into videoSetMode, my images mess up. Only part of the sprite is drawn and pieces of other sprites are drawn with it.
What exactly do I need to do to so I can show more sprites?
Here's my hopefully relevant code:
Code: |
//simple sprite struct
typedef struct { int x,y; int dx, dy; SpriteEntry* oam; int gfxID; }Sprite; void initOAM(void) { int i; for(i = 0; i < 128; i++) { OAMCopy[i].attribute[0] = ATTR0_DISABLED; } } void updateOAM(void) { unsigned int i; for(i = 0; i < 128 * sizeof(SpriteEntry) / 4 ; i++) { ((uint32*)OAM)[i] = ((uint32*)OAMCopy)[i]; } } void MoveSprite(Sprite* sp) { int x = sp->x; int y = sp->y; sp->oam->attribute[1] &= 0xFE00; sp->oam->attribute[1] |= x; sp->oam->attribute[0] &= 0xFF00; sp->oam->attribute[0] |= y; } /* Set up the bottom screen as a frame buffer, and set up * the top screen as a text console. */ void video_setup () { // put our main screen on the bottom lcdSwap (); // set the sub background up for text display videoSetModeSub (MODE_0_2D | DISPLAY_BG0_ACTIVE); // set the main screen for two extended rotation backgrounds and sprites videoSetMode (MODE_5_2D | DISPLAY_SPR_1D | // DISPLAY_SPR_1D_SIZE_256 ? DISPLAY_SPR_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE); // set up the memory banks vramSetMainBanks (VRAM_A_MAIN_BG, VRAM_B_MAIN_BG, VRAM_C_SUB_BG, VRAM_D_LCD); // tell the DS that background 3 is: // a 16 bit bitmap of size 256*256 pixels, // at memory base 0 // at the most visible priority BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE (0) | BG_PRIORITY (0); mainFrontLayer = (u16*) BG_BMP_RAM (0); // tell the DS that background 2 is: // a 16 bit bitmap of size 256*256 pixels, // at memory base 8 // at the 2nd most visible priority BG2_CR = BG_BMP16_256x256 | BG_BMP_BASE (8) | BG_PRIORITY (1); mainBackLayer = (u16*) BG_BMP_RAM (8); // since MODE_5_2D uses rotation backgrounds, we have to specify all this // crap just to get the displays to show up BG3_XDX = 1 << 8; BG3_XDY = 0; BG3_YDX = 0; BG3_YDY = 1 << 8; BG2_XDX = 1 << 8; BG2_XDY = 0; BG2_YDX = 0; BG2_YDY = 1 << 8; // start of by clearing everything int x, y; for (y = 0; y < 256; y++) for (x = 0; x < 256; x++) { mainBackLayer [x * 256 + y] = 0; mainFrontLayer [x * 256 + y] = 0; } } void getImageData (sImage * images) { //load our pcx file into an image loadPCX((u8*)numpad1_pcx, &images[0]); loadPCX((u8*)numpad2_pcx, &images[1]); loadPCX((u8*)numpad3_pcx, &images[2]); loadPCX((u8*)numpad4_pcx, &images[3]); loadPCX((u8*)numpad5_pcx, &images[4]); loadPCX((u8*)numpad6_pcx, &images[5]); loadPCX((u8*)numpad7_pcx, &images[6]); loadPCX((u8*)numpad8_pcx, &images[7]); loadPCX((u8*)numpad9_pcx, &images[8]); loadPCX((u8*)numpad0_pcx, &images[9]); //tile it so it is usefull as sprite data int i; for (i = 0; i < NUM_SPRITES; i++) imageTileData(&images[i]); } static int ds_show_numpad (lua_State *L) { vramSetBankE(VRAM_E_MAIN_SPRITE); Sprite sprites[NUM_SPRITES]; sImage images[NUM_SPRITES]; getImageData(images); // Initialize the colors of the Sprite palette int i; int j; for(i = 0; i < 256; i++) SPRITE_PALETTE[i] = images[0].palette[i]; // Sprite initialisation for (j = 0; j < NUM_SPRITES; j++) for(i = j*64*32; i < 64*32*(j+1); i++) SPRITE_GFX[i] = images[j].data16[i - 64*32*j]; initOAM(); for(i = 0; i < NUM_SPRITES; i++) { sprites[i].oam = &OAMCopy[i]; sprites[i].gfxID = i*128; //set up our sprites OAM entry attributes sprites[i].oam->attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE; sprites[i].oam->attribute[1] = ATTR1_SIZE_64; sprites[i].oam->attribute[2] = sprites[i].gfxID; } position_sprites(sprites); swiWaitForVBlank(); updateOAM(); return 1; } static int ds_setup (lua_State *L) { irq_setup (); video_setup (); console_setup (); sound_setup (); return 1; } |
Thank you!
Last edited by spagnutty on Mon Dec 04, 2006 5:15 pm; edited 1 time in total