PrizmSDK / GCC is C, not C++, so the ' extern "C" { ' is superfluous and wrong. That's only needed when you're putting C code in C++ code.
now this is my file STRLIST.HPP:

http://tinypaste.com/480ed7de

sdk gives me this error:


Code:
                 from main.c:13:
../..//include/STRLIST.hpp:27:1: error: unknown type name 'class'
../..//include/STRLIST.hpp:27:18: error: expected '=', ',', ';', 'asm' or '__att
ribute__' before '{' token
C doesn't have classes or class members. You'll need to unfold that into simple functions, and if you'd like, make a struct to pass the class private/public variables around.
I have some questions about the example prizmsdk program:


Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
 
int main(void) {
   int key;
    char blah[10];
    blah[1]='k';
     
   while (1) {
        GetKey(&key);
      switch (key) {
      }
   }
 
   return;
}


What does "return" do? what would happen if i made a program without it?

what does this section of code do?


Code:

   while (1) {
        GetKey(&key);
      switch (key) {
      }
   }


Also, what happens when you press the menu key? Does it pause the program? Or does it do what AC/on does in BASIC progs?
return simply returns execution to the function that called the function you are currently in, in this case, it returns to the OS.

while(1) is the same is while(true), meaning it loops forever unless you break out of it. Hitting the menu key breaks out of it for you, btw.

The GetKey function takes a pointer to an integer as an argument, and I believe it blocks execution until a key is pressed. It then returns the keycode in the variable pointed to by that pointer. In this case the "&" symbol means "make a pointer of". You'll notice key is an int. Well, &key means "give me a pointer to the variable key which is an int"

The Switch statement allows you to do things based on what key was pressed.
graphmastur wrote:
return simply returns execution to the function that called the function you are currently in, in this case, it returns to the OS.

while(1) is the same is while(true), meaning it loops forever unless you break out of it. Hitting the menu key breaks out of it for you, btw.

The GetKey function takes a pointer to an integer as an argument, and I believe it blocks execution until a key is pressed. It then returns the keycode in the variable pointed to by that pointer. In this case the "&" symbol means "make a pointer of". You'll notice key is an int. Well, &key means "give me a pointer to the variable key which is an int"

The Switch statement allows you to do things based on what key was pressed.


Does the menu key always break out of loops?
flyingfisch wrote:
Does the menu key always break out of loops?


It does if it's caught during the GetKey(&key) call. Otherwise, the MENU key does nothing when pressed.
There's also GetKeyWait_OS(), which I use in a lot of routines and which can be instructed to either return [MENU] as a keycode or process it and go to the menu.
I have noticed Flyingfisch you have been asking about some basic C programming why don't you check this site out: www.cprogramming.com
This will get you familiar with the structure and syntax with C so you will be ready for programming on the Prizm. Sorry if you actually know C and I am just being dumb.
how to obtain a random number between two values in prizm C?
The usual way:
Code:
/*
 * Random integer in range [min,max)
 */
unsigned randInt(unsigned min, unsigned max) {
    return (rand()%(max - min)) + min;
}

This'll exhibit a slight bias depending on the desired max value (and that of RAND_MAX), but meh.
how can i use that function to call others, according to the number, similar to the example below for fx9860:



Code:

int intro;
int getkey;
int seed;
int secondseed;
int number;
int a;
int timecheck;
   timecheck=RTCReadSecond();
   if(timecheck==0){RTCSetSecond(0,0);RTCStart();}
   Bdisp_AllClr_DDVRAM();

while(1==1){
      RestoreDisp(1);
Bdisp_PutDisp_DD();
      GetKey(&getkey);
if(getkey==KEY_CTRL_EXE){
         srand(RTCReadSecond());
         seed=(int)((float)rand()*50/(RAND_MAX+1)+1);
         srand(seed);
         secondseed=(int)((float)rand()*50/(RAND_MAX+1)+1);
         srand(seed*secondseed);
         number=(int)((float)rand()*20/(RAND_MAX+1)+1);
      if(number==1){
         AskPic(0,0,3);
         GetKey(&a);
         xim1(0,0,3);
         GetKey(&a);
      }
if(number==2){
         AskPic(0,0,3);
         GetKey(&a);
         xim2(0,0,3);
         GetKey(&a);
      }
You could use it almost exactly the same. I'd probably simplify that code to something like:


Code:
         number=randInt(0,19);
         AskPic(0,0,3);
         GetKey(&a);
         switch(number) {
                  case 1:
                           xim1(0,0,3);
                           break;
                  case 2:
                           xim2(0,0,3);
                           break;
         }
         GetKey(&a);
hum, i need some header files?


Code:
main.o: In function `_main':
main.c:(.text.startup+0x58): undefined reference to `_randInt'
You need some library's, that said libfxcg includes a rand() function, similar to the one in the std libc. Perhaps that is what Kerm meant to type.
randInt() is the function Tari posted a few posts back:
Tari wrote:
The usual way:
Code:
/*
 * Random integer in range [min,max)
 */
unsigned randInt(unsigned min, unsigned max) {
    return (rand()%(max - min)) + min;
}

This'll exhibit a slight bias depending on the desired max value (and that of RAND_MAX), but meh.
Indeed, I was assuming you had included the randInt function that Tari had told you about.
I get this error:


Code:

flyingfisch@flyingfisch-Office-Computer:~/Desktop/PrizmSDK-0.3/projects/project$ make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/build/example.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib   -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/src/example.c -o example.o
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/src/example.c: In function 'main':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/src/example.c:19:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/src/example.c:24:2: warning: 'return' with no value, in function returning non-void [-Wreturn-type]
/usr/local/cross/bin/sh3eb-elf-gcc  example.o -mb -m4a-nofpu -mhitachi -nostdlib -T/home/flyingfisch/Desktop/PrizmSDK-0.3/common/prizm.ld -Wl,-static -Wl,-gc-sections  -L/home/flyingfisch/Desktop/PrizmSDK-0.3/lib -lfxcg -lgcc -o /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/project.bin
mkg3a -n basic:example -i uns:../unselected.bmp -i sel:../selected.bmp /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/project.bin /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/project.g3a
Unsupported PNG bit depth or color type, must be RGB-8
make[1]: *** [/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/project.g3a] Segmentation fault
make: *** [build] Error 2


With this code:


Code:

#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <color.h>
 
int main(void) {
   int key;
   int color = TEXT_COLOR_BLACK;
   int text_x;
   
   while (1) {
      PrintXY (text_x, 1, "Text", 1, color);
      
        GetKey(&key);
      switch (key) {
      
      }
      text_x = text_x + 1;
      
      if (text_x = 21) {
         text_x = 1;
      }
   }
 
   return;
}
I poked Tari, but the error is revealed by this:

Code:
Unsupported PNG bit depth or color type, must be RGB-8
make[1]: *** [/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/project.g3a] Segmentation fault
Sounds like you're not passing in real PNGs.

Also, heed those Warnings.
KermMartian wrote:
I poked Tari, but the error is revealed by this:

Code:
Unsupported PNG bit depth or color type, must be RGB-8
make[1]: *** [/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/project/project.g3a] Segmentation fault
Sounds like you're not passing in real PNGs..

They're real PNGs, but the color depth is bad. I was able to reproduce the crash in mkg3a by passing a palettized PNG and subsequently fixed it. mkg3a only supports 24-bit RGB color.

Offtopic mini-rant: people need to learn to read error messages. I'm glad this pointed out a minor bug in mkg3a, but the error message before it crashes is pretty clear..
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 4 of 5
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement