Cleanups for the XT Keyboard code

This commit is contained in:
Jasmine Iwanek
2022-01-11 00:53:17 -05:00
parent 36695f0487
commit a5deb55969

View File

@@ -55,6 +55,17 @@
#define STAT_IFULL 0x02 #define STAT_IFULL 0x02
#define STAT_OFULL 0x01 #define STAT_OFULL 0x01
// Keyboard Types
#define KBD_TYPE_PC81 0
#define KBD_TYPE_PC82 1
#define KBD_TYPE_XT82 2
#define KBD_TYPE_XT86 3
#define KBD_TYPE_COMPAQ 4
#define KBD_TYPE_TANDY 5
#define KBD_TYPE_TOSHIBA 6
#define KBD_TYPE_VTECH 7
#define KBD_TYPE_OLIVETTI 8
#define KBD_TYPE_ZENITH 9
typedef struct { typedef struct {
int want_irq; int want_irq;
@@ -370,7 +381,6 @@ get_fdd_switch_settings(){
return 0x00; return 0x00;
else else
return ((fdd_count - 1) << 6) | 0x01; return ((fdd_count - 1) << 6) | 0x01;
} }
static uint8_t static uint8_t
@@ -382,7 +392,6 @@ get_videomode_switch_settings(){
return 0x20; /* 0x10 would be 40x25 */ return 0x20; /* 0x10 would be 40x25 */
else else
return 0x00; return 0x00;
} }
static void static void
@@ -392,7 +401,7 @@ kbd_poll(void *priv)
timer_advance_u64(&kbd->send_delay_timer, 1000 * TIMER_USEC); timer_advance_u64(&kbd->send_delay_timer, 1000 * TIMER_USEC);
if (!(kbd->pb & 0x40) && (kbd->type != 5)) if (!(kbd->pb & 0x40) && (kbd->type != KBD_TYPE_TANDY))
return; return;
if (kbd->want_irq) { if (kbd->want_irq) {
@@ -504,7 +513,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
xtkbd_t *kbd = (xtkbd_t *)priv; xtkbd_t *kbd = (xtkbd_t *)priv;
switch (port) { switch (port) {
case 0x61: case 0x61: /* Keyboard Control Register (aka Port B) */
if (!(kbd->pb & 0x40) && (val & 0x40)) { if (!(kbd->pb & 0x40) && (val & 0x40)) {
key_queue_start = key_queue_end = 0; key_queue_start = key_queue_end = 0;
kbd->want_irq = 0; kbd->want_irq = 0;
@@ -516,7 +525,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
timer_process(); timer_process();
if ((kbd->type <= 1) && (cassette != NULL)) if (((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82)) && (cassette != NULL))
pc_cas_set_motor(cassette, (kbd->pb & 0x08) == 0); pc_cas_set_motor(cassette, (kbd->pb & 0x08) == 0);
speaker_update(); speaker_update();
@@ -535,13 +544,13 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
} }
#ifdef ENABLE_KEYBOARD_XT_LOG #ifdef ENABLE_KEYBOARD_XT_LOG
if (kbd->type <= 1) if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82))
kbd_log("Cassette motor is %s\n", !(val & 0x08) ? "ON" : "OFF"); kbd_log("Cassette motor is %s\n", !(val & 0x08) ? "ON" : "OFF");
#endif #endif
break; break;
#ifdef ENABLE_KEYBOARD_XT_LOG #ifdef ENABLE_KEYBOARD_XT_LOG
case 0x62: case 0x62: /* Switch Register (aka Port C) */
if (kbd->type <= 1) if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82))
kbd_log("Cassette IN is %i\n", !!(val & 0x10)); kbd_log("Cassette IN is %i\n", !!(val & 0x10));
break; break;
#endif #endif
@@ -555,15 +564,14 @@ kbd_read(uint16_t port, void *priv)
xtkbd_t *kbd = (xtkbd_t *)priv; xtkbd_t *kbd = (xtkbd_t *)priv;
uint8_t ret = 0xff; uint8_t ret = 0xff;
switch (port) { switch (port) {
case 0x60: case 0x60: /* Keyboard Data Register (aka Port A) */
if ((kbd->pb & 0x80) && ((kbd->type <= 3) || (kbd->type == 9))) { if ((kbd->pb & 0x80) && ((kbd->type <= KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_ZENITH))) {
if (kbd->type <= 1) if (kbd->type <= KBD_TYPE_PC82)
ret = (kbd->pd & ~0x02) | (hasfpu ? 0x02 : 0x00); ret = (kbd->pd & ~0x02) | (hasfpu ? 0x02 : 0x00);
else if ((kbd->type == 2) || (kbd->type == 3)) else if ((kbd->type == KBD_TYPE_XT82) || (kbd->type == KBD_TYPE_XT86))
ret = 0xff; /* According to Ruud on the PCem forum, this is supposed to return 0xFF on the XT. */ ret = 0xff; /* According to Ruud on the PCem forum, this is supposed to return 0xFF on the XT. */
else if (kbd->type == 9) { else if (kbd->type == KBD_TYPE_ZENITH) {
/* Zenith Data Systems Z-151 /* Zenith Data Systems Z-151
* SW1 switch settings: * SW1 switch settings:
* bits 6-7: floppy drive number * bits 6-7: floppy drive number
@@ -586,32 +594,32 @@ kbd_read(uint16_t port, void *priv)
ret = kbd->pa; ret = kbd->pa;
break; break;
case 0x61: case 0x61: /* Keyboard Control Register (aka Port B) */
ret = kbd->pb; ret = kbd->pb;
break; break;
case 0x62: case 0x62: /* Switch Register (aka Port C) */
if (kbd->type == 0) if (kbd->type == KBD_TYPE_PC81)
ret = 0x00; ret = 0x00;
else if (kbd->type == 1) { else if (kbd->type == KBD_TYPE_PC82) {
if (kbd->pb & 0x04) if (kbd->pb & 0x04) /* PB2 */
ret = ((mem_size - 64) / 32) & 0x0f; ret = ((mem_size - 64) / 32) & 0x0f;
else else
ret = ((mem_size - 64) / 32) >> 4; ret = ((mem_size - 64) / 32) >> 4;
} else if (kbd->type == 8 || kbd->type == 9) { } else if (kbd->type == KBD_TYPE_OLIVETTI || kbd->type == KBD_TYPE_ZENITH) {
/* Olivetti M19 or Zenith Data Systems Z-151 */ /* Olivetti M19 or Zenith Data Systems Z-151 */
if (kbd->pb & 0x04) if (kbd->pb & 0x04) /* PB2 */
ret = kbd->pd & 0xbf; ret = kbd->pd & 0xbf;
else else
ret = kbd->pd >> 4; ret = kbd->pd >> 4;
} else { } else {
if (kbd->pb & 0x08) if (kbd->pb & 0x08) /* PB3 */
ret = kbd->pd >> 4; ret = kbd->pd >> 4;
else { else {
/* LaserXT = Always 512k RAM; /* LaserXT = Always 512k RAM;
LaserXT/3 = Bit 0: set = 512k, clear = 256k. */ LaserXT/3 = Bit 0: set = 512k, clear = 256k. */
#if defined(DEV_BRANCH) && defined(USE_LASERXT) #if defined(DEV_BRANCH) && defined(USE_LASERXT)
if (kbd->type == 6) if (kbd->type == KBD_TYPE_TOSHIBA)
ret = ((mem_size == 512) ? 0x0d : 0x0c) | (hasfpu ? 0x02 : 0x00); ret = ((mem_size == 512) ? 0x0d : 0x0c) | (hasfpu ? 0x02 : 0x00);
else else
#endif #endif
@@ -622,19 +630,20 @@ kbd_read(uint16_t port, void *priv)
/* This is needed to avoid error 131 (cassette error). /* This is needed to avoid error 131 (cassette error).
This is serial read: bit 5 = clock, bit 4 = data, cassette header is 256 x 0xff. */ This is serial read: bit 5 = clock, bit 4 = data, cassette header is 256 x 0xff. */
if (kbd->type <= 1) { if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82)) {
if (cassette == NULL) if (cassette == NULL)
ret |= (ppispeakon ? 0x10 : 0); ret |= (ppispeakon ? 0x10 : 0);
else else
ret |= (pc_cas_get_inp(cassette) ? 0x10 : 0); ret |= (pc_cas_get_inp(cassette) ? 0x10 : 0);
} }
if (kbd->type == 5) if (kbd->type == KBD_TYPE_TANDY)
ret |= (tandy1k_eeprom_read() ? 0x10 : 0); ret |= (tandy1k_eeprom_read() ? 0x10 : 0);
break; break;
case 0x63: case 0x63: /* Keyboard Configuration Register (aka Port D) */
if ((kbd->type == 2) || (kbd->type == 3) || (kbd->type == 4) || (kbd->type == 6)) if ((kbd->type == KBD_TYPE_XT82) || (kbd->type == KBD_TYPE_XT86)
|| (kbd->type == KBD_TYPE_COMPAQ) || (kbd->type == KBD_TYPE_TOSHIBA))
ret = kbd->pd; ret = kbd->pd;
break; break;
} }
@@ -685,9 +694,10 @@ kbd_init(const device_t *info)
video_reset(gfxcard); video_reset(gfxcard);
if ((kbd->type <= 3) || (kbd->type == 4) || (kbd->type == 6) || (kbd->type == 8)) { if ((kbd->type <= KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_COMPAQ)
|| (kbd->type == KBD_TYPE_TOSHIBA) || (kbd->type == KBD_TYPE_OLIVETTI)) {
/* DIP switch readout: bit set = OFF, clear = ON. */ /* DIP switch readout: bit set = OFF, clear = ON. */
if (kbd->type == 8) if (kbd->type == KBD_TYPE_OLIVETTI)
/* Olivetti M19 /* Olivetti M19
* Jumpers J1, J2 - monitor type. * Jumpers J1, J2 - monitor type.
* 01 - mono (high-res) * 01 - mono (high-res)
@@ -699,10 +709,12 @@ kbd_init(const device_t *info)
/* Switches 7, 8 - floppy drives. */ /* Switches 7, 8 - floppy drives. */
kbd->pd = get_fdd_switch_settings(); kbd->pd = get_fdd_switch_settings();
/* Siitches 5, 6 - video card type */
kbd->pd |= get_videomode_switch_settings(); kbd->pd |= get_videomode_switch_settings();
/* Switches 3, 4 - memory size. */ /* Switches 3, 4 - memory size. */
if ((kbd->type == 3) || (kbd->type == 4) || (kbd->type == 6)) { if ((kbd->type == KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_COMPAQ)
|| (kbd->type == KBD_TYPE_TOSHIBA)) {
switch (mem_size) { switch (mem_size) {
case 256: case 256:
kbd->pd |= 0x00; kbd->pd |= 0x00;
@@ -718,34 +730,49 @@ kbd_init(const device_t *info)
kbd->pd |= 0x0c; kbd->pd |= 0x0c;
break; break;
} }
} else if (kbd->type >= 1) { } else if (kbd->type == KBD_TYPE_XT82) {
switch (mem_size) { switch (mem_size) {
case 64: case 64: /* 1x64k */
kbd->pd |= 0x00; kbd->pd |= 0x00;
break; break;
case 128: case 128: /* 2x64k */
kbd->pd |= 0x04; kbd->pd |= 0x04;
break; break;
case 192: case 192: /* 3x64k */
kbd->pd |= 0x08; kbd->pd |= 0x08;
break; break;
case 256: case 256: /* 4x64k */
default: default:
kbd->pd |= 0x0c; kbd->pd |= 0x0c;
break; break;
} }
} else { } else if (kbd->type == KBD_TYPE_PC82) {
switch (mem_size) { switch (mem_size) {
case 16: case 192: /* 3x64k, not supported by stock BIOS due to bugs */
kbd->pd |= 0x00;
break;
case 32:
kbd->pd |= 0x04;
break;
case 48:
kbd->pd |= 0x08; kbd->pd |= 0x08;
break; break;
case 64: case 64: /* 4x16k */
case 96: /* 2x32k + 2x16k */
case 128: /* 4x32k */
case 160: /* 2x64k + 2x16k */
case 224: /* 3x64k + 1x32k */
case 256: /* 4x64k */
default:
kbd->pd |= 0x0c;
break;
}
} else { /* really just the PC '81 */
switch (mem_size) {
case 16: /* 1x16k */
kbd->pd |= 0x00;
break;
case 32: /* 2x16k */
kbd->pd |= 0x04;
break;
case 48: /* 3x16k */
kbd->pd |= 0x08;
break;
case 64: /* 4x16k */
default: default:
kbd->pd |= 0x0c; kbd->pd |= 0x0c;
break; break;
@@ -755,7 +782,7 @@ kbd_init(const device_t *info)
/* Switch 2 - 8087 FPU. */ /* Switch 2 - 8087 FPU. */
if (hasfpu) if (hasfpu)
kbd->pd |= 0x02; kbd->pd |= 0x02;
} else if (kbd-> type == 9) { } else if (kbd-> type == KBD_TYPE_ZENITH) {
/* Zenith Data Systems Z-151 /* Zenith Data Systems Z-151
* SW2 switch settings: * SW2 switch settings:
* bit 7: monitor frequency * bit 7: monitor frequency
@@ -799,8 +826,8 @@ kbd_init(const device_t *info)
keyboard_set_table(scancode_xt); keyboard_set_table(scancode_xt);
is_tandy = (kbd->type == 5); is_tandy = (kbd->type == KBD_TYPE_TANDY);
is_t1x00 = (kbd->type == 6); is_t1x00 = (kbd->type == KBD_TYPE_TOSHIBA);
is_amstrad = 0; is_amstrad = 0;
@@ -831,7 +858,7 @@ kbd_close(void *priv)
const device_t keyboard_pc_device = { const device_t keyboard_pc_device = {
"IBM PC Keyboard (1981)", "IBM PC Keyboard (1981)",
0, 0,
0, KBD_TYPE_PC81,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -841,7 +868,7 @@ const device_t keyboard_pc_device = {
const device_t keyboard_pc82_device = { const device_t keyboard_pc82_device = {
"IBM PC Keyboard (1982)", "IBM PC Keyboard (1982)",
0, 0,
1, KBD_TYPE_PC82,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -851,7 +878,7 @@ const device_t keyboard_pc82_device = {
const device_t keyboard_xt_device = { const device_t keyboard_xt_device = {
"XT (1982) Keyboard", "XT (1982) Keyboard",
0, 0,
2, KBD_TYPE_XT82,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -861,7 +888,7 @@ const device_t keyboard_xt_device = {
const device_t keyboard_xt86_device = { const device_t keyboard_xt86_device = {
"XT (1986) Keyboard", "XT (1986) Keyboard",
0, 0,
3, KBD_TYPE_XT86,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -871,7 +898,7 @@ const device_t keyboard_xt86_device = {
const device_t keyboard_xt_compaq_device = { const device_t keyboard_xt_compaq_device = {
"Compaq Portable Keyboard", "Compaq Portable Keyboard",
0, 0,
4, KBD_TYPE_COMPAQ,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -881,7 +908,7 @@ const device_t keyboard_xt_compaq_device = {
const device_t keyboard_tandy_device = { const device_t keyboard_tandy_device = {
"Tandy 1000 Keyboard", "Tandy 1000 Keyboard",
0, 0,
5, KBD_TYPE_TANDY,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -891,7 +918,7 @@ const device_t keyboard_tandy_device = {
const device_t keyboard_xt_t1x00_device = { const device_t keyboard_xt_t1x00_device = {
"Toshiba T1x00 Keyboard", "Toshiba T1x00 Keyboard",
0, 0,
6, KBD_TYPE_TOSHIBA,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -902,7 +929,7 @@ const device_t keyboard_xt_t1x00_device = {
const device_t keyboard_xt_lxt3_device = { const device_t keyboard_xt_lxt3_device = {
"VTech Laser XT3 Keyboard", "VTech Laser XT3 Keyboard",
0, 0,
7, KBD_TYPE_VTECH,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -913,7 +940,7 @@ const device_t keyboard_xt_lxt3_device = {
const device_t keyboard_xt_olivetti_device = { const device_t keyboard_xt_olivetti_device = {
"Olivetti XT Keyboard", "Olivetti XT Keyboard",
0, 0,
8, KBD_TYPE_OLIVETTI,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,
@@ -923,7 +950,7 @@ const device_t keyboard_xt_olivetti_device = {
const device_t keyboard_xt_zenith_device = { const device_t keyboard_xt_zenith_device = {
"Zenith XT Keyboard", "Zenith XT Keyboard",
0, 0,
9, KBD_TYPE_ZENITH,
kbd_init, kbd_init,
kbd_close, kbd_close,
kbd_reset, kbd_reset,