I'm not the greatest at C, so somebody can count the number of mistakes I've made...
Alright, so let's make this a bit better. I'll explain why along the way.
Let's begin by removing this:
Code: int Prgm_GetKey();
This only serves to say that the function is here... but are you trying to redefine it? Obviously not!
This kind of line is usually seen in header files, where the function is made known to other source files. You already (I think) have this defined in the headers above, so you don't need to do it again.
Let's change this:
Code: attop:
int looping = 256;
to
Code: int looping;
attop:
looping = 256;
Souvik has quoted what I said on IRC, so I'm just reiterating the fix.
Finally, the big "don't use labels and loops"! Since you are new to the language, this can be forgiven. But what can we use instead?
There are a few solutions, elegant and... not so elegant.
1) Make a if conditional inside the while loop.
Probably the worst way to do it, but...
Code: int main(void) {
int looping = 256;
PrintXY(4, 3, "XXTI-Freakware",0x20,4);
PrintXY(4, 4, "XXSays Hello!",0x20,5);
PrintXY(4, 5, "XXNow kneel before",0x20,2);
while (looping > 0) {
looping--;
Bdisp_PutDisp_DD();
GetKeyWait_OS(&kcol,&krow,KEYWAIT_HALTON_TIMEROFF,1,0,&key);
Bdisp_EnableColor(1);
if (key = Prgm_GetKey()) {
if (key == KEY_PRGM_EXIT) {
looping = 256;
PrintXY(4, 3, "XXTI-Freakware",0x20,4);
PrintXY(4, 4, "XXSays Hello!",0x20,5);
PrintXY(4, 5, "XXNow kneel before",0x20,2);
}
}
}
}
2) Global variable and Functions
Another bad, bad way to do it, but we're getting there.
This time, we make a function to do your initialization.
Code: #include <display_syscalls.h>
#include <display.h>
#include <keyboard_syscalls.h>
#include <STD_syscalls.h>
#include <keyboard.hpp>
#include <color.h>
#include <HEAP_syscalls.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int krow, kcol;
unsigned short key=0;
int looping = 256; // Note that we're outside of the main()!
void init() {
looping = 256;
PrintXY(4, 3, "XXTI-Freakware",0x20,4);
PrintXY(4, 4, "XXSays Hello!",0x20,5);
PrintXY(4, 5, "XXNow kneel before",0x20,2);
}
int main(void) {
init();
while (looping > 0) {
looping--;
Bdisp_PutDisp_DD();
GetKeyWait_OS(&kcol,&krow,KEYWAIT_HALTON_TIMEROFF,1,0,&key);
Bdisp_EnableColor(1);
if (key = Prgm_GetKey()) {
if (key == KEY_PRGM_EXIT) {
init();
}
}
}
}
Doesn't it look cleaner? The best part is that you can easily modify your initialization code just by editing the function! (So you preserve the pluses of having a label!)
3) Pointers and Functions
FINALLY, a better way - we can keep it "local" and be clean too!
This time, we have a thing called a pointer - literally, it points to the variable! It's not a variable, but it points to it. Kinda odd, but you'll eventually figure it out.
We pass a pointer to the resetval() function, and the resetval() function can set the local variable from the pointer given to 256.
(I probably did this all wrong, but...)
Code: #include <display_syscalls.h>
#include <display.h>
#include <keyboard_syscalls.h>
#include <STD_syscalls.h>
#include <keyboard.hpp>
#include <color.h>
#include <HEAP_syscalls.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int krow, kcol;
unsigned short key=0;
void resetval(int *x) {
*x = 256;
}
void init() {
PrintXY(4, 3, "XXTI-Freakware",0x20,4);
PrintXY(4, 4, "XXSays Hello!",0x20,5);
PrintXY(4, 5, "XXNow kneel before",0x20,2);
}
int main(void) {
int looping = 256;
init();
while (looping > 0) {
looping--;
Bdisp_PutDisp_DD();
GetKeyWait_OS(&kcol,&krow,KEYWAIT_HALTON_TIMEROFF,1,0,&key);
Bdisp_EnableColor(1);
if (key = Prgm_GetKey()) {
if (key == KEY_PRGM_EXIT) {
init();
resetval(*looping);
}
}
}
}
Not only do we have the awesome functions, but also we have a way to make any variable equal to 256!
Hope this helps!
(And hopefully I am right
)