[A89] Re: OSDequeue


[Prev][Next][Index][Thread]

[A89] Re: OSDequeue




John David Ratliff wrote:

> -------------------
> >
> > John David Ratliff wrote:
> >
> > > -------------------
> > > >
> > > > How do you implement this and save the key press to a variable,
> > > every
> > > > time I do it the thing won't work!
> > > >
> > > >
> > > >
> > > >
> > >
> > > OSdequeue for keyboard reading is very simple.
> > >
> > > #include <system.h>
> > > #include <kbd.h>
> > >
> > > short int getKey(short int wait) {
> > >     unsigned short int key = 0;
> > >     short int done = 0;
> > >     void *kbq = kbd_queue();
> > >
> > >     while (!done) {
> > >         if (!wait || !OSdequeue(&key,kbq)) {
> > >             done = 1;
> > >         }
> > >     }
> > >
> > >     return (signed short int)key;
> > > }
> > >
> > > It's sometimes a good idea to cast it to a signed int to avoid
> > > warnings between signed and unsigned comparisons, which you will
> often
> > > get when comparing the KEY macros, like arrow keys KEY_LEFT.
> > >
> > > So, if you want to use that function...
> > >
> > > void _main(void) {
> > >     short int key;
> > >
> > >     key = getKey(1);
> > > }
> > >
> > > This will wait until a key is available and return the signed
> > > keypress, stored in the variable key local to the _main()
> function.
> > >
> > > OSdequeue() will not work if you have disabled interrupts or
> > > redirected auto-int 1. If you did this, you will have to use
> low-level
> > > keyboard reading...
> > >
> > > Hope this helps...
> > >
> > > John David Ratliff
> > > jdratlif@cs.indiana.edu
> >
> > When the compiler goes over void kbq = kdb_queue(); it gives an
> error
> >
> >
> >
> >
>
> It must be a pointer.
>
> void *kbq = kbd_queue();
>
> You must include kbd.h for this, or tigcclib.h
> You must include system.h for the OSdequeue() function, or tigcclib.h
>
> This program compiles and runs fine for me, using TIGCC 0.91 SP1
>
> // C Source File
> // Created 6/15/2001; 2:41:11 PM
>
> #define OPTIMIZE_ROM_CALLS    // Use ROM Call Optimization
>
> #define SAVE_SCREEN           // Save/Restore LCD Contents
>
> #include <stdio.h>
> #include <graph.h>
> #include <system.h>
> #include <kbd.h>
>
> short _ti89;                  // Produce .89Z File
> short _ti92plus;              // Produce .9XZ File
>
> short int getKey(short int wait) {
>      unsigned short int key = 0;
>      short int done = 0;
>      void *kbq = kbd_queue();
>
>      while (!done) {
>          if (!wait || !OSdequeue(&key,kbq)) {
>              done = 1;
>          }
>      }
>
>     return (signed short int)key;
> }
>
> void _main(void) {
>     short int key;
>     key = getKey(1);
>
>     ClrScr();
>     printf_xy(0,0,"Key: %hd",key);
>
>     getKey(1);
> }
>
> John David Ratliff
> jdratlif@cs.indiana.edu

I had it set with a pointer, but I didn't have it declared in the _main
function, but I did this now and it works... Computer insufficiencies
amaze me!




References: