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.

Graphics > When moving tiles the screen flickers.

#8076 - Archeious - Tue Jul 01, 2003 5:36 pm

I thought the following code would work but I am getting intermitent skipping.

Quote:

while (1) {
RotateBackground(&bg3,angle,119,79,zoom); //set center of screen
inputResponse=process_Input();
WaitForVsync();

if (inputResponse & MAP_MOVERIGHT) {
bg3.x_scroll++;
bg3.x_display++;
if (bg3.x_scroll > 151) {
bg3.x_scroll = 136;
x+=2;
REG_DM3SAD = (u32)bg3.mapData+2;
REG_DM3DAD = (u32)bg3.mapData;
REG_DM3CNT = 2048 | DMA_16NOW; // width*height / 2 = 2048
test = (u16*)bg3.mapData;
for (loop=0;loop<=22;loop++) {
test[(loop*32)+16] = myMap->data[(loop*myMap->width)+x+32] | (myMap->data[(loop*myMap->width)+x+33] << 8);
}
}
}

if (inputResponse & MAP_MOVELEFT) {
bg3.x_scroll--;
bg3.x_display++;
if (bg3.x_scroll < 121) {
bg3.x_scroll = 136;
REG_DM3SAD = (u32)bg3.mapData+4094;
REG_DM3DAD = (u32)bg3.mapData+4096;
REG_DM3CNT = 32*64 | DMA_SOURCE_DECREMENT | DMA_DEST_DECREMENT | DMA_16NOW; // 32 = 8x8/16 bit word
}
}

if (inputResponse & MAP_MOVEDOWN) {
bg3.y_scroll++;
bg3.y_display++;
if (bg3.y_scroll > 111) {
bg3.y_scroll = 96;
y+=2;
REG_DM3SAD = (u32)bg3.mapData+128;
REG_DM3DAD = (u32)bg3.mapData;
REG_DM3CNT = 32*64 | DMA_16NOW; // 32 = 8x8/16 bit word

REG_DM3SAD = (u32)&myMap->data[((y+22)*myMap->width)+x];
REG_DM3DAD = (u32)bg3.mapData+(1408); // 22*64
REG_DM3CNT = 32 | DMA_16NOW; // 32 = 8x8/16 bit word

REG_DM3SAD = (u32)&myMap->data[((y+23)*myMap->width)+x];
REG_DM3DAD = (u32)bg3.mapData+(1472); // 23*64
REG_DM3CNT = 32 | DMA_16NOW; // 32 = 8x8/16 bit word */
FONT_printU32(y,0,0);
}
}

if ((inputResponse & MAP_MOVEUP) && bg3.y_display > 0) {
bg3.y_scroll--;
bg3.y_display--;
if (bg3.y_scroll < 81) {
bg3.y_scroll = 96;
y+=-2;
REG_DM3SAD = (u32)bg3.mapData+3968;
REG_DM3DAD = (u32)bg3.mapData+4096;
REG_DM3CNT = 32*64 | DMA_SOURCE_DECREMENT | DMA_DEST_DECREMENT | DMA_16NOW; // 32 = 8x8/16 bit word

REG_DM3SAD = (u32)&myMap->data[(y*myMap->width)+x];
REG_DM3DAD = (u32)bg3.mapData;
REG_DM3CNT = 32 | DMA_16NOW; // 32 = 8x8/16 bit word

REG_DM3SAD = (u32)&myMap->data[((y+1)*myMap->width)+x];
REG_DM3DAD = (u32)bg3.mapData+64;
REG_DM3CNT = 32 | DMA_16NOW; // 32 = 8x8/16 bit word
FONT_printU32(y,0,0);
}
}

UpdateBackground(&bg3);

CopyOAM();
}


The bin can be found at http://www.geocities.com/archeious/netwars.bin is you want to see what is going on. Any and all help figuring this out would be great.

Archeious

#8156 - djei-dot - Thu Jul 03, 2003 11:29 am

Looks like your map is being dynamically loaded the wrong way. I don't know much about dinamically loading maps but you can check out Dovoto's tutorial about this (it's in the Making the Game section).

#8161 - Quirky - Thu Jul 03, 2003 2:21 pm

It seems to load the graphics 8 pixels too far left, (when "moving right") then jumps the screen to the correct position.

The problem, I think, is that you do this first:

RotateBackground(&bg3,angle,119,79,zoom); //set center of screen
then update the scroll registers,
then UpdateBackground(&bg3); (which is when the new scroll changes take place.)

So if you reach the "edge" and have to do a change over of tiles, you will go from, say bg3.y_scroll == 82 to 96, then the screen will jump to 79 at the start of the loop.

Does that make sense? My advice is get out VBA, its map viewer then Insight, GDB, etc and step through to see how it all works one step at a time.

#8176 - Archeious - Thu Jul 03, 2003 9:15 pm

Quirky wrote:
It seems to load the graphics 8 pixels too far left, (when "moving right") then jumps the screen to the correct position.

The problem, I think, is that you do this first:

RotateBackground(&bg3,angle,119,79,zoom); //set center of screen
then update the scroll registers,
then UpdateBackground(&bg3); (which is when the new scroll changes take place.)

So if you reach the "edge" and have to do a change over of tiles, you will go from, say bg3.y_scroll == 82 to 96, then the screen will jump to 79 at the start of the loop.

Does that make sense? My advice is get out VBA, its map viewer then Insight, GDB, etc and step through to see how it all works one step at a time.


Doesn't make too much sense. How can I hook GDB up to VBA? I will look at the map view and see what that is doing. It looks almost like the DMA transfer are not working (only happens some of the times). Anyways thatnbks for hte ideas.

#8183 - Archeious - Thu Jul 03, 2003 10:48 pm

Quirky wrote:
It seems to load the graphics 8 pixels too far left, (when "moving right") then jumps the screen to the correct position.

The problem, I think, is that you do this first:

RotateBackground(&bg3,angle,119,79,zoom); //set center of screen
then update the scroll registers,
then UpdateBackground(&bg3); (which is when the new scroll changes take place.)

So if you reach the "edge" and have to do a change over of tiles, you will go from, say bg3.y_scroll == 82 to 96, then the screen will jump to 79 at the start of the loop.

Does that make sense? My advice is get out VBA, its map viewer then Insight, GDB, etc and step through to see how it all works one step at a time.


Well I figured it out. The problem is closey related to wait you mentioned (thanks a ton). What was happening was the rotateBackground was getting call before the updating of the x and y so the rotation matrix was getting fubar'ed. I just moved teh function call below the input tests. and everything is running great. Infinite (not really) map size here I come.

BTW I have looked at Dovoto's toots and find them overly complicated.

#8198 - Quirky - Fri Jul 04, 2003 7:55 am

Glad I could help. I had similar problems with my own "infinite engine" - the next part you have to look forward to will be adding non player sprites ;)

Incidently, setting up gdb is easier than you might think. Download the sdl version of visual boy advance from the VBA homepage, then download the arm-gdb and shared files from the same place (scroll down the list til you find GDB/Insight download). Unzip all that lot where it says then follow the instructions on the VBA FAQ page for running the emulator in debug mode. It took longer for me downloading the files than it did to get the debugger up and running.

Also, the SDL version has a print-to-console output that is very useful if you can't be arsed with the full debugger or want to "debug" interrupt routines. I don't know how I managed before! :)

#8244 - Archeious - Sat Jul 05, 2003 6:33 am

Quirky wrote:
Glad I could help. I had similar problems with my own "infinite engine" - the next part you have to look forward to will be adding non player sprites ;)

Incidently, setting up gdb is easier than you might think. Download the sdl version of visual boy advance from the VBA homepage, then download the arm-gdb and shared files from the same place (scroll down the list til you find GDB/Insight download). Unzip all that lot where it says then follow the instructions on the VBA FAQ page for running the emulator in debug mode. It took longer for me downloading the files than it did to get the debugger up and running.

Also, the SDL version has a print-to-console output that is very useful if you can't be arsed with the full debugger or want to "debug" interrupt routines. I don't know how I managed before! :)


:) I already have my sprite library fleshed out. Including dynamic memry manager. I am actually hanging up my gba coding hat for the next little bit. The artist want a better map/tile editor.