Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2019-12-01 14:59:18

jchristof
Member
Registered: 2019-12-01
Posts: 17

vertical blank scrolling artifacts

I'm attempting to parallax scroll portions of my background (using Zalo's excellent ZBG kit.)
The effect is mostly working but I get occasional screen glitching for the background (a scan line or two is in the wrong spot momentarily). The glitch appears both on BGB and Gambete (haven't tried it on real hardware)

I've disabled the engine's other scroll manipulation code and don't have a scroll target set.
I realize that the code is probably too slow to keep up, but here's what I have:

in main.c

Code:

    
LYC_REG = 0x08;
disable_interrupts();
add_VBL(vbl_update);
add_TIM(MusicUpdate);
add_LCD(LcdUpdate);
 set_interrupts(VBL_IFLAG | TIM_IFLAG | LCD_IFLAG);
enable_interrupts();

Code:

UINT8 bgOffset = 0;
UINT8 frameSkip = 16;
void LcdUpdate(){
    if(current_state != StateGame)
        return;

    switch (LYC_REG)
    {

    case  0x08:
        SCX_REG = bgOffset;
        LYC_REG = 0x40;

        if(frameSkip--)
            return;
        
        frameSkip = 16;
        bgOffset++;
        
        break;
    
    case 0x40:
        SCX_REG = 0;
        LYC_REG = 0x08;
        break;
    }
}

Any ideas though are welcome.

Offline

 

#2 2019-12-09 23:37:42

jchristof
Member
Registered: 2019-12-01
Posts: 17

Re: vertical blank scrolling artifacts

Experimenting more this evening reveals that if I remove the timer callbacks (TIM_IFLAG) it fixes the vblank artifacts.

I was also seeing tile glitches at times too since I occasionally push new tiles for existing sprites during the update. The problem is that I don't want to disable the music.

Anyone know of a fix for this?

Offline

 

#3 2019-12-10 18:06:45

jchristof
Member
Registered: 2019-12-01
Posts: 17

Re: vertical blank scrolling artifacts

oh wait - maybe I need to nest the hblank interrupt into timer interrupt method?

Offline

 

#4 2019-12-10 18:47:37

Tauwasser
Member
Registered: 2010-10-23
Posts: 160

Re: vertical blank scrolling artifacts

Is bgOffset some variable used in your main rendering code to write to the scroll registers?
That means if you miss once you'll have a stray line every so often. I've only ever seen the opposite of what you're trying to do: have a shadow register that's copied to the scroll registers during vblank and manipulate that either from regular (non-interrupt) code or have a special effect that copies values from a table or generates them in a tight loop. That way you're sure not to miss any frames (as long as your vblank code does not take too long).

Hblank interrupt would be another method where you can modify the scroll registers once per line in order to get cool wavy effects or line-based effects like moving water (think Pokémon Gold intro).

Offline

 

#5 2019-12-10 22:42:08

jchristof
Member
Registered: 2019-12-01
Posts: 17

Re: vertical blank scrolling artifacts

Yes you're right, bgOffset is incremented in the vblank code and used to offset part of the bg in certain hblank interrupts. I think that occasionally due to the music timer interrupt that one of my hblank interrupts would not fire correctly.

I appear to have fixed my issue by (in GBDK) asking for interrupts to be enabled during the timer interrupt that drives the gbt music player.

MusicUpdate() is the timer interrupt handler

Code:

void MusicUpdate() {
    enable_interrupts();
    gbt_update();
    REFRESH_BANK;
}

I suspect that enable_interrupts(); calls EI, though when I do a search for this in the GBDK folder I don't identify the connection between them.
I got the idea from the pan docs that say you can nest interrupts like this since during any interrupt the EI is disabled by default.

Offline

 

#6 2019-12-14 06:34:55

Tauwasser
Member
Registered: 2010-10-23
Posts: 160

Re: vertical blank scrolling artifacts

You can nest them like this, but does the gbt player really take that much time? The hblank interrupt should fire anyway, just a bit later.

Offline

 

#7 2019-12-15 14:39:24

jchristof
Member
Registered: 2019-12-01
Posts: 17

Re: vertical blank scrolling artifacts

You're correct in wondering about the timing - I need to figure out how to measure this.

Typically I'd try to inspect this in a debugger, but I haven't yet tried to use the BGB debugger to inspect my running code.

I suppose I could also calculate the instruction timing in the audio player's update - I don't have much experience with asm atm.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson