File: keyboard.c

package info (click to toggle)
invaders 1.0.0-13
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid, stretch
  • size: 296 kB
  • ctags: 384
  • sloc: ansic: 1,944; sh: 54; asm: 28; makefile: 16
file content (60 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "keyboard.h"

#include "io.h"
#include "memory.h"

static uint8 *ringbuf=0;
static uint32 ringstart=0, ringend=0, ringsize=1024;

void key_decode(uint8 *key, bool *pressed)
{
  uint8 c;
  uint32 ringoldstart = ringstart;

  *key='x';
  *pressed=false;
    
  if (ringstart == ringend) return;
  c=ringbuf[ringstart++];
  if (ringstart==ringsize) ringstart=0;

  if (c == 0xe0) {
    if (ringstart == ringend) {
      ringstart = ringoldstart;
      return;
    };
    c = ringbuf[ringstart++];
    if (ringstart == ringsize) ringstart=0;
    *pressed = ((c&0x80) == 0) ? true : false;
    c &= ~0x80;
    if (c==0x4d) *key='>';
    if (c==0x4b) *key='<';
    if (c==0x48) *key='^';
    if (c==0x50) *key='v';
    if (c==0x49) *key='u';
    if (c==0x51) *key='d';
  }else{
    *pressed = ((c&0x80) == 0) ? true : false;
    c &= ~0x80;
    if ((c>=0x3b) && (c<=0x44)) *key=c-0x3b+'0';
    if (c==0x2a) *key='l';
    if (c==0x36) *key='r';
    if (c==1) *key='@';
    if (c==0x1c) *key='e';
    if (c==0x39) *key=' ';
    if (c==0x19) *key='p';
  };
};

void key_polling()
{
  if (inb(0x64)&1) {
    ringbuf[ringend++] = inb(0x60);
    if (ringend==ringsize) ringend=0;
  };
};

void key_initialize()
{
  ringbuf = malloc (ringsize);
};