Jump to content

Possible bug in background scrolling?


ficedula

Recommended Posts

Hi... I've been writing some code and Dualis seems to be handling the scroll registers for BG2 incorrectly for some reason... under some circumstances when I set BG2_X0 (BG2 horizontal scroll) it seems to be overwriting the map associated with BG2?!

 

It only seems to happen when blending and BG0/1 are also enabled for some reason - I've got a relatively small app below based on the NDSLIB examples that shows the problem. Set the scroll register using left/right and see the map data getting overwritten for some reason, the first three map entries are printed on the subscreen each frame.

 

Works as expected on real hardware, and BG0/1 scrolling all works fine too. (Well, the BG2 scroll registers do scroll the background, I just seem to lose my map sometimes...)

 

#include <NDS/NDS.h>
#include <NDS/ARM9/console.h>

int main(void)
{
powerON(POWER_LCD_TOP | POWER_LCD_BOTTOM | POWER_2D | POWER_2D_SUB);
DC_FlushAll();
irqInitHandler(irqDefaultHandler);
irqSet(IRQ_VBLANK, 0);

vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_SUB_BG, VRAM_D_TEXTURE);
videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE);
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); 

BG0_CR = TEXTBG_SIZE_256x256 | BG_WRAP_ON | BG_PRIORITY_3 | BG_16_COLOR | BG_TILE_BASE(1) | BG_MAP_BASE(7);
BG1_CR = TEXTBG_SIZE_256x256 | BG_WRAP_ON | BG_PRIORITY_1 | BG_16_COLOR | BG_TILE_BASE(3) | BG_MAP_BASE(6);
BG2_CR = TEXTBG_SIZE_256x256 | BG_WRAP_ON | BG_PRIORITY_0 | BG_16_COLOR | BG_TILE_BASE(5) | BG_MAP_BASE(5);
BLEND_CR = BLEND_ALPHA | BLEND_SRC_BG2 | BLEND_DST_BG0 | BLEND_DST_BG1 | BLEND_DST_SPRITE;
BLEND_AB = 0x1f | (0x1f << 8);

consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
SUB_BG0_CR = BG_MAP_BASE(31);
BG_PALETTE_SUB[255] = RGB15(31,31,31);

int scrollx=0;
u16* map = (u16*)BG_MAP_RAM(5);
map[0] = 0; map[1] = 1; map[2] = 2;

while(1)
{	
 consolePrintSet(0,0);
 consolePrintf("L3 %d %d %d\n", map[0], map[1], map[2]);
 consolePrintf("Scroll %d\n", scrollx);
 swiWaitForVBlank();	
 consoleClear();
 if(!(KEYS & KEY_LEFT)) scrollx--;
 if(!(KEYS & KEY_RIGHT)) scrollx++;
 BG2_X0 = (scrollx & 0xff);
}
return 0;
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...