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 > Affine transformation paremeters 0-7 valid, but I NEED 0-31

#169500 - LOst? - Sat Jul 18, 2009 11:47 am

Okay, I have a quick sprite system that allows 32 scaled sprites (0-31).

Code:

SpriteEntry            OamEntry [128] VAR_IN_EXRAM;
SpriteRotation*         pOamRotation   = (SpriteRotation*) OamEntry;


void ClearOAM ()
{
...
uRotPos = 0;
}

void AddOAMScaled (...)
{
if (uRotPos >= 32)
 return;

...
         // Set X offset, affine transformation index, sprite size
         OamEntry [uOamPos].attribute [1] = ((x & 0x1FF) |
                                    ((uRotPos & 0x1F) << 9) |
                                    ((size & 0x3) << 14));

...

         // Scale the sprite using one of the 32 affine transformation parameters
         pOamRotation [uRotPos].hdx      = (signed short) ((signed int) 0x10000 / (signed int) shScaleWidth);
         pOamRotation [uRotPos].hdy      = 0;
         pOamRotation [uRotPos].vdx      = 0;
         pOamRotation [uRotPos].vdy      = (signed short) ((signed int) 0x10000 / (signed int) shScaleHeight);

uRotPos++;
}


So once uRotPos >= 8, the sprite is just one color (all scaled to a wierd value). Because there is no DS emulator with accurate debugging information, I am stuck! Help plz ;)

Is there anything I have missed?
_________________
Exceptions are fun

#169505 - eKid - Sun Jul 19, 2009 7:36 am

Are you copying the entire OamEntry array into the OAM? (and not something like half or just how many you put data into?)

#169511 - LOst? - Sun Jul 19, 2009 9:30 pm

eKid wrote:
Are you copying the entire OamEntry array into the OAM? (and not something like half or just how many you put data into?)


Holy!

I just fixed a bug earlier today where only 32 sprites made it instead of 128. So I guess this fixed itself!

Changed:
Code:

      DC_FlushRange (OamEntry, 256);
      dmaCopyHalfWords (3, OamEntry, OAM, 256);


Into this:
Code:

      DC_FlushRange (OamEntry, 1024);
      dmaCopyHalfWords (3, OamEntry, OAM, 1024);




Okay, into another problem of mine then:
Sprite extended palettes are supposed to have 2 slots. I can only write to 1 slot. This code updates slot 0:

Code:

void UploadOBJExtPal0 (const unsigned short* pcwPalette, unsigned int uNumPaletteEntries,
                  unsigned short wPalettePage, unsigned short wPaletteIndex)
{
   // Prepare VRAM extended palette bank for writing
   VRAM_G_CR = VRAM_ENABLE | VRAM_G_LCD;

   // DMA copy prio 3
   dmaCopyHalfWords (3, pcwPalette, ((VRAM_G + (wPalettePage << 8)) + wPaletteIndex), uNumPaletteEntries << 1);

   // Set to extended palette mode (Bank G holds OBJExtPal 0 and 1)
   VRAM_G_CR = VRAM_ENABLE | VRAM_G_SPRITE_EXT_PALETTE;
}

... and it works.

Now, this code should update slot 1 (note the only change is that I add 16 to the 256 palette page since the G bank should be 16 kb (as well as the I bank for use with the sub screen's extended sprite palettes) but it doesn't:

Code:

void UploadOBJExtPal1 (const unsigned short* pcwPalette, unsigned int uNumPaletteEntries,
                  unsigned short wPalettePage, unsigned short wPaletteIndex)
{
   // Prepare VRAM extended palette bank for writing
   VRAM_G_CR = VRAM_ENABLE | VRAM_G_LCD;

   // DMA copy prio 3
   dmaCopyHalfWords (3, pcwPalette, ((VRAM_G + ((16 + wPalettePage) << 8)) + wPaletteIndex), uNumPaletteEntries << 1);

   // Set to extended palette mode (Bank G holds OBJExtPal 0 and 1)
   VRAM_G_CR = VRAM_ENABLE | VRAM_G_SPRITE_EXT_PALETTE;
}


Anything wrong?
_________________
Exceptions are fun

#169512 - eKid - Sun Jul 19, 2009 10:06 pm

LOst? wrote:
Sprite extended palettes are supposed to have 2 slots.

Are you sure? :/

#169517 - DiscoStew - Mon Jul 20, 2009 12:36 am

Taken from GBATEK

Code:
VRAM   SIZE  MST  OFS   2D Graphics Engine A, OBJ Extended Palette
F,G     16K   5    -     Slot 0  ;16K each (only lower 8K used)

_________________
DS - It's all about DiscoStew

#169523 - LOst? - Mon Jul 20, 2009 11:31 am

eKid wrote:
LOst? wrote:
Sprite extended palettes are supposed to have 2 slots.

Are you sure? :/

I am not sure. But the emulator desmume has "Main spr ExtPal 0", "Main spr ExtPal 1", "Sub spr ExtPal 0", and "Sub spr ExtPal 1" available in its Tools->Wide palettes (PAL VIEW) dialog box. And I can't write to ExtPal 1 for those.

DiscoStew wrote:
Taken from GBATEK

Code:
VRAM   SIZE  MST  OFS   2D Graphics Engine A, OBJ Extended Palette
F,G     16K   5    -     Slot 0  ;16K each (only lower 8K used)

I have the only working configiration I think when it comes to using 2D BG and OBJ extended palettes on both screens.

Also, I know of no way to actually use slot 1 of object extended palettes anyway. So this is only a way for me to be able to write to all palettes that desmume says exist.
_________________
Exceptions are fun

#169796 - sverx - Tue Aug 04, 2009 10:23 am

I think there's no such Sprite Extended Paletto Slot 1. In fact, how would you tell to the sprite(s) to use Slot 1 palettes instead of Slot 0?

And
GBATek wrote:
(only lower 8K used)
means exactly that too, the second half won't be ever used.

:)