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 arrow ={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