2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// $Id: floppy.cc,v 1.24 2001-10-03 13:10:38 bdenney Exp $
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-06-13 11:06:10 +04:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// Floppy Disk Controller Docs:
|
|
|
|
// Intel 82077A Data sheet
|
|
|
|
// ftp://void-core.2y.net/pub/docs/fdc/82077AA_FloppyControllerDatasheet.pdf
|
|
|
|
// Intel 82078 Data sheet
|
|
|
|
// ftp://download.intel.com/design/periphrl/datashts/29047403.PDF
|
|
|
|
// Other FDC references
|
|
|
|
// http://debs.future.easyspace.com/Programming/Hardware/FDC/floppy.html
|
|
|
|
// And a port list:
|
|
|
|
// http://mudlist.eorbit.net/~adam/pickey/ports.html
|
|
|
|
//
|
2001-04-10 05:04:59 +04:00
|
|
|
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
extern "C" {
|
|
|
|
#include <errno.h>
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "bochs.h"
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS bx_floppy.
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
bx_floppy_ctrl_c bx_floppy;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if BX_USE_FD_SMF
|
|
|
|
#define this (&bx_floppy)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* for main status register */
|
|
|
|
#define FD_MS_MRQ 0x80
|
|
|
|
#define FD_MS_DIO 0x40
|
|
|
|
#define FD_MS_NDMA 0x20
|
|
|
|
#define FD_MS_BUSY 0x10
|
|
|
|
#define FD_MS_ACTD 0x08
|
|
|
|
#define FD_MS_ACTC 0x04
|
|
|
|
#define FD_MS_ACTB 0x02
|
|
|
|
#define FD_MS_ACTA 0x01
|
|
|
|
|
|
|
|
#define FROM_FLOPPY 10
|
|
|
|
#define TO_FLOPPY 11
|
|
|
|
|
|
|
|
#define FLOPPY_DMA_CHAN 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bx_floppy_ctrl_c::bx_floppy_ctrl_c(void)
|
|
|
|
{
|
2001-06-27 23:16:01 +04:00
|
|
|
put("FDD");
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
settype(FDLOG);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bx_floppy_ctrl_c::~bx_floppy_ctrl_c(void)
|
|
|
|
{
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
// nothing for now
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("Exit."));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::init(bx_devices_c *d, bx_cmos_c *cmos)
|
|
|
|
{
|
2001-10-03 17:10:38 +04:00
|
|
|
BX_DEBUG(("Init $Id: floppy.cc,v 1.24 2001-10-03 13:10:38 bdenney Exp $"));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS devices = d;
|
|
|
|
|
|
|
|
BX_FD_THIS devices->register_irq(6, "Floppy Drive");
|
|
|
|
for (unsigned addr=0x03F2; addr<=0x03F7; addr++) {
|
|
|
|
BX_FD_THIS devices->register_io_read_handler(this, read_handler,
|
|
|
|
addr, "Floppy Drive");
|
|
|
|
BX_FD_THIS devices->register_io_write_handler(this, write_handler,
|
|
|
|
addr, "Floppy Drive");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmos->s.reg[0x10] = 0x00; /* start out with: no drive 0, no drive 1 */
|
|
|
|
|
|
|
|
BX_FD_THIS s.num_supported_floppies = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Floppy A setup
|
|
|
|
//
|
|
|
|
BX_FD_THIS s.media[0].sectors_per_track = 0;
|
|
|
|
BX_FD_THIS s.media[0].tracks = 0;
|
|
|
|
BX_FD_THIS s.media[0].heads = 0;
|
|
|
|
BX_FD_THIS s.media[0].sectors = 0;
|
|
|
|
BX_FD_THIS s.media[0].type = BX_FLOPPY_NONE;
|
|
|
|
BX_FD_THIS s.media[0].fd = -1;
|
|
|
|
BX_FD_THIS s.media_present[0] = 0;
|
|
|
|
|
|
|
|
|
2001-06-20 18:01:39 +04:00
|
|
|
switch (bx_options.floppya.Otype->get ()) {
|
2001-04-10 05:04:59 +04:00
|
|
|
case BX_FLOPPY_NONE:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0x0f) | 0x00;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_2:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0x0f) | 0x20;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_720K:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0x0f) | 0x30;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_44:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0x0f) | 0x40;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_2_88:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0x0f) | 0x50;
|
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(( "unknown floppya type" ));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2001-06-20 18:01:39 +04:00
|
|
|
if (bx_options.floppya.Otype->get () != BX_FLOPPY_NONE) {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.num_supported_floppies++;
|
2001-06-20 18:01:39 +04:00
|
|
|
if ( bx_options.floppya.Oinitial_status->get () == BX_INSERTED) {
|
|
|
|
if (evaluate_media(bx_options.floppya.Otype->get (), bx_options.floppya.Opath->getptr (),
|
2001-04-10 05:04:59 +04:00
|
|
|
& BX_FD_THIS s.media[0]))
|
|
|
|
BX_FD_THIS s.media_present[0] = 1;
|
2001-08-31 20:06:32 +04:00
|
|
|
#define MED (BX_FD_THIS s.media[0])
|
|
|
|
BX_INFO(("fd0: '%s' ro=%d, h=%d,t=%d,spt=%d", bx_options.floppya.Opath->getptr(),
|
|
|
|
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
|
|
|
|
#undef MED
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Floppy B setup
|
|
|
|
//
|
|
|
|
BX_FD_THIS s.media[1].sectors_per_track = 0;
|
|
|
|
BX_FD_THIS s.media[1].tracks = 0;
|
|
|
|
BX_FD_THIS s.media[1].heads = 0;
|
|
|
|
BX_FD_THIS s.media[1].sectors = 0;
|
|
|
|
BX_FD_THIS s.media[1].type = BX_FLOPPY_NONE;
|
|
|
|
BX_FD_THIS s.media[1].fd = -1;
|
|
|
|
BX_FD_THIS s.media_present[1] = 0;
|
|
|
|
|
2001-06-20 18:01:39 +04:00
|
|
|
switch (bx_options.floppyb.Otype->get ()) {
|
2001-04-10 05:04:59 +04:00
|
|
|
case BX_FLOPPY_NONE:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0xf0) | 0x00;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_2:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0xf0) | 0x02;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_720K:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0xf0) | 0x03;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_44:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0xf0) | 0x04;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_2_88:
|
|
|
|
cmos->s.reg[0x10] = (cmos->s.reg[0x10] & 0xf0) | 0x05;
|
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("unknown floppyb type"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2001-06-20 18:01:39 +04:00
|
|
|
if (bx_options.floppyb.Otype->get () != BX_FLOPPY_NONE) {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.num_supported_floppies++;
|
2001-06-20 18:01:39 +04:00
|
|
|
if ( bx_options.floppyb.Oinitial_status->get () == BX_INSERTED) {
|
|
|
|
if (evaluate_media(bx_options.floppyb.Otype->get (), bx_options.floppyb.Opath->getptr (),
|
2001-04-10 05:04:59 +04:00
|
|
|
& BX_FD_THIS s.media[1]))
|
|
|
|
BX_FD_THIS s.media_present[1] = 1;
|
2001-08-31 20:06:32 +04:00
|
|
|
#define MED (BX_FD_THIS s.media[1])
|
|
|
|
BX_INFO(("fd1: '%s' ro=%d, h=%d,t=%d,spt=%d", bx_options.floppyb.Opath->getptr(),
|
|
|
|
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
|
|
|
|
#undef MED
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* CMOS Equipment Byte register */
|
|
|
|
if (BX_FD_THIS s.num_supported_floppies > 0)
|
|
|
|
cmos->s.reg[0x14] = (cmos->s.reg[0x14] & 0x3e) |
|
|
|
|
((BX_FD_THIS s.num_supported_floppies-1) << 6) |
|
|
|
|
1;
|
|
|
|
else
|
|
|
|
cmos->s.reg[0x14] = (cmos->s.reg[0x14] & 0x3e);
|
|
|
|
|
|
|
|
|
|
|
|
BX_FD_THIS s.floppy_timer_index =
|
|
|
|
bx_pc_system.register_timer( this, timer_handler,
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Ofloppy_command_delay->get (), 0,0);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("bx_options.Ofloppy_command_delay = %u",
|
2001-06-20 18:01:39 +04:00
|
|
|
(unsigned) bx_options.Ofloppy_command_delay->get ()));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::reset(unsigned source)
|
|
|
|
{
|
|
|
|
Bit32u i;
|
|
|
|
|
|
|
|
BX_FD_THIS s.data_rate = 0; /* 500 Kbps */
|
|
|
|
|
|
|
|
BX_FD_THIS s.command_complete = 1; /* waiting for new command */
|
|
|
|
BX_FD_THIS s.command_index = 0;
|
|
|
|
BX_FD_THIS s.command_size = 0;
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.result_size = 0;
|
|
|
|
|
|
|
|
/* data register ready, not in DMA mode */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ;
|
|
|
|
BX_FD_THIS s.status_reg0 = 0;
|
|
|
|
BX_FD_THIS s.status_reg1 = 0;
|
|
|
|
BX_FD_THIS s.status_reg2 = 0;
|
|
|
|
BX_FD_THIS s.status_reg3 = 0;
|
|
|
|
|
|
|
|
// software reset (via DOR port 0x3f2 bit 2) does not change DOR
|
|
|
|
if (source == BX_RESET_HARDWARE) {
|
|
|
|
BX_FD_THIS s.DOR = 0x0c;
|
|
|
|
// motor off, drive 3..0
|
|
|
|
// DMA/INT enabled
|
|
|
|
// normal operation
|
|
|
|
// drive select 0
|
|
|
|
|
|
|
|
// DIR affected only by hard reset
|
|
|
|
BX_FD_THIS s.DIR |= 0x80; // disk changed
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
BX_FD_THIS s.cylinder[i] = 0;
|
|
|
|
BX_FD_THIS s.head[i] = 0;
|
|
|
|
BX_FD_THIS s.sector[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_FD_THIS s.floppy_buffer_index = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static IO port read callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
|
|
|
|
|
|
|
Bit32u
|
|
|
|
bx_floppy_ctrl_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
|
|
|
{
|
|
|
|
#if !BX_USE_FD_SMF
|
|
|
|
bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr;
|
|
|
|
|
|
|
|
return( class_ptr->read(address, io_len) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* reads from the floppy io ports */
|
|
|
|
Bit32u
|
|
|
|
bx_floppy_ctrl_c::read(Bit32u address, unsigned io_len)
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_FD_SMF
|
|
|
|
Bit8u status, value;
|
|
|
|
|
|
|
|
if (io_len > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io read from address %08x, len=%u",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) address, (unsigned) io_len));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// ???
|
|
|
|
//if (bx_cpu.cs.selector.value != 0xf000) {
|
2001-05-30 22:56:02 +04:00
|
|
|
// BX_INFO(("BIOS: floppy: read access to port %04x", (unsigned) address);
|
2001-04-10 05:04:59 +04:00
|
|
|
// }
|
|
|
|
|
|
|
|
if (bx_dbg.floppy)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("read access to port %04x", (unsigned) address));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
switch (address) {
|
|
|
|
#if BX_DMA_FLOPPY_IO
|
|
|
|
case 0x3F2: // diskette controller digital output register
|
|
|
|
value = BX_FD_THIS s.DOR;
|
|
|
|
return(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F4: /* diskette controller main status register */
|
|
|
|
status = BX_FD_THIS s.main_status_reg;
|
|
|
|
return(status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F5: /* diskette controller data */
|
|
|
|
if (BX_FD_THIS s.result_size == 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("diskette controller:port3f5: no results to read"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
value = BX_FD_THIS s.result[BX_FD_THIS s.result_index++];
|
|
|
|
if (BX_FD_THIS s.result_index >= BX_FD_THIS s.result_size) {
|
|
|
|
BX_FD_THIS s.result_size = 0;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ;
|
|
|
|
}
|
|
|
|
return(value);
|
|
|
|
break;
|
|
|
|
#endif // #if BX_DMA_FLOPPY_IO
|
|
|
|
|
|
|
|
case 0x3F6: // Reserved for future floppy controllers
|
|
|
|
// This address shared with the hard drive controller
|
|
|
|
value = BX_FD_THIS devices->hard_drive->read_handler(BX_FD_THIS devices->hard_drive, address, io_len);
|
|
|
|
return( value );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F7: // diskette controller digital input register
|
|
|
|
// This address shared with the hard drive controller:
|
|
|
|
// Bit 7 : floppy
|
|
|
|
// Bits 6..0: hard drive
|
|
|
|
value = BX_FD_THIS devices->hard_drive->read_handler(BX_FD_THIS devices->hard_drive, address, io_len);
|
|
|
|
value &= 0x7f;
|
|
|
|
// add in diskette change line
|
|
|
|
value |= (BX_FD_THIS s.DIR & 0x80);
|
|
|
|
return( value );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_DMA_FLOPPY_IO
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io_read: bailing"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
|
|
|
#endif // #if BX_DMA_FLOPPY_IO
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static IO port write callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
|
|
|
{
|
|
|
|
#if !BX_USE_FD_SMF
|
|
|
|
bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr;
|
|
|
|
|
|
|
|
class_ptr->write(address, value, io_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* writes to the floppy io ports */
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_FD_SMF
|
|
|
|
Bit8u dma_and_interrupt_enable;
|
|
|
|
Bit8u normal_operation, prev_normal_operation;
|
|
|
|
Bit8u drive_select;
|
|
|
|
Bit8u motor_on_drive0, motor_on_drive1;
|
|
|
|
|
|
|
|
if (io_len > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io write to address %08x, len=%u",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) address, (unsigned) io_len));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// ???
|
|
|
|
//if (bx_cpu.cs.selector.value != 0xf000) {
|
2001-05-30 22:56:02 +04:00
|
|
|
// BX_INFO(("BIOS: floppy: write access to port %04x, value=%02x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
// (unsigned) address, (unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
// }
|
|
|
|
|
|
|
|
if (bx_dbg.floppy)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("write access to port %04x, value=%02x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) address, (unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
switch (address) {
|
|
|
|
#if BX_DMA_FLOPPY_IO
|
|
|
|
case 0x3F2: /* diskette controller digital output register */
|
|
|
|
motor_on_drive1 = value & 0x20;
|
|
|
|
motor_on_drive0 = value & 0x10;
|
|
|
|
dma_and_interrupt_enable = value & 0x08;
|
|
|
|
if (!dma_and_interrupt_enable)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("DMA and interrupt capabilities disabled"));
|
2001-04-10 05:04:59 +04:00
|
|
|
normal_operation = value & 0x04;
|
|
|
|
drive_select = value & 0x03;
|
|
|
|
|
|
|
|
prev_normal_operation = BX_FD_THIS s.DOR & 0x04;
|
|
|
|
BX_FD_THIS s.DOR = value;
|
|
|
|
|
|
|
|
if (prev_normal_operation==0 && normal_operation) {
|
|
|
|
// transition from RESET to NORMAL
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = 0xfe; // RESET pending
|
|
|
|
|
|
|
|
bx_pc_system.activate_timer( BX_FD_THIS s.floppy_timer_index,
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Ofloppy_command_delay->get (), 0 );
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (prev_normal_operation && normal_operation==0) {
|
|
|
|
// transition from NORMAL to RESET
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = 0xfe; // RESET pending
|
|
|
|
|
|
|
|
bx_pc_system.activate_timer( BX_FD_THIS s.floppy_timer_index,
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Ofloppy_command_delay->get (), 0 );
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("io_write: digital output register"));
|
|
|
|
BX_DEBUG((" motor on, drive1 = %d", motor_on_drive1 > 0));
|
|
|
|
BX_DEBUG((" motor on, drive0 = %d", motor_on_drive0 > 0));
|
|
|
|
BX_DEBUG((" dma_and_interrupt_enable=%02x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) dma_and_interrupt_enable));
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG((" normal_operation=%02x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) normal_operation));
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG((" drive_select=%02x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) drive_select));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (drive_select>1) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io_write: drive_select>1"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3f4: /* diskette controller data rate select register */
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io_write: data rate select register"));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F5: /* diskette controller data */
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("command = %02x", (unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (BX_FD_THIS s.command_complete) {
|
|
|
|
if (BX_FD_THIS s.pending_command!=0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io: 3f5: receiving new comm, old one (%02x) pending",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_FD_THIS s.pending_command));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.command[0] = value;
|
|
|
|
BX_FD_THIS s.command_complete = 0;
|
|
|
|
BX_FD_THIS s.command_index = 1;
|
|
|
|
/* read/write command in progress */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_BUSY;
|
|
|
|
switch (value) {
|
|
|
|
case 0x03: /* specify */
|
|
|
|
BX_FD_THIS s.command_size = 3;
|
|
|
|
break;
|
|
|
|
case 0x04: // get status
|
|
|
|
BX_FD_THIS s.command_size = 2;
|
|
|
|
break;
|
|
|
|
case 0x07: /* recalibrate */
|
|
|
|
BX_FD_THIS s.command_size = 2;
|
|
|
|
break;
|
|
|
|
case 0x08: /* sense interrupt status */
|
|
|
|
BX_FD_THIS s.command_size = 1;
|
|
|
|
floppy_command();
|
|
|
|
BX_FD_THIS s.command_complete = 1;
|
|
|
|
break;
|
|
|
|
case 0x0f: /* seek */
|
|
|
|
BX_FD_THIS s.command_size = 3;
|
|
|
|
break;
|
|
|
|
case 0x4a: /* read ID */
|
|
|
|
BX_FD_THIS s.command_size = 2;
|
|
|
|
break;
|
|
|
|
case 0xc5: /* write normal data */
|
|
|
|
BX_FD_THIS s.command_size = 9;
|
|
|
|
break;
|
|
|
|
case 0xe6: /* read normal data */
|
|
|
|
BX_FD_THIS s.command_size = 9;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x13: // Configure command (Enhanced)
|
|
|
|
BX_FD_THIS s.command_size = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0e: // dump registers (Enhanced drives)
|
|
|
|
case 0x10: // Version command, standard controller returns 80h
|
|
|
|
case 0x18: // National Semiconductor version command; return 80h
|
|
|
|
// These commands are not implemented on the standard
|
|
|
|
// controller and return an error. They are available on
|
|
|
|
// the enhanced controller.
|
|
|
|
BX_FD_THIS s.command_size = 1;
|
|
|
|
BX_FD_THIS s.result[0] = 0x80;
|
|
|
|
BX_FD_THIS s.result_size = 1;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.command_complete = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io write:3f5: unsupported case 0x%02x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_FD_THIS s.command[BX_FD_THIS s.command_index++] =
|
|
|
|
value;
|
|
|
|
if (BX_FD_THIS s.command_index ==
|
|
|
|
BX_FD_THIS s.command_size) {
|
|
|
|
/* read/write command not in progress any more */
|
|
|
|
floppy_command();
|
|
|
|
BX_FD_THIS s.command_complete = 1;
|
|
|
|
}
|
|
|
|
}
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("io_write: diskette controller data"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
#endif // #if BX_DMA_FLOPPY_IO
|
|
|
|
|
|
|
|
case 0x3F6: /* diskette controller (reserved) */
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("io_write: reserved register unsupported"));
|
2001-04-10 05:04:59 +04:00
|
|
|
// this address shared with the hard drive controller
|
|
|
|
BX_FD_THIS devices->hard_drive->write_handler(BX_FD_THIS devices->hard_drive, address, value, io_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if BX_DMA_FLOPPY_IO
|
|
|
|
case 0x3F7: /* diskette controller configuration control register */
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("io_write: config control register"));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.data_rate = value & 0x03;
|
2001-08-31 20:06:32 +04:00
|
|
|
switch (BX_FD_THIS s.data_rate) {
|
|
|
|
case 0: BX_DEBUG((" 500 Kbps")); break;
|
|
|
|
case 1: BX_DEBUG((" 300 Kbps")); break;
|
|
|
|
case 2: BX_DEBUG((" 250 Kbps")); break;
|
|
|
|
case 3: BX_DEBUG((" 1 Mbps")); break;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io_write: unknown port %04h", (unsigned) address));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
#endif // #if BX_DMA_FLOPPY_IO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::floppy_command(void)
|
|
|
|
{
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY==0
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
BX_PANIC(("floppy_command(): uses DMA: not supported for"
|
2001-05-30 22:56:02 +04:00
|
|
|
" external environment"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#else
|
|
|
|
unsigned i;
|
|
|
|
Bit8u step_rate_time;
|
|
|
|
Bit8u head_unload_time;
|
|
|
|
Bit8u head_load_time;
|
|
|
|
Bit8u motor_on;
|
|
|
|
Bit8u head, drive, cylinder, sector, eot;
|
|
|
|
Bit8u sector_size, data_length;
|
|
|
|
Bit32u logical_sector;
|
|
|
|
|
|
|
|
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("FLOPPY COMMAND: "));
|
|
|
|
for (i=0; i<BX_FD_THIS s.command_size; i++)
|
|
|
|
BX_DEBUG(("[%02x] ", (unsigned) BX_FD_THIS s.command[i]));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* execute phase of command is in progress (non DMA mode) */
|
|
|
|
BX_FD_THIS s.main_status_reg |= 20;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (BX_FD_THIS s.command[0]) {
|
|
|
|
case 0x03: // specify
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_INFO(("floppy_command specify"));
|
2001-04-10 05:04:59 +04:00
|
|
|
// execution: specified parameters are loaded
|
|
|
|
// result: no result bytes, no interrupt
|
|
|
|
step_rate_time = BX_FD_THIS s.command[1] >> 4;
|
|
|
|
head_unload_time = BX_FD_THIS s.command[1] & 0x0f;
|
|
|
|
head_load_time = BX_FD_THIS s.command[2] >> 1;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ;
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x04: // get status
|
2001-06-13 11:06:10 +04:00
|
|
|
drive = (BX_FD_THIS s.command[1] & 0x03);
|
|
|
|
BX_FD_THIS s.result[0] =
|
|
|
|
BX_FD_THIS s.media[drive].write_protected ? 0x40 : 0x00;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.result_size = 1;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x07: // recalibrate
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_INFO(("floppy_command recalibrate"));
|
2001-04-10 05:04:59 +04:00
|
|
|
drive = (BX_FD_THIS s.command[1] & 0x03);
|
|
|
|
BX_FD_THIS s.DOR &= 0xfc;
|
|
|
|
BX_FD_THIS s.DOR |= drive;
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("floppy_command(): recalibrate drive %u",
|
|
|
|
(unsigned) drive));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (drive > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command(): drive > 1"));
|
2001-04-10 05:04:59 +04:00
|
|
|
//motor_on = BX_FD_THIS s.DOR & 0xf0;
|
|
|
|
motor_on = ( (BX_FD_THIS s.DOR>>(drive+4))
|
|
|
|
& 0x01 );
|
|
|
|
if (motor_on == 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("floppy_command(): recal drive with motor off"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
if (drive==0)
|
|
|
|
BX_FD_THIS s.DOR |= 0x10; // turn on MOTA
|
|
|
|
else
|
|
|
|
BX_FD_THIS s.DOR |= 0x20; // turn on MOTB
|
|
|
|
BX_FD_THIS s.cylinder[drive] = 0;
|
|
|
|
bx_pc_system.activate_timer( BX_FD_THIS s.floppy_timer_index,
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Ofloppy_command_delay->get (), 0 );
|
2001-04-10 05:04:59 +04:00
|
|
|
/* command head to track 0
|
|
|
|
* controller set to non-busy
|
|
|
|
* error condition noted in Status reg 0's equipment check bit
|
|
|
|
* seek end bit set to 1 in Status reg 0 regardless of outcome
|
|
|
|
*/
|
|
|
|
/* data reg not ready, controller busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = 0x07; // recalibrate pending
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08: /* sense interrupt status */
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_INFO(("floppy_command sense interrupt status"));
|
2001-04-10 05:04:59 +04:00
|
|
|
/* execution:
|
|
|
|
* get status
|
|
|
|
* result:
|
|
|
|
* no interupt
|
|
|
|
* byte0 = status reg0
|
|
|
|
* byte1 = current cylinder number (0 to 79)
|
|
|
|
*/
|
|
|
|
/*BX_FD_THIS s.status_reg0 = ;*/
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
BX_FD_THIS s.result[0] = 0x20 | drive;
|
|
|
|
BX_FD_THIS s.result[1] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result_size = 2;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
|
|
|
|
/* read ready */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("sense interrupt status"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0f: /* seek */
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_INFO(("floppy_command seek"));
|
2001-04-10 05:04:59 +04:00
|
|
|
/* command:
|
|
|
|
* byte0 = 0F
|
|
|
|
* byte1 = drive & head select
|
|
|
|
* byte2 = cylinder number
|
|
|
|
* execution:
|
|
|
|
* postion head over specified cylinder
|
|
|
|
* result:
|
|
|
|
* no result bytes, issues an interrupt
|
|
|
|
*/
|
|
|
|
drive = BX_FD_THIS s.command[1] & 0x03;
|
|
|
|
BX_FD_THIS s.DOR &= 0xfc;
|
|
|
|
BX_FD_THIS s.DOR |= drive;
|
|
|
|
|
|
|
|
BX_FD_THIS s.head[drive] = (BX_FD_THIS s.command[1] >> 2) & 0x01;
|
|
|
|
BX_FD_THIS s.cylinder[drive] = BX_FD_THIS s.command[2];
|
|
|
|
if (drive > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command(): seek: drive>1"));
|
2001-04-10 05:04:59 +04:00
|
|
|
/* ??? should also check cylinder validity */
|
|
|
|
bx_pc_system.activate_timer( BX_FD_THIS s.floppy_timer_index,
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Ofloppy_command_delay->get (), 0 );
|
2001-04-10 05:04:59 +04:00
|
|
|
/* data reg not ready, controller busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = 0x0f; /* seek pending */
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x13: // Configure
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("io: configure (mode=%02xh, pretrack=%02xh)",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned)(BX_FD_THIS s.command[2]), (unsigned)(BX_FD_THIS s.command[3]) ));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.result_size = 0;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4a: // read ID
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_INFO(("floppy_command read ID")); // ???
|
2001-04-10 05:04:59 +04:00
|
|
|
drive = BX_FD_THIS s.command[1] & 0x03;
|
|
|
|
BX_FD_THIS s.DOR &= 0xfc;
|
|
|
|
BX_FD_THIS s.DOR |= drive;
|
|
|
|
|
|
|
|
motor_on = (BX_FD_THIS s.DOR>>(drive+4)) & 0x01;
|
|
|
|
if (motor_on == 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command(): 4a: motor not on"));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (drive > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io: 4a: bad drive #"));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.result[0] = 0; /* ??? */
|
|
|
|
BX_FD_THIS s.result[1] = 0;
|
|
|
|
BX_FD_THIS s.result[2] = 0;
|
|
|
|
BX_FD_THIS s.result[3] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result[4] = 0; /* head */
|
|
|
|
BX_FD_THIS s.result[5] = 0; /* sector at completion */
|
|
|
|
BX_FD_THIS s.result[6] = 2;
|
|
|
|
bx_pc_system.activate_timer( BX_FD_THIS s.floppy_timer_index,
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Ofloppy_command_delay->get (), 0 );
|
2001-04-10 05:04:59 +04:00
|
|
|
/* data reg not ready, controller busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = 0x4a; /* read ID pending */
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 0xe6: // read normal data
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_INFO(("floppy_command read normal data"));
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0xc5: // write normal data
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_INFO(("floppy_command write normal data"));
|
2001-04-10 05:04:59 +04:00
|
|
|
if ( (BX_FD_THIS s.DOR & 0x08) == 0 )
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("read/write command with DMA and int disabled"));
|
2001-04-10 05:04:59 +04:00
|
|
|
drive = BX_FD_THIS s.command[1] & 0x03;
|
|
|
|
BX_FD_THIS s.DOR &= 0xfc;
|
|
|
|
BX_FD_THIS s.DOR |= drive;
|
|
|
|
|
|
|
|
motor_on = (BX_FD_THIS s.DOR>>(drive+4)) & 0x01;
|
|
|
|
if (motor_on == 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command(): read/write: motor not on"));
|
2001-04-10 05:04:59 +04:00
|
|
|
head = BX_FD_THIS s.command[3] & 0x01;
|
|
|
|
cylinder = BX_FD_THIS s.command[2]; /* 0..79 depending */
|
|
|
|
sector = BX_FD_THIS s.command[4]; /* 1..36 depending */
|
|
|
|
eot = BX_FD_THIS s.command[6]; /* 1..36 depending */
|
|
|
|
sector_size = BX_FD_THIS s.command[5];
|
|
|
|
data_length = BX_FD_THIS s.command[8];
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("read/write normal data"));
|
|
|
|
BX_DEBUG(("BEFORE"));
|
|
|
|
BX_DEBUG((" drive = %u", (unsigned) drive));
|
|
|
|
BX_DEBUG((" head = %u", (unsigned) head));
|
|
|
|
BX_DEBUG((" cylinder = %u", (unsigned) cylinder));
|
|
|
|
BX_DEBUG((" sector = %u", (unsigned) sector));
|
|
|
|
BX_DEBUG((" eot = %u", (unsigned) eot));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (drive > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io: bad drive #"));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (head > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io: bad head #"));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-09-29 07:29:27 +04:00
|
|
|
// check that head number in command[1] bit two matches the head
|
|
|
|
// reported in the head number field. Real floppy drives are
|
|
|
|
// picky about this, as reported in SF bug #439945, (Floppy drive
|
|
|
|
// read input error checking).
|
|
|
|
if (head != (BX_FD_THIS s.command[1]>>2)&1) {
|
|
|
|
BX_ERROR(("head number in command[1] doesn't match head field"));
|
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.result[0] = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive; // abnormal termination
|
|
|
|
BX_FD_THIS s.result[1] = 0x04; // 0000 0100
|
|
|
|
BX_FD_THIS s.result[2] = 0x00; // 0000 0000
|
|
|
|
BX_FD_THIS s.result[3] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result[4] = BX_FD_THIS s.head[drive];
|
|
|
|
BX_FD_THIS s.result[5] = BX_FD_THIS s.sector[drive];
|
|
|
|
BX_FD_THIS s.result[6] = 2; // sector size = 512
|
|
|
|
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
if ( BX_FD_THIS s.media_present[drive] == 0 ) {
|
|
|
|
// media not in drive, return error
|
|
|
|
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
BX_INFO(("attempt to read/write sector %u,"
|
2001-05-30 22:56:02 +04:00
|
|
|
" sectors/track=%u", (unsigned) sector,
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_FD_THIS s.media[drive].sectors_per_track));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.result[0] = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive; // abnormal termination
|
|
|
|
BX_FD_THIS s.result[1] = 0x25; // 0010 0101
|
|
|
|
BX_FD_THIS s.result[2] = 0x31; // 0011 0001
|
|
|
|
BX_FD_THIS s.result[3] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result[4] = BX_FD_THIS s.head[drive];
|
|
|
|
BX_FD_THIS s.result[5] = BX_FD_THIS s.sector[drive];
|
|
|
|
BX_FD_THIS s.result[6] = 2; // sector size = 512
|
|
|
|
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sector_size != 0x02) { // 512 bytes
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("sector_size not 512"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
if ( cylinder >= BX_FD_THIS s.media[drive].tracks ) {
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_PANIC(("io: norm r/w parms out of range: sec#%02xh cyl#%02xh eot#%02h head#%02xh",
|
|
|
|
(unsigned) sector, (unsigned) cylinder, (unsigned) eot,
|
|
|
|
(unsigned) head));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
2001-08-31 20:06:32 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (sector > BX_FD_THIS s.media[drive].sectors_per_track) {
|
|
|
|
// requested sector > last sector on track
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
BX_INFO(("attempt to read/write sector %u,"
|
2001-05-30 22:56:02 +04:00
|
|
|
" sectors/track=%u", (unsigned) sector,
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_FD_THIS s.media[drive].sectors_per_track));
|
2001-04-10 05:04:59 +04:00
|
|
|
// set controller to where drive would have left off
|
|
|
|
// after it discovered the sector was past EOT
|
|
|
|
BX_FD_THIS s.cylinder[drive] = cylinder;
|
|
|
|
BX_FD_THIS s.head[drive] = head;
|
|
|
|
BX_FD_THIS s.sector[drive] = BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
|
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
// 0100 0HDD abnormal termination
|
|
|
|
BX_FD_THIS s.result[0] = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive;
|
|
|
|
// 1000 0101 end of cyl/NDAT/NID
|
|
|
|
BX_FD_THIS s.result[1] = 0x86;
|
|
|
|
// 0000 0000
|
|
|
|
BX_FD_THIS s.result[2] = 0x00;
|
|
|
|
BX_FD_THIS s.result[3] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result[4] = BX_FD_THIS s.head[drive];
|
|
|
|
BX_FD_THIS s.result[5] = BX_FD_THIS s.sector[drive];
|
|
|
|
BX_FD_THIS s.result[6] = 2; // sector size = 512
|
|
|
|
|
|
|
|
bx_pc_system.activate_timer( BX_FD_THIS s.floppy_timer_index,
|
2001-06-20 18:01:39 +04:00
|
|
|
bx_options.Ofloppy_command_delay->get (), 0 );
|
2001-04-10 05:04:59 +04:00
|
|
|
/* data reg not ready, controller busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = BX_FD_THIS s.command[0];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (eot != BX_FD_THIS s.media[drive].sectors_per_track)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("io: bad eot #%02xh", (unsigned) eot));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (cylinder != BX_FD_THIS s.cylinder[drive])
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("io: cylinder request != current cylinder"));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
logical_sector = (cylinder * 2 * BX_FD_THIS s.media[drive].sectors_per_track) +
|
|
|
|
(head * BX_FD_THIS s.media[drive].sectors_per_track) +
|
|
|
|
(sector - 1);
|
|
|
|
|
|
|
|
if (logical_sector >= BX_FD_THIS s.media[drive].sectors) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io: logical sector out of bounds"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BX_FD_THIS s.cylinder[drive] = cylinder;
|
|
|
|
BX_FD_THIS s.sector[drive] = sector;
|
|
|
|
BX_FD_THIS s.head[drive] = head;
|
|
|
|
|
|
|
|
if (BX_FD_THIS s.command[0] == 0xe6) { // read
|
|
|
|
floppy_xfer(drive, logical_sector*512, BX_FD_THIS s.floppy_buffer,
|
|
|
|
512, FROM_FLOPPY);
|
|
|
|
BX_FD_THIS s.floppy_buffer_index = 0;
|
|
|
|
|
|
|
|
bx_pc_system.set_DRQ(FLOPPY_DMA_CHAN, 1);
|
|
|
|
|
|
|
|
/* data reg not ready, controller busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = BX_FD_THIS s.command[0];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (BX_FD_THIS s.command[0] == 0xc5) { // write
|
|
|
|
BX_FD_THIS s.floppy_buffer_index = 0;
|
|
|
|
|
|
|
|
bx_pc_system.set_DRQ(FLOPPY_DMA_CHAN, 1);
|
|
|
|
|
|
|
|
/* data reg not ready, controller busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.pending_command = BX_FD_THIS s.command[0];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command(): unknown read/write command"));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command(): unknown function"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command()"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-06-13 11:08:04 +04:00
|
|
|
void
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
|
|
|
|
Bit32u bytes, Bit8u direction)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (drive > 1)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_xfer: drive > 1"));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (bx_dbg.floppy) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("drive=%u", (unsigned) drive));
|
|
|
|
BX_INFO(("offset=%u", (unsigned) offset));
|
|
|
|
BX_INFO(("bytes=%u", (unsigned) bytes));
|
|
|
|
BX_INFO(("direction=%s", (direction==FROM_FLOPPY)? "from" : "to"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2001-09-26 04:19:44 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-06-20 18:01:39 +04:00
|
|
|
if (strcmp(bx_options.floppya.Opath->getptr (), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ret = lseek(BX_FD_THIS s.media[drive].fd, offset, SEEK_SET);
|
|
|
|
if (ret < 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("could not perform lseek() on floppy image file"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (direction == FROM_FLOPPY) {
|
2001-09-26 04:19:44 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-06-20 18:01:39 +04:00
|
|
|
if (!strcmp(bx_options.floppya.Opath->getptr (), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
ret = fd_read((char *) buffer, offset, bytes);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ret = ::read(BX_FD_THIS s.media[drive].fd, (bx_ptr_t) buffer, bytes);
|
|
|
|
if (ret < int(bytes)) {
|
|
|
|
/* ??? */
|
|
|
|
if (ret > 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("partial read() on floppy image returns %u/%u",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) ret, (unsigned) bytes));
|
2001-04-10 05:04:59 +04:00
|
|
|
memset(buffer + ret, 0, bytes - ret);
|
|
|
|
}
|
|
|
|
else {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("read() on floppy image returns 0"));
|
2001-04-10 05:04:59 +04:00
|
|
|
memset(buffer, 0, bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else { // TO_FLOPPY
|
2001-06-13 11:06:10 +04:00
|
|
|
BX_ASSERT (!BX_FD_THIS s.media[drive].write_protected);
|
2001-09-26 21:35:51 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-06-20 18:01:39 +04:00
|
|
|
if (!strcmp(bx_options.floppya.Opath->getptr (), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
ret = fd_write((char *) buffer, offset, bytes);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ret = ::write(BX_FD_THIS s.media[drive].fd, (bx_ptr_t) buffer, bytes);
|
|
|
|
if (ret < int(bytes)) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("could not perform write() on floppy image file"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-06-13 04:30:34 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::timer_handler(void *this_ptr)
|
|
|
|
{
|
|
|
|
#if defined(SIMX86)
|
2001-05-30 22:56:02 +04:00
|
|
|
printf("Floppy timer");
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr;
|
|
|
|
|
|
|
|
class_ptr->timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::timer()
|
|
|
|
{
|
|
|
|
switch ( BX_FD_THIS s.pending_command ) {
|
|
|
|
case 0x07: // recal
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
/* write ready, not busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ;
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
goto reset_changeline;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0f: // seek
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
/* write ready, not busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ;
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
goto reset_changeline;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 0x4a: /* read ID */
|
|
|
|
case 0xc5: // write normal data
|
|
|
|
case 0xe6: // read normal data
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
/* read ready, busy */
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO;
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xfe: // (contrived) RESET
|
|
|
|
reset(BX_RESET_SOFTWARE);
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ;
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy:timer(): unknown case %02x",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(unsigned) BX_FD_THIS s.pending_command));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
reset_changeline:
|
|
|
|
unsigned drive = BX_FD_THIS s.DOR & 0x3;
|
|
|
|
if (drive > 1) return;
|
|
|
|
if (BX_FD_THIS s.media_present[drive])
|
|
|
|
BX_FD_THIS s.DIR &= ~0x80; // clear disk change line
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::dma_write(Bit8u *data_byte)
|
|
|
|
{
|
|
|
|
// A DMA write is from I/O to Memory
|
|
|
|
// We need to return then next data byte from the floppy buffer
|
|
|
|
// to be transfered via the DMA to memory. (read block from floppy)
|
|
|
|
|
|
|
|
|
|
|
|
*data_byte = BX_FD_THIS s.floppy_buffer[BX_FD_THIS s.floppy_buffer_index++];
|
|
|
|
|
|
|
|
if (BX_FD_THIS s.floppy_buffer_index >= 512) {
|
|
|
|
Bit8u drive;
|
|
|
|
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
increment_sector(); // increment to next sector before retrieving next one
|
|
|
|
BX_FD_THIS s.floppy_buffer_index = 0;
|
|
|
|
if (bx_pc_system.TC) { // Terminal Count line, done
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.result[0] = (BX_FD_THIS s.head[drive] << 2) | drive;
|
|
|
|
BX_FD_THIS s.result[1] = 0;
|
|
|
|
BX_FD_THIS s.result[2] = 0;
|
|
|
|
BX_FD_THIS s.result[3] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result[4] = BX_FD_THIS s.head[drive];
|
|
|
|
BX_FD_THIS s.result[5] = BX_FD_THIS s.sector[drive];
|
|
|
|
BX_FD_THIS s.result[6] = 2;
|
|
|
|
|
|
|
|
if (bx_dbg.floppy) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("<<READ DONE>>"));
|
|
|
|
BX_INFO(("AFTER"));
|
|
|
|
BX_INFO((" drive = %u", (unsigned) drive));
|
|
|
|
BX_INFO((" head = %u", (unsigned) BX_FD_THIS s.head[drive]));
|
|
|
|
BX_INFO((" cylinder = %u", (unsigned) BX_FD_THIS s.cylinder[drive]));
|
|
|
|
BX_INFO((" sector = %u", (unsigned) BX_FD_THIS s.sector[drive]));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
bx_pc_system.set_DRQ(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
|
|
|
else { // more data to transfer
|
|
|
|
Bit32u logical_sector;
|
|
|
|
logical_sector = (BX_FD_THIS s.cylinder[drive] * 2 *
|
|
|
|
BX_FD_THIS s.media[drive].sectors_per_track) +
|
|
|
|
(BX_FD_THIS s.head[drive] *
|
|
|
|
BX_FD_THIS s.media[drive].sectors_per_track) +
|
|
|
|
(BX_FD_THIS s.sector[drive] - 1);
|
|
|
|
floppy_xfer(drive, logical_sector*512, BX_FD_THIS s.floppy_buffer,
|
|
|
|
512, FROM_FLOPPY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::dma_read(Bit8u *data_byte)
|
|
|
|
{
|
|
|
|
// A DMA read is from Memory to I/O
|
|
|
|
// We need to write the data_byte which was already transfered from memory
|
|
|
|
// via DMA to I/O (write block to floppy)
|
|
|
|
|
|
|
|
Bit8u drive;
|
|
|
|
Bit32u logical_sector;
|
|
|
|
|
|
|
|
BX_FD_THIS s.floppy_buffer[BX_FD_THIS s.floppy_buffer_index++] = *data_byte;
|
|
|
|
|
|
|
|
if (BX_FD_THIS s.floppy_buffer_index >= 512) {
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
logical_sector = (BX_FD_THIS s.cylinder[drive] * 2 * BX_FD_THIS s.media[drive].sectors_per_track) +
|
|
|
|
(BX_FD_THIS s.head[drive] * BX_FD_THIS s.media[drive].sectors_per_track) +
|
|
|
|
(BX_FD_THIS s.sector[drive] - 1);
|
2001-06-13 11:06:10 +04:00
|
|
|
if ( BX_FD_THIS s.media[drive].write_protected ) {
|
|
|
|
// write protected error
|
|
|
|
BX_INFO(("tried to write disk %u, which is write-protected", drive));
|
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
// ST0: IC1,0=01 (abnormal termination: started execution but failed)
|
|
|
|
BX_FD_THIS s.result[0] = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive;
|
|
|
|
// ST1: DataError=1, NDAT=1, NotWritable=1, NID=1
|
|
|
|
BX_FD_THIS s.result[1] = 0x27; // 0010 0111
|
|
|
|
// ST2: CRCE=1, SERR=1, BCYL=1, NDAM=1.
|
|
|
|
BX_FD_THIS s.result[2] = 0x31; // 0011 0001
|
|
|
|
BX_FD_THIS s.result[3] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result[4] = BX_FD_THIS s.head[drive];
|
|
|
|
BX_FD_THIS s.result[5] = BX_FD_THIS s.sector[drive];
|
|
|
|
BX_FD_THIS s.result[6] = 2; // sector size = 512
|
|
|
|
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
floppy_xfer(drive, logical_sector*512, BX_FD_THIS s.floppy_buffer,
|
|
|
|
512, TO_FLOPPY);
|
|
|
|
increment_sector(); // increment to next sector after writing current one
|
|
|
|
BX_FD_THIS s.floppy_buffer_index = 0;
|
|
|
|
if (bx_pc_system.TC) { // Terminal Count line, done
|
|
|
|
BX_FD_THIS s.pending_command = 0;
|
|
|
|
BX_FD_THIS s.main_status_reg = FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
|
|
|
BX_FD_THIS s.result[0] = (BX_FD_THIS s.head[drive] << 2) | drive;
|
|
|
|
BX_FD_THIS s.result[1] = 0;
|
|
|
|
BX_FD_THIS s.result[2] = 0;
|
|
|
|
BX_FD_THIS s.result[3] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
BX_FD_THIS s.result[4] = BX_FD_THIS s.head[drive];
|
|
|
|
BX_FD_THIS s.result[5] = BX_FD_THIS s.sector[drive];
|
|
|
|
BX_FD_THIS s.result[6] = 2;
|
|
|
|
if (bx_dbg.floppy) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("<<WRITE DONE>>"));
|
|
|
|
BX_INFO(("AFTER"));
|
|
|
|
BX_INFO((" drive = %u", (unsigned) drive));
|
|
|
|
BX_INFO((" head = %u", (unsigned) BX_FD_THIS s.head[drive]));
|
|
|
|
BX_INFO((" cylinder = %u", (unsigned) BX_FD_THIS s.cylinder[drive]));
|
|
|
|
BX_INFO((" sector = %u", (unsigned) BX_FD_THIS s.sector[drive]));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BX_FD_THIS devices->pic->trigger_irq(6);
|
|
|
|
bx_pc_system.set_DRQ(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
|
|
|
else { // more data to transfer
|
|
|
|
} // else
|
|
|
|
} // if BX_FD_THIS s.floppy_buffer_index >= 512
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_floppy_ctrl_c::increment_sector(void)
|
|
|
|
{
|
|
|
|
Bit8u drive;
|
|
|
|
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
|
|
|
|
// values after completion of data xfer
|
|
|
|
// ??? calculation depends on base_count being multiple of 512
|
|
|
|
BX_FD_THIS s.sector[drive] ++;
|
|
|
|
if (BX_FD_THIS s.sector[drive] > BX_FD_THIS s.media[drive].sectors_per_track) {
|
|
|
|
BX_FD_THIS s.sector[drive] -= BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
BX_FD_THIS s.head[drive] ++;
|
|
|
|
if (BX_FD_THIS s.head[drive] > 1) {
|
|
|
|
BX_FD_THIS s.head[drive] = 0;
|
|
|
|
BX_FD_THIS s.cylinder[drive] ++;
|
|
|
|
if (BX_FD_THIS s.cylinder[drive] >= BX_FD_THIS s.media[drive].tracks) {
|
|
|
|
// Set to 1 past last possible cylinder value.
|
|
|
|
// I notice if I set it to tracks-1, prama linux won't boot.
|
|
|
|
BX_FD_THIS s.cylinder[drive] = BX_FD_THIS s.media[drive].tracks;
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("increment_sector: clamping cylinder to max"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
bx_floppy_ctrl_c::set_media_status(unsigned drive, unsigned status)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
unsigned type;
|
|
|
|
|
|
|
|
// if setting to the current value, nothing to do
|
|
|
|
if (status == BX_FD_THIS s.media_present[drive])
|
|
|
|
return(status);
|
|
|
|
|
|
|
|
if (status == 0) {
|
|
|
|
// eject floppy
|
|
|
|
if (BX_FD_THIS s.media[drive].fd >= 0) {
|
|
|
|
close( BX_FD_THIS s.media[drive].fd );
|
|
|
|
BX_FD_THIS s.media[drive].fd = -1;
|
|
|
|
}
|
|
|
|
BX_FD_THIS s.media_present[drive] = 0;
|
|
|
|
BX_FD_THIS s.DIR |= 0x80; // disk changed line
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// insert floppy
|
|
|
|
if (drive == 0) {
|
2001-06-20 18:01:39 +04:00
|
|
|
path = bx_options.floppya.Opath->getptr ();
|
|
|
|
type = bx_options.floppya.Otype->get ();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-06-20 18:01:39 +04:00
|
|
|
path = bx_options.floppyb.Opath->getptr ();
|
|
|
|
type = bx_options.floppyb.Otype->get ();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
if (evaluate_media(type, path, & BX_FD_THIS s.media[drive])) {
|
|
|
|
BX_FD_THIS s.media_present[drive] = 1;
|
|
|
|
BX_FD_THIS s.DIR |= 0x80; // disk changed line
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_FD_THIS s.media_present[drive] = 0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
bx_floppy_ctrl_c::get_media_status(unsigned drive)
|
|
|
|
{
|
|
|
|
return( BX_FD_THIS s.media_present[drive] );
|
|
|
|
}
|
|
|
|
|
2001-10-01 21:20:08 +04:00
|
|
|
#ifdef O_BINARY
|
|
|
|
#define BX_RDONLY O_RDONLY | O_BINARY
|
|
|
|
#define BX_RDWR O_RDWR | O_BINARY
|
|
|
|
#else
|
|
|
|
#define BX_RDONLY O_RDONLY
|
|
|
|
#define BX_RDWR O_RDWR
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
Boolean
|
|
|
|
bx_floppy_ctrl_c::evaluate_media(unsigned type, char *path, floppy_t *media)
|
|
|
|
{
|
|
|
|
struct stat stat_buf;
|
|
|
|
int ret;
|
|
|
|
char sTemp[1024];
|
|
|
|
|
|
|
|
if (type == BX_FLOPPY_NONE)
|
|
|
|
return(0);
|
|
|
|
|
2001-08-23 17:02:50 +04:00
|
|
|
//If media file is already open, close it before reopening.
|
|
|
|
if(media->fd >=0) {
|
|
|
|
close(media->fd);
|
|
|
|
media->fd=-1;
|
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// open media file (image file or device)
|
2001-06-13 11:06:10 +04:00
|
|
|
media->write_protected = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef macintosh
|
|
|
|
media->fd = 0;
|
2001-06-20 18:01:39 +04:00
|
|
|
if (strcmp(bx_options.floppya.Opath->getptr (), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2001-10-01 21:23:45 +04:00
|
|
|
#if BX_WITH_WIN32
|
2001-10-01 21:20:08 +04:00
|
|
|
if ( (path[1] == ':') && (strlen(path) == 2) ) {
|
|
|
|
wsprintf(sTemp, "\\\\.\\%s", path);
|
|
|
|
media->fd = open(sTemp, BX_RDWR);
|
|
|
|
} else {
|
|
|
|
media->fd = open(path, BX_RDWR);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
media->fd = open(path, BX_RDWR);
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (media->fd < 0) {
|
2001-06-13 04:30:34 +04:00
|
|
|
BX_INFO(( "tried to open %s read/write: %s",path,strerror(errno) ));
|
|
|
|
// try opening the file read-only
|
2001-06-13 11:06:10 +04:00
|
|
|
media->write_protected = 1;
|
2001-06-13 04:30:34 +04:00
|
|
|
#ifdef macintosh
|
|
|
|
media->fd = 0;
|
2001-06-20 18:01:39 +04:00
|
|
|
if (strcmp(bx_options.floppya.Opath->getptr (), SuperDrive))
|
2001-06-13 04:30:34 +04:00
|
|
|
#endif
|
2001-10-01 21:23:45 +04:00
|
|
|
#if BX_WITH_WIN32
|
2001-10-01 21:20:08 +04:00
|
|
|
if ( (path[1] == ':') && (strlen(path) == 2) ) {
|
|
|
|
wsprintf(sTemp, "\\\\.\\%s", path);
|
|
|
|
media->fd = open(sTemp, BX_RDONLY);
|
|
|
|
} else {
|
|
|
|
media->fd = open(path, BX_RDONLY);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
media->fd = open(path, BX_RDONLY);
|
2001-06-13 04:30:34 +04:00
|
|
|
#endif
|
|
|
|
if (media->fd < 0) {
|
|
|
|
// failed to open read-only too
|
|
|
|
BX_INFO(( "tried to open %s read only: %s",path,strerror(errno) ));
|
|
|
|
return(0);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-06-13 04:30:34 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-04-10 06:17:43 +04:00
|
|
|
#if BX_WITH_MACOS
|
2001-06-20 18:01:39 +04:00
|
|
|
if (!strcmp(bx_options.floppya.Opath->getptr (), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
ret = fd_stat(&stat_buf);
|
|
|
|
else
|
|
|
|
ret = fstat(media->fd, &stat_buf);
|
2001-04-10 06:17:43 +04:00
|
|
|
#elif BX_WITH_WIN32
|
2001-10-01 21:20:08 +04:00
|
|
|
// if ( (path[1] == ':') && (strlen(path) == 2) ) {
|
|
|
|
stat_buf.st_mode = S_IFCHR;
|
|
|
|
// maybe replace with code that sets ret to -1 if the disk is not available
|
|
|
|
ret = 0;
|
|
|
|
// } else {
|
|
|
|
// put code here for disk images
|
|
|
|
// ret = fstat(media->fd, &stat_buf);
|
|
|
|
// }
|
2001-04-10 06:17:43 +04:00
|
|
|
#else
|
|
|
|
// unix
|
|
|
|
ret = fstat(media->fd, &stat_buf);
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
if (ret) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("fstat()'ing floppy 0 drive image file returns error!"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( S_ISREG(stat_buf.st_mode) ) {
|
|
|
|
// regular file
|
|
|
|
switch (type) {
|
|
|
|
case BX_FLOPPY_720K: // 720K 3.5"
|
|
|
|
media->type = BX_FLOPPY_720K;
|
|
|
|
media->sectors_per_track = 9;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_2: // 1.2M 5.25"
|
|
|
|
media->type = BX_FLOPPY_1_2;
|
|
|
|
media->sectors_per_track = 15;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_44: // 1.44M 3.5"
|
|
|
|
media->type = BX_FLOPPY_1_44;
|
|
|
|
if (stat_buf.st_size <= 1474560) {
|
|
|
|
media->sectors_per_track = 18;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
}
|
|
|
|
else if (stat_buf.st_size == 1720320) {
|
|
|
|
media->sectors_per_track = 21;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
}
|
|
|
|
else if (stat_buf.st_size == 1763328) {
|
|
|
|
media->sectors_per_track = 21;
|
|
|
|
media->tracks = 82;
|
|
|
|
media->heads = 2;
|
|
|
|
}
|
|
|
|
else {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("evaluate_media: file '%s' of unknown size %lu",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
path, (unsigned long) stat_buf.st_size));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_2_88: // 2.88M 3.5"
|
|
|
|
media->type = BX_FLOPPY_2_88;
|
|
|
|
media->sectors_per_track = 36;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("evaluate_media: unknown media type"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
media->sectors = media->heads * media->tracks * media->sectors_per_track;
|
|
|
|
return(1); // success
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( S_ISCHR(stat_buf.st_mode)
|
|
|
|
#if BX_WITH_MACOS == 0
|
|
|
|
#ifdef S_ISBLK
|
2001-10-01 21:23:45 +04:00
|
|
|
|| S_ISBLK(stat_buf.st_mode)
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
// character or block device
|
|
|
|
// assume media is formatted to typical geometry for drive
|
|
|
|
switch (type) {
|
|
|
|
case BX_FLOPPY_720K: // 720K 3.5"
|
|
|
|
media->type = BX_FLOPPY_720K;
|
|
|
|
media->sectors_per_track = 9;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_2: // 1.2M 5.25"
|
|
|
|
media->type = BX_FLOPPY_1_2;
|
|
|
|
media->sectors_per_track = 15;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_44: // 1.44M 3.5"
|
|
|
|
media->type = BX_FLOPPY_1_44;
|
|
|
|
media->sectors_per_track = 18;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_2_88: // 2.88M 3.5"
|
|
|
|
media->type = BX_FLOPPY_2_88;
|
|
|
|
media->sectors_per_track = 36;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("evaluate_media: unknown media type"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
media->sectors = media->heads * media->tracks * media->sectors_per_track;
|
|
|
|
return(1); // success
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// unknown file type
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("unknown mode type"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
2001-10-01 21:20:08 +04:00
|
|
|
|