-
Notifications
You must be signed in to change notification settings - Fork 1
/
Keyboard.h
218 lines (188 loc) · 5.92 KB
/
Keyboard.h
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* ES40 emulator.
* Copyright (C) 2007-2008 by the ES40 Emulator Project
*
* WWW : http://sourceforge.net/projects/es40
* E-mail : [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Although this is not required, the author would appreciate being notified of,
* and receiving any modifications you may make to the source code that might serve
* the general public.
*/
/**
* \file
* Contains the definitions for the emulated Keyboard and mouse devices and controller.
*
* $Id: Keyboard.h,v 1.1 2008/02/12 11:07:09 iamcamiel Exp $
*
* X-1.1 Camiel Vanderhoeven 12-FEB-2008
* Created. Contains code previously found in AliM1543C.h
*
* \author Camiel Vanderhoeven ([email protected] / http://www.camicom.com)
**/
#if !defined(INCLUDED_KEYBOARD_H)
#define INCLUDED_KEYBOARD_H
#include "SystemComponent.h"
#include "gui/gui.h"
#define BX_KBD_ELEMENTS 16
#define BX_MOUSE_BUFF_SIZE 48
#define MOUSE_MODE_RESET 10
#define MOUSE_MODE_STREAM 11
#define MOUSE_MODE_REMOTE 12
#define MOUSE_MODE_WRAP 13
/**
* \brief Emulated keyboard controller, keyboard and mouse.
**/
class CKeyboard : public CSystemComponent
{
public:
CKeyboard(CConfigurator * cfg, CSystem * c);
virtual ~CKeyboard();
virtual int DoClock();
virtual void WriteMem(int index, u64 address, int dsize, u64 data);
virtual u64 ReadMem(int index, u64 address, int dsize);
virtual int SaveState(FILE * f);
virtual int RestoreState(FILE * f);
void gen_scancode(u32 key);
private:
u8 read_60();
void write_60(u8 data);
u8 read_64();
void write_64(u8 data);
void resetinternals(bool powerup);
void enQ(u8 scancode);
void controller_enQ(u8 data, unsigned source);
void set_kbd_clock_enable(u8 value);
void set_aux_clock_enable(u8 value);
void ctrl_to_kbd(u8 value);
void enQ_imm(u8 val);
void ctrl_to_mouse(u8 value);
bool mouse_enQ_packet(u8 b1, u8 b2, u8 b3, u8 b4);
void mouse_enQ(u8 mouse_data);
unsigned periodic();
// void kbd_clock();
void create_mouse_packet(bool force_enq);
/// The state structure contains all elements that need to be saved to the statefile.
struct SKb_state {
/// status bits matching the status port
struct SAli_kbdc_status {
bool pare; /**< Bit7, 1= parity error from keyboard/mouse - ignored. */
bool tim; /**< Bit6, 1= timeout from keyboard - ignored. */
bool auxb; /**< Bit5, 1= mouse data waiting for CPU to read. */
bool keyl; /**< Bit4, 1= keyswitch in lock position - ignored. */
bool c_d; /**< Bit3, 1=command to port 64h, 0=data to port 60h. */
bool sysf; /**< Bit2 */
bool inpb; /**< Bit1 */
bool outb; /**< Bit0, 1= keyboard data or mouse data ready for CPU. Check aux to see which. */
} status;
/* internal to our version of the keyboard controller */
bool kbd_clock_enabled;
bool aux_clock_enabled;
bool allow_irq1;
bool allow_irq12;
u8 kbd_output_buffer;
u8 aux_output_buffer;
u8 last_comm;
u8 expecting_port60h;
u8 expecting_mouse_parameter;
u8 last_mouse_command;
u32 timer_pending;
bool irq1_requested;
bool irq12_requested;
bool scancodes_translate;
bool expecting_scancodes_set;
u8 current_scancodes_set;
bool bat_in_progress;
/// mouse status
struct SAli_mouse {
bool captured; // host mouse capture enabled
// u8 type;
u8 sample_rate;
u8 resolution_cpmm; // resolution in counts per mm
u8 scaling;
u8 mode;
u8 saved_mode; // the mode prior to entering wrap mode
bool enable;
u8 get_status_byte ()
{
// top bit is 0 , bit 6 is 1 if remote mode.
u8 ret = (u8) ((mode == MOUSE_MODE_REMOTE) ? 0x40 : 0);
ret |= (enable << 5);
ret |= (scaling == 1) ? 0 : (1 << 4);
ret |= ((button_status & 0x1) << 2);
ret |= ((button_status & 0x2) << 0);
return ret;
}
u8 get_resolution_byte ()
{
u8 ret = 0;
switch (resolution_cpmm) {
case 1:
ret = 0;
break;
case 2:
ret = 1;
break;
case 4:
ret = 2;
break;
case 8:
ret = 3;
break;
default:
FAILURE("mouse: invalid resolution_cpmm");
};
return ret;
}
u8 button_status;
s16 delayed_dx;
s16 delayed_dy;
s16 delayed_dz;
u8 im_request;
bool im_mode;
} mouse;
/// internal keyboard buffer
struct SAli_kbdib{
int num_elements;
u8 buffer[BX_KBD_ELEMENTS];
int head;
bool expecting_typematic;
bool expecting_led_write;
bool expecting_make_break;
u8 delay;
u8 repeat_rate;
u8 led_status;
bool scanning_enabled;
} kbd_internal_buffer;
/// internal mouse buffer
struct SAli_mib{
int num_elements;
u8 buffer[BX_MOUSE_BUFF_SIZE];
int head;
} mouse_internal_buffer;
#define BX_KBD_CONTROLLER_QSIZE 5
u8 kbd_controller_Q[BX_KBD_CONTROLLER_QSIZE];
unsigned kbd_controller_Qsize;
unsigned kbd_controller_Qsource; /**< 0=keyboard, 1=mouse */
} state;
int listenSocket;
int connectSocket;
#if defined(IDB) && defined(LS_MASTER)
int throughSocket;
#endif
};
extern CKeyboard * theKeyboard;
#endif // !defined(INCLUDED_KEYBOARD_H)