#44548 - b0on - Thu Jun 02, 2005 8:14 pm
After trying forever to get a sprite to work onscreen, i tried to put a bg, but all it shows is scrambled stuff.
Code: |
for(i=0; i<256; i++) { BG_PALETTE_SUB[i] = bg_palette[i]; }
for(i=0; i<(49152); i++) { BG_GFX_SUB[i] = bg_data[i]; } |
what did i do wrong?
#44551 - josath - Thu Jun 02, 2005 8:21 pm
wow you told us almost nothing besides "it shows scrambled stuff" and then you only post two lines from your code? you don't say what screen mode you are using, what the graphics are, how you converted them, what format you converted them or anything. these would help others to figure out what is wrong.
my only guess is you didn't convert the graphics correctly.
#44553 - strager - Thu Jun 02, 2005 8:25 pm
Maybe you need to change the pallet of each tile, or set the pallet mode in BGxCNT. And, as josath said, please post more information.
#44824 - b0on - Sun Jun 05, 2005 8:59 pm
sorry, i was in hurry.
Code: |
//Custom defines
#define REG_VCOUNT *(vu16*)0x4000006 //Our good old vblank counter
//System includes
#include <NDS/NDS.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; }
}
//-------------------------------------------------------------------
//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;
//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( 31, 21, 11); //Main screen
//BG_PALETTE_SUB[0] = RGB15( 11, 21, 31);//Top screen
// BGs not working
for(i=0; i<256; i++) { BG_PALETTE_SUB[i] = bg_palette[i]; }
for(i=0; i<(49152); i++) { BG_GFX_SUB[i] = bg_data[i]; }
//-------------------------------------------------------------------
//Main game loop
bool exitFlag = false;
while (!exitFlag)
{
//swiWaitForVBlank();
while(REG_VCOUNT != 190) {;}
updateOAM();
}
return 0;
}
|
I cant find a host to host images...
josath dont get angry at me :P
#44831 - DekuTree64 - Sun Jun 05, 2005 9:38 pm
2 things I noticed after a quick read:
1. Why is your VRAM bank allocation commented out?
2: You're not setting BG0CNT to tell it where your map and tile data are. That means the screen block is set to 0, and char block to 0 as well...
But judging by the size of the data you're loading, is it a bitmap? Still need to set BG0CNT for that.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#44868 - b0on - Mon Jun 06, 2005 10:09 am
1) When i try to compile it in ndsdev, it doesn't recognize Vram_core_a and b and c and d.
2)how do i set bg0cnt?
thanks anyway for ur help
#44871 - Ethos - Mon Jun 06, 2005 1:08 pm
b0on wrote: |
1) When i try to compile it in ndsdev, it doesn't recognize Vram_core_a and b and c and d.
2)how do i set bg0cnt?
thanks anyway for ur help |
1) Uncomment only:
vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_SPRITE,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);
2) Well I don't see where you are getting your palette or bg data from?
No includes at top of program. Also in Mode 0 you have to load tiles and a map, and set the Control Register appropriately.
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)
#44889 - b0on - Mon Jun 06, 2005 4:22 pm
i forgot to add #include resources/bg.h
so if i have the map data, what do i do?
which mode allows to put bgs without maps?
thanks again a lot
#45899 - b0on - Thu Jun 16, 2005 9:08 am
Since noone replied, could someone please just post an example(or code) that just shows a bg.
thanks again alot.
#45956 - arog - Fri Jun 17, 2005 4:13 am
Quote: |
Since noone replied, could someone please just post an example(or code) that just shows a bg. |
Did you go through any of the examples that come with ndslib?
Here's a modified version of one of dovoto's 256 color backgrounds I made:
http://www.aaronrogers.com/nintendods/temp/256_color_bmp.zip
Screenshot here:
[Images not permitted - Click here to view it]
I haven't tested/updated it with the latest ndslib, so who knows if it still works. :)
- Aaron Rogers
http://www.aaronrogers.com/nintendods/