- multiple parallel port support added (2 ports are available now)

- parport irq is now only registered in irq mode
- bx_reset_options() updated for multiple parallel and serial ports
This commit is contained in:
Volker Ruppert 2004-01-27 21:38:51 +00:00
parent 22a2e01975
commit ac28f72551
4 changed files with 164 additions and 126 deletions

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: bochs.h,v 1.132 2004-01-19 21:45:21 cbothamy Exp $ // $Id: bochs.h,v 1.133 2004-01-27 21:38:51 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2002 MandrakeSoft S.A. // Copyright (C) 2002 MandrakeSoft S.A.
@ -627,7 +627,7 @@ typedef struct {
#define BX_N_OPTROM_IMAGES 4 #define BX_N_OPTROM_IMAGES 4
#define BX_N_SERIAL_PORTS 4 #define BX_N_SERIAL_PORTS 4
#define BX_N_PARALLEL_PORTS 1 #define BX_N_PARALLEL_PORTS 2
#define BX_N_USB_HUBS 1 #define BX_N_USB_HUBS 1
typedef struct BOCHSAPI { typedef struct BOCHSAPI {

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: parallel.cc,v 1.24 2003-10-29 17:29:26 vruppert Exp $ // $Id: parallel.cc,v 1.25 2004-01-27 21:38:51 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2002 MandrakeSoft S.A. // Copyright (C) 2002 MandrakeSoft S.A.
@ -57,52 +57,61 @@ bx_parallel_c::bx_parallel_c(void)
{ {
put("PAR"); put("PAR");
settype(PARLOG); settype(PARLOG);
s.output = NULL; for (int i=0; i<BX_PARPORT_MAXDEV; i++) {
s[i].output = NULL;
}
} }
bx_parallel_c::~bx_parallel_c(void) bx_parallel_c::~bx_parallel_c(void)
{ {
if (s.output != NULL) for (int i=0; i<BX_PARPORT_MAXDEV; i++) {
fclose(s.output); if (s[i].output != NULL)
fclose(s[i].output);
}
} }
void void
bx_parallel_c::init(void) bx_parallel_c::init(void)
{ {
BX_DEBUG(("Init $Id: parallel.cc,v 1.24 2003-10-29 17:29:26 vruppert Exp $")); Bit16u ports[BX_PARPORT_MAXDEV] = {0x0378, 0x0278};
Bit8u irqs[BX_PARPORT_MAXDEV] = {7, 5};
char name[16];
if (bx_options.par[0].Oenabled->get ()) { BX_DEBUG(("Init $Id: parallel.cc,v 1.25 2004-01-27 21:38:51 vruppert Exp $"));
/* PARALLEL PORT 1 */ for (unsigned i=0; i<BX_N_PARALLEL_PORTS; i++) {
if (bx_options.par[i].Oenabled->get ()) {
DEV_register_irq(7, "Parallel Port 1"); sprintf(name, "Parallel Port %d", i + 1);
BX_INFO (("parallel port 1 at 0x378 irq 7")); /* parallel interrupt and i/o ports */
for (unsigned addr=0x0378; addr<=0x037A; addr++) { BX_PAR_THIS s[i].IRQ = irqs[i];
DEV_register_ioread_handler(this, read_handler, addr, "Parallel Port 1", 1); for (unsigned addr=ports[i]; addr<=(unsigned)(ports[i]+2); addr++) {
DEV_register_ioread_handler(this, read_handler, addr, name, 1);
} }
DEV_register_iowrite_handler(this, write_handler, 0x0378, "Parallel Port 1", 1); DEV_register_iowrite_handler(this, write_handler, ports[i], name, 1);
DEV_register_iowrite_handler(this, write_handler, 0x037A, "Parallel Port 1", 1); DEV_register_iowrite_handler(this, write_handler, ports[i]+2, name, 1);
BX_INFO (("parallel port %d at 0x%04x irq %d", i+1, ports[i], irqs[i]));
/* internal state */
BX_PAR_THIS s[i].STATUS.error = 1;
BX_PAR_THIS s[i].STATUS.slct = 1;
BX_PAR_THIS s[i].STATUS.pe = 0;
BX_PAR_THIS s[i].STATUS.ack = 1;
BX_PAR_THIS s[i].STATUS.busy = 1;
BX_PAR_THIS s.STATUS.error = 1; BX_PAR_THIS s[i].CONTROL.strobe = 0;
BX_PAR_THIS s.STATUS.slct = 1; BX_PAR_THIS s[i].CONTROL.autofeed = 0;
BX_PAR_THIS s.STATUS.pe = 0; BX_PAR_THIS s[i].CONTROL.init = 1;
BX_PAR_THIS s.STATUS.ack = 1; BX_PAR_THIS s[i].CONTROL.slct_in = 1;
BX_PAR_THIS s.STATUS.busy = 1; BX_PAR_THIS s[i].CONTROL.irq = 0;
BX_PAR_THIS s[i].CONTROL.input = 0;
BX_PAR_THIS s.CONTROL.strobe = 0; BX_PAR_THIS s[i].initmode = 0;
BX_PAR_THIS s.CONTROL.autofeed = 0; /* output file */
BX_PAR_THIS s.CONTROL.init = 1; if (strlen(bx_options.par[i].Ooutfile->getptr ()) > 0) {
BX_PAR_THIS s.CONTROL.slct_in = 1; s[i].output = fopen(bx_options.par[i].Ooutfile->getptr (), "wb");
BX_PAR_THIS s.CONTROL.irq = 0; if (!s[i].output)
BX_PAR_THIS s.CONTROL.input = 0; BX_PANIC (("Could not open '%s' to write parport%d output",
bx_options.par[i].Ooutfile->getptr (), i+1));
BX_PAR_THIS s.initmode = 0; }
if (strlen(bx_options.par[0].Ooutfile->getptr ()) > 0) {
s.output = fopen(bx_options.par[0].Ooutfile->getptr (), "wb");
if (!s.output)
BX_PANIC (("Could not open '%s' to write parport1 output",
bx_options.par[0].Ooutfile->getptr ()));
} }
} }
} }
@ -113,18 +122,18 @@ bx_parallel_c::reset(unsigned type)
} }
void void
bx_parallel_c::virtual_printer(void) bx_parallel_c::virtual_printer(Bit8u port)
{ {
if (BX_PAR_THIS s.STATUS.slct) { if (BX_PAR_THIS s[port].STATUS.slct) {
if (BX_PAR_THIS s.output != NULL) { if (BX_PAR_THIS s[port].output != NULL) {
fputc(BX_PAR_THIS s.data, BX_PAR_THIS s.output); fputc(BX_PAR_THIS s[port].data, BX_PAR_THIS s[port].output);
fflush (BX_PAR_THIS s.output); fflush (BX_PAR_THIS s[port].output);
} }
if (BX_PAR_THIS s.CONTROL.irq == 1) { if (BX_PAR_THIS s[port].CONTROL.irq == 1) {
DEV_pic_raise_irq(7); DEV_pic_raise_irq(BX_PAR_THIS s[port].IRQ);
} }
BX_PAR_THIS s.STATUS.ack = 0; BX_PAR_THIS s[port].STATUS.ack = 0;
BX_PAR_THIS s.STATUS.busy = 1; BX_PAR_THIS s[port].STATUS.busy = 1;
} }
else { else {
BX_ERROR(("data is valid, but printer is offline")); BX_ERROR(("data is valid, but printer is offline"));
@ -150,54 +159,60 @@ bx_parallel_c::read(Bit32u address, unsigned io_len)
#else #else
UNUSED(this_ptr); UNUSED(this_ptr);
#endif // !BX_USE_PAR_SMF #endif // !BX_USE_PAR_SMF
Bit8u offset;
Bit8u port = 0;
Bit32u retval; Bit32u retval;
switch (address) { offset = address & 0x07;
/* PARALLEL PORT 1 */ switch (address & 0x03f8) {
case 0x0378: case 0x0378: port = 0; break;
if (!BX_PAR_THIS s.CONTROL.input) { case 0x0278: port = 1; break;
return (Bit32u)BX_PAR_THIS s.data; }
switch (offset) {
case BX_PAR_DATA:
if (!BX_PAR_THIS s[port].CONTROL.input) {
return (Bit32u)BX_PAR_THIS s[port].data;
} else { } else {
BX_ERROR(("read: input mode not supported")); BX_ERROR(("read: input mode not supported"));
return (0xFF); return (0xFF);
} }
break; break;
case 0x0379: case BX_PAR_STAT:
{ {
retval = ((BX_PAR_THIS s.STATUS.busy << 7) | retval = ((BX_PAR_THIS s[port].STATUS.busy << 7) |
(BX_PAR_THIS s.STATUS.ack << 6) | (BX_PAR_THIS s[port].STATUS.ack << 6) |
(BX_PAR_THIS s.STATUS.pe << 5) | (BX_PAR_THIS s[port].STATUS.pe << 5) |
(BX_PAR_THIS s.STATUS.slct << 4) | (BX_PAR_THIS s[port].STATUS.slct << 4) |
(BX_PAR_THIS s.STATUS.error << 3)); (BX_PAR_THIS s[port].STATUS.error << 3));
if (BX_PAR_THIS s.STATUS.ack == 0) { if (BX_PAR_THIS s[port].STATUS.ack == 0) {
BX_PAR_THIS s.STATUS.ack = 1; BX_PAR_THIS s[port].STATUS.ack = 1;
if (BX_PAR_THIS s.CONTROL.irq == 1) { if (BX_PAR_THIS s[port].CONTROL.irq == 1) {
DEV_pic_lower_irq(7); DEV_pic_lower_irq(BX_PAR_THIS s[port].IRQ);
} }
} }
if (BX_PAR_THIS s.initmode == 1) { if (BX_PAR_THIS s[port].initmode == 1) {
BX_PAR_THIS s.STATUS.busy = 1; BX_PAR_THIS s[port].STATUS.busy = 1;
BX_PAR_THIS s.STATUS.slct = 1; BX_PAR_THIS s[port].STATUS.slct = 1;
BX_PAR_THIS s.STATUS.ack = 0; BX_PAR_THIS s[port].STATUS.ack = 0;
if (BX_PAR_THIS s.CONTROL.irq == 1) { if (BX_PAR_THIS s[port].CONTROL.irq == 1) {
DEV_pic_raise_irq(7); DEV_pic_raise_irq(BX_PAR_THIS s[port].IRQ);
} }
BX_PAR_THIS s.initmode = 0; BX_PAR_THIS s[port].initmode = 0;
} }
BX_DEBUG(("read: status register returns 0x%02x", retval)); BX_DEBUG(("read: parport%d status register returns 0x%02x", port+1, retval));
return retval; return retval;
} }
break; break;
case 0x037A: case BX_PAR_CTRL:
{ {
retval = ((BX_PAR_THIS s.CONTROL.input << 5) | retval = ((BX_PAR_THIS s[port].CONTROL.input << 5) |
(BX_PAR_THIS s.CONTROL.irq << 4) | (BX_PAR_THIS s[port].CONTROL.irq << 4) |
(BX_PAR_THIS s.CONTROL.slct_in << 3) | (BX_PAR_THIS s[port].CONTROL.slct_in << 3) |
(BX_PAR_THIS s.CONTROL.init << 2) | (BX_PAR_THIS s[port].CONTROL.init << 2) |
(BX_PAR_THIS s.CONTROL.autofeed << 1) | (BX_PAR_THIS s[port].CONTROL.autofeed << 1) |
(BX_PAR_THIS s.CONTROL.strobe)); (BX_PAR_THIS s[port].CONTROL.strobe));
BX_DEBUG(("read: control register returns 0x%02x", retval)); BX_DEBUG(("read: parport%d control register returns 0x%02x", port+1, retval));
return retval; return retval;
} }
break; break;
@ -224,75 +239,87 @@ bx_parallel_c::write(Bit32u address, Bit32u value, unsigned io_len)
#else #else
UNUSED(this_ptr); UNUSED(this_ptr);
#endif // !BX_USE_PAR_SMF #endif // !BX_USE_PAR_SMF
Bit8u offset;
Bit8u port = 0;
char name[16];
switch (address) { offset = address & 0x07;
/* PARALLEL PORT 1 */ switch (address & 0x03f8) {
case 0x0378: case 0x0378: port = 0; break;
BX_PAR_THIS s.data = (Bit8u)value; case 0x0278: port = 1; break;
BX_DEBUG(("write: data output register = 0x%02x", (Bit8u)value)); }
switch (offset) {
case BX_PAR_DATA:
BX_PAR_THIS s[port].data = (Bit8u)value;
BX_DEBUG(("write: parport%d data output register = 0x%02x", port+1, (Bit8u)value));
break; break;
case 0x037A: case BX_PAR_CTRL:
{ {
if ((value & 0x01) == 0x01) { if ((value & 0x01) == 0x01) {
if (BX_PAR_THIS s.CONTROL.strobe == 0) { if (BX_PAR_THIS s[port].CONTROL.strobe == 0) {
BX_PAR_THIS s.CONTROL.strobe = 1; BX_PAR_THIS s[port].CONTROL.strobe = 1;
virtual_printer(); // data is valid now virtual_printer(port); // data is valid now
} }
} else { } else {
if (BX_PAR_THIS s.CONTROL.strobe == 1) { if (BX_PAR_THIS s[port].CONTROL.strobe == 1) {
BX_PAR_THIS s.CONTROL.strobe = 0; BX_PAR_THIS s[port].CONTROL.strobe = 0;
} }
} }
BX_PAR_THIS s.CONTROL.autofeed = ((value & 0x02) == 0x02); BX_PAR_THIS s[port].CONTROL.autofeed = ((value & 0x02) == 0x02);
if ((value & 0x04) == 0x04) { if ((value & 0x04) == 0x04) {
if (BX_PAR_THIS s.CONTROL.init == 0) { if (BX_PAR_THIS s[port].CONTROL.init == 0) {
BX_PAR_THIS s.CONTROL.init = 1; BX_PAR_THIS s[port].CONTROL.init = 1;
BX_PAR_THIS s.STATUS.busy = 0; BX_PAR_THIS s[port].STATUS.busy = 0;
BX_PAR_THIS s.STATUS.slct = 0; BX_PAR_THIS s[port].STATUS.slct = 0;
BX_PAR_THIS s.initmode = 1; BX_PAR_THIS s[port].initmode = 1;
BX_DEBUG(("printer init requested")); BX_DEBUG(("parport%d: printer init requested", port+1));
} }
} else { } else {
if (BX_PAR_THIS s.CONTROL.init == 1) { if (BX_PAR_THIS s[port].CONTROL.init == 1) {
BX_PAR_THIS s.CONTROL.init = 0; BX_PAR_THIS s[port].CONTROL.init = 0;
} }
} }
if ((value & 0x08) == 0x08) { if ((value & 0x08) == 0x08) {
if (BX_PAR_THIS s.CONTROL.slct_in == 0) { if (BX_PAR_THIS s[port].CONTROL.slct_in == 0) {
BX_PAR_THIS s.CONTROL.slct_in = 1; BX_PAR_THIS s[port].CONTROL.slct_in = 1;
BX_DEBUG(("printer now online")); BX_DEBUG(("parport%d: printer now online", port+1));
} }
} else { } else {
if (BX_PAR_THIS s.CONTROL.slct_in == 1) { if (BX_PAR_THIS s[port].CONTROL.slct_in == 1) {
BX_PAR_THIS s.CONTROL.slct_in = 0; BX_PAR_THIS s[port].CONTROL.slct_in = 0;
BX_DEBUG(("printer now offline")); BX_DEBUG(("parport%d: printer now offline", port+1));
} }
} }
BX_PAR_THIS s.STATUS.slct = BX_PAR_THIS s.CONTROL.slct_in; BX_PAR_THIS s[port].STATUS.slct = BX_PAR_THIS s[port].CONTROL.slct_in;
if ((value & 0x10) == 0x10) { if ((value & 0x10) == 0x10) {
if (BX_PAR_THIS s.CONTROL.irq == 0) { if (BX_PAR_THIS s[port].CONTROL.irq == 0) {
BX_PAR_THIS s.CONTROL.irq = 1; BX_PAR_THIS s[port].CONTROL.irq = 1;
BX_DEBUG(("irq mode selected")); sprintf(name, "Parallel Port %d", port+1);
DEV_register_irq(BX_PAR_THIS s[port].IRQ, name);
BX_DEBUG(("parport%d: irq mode selected", port+1));
} }
} else { } else {
if (BX_PAR_THIS s.CONTROL.irq == 1) { if (BX_PAR_THIS s[port].CONTROL.irq == 1) {
BX_PAR_THIS s.CONTROL.irq = 0; BX_PAR_THIS s[port].CONTROL.irq = 0;
BX_DEBUG(("polling mode selected")); sprintf(name, "Parallel Port %d", port+1);
DEV_unregister_irq(BX_PAR_THIS s[port].IRQ, name);
BX_DEBUG(("parport%d: polling mode selected", port+1));
} }
} }
if ((value & 0x20) == 0x20) { if ((value & 0x20) == 0x20) {
if (BX_PAR_THIS s.CONTROL.input == 0) { if (BX_PAR_THIS s[port].CONTROL.input == 0) {
BX_PAR_THIS s.CONTROL.input = 1; BX_PAR_THIS s[port].CONTROL.input = 1;
BX_DEBUG(("data input mode selected")); BX_DEBUG(("parport%d: data input mode selected", port+1));
} }
} else { } else {
if (BX_PAR_THIS s.CONTROL.input == 1) { if (BX_PAR_THIS s[port].CONTROL.input == 1) {
BX_PAR_THIS s.CONTROL.input = 0; BX_PAR_THIS s[port].CONTROL.input = 0;
BX_DEBUG(("data output mode selected")); BX_DEBUG(("parport%d: data output mode selected", port+1));
} }
} }
if ((value & 0xC0) > 0) { if ((value & 0xC0) > 0) {
BX_ERROR(("write: unsupported control bit ignored")); BX_ERROR(("write: parport%d: unsupported control bit ignored", port+1));
} }
} }
break; break;

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: parallel.h,v 1.11 2002-10-25 11:44:40 bdenney Exp $ // $Id: parallel.h,v 1.12 2004-01-27 21:38:51 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2001 MandrakeSoft S.A. // Copyright (C) 2001 MandrakeSoft S.A.
@ -33,6 +33,12 @@
# define BX_PAR_THIS this-> # define BX_PAR_THIS this->
#endif #endif
#define BX_PARPORT_MAXDEV 2
#define BX_PAR_DATA 0
#define BX_PAR_STAT 1
#define BX_PAR_CTRL 2
typedef struct { typedef struct {
Bit8u data; Bit8u data;
struct { struct {
@ -50,6 +56,7 @@ typedef struct {
bx_bool irq; bx_bool irq;
bx_bool input; bx_bool input;
} CONTROL; } CONTROL;
Bit8u IRQ;
FILE *output; FILE *output;
bx_bool initmode; bx_bool initmode;
} bx_par_t; } bx_par_t;
@ -65,9 +72,9 @@ public:
virtual void reset(unsigned type); virtual void reset(unsigned type);
private: private:
bx_par_t s; bx_par_t s[BX_PARPORT_MAXDEV];
static void virtual_printer(); static void virtual_printer(Bit8u port);
static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len); static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len); static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.260 2004-01-18 00:18:44 vruppert Exp $ // $Id: main.cc,v 1.261 2004-01-27 21:38:51 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2002 MandrakeSoft S.A. // Copyright (C) 2002 MandrakeSoft S.A.
@ -1632,6 +1632,8 @@ void bx_init_options ()
void bx_reset_options () void bx_reset_options ()
{ {
Bit8u i;
// drives // drives
bx_options.floppya.Opath->reset(); bx_options.floppya.Opath->reset();
bx_options.floppya.Odevtype->reset(); bx_options.floppya.Odevtype->reset();
@ -1670,10 +1672,14 @@ void bx_reset_options ()
bx_options.memory.Osize->reset(); bx_options.memory.Osize->reset();
// standard ports // standard ports
bx_options.com[0].Oenabled->reset(); for (i=0; i<BX_N_SERIAL_PORTS; i++) {
bx_options.com[0].Odev->reset(); bx_options.com[i].Oenabled->reset();
bx_options.par[0].Oenabled->reset(); bx_options.com[i].Odev->reset();
bx_options.par[0].Ooutfile->reset(); }
for (i=0; i<BX_N_PARALLEL_PORTS; i++) {
bx_options.par[i].Oenabled->reset();
bx_options.par[i].Ooutfile->reset();
}
// rom images // rom images
bx_options.rom.Opath->reset(); bx_options.rom.Opath->reset();
@ -3857,7 +3863,6 @@ parse_line_formatted(char *context, int num_params, char *params[])
} }
} }
#if 0
else if (!strcmp(params[0], "parport2")) { else if (!strcmp(params[0], "parport2")) {
for (i=1; i<num_params; i++) { for (i=1; i<num_params; i++) {
if (!strncmp(params[i], "enabled=", 8)) { if (!strncmp(params[i], "enabled=", 8)) {
@ -3872,7 +3877,6 @@ parse_line_formatted(char *context, int num_params, char *params[])
} }
} }
} }
#endif
else if (!strcmp(params[0], "i440fxsupport")) { else if (!strcmp(params[0], "i440fxsupport")) {
if (num_params != 2) { if (num_params != 2) {