Jump to content



Photo
- - - - -

Turbo C Help


  • Please log in to reply
6 replies to this topic

#1 AlephMobius

AlephMobius

    Casio Freak

  • Members
  • PipPipPipPip
  • 189 posts

  • Calculators:
    AFX 2.0+, TI-89, EL-9300C

Posted 29 March 2003 - 07:56 PM

Do any of you know how to write a Turbo C function that accepts a key code as a parameter and returns true or false according to whether it is held down? For example "Func(65)" would return true if the "A" key was down and false if any other key or no key was held down. kbhit and getch are just too slow.

#2 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1564 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 29 March 2003 - 11:52 PM

You can replace the function kbhit() by the code below, this is MUSCH faster:

peekb(0x41, 0xD))==(peekb(0x41, 0xB)

Then for your function, I'have done this "getkey like" function a long time ago:

#include <dos.h>

unsigned long getkey (void)
{
    return (peek(0, 0x4ac) + (((unsigned long)(peek(0, 0x4ae)) << 16))) * CASIO;
}

To know the return value of a key you have to use TOUCHE. For example for the key 'A' this function should return 0x1E400040
This function return 0 if no key is pressed.

The other way is to use multikeypress but it's more difficult to implement...

#3 C@siomax

C@siomax

    Casio Freak

  • Members
  • PipPipPipPip
  • 229 posts
  • Location:Grenoble, FRANCE

  • Calculators:
    Graph 100 v1.0 and Graph 100+ v1.03

Posted 30 March 2003 - 08:39 AM

2072, you really like complicate things... and what's the length of the value returned ?? long type (32bits if I remember good)


Here is a good key function:

key=peekb(0x40,0xAF);

and key is an integer ... 16bits only!! :P :P
Do a little program to know the value of a key, it isn't very complicated!

and that's all ...

#4 X-thunder28

X-thunder28

    Casio Freak

  • Members
  • PipPipPipPip
  • 192 posts

  • Calculators:
    2 Graph100 (rom 1.02 and rom 1.03 (+) )

Posted 30 March 2003 - 09:48 AM

multiple key powaaaa

#5 AlephMobius

AlephMobius

    Casio Freak

  • Members
  • PipPipPipPip
  • 189 posts

  • Calculators:
    AFX 2.0+, TI-89, EL-9300C

Posted 30 March 2003 - 11:23 PM

How would it change if you did it on the PC?

#6 BiTwhise

BiTwhise

    Casio Overgod

  • [Legends]
  • PipPipPipPipPipPipPip
  • 627 posts
  • Gender:Male
  • Location:Guildford, Surry, UK
  • Interests:Programming, games, consoles, martial arts

  • Calculators:
    FX9700WE, CFX9970G, AFX2.0, Classpad 300

Posted 30 March 2003 - 11:54 PM

First of all, in windows, you'de be working in protected mode, so you can't access those parts of memory

Secondly, the keyboard buffer isn't held in the same area of memory on the pc

so, reading keys directly from memory would be different

(under DOS you might do it, but from which address, I don't know)

#7 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1564 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Alternative states of consciousness, programming, making things work the best they possibly can.

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 31 March 2003 - 09:13 PM

key=peekb(0x40,0xAF);

and key is an integer ... 16bits only!! :P :P
Do a little program to know the value of a key, it isn't very complicated!

and that's all ...

peekb returns a char type so it's 8 bits long, key should be a char.

You don't have to make a litle program, you can use TOUCHE to know this value in the "1: Touche" menu entry (like for my function): The values of offsets 0x4a:0xc, 0x4a:0xd, 0x4a:0xe, 0x4a:0xf are displayed...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users