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 2014-10-26 12:50:49

andreai
Member
Registered: 2014-07-28
Posts: 21

LCD interrupt and STAT register with GBDK, does it work?

Hi there,

Trying to achieve the wavy screen effect from C using GBDK,  but my interrupt callback is never called, any idea what I might be doing wrong?
this is the code I'm using:
disable_interrupts();
STAT_REG = 0x44; // interrupt for each line of background?
add_LCD(scanline);
enable_interrupts();
set_interrupts(LCD_IFLAG);

If nobody has done that with C but someone has an assembly snippet that'd do as well.

Thanks!

Offline

 

#2 2014-11-08 06:42:04

Mills
Member
Registered: 2012-12-21
Posts: 132

Re: LCD interrupt and STAT register with GBDK, does it work?

andreai wrote:

Hi there,

Trying to achieve the wavy screen effect from C using GBDK,  but my interrupt callback is never called, any idea what I might be doing wrong?
this is the code I'm using:
disable_interrupts();
STAT_REG = 0x44; // interrupt for each line of background?
add_LCD(scanline);
enable_interrupts();
set_interrupts(LCD_IFLAG);

If nobody has done that with C but someone has an assembly snippet that'd do as well.

Thanks!

I also tried to do that in C, and in ASM. I always get the same effect with screen garbage...

Finally i could make a wave effect with no garbage using 8 Mhz on GBC. I think this can be made much faster even in C using only 4 Mhz for GB, using interrupts.

I did not find any info about add_LCD and LCD FLAG.. they never worked for me, so i used if's.. (much slower i think)

This is the best i got it:

Code:

//variables

int FR = 0; //frame
int FS = 0; //frame
const int wave[] = {0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1}; 

void Scroll_Control(){
        FS++; 
    FR = FS;
}

void main(){
     cpu_fast(); //for GBC
  
     //Load your tiles, palette and BKG Here

    add_VBL(Scroll_Control);

    while (1) {
        //STAT reg is the state of the screen, 1 is drawing a line, 2 is finished drawing a line
        if (STAT_REG & 1) { SCX_REG = wave[FR];}
        if (STAT_REG & 2) FR++;
        if (FR == 17) FR = 0;
    if (FS == 17) FS = 0;
    }
}

Last edited by Mills (2014-11-08 06:45:51)

Offline

 

#3 2014-11-13 14:20:54

andreai
Member
Registered: 2014-07-28
Posts: 21

Re: LCD interrupt and STAT register with GBDK, does it work?

Thanks Mills, I'll have to try that, unfortunately I need to be GB-compatible, but at least it's a starting point.

Offline

 

#4 2014-12-28 19:54:04

Stinaris
New member
Registered: 2014-12-28
Posts: 9

Re: LCD interrupt and STAT register with GBDK, does it work?

I'm having trouble getting this to do anything at all.

It never seems to trigger an interrupt on any scan line. Quite irritating. Not sure if it's the Emulator or the GBDK.

Offline

 

#5 2015-01-07 09:42:18

Mills
Member
Registered: 2012-12-21
Posts: 132

Re: LCD interrupt and STAT register with GBDK, does it work?

andreai wrote:

Thanks Mills, I'll have to try that, unfortunately I need to be GB-compatible, but at least it's a starting point.

I got it, it is working with no screen garbage at 4 Mhz.

You need to modify SCX using a very accurate counter, I only found the LY_REG, (it counts scanlines).

Code:

SCX_REG = wave[LY_REG+FR];

GBDK won't compile it if you don't add a variable (FR) inside [].


Here i used an array like this: wave[] = {-40,40,-40,40...};

https://dl.dropboxusercontent.com/u/757056/GameBoy/WAVES_BKG/1.bmp

It looked perfect on my GBC. smile


Here I used sinewave values

https://dl.dropboxusercontent.com/u/757056/GameBoy/WAVES_BKG/2.bmp

But still you can notice some kind of "vibration" at some points if the array is too big.


Code:

    
//Add an array with sine wave values
const int wave[] = {};
//Array position
int FR = 0;

//Increase Array position every frame if you want the wave to move.
void Scroll_Control(){ 
    FR++;
    if (FR == Size) FR = 0; //Go back to cero, "Size" is the array size 
}

void main(){

    add_VBL(Scroll_Control);

    while (1) {
         
          //LY_REG takes the value of the scanline being drawn
          SCX_REG = wave[LY_REG+FR]; 

    }
}

Last edited by Mills (2015-01-07 09:49:23)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson