Register

Casio Basic to SDK

Discuss issues related to the fx-9860G Software Development Kit
Senior Member
Posts: 68
Joined: Tue May 08, 2012 5:40 pm

Postby happy » Thu May 17, 2012 10:02 am

aapman55 wrote:If i now want to exit the program then i use return 0, but then the program cant be reaccessed again without switching to another menu first. So what i want to know if there is a function that does exactly the same as the menu key in a infinite loop.


You can do what Simon wrote, but if that is too daunting (I personally have never got the hang of syscalls!), you can go with the default calculator behaviour. Which is:
[MENU] button does not exit the addin. It just takes the user to the calculator main menu. Addin is exited only when user presses [MENU] and goes into another addin. If you have defined SetQuitHandler, that is when your handler would be called. Don't return 0 from AddIn_main. If you don't want to use syscalls/revolution etc., you will have to program for this behaviour.

aapman55 wrote:I want to have a random number generator, ive found the function rand() on cprogramming.com. But when i want to print the random number to the screen it doesnt display anything. My display function might be wrong, but thus i cant check if the rand() is working or not. Here is the code that i used:

I haven't tested your code, but: PrintC prints only 1 character I think. Also, please try and not use goto. You will also need a function which will convert int to string since the print functions accept only char*. You will find different implementations of itoa() on the web.

aapman55 wrote:Is it possible to fill the whole array with a certain number? Is it possible to take the sum of all numbers in an array? and the product of an array?


Yes to all, obviously.

Senior Member
Posts: 68
Joined: Tue May 08, 2012 5:40 pm

Postby happy » Thu May 17, 2012 10:10 am

Our posts crossed paths -:)

SimonLothar wrote:I don't remember in which header-file itoa is located. I normally use the syscall.


Don't think it is included. Can't find it in the "C Standard Libraries" doc.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Postby SimonLothar » Thu May 17, 2012 10:11 am

aapman55 wrote:I also want to do something with arrays. Is it possible to fill the whole array with a certain number? Is it possible to take the sum of all numbers in an array? and the product of an array?


Code: Select all
#define ARRAYSIZE 20
unsigned int i;
unsigned int sum;
unsigned int product;
// declare an array
unsigned int aInt[ ARRAYSIZE ];

// fill the array with certain values
for ( i=0; i<ARRAYSIZE; i++) aInt[ i ] = 12;
 
// calculate the sum
sum = 0;
for ( i=0; i<ARRAYSIZE; i++) sum += aInt[ i ];

// calculate the product
product = 1;
for ( i=0; i<ARRAYSIZE; i++) product *= aInt[ i ];

// especially the product can be subject to overflow

I'll be back!

Senior Member
User avatar
Posts: 66
Joined: Sun Apr 15, 2012 4:00 pm
Calculators: Casio fx-9860G

Postby aapman55 » Thu May 17, 2012 8:29 pm

thanks guys for the reply.
in point 1 i meant not to really exit the program, just as the menu button does.

The random code i do not totally understand with the syscalls etc. But this is what i think.
The code above the main add in is just to define the functions itoa and rand().
and in the program itself it's being used.

but what does this part of the code does?
Code: Select all
rand( RTC_GetTicks() );


when i tried the code the compiler run into 2 errors

Code: Select all
C:\Users\Admin\Documents\CASIO\fx-9860G SDK\random\random.c(25) : C2500 (E) Illegal token "="
C:\Users\Admin\Documents\CASIO\fx-9860G SDK\random\random.c(53) : C2202 (E) Number of parameters mismatch


the corresponding lines in the code are:

Code: Select all
unsigned int rand( int seed = 0 ){

and
Code: Select all
    randomnr = rand();


I encounter these errors often,then i just randomly do something like adding spaces or removing spaces and sometimes it works. Maybe you could explain the errors, beacause i cant get this to work.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Postby SimonLothar » Thu May 17, 2012 10:09 pm

aapman55 wrote:but what does this part of the code does?
Code: Select all
rand( RTC_GetTicks() );


it initializes the random-generator with a number which is different on every program start. (RTC_GetTicks()) So the random-number sequence is different with every program run. If the random-number generator would be initialized with a constant value, you always would get the same random number sequence.

aapman55 wrote:
Code: Select all
unsigned int rand( int seed = 0 ){

and
Code: Select all
    randomnr = rand();



try this
Code: Select all
unsigned int rand( int seed ){

and
Code: Select all
    randomnr = rand( 0 );


I think default parameters are not allowed with C. I use C++.
I'll be back!

Senior Member
User avatar
Posts: 66
Joined: Sun Apr 15, 2012 4:00 pm
Calculators: Casio fx-9860G

Postby aapman55 » Fri May 18, 2012 9:47 am

thanks simon, with these building blocks i think i am able to convert some of my basic programs to C.

Senior Member
User avatar
Posts: 66
Joined: Sun Apr 15, 2012 4:00 pm
Calculators: Casio fx-9860G

Postby aapman55 » Sat May 19, 2012 7:55 pm

i encountered a problem while converting a basic game to C. Is the function GetKey pausing the program and waits till you press a button? If so then i need another program. Because i want the the same get key function as in casio basic.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Postby SimonLothar » Sat May 19, 2012 9:00 pm

aapman55 wrote:i encountered a problem while converting a basic game to C. Is the function GetKey pausing the program and waits till you press a button? If so then i need another program. Because i want the the same get key function as in casio basic.

Yes, the SDK-GetKey is blocking.

This is what you need:

Code: Select all
// if you use the instant syscalls:
#define SCA 0xD201D002
#define SCB 0x422B0009
#define SCE 0x80010070
typedef void(*sc_vpuc)(unsigned char*);
const unsigned int sc06C4[] = { SCA, SCB, SCE, 0x06C4 };
#define KBD_PRGM_GetKey (*(sc_vpuc)sc06C4)

//
int PRGM_GetKey(){
unsigned char buffer[12];
        KBD_PRGM_GetKey( buffer );
        return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2]  & 0xF0 )  >> 4 );
}

PRGM_GetKey() is not blocking and returns the PRGM GetKey values.
But PRGM_GetKey() does not automatically rewrite the screen like SDK-GetKey.
You have to refresh the display with Bdisp_PutDisp_DD() yourself.

This is the fx-9860 version!
I'll be back!

Senior Member
User avatar
Posts: 66
Joined: Sun Apr 15, 2012 4:00 pm
Calculators: Casio fx-9860G

Postby aapman55 » Fri May 25, 2012 8:25 pm

Hi simon, thanks for the reply. Havent had time since now to check it out.
to check if it is working i wrote this small program, but it isnt working, it just gives one number and then does nothing. I also included the Bdisp_PutDisp_DD().

here is the code, maybe you can point out what i did wrong. I included the syscalls for prgm getkey and itoa.

Code: Select all
int AddIn_main(int isAppli, unsigned short OptionNum)
{
    unsigned int key;
unsigned char toets[15];
    Bdisp_AllClr_DDVRAM();
while( 1 ){
PRGM_GetKey(&key);
itoa( key,toets );
locate(1,1);
Print(toets);
Bdisp_PutDisp_DD();
}

    return 1;
}

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Postby SimonLothar » Fri May 25, 2012 9:00 pm

PRGM_GetKey is an int function, which returns the pressed key as int-function result.
GetKey passes the pressed key via an unsigned int-pointer-parameter ( &key ).

Code: Select all
int AddIn_main(int isAppli, unsigned short OptionNum)
{
int key;                            // changed
unsigned char toets[15];
    Bdisp_AllClr_DDVRAM();
    while( 1 ){
      key = PRGM_GetKey();        // changed
      itoa( key,toets );
      locate(1,1);
      Print(toets);
      Bdisp_PutDisp_DD();
   }
   return 1;
}
I'll be back!

PreviousNext

Return to Casio fx-9860 SDK

Who is online

Users browsing this forum: No registered users and 27 guests