FreeBASIC  0.91.0
gfx_inkey.c
Go to the documentation of this file.
1 /* inkey$ handling */
2 
3 #include "fb_gfx.h"
4 
5 #define KEY_BUFFER_LEN 16
6 
7 static int key_buffer[KEY_BUFFER_LEN], key_head = 0, key_tail = 0;
8 static int key_buffer_changed = FALSE;
9 
11 {
12  int res;
13 
14  DRIVER_LOCK();
15 
16  res = key_buffer_changed;
18 
19  DRIVER_UNLOCK();
20 
21  return res;
22 }
23 
24 void fb_hPostKey(int key)
25 {
27  if (((key_tail + 1) & (KEY_BUFFER_LEN - 1)) == key_head)
28  key_head = (key_head + 1) & (KEY_BUFFER_LEN - 1);
29  key_tail = (key_tail + 1) & (KEY_BUFFER_LEN - 1);
31 }
32 
33 #ifdef HOST_DOS
34 void fb_hPostKey_End(void)
35 { /* this function is here to get the length of the fb_hPostKey function so
36  the DOS gfxlib driver can lock it into physical memory for use in an
37  interrupt handler */ }
38 #endif
39 
40 static int get_key(void)
41 {
42  int key = 0;
43 
44  DRIVER_LOCK();
45 
46  if (key_head != key_tail) {
47  key = key_buffer[key_head];
48  key_head = (key_head + 1) & (KEY_BUFFER_LEN - 1);
49  }
50 
51  /* Reset the status for "key buffer changed" when a key
52  * was removed from the input queue. */
54 
55  DRIVER_UNLOCK();
56 
57  return key;
58 }
59 
60 int fb_GfxGetkey(void)
61 {
62  int key = 0;
63 
64  if (!__fb_gfx)
65  return 0;
66 
67  while ((key = get_key()) == 0) {
68  fb_Sleep(20);
69  }
70 
71  return key;
72 }
73 
74 int fb_GfxKeyHit(void)
75 {
76  int res;
77 
78  DRIVER_LOCK();
79 
80  res = (key_head != key_tail? 1: 0);
81 
82  DRIVER_UNLOCK();
83 
84  return res;
85 }
86 
88 {
89  FBSTRING *res;
90  int ch;
91 
92  if (__fb_gfx && (ch = get_key())) {
93  res = fb_hMakeInkeyStr( ch );
94  } else {
95  res = &__fb_ctx.null_desc;
96  }
97 
98  return res;
99 }
100 
101 int fb_GfxIsRedir(int is_input)
102 {
103  return FALSE;
104 }