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.
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
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:
//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
Thanks Mills, I'll have to try that, unfortunately I need to be GB-compatible, but at least it's a starting point.
Offline
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
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).
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...};
It looked perfect on my GBC.
Here I used sinewave values
But still you can notice some kind of "vibration" at some points if the array is too big.
//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