| 1 |
/* |
| 2 |
* KCemu -- The emulator for the KC85 homecomputer series and much more. |
| 3 |
* Copyright (C) 1997-2010 Torsten Paul |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <iostream> |
| 21 |
#include <iomanip> |
| 22 |
|
| 23 |
#include "kc/system.h" |
| 24 |
|
| 25 |
#include "kc/z80.h" |
| 26 |
#include "kc/keys.h" |
| 27 |
//#include "kc/muglerpc/keydef.h" |
| 28 |
#include "kc/muglerpc/keyboard.h" |
| 29 |
|
| 30 |
#include "libdbg/dbg.h" |
| 31 |
|
| 32 |
KeyboardMuglerPC::KeyboardMuglerPC(void) |
| 33 |
{ |
| 34 |
init(); |
| 35 |
z80->register_ic(this); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
KeyboardMuglerPC::~KeyboardMuglerPC(void) |
| 40 |
{ |
| 41 |
z80->unregister_ic(this); |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
KeyboardMuglerPC::init(void) |
| 46 |
{ |
| 47 |
int a; |
| 48 |
|
| 49 |
for (a = 0;a < MAX_KEYS;a++) |
| 50 |
{ |
| 51 |
_keybuf[a].sym = -1; |
| 52 |
_keybuf[a].code = -1; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
int |
| 57 |
KeyboardMuglerPC::decode_key(int keysym, bool press) |
| 58 |
{ |
| 59 |
return keysym; |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
KeyboardMuglerPC::keyPressed(int keysym, int keycode) |
| 64 |
{ |
| 65 |
int k; |
| 66 |
|
| 67 |
/* |
| 68 |
* ignore repeated key press events (e.g. generated by |
| 69 |
* GTK that reports key repeat as keypress/keypress/keypress/... |
| 70 |
* without the possibility to switch that off :-( ) |
| 71 |
*/ |
| 72 |
for (int a = 0;a < MAX_KEYS;a++) |
| 73 |
if (_keybuf[a].code == keycode) |
| 74 |
return; |
| 75 |
|
| 76 |
k = decode_key(keysym, true); |
| 77 |
if (k == -1) |
| 78 |
return; |
| 79 |
|
| 80 |
DBG(2, form("KCemu/keyboard/muglerpc/key_press", |
| 81 |
"##### Keyboard: keyPressed [%03x/%02x] ", |
| 82 |
keysym, k)); |
| 83 |
|
| 84 |
for (int a = 0;a < MAX_KEYS;a++) |
| 85 |
{ |
| 86 |
if (_keybuf[a].code == -1) |
| 87 |
{ |
| 88 |
_keybuf[a].sym = k; |
| 89 |
_keybuf[a].code = keycode; |
| 90 |
break; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
for (int a = 0;a < MAX_KEYS;a++) |
| 95 |
if (_keybuf[a].code != -1) |
| 96 |
DBG(2, form("KCemu/keyboard/muglerpc/key_press", |
| 97 |
" {%02d:%02x:%02x}", a, _keybuf[a].sym, _keybuf[a].code)); |
| 98 |
|
| 99 |
DBG(2, form("KCemu/keyboard/muglerpc/key_press", |
| 100 |
"\n")); |
| 101 |
} |
| 102 |
|
| 103 |
void |
| 104 |
KeyboardMuglerPC::keyReleased(int keysym, int keycode) |
| 105 |
{ |
| 106 |
if (keysym == -1) |
| 107 |
{ |
| 108 |
for (int a = 0;a < MAX_KEYS;a++) |
| 109 |
_keybuf[a].code = -1; |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
/* |
| 114 |
* remove (maybe multiple) entries from keyboard buffer |
| 115 |
*/ |
| 116 |
for (int a = 0;a < MAX_KEYS;a++) |
| 117 |
if (_keybuf[a].code == keycode) |
| 118 |
_keybuf[a].code = -1; |
| 119 |
|
| 120 |
DBG(2, form("KCemu/keyboard/muglerpc/key_release", |
| 121 |
"##### Keyboard: keyPressed [%03x/%02x] ", |
| 122 |
keysym, keycode)); |
| 123 |
|
| 124 |
for (int a = 0;a < MAX_KEYS;a++) |
| 125 |
if (_keybuf[a].code != -1) |
| 126 |
DBG(2, form("KCemu/keyboard/muglerpc/key_press", |
| 127 |
" {%02d:%02x:%02x}", a, _keybuf[a].sym, _keybuf[a].code)); |
| 128 |
|
| 129 |
DBG(2, form("KCemu/keyboard/muglerpc/key_release", |
| 130 |
"\n")); |
| 131 |
} |
| 132 |
|
| 133 |
void |
| 134 |
KeyboardMuglerPC::replayString(const char *text) |
| 135 |
{ |
| 136 |
} |
| 137 |
|
| 138 |
void |
| 139 |
KeyboardMuglerPC::callback(void *data) |
| 140 |
{ |
| 141 |
} |
| 142 |
|
| 143 |
int |
| 144 |
KeyboardMuglerPC::callback_A_in(void) |
| 145 |
{ |
| 146 |
for (int a = 0;a < MAX_KEYS;a++) |
| 147 |
{ |
| 148 |
if (_keybuf[a].code == -1) |
| 149 |
continue; |
| 150 |
|
| 151 |
if (_keybuf[a].sym == KC_KEY_SHIFT) |
| 152 |
continue; |
| 153 |
|
| 154 |
if (_keybuf[a].sym == KC_KEY_CONTROL) |
| 155 |
continue; |
| 156 |
|
| 157 |
return _keybuf[a].sym | 0x80; |
| 158 |
} |
| 159 |
|
| 160 |
return 0; |
| 161 |
} |
| 162 |
|
| 163 |
void |
| 164 |
KeyboardMuglerPC::callback_A_out(byte_t val) |
| 165 |
{ |
| 166 |
} |
| 167 |
|
| 168 |
int |
| 169 |
KeyboardMuglerPC::callback_B_in(void) |
| 170 |
{ |
| 171 |
return -1; |
| 172 |
} |
| 173 |
|
| 174 |
void |
| 175 |
KeyboardMuglerPC::callback_B_out(byte_t val) |
| 176 |
{ |
| 177 |
} |
| 178 |
|
| 179 |
void |
| 180 |
KeyboardMuglerPC::reset(bool power_on) |
| 181 |
{ |
| 182 |
init(); |
| 183 |
} |
| 184 |
|
| 185 |
void |
| 186 |
KeyboardMuglerPC::reti(void) |
| 187 |
{ |
| 188 |
} |