OSDN Git Service

* debug/debug.h: Move to top-level bochs directory.
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / bochs / keyboard / keyboard.h
1 //  Copyright (C) 2001  MandrakeSoft S.A.
2 //
3 //    MandrakeSoft S.A.
4 //    43, rue d'Aboukir
5 //    75002 Paris - France
6 //    http://www.linux-mandrake.com/
7 //    http://www.mandrakesoft.com/
8 //
9 //  This library is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU Lesser General Public
11 //  License as published by the Free Software Foundation; either
12 //  version 2 of the License, or (at your option) any later version.
13 //
14 //  This library is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 //  Lesser General Public License for more details.
18 //
19 //  You should have received a copy of the GNU Lesser General Public
20 //  License along with this library; if not, write to the Free Software
21 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22
23
24 #ifndef _PCKEY_H
25 #define _PCKEY_H
26 #if BX_SUPPORT_SID
27 #include "keysymbols.h"
28 class keyboard;
29 #endif
30
31 #define BX_KBD_ELEMENTS 16
32 #define BX_MOUSE_BUFF_SIZE 48
33
34 #if BX_USE_KEY_SMF
35 #  define BX_KEY_SMF  static
36 #  define BX_KEY_THIS bx_keyboard.
37 #else
38 #  define BX_KEY_SMF
39 #  define BX_KEY_THIS this->
40 #endif
41 #if BX_SUPPORT_SID==0
42 extern bx_keyb_c bx_keyboard;
43 #endif
44 class bx_keyb_c : public logfunctions {
45 public:
46   bx_keyb_c(void);
47   ~bx_keyb_c(void);
48 #if BX_SUPPORT_SID
49   BX_KEY_SMF void     init(keyboard *kbd_comp);
50 #else
51   BX_KEY_SMF void     init(bx_devices_c *d, bx_cmos_c *cmos);
52 #endif
53   BX_KEY_SMF void     gen_scancode(Bit32u   scancode);
54   BX_KEY_SMF Bit8u    get_kbd_enable(void);
55   BX_KEY_SMF void     mouse_motion(int delta_x, int delta_y, unsigned button_state);
56   BX_KEY_SMF void     mouse_button(unsigned mouse_state);
57 #if BX_SUPPORT_SID==0
58   BX_KEY_SMF int      SaveState( class state_file *fd );
59   BX_KEY_SMF int      LoadState( class state_file *fd );
60 #endif
61   BX_KEY_SMF unsigned periodic( Bit32u   usec_delta );
62   BX_KEY_SMF void     put_scancode( unsigned char *code, int count );
63
64 private:
65
66   static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
67   static void   write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
68 #if !BX_USE_KEY_SMF
69 #if BX_SUPPORT_SID
70  public:
71 #endif
72   void     write(Bit32u   address, Bit32u   value, unsigned io_len);
73   Bit32u   read(Bit32u   address, unsigned io_len);
74 #endif
75 #if BX_SUPPORT_SID
76  private:
77 #endif
78   struct {
79     struct {
80       /* status bits */
81       Boolean pare;
82       Boolean tim;
83       Boolean auxb;
84       Boolean keyl;
85       Boolean c_d; /* 1=command to port 64h, 0=data to port 60h */
86       Boolean sysf;
87       Boolean inpb;
88       Boolean outb;
89
90       Boolean scan_convert;
91       Boolean kbd_clock_enabled;
92       Boolean aux_clock_enabled;
93       Boolean allow_irq1;
94       Boolean allow_irq12;
95       Bit8u   kbd_output_buffer;
96       Bit8u   aux_output_buffer;
97       Bit8u   last_comm;
98       Bit8u   expecting_port60h;
99       Bit8u   expecting_mouse_parameter;
100       Bit8u   last_mouse_command;
101       Bit32u   timer_pending;
102       Boolean irq1_requested;
103       Boolean irq12_requested;
104       } kbd_controller;
105
106     struct mouseStruct {
107       Bit8u   sample_rate;
108       Bit8u   resolution_cpmm; // resolution in counts per mm
109       Bit8u   scaling;
110       Bit8u   mode;
111       Boolean enable;
112
113       Bit8u get_status_byte ()
114         {
115           Bit8u ret = 0;
116           // we're always in stream mode (right?)
117           ret |= (enable << 5);
118           ret |= (scaling == 1) ? 0 : (1 << 4);
119           ret |= ((button_status & 0x1) << 2);
120           ret |= ((button_status & 0x2) << 0);
121           return ret;
122         }
123
124       Bit8u get_resolution_byte ()
125         {
126           Bit8u ret = 0;
127
128           switch (resolution_cpmm) {
129           case 1:
130             ret = 0;
131             break;
132
133           case 2:
134             ret = 1;
135             break;
136
137           case 4:
138             ret = 2;
139             break;
140
141           case 8:
142             ret = 3;
143             break;
144 #if BX_SUPPORT_SID==0
145           default:
146 #define LOG_THIS bx_keyboard.
147             BX_PANIC(("mouse: invalid resolution_cpmm"));
148 #undef LOG_THIS
149 #endif
150           };
151           return ret;
152         }
153
154       Bit8u button_status;
155       } mouse;
156
157     struct {
158       int     num_elements;
159       Bit8u   buffer[BX_KBD_ELEMENTS];
160       int     head;
161       Boolean expecting_typematic;
162       Boolean expecting_led_write;
163       Bit8u   delay;
164       Bit8u   repeat_rate;
165       Bit8u   led_status;
166       Boolean scanning_enabled;
167       } kbd_internal_buffer;
168
169     struct {
170       int     num_elements;
171       Bit8u   buffer[BX_MOUSE_BUFF_SIZE];
172       int     head;
173       } mouse_internal_buffer;
174 #define BX_KBD_CONTROLLER_QSIZE 5
175     Bit8u    controller_Q[BX_KBD_CONTROLLER_QSIZE];
176     unsigned controller_Qsize;
177     unsigned controller_Qsource; // 0=keyboard, 1=mouse
178     } s; // State information for saving/loading
179 #if BX_SUPPORT_SID
180   keyboard *kbd_component;
181 #else
182   bx_devices_c *devices;
183 #endif
184   BX_KEY_SMF void     resetinternals(Boolean powerup);
185   BX_KEY_SMF void     set_kbd_clock_enable(Bit8u   value);
186   BX_KEY_SMF void     set_aux_clock_enable(Bit8u   value);
187   BX_KEY_SMF void     kbd_ctrl_to_kbd(Bit8u   value);
188   BX_KEY_SMF void     kbd_ctrl_to_mouse(Bit8u   value);
189   BX_KEY_SMF void     kbd_enQ(Bit8u   scancode);
190   BX_KEY_SMF void     kbd_enQ_imm(Bit8u   val);
191   BX_KEY_SMF void     activate_timer(void);
192   BX_KEY_SMF void     controller_enQ(Bit8u   data, unsigned source);
193   BX_KEY_SMF Boolean  mouse_enQ_packet(Bit8u   b1, Bit8u   b2, Bit8u   b3);
194   BX_KEY_SMF void     mouse_enQ(Bit8u   mouse_data);
195   };
196
197
198 #endif  // #ifndef _PCKEY_H