forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeybuf.cpp
112 lines (94 loc) · 2.03 KB
/
keybuf.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* UAE - The Un*x Amiga Emulator
*
* Keyboard buffer. Not really needed for X, but for SVGAlib and possibly
* Mac and DOS ports.
*
* Note: it's possible to have two threads in UAE, one reading keystrokes
* and the other one writing them. Despite this, no synchronization effort
* is needed. This code should be perfectly thread safe. At least if you
* assume that integer store instructions are atomic.
*
* Copyright 1995, 1997 Bernd Schmidt
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include <assert.h>
#include "options.h"
#include "keybuf.h"
#include "keyboard.h"
#include "inputdevice.h"
#include "custom.h"
#include "savestate.h"
static int kpb_first, kpb_last;
static int keybuf[256];
int keys_available (void)
{
int val;
val = kpb_first != kpb_last;
return val;
}
int get_next_key (void)
{
int key;
assert (kpb_first != kpb_last);
key = keybuf[kpb_last];
if (++kpb_last == 256)
kpb_last = 0;
//write_log (L"%02x:%d\n", key >> 1, key & 1);
return key;
}
int record_key (int kc)
{
if (input_recording < 0 || pause_emulation)
return 0;
return record_key_direct (kc);
}
int record_key_direct (int kc)
{
int fs = 0;
int kpb_next = kpb_first + 1;
int k = kc >> 1;
int b = !(kc & 1);
//write_log (L"got kc %02X\n", ((kc << 7) | (kc >> 1)) & 0xff);
if (kpb_next == 256)
kpb_next = 0;
if (kpb_next == kpb_last) {
write_log (L"Keyboard buffer overrun. Congratulations.\n");
return 0;
}
if ((kc >> 1) == AK_RCTRL) {
kc ^= AK_RCTRL << 1;
kc ^= AK_CTRL << 1;
}
if (input_recording > 0) {
inprec_rstart(INPREC_KEY);
inprec_ru8(kc);
inprec_rend();
}
keybuf[kpb_first] = kc;
kpb_first = kpb_next;
return 1;
}
void keybuf_init (void)
{
kpb_first = kpb_last = 0;
inputdevice_updateconfig (&currprefs);
}
#ifdef SAVESTATE
uae_u8 *save_keyboard (int *len)
{
uae_u8 *dst, *t;
dst = t = xmalloc (uae_u8, 8);
save_u32 (getcapslockstate () ? 1 : 0);
save_u32 (0);
*len = 8;
return t;
}
uae_u8 *restore_keyboard (uae_u8 *src)
{
setcapslockstate (restore_u32 ());
restore_u32 ();
return src;
}
#endif /* SAVESTATE */