Register

[Fx9860] Basic Bdisp and I-O (C)

Learn how to program. Code snippets for creating sprites etc. Submit your own or use those of others.
Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400

[Fx9860] Basic Bdisp and I-O (C)

Postby helder7 » Mon Jul 09, 2012 6:55 pm

Introduction

So this is a quick tutorial on the the basic input output of casio c. Of course for the input, you will need to download Kucalc's Revolution-FX. You can make your own input function, but this is basic, so we will use kucalcs version.

B-DispTutorial
Bdisp functions are all about the screen of the calculator. There are two screens you can draw to. DD and VRAM. DD known as the Display Driver. It is what you see. It is the screen of the calculator. The VRAM is the same thing as RAM in a computer. You can draw to the VRAM first then transfer the data from VRAM to DD. This enables faster drawing. Plus some functions like drawline can only be drawn to VRAM.
Another thing to keep in mind is the Screen Dimensions. It is a 128x64 screen. These are the used by the coordinates for the screen. It basically means 128 pixels across the x axis and 64 across the y. The top left corner and the coordinates of (0,0) while the Lower right hand corner is (127,63). These have to be precise when drawing otherwise you picture will get screwed up. You need the exact pixel location and your dealing with 128x64 pixels. Which adds up to 8192 pixels to choose from.



  1. Bdisp_AllClr_DD/VRAM/DDVRAM()
  2. Bdisp_PutDisp_DD()
  3. Bdisp_DrawLineVRAM()
  4. Bdisp_ClearLineVRAM()
  5. Bdisp_AreaClr_DD/VRAM/DDVRAM()
  6. Bdisp_AreaReverseVRAM()
  7. Bdisp_GetDisp_DD/VRAM()
  8. Bdisp_PutDispArea_DD()
  9. Bdisp_SetPoint_DD/VRAM/DDVRAM()
  10. Bdisp_GetPoint_VRAM()
  11. Bdisp_WriteGraph_DD/VRAM/DDVRAM()
  12. Bdisp_ReadArea_DD/VRAM()

Bdisp_AllClr_DD/VRAM/DDVRAM();

This is the function you would most likely call at the very start of the add in to clear the menu of the screen. It basically clears the screen. You can choose to clear the DD, VRAM or both.

Clearing the DD at the start
Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DD();
    Sleep(3000);
}


#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


This simple code clears the Display Driver. It would leave the information on the VRAM but the menu is only on the DD.

Clearing the VRAM
Clearing just the VRAM could be useful. You could leave and image on the display as another is drawn to the VRAM. Then clear the display and then put the VRAM to DD. Here is an example using print_mini to print some text to VRAM but leave the menu on the DD. The after 3 seconds clear the Display and put the text there. Then clear the VRAM and draw some more text. but wait 3 seconds till its drawn.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    PrintMini(0,0,(unsigned char*)"Text 1",MINI_OVER);
    Sleep(3000);
    Bdisp_AllClr_DD();
    Bdisp_PutDisp_DD();
    Bdisp_AllClr_VRAM();
    PrintMini(0,0,(unsigned char*)"Text 2",MINI_OVER);
    Sleep(3000);
    Bdisp_AllClr_DD();
    Bdisp_PutDisp_DD();
    Sleep(3000);
}


#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


Clearing everything
Bdisp_AllClr_DDVRAM clears both the disply and vram. This is almost always used at the start.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    Sleep(3000);
}


#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


Bdisp_PutDisp_DD()
Bdisp_PutDisp_DD() basicly transfers all of the data from the VRAM to the DD. Here is an example.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    PrintMini(0,0,(unsigned char*)"I am printed to the the VRAM",MINI_OVER);
    PrintMini(0,7,(unsigned char*)"first and then transfered ",MINI_OVER);
    PrintMini(0,14,(unsigned char*)"to the DD",MINI_OVER);
    Bdisp_PutDisp_DD();
    Sleep(3000);
}


#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


Bdisp_DrawLineVRAM()
This function draws a line onto the VRAM. It takes 4 arguments. x1, y1, x2, and y2. These are the coordinates of the line. x1 and y1 are the coordinates for the first point of the line. x2 and y2 are the end points. A line is then drawn between them.
The following example draws a border around the screen and then a cross through the center. This is the transferred to the DD.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    Bdisp_DrawLineVRAM(0,0,127,0);
    Bdisp_DrawLineVRAM(127,0,127,63);
    Bdisp_DrawLineVRAM(127,63,0,63);
    Bdisp_DrawLineVRAM(0,63,0,0);
    Bdisp_DrawLineVRAM(0,0,127,64);
    Bdisp_DrawLineVRAM(127,0,0,63);
    Bdisp_PutDisp_DD();
    Sleep(3000);
}


#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


Bdisp_ClearLineVRAM()
This is the same as Bdisp_DrawLineVRAM() except that it clears the line instead of drawing it. It takes the same amount of arguments as drawline.
The following example uses a for loop to Draw lines the make the screen black. Then it does the same as the draw line example but its white on black.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
int y;
    Bdisp_AllClr_DDVRAM();
    for(y=0;y<=63;y++){
        Bdisp_DrawLineVRAM(0,y,127,y);
    }
    Bdisp_PutDisp_DD();
    Sleep(3000);
    Bdisp_ClearLineVRAM(0,0,127,0);
    Bdisp_ClearLineVRAM(127,0,127,63);
    Bdisp_ClearLineVRAM(127,63,0,63);
    Bdisp_ClearLineVRAM(0,63,0,0);
    Bdisp_ClearLineVRAM(0,0,127,63);
    Bdisp_ClearLineVRAM(127,0,0,63);
    Bdisp_AllClr_DD();
    Bdisp_PutDisp_DD();
    Sleep(3000);
}


#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


Bdisp_AreaClr_DD/VRAM/DDVRAM()
This clears an area from the DD VRAM or both. This introduces a new type of argument. A DISPBOX which is basically a predefined set of variables. First you have to declare a new DISPBOX and give it a name. Then you have to give the variables values.

Code: Select all
DISPBOX cleararea;
cleararea.left = 10;
cleararea.top = 10;
cleararea.right = 20;
cleararea.bottom = 20;


This is a basic DISPBOX.
Now we will create a black screen and clear a center box.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
int y;
DISPBOX cleararea;
cleararea.left = 54;
cleararea.top = 22;
cleararea.right = 74;
cleararea.bottom = 42;
    Bdisp_AllClr_DDVRAM();
    for(y=0;y<=63;y++){
        Bdisp_DrawLineVRAM(0,y,127,y);
    }
    Bdisp_PutDisp_DD();
    Sleep(3000);
    Bdisp_AreaClr_DDVRAM(&cleararea);
    Sleep(3000);
}


#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


Bdisp_AreaReverseVRAM()
This function reverses the area of the VRAM within the coordinates. You have four arguments. x1, y1, x2, and y2. These four coordinates declare a rectangle and every pixel within this rectange is reversed in colour. We will do the same example as the AreaClr except this way is far more simpler.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    Bdisp_AreaReverseVRAM(0,0,127,63);
    Bdisp_PutDisp_DD();
    Sleep(3000);
    Bdisp_AllClr_DD();
    Bdisp_AreaReverseVRAM(54,22,74,42);
    Bdisp_PutDisp_DD();
    Sleep(3000);
}


#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


Bdisp_GetDisp_DD/VRAM()
This gets the data or the bitmap from either DD or VRAM and stores it in an array. The array has to be of char type and be 1024 in size. In this example we will draw the same example as before and then copy it to an array.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
char bitmap[1024];
    Bdisp_AllClr_DDVRAM();
    Bdisp_AreaReverseVRAM(0,0,127,63);
    Bdisp_PutDisp_DD();
    Sleep(3000);
    Bdisp_AllClr_DD();
    Bdisp_AreaReverseVRAM(54,22,74,42);
    Bdisp_PutDisp_DD();
    Bdisp_GetDisp_DD(&bitmap);
    Sleep(3000);
}


#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


Bdisp_PutDispArea_DD()
Now this one I never use if I can help it. Sometimes the entire box doesn't get transferred.
This function also uses a DISPBOX. It transfers the rectangle declared in the DISPBOX to the DD. Here is an example. It makes the screen black and then clears the VRAM. Then it transfers the middle section to the DD.
This code is a classic example of not transferring all the data.

Code: Select all
#include "fxlib.h"
#include "dispbios.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
DISPBOX cleararea;
cleararea.left = 1;
cleararea.top = 1;
cleararea.right = 126;
cleararea.bottom =62;
    Bdisp_AllClr_DDVRAM();
    Bdisp_AreaReverseVRAM(0,0,127,63);
    Bdisp_PutDisp_DD();
    Bdisp_AreaReverseVRAM(0,0,127,63);
    Sleep(3000);
    Bdisp_PutDispArea_DD(&cleararea);
    Sleep(3000);
}


#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


Bdisp_SetPoint_DD/VRAM/DDVRAM()
This just turns a pixel to the colour stated. It takes 3 arguments. x, y and the colour. x and y are just the position on the screen. The color is if the pixel is black or white. If it is set to 1 then it is turned black. If it is set to 0 then it is set to white. Here is an example.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    Bdisp_SetPoint_DDVRAM(15,36,1);
    Bdisp_SetPoint_DDVRAM(82,48,1);
    Bdisp_SetPoint_DDVRAM(43,25,1);
    Bdisp_SetPoint_DDVRAM(103,51,1);
    Sleep(3000);
    Bdisp_AllClr_DDVRAM();
    Bdisp_AreaReverseVRAM(0,0,127,63);
    Bdisp_SetPoint_VRAM(15,36,0);
    Bdisp_SetPoint_VRAM(82,48,0);
    Bdisp_SetPoint_VRAM(43,25,0);
    Bdisp_SetPoint_VRAM(103,51,0);
    Bdisp_PutDisp_DD();
    Sleep(3000);
}


#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


Bdisp_GetPoint_VRAM()
This returns a value to and int. It takes 2 arguments. x and y. These are the position of the pixel to read. It basically reads the pixel to see what colour it is. Then returns a value accordingly. If it returns 1 then the pixel is black. If it returns 0 then the pixel is white.
Here is an example. It Creates a while loop. This will make the center pixel flash on and off. If gets the pixel colour then sets it to the opposite.

Code: Select all
#include "fxlib.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
int pixel;
    Bdisp_AllClr_DDVRAM();
    while(IsKeyDown(KEY_CTRL_EXIT)==0){
        pixel = Bdisp_GetPoint_VRAM(64,32);
        if(pixel == 1){
            Bdisp_SetPoint_DDVRAM(64,32,0);
        }
        if(pixel == 0){
            Bdisp_SetPoint_DDVRAM(64,32,1);
        }
        Sleep(500);
    }
}


#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


Bdisp_WriteGraph_DD/VRAM/DDVRAM()
This function copies a bitmap array onto the DD, VRAM or both. In this one we have 2 different types of Predefined variable structures. GRAPHDATA and DISPGRAPH. The GRAPHDATA is responsible for the information about the picture. The DISPBOX however is responsible for where and how the picture is displayed.
Here is an example. It draws a cross to the VRAM and copies it to a buffer. Then we use a void and throw the bitmap to it. It then draws it to the screen.

Code: Select all
#include "fxlib.h"
#include "dispbios.h"

void draw(unsigned char bitmap[]){
GRAPHDATA picturedata;
DISPGRAPH pictureinfo;

picturedata.width = 128;
picturedata.height = 64;
picturedata.pBitmap = bitmap;

pictureinfo.x = 0;
pictureinfo.y = 0;
pictureinfo.GraphData = picturedata;
pictureinfo.WriteModify = IMB_WRITEMODIFY_NORMAL;
pictureinfo.WriteKind = IMB_WRITEKIND_OVER;
    Bdisp_WriteGraph_DDVRAM(&pictureinfo);
    Sleep(3000);
}

int AddIn_main(int isAppli, unsigned short OptionNum)
{
char bitmap[1024];
    Bdisp_AllClr_DDVRAM();
    Bdisp_DrawLineVRAM(0,0,127,0);
    Bdisp_DrawLineVRAM(127,0,127,63);
    Bdisp_DrawLineVRAM(127,63,0,63);
    Bdisp_DrawLineVRAM(0,63,0,0);
    Bdisp_DrawLineVRAM(0,0,127,63);
    Bdisp_DrawLineVRAM(127,0,0,63);
    Bdisp_GetDisp_VRAM(bitmap);
    Bdisp_AllClr_VRAM();
    Sleep(3000);
    draw(bitmap);
}


#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


Bdisp_ReadArea_DD/VRAM()
This function reads the data only from a certain area of the screen. It uses the DISPBOX function to do it.
Here is an example of the same thing as above except it only reads a small bit. the middle square, and then transfers it.

Code: Select all
#include "fxlib.h"
#include "dispbios.h"

void draw(unsigned char bitmap[]){
GRAPHDATA picturedata;
DISPGRAPH pictureinfo;

picturedata.width = 20;
picturedata.height = 20;
picturedata.pBitmap = bitmap;

pictureinfo.x = 54;
pictureinfo.y = 22;
pictureinfo.GraphData = picturedata;
pictureinfo.WriteModify = IMB_WRITEMODIFY_NORMAL;
pictureinfo.WriteKind = IMB_WRITEKIND_OVER;
    Bdisp_WriteGraph_DDVRAM(&pictureinfo);
    Sleep(3000);
}

int AddIn_main(int isAppli, unsigned short OptionNum)
{
char bitmap[1024];
DISPBOX readarea;
readarea.left = 54;
readarea.top = 22;
readarea.right = 74;
readarea.bottom = 42;
    Bdisp_AllClr_DDVRAM();
    Bdisp_DrawLineVRAM(0,0,127,0);
    Bdisp_DrawLineVRAM(127,0,127,63);
    Bdisp_DrawLineVRAM(127,63,0,63);
    Bdisp_DrawLineVRAM(0,63,0,0);
    Bdisp_DrawLineVRAM(0,0,127,63);
    Bdisp_DrawLineVRAM(127,0,0,63);
    Bdisp_ReadArea_VRAM(&readarea, &bitmap);
    Bdisp_AllClr_VRAM();
    Sleep(3000);
    draw(bitmap);
}


#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


Basic I/O

Introduction

This is a small tutorial about simple input/output. It has two tutorial programs. First is a small program the takes 2 numbers and multiplies them together and displays the result. The second one is about how to create a simple menu, and how to determine the selection.

Index

  1. Multiplyer - Intro
  2. Multiplyer - Revolution-FX
  3. Multipler - Steps
  4. Menu - Intro
  5. Menu - Steps


Multiplyer - Intro

Multipler is the name of the add-in we will make in this section. First the user will be asked to input a number. This number will then be stored inside a variable. The user will then be asked to enter in another number, which is stored inside another variable. These to numbers are multiplied together, and the result is displayed.

This is a very simple example of input/output, but it gets the job done.

Multiplyer - Empty Program

This is the empty add-in that you will get when you create a new project. This has all the comments and junk that you don't need from it.

Code: Select all
#include "fxlib.h"



int AddIn_main(int isAppli, unsigned short OptionNum)
{

}


#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


Multiplyer - Revlution-fx

You will need to have downloaded Revolution-FX to use the input. Please don't continue until you have downloaded it and installed it to your SDK.

Once installed you will need to add a simple include to include the revolution-fx library.

Code: Select all
#include "revolution.h"


Multiplyer - Steps

The first steps in creating this add-in will be to clear the screen of all display. After this, ask the user for the first number.

Code: Select all
#include "fxlib.h"
#include "revolution.h"



int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    PrintMini(0, 0, (unsigned char*)"First Number?", MINI_OVER);
    Bdisp_PutDisp_DD();
}


#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


Now you will need to declare the first variable. We will call this one num_a. This variable will contain the number that is taken from the input.

Code: Select all
unsigned int num_a;


Also we are going to need to declare a string. The string_input function takes input from the user and sticks it into a string. As you should know, a string is simply a variable of char type, but an array. In this case we will have an array of 20.

Code: Select all
unsigned char string[20];


Now we are going to need to call the string input function.

Code: Select all
#include "fxlib.h"
#include "revolution.h"



int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int num_a;
unsigned char string[20];
    Bdisp_AllClr_DDVRAM();
    PrintMini(0, 0, (unsigned char*)"First Number?", MINI_OVER);
    Bdisp_PutDisp_DD();
    string_input(0, 7, &string);
}


#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


Now you are going to need to take the number from the string and stick it into the variable we declared ealier.

Code: Select all
num_a = atoi(&string);


Now declare another variable called num_b. We are also going to have to clear the string of everything on it. We do this with memset.

Code: Select all
memset(string, 0, 20);


Now ask for the second number. Use string input again, and use atoi to store it in num_b. For future ares of this add-in we are going to have to include the library stdio.h.

Code: Select all
#include "fxlib.h"
#include "revolution.h"
#include "stdio.h"



int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int num_a, num_b;
unsigned char string[20];
    Bdisp_AllClr_DDVRAM();
    PrintMini(0, 0, (unsigned char*)"First Number?", MINI_OVER);
    Bdisp_PutDisp_DD();
    string_input(0, 7, &string);
    num_a = atoi(&string);
    memset(string, 0, 20);
    PrintMini(0, 14, (unsigned char*)"Second Number?", MINI_OVER);
    Bdisp_PutDisp_DD();
    string_input(0, 21, &string);
    num_b = atoi(&string);
}


#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


Now we are going to have to clear that string again. Now we are going to use sprintf to times the 2 variables together and stick the result in the string for displaying back.

Code: Select all
memset(string, 0, 20);
sprintf(&string, "Answer: %d", (num_a * num_b));


This writes the string "Answer: " to the string. And the "%d" means a interger. In the next argument you can tell the function what this interger is. In this case it is num_a multiplied by num_b.

Now we are going to use PrintMini to print this string to the screen. Then tell it to sleep/pause for 2 seconds.

Code: Select all
#include "fxlib.h"
#include "revolution.h"
#include "stdio.h"



int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int num_a, num_b;
unsigned char string[20];
    Bdisp_AllClr_DDVRAM();
    PrintMini(0, 0, (unsigned char*)"First Number?", MINI_OVER);
    Bdisp_PutDisp_DD();
    string_input(0, 7, &string);
    num_a = atoi(&string);
    memset(string, 0, 20);
    PrintMini(0, 14, (unsigned char*)"Second Number?", MINI_OVER);
    Bdisp_PutDisp_DD();
    string_input(0, 21, &string);
    num_b = atoi(&string);
    memset(string, 0, 20);
    sprintf(&string, "Answer: %d", (num_a * num_b));
    PrintMini(0, 28, (unsigned char*)string, MINI_OVER);
    Bdisp_PutDisp_DD();
    Sleep(2000);
}


#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


Menu - Intro

This is a simple add-in that makes a menu, and displays something depending on what the user chose.

Menu - Steps

First there is the blank program qith the junk removed and the display cleared. Of course this is the same as the one above so I won;t be displaying that here. Just create a new project and call it menu.

What you have to do now is display 6 choices. Labeled Choice 1, Choice 2, ... Choice 6.

Code: Select all
#include "fxlib.h"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    PrintMini(0, 0, (unsigned char*)"Choice 1", MINI_OVER);
    PrintMini(0, 7, (unsigned char*)"Choice 2", MINI_OVER);
    PrintMini(0, 14, (unsigned char*)"Choice 3", MINI_OVER);
    PrintMini(0, 21, (unsigned char*)"Choice 4", MINI_OVER);
    PrintMini(0, 28, (unsigned char*)"Choice 5", MINI_OVER);
    PrintMini(0, 35, (unsigned char*)"Choice 6", MINI_OVER);
    Bdisp_PutDisp_DD();
}

#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


Now we must do 2 things. Create an array that contains the arrow. Also save the display to display 1.

Code: Select all
#include "fxlib.h"

unsigned char arrow[3] = {0xE6, 0x90, 0};

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Bdisp_AllClr_DDVRAM();
    PrintMini(0, 0, (unsigned char*)"Choice 1", MINI_OVER);
    PrintMini(0, 7, (unsigned char*)"Choice 2", MINI_OVER);
    PrintMini(0, 14, (unsigned char*)"Choice 3", MINI_OVER);
    PrintMini(0, 21, (unsigned char*)"Choice 4", MINI_OVER);
    PrintMini(0, 28, (unsigned char*)"Choice 5", MINI_OVER);
    PrintMini(0, 35, (unsigned char*)"Choice 6", MINI_OVER);
    SaveDisp(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


Now we are going to create a loop. It is a while loop. It will loop over until the condition returns false. In this case the condition is the result of IsKeyDown. We will test if the key [EXIT] is being pressed down. If this is true, it will return true. If the key isn't being pressed down, it will return false. Now since the loop only runs if the condition returns true, we are going to have to stick a "!" in front of the condition. This basically switches them. If it's true, it is now false. I have gone through thinking of it in this way.

Code: Select all
while(!IsKeyDown(KEY_CTRL_EXIT))
{

}


Now we are going to create a new variable called yarrow. This will determine the position of the arrow. We are going to set the first value of it to 0.

Also restore the Display 1 to the screen. Now print the arrow to the screen at the position of yarrow.

Code: Select all
int yarrow = 0;


Code: Select all
while(!IsKeyDown(KEY_CTRL_EXIT))
{
    RestoreDisp(1);
    PrintMini(40, yarrow, (unsigned char*)arrow, MINI_OVER);
    Bdisp_PutDisp_DD();
}


Now it's time for some interactivity. We will say if the up arrow is down, yarrow will decrease by 7. If down is pressed yarrow will increase by 7. There is going to need a 30 millisecond pause in between.

Code: Select all
while(!IsKeyDown(KEY_CTRL_EXIT))
{
    RestoreDisp(1);
    PrintMini(40, yarrow, (unsigned char*)arrow, MINI_OVER);
    Bdisp_PutDisp_DD();
    if(IsKeyDown(KEY_CTRL_UP))
    {
        yarrow -= 7;
        Sleep(30);
    }
    if(IsKeyDown(KEY_CTRL_DOWN))
    {
        yarrow += 7;
        Sleep(30);
    }
}


Now if you compile this, it's obvious we need to add some bounduries. The arrow can go WAY down.out of the screen down. Same with up. To add some bouduries, it is another couple of if statements.

If yarrow becomes less than 0(its gone way up.) set yarrow to 0. If it's become more than 35(It's gone way down) set it to 35.

Code: Select all
while(!IsKeyDown(KEY_CTRL_EXIT))
{
    RestoreDisp(1);
    PrintMini(40, yarrow, (unsigned char*)arrow, MINI_OVER);
    Bdisp_PutDisp_DD();
    if(IsKeyDown(KEY_CTRL_UP))
    {
        yarrow -= 7;
        Sleep(30);
    }
    if(IsKeyDown(KEY_CTRL_DOWN))
    {
        yarrow += 7;
        Sleep(30);
    }
    if(yarrow < 0)
    {
        yarrow = 0;
    }
    if(yarrow > 35)
    {
        yarrow = 35;
    }
}


Now another if statement. This time testing if the [EXE] key is being pressed. It will then go to a switch statement, with the condition being the value of yarrow. Then it will call a function that will display a popup window with the choice number it. This will remain for 3 seconds until it goes back to the menu.

Function popup

Code: Select all
void popup(unsigned int num)
{
unsigned char string[20];
    PopUpWin(1);
    memset(string, 0, 20);
    sprintf(string, "Choice %d", num);
    PrintMini(12, 25, (unsigned char*)string, MINI_OVER);
    Bdisp_PutDisp_DD();
    Sleep(3000);
}


Switch

Code: Select all
switch(yarrow)
{
case 0:
    popup(1);
    break;
case 7:
    popup(2);
    break;
case 14:
    popup(3);
    break;
case 21:
    popup(4);
    break;
case 28:
    popup(5);
    break;
case 35:
    popup(6);
    break;
}


Full Add In

Code: Select all
#include "fxlib.h"
#include "stdio.h"

unsigned char arrow[3] = {0xE6, 0x90, 0};

void popup(unsigned int num)
{
unsigned char string[20];
    PopUpWin(1);
    memset(string, 0, 20);
    sprintf(string, "Choice %d", num);
    PrintMini(12, 25, (unsigned char*)string, MINI_OVER);
    Bdisp_PutDisp_DD();
    Sleep(3000);
}

int AddIn_main(int isAppli, unsigned short OptionNum)
{
int yarrow = 0;
    Bdisp_AllClr_DDVRAM();
    PrintMini(0, 0, (unsigned char*)"Choice 1", MINI_OVER);
    PrintMini(0, 7, (unsigned char*)"Choice 2", MINI_OVER);
    PrintMini(0, 14, (unsigned char*)"Choice 3", MINI_OVER);
    PrintMini(0, 21, (unsigned char*)"Choice 4", MINI_OVER);
    PrintMini(0, 28, (unsigned char*)"Choice 5", MINI_OVER);
    PrintMini(0, 35, (unsigned char*)"Choice 6", MINI_OVER);
    SaveDisp(1);
    while(!IsKeyDown(KEY_CTRL_EXIT))
    {
        RestoreDisp(1);
        PrintMini(40, yarrow, (unsigned char*)arrow, MINI_OVER);
        Bdisp_PutDisp_DD();
        if(IsKeyDown(KEY_CTRL_UP))
        {
            yarrow -= 7;
            Sleep(30);
        }
        if(IsKeyDown(KEY_CTRL_DOWN))
        {
            yarrow += 7;
            Sleep(30);
        }
        if(IsKeyDown(KEY_CTRL_EXE))
        {
            switch(yarrow)
            {
            case 0:
                popup(1);
                break;
            case 7:
                popup(2);
                break;
            case 14:
                popup(3);
                break;
            case 21:
                popup(4);
                break;
            case 28:
                popup(5);
                break;
            case 35:
                popup(6);
                break;
            }
        }
        if(yarrow < 0)
        {
            yarrow = 0;
        }
        if(yarrow > 35)
        {
            yarrow = 35;
        }
    }
}

#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


There we go. I hope you found this tutorial useful in some way. Thank you taking the time to read it.

Source: Assembla CPDT
SiO2 + CaCO3 ----------> CaSiO3 + CO2

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

Postby aapman55 » Mon Jul 09, 2012 7:58 pm

great tut, just one question, why do you use IskeyDown? I thought i read something about it and it said that itwasnt compatible with the new calcs or something like that.

Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400

Postby helder7 » Mon Jul 09, 2012 9:28 pm

this is a old tutorial from assembla cpdt (dead).

you can read more about the new power graphic 2 and IskeyDown, here.
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Junior Member
Posts: 5
Joined: Sun Aug 13, 2017 5:59 am
Calculators: Casio fx-9860GII SD Power Graphic 2

Re: [Fx9860] Basic Bdisp and I-O (C)

Postby 3.141592 » Sun Aug 13, 2017 7:40 am

hi

Thanks so much . this helpful post.

but
is C Standard Libraries work on current sdk?
many c'API dose not work.
math.h stdin.h dose not work.

Junior Member
Posts: 5
Joined: Sun Aug 13, 2017 5:59 am
Calculators: Casio fx-9860GII SD Power Graphic 2

Re: [Fx9860] Basic Bdisp and I-O (C)

Postby 3.141592 » Mon Sep 04, 2017 10:52 am

//*hi
//*this my method for input double numbers: *//

#include "fxlib.h"
#include <stdlib.h>
#include <stdio.h>
#include "revolution.h"

double InputD (int ,int );

double InputD (int x,int y)
{
char *string[128], *stopstring;
string_input( x , y , string);
return strtod(string, &stopstring);
//*IBM Knowledge Center is one the *//
//* best for c reference*//
}



int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
char str[128];
double num_a ,num_b;
Bdisp_AllClr_DDVRAM();

num_a=InputD(1,1);
num_b=InputD(1,8);
sprintf(str,"ans: %10.3f", (num_a*num_b));
locate(1,4);
Print((unsigned char*)str);
locate(1,6);
Print((unsigned char*)" Arash ");

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

return 1;
}

Return to Tutorials & Code Snippets

Who is online

Users browsing this forum: No registered users and 14 guests