Some clean-ups.

This commit is contained in:
OBattler
2023-04-20 14:28:37 +02:00
parent 333e9377ff
commit 0458034cbf
3 changed files with 50 additions and 78 deletions

View File

@@ -69,6 +69,8 @@ uint8_t keyboard_mode = 0x02;
static atkbc_dev_t *SavedKbd = NULL;
static uint8_t inv_cmd_response = 0xfa;
static const scancode scancode_set1[512] = {
// clang-format off
{ { 0},{ 0} }, { { 0x01,0},{ 0x81,0} }, { { 0x02,0},{ 0x82,0} }, { { 0x03,0},{ 0x83,0} }, /*000*/
@@ -685,7 +687,6 @@ static void
keyboard_at_set_defaults(atkbc_dev_t *dev)
{
dev->rate = 1;
dev->flags &= FLAG_ENABLED;
keyboard_set3_all_break = 0;
keyboard_set3_all_repeat = 0;
@@ -703,7 +704,6 @@ keyboard_at_bat(void *priv)
keyboard_at_set_defaults(dev);
keyboard_scan = 1;
dev->flags |= FLAG_ENABLED;
kbc_at_dev_queue_add(dev, 0xaa, 0);
}
@@ -711,18 +711,10 @@ keyboard_at_bat(void *priv)
static void
keyboard_at_invalid_cmd(atkbc_dev_t *dev)
{
/* The AT firmware sends FA on unknown but semantically valid (ie. >= 0xED) commands. */
keyboard_at_log("%s: Invalid AT command [%02X]\n", dev->name, dev->port->dat);
kbc_at_dev_queue_add(dev, 0xfa, 0);
keyboard_at_log("%s: Invalid command [%02X]\n", dev->name, dev->port->dat);
kbc_at_dev_queue_add(dev, inv_cmd_response, 0);
}
static void
keyboard_ps2_invalid_cmd(atkbc_dev_t *dev)
{
/* Send FE on unknown/invalid command per the PS/2 technical reference. */
keyboard_at_log("%s: Invalid PS/2 command [%02X]\n", dev->name, dev->port->dat);
kbc_at_dev_queue_add(dev, 0xfe, 0);
}
static void
keyboard_at_write(void *priv)
@@ -748,20 +740,22 @@ keyboard_at_write(void *priv)
case 0xf0: /* Get/set scancode set */
kbc_at_dev_queue_add(dev, (val > 3) ? 0xfe : 0xfa, 0);
if (val == 0) {
keyboard_at_log("%s: Get scan code set [%02X]\n", dev->name, keyboard_mode);
kbc_at_dev_queue_add(dev, keyboard_mode, 0);
} else {
if (val <= 3) {
switch (val) {
case 0x00:
keyboard_at_log("%s: Get scan code set [%02X]\n", dev->name, keyboard_mode);
kbc_at_dev_queue_add(dev, keyboard_mode, 0);
break;
case 0x01 ... 0x03:
keyboard_mode = val;
keyboard_at_log("%s: Set scan code set [%02X]\n", dev->name, keyboard_mode);
keyboard_at_set_scancode_set();
} else {
break;
default:
/* Fatal so any instance of anything attempting to set scan code > 3 can be reported to us. */
fatal("%s: Scan code set [%02X] invalid, resend\n", dev->name, val);
dev->flags |= FLAG_CTRLDAT;
dev->state = DEV_STATE_MAIN_WANT_IN;
}
break;
}
break;
@@ -784,23 +778,14 @@ keyboard_at_write(void *priv)
}
} else {
if (dev->flags & FLAG_CTRLDAT) {
if (val == 0xfe) {
/* Special case - resend last scan code command during another command that wants
input - output as normal but do not cancel the command (so keep waiting for
input). */
keyboard_at_log("%s: resend last scan code during command [%02X]\n", dev->name, dev->command);
/* Special case - another command during another command that wants input - proceed
as normal but do not cancel the command (so keep waiting for input), unless the
command in progress is ED (Set/reset LEDs). */
if (val == 0xed) {
keyboard_scan = 1;
dev->flags &= ~FLAG_CTRLDAT;
} else
dev->state = DEV_STATE_MAIN_WANT_IN;
kbc_at_dev_queue_add(dev, 0xfa, dev->last_scan_code);
} else {
/* Special case - another command during another command that wants input - proceed
as normal but do not cancel the command (so keep waiting for input), unless the
command in progress is ED (Set/reset LEDs). */
if (dev->command == 0xed) {
keyboard_scan = 1;
dev->flags &= ~FLAG_CTRLDAT;
} else
dev->state = DEV_STATE_MAIN_WANT_IN;
}
}
dev->command = val;
@@ -820,10 +805,8 @@ keyboard_at_write(void *priv)
case 0xef: /* Invalid command */
case 0xf1: /* Invalid command */
if (dev->type & FLAG_PS2)
keyboard_ps2_invalid_cmd(dev);
else
keyboard_at_invalid_cmd(dev);
keyboard_at_log("%s: Invalid command [%02X]\n", dev->name, dev->port->dat);
kbc_at_dev_queue_add(dev, inv_cmd_response, 0);
break;
case 0xf0: /* get/set scan code set */
@@ -858,7 +841,6 @@ keyboard_at_write(void *priv)
case 0xf4: /* enable */
keyboard_at_log("%s: enable keyboard\n", dev->name);
dev->flags |= FLAG_ENABLED;
keyboard_scan = 1;
kbc_at_dev_queue_add(dev, 0xfa, 0);
break;
@@ -866,7 +848,7 @@ keyboard_at_write(void *priv)
case 0xf5: /* set defaults and disable keyboard */
case 0xf6: /* set defaults */
keyboard_at_log("%s: set defaults%s\n", (val == 0xf6) ? "" : " and disable keyboard");
keyboard_scan = (val == 0xf6);
keyboard_scan = !(val & 0x01);
keyboard_at_log("%s: val = %02X, keyboard_scan = %i\n",
dev->name, val, keyboard_scan);
kbc_at_dev_queue_add(dev, 0xfa, 0);
@@ -918,33 +900,24 @@ keyboard_at_write(void *priv)
/* TODO: Actually implement these commands. */
case 0xfb: /* set some keys to repeat */
if (dev->type & FLAG_PS2) {
keyboard_at_log("%s: set some keys to repeat\n", dev->name);
kbc_at_dev_queue_add(dev, 0xfe, 0);
} else
keyboard_at_invalid_cmd(dev);
keyboard_at_log("%s: set some keys to repeat\n", dev->name);
kbc_at_dev_queue_add(dev, inv_cmd_response, 0);
break;
case 0xfc: /* set some keys to give make/break codes */
if (dev->type & FLAG_PS2) {
keyboard_at_log("%s: set some keys to give make/break codes\n", dev->name);
kbc_at_dev_queue_add(dev, 0xfe, 0);
} else
keyboard_at_invalid_cmd(dev);
keyboard_at_log("%s: set some keys to give make/break codes\n", dev->name);
kbc_at_dev_queue_add(dev, inv_cmd_response, 0);
break;
case 0xfd: /* set some keys to give make codes only */
if (dev->type & FLAG_PS2) {
keyboard_at_log("%s: set some keys to give make codes only\n", dev->name);
kbc_at_dev_queue_add(dev, 0xfe, 0);
} else
keyboard_at_invalid_cmd(dev);
keyboard_at_log("%s: set some keys to give make codes only\n", dev->name);
kbc_at_dev_queue_add(dev, inv_cmd_response, 0);
break;
/* TODO: This is supposed to resend multiple bytes after some commands. */
case 0xfe: /* resend last scan code */
keyboard_at_log("%s: resend last scan code\n", dev->name);
kbc_at_dev_queue_add(dev, 0xfa, dev->last_scan_code);
kbc_at_dev_queue_add(dev, dev->last_scan_code, 0);
break;
case 0xff: /* reset */
@@ -992,6 +965,8 @@ keyboard_at_init(const device_t *info)
keyboard_send = add_data_kbd;
SavedKbd = dev;
inv_cmd_response = (dev->type & FLAG_PS2) ? 0xfe : 0xfa;
/* Return our private data to the I/O layer. */
return (dev);
}

View File

@@ -134,7 +134,7 @@ ps2_set_defaults(atkbc_dev_t *dev)
{
dev->mode = MODE_STREAM;
dev->rate = 1;
dev->flags &= (0x88 | FLAG_ENABLED);
dev->flags &= 0x88;
}
static void
@@ -145,7 +145,6 @@ ps2_bat(void *priv)
ps2_set_defaults(dev);
mouse_scan = 1;
dev->flags |= FLAG_ENABLED;
kbc_at_dev_queue_add(dev, 0xaa, 0);
kbc_at_dev_queue_add(dev, 0x00, 0);
@@ -156,6 +155,7 @@ ps2_write(void *priv)
{
atkbc_dev_t *dev = (atkbc_dev_t *) priv;
uint8_t temp, val;
static uint8_t last_data[6] = { 0x00 };
if (dev->port == NULL)
return;
@@ -211,7 +211,9 @@ ps2_write(void *priv)
case 0xe9: /* status request */
mouse_ps2_log("%s: Status request\n", dev->name);
kbc_at_dev_queue_add(dev, 0xfa, 0);
temp = (dev->flags & 0x30);
temp = (dev->flags & 0x20);
if (mouse_scan)
temp |= FLAG_ENABLED;
if (mouse_buttons & 1)
temp |= 4;
if (mouse_buttons & 2)
@@ -255,14 +257,12 @@ ps2_write(void *priv)
case 0xf4: /* enable */
mouse_ps2_log("%s: Enable\n", dev->name);
dev->flags |= FLAG_ENABLED;
mouse_scan = 1;
kbc_at_dev_queue_add(dev, 0xfa, 0);
break;
case 0xf5: /* disable */
mouse_ps2_log("%s: Disable\n", dev->name);
dev->flags &= ~FLAG_ENABLED;
mouse_scan = 0;
kbc_at_dev_queue_add(dev, 0xfa, 0);
break;
@@ -285,19 +285,19 @@ ps2_write(void *priv)
if (dev->flags & FLAG_INTELLI) {
for (temp = 0; temp < 5; temp++)
dev->last_data[temp] = dev->last_data[temp + 1];
last_data[temp] = last_data[temp + 1];
dev->last_data[5] = val;
last_data[5] = val;
if ((dev->last_data[0] == 0xf3) && (dev->last_data[1] == 0xc8) &&
(dev->last_data[2] == 0xf3) && (dev->last_data[3] == 0x64) &&
(dev->last_data[4] == 0xf3) && (dev->last_data[5] == 0x50))
if ((last_data[0] == 0xf3) && (last_data[1] == 0xc8) &&
(last_data[2] == 0xf3) && (last_data[3] == 0x64) &&
(last_data[4] == 0xf3) && (last_data[5] == 0x50))
dev->flags |= FLAG_INTMODE;
if ((dev->flags & FLAG_EXPLORER) && (dev->flags & FLAG_INTMODE) &&
(dev->last_data[0] == 0xf3) && (dev->last_data[1] == 0xc8) &&
(dev->last_data[2] == 0xf3) && (dev->last_data[3] == 0xc8) &&
(dev->last_data[4] == 0xf3) && (dev->last_data[5] == 0x50))
(last_data[0] == 0xf3) && (last_data[1] == 0xc8) &&
(last_data[2] == 0xf3) && (last_data[3] == 0xc8) &&
(last_data[4] == 0xf3) && (last_data[5] == 0x50))
dev->flags |= FLAG_5BTN;
}
}

View File

@@ -38,9 +38,9 @@ enum {
/* Used by the AT / PS/2 keyboard controller, common device, keyboard, and mouse. */
typedef struct {
uint8_t wantcmd, dat, pad, pad0;
uint8_t wantcmd, dat;
int out_new;
int16_t out_new;
void *priv;
@@ -51,12 +51,9 @@ typedef struct {
typedef struct {
const char *name; /* name of this device */
uint8_t type, inst, command, wantdata,
last_scan_code, state, resolution, rate,
cmd_queue_start, cmd_queue_end, queue_start, queue_end;
/* 6 bytes needed for mouse */
uint8_t last_data[6];
uint8_t type, command, last_scan_code, state,
resolution, rate, cmd_queue_start, cmd_queue_end,
queue_start, queue_end;
uint16_t flags;