Register

Need some newbie help please

Discuss issues related to the fx-9860G Software Development Kit
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

Re: Need some newbie help please

Postby SimonLothar » Thu Jul 04, 2013 6:29 am

MrMagoo wrote:So each function needs to be declared just like a variable?
It ain't necessarily so.

It's a matter of the order of function definitions.
In C/C++ the compiler has to know everything before it is used.

if

Code: Select all
void option1(){
Bdisp_AllClr_DDVRAM();
locate(1,2);
Print((unsigned char*)"You pressed Option1");
}

would precede Addin_Main,
the interface declaration

void option1();

could be omitted.

But that are basic aspects of C/C++.

MrMagoo wrote:Would I also be right in thinking if I added all the functions to their own file, and inlcuded that file, I wouldnt need to declare them?

Usually you gather declarations (interfaces) like

void option1();
void option2();

in a header-file (*.h or *.hpp) and include this file at the beginning of a source file, where the functions are needed.

The function bodies (implementation) are stored in separate files (*.c or *.cpp).
You can include the function bodies directly as source. In this case the source is compiled repeatedly, irrespective of whether the source has been changed or not.
If you include the function module to the source file list of the SDK-project, the SDK generates an object-file (*.obj), which is linked to the resulting binary file. After that the source is not recompiled, unless it has been changed or you do a "rebuild all".
With large function modules or a larger number of function modules, your choice would significantly affect the compile time.

---
Some SDK-specific hint:

The declaration of a variable outside of any function body like

int lContinue = 1;

results in a global variable, which is stored in static RAM.
Static RAM is a limited resource (8 KiB) with the CASIO SDK.
You should avoid global variables, if possible.
I'll be back!

Member
User avatar
Posts: 44
Joined: Tue Jul 02, 2013 11:57 am
Location: London
Calculators: Casio fx-7400G, Casio fx-7400G PLUS, Casio fx-7400GII, Casio fx-9750G, Casio fx-9750G PLUS, Casio fx-9860GII

Re: Need some newbie help please

Postby MrMagoo » Thu Jul 04, 2013 7:58 am

that makes perfect sense. Finally the light at the end of the tunnel. :-)

Now how do we get input from the user and assign it to a variable?
Thanks for everything so far.
"The trouble with internet quotations, is that the majority are totally made up." - Abraham Lincoln 1863

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

Re: Need some newbie help please

Postby SimonLothar » Thu Jul 04, 2013 9:32 am

MrMagoo wrote:Now how do we get input from the user and assign it to a variable?
There are two basic approaches possible.
1. You can try to use stringInput from mylib.
2. You can try to write the user input function from scratch. This could be a useful exercise.
I'll be back!

Member
User avatar
Posts: 44
Joined: Tue Jul 02, 2013 11:57 am
Location: London
Calculators: Casio fx-7400G, Casio fx-7400G PLUS, Casio fx-7400GII, Casio fx-9750G, Casio fx-9750G PLUS, Casio fx-9860GII

Re: Need some newbie help please

Postby MrMagoo » Thu Jul 04, 2013 10:15 am

I'd like to do option 2, whats the best approach?
I generally need between 4 and 10 inputs for the various calculations, and in the old casio basic I would split these up into 3 or 4 a page until I cleared the screen.
"The trouble with internet quotations, is that the majority are totally made up." - Abraham Lincoln 1863

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

Re: Need some newbie help please

Postby SimonLothar » Mon Jul 08, 2013 9:56 pm

The following snippet is a very simple line-editor. But it may serve as starting point for some experiments.
I hoped that I could avoid syscalls. But one is needed to control the cursor's visibility. You could put the syscall-part in some file and include it.

Code: Select all
#ifdef __cplusplus
  extern "C" {
#endif

#include "fxlib.h"
#include "string.h"

// SYSCALLS Start
// the following definitions are only needed once
#define SCA 0xD201D002
#define SCB 0x422B0009
#define SCE 0x80010070
// 0x80010070 is the fx-9860-syscall-entry point

// now define some function pointer types
// (for every syscall's interface a different function pointer type is required)
// the following type is for syscalls, which return nothing and require a integer as input.
typedef void(*sc_vi)(int);
//
const unsigned int sc013A[] = { SCA, SCB, SCE, 0x013A };
#define Cursor_SetFlashMode (*(sc_vi)sc013A)
// SYSCALLS End

//
int InputString( int x, int y, unsigned char*prompt, unsigned char*buffer, int lmax ){
int pos;
int lContinue = 0;
unsigned int key;
   Cursor_SetFlashMode( 1 );
   pos = strlen( (char*)buffer );

   locate( x, y );
   Print( prompt );
   while ( lContinue == 0 ){
      locate( x, y+1 );
      PrintLine( buffer, 22-x );
      locate( x + pos, y + 1 );
      GetKey( &key );
      if ( ( key >= 0x30 ) && ( key <= 0x39 ) ){
      }else{
         switch ( key ){
            case '.' :
               break;
            case KEY_CTRL_DEL :
               key = 0;
               if ( pos > 0 ) pos--;
               buffer[ pos ] = 0;
               break;
            case KEY_CTRL_EXE :
               key = 0;
               lContinue = 1;
               break;
            case KEY_CTRL_EXIT :
               key = 0;
               lContinue = 2;
               break;
            default :
               key = 0;
               break;
         };
      }
      if ( key > 0 ){
         if ( pos < lmax ){
            buffer[ pos ] = key;
            pos++;
            buffer[ pos ] = 0;
         }
      }
   }
   Cursor_SetFlashMode( 0 );
   return ( lContinue );
}

int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned char buffer[21];
int editresult;

   Bdisp_AllClr_DDVRAM();

   memset( buffer, 0, sizeof( buffer ) );   
   
    while(1){
      editresult = InputString( 1, 1, "My prompt:", buffer, 20 );
      locate( 1, 4 );
      PrintLine( buffer, 21 );
   };
    return 1;
}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section

#pragma section _TOP

int InitializeSystem(int isAppli, unsigned short OptionNum)
{
    return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}

#pragma section

#ifdef __cplusplus
}
#endif
I'll be back!

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

Re: Need some newbie help please

Postby SimonLothar » Tue Jul 09, 2013 6:39 am

This version of InputString is a bit enhanced. Additionally a simple example of how to process the resulting string is included.

Code: Select all
#ifdef __cplusplus
  extern "C" {
#endif

#include "fxlib.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"

// SYSCALLS Start
// the following definitions are only needed once
#define SCA 0xD201D002
#define SCB 0x422B0009
#define SCE 0x80010070
// 0x80010070 is the fx-9860-syscall-entry point

// now define some function pointer types
// (for every syscall's interface a different function pointer type is required)
// the following type is for syscalls, which return nothing and require a integer as input.
typedef void(*sc_vi)(int);
//
const unsigned int sc013A[] = { SCA, SCB, SCE, 0x013A };
#define Cursor_SetFlashMode (*(sc_vi)sc013A)
// SYSCALLS End

//
int InputString( int x, int y, unsigned char*prompt, unsigned char*buffer, int bufferSize ){
unsigned int key, edit_key, return_key = 0;
int pos, len;

   Cursor_SetFlashMode( 1 );   // set cursor visibility on
   pos = strlen( (char*)buffer );// initially set the cursor to the end of the string
//   pos = 0;   // initially set the cursor to the start of the string

   locate( x, y );
   Print( prompt );
   while ( !return_key ){
      locate( x, y + 1 );
      PrintLine( buffer, 22-x );
      locate( x + pos, y + 1 );
      GetKey( &key );
      edit_key = 0;
      if ( ( key >= 0x30 ) && ( key <= 0x39 ) ){
         edit_key = key;
      }else{
         switch ( key ){
            case KEY_CHAR_MINUS :
            case KEY_CHAR_PMINUS :
               // the sign: first character only
               if ( pos == 0 ) edit_key = '-';
               break;
            case KEY_CHAR_DP :
               // check if the dot is already present
               if ( !strchr((char*)buffer, '.') ) edit_key = key;
               break;
            case KEY_CTRL_DEL :
               if ( pos > 0 ) pos--;
               len = strlen( (char*)buffer );   // get the current length of the string
               memmove( buffer+pos, buffer+pos+1, len-pos);   // shift the memory: XXYDYYY -> XXXYYY
               break;
            case KEY_CTRL_RIGHT :
               len = strlen( (char*)buffer );   // get the current length of the string
               if ( pos < len ) pos++;
               break;
            case KEY_CTRL_LEFT :
               if ( pos > 0 ) pos--;
               break;
            case KEY_CTRL_UP :
            case KEY_CTRL_DOWN :
//               return_key = key;
               break;
            case KEY_CTRL_EXE :
            case KEY_CTRL_EXIT :
               return_key = key;
               break;
            default :
               break;
         };
      }
      if ( edit_key ){
         if ( pos < bufferSize-1 ){
            buffer[ pos ] = edit_key;
            pos++;
         }
      }
   }
   Cursor_SetFlashMode( 0 );   // set cursor visibility on
   return ( return_key );
}

int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned char buffer[10];
unsigned char out_buffer[20];
// char**p;
int editresult;
double d;

   Bdisp_AllClr_DDVRAM();
   memset( buffer, 0, sizeof( buffer ) );   
    while(1){
      editresult = InputString( 1, 1, "My prompt:", buffer, sizeof( buffer ) );
      locate( 1, 4 );
      d = atof( (char*)buffer ); // convert the string to some floating point variable
//      d = strtod( (char*)buffer, p );   
// strtod is the better choice, if a conversion error is possible
// if InputString intercepts any possible input error, atof may be sufficient
      d = 2 * d;   // now process the input
      sprintf( (char*)out_buffer, "%f", d );   // convert the processing result back to a presentable string
      PrintLine( out_buffer, 21 );
   };
    return 1;
}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section

#pragma section _TOP

int InitializeSystem(int isAppli, unsigned short OptionNum)
{
    return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}

#pragma section

#ifdef __cplusplus
}
#endif
I'll be back!

Member
User avatar
Posts: 44
Joined: Tue Jul 02, 2013 11:57 am
Location: London
Calculators: Casio fx-7400G, Casio fx-7400G PLUS, Casio fx-7400GII, Casio fx-9750G, Casio fx-9750G PLUS, Casio fx-9860GII

Re: Need some newbie help please

Postby MrMagoo » Tue Jul 09, 2013 11:59 am

Simon,

This is excellent. I think the second example is the one I'd like to use. I'm trying to get it to accept 4 different inputs, but it doesnt seem to like it. Is there an easy way of copying the function to a new code such as "input.c" and then just calling the function from the main script? Could I also include the

Code: Select all
d = atof( (char*)buffer ); // convert the string to some floating point variable


part, so it keeps the script tidy?
"The trouble with internet quotations, is that the majority are totally made up." - Abraham Lincoln 1863

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

Re: Need some newbie help please

Postby SimonLothar » Tue Jul 09, 2013 2:37 pm

Copy this to input.cpp

Code: Select all
#ifdef __cplusplus
  extern "C" {
#endif

#include "fxlib.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"

// SYSCALLS Start
// the following definitions are only needed once
#define SCA 0xD201D002
#define SCB 0x422B0009
#define SCE 0x80010070
// 0x80010070 is the fx-9860-syscall-entry point

// now define some function pointer types
// (for every syscall's interface a different function pointer type is required)
// the following type is for syscalls, which return nothing and require a integer as input.
typedef void(*sc_vi)(int);
//
const unsigned int sc013A[] = { SCA, SCB, SCE, 0x013A };
#define Cursor_SetFlashMode (*(sc_vi)sc013A)
// SYSCALLS End

//
int InputString( int x, int y, unsigned char*prompt, unsigned char*buffer, int bufferSize ){
unsigned int key, edit_key, return_key = 0;
int pos, len;

   Cursor_SetFlashMode( 1 );   // set cursor visibility on
   pos = strlen( (char*)buffer );// initially set the cursor to the end of the string
//   pos = 0;   // initially set the cursor to the start of the string

   locate( x, y );
   Print( prompt );
   while ( !return_key ){
      locate( x, y + 1 );
      PrintLine( buffer, 22-x );
      locate( x + pos, y + 1 );
      GetKey( &key );
      edit_key = 0;
      if ( ( key >= 0x30 ) && ( key <= 0x39 ) ){
         edit_key = key;
      }else{
         switch ( key ){
            case KEY_CHAR_MINUS :
            case KEY_CHAR_PMINUS :
               // the sign: first character only
               if ( pos == 0 ) edit_key = '-';
               break;
            case KEY_CHAR_DP :
               // check if the dot is already present
               if ( !strchr((char*)buffer, '.') ) edit_key = key;
               break;
            case KEY_CTRL_DEL :
               if ( pos > 0 ) pos--;
               len = strlen( (char*)buffer );   // get the current length of the string
               memmove( buffer+pos, buffer+pos+1, len-pos);   // shift the memory: XXYDYYY -> XXXYYY
               break;
            case KEY_CTRL_RIGHT :
               len = strlen( (char*)buffer );   // get the current length of the string
               if ( pos < len ) pos++;
               break;
            case KEY_CTRL_LEFT :
               if ( pos > 0 ) pos--;
               break;
            case KEY_CTRL_UP :
            case KEY_CTRL_DOWN :
//               return_key = key;
               break;
            case KEY_CTRL_EXE :
            case KEY_CTRL_EXIT :
               return_key = key;
               break;
            default :
               break;
         };
      }
      if ( edit_key ){
         if ( pos < bufferSize-1 ){
            buffer[ pos ] = edit_key;
            pos++;
         }
      }
   }
   Cursor_SetFlashMode( 0 );   // set cursor visibility on
   return ( return_key );
}

//
int InputDouble( int x, int y, unsigned char*prompt, double&d ){
unsigned char buffer[20];
int editresult;
   memset( buffer, 0, sizeof( buffer ) );   
    sprintf( (char*)buffer, "%f", d );
    editresult = InputString( x, y, prompt, buffer, sizeof( buffer ) );
   d = atof( (char*)buffer ); // convert the string to some floating point variable
//      d = strtod( (char*)buffer, p );   
// strtod is the better choice, if a conversion error is possible
// if InputString intercepts any possible input error, atof may be sufficient


   return editresult;
};

#ifdef __cplusplus
}
#endif


Copy this to input.hpp

Code: Select all
int InputString( int x, int y, unsigned char*prompt, unsigned char*buffer, int bufferSize );
int InputDouble( int x, int y, unsigned char*prompt, double&value );


And the main:

Code: Select all
#ifdef __cplusplus
  extern "C" {
#endif

#include "fxlib.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"

#include "input.hpp"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned char out_buffer[20];
// char**p;
int editresult;
double d = 1.23;

   Bdisp_AllClr_DDVRAM();
    while(1){
      editresult = InputDouble( 1, 1, "My prompt:", d );
      locate( 1, 4 );
      d = 2 * d;   // now process the input
      sprintf( (char*)out_buffer, "%f", d );   // convert the processing result back to a presentable string
      PrintLine( out_buffer, 21 );
   };
    return 1;
}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section

#pragma section _TOP

int InitializeSystem(int isAppli, unsigned short OptionNum)
{
    return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}

#pragma section

#ifdef __cplusplus
}
#endif


Do not forget to add input.cpp to the SDK's source file list!
I'll be back!

Member
User avatar
Posts: 44
Joined: Tue Jul 02, 2013 11:57 am
Location: London
Calculators: Casio fx-7400G, Casio fx-7400G PLUS, Casio fx-7400GII, Casio fx-9750G, Casio fx-9750G PLUS, Casio fx-9860GII

Re: Need some newbie help please

Postby MrMagoo » Tue Jul 09, 2013 3:21 pm

Ok, done all that.
Got these two errors

E:\Casio\Projects\Inputs\input.hpp(2) : C2500 (E) Illegal token "&"
E:\Casio\Projects\Inputs\Input.c(22) : C1016 (W) Argument mismatch
"The trouble with internet quotations, is that the majority are totally made up." - Abraham Lincoln 1863

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

Re: Need some newbie help please

Postby SimonLothar » Tue Jul 09, 2013 4:33 pm

Possibly a C++ thing. I recommend to rename all source files from *.c to *.cpp. That instructs the SDK to use the C++ compiler.
I'll be back!

PreviousNext

Return to Casio fx-9860 SDK

Who is online

Users browsing this forum: No registered users and 34 guests