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.

Beginners > Blocky Text

#171570 - Azenris - Sun Nov 29, 2009 9:39 pm

I changed my function from

Code:
// =================================================================================
// SetPalette:
void CTileManager::SetPalette(const void *pPalette)
{
   ASSERT(pPalette != NULL, "Palette pointer is NULL")

   dmaCopy(pPalette, m_pPalette, MODIFABLE_PALETTE_SIZE[BG_PAL]);
   dmaCopy(pPalette, m_pOriginalPalette, MODIFABLE_PALETTE_SIZE[BG_PAL]);
}

to
Code:
// =================================================================================
// SetPalette:
void CTileManager::SetPalette(const void *pPalette, bool forceAllColours)
{
   ASSERT(pPalette != NULL, "Palette pointer is NULL")

   int size = (forceAllColours ? 512 : MODIFABLE_PALETTE_SIZE[BG_PAL]);

   dmaCopy(pPalette, m_pPalette, size);
   dmaCopy(pPalette, m_pOriginalPalette, size);
}


The palettes are pretty much the same during the main menu. (none of which are used) the text colours are unchanged. However the text comes out all blocky. I took some screenshots

First Way: [Images not permitted - Click here to view it]
Changed Way: [Images not permitted - Click here to view it]
_________________
My Homebrew Games

#171571 - Dwedit - Sun Nov 29, 2009 10:00 pm

Looks like 8-bit writes to VRAM.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#171572 - Azenris - Sun Nov 29, 2009 10:03 pm

you mean when loading the text? I use

Code:
// =================================================================================
// Init_RegTileMap256:
int CTextManager::Init_RegTileMap256(int tileOffset, u8 *pTileset, u16 *pMap, u16 *pPalette, const FONT *pFont)
{   
   ASSERT(pTileset != NULL, "NULL tileset")
   ASSERT(pMap != NULL, "NULL mapping")
   ASSERT(pPalette != NULL, "NULL palette")

   // default variables
   m_cursor.Set(0, 0);
   pFont == NULL ? m_pFont = &Text_Font_Morli : m_pFont = pFont;
   drawGlyph = RegTileMap_Write;
   eraseArea = RegTileMap_Erase;
   m_pPalette = pPalette;
   m_pMap = pMap;
   m_pTileset = pTileset;
   m_tileOffset = tileOffset;
   m_tileUsed = m_pFont->characters;
   ClearFrames();

   // add the palette
   dmaCopy(m_pFont->pPalette, (m_pPalette + TEXT_PALETTE_OFFSET), m_pFont->paletteColours << 1);
   
   // copy the tiledata and offset the palette
   u16 offset = ((TEXT_PALETTE_OFFSET - 1) << 8) + (TEXT_PALETTE_OFFSET - 1);
   u16 size = (m_pFont->characters * m_pFont->imageSize) / 2;
   u16 *dst = (u16*)(m_pTileset + ((m_tileOffset * m_pFont->imageSize) / 2));
   u16 *src = (u16*)m_pFont->pTileset;

   // apply the palette offset to both bytes
   while (size-- != 0)
      *dst++ = *src == 0 ? (*src++) : (*src++) + offset;

   // set as ready
   SetLoaded(true);

   return m_tileUsed;
}


This code has been working fine till I made the palette change, I can change back and forth always same results.
_________________
My Homebrew Games

#171574 - Dwedit - Sun Nov 29, 2009 10:42 pm

That's clearly 16 bit writes there, so that must not be the problem. The source address is aligned, right?

Oh yeah, this is a NDS. Always flush the cache before doing any DMA copies.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#171575 - Azenris - Mon Nov 30, 2009 12:18 am

i tried adding DC_FlushAll();
i tried aligning the source data for the text tileset

I also put some text on the lower screen and it works fine. Only the upper screen that uses SetPalette function having forceAllColours as true fails to work properly.

However the SetPalette function is called in the splashscreen, it then goes to the titlescreen then the mainmenu (where the text is for the menu items)

I decided to call it on the lower screen too at the splashscreen and it causes the text to go blocky.

Basically if I ever call SetPalette with forceAllColours as true, the text messes up for the rest of the game on which ever screen used it.

EDIT:
The difference in the palettes was an extra few blues (the screen was shades of blue). Normally cut off they were being placed by the fact I forced the whole palette to show.

Anyway my text was blue and made it look blocky, I changed the colour of the difference in palettes to red and can see red all over my text. Not sure why yet but i feel better knowing im on a track!

Just letting you know my progress. back to work!

EDIT:
Ok i solved it, it was a silly mistake :( I was only checking the whole 16 bit for 0, when I should have been checking both bytes seperatly and applying the offset if needed.
This mistake caused the text data to have some incorrect data, which meant it pointed to the wrong palette entry, was never a problem before because I used only black background, and the palette entries wernt used till now.

changed it to below, which is now working
Code:

   u16 offset_l = (TEXT_PALETTE_OFFSET - 1) << 8;      // offset only left byte
   u16 offset_r = (TEXT_PALETTE_OFFSET - 1);         // offset only right byte

   u16 size = (m_pFont->characters * m_pFont->imageSize) / 2;
   u16 *dst = (u16*)(m_pTileset + ((m_tileOffset * m_pFont->imageSize) / 2));
   u16 *src = (u16*)m_pFont->pTileset;
   u16 value = 0;

   // apply the palette offset to both bytes
   while (size-- != 0)
   {
      value = (*src++);

      value += ((value & 0xFF) == 0) ? 0 : offset_r;
      value += ((value >> 8) == 0) ? 0 : offset_l;

      *dst++ = value;
   }

_________________
My Homebrew Games