gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > sprite problem after upgrading libnds (and devkit) [SOLVED]

#153152 - silent_code - Tue Mar 25, 2008 7:05 pm

hi guys!

can anyone tell me what is wrong with this code??? no$ tells me it's causing an error. commenting it out will yield no errors, but one right before the first line of code in main - what about that?
Code:

j = 0;

for(i = 0; i < 256; i++)
SPRITE_PALETTE[i] = ((uint16*)sprites_pal_bin)[i]; // works

for(i = 0; i < 512; i++, j++)
//      SPRITE_GFX[j] = ((u16*)player8_img_bin)[i]; // does not work
      SPRITE_GFX[j] = (uint16)(4 << 8 | 4); // doesn't eighter!

// at this point no$ shows 513 errors, then, no more are generated throughout the rest of the code!

// all this works:
for(i = 0; i < 256; i++)
BG_PALETTE[i] = ((uint16*)bg8_pal_bin)[i];

for(i = 0; i < bg8_img_bin_size / (sizeof(uint32)); i++)
((uint32*)SCREEN_BASE_BLOCK(0))[i] = ((uint32*)bg8_img_bin)[i];

it all worked before i upgraded to the most recent tools and libs.

backgrounds will show, palettes (bg and sprite) will load and work without trouble, the only problem is that sprite graphics data can't be writen, but i'm sure NOT writing bytes, but halfwords!

i know i could use dma etc., but i want to know WHY this doesn't work!

btw: my vram setup:
Code:

videoSetMode(MODE_5_2D |
      DISPLAY_SPR_ACTIVE |
      DISPLAY_BG3_ACTIVE |
      DISPLAY_BG2_ACTIVE |
      DISPLAY_SPR_1D);

vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
      VRAM_B_MAIN_SPRITE,
      VRAM_C_SUB_BG_0x06200000,
      VRAM_D_LCD);

i don't get it!

any help is appreciated! :^D
thanks!

ps: dualis' debugging tools show that indeed *NOTHING* is written to SPRITE_GFX! all pixels are set to 0!

EDIT: CRAP!!! i need to check j!!! ... okay, j is propperly initialized with 0, so that's not the problem!


Last edited by silent_code on Wed Mar 26, 2008 2:24 am; edited 1 time in total

#153157 - Miked0801 - Tue Mar 25, 2008 8:17 pm

Double check your define for SPRITE_GFX. If it's pointing at an odd, unaligned address or is cast incorrectly, then that would explain why no$ is grumbling. Also, for sanity's sake, please use parenthesis on your or/shifts. The Order of Presidence on those is not what you expect.

Also, make sure that the area of memory that SPRITE_GFX is pointing at is enabled and/or in the correct video mode for the operation.

#153162 - silent_code - Tue Mar 25, 2008 9:58 pm

thanks! your post is totally valid... i changed the code a bit for testing to see if *anything* will go, so the usual lisp (for those who don't know: "Lots of Irritating Superfluous Parentheses") got left out. ;^) even assigning a single value won't work. i'm using 4bit sprites, btw.

as stated before, it worked just before switching libnds (and devkit, but that shouldn't really be the problem). in another project, i compiled with the same setup, but that was using the dma halfword transfer, things are okay.

define from libnds, file "memory.h", line 80:
Code:

#define SPRITE_GFX         ((uint16*)0x6400000)

gbatek says:
Quote:
06400000h VRAM - Engine A, OBJ VRAM (max 256KB)

which is pretty much the same...

also my first line in main is:
Code:

powerON(POWER_ALL_2D);


so, what's wrong? i *never* has such problems! (no$ always reportet 0/1 error for this code - total, that is!)

can anyone confirm that?

#153167 - wintermute - Tue Mar 25, 2008 11:24 pm

use VRAM_B_MAIN_BG_0x06040000.

Dovoto rearranged the default macros a little bit and they're not quite what you expect.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#153176 - silent_code - Wed Mar 26, 2008 1:28 am

i'll try that, thank you! :^)
but what i still don't understand is, why do the other memory areas work as expected? i guess this is subject to change, isn't it?

EDIT: still nothing... :^(
now i have:
Code:

vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
         VRAM_B_MAIN_BG_0x06040000,
         VRAM_C_SUB_BG_0x06200000,
         VRAM_D_LCD);


i'll try to replace SPRITE_GFX with 0x06040000 and use the vram setup i had before.

EDIT2: again, nothing.

i'm out of ideas... any other suggestions?

#153179 - silent_code - Wed Mar 26, 2008 2:05 am

i stripped it down to this:
Code:


#include <nds.h>

int main(void)
{
   powerON(POWER_ALL_2D);
   irqInit();

   videoSetMode(   MODE_5_2D |
               DISPLAY_SPR_ACTIVE |
               DISPLAY_BG3_ACTIVE |
               DISPLAY_BG2_ACTIVE |
               DISPLAY_SPR_1D);

   vramSetMainBanks(   VRAM_A_MAIN_BG_0x06000000,
                  VRAM_B_MAIN_SPRITE,
                  VRAM_C_SUB_BG_0x06200000,
                  VRAM_D_LCD);

   videoSetModeSub(MODE_0_2D);
   vramSetBankC(VRAM_C_SUB_BG_0x06200000);

   for(uint16 i = 0; i < 256; i++)
      SPRITE_PALETTE[i] = (uint16)(0x0F0F & i | i); // ... for the fun of it

   for(uint16 i = 0; i < 512; i++)
      SPRITE_GFX[i] = (uint16)0x1234;

   while(true);

   return(0);
}



still i get nothing written to SPRITE_GFX (palette works as usually) and 513 errors... if i comment the relevant code segment just the usual single error (???) is reported.
???


Last edited by silent_code on Wed Mar 26, 2008 2:10 am; edited 1 time in total

#153181 - tepples - Wed Mar 26, 2008 2:10 am

Does this work?
Code:
vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
         VRAM_B_MAIN_SPRITE_0x06400000,
         VRAM_C_SUB_BG_0x06200000,
         VRAM_D_LCD);

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#153182 - wintermute - Wed Mar 26, 2008 2:11 am

wintermute wrote:
use VRAM_B_MAIN_BG_0x06040000.

Dovoto rearranged the default macros a little bit and they're not quite what you expect.


I'm an idiot, copy, paste & post without checking, sorry

VRAM_B_MAIN_SPRITE_0x06400000 is what I meant

damn you tepples, just beat me to it :P
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#153184 - silent_code - Wed Mar 26, 2008 2:20 am

GREAT!

THANKS A LOT, both of you! :?)

it works, perfectly! so after all, it was incorrect mapping. i knew it had to be, but i haven't done any nds screwing in months, so i wasn't really up to date and didn't know about those changes.

you have saved me hours of looking through header files.

thank you, again! :^D

ps: now i can finally go to bed... it's 2:19am over here. ;?D

EDIT: now i see the damn thing was mapped to the first offset by default, instead of being mapped without offset!

#153185 - silent_code - Wed Mar 26, 2008 2:24 am

PPPS: my girlfriend left me, can you guys fix that, too?

#153187 - tepples - Wed Mar 26, 2008 2:41 am

silent_code wrote:
PPPS: my girlfriend left me, can you guys fix that, too?

Maybe you need a new animal girlfriend in DS land. I can help you fix that.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#153189 - silent_code - Wed Mar 26, 2008 3:01 am

no new one, i want the old one back... :^C
i like animals, though.
(what does that even mean, tepples?)

back on topic: what about the initial error no$ keeps reporting (put in a while(true); at the very beginning of main())?

#153191 - wintermute - Wed Mar 26, 2008 5:01 am

offtopic: why did she leave you? I had to promise mine I'd spend a bit less time on the computer & more quality time with her.

ontopic: no$ complains about endless loops that drain the battery
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#153214 - silent_code - Wed Mar 26, 2008 2:38 pm

<OT> wasn't because of me or something i did. she's "lost" her feelings... but i really think it's because she's got a NPD (google that), then add ignorance and intolerance to that. she even told me, she might need some professional help - although she doesn't know about NPDs. well, in fact, i don't understand it at all. i'm very sad and still love her and all, because she *can* be such a beautiful person, if she allowed herself.</OT>

hm, interesting. i usually ignore that error and no$ tells me everything is good. it's just that there's the total of "one" errors.

#153252 - tepples - Thu Mar 27, 2008 2:11 am

silent_code wrote:
no new one, i want the old one back... :^C
i like animals, though.
(what does that even mean, tepples?)

Wiki wiki wiki.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#153266 - silent_code - Thu Mar 27, 2008 1:41 pm

ha, ha, ha! :^D
i don't think ACWW will do me any good, but willingnes counts, so tepples, you get a "+" for sympathy (in a sims-sim). ;^)