Jump to content

VBlank and Bitmap BGs


pacifist

Recommended Posts

Alright! I've been looking foreward to this version of dualis.

 

I'm having some troubles though.

 

Enabling the VBlank interrupt with this code

irqInitHandler(irqDefaultHandler);
irqSet(IRQ_VBLANK, irqVBlank);

 

seems to always crash the emu.

 

I can do it the long way:

IME = 0;
IRQ_HANDLER = &irqVBlank;
IE = IRQ_VBLANK;
IF = ~0;
DISP_SR = DISP_VBLANK_IRQ;
IME = 1;

 

but only if I have turned the power to the screen on first

 

POWER_CR = POWER_ALL_2D;

 

and even then dualis crashes after I start excecuting code.

 

Turning on a timer

TIMER2_CR = (TIMER_ENABLE | TIMER_DIV_256);

also crashes dualis if I haven't set the power cr yet.

 

Also I'm having problems with my bitmap backgrounds:

	vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_BG, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE);
vramSetBankE(VRAM_E_MAIN_SPRITE);
vramSetBankI(VRAM_I_SUB_BG);

SUB_BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(BMP_BASE) | BG_PRIORITY_1;

for(int i = 0; i < 128*256; i++)
  ((u16*)BG_BMP_RAM_SUB(BMP_BASE))[i] = (u16)0;

(note this code isn't a straight copy and paste there are other backgrounds being set-up, scaling registers being set etc...)

 

this crashes when I try to initialise the background, that is, on this line:

for(int i = 0; i < 128*256; i++)
  ((u16*)BG_BMP_RAM_SUB(BMP_BASE))[i] = (u16)0;

 

I assume this is a VRAM thing but I don't really understand VRAM.

 

I can work up a demo for any of this if you like.

 

btw, mic, in my struggle to get various bitmap backgrounds going I stumbled upon your graphics notes and found them exTREMELY helpfull. thanks for posting them.

Link to comment
Share on other sites

The IRQ/timer issue is news to me. I'll look into it.

 

For the VRAM problem, what mode are you using?

I'm not familiar with the ndslib defines, only with the raw bitpatterns. If you posted a demo eventually that'd help, since that way I could figure out which line of code in the emulator is causing the crash which makes finding the reason behind it easier.

Link to comment
Share on other sites

Found the bug. Bank I was getting a 128kB size when mapped to the sub BG, when it's actually only 16kB -> crash. (This is what you get when creating large arrays by copy-pasting :P

 

mode3ds.png

Link to comment
Share on other sites

ok I'm thinkin' the vblank stuff is my fault :afro:

 

I went and grabbed the new version of ndslib, re-compiled, and dualis is havin' no troubles.

 

although while I was building the demo I did notice that while on hardware this code displays one screen red and one screen blue on dualis they are both white.

 

void irqVBlank(void)
{	
IF = IRQ_VBLANK;
}

int main(void) 
{
POWER_CR = POWER_ALL_2D;
DISPLAY_CR = MODE_0_2D | DISPLAY_BG0_ACTIVE;
SUB_DISPLAY_CR = MODE_0_2D | DISPLAY_BG0_ACTIVE;

irqInitHandler(irqDefaultHandler);
irqSet(IRQ_VBLANK, irqVBlank);

PALETTE[0] = RGB15(0, 0, 31);
PALETTE[512] = RGB15(31, 0, 0);

while(1)
 swiWaitForVBlank;

return 0;
}

 

Not a big deal for me, but I thought I'd mention it since I stumbled across it.

 

sorry about the false alarm on the VBlank :naughty:

Link to comment
Share on other sites

The reason for the screens being white is that the scanline renderer is searching for an appropriately mapped VRAM bank for each active BG. If no suitable bank was found for any of the active BGs I should draw just the backdrop (which I'm not at this point).

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...