Temporarily removed scan code set 1 support from the AT keyboard, fixes the keyboard in TSX.

This commit is contained in:
OBattler
2018-08-20 04:03:48 +02:00
parent a0b29ce138
commit 02a2224939

View File

@@ -8,7 +8,7 @@
* *
* Intel 8042 (AT keyboard controller) emulation. * Intel 8042 (AT keyboard controller) emulation.
* *
* Version: @(#)keyboard_at.c 1.0.36 2018/05/12 * Version: @(#)keyboard_at.c 1.0.37 2018/08/20
* *
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/> * Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -130,6 +130,7 @@ uint8_t keyboard_set3_all_repeat;
uint8_t keyboard_set3_all_break; uint8_t keyboard_set3_all_break;
/* Bits 0 - 1 = scan code set, bit 6 = translate or not. */ /* Bits 0 - 1 = scan code set, bit 6 = translate or not. */
/* Q */
uint8_t keyboard_mode = 0x42; uint8_t keyboard_mode = 0x42;
int mouse_queue_start = 0, int mouse_queue_start = 0,
@@ -185,6 +186,7 @@ static const uint8_t nont_to_t[256] = {
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
}; };
#if 0
static const scancode scancode_set1[512] = { static const scancode scancode_set1[512] = {
{ { -1},{ -1} }, { { 0x01,-1},{ 0x81,-1} }, { { 0x02,-1},{ 0x82,-1} }, { { 0x03,-1},{ 0x83,-1} }, /*000*/ { { -1},{ -1} }, { { 0x01,-1},{ 0x81,-1} }, { { 0x02,-1},{ 0x82,-1} }, { { 0x03,-1},{ 0x83,-1} }, /*000*/
{ { 0x04,-1},{ 0x84,-1} }, { { 0x05,-1},{ 0x85,-1} }, { { 0x06,-1},{ 0x86,-1} }, { { 0x07,-1},{ 0x87,-1} }, /*004*/ { { 0x04,-1},{ 0x84,-1} }, { { 0x05,-1},{ 0x85,-1} }, { { 0x06,-1},{ 0x86,-1} }, { { 0x07,-1},{ 0x87,-1} }, /*004*/
@@ -314,6 +316,7 @@ static const scancode scancode_set1[512] = {
{ { -1},{ -1} }, { { -1},{ -1} }, { { -1},{ -1} }, { { -1},{ -1} }, /*1f8*/ { { -1},{ -1} }, { { -1},{ -1} }, { { -1},{ -1} }, { { -1},{ -1} }, /*1f8*/
{ { -1},{ -1} }, { { -1},{ -1} }, { {0xe0,0xfe,-1},{ -1} }, { {0xe0,0xff,-1},{ -1} } /*1fc*/ { { -1},{ -1} }, { { -1},{ -1} }, { {0xe0,0xfe,-1},{ -1} }, { {0xe0,0xff,-1},{ -1} } /*1fc*/
}; };
#endif
static const scancode scancode_set2[512] = { static const scancode scancode_set2[512] = {
{ { -1},{ -1} }, { { 0x76,-1},{ 0xF0,0x76,-1} }, { { 0x16,-1},{ 0xF0,0x16,-1} }, { { 0x1E,-1},{ 0xF0,0x1E,-1} }, /*000*/ { { -1},{ -1} }, { { 0x76,-1},{ 0xF0,0x76,-1} }, { { 0x16,-1},{ 0xF0,0x16,-1} }, { { 0x1E,-1},{ 0xF0,0x1E,-1} }, /*000*/
@@ -575,6 +578,13 @@ static const scancode scancode_set3[512] = {
{ { -1},{ -1} }, { { -1},{ -1} }, { {0xe0,0xfe,-1},{0xe0,0xF0,0xFE,-1} }, { {0xe0,0xff,-1},{0xe0,0xF0,0xFF,-1} } /*1fc*/ { { -1},{ -1} }, { { -1},{ -1} }, { {0xe0,0xfe,-1},{0xe0,0xF0,0xFE,-1} }, { {0xe0,0xff,-1},{0xe0,0xF0,0xFF,-1} } /*1fc*/
}; };
#ifdef ENABLE_KEYBOARD_AT_LOG
#define ENABLE_KEYBOARD_LOG
int keyboard_at_do_log = ENABLE_KEYBOARD_AT_LOG;
#endif
static void static void
kbd_log(const char *fmt, ...) kbd_log(const char *fmt, ...)
{ {
@@ -593,6 +603,7 @@ static void
kbd_setmap(atkbd_t *kbd) kbd_setmap(atkbd_t *kbd)
{ {
switch (keyboard_mode & 3) { switch (keyboard_mode & 3) {
#if 0
case 1: case 1:
default: default:
keyboard_set_table(scancode_set1); keyboard_set_table(scancode_set1);
@@ -601,14 +612,19 @@ kbd_setmap(atkbd_t *kbd)
case 2: case 2:
keyboard_set_table(scancode_set2); keyboard_set_table(scancode_set2);
break; break;
#else
case 2:
default:
keyboard_set_table(scancode_set2);
break;
#endif
case 3: case 3:
keyboard_set_table(scancode_set3); keyboard_set_table(scancode_set3);
break; break;
} }
if (keyboard_mode & 0x20) if (keyboard_mode & 0x20)
keyboard_set_table(scancode_set1); keyboard_set_table(scancode_set2);
} }
@@ -685,11 +701,19 @@ kbd_adddata(uint8_t val)
static void static void
kbd_adddata_vals(uint8_t *val, uint8_t len) kbd_adddata_vals(uint8_t *val, uint8_t len)
{ {
int translate = (keyboard_mode & 0x40) && !(keyboard_mode & 0x20); int xt_mode = (keyboard_mode & 0x20) && ((CurrentKbd->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_1);
int translate = (keyboard_mode & 0x40);
int i; int i;
uint8_t or = 0; uint8_t or = 0;
uint8_t send; uint8_t send;
#if 0
translate = translate || (keyboard_mode & 0x40) && !xt_mode;
#else
translate = translate || (keyboard_mode & 0x40) || xt_mode;
translate = translate || ((CurrentKbd->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2);
#endif
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (translate) { if (translate) {
if (val[i] == 0xf0) { if (val[i] == 0xf0) {
@@ -727,11 +751,18 @@ kbd_adddata_vals(uint8_t *val, uint8_t len)
static void static void
kbd_adddata_keyboard(uint16_t val) kbd_adddata_keyboard(uint16_t val)
{ {
int translate = (keyboard_mode & 0x40) && !(keyboard_mode & 0x20); int xt_mode = (keyboard_mode & 0x20) && ((CurrentKbd->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_1);
int translate = (keyboard_mode & 0x40);
uint8_t fake_shift[4]; uint8_t fake_shift[4];
uint8_t num_lock = 0, shift_states = 0; uint8_t num_lock = 0, shift_states = 0;
#if 0
translate = translate || (keyboard_mode & 0x40) && !xt_mode;
#else
translate = translate || (keyboard_mode & 0x40) || xt_mode;
translate = translate || ((CurrentKbd->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2);
#endif
keyboard_get_states(NULL, &num_lock, NULL); keyboard_get_states(NULL, &num_lock, NULL);
shift_states = keyboard_get_shift() & STATE_SHIFT_MASK; shift_states = keyboard_get_shift() & STATE_SHIFT_MASK;
@@ -1016,6 +1047,8 @@ kbd_cmd_write(atkbd_t *kbd, uint8_t val)
kbd_log("ATkbd: mouse interrupt is now %s\n", (val & 0x02) ? "enabled" : "disabled"); kbd_log("ATkbd: mouse interrupt is now %s\n", (val & 0x02) ? "enabled" : "disabled");
#endif #endif
} }
kbd_log("Command byte now: %02X (%02X)\n", kbd->mem[0], val);
} }
@@ -1699,18 +1732,22 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
kbd->key_wantdata = 0; kbd->key_wantdata = 0;
switch (kbd->key_command) { switch (kbd->key_command) {
case 0xed: /*Set/reset LEDs*/ case 0xed: /*Set/reset LEDs*/
if (val & 0xf8)
goto do_command; /* Command ED does command if command is recognized. */
kbd_adddata_keyboard(0xfa); kbd_adddata_keyboard(0xfa);
break; break;
case 0xf0: /*Get/set scancode set*/ case 0xf0: /*Get/set scancode set*/
kbd_adddata_keyboard(0xfa);
if (val == 0) { if (val == 0) {
kbd_log("Get scan code set: %02X\n", keyboard_mode & 3);
kbd_adddata_keyboard(keyboard_mode & 3); kbd_adddata_keyboard(keyboard_mode & 3);
} else { } else {
if (val <= 3) { if ((val <= 3) && (val != 1)) {
keyboard_mode &= 0xFC; keyboard_mode &= 0xFC;
keyboard_mode |= (val & 3); keyboard_mode |= (val & 3);
kbd_log("Scan code set now: %02X\n", val);
} }
kbd_adddata_keyboard(0xfa);
kbd_setmap(kbd); kbd_setmap(kbd);
} }
break; break;
@@ -1729,6 +1766,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
/* Keyboard command is now done. */ /* Keyboard command is now done. */
kbd->key_command = 0x00; kbd->key_command = 0x00;
} else { } else {
do_command:
/* No keyboard command in progress. */ /* No keyboard command in progress. */
kbd->key_command = 0x00; kbd->key_command = 0x00;
@@ -1794,8 +1832,8 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
kbd_log("ATkbd: read keyboard id\n"); kbd_log("ATkbd: read keyboard id\n");
#endif #endif
kbd_adddata_keyboard(0xfa); kbd_adddata_keyboard(0xfa);
kbd_adddata_keyboard(0xab); /* kbd_adddata_keyboard(0xab);
kbd_adddata_keyboard(0x83); kbd_adddata_keyboard(0x83); */
break; break;
case 0xf3: /*Set typematic rate/delay*/ case 0xf3: /*Set typematic rate/delay*/
@@ -1821,7 +1859,8 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
#endif #endif
kbd_adddata_keyboard(0xfa); kbd_adddata_keyboard(0xfa);
keyboard_scan = 0; keyboard_scan = 0;
break; /* Disabling the keyboard also resets it to the default values, so continue below. */
// break;
case 0xf6: /*Set defaults*/ case 0xf6: /*Set defaults*/
#ifdef ENABLE_KEYBOARD_LOG #ifdef ENABLE_KEYBOARD_LOG
@@ -1832,6 +1871,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
keyboard_set3_all_break = 0; keyboard_set3_all_break = 0;
keyboard_set3_all_repeat = 0; keyboard_set3_all_repeat = 0;
memset(keyboard_set3_flags, 0, 512); memset(keyboard_set3_flags, 0, 512);
/* Q */
keyboard_mode = (keyboard_mode & 0xFC) | 0x02; keyboard_mode = (keyboard_mode & 0xFC) | 0x02;
kbd_setmap(kbd); kbd_setmap(kbd);
break; break;
@@ -1883,9 +1923,9 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
key_queue_start = key_queue_end = 0; /*Clear key queue*/ key_queue_start = key_queue_end = 0; /*Clear key queue*/
kbd_adddata_keyboard(0xfa); kbd_adddata_keyboard(0xfa);
kbd_adddata_keyboard(0xaa); kbd_adddata_keyboard(0xaa);
/* Set system flag to 1 and scan code set to 2. */ /* Set scan code set to 2. */
keyboard_mode &= 0xFC; /* Q */
keyboard_mode |= 2; keyboard_mode = (keyboard_mode & 0xFC) | 0x02;
kbd_setmap(kbd); kbd_setmap(kbd);
break; break;
@@ -2162,6 +2202,7 @@ kbd_reset(void *priv)
kbd->secr_phase = 0; kbd->secr_phase = 0;
kbd->key_wantdata = 0; kbd->key_wantdata = 0;
/* Q */
keyboard_mode = 0x02 | kbd->dtrans; keyboard_mode = 0x02 | kbd->dtrans;
kbd_keyboard_set(kbd, 1); kbd_keyboard_set(kbd, 1);
@@ -2195,13 +2236,16 @@ kbd_init(const device_t *info)
timer_add(kbd_poll, &keyboard_delay, TIMER_ALWAYS_ENABLED, kbd); timer_add(kbd_poll, &keyboard_delay, TIMER_ALWAYS_ENABLED, kbd);
if ((kbd->flags & KBC_TYPE_MASK) != KBC_TYPE_ISA) { if ((kbd->flags & KBC_TYPE_MASK) != KBC_TYPE_ISA) {
#if 0
if ((kbd->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2) { if ((kbd->flags & KBC_TYPE_MASK) == KBC_TYPE_PS2_2) {
/* /*
* These machines force translation off, so the * These machines force translation off, so the
* the keyboard must start in scan code set 0. * the keyboard must start in scan code set 1.
*/ */
keyboard_mode &= ~0x03; keyboard_mode &= ~0x03;
keyboard_mode |= 0x01;
} }
#endif
timer_add(kbd_refresh, timer_add(kbd_refresh,
&kbd->refresh_time, TIMER_ALWAYS_ENABLED, kbd); &kbd->refresh_time, TIMER_ALWAYS_ENABLED, kbd);