2016-08-14 22:07:17 -04:00
|
|
|
/* Copyright holders: Sarah Walker
|
|
|
|
|
see COPYING for more details
|
|
|
|
|
*/
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdio.h>
|
2016-07-19 02:44:32 +02:00
|
|
|
#include <stdint.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <wchar.h>
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "ibm.h"
|
|
|
|
|
#include "io.h"
|
|
|
|
|
#include "mem.h"
|
2017-09-25 04:31:20 -04:00
|
|
|
#include "rom.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "pic.h"
|
2017-05-05 01:49:42 +02:00
|
|
|
#include "pit.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "timer.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
#include "device.h"
|
|
|
|
|
#include "tandy_eeprom.h"
|
2017-08-27 04:33:47 +01:00
|
|
|
#include "sound/sound.h"
|
|
|
|
|
#include "sound/snd_speaker.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "keyboard.h"
|
|
|
|
|
#include "keyboard_xt.h"
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
#define STAT_PARITY 0x80
|
|
|
|
|
#define STAT_RTIMEOUT 0x40
|
|
|
|
|
#define STAT_TTIMEOUT 0x20
|
|
|
|
|
#define STAT_LOCK 0x10
|
|
|
|
|
#define STAT_CD 0x08
|
|
|
|
|
#define STAT_SYSFLAG 0x04
|
|
|
|
|
#define STAT_IFULL 0x02
|
|
|
|
|
#define STAT_OFULL 0x01
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
int blocked;
|
|
|
|
|
|
|
|
|
|
uint8_t pa;
|
|
|
|
|
uint8_t pb;
|
|
|
|
|
|
|
|
|
|
int tandy;
|
|
|
|
|
} keyboard_xt;
|
|
|
|
|
|
|
|
|
|
static uint8_t key_queue[16];
|
|
|
|
|
static int key_queue_start = 0, key_queue_end = 0;
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
|
|
|
|
static void keyboard_xt_poll(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-10-09 01:48:36 +02:00
|
|
|
keybsenddelay += (1000LL * TIMER_USEC);
|
2016-06-26 00:34:39 +02:00
|
|
|
if (key_queue_start != key_queue_end && !keyboard_xt.blocked)
|
|
|
|
|
{
|
|
|
|
|
keyboard_xt.pa = key_queue[key_queue_start];
|
|
|
|
|
picint(2);
|
2017-09-28 20:10:15 -04:00
|
|
|
#if ENABLE_KEYBOARD_LOG
|
2016-06-26 00:34:39 +02:00
|
|
|
pclog("Reading %02X from the key queue at %i\n", keyboard_xt.pa, key_queue_start);
|
2017-09-28 20:10:15 -04:00
|
|
|
#endif
|
2016-06-26 00:34:39 +02:00
|
|
|
key_queue_start = (key_queue_start + 1) & 0xf;
|
|
|
|
|
keyboard_xt.blocked = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void keyboard_xt_adddata(uint8_t val)
|
|
|
|
|
{
|
|
|
|
|
key_queue[key_queue_end] = val;
|
2017-09-28 20:10:15 -04:00
|
|
|
#if ENABLE_KEYBOARD_LOG
|
2016-06-26 00:34:39 +02:00
|
|
|
pclog("keyboard_xt : %02X added to key queue at %i\n", val, key_queue_end);
|
2017-09-28 20:10:15 -04:00
|
|
|
#endif
|
2016-06-26 00:34:39 +02:00
|
|
|
key_queue_end = (key_queue_end + 1) & 0xf;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
static void keyboard_xt_write(uint16_t port, uint8_t val, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0x61:
|
|
|
|
|
if (!(keyboard_xt.pb & 0x40) && (val & 0x40)) /*Reset keyboard*/
|
|
|
|
|
{
|
2017-09-28 20:10:15 -04:00
|
|
|
#if ENABLE_KEYBOARD_LOG
|
2016-06-26 00:34:39 +02:00
|
|
|
pclog("keyboard_xt : reset keyboard\n");
|
2017-09-28 20:10:15 -04:00
|
|
|
#endif
|
2016-06-26 00:34:39 +02:00
|
|
|
key_queue_end = key_queue_start;
|
|
|
|
|
keyboard_xt_adddata(0xaa);
|
|
|
|
|
}
|
|
|
|
|
if ((keyboard_xt.pb & 0x80)==0 && (val & 0x80)!=0)
|
|
|
|
|
{
|
|
|
|
|
keyboard_xt.pa = 0;
|
|
|
|
|
keyboard_xt.blocked = 0;
|
|
|
|
|
picintc(2);
|
|
|
|
|
}
|
|
|
|
|
keyboard_xt.pb = val;
|
|
|
|
|
ppi.pb = val;
|
|
|
|
|
|
|
|
|
|
timer_process();
|
|
|
|
|
timer_update_outstanding();
|
|
|
|
|
|
|
|
|
|
speaker_update();
|
|
|
|
|
speaker_gated = val & 1;
|
|
|
|
|
speaker_enable = val & 2;
|
|
|
|
|
if (speaker_enable)
|
|
|
|
|
was_speaker_enable = 1;
|
2017-05-05 01:49:42 +02:00
|
|
|
pit_set_gate(&pit, 2, val & 1);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
static uint8_t keyboard_xt_read(uint16_t port, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
uint8_t temp;
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0x60:
|
|
|
|
|
if ((romset == ROM_IBMPC) && (keyboard_xt.pb & 0x80))
|
|
|
|
|
{
|
|
|
|
|
if (VGA || gfxcard == GFX_EGA)
|
|
|
|
|
temp = 0x4D;
|
|
|
|
|
else if (MDA)
|
|
|
|
|
temp = 0x7D;
|
|
|
|
|
else
|
|
|
|
|
temp = 0x6D;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
temp = keyboard_xt.pa;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x61:
|
|
|
|
|
temp = keyboard_xt.pb;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x62:
|
|
|
|
|
if (romset == ROM_IBMPC)
|
|
|
|
|
{
|
|
|
|
|
if (keyboard_xt.pb & 0x04)
|
2016-08-20 03:40:12 +02:00
|
|
|
temp = ((mem_size-64) / 32) & 0xf;
|
2016-06-26 00:34:39 +02:00
|
|
|
else
|
2016-08-20 03:40:12 +02:00
|
|
|
temp = ((mem_size-64) / 32) >> 4;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (keyboard_xt.pb & 0x08)
|
|
|
|
|
{
|
|
|
|
|
if (VGA || gfxcard == GFX_EGA)
|
|
|
|
|
temp = 4;
|
|
|
|
|
else if (MDA)
|
|
|
|
|
temp = 7;
|
|
|
|
|
else
|
|
|
|
|
temp = 6;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
temp = 0xD;
|
|
|
|
|
}
|
|
|
|
|
temp |= (ppispeakon ? 0x20 : 0);
|
|
|
|
|
if (keyboard_xt.tandy)
|
|
|
|
|
temp |= (tandy_eeprom_read() ? 0x10 : 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
pclog("\nBad XT keyboard read %04X\n", port);
|
2017-05-05 01:49:42 +02:00
|
|
|
temp = 0xff;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
void keyboard_xt_reset(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
keyboard_xt.blocked = 0;
|
|
|
|
|
|
|
|
|
|
keyboard_scan = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
void keyboard_xt_init(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
io_sethandler(0x0060, 0x0004, keyboard_xt_read, NULL, NULL, keyboard_xt_write, NULL, NULL, NULL);
|
|
|
|
|
keyboard_xt_reset();
|
|
|
|
|
keyboard_send = keyboard_xt_adddata;
|
|
|
|
|
keyboard_poll = keyboard_xt_poll;
|
|
|
|
|
keyboard_xt.tandy = 0;
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
timer_add((void (*)(void *))keyboard_xt_poll, &keybsenddelay, TIMER_ALWAYS_ENABLED, NULL);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
void keyboard_tandy_init(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
io_sethandler(0x0060, 0x0004, keyboard_xt_read, NULL, NULL, keyboard_xt_write, NULL, NULL, NULL);
|
|
|
|
|
keyboard_xt_reset();
|
|
|
|
|
keyboard_send = keyboard_xt_adddata;
|
|
|
|
|
keyboard_poll = keyboard_xt_poll;
|
|
|
|
|
keyboard_xt.tandy = (romset != ROM_TANDY) ? 1 : 0;
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
timer_add((void (*)(void *))keyboard_xt_poll, &keybsenddelay, TIMER_ALWAYS_ENABLED, NULL);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|