#3379 - Jer1400 - Sun Feb 23, 2003 9:02 pm
What I'm trying to do is create 2 functions, one to store the screen away and one to restore it. Then what I'll do is paste random peices of the screen that was drawn when the screen was black (it was hardware faded and then drawn) when I use the hardware fading to bring the screen back to normal for a cool effect. This is what the compiler tells me:
In file included from tutor.c:13:
drawing.h:183: parse error before '}' token
drawing.h:186: parse error before "for"
Here is the code it is talking about, and the lines are labeled so you know which ones are 183 and 186:
///SaveScreen\\\
int SaveScreen()
{ ///////////////////////////////////////Line 183
int x=0, y=0;
int tempscreen [100000];
for (y=0; y<161; y++) ///////////////////////////////////////Line 186
{
for (x=0; x<241; x++)
tempscreen[x+y*240]=videoBuffer[x+y*240];
}
return 0;
}
///RestoreScreen\\\
void RestoreScreen(int x,int y,int x2,int y2,int xlocation,int ylocation)
{
int xcurrent=0, tempy=ylocation, tempx=xlocation;
for (y=y; y<y2; y++)
{
tempx=xlocation;
for (xcurrent=x; xcurrent<x2; xcurrent++)
{
videobuffer[tempx+tempy*240]=tempscreen[xcurrent+y*240];
tempx++;
}
tempy++;
}
}
And incase you were wondering here is the code for the random thing:
int main(void)
{
int stall=0, pixels=0, x, y, x2, y2;
SetMode(MODE_3 | BG2_ENABLE );
fadeout(1);
DrawName();
SaveScreen();
FillScreen(0,0,0);
fadein(1);
while(pixels<160000)
{
x=rand()%241;
y=rand()%161;
x2=x+1;
y2=y+1;
RestoreScreen(x,y,x2,y2,x,y);
pixels++;
}
while(1){}
} //end main
I know most of this is not nessesary for you to see, and I only post it because 2 weeks ago when I was learning the basics it helped me a lot to look through other people's code and I hope that maybe someone else will get one of their problems solved through my own trial and error. Anyway, thanks in advance! :)
^GBA Humor...lol.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3381 - mbcook - Sun Feb 23, 2003 9:30 pm
I think your missing a bracket before the code you posted. Could you give us a few lines before the problem too?
_________________
--Michael
#3392 - Jer1400 - Mon Feb 24, 2003 12:21 am
I gave you everything...I'm not missing a bracket that's not supposed to be there. You see, there is an error in the savescreen function...anyway I just gave you all the code.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3395 - col - Mon Feb 24, 2003 12:41 am
Jer1400 wrote: |
I gave you everything......anyway I just gave you all the code. |
...er so you're suggesting that you have 180 blank lines in the file before the code starts? hmm... ;-)
I think mbcook is probably right. The error is in the code that comes before the saveScreen() function
Cheers
col
#3398 - Jer1400 - Mon Feb 24, 2003 1:28 am
No, all that file contains is a bunch of functions. It was working fine until I added the savescreen() function, and the errors even give me the exact places where they occured.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3400 - mbcook - Mon Feb 24, 2003 1:40 am
Well that code looks correct to me. The error has to be before there. I don't know how it couldn't be.
_________________
--Michael
#3409 - Jer1400 - Mon Feb 24, 2003 6:18 am
Well, usually what it means is that there was just a semi-colin left off. But what it does is it tells you the line and the character or function that comes right before the error. I think something is out of sequence or just plain left off. The problem is I don't know what.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3418 - headspin - Mon Feb 24, 2003 12:13 pm
The line numbers given arn't necessarily where you have made an error, it's only where the compiler has realised there is an error and the line number is a guess of where the error has occured. Often the compiler gives the correct line number but sometimes it dosn't. Generally the error will be around the it which is why several people have said to look above the code given. I can't see any error in the code posted so it's almost certainly above it.
I would get in a habit of writing code with indentation when you have code within { .. } brackets because without it code is harder to read and debug.
#3456 - Jer1400 - Tue Feb 25, 2003 7:50 am
As I have said before, the above code consists of a bunch of functions I use to draw stuff. I've used all of those functions and compiled things without error several times before. It was only when I added that method that it said it had an error. I tested it by taking that one method out and compiling it, and guess what? It gave me the same error message, and on the same lines, respectively. Is there any so-called "guru" around here that I can talk to? I know most communities usually have one or two.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3462 - Splam - Tue Feb 25, 2003 11:45 am
errr
int tempscreen [100000];
where do you think that is going? 390+k.. defining that has probably confused the compiler somewhat, definining it inside a function then referencing it from another function is also not a good idea ;)
#3465 - Paul Shirley - Tue Feb 25, 2003 1:11 pm
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:45 pm; edited 1 time in total
#3489 - Jer1400 - Tue Feb 25, 2003 10:50 pm
Are any of you listening?! I compiled that function and that function alone and I got the same error. I took it out and compiled it and no errors came up in drawing.h! It has nothing to do with what is above there! All that is there are some of starmonkey's drawing functions that I modified. But if you still want it, when I get home I'll post it. Damn this is frustrating-I can't belive no one will listen to anything I am saying!
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3495 - Paul Shirley - Wed Feb 26, 2003 2:20 am
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:46 pm; edited 1 time in total
#3501 - Jer1400 - Wed Feb 26, 2003 6:25 am
//////////////////////////
///Drawing.h///
///////////////////////
#define RGB16(r,g,b) ((r)+(g<<5)+(b<<10))
u16* videoBuffer = (u16*)0x6000000;
/////////////////////////
///Functions///
///////////////////////
//Set a pixel on the screen!
void SetPixel(int x, int y, int r, int g, int b) {videoBuffer[x+y*240] = RGB16(r,g,b);}
//Draw a rectangle on the screen!
void FillRect(int x_start, int y_start, int x_stop, int y_stop, int r, int g, int b)
{
int x_current;
int y_current;
for(x_current = x_start; x_current<x_stop; x_current++) //loop through all x
{
for(y_current = y_start; y_current<y_stop; y_current++) //loop through all x
{
videoBuffer[x_current+y_current*240] = RGB16(r,g,b);
}
}
}
//Fill the screen with color!
void FillScreen(int r, int g, int b)
{
int x_currentfillscreen;
int y_currentfillscreen;
for(x_currentfillscreen = 0; x_currentfillscreen<240; x_currentfillscreen++)
{
for(y_currentfillscreen = 0; y_currentfillscreen<160; y_currentfillscreen++)
{
videoBuffer[x_currentfillscreen+y_currentfillscreen*240] = RGB16(r,g,b);
}
}
}
//Draw a line on the screen!
void DrawLine(int x1, int y1, int x2, int y2, int r, int g, int b)
{
int i, deltax, deltay, numpixels;
int d, dinc1, dinc2;
int x, xinc1, xinc2;
int y, yinc1, yinc2;
deltax = abs(x2 - x1);
deltay = abs(y2 - y1);
if(deltax >= deltay)
{
numpixels = deltax + 1;
d = (2 * deltay) - deltax;
dinc1 = deltay << 1;
dinc2 = (deltay - deltax) << 1;
xinc1 = 1;
xinc2 = 1;
yinc1 = 0;
yinc2 = 1;
}
else
{
numpixels = deltay + 1;
d = (2 * deltax) - deltay;
dinc1 = deltax << 1;
dinc2 = (deltax - deltay) << 1;
xinc1 = 0;
xinc2 = 1;
yinc1 = 1;
yinc2 = 1;
}
if(x1 > x2)
{
xinc1 = -xinc1;
xinc2 = -xinc2;
}
if(y1 > y2)
{
yinc1 = -yinc1;
yinc2 = -yinc2;
}
x = x1;
y = y1;
for(i = 1; i < numpixels; i++)
{
SetPixel(x, y, r, g, b);
if(d < 0)
{
d = d + dinc1;
x = x + xinc1;
y = y + yinc1;
}
else
{
d = d + dinc2;
x = x + xinc2;
y = y + yinc2;
}
}
}
//Draw a circle on the screen!
void DrawCircle(int xCenter, int yCenter, int radius, int r, int g, int b)
{
int x = 0;
int y = radius;
int p = 3 - 2 * radius;
while (x <= y)
{
SetPixel(xCenter + x, yCenter + y, r, g, b);
SetPixel(xCenter - x, yCenter + y, r, g, b);
SetPixel(xCenter + x, yCenter - y, r, g, b);
SetPixel(xCenter - x, yCenter - y, r, g, b);
SetPixel(xCenter + y, yCenter + x, r, g, b);
SetPixel(xCenter - y, yCenter + x, r, g, b);
SetPixel(xCenter + y, yCenter - x, r, g, b);
SetPixel(xCenter - y, yCenter - x, r, g, b);
if (p < 0)
{
p += 4 * x++ + 6;
}
else
{
p += 4 * (x++ - y--) + 10;
}
}
}
//Fill a circle on the screen!
void FillCircle(int x, int y, int radius, int r, int g, int b)
{
float crad=0;
while(crad<radius)
{
crad=crad+.5;
DrawCircle(x,y,crad,r,g,b);
}
crad=0;
while(crad<radius-1)
{
crad=crad+.5;
DrawCircle(x-1,y,crad,r,g,b);
}
crad=0;
while(crad<radius-1)
{
crad=crad+.5;
DrawCircle(x+1,y,crad,r,g,b);
}
}
//Draw a circle that fades between 2 colors on the screen!
int FadeCircle(int x, int y, int radius, int r, int g, int b, int r2, int g2, int b2)
{
float cradius=radius;
int cr=r, cg=g, cb=b;
while (cradius>.5)
{
FillCircle(x,y,cradius,cr,cg,cb);
if (cr>r2)
cr--;
if (cr<r2)
cr++;
if (cg>g2)
cg--;
if (cg<g2)
cg++;
if (cb>b2)
cb--;
if (cb<b2)
cb++;
cradius=cradius-.5;
}
return 0;
}
///SaveScreen\\\
void SaveScreen()
{
int x=0, y=0;
const u16 tempscreen [];
for (y=0; y<161; y++)
{
for (x=0; x<241; x++)
tempscreen[x+y*240]=videoBuffer[x+y*240];
}
}
///RestoreScreen\\\
void RestoreScreen(int x,int y,int x2,int y2,int xlocation,int ylocation)
{
int xcurrent=0, tempy=ylocation, tempx=xlocation;
for (y=y; y<y2; y++)
{
tempx=xlocation;
for (xcurrent=x; xcurrent<x2; xcurrent++)
{
videobuffer[tempx+tempy*240]=tempscreen[xcurrent+y*240];
tempx++;
}
tempy++;
}
}
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3505 - siaspete - Wed Feb 26, 2003 8:29 am
Please use the code tags! Also, is your post any more urgent than others?
#3538 - Jer1400 - Wed Feb 26, 2003 10:54 pm
It used to be, but not any more; I fixed it this morning. What I did was move the comments away from the functions 1 line and I made tempscreen a global variable.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3539 - Paul Shirley - Wed Feb 26, 2003 11:06 pm
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:46 pm; edited 1 time in total
#3548 - Jer1400 - Thu Feb 27, 2003 3:45 am
lol, my editor is notepad and my compiler is gcc.:)
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3551 - Jaywalk - Thu Feb 27, 2003 7:45 am
Ah - the infamous Notepad. Do yourself a big favour and get - well - anything else. Here, try dowloading Textpad at http://textpad.com. This is quite a good editor.
#3556 - Paul Shirley - Thu Feb 27, 2003 2:38 pm
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:47 pm; edited 1 time in total
#3566 - animension - Thu Feb 27, 2003 7:55 pm
I recommend EditPlus for coding if you are running in Windows environment.
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin
#3574 - Probably Bob - Fri Feb 28, 2003 5:56 am
Your error is really simple, and I can't beleive no one else has noticed.
You are missing the terminating ';' on line 182.
That's it.
#3575 - Probably Bob - Fri Feb 28, 2003 5:59 am
I'm sorry, I can't beleive I just said that.
How incredibly wrong could I be :)
I'm drunk, ok? :)
#3577 - Jer1400 - Fri Feb 28, 2003 7:12 am
Okay drunken probably bob.;)
But alas! Another problem has come my way! This time I have no clue what's going on, mainly because I'm such a newb at this stuff.:)
Anyway, it's with the savescreen / restore screen methods. I know there is something wrong within the savescreen that has something to do with temperarily transfering the "videoBuffer" data into the tempscreen array. Something doesn't transfer right, I think it may have something to do with the type of variable I make tempscreen. Anyway, keep in mind that there is no error, and that the problem is it just doesn't do what it's supposed to.
drawing.h:
//////////////////////////
///Drawing.h///
///////////////////////
#define RGB16(r,g,b) ((r)+(g<<5)+(b<<10))
u16* videoBuffer = (u16*)0x6000000;
int tempscreen[];
///////The other drawing functions were here, btw
///SaveScreen\\\
void SaveScreen()
{
int x=0, y=0;
for (y=0; y<161; y++)
{
for (x=0; x<241; x++)
tempscreen[x+y*240]=videoBuffer[x+y*240];
}
}
///RestoreScreen\\\
void RestoreScreen(int x,int y,int x2,int y2,int xlocation,int ylocation)
{
int xcurrent=0, tempy=ylocation, tempx=xlocation;
for (y=y; y<y2; y++)
{
tempx=xlocation;
for (xcurrent=x; xcurrent<x2; xcurrent++)
{
videoBuffer[tempx+tempy*240]=tempscreen[xcurrent+y*240];
tempx++;
}
tempy++;
}
}
And this is the main program:
#include"gba.h"
#include"screenmode.h"
#include"keypad.h"
#include"stdlib.h"
#include"drawing.h"
#include"screen_effects.h"
#include"name.h"
/////////////////////////////////
///Main Program///
///////////////////////////////
int main(void)
{
int stall=0, pixels=0, x, y, x2, y2;
SetMode(MODE_3 | BG2_ENABLE );
fadeout(1); //uses hardware fading to fade the screen out.
DrawName(); //draws an image
SaveScreen(); //it never seems to get past here, and if I take it out
//the restore screen works, but it just draws some weird random lines.
FillScreen(0,0,0); //it never gets to here. (this paints the screen black)
while(stall<1000000)
{
stall++;
}
stall=0;
fadein(1); //fade the screen back in with hardware fading.
while(pixels<160000)
{
x=rand()%241;
y=rand()%161;
x2=x+1;
y2=y+1;
RestoreScreen(x,y,x2,y2,x,y);
pixels++;
}
DrawName();
while(1){}
} //end main
...and that's it.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3582 - Probably Bob - Fri Feb 28, 2003 2:12 pm
Right sober now :)
You didn't say what the actual sypmtoms were, so I can't tell whether this is the entire problem, but :
[code]
for (y=0; y<161; y++)
{
for (x=0; x<241; x++)
[/code]
should be
[code]
for (y=0; y<160; y++)
{
for (x=0; x<240; x++)
[/code]
as x can only go up to 239 and y up to 159. Running that code with x=240, y=0 is exactly equivalent to having x=0, y=1 which is probably not what you are trying to acheive.
#3588 - Paul Shirley - Fri Feb 28, 2003 6:38 pm
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:47 pm; edited 1 time in total
#3593 - Jer1400 - Fri Feb 28, 2003 8:30 pm
Of course it's a good idea to program games for the gba...that's what I want to do. That's what I am doing. I actually don't need this for the game I am working on now, but it just kind of stumped me and I was wondering.
Oh, and paul, I've tried making that array anywhere from 40000 to 10000000. The size isn't the problem. Somewhere the data is getting scrambled and instead of drawing the old screen, it draws some funky colored lines. I'll post a screenshot in about 8 hours to give you a better idea of what this looks like.
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.
#3599 - Paul Shirley - Fri Feb 28, 2003 9:27 pm
removed
Last edited by Paul Shirley on Sun Mar 28, 2004 9:48 pm; edited 1 time in total
#3616 - Jer1400 - Sat Mar 01, 2003 9:57 pm
What answers? Some guy said program pc games and another told me something about the for loop, which is fine and has nothing to do with the tempscreen variable. Anyway, here is that screenshot:
[Images not permitted - Click here to view it]
_________________
http://saoghal.cywh.com/Jer1400/index.html
*Note that the site is still in early development.