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>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <wchar.h>
|
2017-11-02 02:28:00 -05:00
|
|
|
#include "86box.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "io.h"
|
|
|
|
|
#include "lpt.h"
|
2017-09-02 23:39:26 +02:00
|
|
|
#include "sound/snd_lpt_dac.h"
|
|
|
|
|
#include "sound/snd_lpt_dss.h"
|
|
|
|
|
|
2017-09-25 04:31:20 -04:00
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
char lpt_device_names[3][16];
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-09-25 04:31:20 -04:00
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
static const struct
|
2017-09-02 23:39:26 +02:00
|
|
|
{
|
2018-02-18 10:32:51 +01:00
|
|
|
const char *name;
|
|
|
|
|
const char *internal_name;
|
2017-09-02 23:39:26 +02:00
|
|
|
lpt_device_t *device;
|
|
|
|
|
} lpt_devices[] =
|
|
|
|
|
{
|
|
|
|
|
{"None", "none", NULL},
|
|
|
|
|
{"Disney Sound Source", "dss", &dss_device},
|
|
|
|
|
{"LPT DAC / Covox Speech Thing", "lpt_dac", &lpt_dac_device},
|
|
|
|
|
{"Stereo LPT DAC", "lpt_dac_stereo", &lpt_dac_stereo_device},
|
|
|
|
|
{"", "", NULL}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
char *lpt_device_get_name(int id)
|
|
|
|
|
{
|
2018-02-18 10:32:51 +01:00
|
|
|
if (strlen((char *) lpt_devices[id].name) == 0)
|
2017-09-02 23:39:26 +02:00
|
|
|
return NULL;
|
2018-02-18 10:32:51 +01:00
|
|
|
return (char *) lpt_devices[id].name;
|
2017-09-02 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
char *lpt_device_get_internal_name(int id)
|
|
|
|
|
{
|
2018-02-18 10:32:51 +01:00
|
|
|
if (strlen((char *) lpt_devices[id].internal_name) == 0)
|
2017-09-02 23:39:26 +02:00
|
|
|
return NULL;
|
2018-02-18 10:32:51 +01:00
|
|
|
return (char *) lpt_devices[id].internal_name;
|
2017-09-02 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
static lpt_device_t *lpt_device_ts[3];
|
|
|
|
|
static void *lpt_device_ps[3];
|
2017-09-02 23:39:26 +02:00
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
void lpt_devices_init()
|
2017-09-02 23:39:26 +02:00
|
|
|
{
|
2018-02-06 19:53:34 +01:00
|
|
|
int i = 0;
|
2018-02-07 01:46:45 +01:00
|
|
|
int c;
|
2017-09-02 23:39:26 +02:00
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
for (i = 0; i < 3; i++) {
|
2018-02-07 01:46:45 +01:00
|
|
|
c = 0;
|
|
|
|
|
|
2018-02-18 10:32:51 +01:00
|
|
|
while (strcmp((char *) lpt_devices[c].internal_name, lpt_device_names[i]) && strlen((char *) lpt_devices[c].internal_name) != 0)
|
2018-02-06 19:53:34 +01:00
|
|
|
c++;
|
|
|
|
|
|
2018-02-18 10:32:51 +01:00
|
|
|
if (strlen((char *) lpt_devices[c].internal_name) == 0)
|
2018-02-06 19:53:34 +01:00
|
|
|
lpt_device_ts[i] = NULL;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lpt_device_ts[i] = lpt_devices[c].device;
|
|
|
|
|
if (lpt_device_ts[i])
|
|
|
|
|
lpt_device_ps[i] = lpt_device_ts[i]->init();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-02 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
void lpt_devices_close()
|
2017-09-02 23:39:26 +02:00
|
|
|
{
|
2018-02-06 19:53:34 +01:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
if (lpt_device_ts[i])
|
|
|
|
|
lpt_device_ts[i]->close(lpt_device_ps[i]);
|
|
|
|
|
lpt_device_ts[i] = NULL;
|
|
|
|
|
}
|
2017-09-02 23:39:26 +02:00
|
|
|
}
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
static uint8_t lpt_dats[3], lpt_ctrls[3];
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
void lpt_write(int i, uint16_t port, uint8_t val, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
switch (port & 3)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2018-02-06 19:53:34 +01:00
|
|
|
if (lpt_device_ts[i])
|
|
|
|
|
lpt_device_ts[i]->write_data(val, lpt_device_ps[i]);
|
|
|
|
|
lpt_dats[i] = val;
|
2016-06-26 00:34:39 +02:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2018-02-06 19:53:34 +01:00
|
|
|
if (lpt_device_ts[i])
|
|
|
|
|
lpt_device_ts[i]->write_ctrl(val, lpt_device_ps[i]);
|
|
|
|
|
lpt_ctrls[i] = val;
|
2016-06-26 00:34:39 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-06 19:53:34 +01:00
|
|
|
uint8_t lpt_read(int i, uint16_t port, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
switch (port & 3)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2018-02-06 19:53:34 +01:00
|
|
|
return lpt_dats[i];
|
2017-09-02 23:39:26 +02:00
|
|
|
case 1:
|
2018-02-06 19:53:34 +01:00
|
|
|
if (lpt_device_ts[i])
|
|
|
|
|
return lpt_device_ts[i]->read_status(lpt_device_ps[i]);
|
2017-09-02 23:39:26 +02:00
|
|
|
return 0;
|
2016-06-26 00:34:39 +02:00
|
|
|
case 2:
|
2018-02-06 19:53:34 +01:00
|
|
|
return lpt_ctrls[i];
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
return 0xff;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 19:53:34 +01:00
|
|
|
void lpt1_write(uint16_t port, uint8_t val, void *priv)
|
|
|
|
|
{
|
|
|
|
|
lpt_write(0, port, val, priv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t lpt1_read(uint16_t port, void *priv)
|
|
|
|
|
{
|
|
|
|
|
return lpt_read(0, port, priv);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
void lpt2_write(uint16_t port, uint8_t val, void *priv)
|
|
|
|
|
{
|
2018-02-06 19:53:34 +01:00
|
|
|
lpt_write(1, port, val, priv);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2018-02-06 19:53:34 +01:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
uint8_t lpt2_read(uint16_t port, void *priv)
|
|
|
|
|
{
|
2018-02-06 19:53:34 +01:00
|
|
|
return lpt_read(1, port, priv);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-16 02:33:25 +02:00
|
|
|
void lpt3_write(uint16_t port, uint8_t val, void *priv)
|
|
|
|
|
{
|
2018-02-06 19:53:34 +01:00
|
|
|
lpt_write(2, port, val, priv);
|
2017-08-16 02:33:25 +02:00
|
|
|
}
|
2018-02-06 19:53:34 +01:00
|
|
|
|
2017-08-16 02:33:25 +02:00
|
|
|
uint8_t lpt3_read(uint16_t port, void *priv)
|
|
|
|
|
{
|
2018-02-06 19:53:34 +01:00
|
|
|
return lpt_read(2, port, priv);
|
2017-08-16 02:33:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t lpt_addr[3] = { 0x378, 0x278, 0x3bc };
|
2017-02-07 02:19:48 +01:00
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
void lpt_init(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-08-06 00:33:47 +02:00
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_sethandler(0x0378, 0x0003, lpt1_read, NULL, NULL, lpt1_write, NULL, NULL, NULL);
|
|
|
|
|
io_sethandler(0x0278, 0x0003, lpt2_read, NULL, NULL, lpt2_write, NULL, NULL, NULL);
|
|
|
|
|
lpt_addr[0] = 0x378;
|
|
|
|
|
lpt_addr[1] = 0x278;
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lpt1_init(uint16_t port)
|
|
|
|
|
{
|
2017-08-06 00:33:47 +02:00
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_sethandler(port, 0x0003, lpt1_read, NULL, NULL, lpt1_write, NULL, NULL, NULL);
|
|
|
|
|
lpt_addr[0] = port;
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2017-08-24 01:14:39 -04:00
|
|
|
void lpt1_remove(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-08-06 00:33:47 +02:00
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_removehandler(lpt_addr[0], 0x0003, lpt1_read, NULL, NULL, lpt1_write, NULL, NULL, NULL);
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
void lpt2_init(uint16_t port)
|
|
|
|
|
{
|
2017-08-06 00:33:47 +02:00
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_sethandler(port, 0x0003, lpt2_read, NULL, NULL, lpt2_write, NULL, NULL, NULL);
|
|
|
|
|
lpt_addr[1] = port;
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2017-08-24 01:14:39 -04:00
|
|
|
void lpt2_remove(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-08-06 00:33:47 +02:00
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_removehandler(lpt_addr[1], 0x0003, lpt2_read, NULL, NULL, lpt2_write, NULL, NULL, NULL);
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
void lpt2_remove_ams(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-08-06 00:33:47 +02:00
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_removehandler(0x0379, 0x0002, lpt2_read, NULL, NULL, lpt2_write, NULL, NULL, NULL);
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2017-08-16 02:33:25 +02:00
|
|
|
|
|
|
|
|
void lpt3_init(uint16_t port)
|
|
|
|
|
{
|
|
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_sethandler(port, 0x0003, lpt3_read, NULL, NULL, lpt3_write, NULL, NULL, NULL);
|
|
|
|
|
lpt_addr[2] = port;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-24 01:14:39 -04:00
|
|
|
void lpt3_remove(void)
|
2017-08-16 02:33:25 +02:00
|
|
|
{
|
|
|
|
|
if (lpt_enabled)
|
|
|
|
|
{
|
|
|
|
|
io_removehandler(lpt_addr[2], 0x0003, lpt3_read, NULL, NULL, lpt3_write, NULL, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|