Jump to content



Photo
- - - - -

System ERROR while trying to get key input

cpp fx-9860g sdk keys

  • Please log in to reply
11 replies to this topic

#1 Raresh Nistor

Raresh Nistor

    Newbie

  • Members
  • Pip
  • 5 posts
  • Gender:Male
  • Location:Middle Earth
  • Interests:* Software Development
    * Design and Photography
    * Linguistics

  • Calculators:
    * CASIO fx-9750GII MkII

Posted 02 September 2018 - 02:31 AM

Hello.

I'm having issues with getting keyboard input to work.

When I run my code, I get following errors:

  • The IDE first compains about "CPU address error exception by code read access at 0000007F"
  • After I click on "run," it then pops up this wonderful error:
    0HQhSGj.png
  • And lastly, I get error on the emulator screen.
    4jL9Efh.png

I've already stepped through the program and this is the affected area. When it gets to GetKey(&key);.

i = 0;
while (1)
{
    DrawPaddles();
    GetKey(&key);
    locate(1, 1);
    sprintf(str, "%d", i);
    Print((unsigned char*)str);
    if (IsKeyDown(KEY_CTRL_UP))
    {
        if (player1_offset > -20)
            player1_offset--;
    }
    else if (IsKeyDown(KEY_CTRL_DOWN))
    {
        if (player1_offset < 20)
            player1_offset++;
    }
}

I usually do higher-end stuff and I've got a lot to learn... so any help is greatly appreciated.



#2 Viliami

Viliami

    Casio Addict

  • Moderator
  • PipPipPip
  • 99 posts
  • Gender:Male
  • Location:New Zealand
  • Interests:C++ - OpenGL,SDL
    Python - Pygame
    Java - SFML
    C - Casio SDK

  • Calculators:
    FX-9750 GII upgraded to FX-9860 GII

Posted 02 September 2018 - 02:41 AM

This may be because the key variable is not initialized yet, can you copy and paste the code where you declare the key variable?



#3 Raresh Nistor

Raresh Nistor

    Newbie

  • Members
  • Pip
  • 5 posts
  • Gender:Male
  • Location:Middle Earth
  • Interests:* Software Development
    * Design and Photography
    * Linguistics

  • Calculators:
    * CASIO fx-9750GII MkII

Posted 02 September 2018 - 02:46 AM

The key variable was already initialised at the start of the function...

/**
 * Add-in entry point
 * 
 * Parameters: app_mode - Is launched from the main menu
 *             strip_no - Strip number from eActivity
 * 
 * Returns:    NOT error
 */
int AddIn_main(int app_mode, unsigned short strip_no)
{
    unsigned int i, j; // Iteration variables
    unsigned char str[3];
    unsigned int key;  // Keyboard input

If that was the case, the compiler would've stopped me immediately.

 

I suspect something else might be triggering this.


Edited by Raresh Nistor, 02 September 2018 - 02:48 AM.


#4 Viliami

Viliami

    Casio Addict

  • Moderator
  • PipPipPip
  • 99 posts
  • Gender:Male
  • Location:New Zealand
  • Interests:C++ - OpenGL,SDL
    Python - Pygame
    Java - SFML
    C - Casio SDK

  • Calculators:
    FX-9750 GII upgraded to FX-9860 GII

Posted 02 September 2018 - 03:19 AM

I have no idea, code looks good from the snippets that you showed me.

The str variable might not be initialized properly, try commenting out these three lines:

locate(1,1);
sprintf(str, "%d", i);
Print((unsigned char*)str);

and see if the error still comes out.



#5 Todd

Todd

    Newbie

  • Members
  • Pip
  • 14 posts
  • Gender:Male
  • Location:Payson, AZ
  • Interests:Astronomy, electronics, computers, and of course, math.

  • Calculators:
    fx-CG500 - My "daily driver" (actually, CP-400)
    fg-CG50
    fx-991EX Classwiz
    fx-9750gii
    fx-9750giii
    TI-89 Titanium
    TI-83 Silver Edition
    TI-nSpire CX CAS

Posted 03 September 2018 - 06:03 PM

You have a variable labeled "key", and I am wondering why you would pass the address of (&) the variable key instead of just the variable key. I do not know the context that you are programming in, but typically absolute memory addresses are not passed around as function parameters. That could be what your IDE is complaining about, and what is causing the system error message about non-existent memory.

 


I've already stepped through the program and this is the affected area. When it gets to GetKey(&key);.

i = 0;
while (1)
{
    DrawPaddles();
    GetKey(&key);
    locate(1, 1);
    sprintf(str, "%d", i);
    Print((unsigned char*)str);
    if (IsKeyDown(KEY_CTRL_UP))
    {
        if (player1_offset > -20)
            player1_offset--;
    }
    else if (IsKeyDown(KEY_CTRL_DOWN))
    {
        if (player1_offset < 20)
            player1_offset++;
    }
}

I usually do higher-end stuff and I've got a lot to learn... so any help is greatly appreciated.



#6 GodOfCows

GodOfCows

    Casio Addict

  • Members
  • PipPipPip
  • 79 posts
  • Gender:Male

  • Calculators:
    fx-9860gii, fx-9750gii, TI-92, TI-89, TI-83 Plus

Posted 03 September 2018 - 06:53 PM

If you are using the USB Power Graphic 2 model, you are not suppost to use the IsKeyDown function anymore. Use only GetKey and Bkey_GetKeyWait.

 

To Todd: The key variable is passed as a pointer, hint passing its address.

 

 

EDIT: Have you included the stdio library?

 

EDIT 2:

 

http://prizm.cemetec.../Error_handling

 

This is the link to all errors. I assume the error you are experiencing is with the str variable.

 

What I would try first:
 

-Increase the amount str has.

-Check to see if stdio is included

-Remove the sprintf and see if that is the error

-If so, figure out what to do

-Remove the IsKeyDown

 

If none of that works, could you post your entire source code? It'd make it easier for us to debug it.


Edited by GodOfCows, 03 September 2018 - 10:36 PM.


#7 Todd

Todd

    Newbie

  • Members
  • Pip
  • 14 posts
  • Gender:Male
  • Location:Payson, AZ
  • Interests:Astronomy, electronics, computers, and of course, math.

  • Calculators:
    fx-CG500 - My "daily driver" (actually, CP-400)
    fg-CG50
    fx-991EX Classwiz
    fx-9750gii
    fx-9750giii
    TI-89 Titanium
    TI-83 Silver Edition
    TI-nSpire CX CAS

Posted 04 September 2018 - 07:59 AM

The address of a variable is not exactly the same thing as a pointer. A pointer is a variable that contains the address of some variable.

 

int x = 1, y = 2;

int *ip; // ip is a pointer to type int

 

ip = &x; // ip now points to x

y = *ip // y now contains 1

 

The above example is straight out of K&R. However, I know what you mean, because if you look at line 3 of the above code, ip and &x are kind of the same thing. So I am probably splitting hairs here, and that's rarely productive.

 

Getting back to the code posted - I guess I've never seen getkey() used quite that way before. Usually it is more like:

 

unsigned int key;

.

key = getkey();  //getkey() gets its input from STDIN and puts the character code in variable key

.

//end

 

It seems in the posted code that getkey( &key ) is telling getkey to read the key value from some i/o port named key. Is that the intent? Or, is the programmer trying to tell getkey() where to put the key value received from getkey()?

 

At any rate, I haven't written a legitimate line of C/C++ code for a decade, and much of the low-level i/o stuff is compiler implementation dependent anyway, and I know nothing about Casio libraries, so I will bow out.

 

Cheers!

 

 

If you are using the USB Power Graphic 2 model, you are not suppost to use the IsKeyDown function anymore. Use only GetKey and Bkey_GetKeyWait.

 

To Todd: The key variable is passed as a pointer, hint passing its address.

 


Edited by Todd, 04 September 2018 - 08:00 AM.


#8 GodOfCows

GodOfCows

    Casio Addict

  • Members
  • PipPipPip
  • 79 posts
  • Gender:Male

  • Calculators:
    fx-9860gii, fx-9750gii, TI-92, TI-89, TI-83 Plus

Posted 04 September 2018 - 12:54 PM

It seems in the posted code that getkey( &key ) is telling getkey to read the key value from some i/o port named key. Is that the intent? Or, is the programmer trying to tell getkey() where to put the key value received from getkey()?

I would say the latter. I assume that when GetKey is called, it waits for a key to be pressed and the returns the keycode to whatever address was passed.

This is the declaration of GetKey from fxlib:

 

int GetKey(unsigned int *keycode); 

 

When called, whatever key is presssed, its keycode is put into the address of what you passed so take the following example:

unsigned short key;

while (1)
{
GetKey(&key); //Whatever key is pressed, its keycode is put where the variable address points to, which is key in this example

if (key == KEY_CHAR_1) //if key is equal to the keycode of number 1 button, so if (key == 0x31) is also correct
break; 
//else repeat, be aware that GetKey pauses the entire function and waits for a key to be pressed
}

unsigned int key;

 

key = getkey();  //getkey() gets its input from STDIN and puts the character code in variable key

 

 

I don't have any books with me at the moment, but I am fairly confident that you are still passing key's address to GetKey.

 

EDIT: 

But looking at the code, it would traditionally run an error, because the parameter are not being met for the GetKey.

 

Looking at documentation, I am unsure of how your example works, because it would only return 1 (if the key pressed was a numeric key) or a 0 (if the key was a control key)

 

I've never used it in the way you describe, and I don't have a windows computer currently with me to test.

 

I suppose you could do it this way, it is not the same as you mentioned. Maybe the compiler is optimizing it in a way that I have not read (and who wants to read a 600 page instruction manual on SuperH compiler?)

#include "fxlib.h"
#include "stdio.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
 unsigned int key, c;
 unsigned char string[20];

Bdisp_AllClr_DDVRAM();



c = GetKey(&key);
sprintf(&string, "%x", key);

switch (c)
{
case 1: 
PrintXY(0,0,"Key is numeric",0);
PrintXY(0,10,string,0);
break;

case 0:
PrintXY(0,0,"Key is numeric",0);
PrintXY(0,10,string,0);
break;

}

while(1)
GetKey(&key);
    

    return 1;
}

Edited by GodOfCows, 05 September 2018 - 12:37 AM.


#9 Viliami

Viliami

    Casio Addict

  • Moderator
  • PipPipPip
  • 99 posts
  • Gender:Male
  • Location:New Zealand
  • Interests:C++ - OpenGL,SDL
    Python - Pygame
    Java - SFML
    C - Casio SDK

  • Calculators:
    FX-9750 GII upgraded to FX-9860 GII

Posted 04 September 2018 - 07:58 PM

From the docs (fx-9860G libraries.pdf available for download on the Casio website) 

 

Capture_docs.png

 

Key part:

int GetKey( unsigned int *keycode // pointer to key code );


#10 GodOfCows

GodOfCows

    Casio Addict

  • Members
  • PipPipPip
  • 79 posts
  • Gender:Male

  • Calculators:
    fx-9860gii, fx-9750gii, TI-92, TI-89, TI-83 Plus

Posted 04 September 2018 - 08:03 PM

Yes, but how can someone do

unsigned apple;

apple = GetKey();

if you have not satisfied the parameters 

 

Key part:

int GetKey( unsigned int *keycode // pointer to key code );

 

Edit: 

 

Was able to test

To todd: You cannot use the example that you gave as the parameters where not met

unsigned int key;
key = getkey();  //getkey() gets its input from STDIN and puts the character code in variable key
//end

Edited by GodOfCows, 05 September 2018 - 12:39 AM.


#11 Todd

Todd

    Newbie

  • Members
  • Pip
  • 14 posts
  • Gender:Male
  • Location:Payson, AZ
  • Interests:Astronomy, electronics, computers, and of course, math.

  • Calculators:
    fx-CG500 - My "daily driver" (actually, CP-400)
    fg-CG50
    fx-991EX Classwiz
    fx-9750gii
    fx-9750giii
    TI-89 Titanium
    TI-83 Silver Edition
    TI-nSpire CX CAS

Posted 05 September 2018 - 02:42 PM

 

Yes, but how can someone do

unsigned apple;

apple = GetKey();

if you have not satisfied the parameters 

 

Edit: 

 

Was able to test

To todd: You cannot use the example that you gave as the parameters where not met

unsigned int key;
key = getkey();  //getkey() gets its input from STDIN and puts the character code in variable key
//end

Sorry, that was just example code showing a typical usage of getkey() in most of the implementations of C I have used, and not meant to be compiled. Having read Viliami's post from the Casio  programmer's doc, the function prototype clearly shows getkey() wants a parameter that is of type pointer, and points to a variable to store the returned key code value. In the original error post, the programmer was passing the address of the variable to hold the key code. While it may be functionally the same, I wonder if Casio's compiler is strict on type checking? If it is, then he might be getting an error using the address directly. Perhaps he could try creating an actual pointer, assign it the address of key, and then pass the pointer.

 

Another observation is that the prototype has a return of type int besides putting the key code into the passed key code location. Since the original code is not using an assignment statement when getkey() is called, I wonder if that is triggering his compile-time error.

 

Cheers!



#12 GodOfCows

GodOfCows

    Casio Addict

  • Members
  • PipPipPip
  • 79 posts
  • Gender:Male

  • Calculators:
    fx-9860gii, fx-9750gii, TI-92, TI-89, TI-83 Plus

Posted 05 September 2018 - 03:22 PM

-In the original error post, the programmer was passing the address of the variable to hold the key code. While it may be functionally the same, I wonder if Casio's compiler is strict on type checking? If it is, then he might be getting an error using the address directly. Perhaps he could try creating an actual pointer, assign it the address of key, and then pass the pointer.

 

Another observation is that the prototype has a return of type int besides putting the key code into the passed key code location. Since the original code is not using an assignment statement when getkey() is called, I wonder if that is triggering his compile-time error.

 

Cheers!

 

To Todd/The original problem of the post: 

GetKey() returns a 1 if the button that was pressed is numeric and 0 if the key is a control key, which don't make a difference when it comes to execution. I'm unsure how picky the compiler is, but what Raresh Nistor has as source code on his original post wouldn't cause an error (*BUT* the IsKeyDown() function is no longer supported, so he needs to remove them as they may be causing the first problem "CPU address error exception by code read access at 0000007F".

 

I believe the problem has to do with the sprintf, since his error has to do address write error. However, this is just a guess. This has something to do (guessing again) with an array of some sort that he is trying to write to (whether that be a string or numeric). But I cannot test, since he has not posted his entire source code and just a snippet and when trying to debuge his code, I got no errors





Also tagged with one or more of these keywords: cpp, fx-9860g, sdk, keys

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users