NDS-Homebrew-Development icon indicating copy to clipboard operation
NDS-Homebrew-Development copied to clipboard

improved-simple: OAM Graphics allocations happening before oamInit()

Open clamintus opened this issue 2 years ago • 0 comments

First of all I'm a total noob who just got started with console homebrew, so I apologize for any error or imprecision :v Okay so I was practicing with improved-simple trying to draw the three squares in the sub OAM with different colors. They all got displayed on screen but I couldn't get to make them with different colors. If I simply change the original code and allocate the GFX for every sprite like this:

        u16* mainGFX = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_Bmp);
	u16* subGFX = oamAllocateGfx(&oamSub, SpriteSize_16x16, SpriteColorFormat_Bmp);
	u16* subGFX2 = oamAllocateGfx(&oamSub, SpriteSize_16x16, SpriteColorFormat_Bmp);
	u16* subGFX3 = oamAllocateGfx(&oamSub, SpriteSize_16x16, SpriteColorFormat_Bmp);

and then I call createSquare() for every sprite like this (I've slightly modified the function to have the OAM entry id passed as first argument instead of having it hardcoded as 1):

        createSquare(1, touch.px, touch.py, &oamMain, mainGFX, ARGB16(1, 31, 12, 12));
	createSquare(1, touch.px, touch.py, &oamSub, subGFX, ARGB16(1, 12, 31, 12));
	createSquare(2, pos_x, pos_y, &oamSub, subGFX2, ARGB16(1, 0, 0, 31));
	createSquare(3, pos_x2, pos_y2, &oamSub, subGFX3, ARGB16(1, 0, 31, 0));

all I get is one square in the top screen and three of them with the same color (despite having passed completely different values in the createSquare() calls) in the bottom screen:

immagine

Basically, all squares in the bottom screen take the last color passed to dmaFillHalfWords(), ignoring the previous ones. I scratched my head for half a day trying to troubleshoot this (I've even compared my code to other examples like multi-simple where the sprites do display different colors on the same screen, but I didn't manage to find the problem), when I suddenly discovered that subGFX, subGFX2 and subGFX3 all point to the same address (!)

immagine

After googling a bit why oamAllocateGfx() always returned the same address to my subGFX* pointers, I found some hint regarding the use of oamInit(). I checked the other examples like multi-simple and there, in fact, oamInit() was called before any oamAllocateGfx() call! And so when I fixed the order of the calls, suddenly it worked! (yeeee)

YEEEEEEEEE

I felt reeeeeally stupid because I didn't know why it didn't work, but at last it turned out that the problem was not me but the code in this example :') Both the code and the tutorial do not give any hint about needing to have oamInit() called before any other OAM interaction. Please correct this so other people don't need to go through the same hassle trying to figure out why their code is not working. This is not very noob-friendly :D

clamintus avatar Jul 30 '21 18:07 clamintus