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 > Raster effects doesn't work properly on hardware

#144268 - Chano Marrano - Wed Oct 31, 2007 12:21 am

Hi! I've been working on a raster effects system for the GBA. The raster effects are showing correctly on emulators such as VisualBoy, No$gba and the Advanced Debugger emulator included, but on a real GBA the screen seems a little garbled. Where's the problem?

Code for the background raster effect:
Code:

void ATTR_FASTFUNC bgRippleAct(void)
{
    if(REG_VCOUNT > 224 || REG_VCOUNT < 159)
    {
        struct bgStruct *bgPtr = &bg[0];
        u32 counter = sis_generalCounter();
        s32 line, offset;

        if(!REG_VCOUNT || REG_VCOUNT > 225)
            line = 1;
        else
            line = REG_VCOUNT;

        offset = swiDiv(SIN((line + counter) * speed), amplitude);

        M_BG0SCRLX_SET(bgPtr->x + offset);
        M_BG0SCRLY_SET(bgPtr->y + offset);
    }
}


I've uploaded a little demo that shows the problem: look at the vertical line that gets garbled in the middle of the screen, over the last 's' of the word "Sessions":
http://rapidshare.com/files/66369735/bad_rasters_gba_demo.zip.html

#144272 - tepples - Wed Oct 31, 2007 1:32 am

VBA and NO$GBA can use either a high-level-emulated BIOS or an authentic GBA BIOS dumped from your GBA using your flash equipment. The former doesn't require the user to own a GBA and flash equipment, but the latter acts more like a GBA. Does it work on VBA and NO$GBA even if you make a BIOS file and tell the emulator to use it? Do you know how to dump your GBA's BIOS? (For GBAMP use this.)

Also, emulators tend not to handle mid-scanline register writes or palette writes the way a GBA does. If you want to do a raster effect that changes the position of each scanline, use HDMA (DMA with start timing set to horizontal blank).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#144298 - Chano Marrano - Wed Oct 31, 2007 8:33 am

Thanks for your reply.

The emulators mentioned above keep showing the rasters correctly even if I assign them a real BIOS, so I'll try to use HDMA.

#144307 - kusma - Wed Oct 31, 2007 12:14 pm

I seem to remember having similar issues if i did not finish updating the per-scanline registers during h-blank on real hardware. both vba and no$ seems to simply fetch these registers after h-blank, but the real hardware seemed to garble a couple of pixels before updating properly. This was a real pain to get working correctly on both emulators and on hardware without using the h-blank DMA, so I'd recommend using that.

#144331 - Chano Marrano - Wed Oct 31, 2007 5:50 pm

Thanks for your advices, but using HDMA I reach to the same point: the effect works on emulators but not on hardware. I'll post the code associated:

Code:

static void ATTR_FASTFUNC actBGRipple(void)
{
    u32 counter = sis_generalCounter();
    struct bgStruct *bgPtr = &bg[0];
    u32 i;

    // Desactivate DMA:
    REG_DM0CNT_H = 0;

    // Fill the table for next frame:
    for(i = 0; i < 160; i++)
    {
        u32 offset = swiDiv(SIN((i + counter) * speed), amplitude);

        regTable[i * 2] = bgPtr->x + offset;
        regTable[(i * 2) + 1] = bgPtr->yo + offset;
    }

    // Activate DMA:
    REG_DM0CNT = 0;
    REG_DM0SAD = (u32)(&regTable);
    REG_DM0DAD = (u32)(&REG_BG0HOFS);
    REG_DM0CNT = 2 | (DMA_ON);
}

void ATTR_FASTFUNC intrHBLFunc(void)
{
    if(REG_VCOUNT == 1)
    {
        // Act DMA:
        REG_DM0CNT = 0;
        REG_DM0SAD = (u32)(&regTable[1]);
        REG_DM0DAD = (u32)(&REG_BG0HOFS);
        REG_DM0CNT = 2 | (DMA_ON) | (DMA_HBL) | (DMA_REPEAT) | (DMA_DST_RESET);
    }
}

#144337 - Mighty Max - Wed Oct 31, 2007 7:26 pm

Shouldn't an amplitude be multiplied to the base function (SIN here)?

If you intended this, is the table calculated correctly (i.e. swiDiv working as you expect it to work)?
_________________
GBAMP Multiboot

#144343 - Chano Marrano - Wed Oct 31, 2007 8:20 pm

Well, I did it (the HDMA version)! :D. It was just a little problem with the interrupt associated to the AAS sound system. Thanks for your attention.