Keyboard.h

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00047 #if !defined(INCLUDED_KEYBOARD_H)
00048 #define INCLUDED_KEYBOARD_H
00049 
00050 #include "SystemComponent.h"
00051 #include "gui/gui.h"
00052 
00053 #define BX_KBD_ELEMENTS     16
00054 #define BX_MOUSE_BUFF_SIZE  48
00055 
00056 #define MOUSE_MODE_RESET    10
00057 #define MOUSE_MODE_STREAM   11
00058 #define MOUSE_MODE_REMOTE   12
00059 #define MOUSE_MODE_WRAP     13
00060 
00064 class CKeyboard : public CSystemComponent, public Poco::Runnable
00065 {
00066   public:
00067     CKeyboard(CConfigurator* cfg, CSystem* c);
00068     virtual       ~CKeyboard();
00069 
00070     virtual void  check_state();
00071     virtual void  WriteMem(int index, u64 address, int dsize, u64 data);
00072     virtual u64   ReadMem(int index, u64 address, int dsize);
00073     virtual int   SaveState(FILE* f);
00074     virtual int   RestoreState(FILE* f);
00075     virtual void  run();
00076     void          execute();
00077 
00078     void          gen_scancode(u32 key);
00079 
00080     virtual void  init();
00081     virtual void  start_threads();
00082     virtual void  stop_threads();
00083   private:
00084     Poco::Thread * myThread;
00085     bool      StopThread;
00086 
00087     u8        read_60();
00088     void      write_60(u8 data);
00089     u8        read_64();
00090     void      write_64(u8 data);
00091     void      resetinternals(bool powerup);
00092     void      enQ(u8 scancode);
00093     void      controller_enQ(u8 data, unsigned source);
00094     void      set_kbd_clock_enable(u8 value);
00095     void      set_aux_clock_enable(u8 value);
00096     void      ctrl_to_kbd(u8 value);
00097     void      enQ_imm(u8 val);
00098     void      ctrl_to_mouse(u8 value);
00099     bool      mouse_enQ_packet(u8 b1, u8 b2, u8 b3, u8 b4);
00100     void      mouse_enQ(u8 mouse_data);
00101     unsigned  periodic();
00102 
00103     //  void kbd_clock();
00104     void      create_mouse_packet(bool force_enq);
00105 
00107     struct SKb_state
00108     {
00109 
00111       struct SAli_kbdc_status
00112       {
00113         bool  pare;     
00114         bool  tim;      
00115         bool  auxb;     
00116         bool  keyl;     
00117         bool  c_d;      
00118         bool  sysf;     
00119         bool  inpb;     
00120         bool  outb;     
00121       } status;
00122 
00123       /* internal to our version of the keyboard controller */
00124       bool  kbd_clock_enabled;
00125       bool  aux_clock_enabled;
00126       bool  allow_irq1;
00127       bool  allow_irq12;
00128       u8    kbd_output_buffer;
00129       u8    aux_output_buffer;
00130       u8    last_comm;
00131       u8    expecting_port60h;
00132       u8    expecting_mouse_parameter;
00133       u8    last_mouse_command;
00134       u32   timer_pending;
00135       bool  irq1_requested;
00136       bool  irq12_requested;
00137       bool  scancodes_translate;
00138       bool  expecting_scancodes_set;
00139       u8    current_scancodes_set;
00140       bool  bat_in_progress;
00141 
00143       struct SAli_mouse
00144       {
00145         bool  captured; // host mouse capture enabled
00146 
00147         //      u8   type;
00148         u8    sample_rate;
00149         u8    resolution_cpmm;          // resolution in counts per mm
00150         u8    scaling;
00151         u8    mode;
00152         u8    saved_mode;               // the mode prior to entering wrap mode
00153         bool  enable;
00154 
00155         u8 get_status_byte()
00156         {
00157 
00158           // top bit is 0 , bit 6 is 1 if remote mode.
00159           u8  ret = (u8) ((mode == MOUSE_MODE_REMOTE) ? 0x40 : 0);
00160           ret |= (enable << 5);
00161           ret |= (scaling == 1) ? 0 : (1 << 4);
00162           ret |= ((button_status & 0x1) << 2);
00163           ret |= ((button_status & 0x2) << 0);
00164           return ret;
00165         }
00166 
00167         u8 get_resolution_byte()
00168         {
00169           u8  ret = 0;
00170 
00171           switch(resolution_cpmm)
00172           {
00173           case 1:   ret = 0; break;
00174           case 2:   ret = 1; break;
00175           case 4:   ret = 2; break;
00176           case 8:   ret = 3; break;
00177           default:  FAILURE(NotImplemented, "mouse: invalid resolution_cpmm");
00178           };
00179           return ret;
00180         }
00181 
00182         u8    button_status;
00183         s16   delayed_dx;
00184         s16   delayed_dy;
00185         s16   delayed_dz;
00186         u8    im_request;
00187         bool  im_mode;
00188       } mouse;
00189 
00191       struct SAli_kbdib
00192       {
00193         int   num_elements;
00194         u8    buffer[BX_KBD_ELEMENTS];
00195         int   head;
00196         bool  expecting_typematic;
00197         bool  expecting_led_write;
00198         bool  expecting_make_break;
00199         u8    delay;
00200         u8    repeat_rate;
00201         u8    led_status;
00202         bool  scanning_enabled;
00203       } kbd_internal_buffer;
00204 
00206       struct SAli_mib
00207       {
00208         int num_elements;
00209         u8  buffer[BX_MOUSE_BUFF_SIZE];
00210         int head;
00211       } mouse_internal_buffer;
00212 
00213 #define BX_KBD_CONTROLLER_QSIZE 5
00214       u8        kbd_controller_Q[BX_KBD_CONTROLLER_QSIZE];
00215       unsigned  kbd_controller_Qsize;
00216       unsigned  kbd_controller_Qsource; 
00217     } state;
00218 };
00219 
00220 extern CKeyboard*   theKeyboard;
00221 #endif // !defined(INCLUDED_KEYBOARD_H)

SourceForge.net Logo
Project space on SourceForge.net