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.

Coding > Tile-mode Graphics Corruption Problem

#177962 - aidan_aidan - Wed Jun 12, 2013 2:55 pm

[Images not permitted - Click here to view it]

The corruption as you can see is in the lower area of the screen, starting at tile number 512 (block 1). The corruption extends all the way back to the tiles library itself in the Character block, I now this from viewing it in Visual boy. I have spent many hours to no avail trying to figure out the problem and am tired of trying. So I have turned to the forums. I will now post the relevant code.

C FILE WITH MAIN FUNCTION
Code:

#include <..\include\toolbox.h>
#include <..\include\palettes.h>
#include <..\include\tileset.h>
#include <..\include\sprites.h>
#include <..\include\samples.h>
#include <..\include\text.h>
#include <..\include\bitmaps.h>

u32 starXoff = 0, starYoff = 0, shipX = 10, shipY = 72;

void tm1Interrupt(void);
void interruptHandler(void);
void meleeMode(void);
void introScreen(void);
void playSound(u32 frequency, const u32* soundLoc, u32 length);
void displayText(u32 length, const char string[], u32 colorIndex);

int main(void){
   introScreen();
   
   while(1){}
   
   return(0);
}

/*
void initRegisters(){
   REG_ISR_MAIN = interruptHandler;
   SOUNDCNT_H = (SOUND_HVOLUME100 | SOUND_HAVOLUME100 | SOUND_HBVOLUME0 | SOUND_HAENABLERIGHT | SOUND_HAENABLELEFT | SOUND_HATIMER0 | SOUND_HBDISABLERIGHT | SOUND_HBDISABLELEFT | SOUND_HBTIMER0);
   SOUNDCNT_X = (SOUND_XFIFOME);
   INTERRUPTME = (IME_ENABLE);
   INTERRUPTE = (INTERRUPT_TM1);
}
*/

void introScreen(){
   u32 x, y;
   u16 vBlankBool_A = 0, vBlankBool_B = 0;
   
   DISPCNT = (MODE0 | BG0_ENABLE | BG1_ENABLE);
   BG0CNT  = (CBB0 | BGCOLOR256 | SBB16 | BG_REG_32x32);
   BG1CNT  = (CBB3 | BGCOLOR16 | SBB1 | BG_REG_32x32);
   
   for(x = 0; x < INTROSETLENGTH; x++){
      CBB0_U32_LOC[x] = introSet[x];
   }
   for(x = 0; x < 30; x++){
      for(y = 0; y < 20; y++){
         SBB16_U16_LOC[(y * 30) + x + (y * 2)] = (x + (y * 30));
      }
   }
   for(x = 0; x < BGINTROPALETTELENGTH; x++){
      BGPAL[x] = bgIntroPalette[x];
   }
   
   while(1){
      vBlankBool_A = (DISPSTAT & VBLANKFLAG);
      
      if(vBlankBool_A & ~vBlankBool_B){
         
      }
      
      vBlankBool_B = vBlankBool_A;
   }
}

void meleeMode(){
   u32 i, tile0, tile1, flip0, flip1, index0, index1;
   u16 vBlankBool_A = 0, vBlankBool_B = 0;
   
   DISPCNT = (MODE0 | BG0_ENABLE | BG1_ENABLE | BG2_ENABLE | BG3_ENABLE | OBJ_ENABLE | OBJ1D);
   BG1CNT  = (BG_REG_64x32 | SBB16 | CBB0 | BGCOLOR16);
   BG2CNT  = (BG_REG_64x32 | SBB18 | CBB0 | BGCOLOR16);
   BG3CNT  = (BG_REG_64x32 | SBB20 | CBB0 | BGCOLOR16);
   
   for(i = 0; i < BGMELEEMODEPALETTELENGTH; i++){
      BGPAL[i] = bgMeleeModePalette[i];
   }
   for(i = 0; i < STARSETLENGTH; i++){
      CBB0_U32_LOC[i] = starSet[i];
   }
   for(i = 0; i < (BGSTARSLENGTH * 3); i++){
      index0 = r() >> 25;
      index1 = r() >> 25;
      if(index0 > 16){
         tile0 = 0;
      }
      else{
         tile0 = index0;
      }
      if(index1 > 16){
         tile1 = 0;
      }
      else{
         tile1 = index1;
      }
      tile1 = (tile1 << 16);
      flip0 = r() >> 30;
      flip1 = r() >> 30;
      flip0 = (flip0 << 10);
      flip1 = (flip1 << 26);
      SBB16_U32_LOC[i] = (tile0 | tile1 | flip0 | flip1);
   }
   
   while(1){
      vBlankBool_A = (DISPSTAT & VBLANKFLAG);
      
      if(vBlankBool_A & ~vBlankBool_B){
         keyPoll();
   
         if(keyDown(BUTTON_DOWN)){
            starYoff++;
         }
         if(keyDown(BUTTON_UP)){
            starYoff--;
         }
         if(keyDown(BUTTON_LEFT)){
            starXoff -= 2;
         }
         if(keyDown(BUTTON_RIGHT)){
            starXoff += 2;
         }
         
         starXoff += 3;
         
         BG1HOFS = starXoff >> 1;
         BG2HOFS = starXoff >> 2;
         BG3HOFS = starXoff >> 3;
         
         BG1VOFS = starYoff;
         BG2VOFS = starYoff >> 1;
         BG3VOFS = starYoff >> 2;
      }
      
      vBlankBool_B = vBlankBool_A;
   }
}

void interruptHandler(void){
   if(INTERRUPTF & INTERRUPT_TM1){
      tm1Interrupt();
   }
}
void tm1Interrupt(void){
   TM0CNT = 0;
   DMA1CNT = 0;
   INTERRUPTF = INTERRUPT_TM1;
}

void displayText(u32 length, const char string[], u32 colorIndex){
   u32 i;
   for(i = 0; i < length; i++){
      SBB31LOC[i] = (string[i] - 32);
   }
}

void playSound(u32 frequency, const u32* loc, u32 length){
   TM0CNTCOUNT = 65536 - (16777216 / frequency);
   TM1CNTCOUNT = 65536 - length;
   TM1CNT = (TIMER_COUNTUPTIMING | TIMER_IRQENABLE);
   
   DMA1SAD = (u32)loc;
   DMA1DAD = (u32)FIFOA;
   SOUNDCNT_H = SOUNDCNT_H | SOUND_HARESETFIFO;
   DMA1CNT = (DMASTARTTIMING_SPEC | DMAENABLE | DMAREPEAT | DMATRANSFER_32);
   
   TM0CNT = TIMER_START;
   TM1CNT = TM1CNT | TIMER_START;
}


I am not really sure what to include so if anything isn't clear please ask.[/code]
_________________
French re f draft free e w shredder for c rt

#177963 - Dwedit - Wed Jun 12, 2013 3:37 pm

Stuff that looks like that is usually the map memory being interpreted as tile graphics.
Use VisualBoyAdvance's tile viewer to see if it's really corrupt tiles, or if your tiles are intact, and the map is getting invalid data.
If you see evidence of the tile data getting corrupted, you can use data breakpoints to see exactly where the writes are taking place.
Also check for extra background layers with incorrect settings.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#177964 - aidan_aidan - Wed Jun 12, 2013 8:03 pm

Looking at the tile viewer, the tiles are corrupt in the tile viewer. So that means it is somehow getting corrupt when being written to VRAM?

EDIT: Looking at the tile viewer again, i notice the corrupt tiles start right at CBB2

EDIT: There is something specific about CBB2 that is causing the problems because if I change the CBB from 0 to 1 for that layer, the errors move up on the screen as would be expected.
_________________
French re f draft free e w shredder for c rt

#177965 - aidan_aidan - Wed Jun 12, 2013 11:14 pm

Dwedit wrote:
Stuff that looks like that is usually the map memory being interpreted as tile graphics.
Use VisualBoyAdvance's tile viewer to see if it's really corrupt tiles, or if your tiles are intact, and the map is getting invalid data.
If you see evidence of the tile data getting corrupted, you can use data breakpoints to see exactly where the writes are taking place.
Also check for extra background layers with incorrect settings.



Yes it was being interpreted as a map, i was using SBB16 which would put it in the middle of the VRAM - right where my tiles were stored. and the map was written after the tiles which makes sense


In other words, thanks!
_________________
French re f draft free e w shredder for c rt