OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [drivers/] [kbd_fbsd.c] - Blame information for rev 1772

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
#include <sys/time.h>
2
#include <machine/console.h>
3
#include <vgl.h>
4
 
5
#include "device.h"
6
 
7
#define KBLEN           30
8
unsigned short kbuffer[KBLEN];
9
unsigned short klen=0;
10
int states[256];
11
 
12
const int quertycodes[48+1]={41, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,\
13
                          16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 43,\
14
                          30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 44, 45,\
15
                          46, 47, 48, 49, 50, 51, 52, 53, 57, 0};
16
const char chars[48] =    {'`','1','2','3','4','5','6','7','8','9','0','-','=',\
17
                         'q','w','e','r','t','y','u','i','o','p','[',']','\\',\
18
                         'a','s','d','f','g','h','j','k','l',';','\'','z','x',\
19
                         'c','v','b','n','m',',','.','/',' '};
20
 
21
 
22
static int initkeyb(KBDDEVICE *pkd);
23
static void restorekeyb(void);
24
static  void TTY_GetModifierInfo(int *modifiers);
25
static int getkey(MWUCHAR *buf, int *modifiers);
26
static int kbhit(void);
27
 
28
KBDDEVICE kbddev = {
29
  initkeyb,
30
  restorekeyb,
31
  TTY_GetModifierInfo,
32
  getkey,
33
  kbhit
34
};
35
 
36
/*
37
 * Return the possible modifiers for the keyboard.
38
 */
39
 
40
static  void TTY_GetModifierInfo(int *modifiers)
41
{
42
        *modifiers = 0;                  /* no modifiers available */
43
}
44
 
45
static int initkeyb(KBDDEVICE *pkd)
46
{
47
        VGLKeyboardInit(VGL_CODEKEYS);
48
        memset(states, FALSE, (sizeof states));
49
        return(0);
50
 
51
}
52
 
53
static void restorekeyb(void)
54
{
55
        VGLKeyboardEnd();
56
}
57
 
58
void ProcessKbd(void)
59
{
60
        unsigned short result, i;
61
        int isasymbol;
62
        int state;
63
 
64
        while((result = VGLKeyboardGetCh()) != 0) {
65
 
66
                if(result < 128)
67
                        state = TRUE;
68
                else {
69
                        state = FALSE;
70
                        result -= 128;
71
                }
72
 
73
                isasymbol = FALSE;
74
                for(i=0;quertycodes[i]!=0;i++)
75
                        if(result == quertycodes[i]) {
76
                                result = chars[i];
77
                                isasymbol = TRUE;
78
                                break;
79
                        }
80
 
81
                if (isasymbol == FALSE)
82
                        result+=128;
83
 
84
                states[result] = state;
85
 
86
                if(state == TRUE)
87
                        continue;
88
 
89
                if(klen == KBLEN) /* Buffer is full, drop some pieces */
90
                        memcpy(kbuffer, kbuffer + 1, --klen);
91
                kbuffer[klen++] = result;
92
        }
93
}
94
 
95
int GetAsyncKeyState(int key)
96
{
97
        ProcessKbd();
98
        return(states[key]);
99
}
100
 
101
static int getkey(MWUCHAR *buf, int *modifiers)
102
{
103
        MWUCHAR result;
104
 
105
        while(kbhit() != TRUE);
106
        result = kbuffer[0];
107
        memcpy(kbuffer, kbuffer + 1, --klen);
108
 
109
        *buf=result;
110
        return(0);
111
}
112
 
113
static int kbhit(void)
114
{
115
        ProcessKbd();
116
 
117
        if (klen > 0)
118
                return(1);
119
        else
120
                return(0);
121
}
122
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.