#41333 - wally - Wed Apr 27, 2005 6:17 pm
How do you determine what attribute 2 should be. I have 5 64x64 tiles, and I can't get them to all load properly. I'm sure it's because I have the wrong number for attribute 2. Could somebody tell me how to determine what this number should be.
Thanks
#41376 - wally - Wed Apr 27, 2005 11:22 pm
I was looking at the drunken coders tutorial. There are 5 256 color 64x64 sprites. I'm modifying a small demo, so I can figure out how to program for the gameboy. I have not been able to get sprite 5 to ever be displayed. It always shows up as a copy of one of the other ones.
//Custom defines
#define REG_VCOUNT *(vu16*)0x4000006 //Our good old vblank counter
//System includes
#include <NDS/NDS.h>
#include <NDS/ARM9/rand.h>
//Artwork includes
#include "resources/pal.h"
#include "resources/pac0.h"
#include "resources/gh0.h"
#include "resources/bg.h"
//-------------------------------------------------------------------
//OAM globals
sSpriteEntry OAMCopy[128];
sSpriteEntry OAMCopySub[128];
//Sprite structure
typedef struct
{
int x,y; //location
int xSpeed, ySpeed; //speed
sSpriteEntry* oam;
}Sprite;
//-------------------------------------------------------------------
//Moves a sprite in OAM memory
void MoveSprite(Sprite* sp)
{
int x = sp->x >> 8;
int y = sp->y >> 8;
sp->oam->attribute[1] &= 0xFE00;
sp->oam->attribute[1] |= x;
sp->oam->attribute[0] &= 0xFF00;
sp->oam->attribute[0] |= y;
}
//-------------------------------------------------------------------
//Initializes the sprites
void NextSprite(Sprite* sp, int number)
{
sp->x += sp->xSpeed;
sp->y += sp->ySpeed;
if(sp->x < 256 || sp->x > 61440) { sp->xSpeed=-sp->xSpeed; }
if(sp->y < 256 || sp->y > 45056) { sp->ySpeed=-sp->ySpeed; }
}
//-------------------------------------------------------------------
//Initializes the sprites
void CreateSprite(Sprite* sp, int number)
{
sp->x = ((5*number)<<10);
sp->y = ((5+number)<<10);
sp->xSpeed = (rand() & (3<<6))+(1<<6);
sp->ySpeed = (rand() & (3<<6))+(1<<6);
sp->oam = &OAMCopy[number];
sp->oam->attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE;
sp->oam->attribute[1] = ATTR1_SIZE_64;
sp->oam->attribute[2] = 0;
}
//-------------------------------------------------------------------
//Initialises OAM, moving all sprites offscreen
void initOAM(void)
{
int i;
for(i = 0; i < 128; i++)
{
OAMCopy[i].attribute[0] = ATTR0_DISABLED;
OAMCopySub[i].attribute[0] = ATTR0_DISABLED;
}
}
//-------------------------------------------------------------------
//Copies OAM buffer to actual OAM memory space
void updateOAM(void)
{
int i;
for(i = 0; i < 128 * sizeof(sSpriteEntry) / 4 ; i++)
{
((uint32*)OAM)[i] = ((uint32*)OAMCopy)[i];
((uint32*)OAM_SUB)[i] = ((uint32*)OAMCopySub)[i];
}
}
//-------------------------------------------------------------------
//Entry point- this is where we start!
int main(int argc, char ** argv) {
int i=0, colourComponent=0;
//turn on the power to the system
powerON(POWER_ALL);
videoSetMode( MODE_0_2D | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE | DISPLAY_BG0_ACTIVE );
videoSetModeSub( MODE_0_2D | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE | DISPLAY_BG0_ACTIVE );
/*
VRAM_A_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_A;
VRAM_B_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_A;
VRAM_C_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_B;
VRAM_D_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_B;
vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_SPRITE,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);
*/
//Set screens to black initially
BG_PALETTE[0] = RGB15(0, 0, 0); //Main screen
BG_PALETTE[512] = RGB15(0, 0, 0); //Sub screen
Sprite sprites[128];
Sprite sprites_sub[128];
initOAM();
//Setup heads
CreateSprite(&sprites[0],0);
CreateSprite(&sprites[1],1);
CreateSprite(&sprites[2],2);
CreateSprite(&sprites[3],3);
CreateSprite(&sprites[4],4);
sprites[0].oam->attribute[2] = 0;
sprites[1].oam->attribute[2] = 4096;
sprites[2].oam->attribute[2] = 8192;
sprites[3].oam->attribute[2] = 12288;
sprites[4].oam->attribute[2] = 16384;
//Load palette and sprite data (main screen)
for(i=0; i<512; i++) { SPRITE_PALETTE[i] = palPalette[i]; }
for(i=0; i<8192; i++) { SPRITE_GFX[i] = pac0Data[i]; }
for(i=8193; i<16384; i++) { SPRITE_GFX[i] = pac1Data[i-8193]; }
for(i=16385; i<24576; i++) { SPRITE_GFX[i] = pac2Data[i-16385]; }
for(i=24577; i<32768; i++) { SPRITE_GFX[i] = pac3Data[i-24577]; }
for(i=32769; i<40960; i++) { SPRITE_GFX[i] = pac4Data[i-32769]; }
//Setup top screen
sprites_sub[0].x = 8;
sprites_sub[0].y = 8;
sprites_sub[0].xSpeed = (8<<8);
sprites_sub[0].ySpeed = (1<<8);
sprites_sub[0].oam = &OAMCopySub[0];
sprites_sub[0].oam->attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE;
sprites_sub[0].oam->attribute[1] = ATTR1_SIZE_64;
sprites_sub[0].oam->attribute[2] = 0;
//Load palette and sprite data (sub screen)
for(i=0; i<512; i++) { SPRITE_PALETTE_SUB[i] = palPalette[i]; }
for(i=0; i<8192; i++) { SPRITE_GFX_SUB[i] = gh0Data[i]; }
//-------------------------------------------------------------------
//Main game loop
bool exitFlag = false;
while (!exitFlag)
{
//Pulse screen colours (disco time!)
if (colourComponent < 31) { colourComponent++; }
else { colourComponent = 0; }
PALETTE[0] = RGB15(colourComponent, 0, 0);
PALETTE[512] = RGB15(0, 0, 31-colourComponent);
//Move heads
NextSprite(&sprites[0],0);
NextSprite(&sprites[1],1);
NextSprite(&sprites[2],2);
NextSprite(&sprites[3],3);
NextSprite(&sprites[4],4);
MoveSprite(&sprites[0]);
MoveSprite(&sprites[1]);
MoveSprite(&sprites[2]);
MoveSprite(&sprites[3]);
MoveSprite(&sprites[4]);
//swiWaitForVBlank();
while(REG_VCOUNT != 190) {;}
updateOAM();
}
return 0;
}
#41385 - tepples - Thu Apr 28, 2005 12:16 am
"Beginners" is currently designated for the GBA platform. If you're on the Nintendo DS, I'll move it.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#41387 - wally - Thu Apr 28, 2005 12:38 am
yes it is for the nintendo ds.
#41460 - wally - Thu Apr 28, 2005 7:05 pm
Ok I finalyl figured it out. Just in case anyone was curious. It was over the 32k size limit. So the first 4 objects were ok, then number 5 was out of range.
#41508 - FluBBa - Fri Apr 29, 2005 9:10 am
64*64*5 = 20480?
_________________
I probably suck, my not is a programmer.
#41553 - wally - Fri Apr 29, 2005 4:44 pm
They are pictures of my kids the 3 sprites. So I can't really make them smaller. But I'll just put the 3 pics on that screen then.
Thanks
#41771 - FluBBa - Sun May 01, 2005 8:34 pm
The VRAM on the DS is still 16bit only access or?
_________________
I probably suck, my not is a programmer.