GBDK2020 - Wobble Effect with some glitches

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
M2m
Posts: 24
Joined: Mon Feb 15, 2021 12:53 pm

GBDK2020 - Wobble Effect with some glitches

Post by M2m »

I'm trying to make some kind of 'wobble' effect for the Gameboy in GBDK2020: inspired to what Links Awakening did with the Windfish in the end.

I'm getting graphical glitches if I modify 'too many' lines during hlank and also I seem only to be able to adjust like every 3-4th line, otherwise I also start to get graphic glitches.

Basically I fire a function as follows and add it to LCD interrupt:

Code: Select all

void interruptLCD(){
    switch (LYC_REG)
    {
        case 0x00:
            move_bkg(backgroundoffset1x,0);
            LYC_REG = 0x03;
            break;
        case 0x03:
            move_bkg(backgroundoffset3x,0);
            LYC_REG = 0x06;
            break;
        case 0x06:
            move_bkg(backgroundoffset5x,0);
            LYC_REG = 0x09;
            break;
        case 0x09:
            move_bkg(backgroundoffset2x,0);
            LYC_REG = 0x0c;
            break;
            ....
            
main:

Code: Select all

STAT_REG = 0x45; // enable LYC=LY interrupt so that we can set a specific line it will fire at
    LYC_REG = 0x00;

    disable_interrupts();
    add_LCD(interruptLCD);
    enable_interrupts();

    set_interrupts(VBL_IFLAG | LCD_IFLAG);

    SHOW_BKG;
    DISPLAY_ON;

    while(1){....
Full code + rom here (you can 'wobble' with LEFT key): https://github.com/sttng/gb-stuff/tree/main/wobble

Image

Would appreciate some tips.
User avatar
dink
Posts: 157
Joined: Sun Jan 12, 2020 8:42 pm

Re: GBDK2020 - Wobble Effect with some glitches

Post by dink »

You almost got it: try using a sine (table) and modulate each line position with the sine, changing the offset into the sine table for all lines every few frames or so.

p.s. Outside of gbdev, this "wobble" effect is raster (if the effect relies on modifying the scroll registers for each line using an interrupt or hblank detection) or linescroll (if hw has scroll registers for each line)

best regards & good luck,
- dink
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: GBDK2020 - Wobble Effect with some glitches

Post by calima »

A giant switch() probably turns into if() else if() cascade, which explains why it gets slow. Look at the asm, and maybe try a jump table.
M2m
Posts: 24
Joined: Mon Feb 15, 2021 12:53 pm

Re: GBDK2020 - Wobble Effect with some glitches

Post by M2m »

calima wrote: Sat Apr 17, 2021 9:50 am A giant switch() probably turns into if() else if() cascade, which explains why it gets slow. Look at the asm, and maybe try a jump table.
Indeed. Thanks for the tipp ! I changed it now to an offset table for each LYC_REG value and this works without graphic glitches :D even with every 2nd scanline. I couldn't get it working with every scanline. Seems to be a bug in GBDK2020.

Code: Select all

INT8 offset_array[144] = {-3,0,-2,-1,-2,-5,-2,-3,0,-4,-4,-3,-1,-3,-1,-2,-6,-6,-5,-2,-2,-4,-6,-5,-5,-2,-4,-3,-7,-9,-9,-10,-10,-9,-11,-14,-15,-18,-18,-20,-21,-25,-24,-21,-23,-22,-26,-27,-24,-27,-26,-26,-28,-28,-27,-26,-23,-20,-18,-16,-18,-21,-23,-21,-23,-22,-21,-18,-18,-17,-15,-12,-11,-12,-12,-11,-14,-13,-14,-17,-17,-17,-16,-17,-21,-18,-20,-23,-27,-24,-25,-28,-27,-30,-34,-33,-35,-37,-36,-36,-37,-41,-44,-48,-49,-48,-48,-50,-51,-48,-47,-44,-44,-42,-46,-43,-42,-45,-48,-51,-54,-55,-55,-59,-56,-60,-59,-58,-57,-58,-59,-57,-57,-59,-58,-59,-57,-55,-53,-51,-55,-53,-56,-58};

void interruptLCD(){
	if (offset_array[LYC_REG] > 0){
		move_bkg(offset_array[LYC_REG],0);
	}
	else {
		move_bkg(0,0);
	}
	LYC_REG +=2; //Doesn't work for LYC_REG +=1;
	if (LYC_REG > 143) {LYC_REG = 0;}
}
Post Reply