Files
86Box/src/lpt.c
OBattler 46d0ed2baa Rewritten 808x CPU emulation core based on reenigne's XTCE, VisiOn, SnatchIt, and 8088 MPH now work correctly;
Fixed PC speaker sound volume in PIT mode 0;
A few CPU emulation clean-ups;
Hard disk controller changing redone in a less messy way;
Re-added the long-missing key send delay handling to the XT keyboard handler;
Fixed a bug that was causing SLiRP not to work when compiled with MingW/GCC 7.3.0-2 or newer;
Some serial mouse and port fixes;
A lot of changes to printer emulation, mostly based on DOSBox-X;
Printer PNG writer now uses statically linked libpng;
Added support for the HxC MFM floppy image format and upped 86F format version to 2.12;
Ported various things from PCem and some from VARCem;
Added the S3 86c801/805 emulation (patch from TheCollector1995);
Fixed and renamed the EGA monitor options;
Better synchronized the 808x to the PIT and the CGA;
Fixed the CGA wait state calculation;
Cleaned up some things in mem.c;
Fixed some things in the floppy emulation to make VisiOn get the correct errors from the copy protection disk;
Fixed several renderer-related bugs, including the SDL2 renderer's failure to take screenshots;
The Jenkins builds are now compiled with MingW/GCC 7.4.0-1 and include all the required DLL's.
2019-02-06 03:34:39 +01:00

237 lines
5.4 KiB
C

/* Copyright holders: Sarah Walker
see COPYING for more details
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include "86box.h"
#include "io.h"
#include "lpt.h"
#include "sound/snd_lpt_dac.h"
#include "sound/snd_lpt_dss.h"
#include "printer/prt_devs.h"
char lpt_device_names[3][16];
static const struct
{
const char *name;
const char *internal_name;
const 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},
{"Generic Text Printer", "text_prt", &lpt_prt_text_device},
{"Generic ESC/P Dot-Matrix", "dot_matrix", &lpt_prt_escp_device},
{"", "", NULL}
};
char *lpt_device_get_name(int id)
{
if (strlen((char *) lpt_devices[id].name) == 0)
return NULL;
return (char *) lpt_devices[id].name;
}
char *lpt_device_get_internal_name(int id)
{
if (strlen((char *) lpt_devices[id].internal_name) == 0)
return NULL;
return (char *) lpt_devices[id].internal_name;
}
static lpt_device_t *lpt_device_ts[3];
static void *lpt_device_ps[3];
void lpt_devices_init()
{
int i = 0;
int c;
for (i = 0; i < 3; i++) {
c = 0;
while (strcmp((char *) lpt_devices[c].internal_name, lpt_device_names[i]) && strlen((char *) lpt_devices[c].internal_name) != 0)
c++;
if (strlen((char *) lpt_devices[c].internal_name) == 0)
lpt_device_ts[i] = NULL;
else
{
lpt_device_ts[i] = (lpt_device_t *) lpt_devices[c].device;
if (lpt_device_ts[i])
lpt_device_ps[i] = lpt_device_ts[i]->init(lpt_device_ts[i]);
}
}
}
void lpt_devices_close()
{
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;
}
}
static uint8_t lpt_dats[3], lpt_ctrls[3] = { 0x04, 0x04, 0x04 };
void lpt_write(int i, uint16_t port, uint8_t val, void *priv)
{
switch (port & 3)
{
case 0:
if (lpt_device_ts[i] && lpt_device_ts[i]->write_data)
lpt_device_ts[i]->write_data(val, lpt_device_ps[i]);
lpt_dats[i] = val;
break;
case 1:
break;
case 2:
if (lpt_device_ts[i] && lpt_device_ts[i]->write_ctrl)
lpt_device_ts[i]->write_ctrl(val, lpt_device_ps[i]);
lpt_ctrls[i] = val;
break;
}
}
uint8_t lpt_read(int i, uint16_t port, void *priv)
{
uint8_t retval = 0xff;
switch (port & 3)
{
case 0:
if (lpt_device_ts[i] && lpt_device_ts[i]->read_data) {
retval = lpt_device_ts[i]->read_data(lpt_device_ps[i]);
break;
}
retval = lpt_dats[i];
break;
case 1:
if (lpt_device_ts[i] && lpt_device_ts[i]->read_status) {
retval = lpt_device_ts[i]->read_status(lpt_device_ps[i]);
break;
}
retval = 0xdf;
break;
case 2:
if (lpt_device_ts[i] && lpt_device_ts[i]->read_ctrl) {
retval = lpt_device_ts[i]->read_ctrl(lpt_device_ps[i]);
break;
}
retval = 0xe0 | lpt_ctrls[i];
break;
}
return retval;
}
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);
}
void lpt2_write(uint16_t port, uint8_t val, void *priv)
{
lpt_write(1, port, val, priv);
}
uint8_t lpt2_read(uint16_t port, void *priv)
{
return lpt_read(1, port, priv);
}
void lpt3_write(uint16_t port, uint8_t val, void *priv)
{
lpt_write(2, port, val, priv);
}
uint8_t lpt3_read(uint16_t port, void *priv)
{
return lpt_read(2, port, priv);
}
uint16_t lpt_addr[3] = { 0x378, 0x278, 0x3bc };
void lpt_init(void)
{
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;
}
}
void lpt1_init(uint16_t port)
{
if (lpt_enabled)
{
io_sethandler(port, 0x0003, lpt1_read, NULL, NULL, lpt1_write, NULL, NULL, NULL);
lpt_addr[0] = port;
}
}
void lpt1_remove(void)
{
if (lpt_enabled)
{
io_removehandler(lpt_addr[0], 0x0003, lpt1_read, NULL, NULL, lpt1_write, NULL, NULL, NULL);
}
}
void lpt2_init(uint16_t port)
{
if (lpt_enabled)
{
io_sethandler(port, 0x0003, lpt2_read, NULL, NULL, lpt2_write, NULL, NULL, NULL);
lpt_addr[1] = port;
}
}
void lpt2_remove(void)
{
if (lpt_enabled)
{
io_removehandler(lpt_addr[1], 0x0003, lpt2_read, NULL, NULL, lpt2_write, NULL, NULL, NULL);
}
}
void lpt2_remove_ams(void)
{
if (lpt_enabled)
{
io_removehandler(0x0379, 0x0002, lpt2_read, NULL, NULL, lpt2_write, NULL, NULL, NULL);
}
}
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;
}
}
void lpt3_remove(void)
{
if (lpt_enabled)
{
io_removehandler(lpt_addr[2], 0x0003, lpt3_read, NULL, NULL, lpt3_write, NULL, NULL, NULL);
}
}