Help - Search - Members - Calendar
Full Version: VBlank and Bitmap BGs
1Emulation.Com > Official Emulator Forums > Dualis
pacifist
Alright! I've been looking foreward to this version of dualis.

I'm having some troubles though.

Enabling the VBlank interrupt with this code
CODE
irqInitHandler(irqDefaultHandler);
irqSet(IRQ_VBLANK, irqVBlank);


seems to always crash the emu.

I can do it the long way:
CODE
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

CODE
POWER_CR = POWER_ALL_2D;


and even then dualis crashes after I start excecuting code.

Turning on a timer
CODE
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:
CODE
    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:
CODE
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.
mic
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.
pacifist
I'm using mode 3

Here's a quick demo to show off the problem.

http://on-tap.ca/Mode3.zip

expected output is one screen with every second pixel red and the other with every second pixel yellow.
mic
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 smile.gif

Robert
That was pretty quick!

Mic, how did you go with the IRQ / timer issue?
mic
QUOTE
Mic, how did you go with the IRQ / timer issue?

I haven't solved that yet, since I don't know of any demos that exhibit that behavior. Might have to write one myself.
pacifist
I can probably work out a demo for that as well if you like.
mic
That'd be swell.
pacifist
ok I'm thinkin' the vblank stuff is my fault smile.gif

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.

CODE
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 wink.gif
mic
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).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.