Jump to content



Photo
- - - - -

Basic Cursor Tutorial


  • Please log in to reply
4 replies to this topic

#1 Fez

Fez

    Casio Freak

  • Members
  • PipPipPipPip
  • 162 posts
  • Gender:Male
  • Location:Australia

  • Calculators:
    Casio fx-9860G AU

Posted 02 November 2007 - 01:10 AM

I know that all of you here probably know how to make a basic cursor, but everyone is going on about making tutorials, and I want to contribute. So this is probably for those who are now starting Casio C. In this tutorial I am asuming that you have read the documentation.

Tutorial Name: Basic Cursor.
Difficulty: Very very very very Easy

[list]
[*]First you will need an empty prgram with the screen cleared. To clear the screen you would use the function Bdisp_AllClr_DDVRAM()
#include "fxlib.h"


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

#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
[*]For the GetKey function you will need to declare a variable. This variable will be called getkey and is an int. Another int will be declared as well, called yarrow. Tis variable will be explained later.
#include "fxlib.h"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
int getkey;
int yarrow;
	Bdisp_AllClr_DDVRAM();
}

#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
[*]Draw the screen and options by using Bdisp_DrawLineVRAM() and PrintMini(); We will draw a box around the screen and then Draw 6 options. We will then save the display with SaveDisp(); Then we will Put the VRAM to the screen, with Bdisp_PutDisp_DD(); Then use GetKey() to pause the program until a key is pressed.
#include "fxlib.h"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
int getkey;
int yarrow;
	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);
	PrintMini(2,2,(unsigned char*)"Option 1",MINI_OVER);
	PrintMini(2,9,(unsigned char*)"Option 2",MINI_OVER);
	PrintMini(2,16,(unsigned char*)"Option 3",MINI_OVER);
	PrintMini(2,23,(unsigned char*)"Option 4",MINI_OVER);
	PrintMini(2,30,(unsigned char*)"Option 5",MINI_OVER);
	PrintMini(2,37,(unsigned char*)"Option 6",MINI_OVER);
	SaveDisp(1);
	Bdisp_PutDisp_DD();
	GetKey(&getkey);
}

#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
[*]We will now draw and arrow to the screen. The arrow will be an array called arrow. This is where that yarrow variable comes in. We will set the yarow variable to the value of 2. THen we will make the array. Then we stick the GetKey() into a while loop and RestoreDisp() above the GetKey(). Then we will use PrintMini to draw the arrow to the screen.
#include "fxlib.h"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
int getkey;
int yarrow=2;
char arrow[3]={0xE6,0x90,0};
	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);
	PrintMini(2,2,(unsigned char*)"Option 1",MINI_OVER);
	PrintMini(2,9,(unsigned char*)"Option 2",MINI_OVER);
	PrintMini(2,16,(unsigned char*)"Option 3",MINI_OVER);
	PrintMini(2,23,(unsigned char*)"Option 4",MINI_OVER);
	PrintMini(2,30,(unsigned char*)"Option 5",MINI_OVER);
	PrintMini(2,37,(unsigned char*)"Option 6",MINI_OVER);
	SaveDisp(1);
	Bdisp_PutDisp_DD();
	while(1){
		RestoreDisp(1);
		PrintMini(50,yarrow,(unsigned char*)arrow,MINI_OVER);
		GetKey(&getkey);
	}
}

#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 it's time for some interaction. Getkey waits for a key to be pressed then returns an number into the int inside the brackets. These numbers have been predefined inside the fxlib header. we will use an if statement. If down arrow was pressed it adds 7 onto yarrow, changing the position of the arrow. Same with up but this will subtract 7 instead.
#include "fxlib.h"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
int getkey;
int yarrow=2;
char arrow[3]={0xE6,0x90,0};
	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);
	PrintMini(2,2,(unsigned char*)"Option 1",MINI_OVER);
	PrintMini(2,9,(unsigned char*)"Option 2",MINI_OVER);
	PrintMini(2,16,(unsigned char*)"Option 3",MINI_OVER);
	PrintMini(2,23,(unsigned char*)"Option 4",MINI_OVER);
	PrintMini(2,30,(unsigned char*)"Option 5",MINI_OVER);
	PrintMini(2,37,(unsigned char*)"Option 6",MINI_OVER);
	SaveDisp(1);
	Bdisp_PutDisp_DD();
	while(1){
		RestoreDisp(1);
		PrintMini(50,yarrow,(unsigned char*)arrow,MINI_OVER);
		GetKey(&getkey);
		if(getkey==KEY_CTRL_DOWN){
			yarrow=yarrow+7;
		}
		if(getkey==KEY_CTRL_UP){
			yarrow=yarrow-7;
		}
	}
}

#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
[*]As you can see when you build it that the arrow can go off the screen. That is why you will now need to add some restrictions. It will be if yarrow becomes greater than 37(The position of the arrow on option 6), then change yarrow to 2. Same with the opposite.
[code=auto:0]#include "fxlib.h"


int AddIn_main(int isAppli, unsigned short OptionNum)
{
int getkey;
int yarrow=2;
char arrow3={0xE6,0x90,0};
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);
PrintMini(2,2,(unsigned char*)"Option 1",MINI_OVER);
PrintMini(2,9,(unsigned char*)"Option 2",MINI_OVER);
PrintMini(2,16,(unsigned char*)"Option 3",MINI_OVER);
PrintMini(2,23,(unsigned char*)"Option 4",MINI_OVER);
PrintMini(2,30,(unsigned char*)"Option 5",MINI_OVER);
PrintMini(2,37,(unsigned char*)"Option 6",MINI_OVER);
SaveDisp(1);
Bdisp_PutDisp_DD();
while(1){
RestoreDisp(1);
PrintMini(50,yarrow,(unsigned char*)arrow,MINI_OVER);
GetKey(&getkey);
if(getkey==KEY_CTRL_DOWN){
yarrow=yarrow+7;
}
if(getkey==KEY_CTRL_UP){
yarrow=yarrow-7;
}
if(yarrow>37){
yarrow=2;
}
if(yarrow37){
yarrow=2;
}
if(yarrow

#2 kucalc

kucalc

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1422 posts
  • Gender:Male
  • Location:USA
  • Interests:Programming: C/C++, Fortran, LISP, COBOL 85 Standard, PHP, x86 and SH3 Assembly

    Computer graphics

  • Calculators:
    fx-9860G / fx-7400G Plus / Algebra FX 2.0+ / fx-9770G / CFX-9850G / CFX-9850GB+ / TI-89 / TI-nSpire

Posted 04 November 2007 - 03:48 AM

Hey, this is a pretty nice tutorial. Should be helpful to C programmers out there.

#3 E_net4

E_net4

    Casio Freak

  • Members
  • PipPipPipPip
  • 189 posts
  • Gender:Male
  • Location:Output("Error: Coord type not specified");
  • Interests:Programming 'n' stuff...

  • Calculators:
    CASIO fx 9860G SD

Posted 10 November 2007 - 02:47 PM

That is sort of ambiguous on how it works. What does it actually do?

#4 kucalc

kucalc

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1422 posts
  • Gender:Male
  • Location:USA
  • Interests:Programming: C/C++, Fortran, LISP, COBOL 85 Standard, PHP, x86 and SH3 Assembly

    Computer graphics

  • Calculators:
    fx-9860G / fx-7400G Plus / Algebra FX 2.0+ / fx-9770G / CFX-9850G / CFX-9850GB+ / TI-89 / TI-nSpire

Posted 11 November 2007 - 05:26 PM

I think it does what it says. I believe it has one of those -> cursors.

#5 Fez

Fez

    Casio Freak

  • Members
  • PipPipPipPip
  • 162 posts
  • Gender:Male
  • Location:Australia

  • Calculators:
    Casio fx-9860G AU

Posted 11 November 2007 - 11:48 PM

Yup. well a


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users