svn-id: r10367
This commit is contained in:
Torbjörn Andersson 2003-09-23 06:30:52 +00:00
parent f8591911ab
commit c7b8a6c01b
2 changed files with 14 additions and 37 deletions

View File

@ -63,61 +63,39 @@
#include "stdafx.h" #include "stdafx.h"
#include "driver96.h" #include "driver96.h"
uint8 keyBacklog = 0; // The number of key presses waiting to be processed. uint8 keyBacklog = 0; // The number of key presses waiting to be processed.
uint8 keyPointer = 0; // Index of the next key to read from the buffer. uint8 keyPointer = 0; // Index of the next key to read from the buffer.
char keyBuffer[MAX_KEY_BUFFER]; // The keyboard buffer
char keyBuffer[MAX_KEY_BUFFER]; // The keyboard buffer
void WriteKey(char key) {
void WriteKey(char key) if (keyBuffer && keyBacklog < MAX_KEY_BUFFER) {
{
if (keyBuffer && keyBacklog < MAX_KEY_BUFFER)
{
keyBuffer[(keyPointer + keyBacklog) % MAX_KEY_BUFFER] = key; keyBuffer[(keyPointer + keyBacklog) % MAX_KEY_BUFFER] = key;
keyBacklog += 1; keyBacklog++;
} }
} }
BOOL KeyWaiting(void) {
BOOL KeyWaiting(void)
{
if (keyBacklog) if (keyBacklog)
return(TRUE); return TRUE;
else
return(FALSE);
return FALSE;
} }
int32 ReadKey(char *key) int32 ReadKey(char *key) {
{
if (!keyBacklog) if (!keyBacklog)
return(RDERR_NOKEYWAITING); return RDERR_NOKEYWAITING;
if (key == NULL) if (key == NULL)
return(RDERR_INVALIDPOINTER); return RDERR_INVALIDPOINTER;
*key = keyBuffer[keyPointer++]; *key = keyBuffer[keyPointer++];
if (keyPointer == MAX_KEY_BUFFER) if (keyPointer == MAX_KEY_BUFFER)
keyPointer = 0; keyPointer = 0;
keyBacklog -= 1; keyBacklog--;
return(RD_OK);
return RD_OK;
} }
void GetKeyStatus(_drvKeyStatus *s)
{
// Flush key buffer
s->pBacklog = &keyBacklog;
s->pPointer = &keyPointer;
s->pBuffer = keyBuffer;
}

View File

@ -40,7 +40,6 @@
#ifndef KEYBOARD_H #ifndef KEYBOARD_H
#define KEYBOARD_H #define KEYBOARD_H
void WriteKey(char key); // Adds a keypress to the buffer void WriteKey(char key); // Adds a keypress to the buffer
#endif #endif