Keymap cfx9850

Programming the cfx-9850/9950

This is hopefully a much better version of the tutorial to give you a step in the direction of creating interactive games on the newer calculator.

Objective: Teach you to move a letter "O" across the screen with your arrow keys.

The first thing to keep in mind is the fact that there are certain functions that do special tasks for you. Without these you cant get too far in programming games.

Below are a few "IMPORTANT" functions and their descriptions

Getkey: This function returns the value of the key that the person

pushed on the calculator pad. You must note that each key on

your calculator has a unique identification number assigned to it,

and that this function returns this value when the user pushes

the key. For example Getkey will return 31 if the user pushes

[EXE], since 31 is the value of [EXE]. If the user doesn't press

anything getkey returns 0 by default.

Locate: This function displays a text or number at a certain location.

The exact syntax is Locate X,Y, "TEXT" Where X is the x

coordinate and y is the y coordinate. You must keep in mind that

the range of the x coordinate you can place the text at is 1

through 21, and the range of y coordinate you can place the text

at is 1 through 7. If you go beyond this the program will crash.

If : This is a conditional operator, which says "IF (this happens)"

"THEN (do this)"

Since we will be using the arrow keys with the function getkey, I will

tell you the values of the arrow keys here:

up : 28

down : 37

right: 27

left : 38

----------------------------------------------------------------

These are most of the complicated functions you need to know for this tutorial.

Now on to the implementation....

Note that everything between the {} curlies are comments and should not be typed into your calculator.

Program One - "Just let me move"

-----------------------------------------------------------------

ClrText

{ClrText just clears the screen so it is clear heh}

11->X

4->Y

{I am setting the initial value of the x and y value to 11 and}

{4 respectively, since the coordinate 11,4 happens to be the }

{center of the screen }

Lbl 1

{Label 1 so that I can come back here indefinitely with Goto 1}

Locate X,Y,"O"

{place the letter "O" at the coordinate X, Y. X and Y have the}

{values 11 and 4 respectively but will change throughout the }

{program so they can be placed at different locations }

If Getkey=27

Then X+1->X

IfEnd

{the 3 lines above says, IF the Keypressed was 27 or right }

{arrow key then move the x coordinate of the "O" 1 unit to the}

{right }

If Getkey=37

Then Y+1->Y

IfEnd

{the 3 lines above says, IF the Keypressed was 37 or down }

{arrow key then move the y coordinate of the "O" 1 unit down}

If Getkey=38

Then X-1->X

IfEnd

{Try interpreting what this line does }

If Getkey=28

Then Y-1->Y

IfEnd

{Try interpreting what this line does }

Goto 1

{Go back to Label 1 so that it loops indefinitely }

-----------------------------------------------------------------

you will notice 2 things when you run this program.

(1)that the program leaves traces wherever it goes

(2)that it crashes if you go beyond the screen

The next program will attempt to fix one of these two problems.

This next one should delete the old traces so that it looks like

you are actually moving the "O". However keep in mind that it will

still crash when you go beyond the screen, we will fix this in the

third program.

In order to delete the old traces of the "O"s we will need to

somehow keep track of where the last "O" was in the x and y

coordinate plane so that we can delete it before we place the

new "O" at the new coordinate. To do this we will introduce

2 more sets of variables A and B. A will be the memory for

storing the old X coordinate of the "O" and B will store the

old coordinate of Y. A and B coordinate will be used to delete

the old O before it draws the new O.

Program Two - "Get me Cleaned"

-----------------------------------------------------------------

ClrText

{ClrText just clears the screen so it is clear heh}

11->X

4->Y

11->A

4->B

{I added 2 more sets for storing the old coordinates of "O"}

{I just assigned the same value as the present coordinate }

{since I cant think up of anything better at the moment }

Lbl 1

Locate A,B," "

{I am actually placing a single empty space at the old }

{location A,B so that it will delete it's old "O"s }

{Since at the beginning I assigned the same value for the old }

{and present value of the coordinates it will make the O }

{appear like it is blinking }

Locate X,Y,"O"

If Getkey=27

Then X->A

Y->B

X+1->X

IfEnd

{notice that now I am storing the value of X and Y before }

{it is changed so that I can delete the old O by remembering}

{the old coordinate of the "O" }

If Getkey=37

Then X->A

Y->B

Y+1->Y

IfEnd

{same here }

If Getkey=38

Then X->A

Y->B

X-1->X

IfEnd

{and here too }

If Getkey=28

Then X->A

Y->B

Y-1->Y

IfEnd

{and here too }

Goto 1

-----------------------------------------------------------------

The last problem now to fix in the next program is to make sure

that the program doesn't crash if you try going off the screen.

As I said before the screen is only 21 characters wide and 7

characters long. Thus if X-coordinate goes beyond 21 or if it

becomes less than 0 it will crash. Similarly if Y-coordinate

goes beyond 7 or becomes less than 0 it will crash.

The goal now is to keep the X and Y coordinate in range.

Program-3 "I am the smart One"

-----------------------------------------------------------------

ClrText

{ClrText just clears the screen so it is clear heh}

11->X

4->Y

11->A

4->B

Lbl 1

Locate A,B," "

Locate X,Y,"O"

If Getkey=27

Then X->A

Y->B

X+1->X

X=22=>21->X

IfEnd

{I just added one line here which basically says.... }

{If X is equal to 22 then it is out of range so make it 21}

If Getkey=37

Then X->A

Y->B

Y+1->Y

Y=8=>7->Y

IfEnd

{same here is just says if Y is 8 then make it 7 }

If Getkey=38

Then X->A

Y->B

X-1->X

X=0=>1->X

IfEnd

{again if X is 0 then make it 1 }

If Getkey=28

Then X->A

Y->B

Y-1->Y

Y=0=>1->Y

IfEnd

{If Y is 0 then make it 1 }

Goto 1

------------------------------------------------------------------------

This is about all you need to know to make a graphic oriented program that is interactive. It is pretty simple its just all the error you have to compensate for in your code that makes this a little tricky.

© Hidetake Jo 1997(v2.1)