Improved passing of scan codes to the emulated keyboards;

Fixed Sound Blaster 16 and earlier CD-ROM volume registers (and made them no longer default to 0);
Serial mouse now resets the FIFO before sending the ID, fixes mouse detection after clipping and moving the mouse;
Rewritten CD-ROM and SCSI disk Mode Select handling and changed things regarding Mode Sense as well, also fixes emulator segmentation faults when anything attempts to do a Mode Select;
Fixed the Microsoft InPort mouse emulation (used the Bochs code as reference for the polling/state update code), now it actually moves;
The PCjr initialization now sets the XT scan code table, makes the keyboard actually work on the PCjr again;
Several bugfixes regarding the Read CD commands, fixes CD Audio in digital mode on Windows ME;
Finally properly fixed the regular CD Audio MSF/LBA conversion mess;
Applied all applicable PCem commits.
This commit is contained in:
OBattler
2018-01-13 22:56:13 +01:00
parent b4aff71a6b
commit 845c8ed4bd
29 changed files with 2127 additions and 2358 deletions

View File

@@ -8,15 +8,15 @@
*
* Implementation of the XT-style keyboard.
*
* Version: @(#)keyboard_xt.c 1.0.4 2017/11/10
* Version: @(#)keyboard_xt.c 1.0.5 2018/01/09
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
*
* Copyright 2008-2017 Sarah Walker.
* Copyright 2016,2017 Miran Grca.
* Copyright 2017 Fred N. van kempen.
* Copyright 2008-2018 Sarah Walker.
* Copyright 2016,2018 Miran Grca.
* Copyright 2018 Fred N. van kempen.
*/
#include <stdio.h>
#include <stdint.h>
@@ -60,7 +60,7 @@ typedef struct {
/*XT keyboard has no escape scancodes, and no scancodes beyond 53*/
scancode scancode_xt[272] = {
scancode scancode_xt[512] = {
{ {-1}, {-1} }, { {0x01, -1}, {0x81, -1} },
{ {0x02, -1}, {0x82, -1} }, { {0x03, -1}, {0x83, -1} },
{ {0x04, -1}, {0x84, -1} }, { {0x05, -1}, {0x85, -1} },
@@ -104,91 +104,91 @@ scancode scancode_xt[272] = {
{ {0x50, -1}, {0xd0, -1} }, { {0x51, -1}, {0xd1, -1} },
{ {0x52, -1}, {0xd2, -1} }, { {0x53, -1}, {0xd3, -1} },
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*54*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*054*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*58*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*058*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*5c*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*05c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*60*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*060*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*64*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*064*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*68*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*068*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*6c*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*06c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*70*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*070*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*74*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*074*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*78*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*078*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*7c*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*07c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*80*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*080*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*84*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*084*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*88*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*088*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*8c*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*08c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*90*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*090*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*94*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*094*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*98*/
{ {0x1c, -1}, {0x9c, -1} }, { {0x1d, -1}, {0x9d, -1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*9c*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*098*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*a0*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*09c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*a4*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0a0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {0xaa, -1}, {0x2a, -1} }, { {-1}, {-1} }, /*a8*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0a4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*ac*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0a8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*b0*/
{ {-1}, {-1} }, { {0x35, -1}, {0xb5, -1} },
{ {0xb6, -1}, {0x36, -1} }, { {0x37, -1}, {0xb7, -1} }, /*b4*/
{ {0x38, -1}, {0xb8, -1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*b8*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0ac*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*bc*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0b0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*c0*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0b4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {0x46, -1}, {0xc6, -1} }, { {0x47, -1}, {0xc7, -1} }, /*c4*/
{ {0x48, -1}, {0xc8, -1} }, { {0x49, -1}, {0xc9, -1} },
{ {-1}, {-1} }, { {0x4b, -1}, {0xcb, -1} }, /*c8*/
{ {-1}, {-1} }, { {0x4d, -1}, {0xcd, -1} },
{ {-1}, {-1} }, { {0x4f, -1}, {0xcf, -1} }, /*cc*/
{ {0x50, -1}, {0xd0, -1} }, { {0x51, -1}, {0xd1, -1} },
{ {0x52, -1}, {0xd2, -1} }, { {0x53, -1}, {0xd3, -1} }, /*d0*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0b8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*d4*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0bc*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*d8*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0c0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*dc*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0c4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*e0*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0c8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*e4*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0cc*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*e8*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0d0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*ec*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0d4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*f0*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0d8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*f4*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0dc*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*f8*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0e0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*fc*/
{ {-1}, {-1} }, { {-1}, {-1} }, /*0e4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*0e8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*0ec*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*0f0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*0f4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*0f8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*0fc*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*100*/
{ {-1}, {-1} }, { {-1}, {-1} },
@@ -197,6 +197,126 @@ scancode scancode_xt[272] = {
{ {-1}, {-1} }, { {-1}, {-1} }, /*108*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*10c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*110*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*114*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*118*/
{ {0x1c, -1}, {0x9c, -1} }, { {0x1d, -1}, {0x9d, -1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*11c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*120*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*124*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*128*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*12c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*130*/
{ {-1}, {-1} }, { {0x35, -1}, {0xb5, -1} },
{ {-1}, {-1} }, { {0x37, -1}, {0xb7, -1} }, /*134*/
{ {0x38, -1}, {0xb8, -1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*138*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*13c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*140*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {0x46, -1}, {0xc6, -1} }, { {0x47, -1}, {0xc7, -1} }, /*144*/
{ {0x48, -1}, {0xc8, -1} }, { {0x49, -1}, {0xc9, -1} },
{ {-1}, {-1} }, { {0x4b, -1}, {0xcb, -1} }, /*148*/
{ {-1}, {-1} }, { {0x4d, -1}, {0xcd, -1} },
{ {-1}, {-1} }, { {0x4f, -1}, {0xcf, -1} }, /*14c*/
{ {0x50, -1}, {0xd0, -1} }, { {0x51, -1}, {0xd1, -1} },
{ {0x52, -1}, {0xd2, -1} }, { {0x53, -1}, {0xd3, -1} }, /*150*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*154*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*158*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*15c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*160*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*164*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*168*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*16c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*170*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*174*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*148*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*17c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*180*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*184*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*88*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*18c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*190*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*194*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*198*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*19c*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1a0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1a4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1a8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1ac*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1b0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1b4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1b8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1bc*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1c0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1c4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1c8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1cc*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1d0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1d4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1d8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1dc*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1e0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1e4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1e8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1ec*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1f0*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1f4*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} }, /*1f8*/
{ {-1}, {-1} }, { {-1}, {-1} },
{ {-1}, {-1} }, { {-1}, {-1} } /*1fc*/
};
@@ -226,7 +346,7 @@ kbd_poll(void *priv)
static void
kbd_adddata(uint8_t val)
kbd_adddata(uint16_t val)
{
key_queue[key_queue_end] = val;
#if ENABLE_KEYBOARD_LOG
@@ -237,6 +357,67 @@ kbd_adddata(uint8_t val)
}
void
kbd_adddata_process(uint16_t val, void (*adddata)(uint16_t val))
{
uint8_t num_lock = 0, shift_states = 0;
if (!adddata)
return;
keyboard_get_states(NULL, &num_lock, NULL);
shift_states = keyboard_get_shift() & STATE_SHIFT_MASK;
switch(val) {
case FAKE_LSHIFT_ON:
if (num_lock) {
if (!shift_states) {
/* Num lock on and no shifts are pressed, send non-inverted fake shift. */
adddata(0x2a);
}
} else {
if (shift_states & STATE_LSHIFT) {
/* Num lock off and left shift pressed. */
adddata(0xaa);
}
if (shift_states & STATE_RSHIFT) {
/* Num lock off and right shift pressed. */
adddata(0xb6);
}
}
break;
case FAKE_LSHIFT_OFF:
pclog("fake left shift on, scan code: ");
if (num_lock) {
if (!shift_states) {
/* Num lock on and no shifts are pressed, send non-inverted fake shift. */
adddata(0xaa);
}
} else {
if (shift_states & STATE_LSHIFT) {
/* Num lock off and left shift pressed. */
adddata(0x2a);
}
if (shift_states & STATE_RSHIFT) {
/* Num lock off and right shift pressed. */
adddata(0x36);
}
}
break;
default:
adddata(val);
break;
}
}
void
kbd_adddata_ex(uint16_t val)
{
kbd_adddata_process(val, kbd_adddata);
}
static void
kbd_write(uint16_t port, uint8_t val, void *priv)
{
@@ -359,7 +540,7 @@ kbd_init(device_t *info)
io_sethandler(0x0060, 4,
kbd_read, NULL, NULL, kbd_write, NULL, NULL, kbd);
keyboard_send = kbd_adddata;
keyboard_send = kbd_adddata_ex;
timer_add(kbd_poll, &keyboard_delay, TIMER_ALWAYS_ENABLED, kbd);
return(kbd);