2002-06-23 22:04:07 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-01-28 12:52:09 +03:00
|
|
|
// Copyright (C) 2002-2017 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// 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
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-06-13 11:06:10 +04:00
|
|
|
//
|
2008-02-16 01:05:43 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-06-13 11:06:10 +04:00
|
|
|
//
|
|
|
|
// Floppy Disk Controller Docs:
|
|
|
|
// Intel 82077A Data sheet
|
2015-01-12 21:52:39 +03:00
|
|
|
// http://www.buchty.net/casio/files/82077.pdf
|
|
|
|
// Intel 82078AA Data sheet
|
|
|
|
// http://download.intel.com/design/archives/periphrl/docs/29047403.pdf
|
2001-06-13 11:06:10 +04:00
|
|
|
//
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
2008-01-27 01:24:03 +03:00
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
2002-10-25 01:07:56 +04:00
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
}
|
2003-12-07 18:59:32 +03:00
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
extern "C" {
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <linux/fd.h>
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2012-08-05 22:13:38 +04:00
|
|
|
#include "hdimage/hdimage.h"
|
2008-12-29 23:16:08 +03:00
|
|
|
#include "floppy.h"
|
2002-10-04 01:07:04 +04:00
|
|
|
// windows.h included by bochs.h
|
2003-12-07 18:59:32 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
extern "C" {
|
|
|
|
#include <winioctl.h>
|
|
|
|
}
|
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
#define LOG_THIS theFloppyController->
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_floppy_ctrl_c *theFloppyController;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
2005-11-22 21:34:51 +03:00
|
|
|
#define FDRIVE_NONE 0x00
|
|
|
|
#define FDRIVE_525DD 0x01
|
2009-03-23 22:05:16 +03:00
|
|
|
#define FDRIVE_525HD 0x02
|
|
|
|
#define FDRIVE_350DD 0x04
|
2005-11-22 21:34:51 +03:00
|
|
|
#define FDRIVE_350HD 0x08
|
|
|
|
#define FDRIVE_350ED 0x10
|
|
|
|
|
2003-11-24 00:54:59 +03:00
|
|
|
typedef struct {
|
|
|
|
unsigned id;
|
|
|
|
Bit8u trk;
|
|
|
|
Bit8u hd;
|
|
|
|
Bit8u spt;
|
|
|
|
unsigned sectors;
|
2005-11-22 21:34:51 +03:00
|
|
|
Bit8u drive_mask;
|
2003-11-24 00:54:59 +03:00
|
|
|
} floppy_type_t;
|
|
|
|
|
|
|
|
static floppy_type_t floppy_type[8] = {
|
2009-03-23 22:05:16 +03:00
|
|
|
{BX_FLOPPY_160K, 40, 1, 8, 320, 0x03},
|
|
|
|
{BX_FLOPPY_180K, 40, 1, 9, 360, 0x03},
|
|
|
|
{BX_FLOPPY_320K, 40, 2, 8, 640, 0x03},
|
|
|
|
{BX_FLOPPY_360K, 40, 2, 9, 720, 0x03},
|
2005-12-03 21:22:18 +03:00
|
|
|
{BX_FLOPPY_720K, 80, 2, 9, 1440, 0x1f},
|
2009-03-23 22:05:16 +03:00
|
|
|
{BX_FLOPPY_1_2, 80, 2, 15, 2400, 0x02},
|
2005-11-22 21:34:51 +03:00
|
|
|
{BX_FLOPPY_1_44, 80, 2, 18, 2880, 0x18},
|
|
|
|
{BX_FLOPPY_2_88, 80, 2, 36, 5760, 0x10}
|
2003-11-24 00:54:59 +03:00
|
|
|
};
|
|
|
|
|
2005-11-12 13:38:51 +03:00
|
|
|
static Bit16u drate_in_k[4] = {
|
|
|
|
500, 300, 250, 1000
|
|
|
|
};
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2017-01-28 12:52:09 +03:00
|
|
|
int CDECL libfloppy_LTX_plugin_init(plugin_t *plugin, plugintype_t type)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2011-12-25 12:52:34 +04:00
|
|
|
if (type == PLUGTYPE_CORE) {
|
|
|
|
theFloppyController = new bx_floppy_ctrl_c();
|
|
|
|
bx_devices.pluginFloppyDevice = theFloppyController;
|
|
|
|
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theFloppyController, BX_PLUGIN_FLOPPY);
|
|
|
|
return 0; // Success
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
2014-06-08 12:40:08 +04:00
|
|
|
void CDECL libfloppy_LTX_plugin_fini(void)
|
2006-09-10 21:18:44 +04:00
|
|
|
{
|
|
|
|
delete theFloppyController;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_floppy_ctrl_c::bx_floppy_ctrl_c()
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2013-12-31 13:20:08 +04:00
|
|
|
put("FLOPPY");
|
2012-02-05 14:08:56 +04:00
|
|
|
memset(&s, 0, sizeof(s));
|
2002-10-25 01:07:56 +04:00
|
|
|
s.floppy_timer_index = BX_NULL_TIMER_HANDLE;
|
2015-08-23 10:04:56 +03:00
|
|
|
s.statusbar_id[0] = -1;
|
|
|
|
s.statusbar_id[1] = -1;
|
|
|
|
s.rt_conf_id = -1;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_floppy_ctrl_c::~bx_floppy_ctrl_c()
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2012-08-14 23:33:24 +04:00
|
|
|
char pname[10];
|
|
|
|
|
2015-08-23 10:04:56 +03:00
|
|
|
SIM->unregister_runtime_config_handler(s.rt_conf_id);
|
2012-08-14 23:33:24 +04:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2011-01-12 01:00:41 +03:00
|
|
|
close_media(&BX_FD_THIS s.media[i]);
|
2012-08-14 23:33:24 +04:00
|
|
|
sprintf(pname, "floppy.%d", i);
|
|
|
|
bx_list_c *floppy = (bx_list_c*)SIM->get_param(pname);
|
|
|
|
SIM->get_param_string("path", floppy)->set_handler(NULL);
|
|
|
|
SIM->get_param_bool("readonly", floppy)->set_handler(NULL);
|
2013-01-23 21:56:57 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set_handler(NULL);
|
2011-01-12 01:00:41 +03:00
|
|
|
}
|
2012-08-19 12:16:20 +04:00
|
|
|
SIM->get_bochs_root()->remove("floppy");
|
2006-09-10 21:18:44 +04:00
|
|
|
BX_DEBUG(("Exit"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::init(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-03-23 22:05:16 +03:00
|
|
|
Bit8u i, devtype, cmos_value;
|
2011-01-18 00:36:00 +03:00
|
|
|
char pname[10];
|
2013-12-08 15:32:13 +04:00
|
|
|
bx_list_c *floppy;
|
2002-07-20 23:53:50 +04:00
|
|
|
|
2011-02-25 01:05:47 +03:00
|
|
|
BX_DEBUG(("Init $Id$"));
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_dma_register_8bit_channel(2, dma_read, dma_write, "Floppy Drive");
|
|
|
|
DEV_register_irq(6, "Floppy Drive");
|
2001-04-10 05:04:59 +04:00
|
|
|
for (unsigned addr=0x03F2; addr<=0x03F7; addr++) {
|
2003-07-31 23:51:42 +04:00
|
|
|
DEV_register_ioread_handler(this, read_handler, addr, "Floppy Drive", 1);
|
|
|
|
DEV_register_iowrite_handler(this, write_handler, addr, "Floppy Drive", 1);
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
2008-12-21 12:41:30 +03:00
|
|
|
cmos_value = 0x00; /* start out with: no drive 0, no drive 1 */
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
BX_FD_THIS s.num_supported_floppies = 0;
|
|
|
|
|
2002-07-20 23:53:50 +04:00
|
|
|
for (i=0; i<4; i++) {
|
2008-12-21 12:41:30 +03:00
|
|
|
BX_FD_THIS s.media[i].type = BX_FLOPPY_NONE;
|
|
|
|
BX_FD_THIS s.media[i].sectors_per_track = 0;
|
|
|
|
BX_FD_THIS s.media[i].tracks = 0;
|
|
|
|
BX_FD_THIS s.media[i].heads = 0;
|
|
|
|
BX_FD_THIS s.media[i].sectors = 0;
|
|
|
|
BX_FD_THIS s.media[i].fd = -1;
|
2011-01-11 23:14:21 +03:00
|
|
|
BX_FD_THIS s.media[i].vvfat_floppy = 0;
|
2011-08-20 00:20:25 +04:00
|
|
|
BX_FD_THIS s.media[i].status_changed = 0;
|
2008-12-21 12:41:30 +03:00
|
|
|
BX_FD_THIS s.media_present[i] = 0;
|
|
|
|
BX_FD_THIS s.device_type[i] = FDRIVE_NONE;
|
2005-11-22 21:34:51 +03:00
|
|
|
}
|
2002-07-20 23:53:50 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// Floppy A setup
|
|
|
|
//
|
|
|
|
|
2013-12-08 15:32:13 +04:00
|
|
|
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYA);
|
|
|
|
devtype = SIM->get_param_enum("devtype", floppy)->get();
|
2009-03-23 22:05:16 +03:00
|
|
|
cmos_value = (devtype << 4);
|
|
|
|
if (devtype != BX_FDD_NONE) {
|
|
|
|
BX_FD_THIS s.device_type[0] = 1 << (devtype - 1);
|
2002-08-04 12:42:34 +04:00
|
|
|
BX_FD_THIS s.num_supported_floppies++;
|
2004-02-08 21:38:26 +03:00
|
|
|
BX_FD_THIS s.statusbar_id[0] = bx_gui->register_statusitem(" A: ");
|
2004-02-07 17:34:35 +03:00
|
|
|
} else {
|
|
|
|
BX_FD_THIS s.statusbar_id[0] = -1;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2013-12-08 15:32:13 +04:00
|
|
|
if (SIM->get_param_enum("type", floppy)->get() != BX_FLOPPY_NONE) {
|
|
|
|
if (SIM->get_param_enum("status", floppy)->get() == BX_INSERTED) {
|
|
|
|
BX_FD_THIS s.media[0].write_protected = SIM->get_param_bool("readonly", floppy)->get();
|
|
|
|
if (evaluate_media(BX_FD_THIS s.device_type[0], SIM->get_param_enum("type", floppy)->get(),
|
|
|
|
SIM->get_param_string("path", floppy)->getptr(), & BX_FD_THIS s.media[0])) {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.media_present[0] = 1;
|
2001-08-31 20:06:32 +04:00
|
|
|
#define MED (BX_FD_THIS s.media[0])
|
2006-02-25 01:35:46 +03:00
|
|
|
BX_INFO(("fd0: '%s' ro=%d, h=%d,t=%d,spt=%d",
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_string("path", floppy)->getptr(),
|
2010-07-03 09:34:27 +04:00
|
|
|
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
|
|
|
|
if (MED.write_protected)
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_bool("readonly", floppy)->set(1);
|
2001-08-31 20:06:32 +04:00
|
|
|
#undef MED
|
2005-11-22 21:34:51 +03:00
|
|
|
} else {
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
2005-11-22 21:34:51 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Floppy B setup
|
|
|
|
//
|
|
|
|
|
2013-12-08 15:32:13 +04:00
|
|
|
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYB);
|
|
|
|
devtype = SIM->get_param_enum("devtype", floppy)->get();
|
2009-03-23 22:05:16 +03:00
|
|
|
cmos_value |= devtype;
|
|
|
|
if (devtype != BX_FDD_NONE) {
|
|
|
|
BX_FD_THIS s.device_type[1] = 1 << (devtype - 1);
|
2002-08-04 12:42:34 +04:00
|
|
|
BX_FD_THIS s.num_supported_floppies++;
|
2004-02-08 21:38:26 +03:00
|
|
|
BX_FD_THIS s.statusbar_id[1] = bx_gui->register_statusitem(" B: ");
|
2004-02-07 17:34:35 +03:00
|
|
|
} else {
|
|
|
|
BX_FD_THIS s.statusbar_id[1] = -1;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2013-12-08 15:32:13 +04:00
|
|
|
if (SIM->get_param_enum("type", floppy)->get() != BX_FLOPPY_NONE) {
|
|
|
|
if (SIM->get_param_enum("status", floppy)->get() == BX_INSERTED) {
|
|
|
|
BX_FD_THIS s.media[1].write_protected = SIM->get_param_bool("readonly", floppy)->get();
|
|
|
|
if (evaluate_media(BX_FD_THIS s.device_type[1], SIM->get_param_enum("type", floppy)->get(),
|
|
|
|
SIM->get_param_string("path", floppy)->getptr(), & BX_FD_THIS s.media[1])) {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.media_present[1] = 1;
|
2001-08-31 20:06:32 +04:00
|
|
|
#define MED (BX_FD_THIS s.media[1])
|
2006-02-25 01:35:46 +03:00
|
|
|
BX_INFO(("fd1: '%s' ro=%d, h=%d,t=%d,spt=%d",
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_string("path", floppy)->getptr(),
|
2010-07-03 09:34:27 +04:00
|
|
|
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
|
|
|
|
if (MED.write_protected)
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_bool("readonly", floppy)->set(1);
|
2001-08-31 20:06:32 +04:00
|
|
|
#undef MED
|
2005-11-22 21:34:51 +03:00
|
|
|
} else {
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
2005-11-22 21:34:51 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2015-07-26 09:48:33 +03:00
|
|
|
// generate CMOS values for floppy and boot sequence if not using a CMOS image
|
|
|
|
if (!SIM->get_param_bool(BXPN_CMOSIMAGE_ENABLED)->get()) {
|
|
|
|
/* CMOS Floppy Type and Equipment Byte register */
|
|
|
|
DEV_cmos_set_reg(0x10, cmos_value);
|
|
|
|
if (BX_FD_THIS s.num_supported_floppies > 0) {
|
|
|
|
DEV_cmos_set_reg(0x14, (DEV_cmos_get_reg(0x14) & 0x3e) |
|
|
|
|
((BX_FD_THIS s.num_supported_floppies-1) << 6) | 1);
|
|
|
|
} else {
|
|
|
|
DEV_cmos_set_reg(0x14, (DEV_cmos_get_reg(0x14) & 0x3e));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the "non-extended" boot device (first floppy or first hard disk).
|
|
|
|
if (SIM->get_param_enum(BXPN_BOOTDRIVE1)->get() != BX_BOOT_FLOPPYA) {
|
|
|
|
// system boot sequence C:, A:
|
|
|
|
DEV_cmos_set_reg(0x2d, DEV_cmos_get_reg(0x2d) & 0xdf);
|
|
|
|
} else { // 'a'
|
|
|
|
// system boot sequence A:, C:
|
|
|
|
DEV_cmos_set_reg(0x2d, DEV_cmos_get_reg(0x2d) | 0x20);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the "extended" boot sequence, bytes 0x38 and 0x3D (needed for cdrom booting)
|
|
|
|
BX_INFO(("Using boot sequence %s, %s, %s",
|
|
|
|
SIM->get_param_enum(BXPN_BOOTDRIVE1)->get_selected(),
|
|
|
|
SIM->get_param_enum(BXPN_BOOTDRIVE2)->get_selected(),
|
|
|
|
SIM->get_param_enum(BXPN_BOOTDRIVE3)->get_selected()));
|
|
|
|
DEV_cmos_set_reg(0x3d, SIM->get_param_enum(BXPN_BOOTDRIVE1)->get() |
|
|
|
|
(SIM->get_param_enum(BXPN_BOOTDRIVE2)->get() << 4));
|
|
|
|
|
|
|
|
// Set the signature check flag in cmos, inverted for compatibility
|
|
|
|
DEV_cmos_set_reg(0x38, SIM->get_param_bool(BXPN_FLOPPYSIGCHECK)->get() |
|
|
|
|
(SIM->get_param_enum(BXPN_BOOTDRIVE3)->get() << 4));
|
|
|
|
BX_INFO(("Floppy boot signature check is %sabled",
|
|
|
|
SIM->get_param_bool(BXPN_FLOPPYSIGCHECK)->get() ? "dis" : "en"));
|
2005-11-12 13:38:51 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-06 23:04:47 +04:00
|
|
|
if (BX_FD_THIS s.floppy_timer_index == BX_NULL_TIMER_HANDLE) {
|
|
|
|
BX_FD_THIS s.floppy_timer_index =
|
2017-03-30 21:08:15 +03:00
|
|
|
DEV_register_timer(this, timer_handler, 250, 0, 0, "floppy");
|
2002-10-06 23:04:47 +04:00
|
|
|
}
|
2007-02-09 17:23:50 +03:00
|
|
|
/* phase out s.non_dma in favor of using FD_MS_NDMA, more like hardware */
|
|
|
|
BX_FD_THIS s.main_status_reg &= ~FD_MS_NDMA; // enable DMA from start
|
2005-11-17 00:21:35 +03:00
|
|
|
/* these registers are not cleared by reset */
|
|
|
|
BX_FD_THIS s.SRT = 0;
|
|
|
|
BX_FD_THIS s.HUT = 0;
|
|
|
|
BX_FD_THIS s.HLT = 0;
|
2011-01-18 00:36:00 +03:00
|
|
|
|
|
|
|
// runtime parameters
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
sprintf(pname, "floppy.%d", i);
|
|
|
|
bx_list_c *floppy = (bx_list_c*)SIM->get_param(pname);
|
2011-01-19 00:04:44 +03:00
|
|
|
SIM->get_param_string("path", floppy)->set_handler(floppy_param_string_handler);
|
|
|
|
SIM->get_param_string("path", floppy)->set_runtime_param(1);
|
2011-01-18 00:36:00 +03:00
|
|
|
SIM->get_param_bool("readonly", floppy)->set_handler(floppy_param_handler);
|
|
|
|
SIM->get_param_bool("readonly", floppy)->set_runtime_param(1);
|
2013-01-23 21:56:57 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set_handler(floppy_param_handler);
|
|
|
|
SIM->get_param_enum("status", floppy)->set_runtime_param(1);
|
2011-01-18 00:36:00 +03:00
|
|
|
}
|
2011-08-20 00:20:25 +04:00
|
|
|
// register handler for correct floppy parameter handling after runtime config
|
2015-08-23 10:04:56 +03:00
|
|
|
BX_FD_THIS s.rt_conf_id = SIM->register_runtime_config_handler(this, runtime_config_handler);
|
2012-03-23 21:22:30 +04:00
|
|
|
#if BX_DEBUGGER
|
|
|
|
// register device for the 'info device' command (calls debug_dump())
|
|
|
|
bx_dbg_register_debug_info("floppy", this);
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::reset(unsigned type)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit32u i;
|
|
|
|
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_FD_THIS s.pending_irq = 0;
|
2002-02-06 21:51:48 +03:00
|
|
|
BX_FD_THIS s.reset_sensei = 0; /* no reset result present */
|
2001-12-27 12:30:31 +03:00
|
|
|
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.main_status_reg = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
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
|
2002-08-27 23:54:46 +04:00
|
|
|
if (type == BX_RESET_HARDWARE) {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.DOR = 0x0c;
|
|
|
|
// motor off, drive 3..0
|
|
|
|
// DMA/INT enabled
|
|
|
|
// normal operation
|
|
|
|
// drive select 0
|
|
|
|
|
2002-01-23 23:23:07 +03:00
|
|
|
// DIR and CCR affected only by hard reset
|
2002-08-13 16:02:37 +04:00
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
BX_FD_THIS s.DIR[i] |= 0x80; // disk changed
|
|
|
|
}
|
2005-11-17 00:21:35 +03:00
|
|
|
BX_FD_THIS s.data_rate = 2; /* 250 Kbps */
|
|
|
|
BX_FD_THIS s.lock = 0;
|
2005-08-25 00:45:57 +04:00
|
|
|
} else {
|
|
|
|
BX_INFO(("controller reset in software"));
|
2005-03-12 00:12:54 +03:00
|
|
|
}
|
2005-11-17 00:21:35 +03:00
|
|
|
if (BX_FD_THIS s.lock == 0) {
|
|
|
|
BX_FD_THIS s.config = 0;
|
|
|
|
BX_FD_THIS s.pretrk = 0;
|
|
|
|
}
|
|
|
|
BX_FD_THIS s.perp_mode = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
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;
|
2006-05-01 22:24:47 +04:00
|
|
|
BX_FD_THIS s.eot[i] = 0;
|
2005-11-12 13:38:51 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_pic_lower_irq(6);
|
2007-02-09 17:23:50 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_idle_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-05-27 19:54:49 +04:00
|
|
|
void bx_floppy_ctrl_c::register_state(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
char name[8];
|
|
|
|
bx_list_c *drive;
|
|
|
|
|
2012-02-12 22:43:20 +04:00
|
|
|
bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "floppy", "Floppy State");
|
2006-05-27 19:54:49 +04:00
|
|
|
new bx_shadow_num_c(list, "data_rate", &BX_FD_THIS s.data_rate);
|
2015-10-05 21:09:58 +03:00
|
|
|
new bx_shadow_data_c(list, "command", BX_FD_THIS s.command, 10, 1);
|
2006-05-27 19:54:49 +04:00
|
|
|
new bx_shadow_num_c(list, "command_index", &BX_FD_THIS s.command_index);
|
|
|
|
new bx_shadow_num_c(list, "command_size", &BX_FD_THIS s.command_size);
|
|
|
|
new bx_shadow_bool_c(list, "command_complete", &BX_FD_THIS s.command_complete);
|
|
|
|
new bx_shadow_num_c(list, "pending_command", &BX_FD_THIS s.pending_command, BASE_HEX);
|
|
|
|
new bx_shadow_bool_c(list, "multi_track", &BX_FD_THIS s.multi_track);
|
|
|
|
new bx_shadow_bool_c(list, "pending_irq", &BX_FD_THIS s.pending_irq);
|
|
|
|
new bx_shadow_num_c(list, "reset_sensei", &BX_FD_THIS s.reset_sensei);
|
|
|
|
new bx_shadow_num_c(list, "format_count", &BX_FD_THIS s.format_count);
|
|
|
|
new bx_shadow_num_c(list, "format_fillbyte", &BX_FD_THIS s.format_fillbyte, BASE_HEX);
|
2015-10-05 21:09:58 +03:00
|
|
|
new bx_shadow_data_c(list, "result", BX_FD_THIS s.result, 10, 1);
|
2006-05-27 19:54:49 +04:00
|
|
|
new bx_shadow_num_c(list, "result_index", &BX_FD_THIS s.result_index);
|
|
|
|
new bx_shadow_num_c(list, "result_size", &BX_FD_THIS s.result_size);
|
|
|
|
new bx_shadow_num_c(list, "DOR", &BX_FD_THIS s.DOR, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "TDR", &BX_FD_THIS s.TDR, BASE_HEX);
|
|
|
|
new bx_shadow_bool_c(list, "TC", &BX_FD_THIS s.TC);
|
|
|
|
new bx_shadow_num_c(list, "main_status_reg", &BX_FD_THIS s.main_status_reg, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "status_reg0", &BX_FD_THIS s.status_reg0, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "status_reg1", &BX_FD_THIS s.status_reg1, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "status_reg2", &BX_FD_THIS s.status_reg2, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "status_reg3", &BX_FD_THIS s.status_reg3, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "floppy_buffer_index", &BX_FD_THIS s.floppy_buffer_index);
|
|
|
|
new bx_shadow_bool_c(list, "lock", &BX_FD_THIS s.lock);
|
|
|
|
new bx_shadow_num_c(list, "SRT", &BX_FD_THIS s.SRT, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "HUT", &BX_FD_THIS s.HUT, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "HLT", &BX_FD_THIS s.HLT, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "config", &BX_FD_THIS s.config, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(list, "pretrk", &BX_FD_THIS s.pretrk);
|
|
|
|
new bx_shadow_num_c(list, "perp_mode", &BX_FD_THIS s.perp_mode);
|
|
|
|
new bx_shadow_data_c(list, "buffer", BX_FD_THIS s.floppy_buffer, 512);
|
|
|
|
for (i=0; i<4; i++) {
|
2015-01-26 00:24:13 +03:00
|
|
|
sprintf(name, "drive%u", i);
|
2012-02-12 22:43:20 +04:00
|
|
|
drive = new bx_list_c(list, name);
|
2006-05-27 19:54:49 +04:00
|
|
|
new bx_shadow_num_c(drive, "cylinder", &BX_FD_THIS s.cylinder[i]);
|
|
|
|
new bx_shadow_num_c(drive, "head", &BX_FD_THIS s.head[i]);
|
|
|
|
new bx_shadow_num_c(drive, "sector", &BX_FD_THIS s.sector[i]);
|
|
|
|
new bx_shadow_num_c(drive, "eot", &BX_FD_THIS s.eot[i]);
|
|
|
|
new bx_shadow_bool_c(drive, "media_present", &BX_FD_THIS s.media_present[i]);
|
|
|
|
new bx_shadow_num_c(drive, "DIR", &BX_FD_THIS s.DIR[i], BASE_HEX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 13:09:04 +04:00
|
|
|
void bx_floppy_ctrl_c::after_restore_state(void)
|
|
|
|
{
|
|
|
|
if (BX_FD_THIS s.statusbar_id[0] >= 0) {
|
|
|
|
if ((BX_FD_THIS s.DOR & 0x10) > 0)
|
|
|
|
bx_gui->statusbar_setitem(BX_FD_THIS s.statusbar_id[0], 1);
|
|
|
|
}
|
|
|
|
if (BX_FD_THIS s.statusbar_id[1] >= 0) {
|
|
|
|
if ((BX_FD_THIS s.DOR & 0x20) > 0)
|
|
|
|
bx_gui->statusbar_setitem(BX_FD_THIS s.statusbar_id[1], 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-20 00:20:25 +04:00
|
|
|
void bx_floppy_ctrl_c::runtime_config_handler(void *this_ptr)
|
|
|
|
{
|
|
|
|
bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr;
|
|
|
|
class_ptr->runtime_config();
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_floppy_ctrl_c::runtime_config(void)
|
|
|
|
{
|
|
|
|
unsigned drive;
|
|
|
|
bx_bool status;
|
|
|
|
char pname[16];
|
|
|
|
|
|
|
|
for (drive=0; drive<2; drive++) {
|
|
|
|
if (BX_FD_THIS s.media[drive].status_changed) {
|
2015-01-26 00:24:13 +03:00
|
|
|
sprintf(pname, "floppy.%u.status", drive);
|
2013-01-23 21:56:57 +04:00
|
|
|
status = (SIM->get_param_enum(pname)->get() == BX_INSERTED);
|
2011-08-20 00:20:25 +04:00
|
|
|
if (BX_FD_THIS s.media_present[drive]) {
|
|
|
|
BX_FD_THIS set_media_status(drive, 0);
|
|
|
|
}
|
|
|
|
if (status) {
|
|
|
|
BX_FD_THIS set_media_status(drive, 1);
|
|
|
|
}
|
|
|
|
BX_FD_THIS s.media[drive].status_changed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// static IO port read callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
Bit32u bx_floppy_ctrl_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_FD_SMF
|
|
|
|
bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
return class_ptr->read(address, io_len);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
/* reads from the floppy io ports */
|
|
|
|
Bit32u bx_floppy_ctrl_c::read(Bit32u address, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_FD_SMF
|
2005-08-31 23:48:03 +04:00
|
|
|
Bit8u value = 0, drive;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-02-23 11:31:41 +03:00
|
|
|
Bit8u pending_command = BX_FD_THIS s.pending_command;
|
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;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F4: /* diskette controller main status register */
|
2005-08-25 00:45:57 +04:00
|
|
|
value = BX_FD_THIS s.main_status_reg;
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F5: /* diskette controller data */
|
2007-02-09 17:23:50 +03:00
|
|
|
if ((BX_FD_THIS s.main_status_reg & FD_MS_NDMA) &&
|
2009-02-23 11:31:41 +03:00
|
|
|
((BX_FD_THIS s.pending_command & 0x4f) == 0x46)) {
|
2012-07-13 01:20:46 +04:00
|
|
|
dma_write(&value, 1);
|
2007-02-09 17:23:50 +03:00
|
|
|
lower_interrupt();
|
|
|
|
// don't enter idle phase until we've given CPU last data byte
|
|
|
|
if (BX_FD_THIS s.TC) enter_idle_phase();
|
|
|
|
} else if (BX_FD_THIS s.result_size == 0) {
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_ERROR(("port 0x3f5: no results to read"));
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
2005-08-31 23:48:03 +04:00
|
|
|
value = BX_FD_THIS s.result[0];
|
|
|
|
} else {
|
|
|
|
value = BX_FD_THIS s.result[BX_FD_THIS s.result_index++];
|
|
|
|
BX_FD_THIS s.main_status_reg &= 0xF0;
|
|
|
|
BX_FD_THIS lower_interrupt();
|
|
|
|
if (BX_FD_THIS s.result_index >= BX_FD_THIS s.result_size) {
|
|
|
|
enter_idle_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-08-31 23:48:03 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
#endif // #if BX_DMA_FLOPPY_IO
|
|
|
|
|
2002-04-11 06:21:59 +04:00
|
|
|
case 0x3F3: // Tape Drive Register
|
2005-08-25 00:45:57 +04:00
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
if (BX_FD_THIS s.media_present[drive]) {
|
2008-02-16 01:05:43 +03:00
|
|
|
switch (BX_FD_THIS s.media[drive].type) {
|
2005-08-25 00:45:57 +04:00
|
|
|
case BX_FLOPPY_160K:
|
|
|
|
case BX_FLOPPY_180K:
|
|
|
|
case BX_FLOPPY_320K:
|
|
|
|
case BX_FLOPPY_360K:
|
|
|
|
case BX_FLOPPY_1_2:
|
|
|
|
value = 0x00;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_720K:
|
|
|
|
value = 0xc0;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_1_44:
|
|
|
|
value = 0x80;
|
|
|
|
break;
|
|
|
|
case BX_FLOPPY_2_88:
|
|
|
|
value = 0x40;
|
|
|
|
break;
|
|
|
|
default: // BX_FLOPPY_NONE
|
|
|
|
value = 0x20;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-31 23:48:03 +04:00
|
|
|
} else {
|
2005-08-25 00:45:57 +04:00
|
|
|
value = 0x20;
|
2005-08-31 23:48:03 +04:00
|
|
|
}
|
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0x3F6: // Reserved for future floppy controllers
|
|
|
|
// This address shared with the hard drive controller
|
2002-10-25 01:07:56 +04:00
|
|
|
value = DEV_hd_read_handler(bx_devices.pluginHardDrive, address, io_len);
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F7: // diskette controller digital input register
|
|
|
|
// This address shared with the hard drive controller:
|
|
|
|
// Bit 7 : floppy
|
|
|
|
// Bits 6..0: hard drive
|
2002-10-25 01:07:56 +04:00
|
|
|
value = DEV_hd_read_handler(bx_devices.pluginHardDrive, address, io_len);
|
2001-04-10 05:04:59 +04:00
|
|
|
value &= 0x7f;
|
2005-09-28 21:36:01 +04:00
|
|
|
// add in diskette change line if motor is on
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
if (BX_FD_THIS s.DOR & (1<<(drive+4))) {
|
|
|
|
value |= (BX_FD_THIS s.DIR[drive] & 0x80);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
2005-08-31 23:48:03 +04:00
|
|
|
|
2002-01-18 00:20:12 +03:00
|
|
|
default:
|
|
|
|
BX_ERROR(("io_read: unsupported address 0x%04x", (unsigned) address));
|
|
|
|
return(0);
|
|
|
|
break;
|
2005-08-31 23:48:03 +04:00
|
|
|
}
|
2009-02-23 11:31:41 +03:00
|
|
|
BX_DEBUG(("read(): during command 0x%02x, port 0x%04x returns 0x%02x",
|
|
|
|
pending_command, address, value));
|
2005-08-31 23:48:03 +04:00
|
|
|
return (value);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// static IO port write callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_FD_SMF
|
|
|
|
bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr;
|
|
|
|
class_ptr->write(address, value, io_len);
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
/* writes to the floppy io ports */
|
|
|
|
void bx_floppy_ctrl_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#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;
|
|
|
|
|
2009-02-23 11:31:41 +03:00
|
|
|
BX_DEBUG(("write access to port 0x%04x, value=0x%02x", address, 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_drive0 = value & 0x10;
|
2004-02-08 13:25:50 +03:00
|
|
|
motor_on_drive1 = value & 0x20;
|
2004-02-07 17:34:35 +03:00
|
|
|
/* set status bar conditions for Floppy 0 and Floppy 1 */
|
2004-02-08 13:25:50 +03:00
|
|
|
if (BX_FD_THIS s.statusbar_id[0] >= 0) {
|
|
|
|
if (motor_on_drive0 != (BX_FD_THIS s.DOR & 0x10))
|
|
|
|
bx_gui->statusbar_setitem(BX_FD_THIS s.statusbar_id[0], motor_on_drive0);
|
|
|
|
}
|
|
|
|
if (BX_FD_THIS s.statusbar_id[1] >= 0) {
|
|
|
|
if (motor_on_drive1 != (BX_FD_THIS s.DOR & 0x20))
|
|
|
|
bx_gui->statusbar_setitem(BX_FD_THIS s.statusbar_id[1], motor_on_drive1);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
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
|
2005-11-09 22:13:32 +03:00
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index, 250, 0);
|
2005-10-09 21:58:37 +04:00
|
|
|
} else if (prev_normal_operation && normal_operation==0) {
|
2001-04-10 05:04:59 +04:00
|
|
|
// transition from NORMAL to RESET
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.pending_command = 0xfe; // RESET pending
|
2005-10-09 21:58:37 +04:00
|
|
|
}
|
|
|
|
BX_DEBUG(("io_write: digital output register"));
|
|
|
|
BX_DEBUG((" motor on, drive0 = %d", motor_on_drive0 > 0));
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG((" motor on, drive1 = %d", motor_on_drive1 > 0));
|
2005-10-09 21:58:37 +04:00
|
|
|
BX_DEBUG((" dma_and_interrupt_enable=%02x",
|
|
|
|
(unsigned) dma_and_interrupt_enable));
|
|
|
|
BX_DEBUG((" normal_operation=%02x",
|
|
|
|
(unsigned) normal_operation));
|
|
|
|
BX_DEBUG((" drive_select=%02x",
|
|
|
|
(unsigned) drive_select));
|
2005-12-23 15:21:09 +03:00
|
|
|
if (BX_FD_THIS s.device_type[drive_select] == FDRIVE_NONE) {
|
2009-02-23 11:31:41 +03:00
|
|
|
BX_DEBUG(("WARNING: non existing drive selected"));
|
2005-10-09 21:58:37 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3f4: /* diskette controller data rate select register */
|
2005-11-17 00:21:35 +03:00
|
|
|
BX_FD_THIS s.data_rate = value & 0x03;
|
|
|
|
if (value & 0x80) {
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
2005-11-17 00:21:35 +03:00
|
|
|
BX_FD_THIS s.pending_command = 0xfe; // RESET pending
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index, 250, 0);
|
|
|
|
}
|
|
|
|
if ((value & 0x7c) > 0) {
|
|
|
|
BX_ERROR(("write to data rate select register: unsupported bits set"));
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3F5: /* diskette controller data */
|
2009-02-23 11:31:41 +03:00
|
|
|
BX_DEBUG(("command = 0x%02x", (unsigned) value));
|
2007-02-09 17:23:50 +03:00
|
|
|
if ((BX_FD_THIS s.main_status_reg & FD_MS_NDMA) && ((BX_FD_THIS s.pending_command & 0x4f) == 0x45)) {
|
2012-07-13 01:20:46 +04:00
|
|
|
BX_FD_THIS dma_read((Bit8u *) &value, 1);
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS lower_interrupt();
|
|
|
|
break;
|
|
|
|
} else if (BX_FD_THIS s.command_complete) {
|
2005-10-09 21:58:37 +04:00
|
|
|
if (BX_FD_THIS s.pending_command != 0)
|
|
|
|
BX_PANIC(("write 0x03f5: receiving new command 0x%02x, old one (0x%02x) pending",
|
|
|
|
value, 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 */
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= ~FD_MS_DIO; // leave drive status untouched
|
2005-08-31 23:48:03 +04:00
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_MRQ | FD_MS_BUSY;
|
2001-04-10 05:04:59 +04:00
|
|
|
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;
|
|
|
|
break;
|
|
|
|
case 0x0f: /* seek */
|
|
|
|
BX_FD_THIS s.command_size = 3;
|
|
|
|
break;
|
|
|
|
case 0x4a: /* read ID */
|
|
|
|
BX_FD_THIS s.command_size = 2;
|
|
|
|
break;
|
2001-12-28 19:38:13 +03:00
|
|
|
case 0x4d: /* format track */
|
|
|
|
BX_FD_THIS s.command_size = 6;
|
|
|
|
break;
|
|
|
|
case 0x45:
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0xc5: /* write normal data */
|
|
|
|
BX_FD_THIS s.command_size = 9;
|
|
|
|
break;
|
2002-07-16 00:11:33 +04:00
|
|
|
case 0x46:
|
2001-12-28 19:38:13 +03:00
|
|
|
case 0x66:
|
2002-07-16 00:11:33 +04:00
|
|
|
case 0xc6:
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0xe6: /* read normal data */
|
|
|
|
BX_FD_THIS s.command_size = 9;
|
|
|
|
break;
|
|
|
|
|
2005-11-17 00:21:35 +03:00
|
|
|
case 0x0e: // dump registers (Enhanced drives)
|
|
|
|
case 0x10: // Version command, enhanced controller returns 0x90
|
|
|
|
case 0x14: // Unlock command (Enhanced)
|
|
|
|
case 0x94: // Lock command (Enhanced)
|
|
|
|
BX_FD_THIS s.command_size = 0;
|
|
|
|
BX_FD_THIS s.pending_command = value;
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG(("COMMAND: [%02x]", value));
|
2005-11-17 00:21:35 +03:00
|
|
|
enter_result_phase();
|
|
|
|
break;
|
|
|
|
case 0x12: // Perpendicular mode (Enhanced)
|
|
|
|
BX_FD_THIS s.command_size = 2;
|
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0x13: // Configure command (Enhanced)
|
2002-01-18 00:20:12 +03:00
|
|
|
BX_FD_THIS s.command_size = 4;
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
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.
|
|
|
|
default:
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG(("COMMAND: [%02x]", value));
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_ERROR(("io_write: 0x3f5: invalid floppy command 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));
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.command_size = 0; // make sure we don't try to process this command
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_FD_THIS s.status_reg0 = 0x80; // status: invalid command
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_result_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
}
|
2005-11-17 00:21:35 +03:00
|
|
|
} else {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.command[BX_FD_THIS s.command_index++] =
|
|
|
|
value;
|
2005-11-17 00:21:35 +03:00
|
|
|
}
|
2001-12-27 12:30:31 +03:00
|
|
|
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;
|
2005-11-17 00:21:35 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
#endif // #if BX_DMA_FLOPPY_IO
|
|
|
|
|
|
|
|
case 0x3F6: /* diskette controller (reserved) */
|
2002-10-21 20:57:35 +04:00
|
|
|
BX_DEBUG(("io_write: reserved register 0x3f6 unsupported"));
|
2001-04-10 05:04:59 +04:00
|
|
|
// this address shared with the hard drive controller
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_hd_write_handler(bx_devices.pluginHardDrive, address, value, io_len);
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
#if BX_DMA_FLOPPY_IO
|
|
|
|
case 0x3F7: /* diskette controller configuration control register */
|
2006-08-12 15:22:40 +04:00
|
|
|
if ((value & 0x03) != BX_FD_THIS s.data_rate)
|
|
|
|
BX_INFO(("io_write: config control register: 0x%02x", value));
|
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
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-10-06 23:38:54 +04:00
|
|
|
BX_ERROR(("io_write ignored: 0x%04x = 0x%02x", (unsigned) address, (unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
#endif // #if BX_DMA_FLOPPY_IO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::floppy_command(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-11-20 17:15:28 +03:00
|
|
|
unsigned i;
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit8u motor_on;
|
|
|
|
Bit8u head, drive, cylinder, sector, eot;
|
2011-10-01 00:38:18 +04:00
|
|
|
Bit8u sector_size;
|
|
|
|
//Bit8u data_length;
|
2005-11-12 13:38:51 +03:00
|
|
|
Bit32u logical_sector, sector_time, step_delay;
|
2005-11-20 17:15:28 +03:00
|
|
|
|
2005-08-25 00:45:57 +04:00
|
|
|
// Print command
|
|
|
|
char buf[9+(9*5)+1], *p = buf;
|
|
|
|
p += sprintf(p, "COMMAND: ");
|
|
|
|
for (i=0; i<BX_FD_THIS s.command_size; i++) {
|
|
|
|
p += sprintf(p, "[%02x] ", (unsigned) BX_FD_THIS s.command[i]);
|
|
|
|
}
|
2010-03-02 10:07:57 +03:00
|
|
|
BX_DEBUG(("%s", buf));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.pending_command = BX_FD_THIS s.command[0];
|
|
|
|
switch (BX_FD_THIS s.pending_command) {
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0x03: // specify
|
|
|
|
// execution: specified parameters are loaded
|
|
|
|
// result: no result bytes, no interrupt
|
2005-11-12 13:38:51 +03:00
|
|
|
BX_FD_THIS s.SRT = BX_FD_THIS s.command[1] >> 4;
|
2005-11-17 00:21:35 +03:00
|
|
|
BX_FD_THIS s.HUT = BX_FD_THIS s.command[1] & 0x0f;
|
|
|
|
BX_FD_THIS s.HLT = BX_FD_THIS s.command[2] >> 1;
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg |= (BX_FD_THIS s.command[2] & 0x01) ? FD_MS_NDMA : 0;
|
|
|
|
if (BX_FD_THIS s.main_status_reg & FD_MS_NDMA)
|
|
|
|
BX_ERROR(("non DMA mode not fully implemented yet"));
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG(("Specify (SRT = 0x%02x)", (BX_FD_THIS s.command[1] & 0xF0) >> 4));
|
|
|
|
BX_DEBUG((" (HUT = 0x%02x)", (BX_FD_THIS s.command[1] & 0x0F) >> 0));
|
|
|
|
BX_DEBUG((" (HLT = 0x%02x)", (BX_FD_THIS s.command[2] & 0xFE) >> 1));
|
|
|
|
BX_DEBUG((" (Non-DMA = %d)", (BX_FD_THIS s.command[2] & 0x01) >> 0));
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_idle_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x04: // get status
|
2001-06-13 11:06:10 +04:00
|
|
|
drive = (BX_FD_THIS s.command[1] & 0x03);
|
2002-07-20 23:53:50 +04:00
|
|
|
BX_FD_THIS s.head[drive] = (BX_FD_THIS s.command[1] >> 2) & 0x01;
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.status_reg3 = 0x28 | (BX_FD_THIS s.head[drive]<<2) | drive
|
2001-12-28 19:38:13 +03:00
|
|
|
| (BX_FD_THIS s.media[drive].write_protected ? 0x40 : 0x00);
|
2009-03-08 11:22:23 +03:00
|
|
|
if ((BX_FD_THIS s.device_type[drive] != FDRIVE_NONE) &&
|
|
|
|
(BX_FD_THIS s.cylinder[drive] == 0))
|
|
|
|
BX_FD_THIS s.status_reg3 |= 0x10;
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_result_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x07: // recalibrate
|
|
|
|
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));
|
2005-11-12 13:38:51 +03:00
|
|
|
step_delay = calculate_step_delay(drive, 0);
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index, step_delay, 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
|
2002-11-30 12:39:29 +03:00
|
|
|
* The last two are taken care of in timer().
|
2001-04-10 05:04:59 +04:00
|
|
|
*/
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.cylinder[drive] = 0;
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= (1 << drive);
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x08: /* sense interrupt status */
|
|
|
|
/* execution:
|
|
|
|
* get status
|
|
|
|
* result:
|
|
|
|
* no interupt
|
|
|
|
* byte0 = status reg0
|
|
|
|
* byte1 = current cylinder number (0 to 79)
|
|
|
|
*/
|
2005-08-31 23:48:03 +04:00
|
|
|
if (BX_FD_THIS s.reset_sensei > 0) {
|
|
|
|
drive = 4 - BX_FD_THIS s.reset_sensei;
|
|
|
|
BX_FD_THIS s.status_reg0 &= 0xf8;
|
|
|
|
BX_FD_THIS s.status_reg0 |= (BX_FD_THIS s.head[drive] << 2) | drive;
|
|
|
|
BX_FD_THIS s.reset_sensei--;
|
|
|
|
} else if (!BX_FD_THIS s.pending_irq) {
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_FD_THIS s.status_reg0 = 0x80;
|
2005-08-31 23:48:03 +04:00
|
|
|
}
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("sense interrupt status"));
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_result_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x0f: /* seek */
|
|
|
|
/* 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;
|
2005-11-12 13:38:51 +03:00
|
|
|
step_delay = calculate_step_delay(drive, BX_FD_THIS s.command[2]);
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index, step_delay, 0);
|
2001-04-10 05:04:59 +04:00
|
|
|
/* ??? should also check cylinder validity */
|
2005-11-12 13:38:51 +03:00
|
|
|
BX_FD_THIS s.cylinder[drive] = BX_FD_THIS s.command[2];
|
2007-02-09 17:23:50 +03:00
|
|
|
/* data reg not ready, drive not busy */
|
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= (1 << drive);
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x13: // Configure
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG(("configure (eis = %d)", (BX_FD_THIS s.command[2] & 0x40) ? 1 : 0));
|
|
|
|
BX_DEBUG(("configure (efifo = %d)", (BX_FD_THIS s.command[2] & 0x20) ? 1 : 0));
|
|
|
|
BX_DEBUG(("configure (no poll = %d)", (BX_FD_THIS s.command[2] & 0x10) ? 1 : 0));
|
|
|
|
BX_DEBUG(("configure (fifothr = %d)", BX_FD_THIS s.command[2] & 0x0f));
|
|
|
|
BX_DEBUG(("configure (pretrk = %d)", BX_FD_THIS s.command[3]));
|
2005-11-17 00:21:35 +03:00
|
|
|
BX_FD_THIS s.config = BX_FD_THIS s.command[2];
|
|
|
|
BX_FD_THIS s.pretrk = BX_FD_THIS s.command[3];
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_idle_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x4a: // read ID
|
|
|
|
drive = BX_FD_THIS s.command[1] & 0x03;
|
2002-07-16 23:36:40 +04:00
|
|
|
BX_FD_THIS s.head[drive] = (BX_FD_THIS s.command[1] >> 2) & 0x01;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.DOR &= 0xfc;
|
|
|
|
BX_FD_THIS s.DOR |= drive;
|
|
|
|
|
|
|
|
motor_on = (BX_FD_THIS s.DOR>>(drive+4)) & 0x01;
|
2001-12-27 12:30:31 +03:00
|
|
|
if (motor_on == 0) {
|
2005-12-25 15:03:14 +03:00
|
|
|
BX_ERROR(("floppy_command(): read ID: motor not on"));
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_BUSY;
|
2005-12-25 15:03:14 +03:00
|
|
|
return; // Hang controller
|
|
|
|
}
|
2005-12-23 15:21:09 +03:00
|
|
|
if (BX_FD_THIS s.device_type[drive] == FDRIVE_NONE) {
|
2005-12-25 15:03:14 +03:00
|
|
|
BX_ERROR(("floppy_command(): read ID: bad drive #%d", drive));
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_BUSY;
|
2005-12-25 15:03:14 +03:00
|
|
|
return; // Hang controller
|
|
|
|
}
|
2005-08-25 00:45:57 +04:00
|
|
|
if (BX_FD_THIS s.media_present[drive] == 0) {
|
|
|
|
BX_INFO(("attempt to read sector ID with media not present"));
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_BUSY;
|
2005-08-25 00:45:57 +04:00
|
|
|
return; // Hang controller
|
2005-12-25 15:03:14 +03:00
|
|
|
}
|
2015-01-12 21:52:39 +03:00
|
|
|
// if the media doesn't have 2 heads, and we tried to ReadID from the second head,
|
|
|
|
// give abnormal termination in ST0 and ST1
|
|
|
|
if (((unsigned int) BX_FD_THIS s.head[drive] + 1) > BX_FD_THIS s.media[drive].heads) {
|
|
|
|
BX_ERROR(("attempt to access from non-present head"));
|
|
|
|
// ST0: IC1,0=01 (abnormal termination: started execution but failed)
|
|
|
|
BX_FD_THIS s.status_reg0 = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive;
|
|
|
|
BX_FD_THIS s.status_reg1 = 1; // missing address mark
|
|
|
|
BX_FD_THIS s.head[drive] = 0;
|
|
|
|
} else
|
|
|
|
BX_FD_THIS s.status_reg0 = (BX_FD_THIS s.head[drive]<<2) | drive;
|
2005-11-09 22:13:32 +03:00
|
|
|
// time to read one sector at 300 rpm
|
|
|
|
sector_time = 200000 / BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index, sector_time, 0);
|
2001-04-10 05:04:59 +04:00
|
|
|
/* data reg not ready, controller busy */
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_BUSY;
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
|
2001-12-28 19:38:13 +03:00
|
|
|
case 0x4d: // format track
|
|
|
|
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)
|
|
|
|
BX_PANIC(("floppy_command(): format track: motor not on"));
|
|
|
|
BX_FD_THIS s.head[drive] = (BX_FD_THIS s.command[1] >> 2) & 0x01;
|
|
|
|
sector_size = BX_FD_THIS s.command[2];
|
|
|
|
BX_FD_THIS s.format_count = BX_FD_THIS s.command[3];
|
|
|
|
BX_FD_THIS s.format_fillbyte = BX_FD_THIS s.command[5];
|
2005-12-23 15:21:09 +03:00
|
|
|
if (BX_FD_THIS s.device_type[drive] == FDRIVE_NONE)
|
2002-07-20 23:53:50 +04:00
|
|
|
BX_PANIC(("floppy_command(): format track: bad drive #%d", drive));
|
2001-12-28 19:38:13 +03:00
|
|
|
|
|
|
|
if (sector_size != 0x02) { // 512 bytes
|
2003-06-20 20:28:00 +04:00
|
|
|
BX_PANIC(("format track: sector size %d not supported", 128<<sector_size));
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-12-28 19:38:13 +03:00
|
|
|
if (BX_FD_THIS s.format_count != BX_FD_THIS s.media[drive].sectors_per_track) {
|
2003-06-20 20:28:00 +04:00
|
|
|
BX_PANIC(("format track: %d sectors/track requested (%d expected)",
|
|
|
|
BX_FD_THIS s.format_count, BX_FD_THIS s.media[drive].sectors_per_track));
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
|
|
|
if (BX_FD_THIS s.media_present[drive] == 0) {
|
2001-12-28 19:38:13 +03:00
|
|
|
BX_INFO(("attempt to format track with media not present"));
|
2005-08-25 00:45:57 +04:00
|
|
|
return; // Hang controller
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-12-28 19:38:13 +03:00
|
|
|
if (BX_FD_THIS s.media[drive].write_protected) {
|
|
|
|
// media write-protected, return error
|
|
|
|
BX_INFO(("attempt to format track with media write-protected"));
|
|
|
|
BX_FD_THIS s.status_reg0 = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive; // abnormal termination
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.status_reg1 = 0x27; // 0010 0111
|
|
|
|
BX_FD_THIS s.status_reg2 = 0x31; // 0011 0001
|
|
|
|
enter_result_phase();
|
2001-12-28 19:38:13 +03:00
|
|
|
return;
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-12-28 19:38:13 +03:00
|
|
|
|
|
|
|
/* 4 header bytes per sector are required */
|
|
|
|
BX_FD_THIS s.format_count <<= 2;
|
|
|
|
|
2007-02-09 17:23:50 +03:00
|
|
|
if (BX_FD_THIS s.main_status_reg & FD_MS_NDMA) {
|
|
|
|
BX_DEBUG(("non-DMA floppy format unimplemented"));
|
|
|
|
} else {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 1);
|
|
|
|
}
|
2001-12-28 19:38:13 +03:00
|
|
|
/* data reg not ready, controller busy */
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_BUSY;
|
2001-12-28 19:38:13 +03:00
|
|
|
BX_DEBUG(("format track"));
|
|
|
|
return;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-07-16 00:11:33 +04:00
|
|
|
case 0x46: // read normal data, MT=0, SK=0
|
|
|
|
case 0x66: // read normal data, MT=0, SK=1
|
|
|
|
case 0xc6: // read normal data, MT=1, SK=0
|
|
|
|
case 0xe6: // read normal data, MT=1, SK=1
|
2001-12-28 19:38:13 +03:00
|
|
|
case 0x45: // write normal data, MT=0
|
|
|
|
case 0xc5: // write normal data, MT=1
|
|
|
|
BX_FD_THIS s.multi_track = (BX_FD_THIS s.command[0] >> 7);
|
2008-02-16 01:05:43 +03: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];
|
2011-10-01 00:38:18 +04:00
|
|
|
// 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((" cylinder = %u", (unsigned) cylinder));
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG((" head = %u", (unsigned) head));
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG((" sector = %u", (unsigned) sector));
|
|
|
|
BX_DEBUG((" eot = %u", (unsigned) eot));
|
2005-12-23 15:21:09 +03:00
|
|
|
if (BX_FD_THIS s.device_type[drive] == FDRIVE_NONE)
|
2002-07-20 23:53:50 +04:00
|
|
|
BX_PANIC(("floppy_command(): read/write: bad drive #%d", drive));
|
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
|
2001-12-28 19:38:13 +03:00
|
|
|
// picky about this, as reported in SF bug #439945, (Floppy drive
|
2001-09-29 07:29:27 +04:00
|
|
|
// read input error checking).
|
2002-06-23 22:04:07 +04:00
|
|
|
if (head != ((BX_FD_THIS s.command[1]>>2)&1)) {
|
2001-09-29 07:29:27 +04:00
|
|
|
BX_ERROR(("head number in command[1] doesn't match head field"));
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_FD_THIS s.status_reg0 = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive; // abnormal termination
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.status_reg1 = 0x04; // 0000 0100
|
|
|
|
BX_FD_THIS s.status_reg2 = 0x00; // 0000 0000
|
|
|
|
enter_result_phase();
|
2001-09-29 07:29:27 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
if (BX_FD_THIS s.media_present[drive] == 0) {
|
2005-08-25 00:45:57 +04:00
|
|
|
BX_INFO(("attempt to read/write sector %u with media not present", (unsigned) sector));
|
|
|
|
return; // Hang controller
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (sector_size != 0x02) { // 512 bytes
|
2003-06-20 20:28:00 +04:00
|
|
|
BX_PANIC(("read/write command: sector size %d not supported", 128<<sector_size));
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2005-08-25 00:45:57 +04:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
if (cylinder >= BX_FD_THIS s.media[drive].tracks) {
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_PANIC(("io: norm r/w parms out of range: sec#%02xh cyl#%02xh eot#%02xh 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) {
|
2005-08-25 00:45:57 +04:00
|
|
|
BX_INFO(("attempt to read/write sector %u past last sector %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.cylinder[drive] = cylinder;
|
|
|
|
BX_FD_THIS s.head[drive] = head;
|
2005-12-03 21:22:18 +03:00
|
|
|
BX_FD_THIS s.sector[drive] = sector;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_FD_THIS s.status_reg0 = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive;
|
2005-12-03 21:22:18 +03:00
|
|
|
BX_FD_THIS s.status_reg1 = 0x04;
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.status_reg2 = 0x00;
|
2002-12-11 18:41:24 +03:00
|
|
|
enter_result_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
2005-10-27 11:38:20 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-11-20 17:15:28 +03:00
|
|
|
if (cylinder != BX_FD_THIS s.cylinder[drive]) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("io: cylinder request != current cylinder"));
|
2005-11-20 17:15:28 +03:00
|
|
|
reset_changeline();
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-10-27 11:38:20 +04:00
|
|
|
logical_sector = (cylinder * BX_FD_THIS s.media[drive].heads * BX_FD_THIS s.media[drive].sectors_per_track) +
|
2001-04-10 05:04:59 +04:00
|
|
|
(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"));
|
2005-10-27 11:38:20 +04:00
|
|
|
}
|
|
|
|
// This hack makes older versions of the Bochs BIOS work
|
|
|
|
if (eot == 0) {
|
|
|
|
eot = BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.cylinder[drive] = cylinder;
|
|
|
|
BX_FD_THIS s.head[drive] = head;
|
2005-08-25 00:45:57 +04:00
|
|
|
BX_FD_THIS s.sector[drive] = sector;
|
2005-10-27 11:38:20 +04:00
|
|
|
BX_FD_THIS s.eot[drive] = eot;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-07-16 00:11:33 +04:00
|
|
|
if ((BX_FD_THIS s.command[0] & 0x4f) == 0x46) { // read
|
2001-04-10 05:04:59 +04:00
|
|
|
floppy_xfer(drive, logical_sector*512, BX_FD_THIS s.floppy_buffer,
|
|
|
|
512, FROM_FLOPPY);
|
2007-02-09 17:23:50 +03:00
|
|
|
/* controller busy; if DMA mode, data reg not ready */
|
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_BUSY;
|
|
|
|
if (BX_FD_THIS s.main_status_reg & FD_MS_NDMA) {
|
|
|
|
BX_FD_THIS s.main_status_reg |= (FD_MS_MRQ | FD_MS_DIO);
|
|
|
|
}
|
2005-08-31 23:48:03 +04:00
|
|
|
// time to read one sector at 300 rpm
|
|
|
|
sector_time = 200000 / BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index,
|
|
|
|
sector_time , 0);
|
|
|
|
} else if ((BX_FD_THIS s.command[0] & 0x7f) == 0x45) { // write
|
2007-02-09 17:23:50 +03:00
|
|
|
/* controller busy; if DMA mode, data reg not ready */
|
|
|
|
BX_FD_THIS s.main_status_reg &= FD_MS_NDMA;
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_BUSY;
|
|
|
|
if (BX_FD_THIS s.main_status_reg & FD_MS_NDMA) {
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_MRQ;
|
|
|
|
} else {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 1);
|
|
|
|
}
|
2005-08-31 23:48:03 +04:00
|
|
|
} else {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("floppy_command(): unknown read/write command"));
|
2005-08-31 23:48:03 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
2005-11-17 00:21:35 +03:00
|
|
|
case 0x12: // Perpendicular mode
|
|
|
|
BX_FD_THIS s.perp_mode = BX_FD_THIS s.command[1];
|
|
|
|
BX_INFO(("perpendicular mode: config=0x%02x", BX_FD_THIS s.perp_mode));
|
|
|
|
enter_idle_phase();
|
|
|
|
break;
|
|
|
|
|
2002-11-30 12:39:29 +03:00
|
|
|
default: // invalid or unsupported command; these are captured in write() above
|
2008-01-27 01:24:03 +03:00
|
|
|
BX_PANIC(("You should never get here! cmd = 0x%02x",
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.command[0]));
|
2005-08-31 23:48:03 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit32u bytes, Bit8u direction)
|
|
|
|
{
|
2004-11-16 22:19:13 +03:00
|
|
|
int ret = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-12-23 15:21:09 +03:00
|
|
|
if (BX_FD_THIS s.device_type[drive] == FDRIVE_NONE)
|
2002-07-20 23:53:50 +04:00
|
|
|
BX_PANIC(("floppy_xfer: bad drive #%d", drive));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-04-24 18:57:25 +04:00
|
|
|
BX_DEBUG(("floppy_xfer: drive=%u, offset=%u, bytes=%u, direction=%s floppy",
|
|
|
|
drive, offset, bytes, (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
|
2013-12-08 15:32:13 +04:00
|
|
|
const char *pname = (drive == 0) ? BXPN_FLOPPYA_PATH : BXPN_FLOPPYB_PATH;
|
|
|
|
if (strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2006-03-08 00:11:20 +03:00
|
|
|
{
|
2011-01-13 01:35:32 +03:00
|
|
|
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
|
|
|
|
ret = (int)BX_FD_THIS s.media[drive].vvfat->lseek(offset, SEEK_SET);
|
2011-08-22 21:57:21 +04:00
|
|
|
} else {
|
2011-01-13 01:35:32 +03:00
|
|
|
ret = (int)lseek(BX_FD_THIS s.media[drive].fd, offset, SEEK_SET);
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
|
|
|
BX_PANIC(("could not perform lseek() to %d on floppy image file", offset));
|
|
|
|
return;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (direction == FROM_FLOPPY) {
|
2011-01-13 01:35:32 +03:00
|
|
|
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
|
2014-01-25 21:07:10 +04:00
|
|
|
ret = (int)BX_FD_THIS s.media[drive].vvfat->read(buffer, bytes);
|
2001-09-26 04:19:44 +04:00
|
|
|
#if BX_WITH_MACOS
|
2015-01-07 19:17:40 +03:00
|
|
|
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive)) {
|
2001-04-10 05:04:59 +04:00
|
|
|
ret = fd_read((char *) buffer, offset, bytes);
|
|
|
|
#endif
|
2011-01-13 01:35:32 +03:00
|
|
|
} else {
|
|
|
|
ret = ::read(BX_FD_THIS s.media[drive].fd, (bx_ptr_t) buffer, bytes);
|
2004-05-31 18:47:12 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
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);
|
2011-08-22 21:57:21 +04:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
2011-08-22 21:57:21 +04:00
|
|
|
} else { // TO_FLOPPY
|
2001-06-13 11:06:10 +04:00
|
|
|
BX_ASSERT (!BX_FD_THIS s.media[drive].write_protected);
|
2011-01-13 01:35:32 +03:00
|
|
|
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
|
2014-01-25 21:07:10 +04:00
|
|
|
ret = (int)BX_FD_THIS s.media[drive].vvfat->write(buffer, bytes);
|
2001-09-26 21:35:51 +04:00
|
|
|
#if BX_WITH_MACOS
|
2015-01-07 19:17:40 +03:00
|
|
|
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive)) {
|
2001-04-10 05:04:59 +04:00
|
|
|
ret = fd_write((char *) buffer, offset, bytes);
|
2011-01-11 23:14:21 +03:00
|
|
|
#endif
|
2011-01-13 01:35:32 +03:00
|
|
|
} else {
|
|
|
|
ret = ::write(BX_FD_THIS s.media[drive].fd, (bx_ptr_t) buffer, bytes);
|
2004-05-31 18:47:12 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::timer_handler(void *this_ptr)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr;
|
|
|
|
class_ptr->timer();
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::timer()
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2005-12-23 15:21:09 +03:00
|
|
|
Bit8u drive, motor_on;
|
2001-12-27 12:30:31 +03:00
|
|
|
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
2006-03-08 00:11:20 +03:00
|
|
|
switch (BX_FD_THIS s.pending_command) {
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0x07: // recal
|
2005-12-25 15:03:14 +03:00
|
|
|
BX_FD_THIS s.status_reg0 = 0x20 | drive;
|
2005-12-23 15:21:09 +03:00
|
|
|
motor_on = ((BX_FD_THIS s.DOR>>(drive+4)) & 0x01);
|
|
|
|
if ((BX_FD_THIS s.device_type[drive] == FDRIVE_NONE) || (motor_on == 0)) {
|
2002-07-20 23:53:50 +04:00
|
|
|
BX_FD_THIS s.status_reg0 |= 0x50;
|
2005-12-23 15:21:09 +03:00
|
|
|
}
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_idle_phase();
|
2005-03-12 00:12:54 +03:00
|
|
|
BX_FD_THIS raise_interrupt();
|
2001-12-27 12:30:31 +03:00
|
|
|
break;
|
|
|
|
|
2005-12-25 15:03:14 +03:00
|
|
|
case 0x0f: // seek
|
|
|
|
BX_FD_THIS s.status_reg0 = 0x20 | (BX_FD_THIS s.head[drive]<<2) | drive;
|
|
|
|
enter_idle_phase();
|
|
|
|
BX_FD_THIS raise_interrupt();
|
|
|
|
break;
|
|
|
|
|
2002-11-30 12:39:29 +03:00
|
|
|
case 0x4a: /* read ID */
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG(("AFTER"));
|
|
|
|
BX_DEBUG((" drive = %u", drive));
|
|
|
|
BX_DEBUG((" cylinder = %u", BX_FD_THIS s.cylinder[drive]));
|
|
|
|
BX_DEBUG((" head = %u", BX_FD_THIS s.head[drive]));
|
|
|
|
BX_DEBUG((" sector = %u", BX_FD_THIS s.sector[drive]));
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_result_phase();
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
2005-11-10 21:56:45 +03:00
|
|
|
case 0x45: /* write normal data */
|
|
|
|
case 0xc5:
|
|
|
|
if (BX_FD_THIS s.TC) { // Terminal Count line, done
|
|
|
|
BX_FD_THIS s.status_reg0 = (BX_FD_THIS s.head[drive] << 2) | drive;
|
|
|
|
BX_FD_THIS s.status_reg1 = 0;
|
|
|
|
BX_FD_THIS s.status_reg2 = 0;
|
|
|
|
|
2009-04-24 18:57:25 +04:00
|
|
|
BX_DEBUG(("<<WRITE DONE>>"));
|
|
|
|
BX_DEBUG(("AFTER"));
|
|
|
|
BX_DEBUG((" drive = %u", drive));
|
|
|
|
BX_DEBUG((" cylinder = %u", BX_FD_THIS s.cylinder[drive]));
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG((" head = %u", BX_FD_THIS s.head[drive]));
|
2009-04-24 18:57:25 +04:00
|
|
|
BX_DEBUG((" sector = %u", BX_FD_THIS s.sector[drive]));
|
2005-11-10 21:56:45 +03:00
|
|
|
|
|
|
|
enter_result_phase();
|
|
|
|
} else {
|
|
|
|
// transfer next sector
|
2007-02-09 17:23:50 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 1);
|
|
|
|
}
|
2005-11-10 21:56:45 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-09-03 21:20:18 +04:00
|
|
|
case 0x46: /* read normal data */
|
2005-08-31 23:48:03 +04:00
|
|
|
case 0x66:
|
|
|
|
case 0xc6:
|
|
|
|
case 0xe6:
|
|
|
|
// transfer next sector
|
2007-02-09 17:23:50 +03:00
|
|
|
if (BX_FD_THIS s.main_status_reg & FD_MS_NDMA) {
|
|
|
|
BX_FD_THIS s.main_status_reg &= ~FD_MS_BUSY; // clear busy bit
|
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_MRQ | FD_MS_DIO; // data byte waiting
|
|
|
|
} else {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 1);
|
|
|
|
}
|
2005-08-31 23:48:03 +04:00
|
|
|
break;
|
|
|
|
|
2005-09-03 21:20:18 +04:00
|
|
|
case 0x4d: /* format track */
|
2006-03-25 15:14:13 +03:00
|
|
|
if ((BX_FD_THIS s.format_count == 0) || BX_FD_THIS s.TC) {
|
2005-09-03 21:20:18 +04:00
|
|
|
BX_FD_THIS s.format_count = 0;
|
|
|
|
BX_FD_THIS s.status_reg0 = (BX_FD_THIS s.head[drive] << 2) | drive;
|
|
|
|
enter_result_phase();
|
|
|
|
} else {
|
|
|
|
// transfer next sector
|
2007-02-09 17:23:50 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 1);
|
|
|
|
}
|
2005-09-03 21:20:18 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0xfe: // (contrived) RESET
|
2002-10-25 01:07:56 +04:00
|
|
|
theFloppyController->reset(BX_RESET_SOFTWARE);
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.pending_command = 0;
|
2001-12-27 12:30:31 +03:00
|
|
|
BX_FD_THIS s.status_reg0 = 0xc0;
|
2005-03-12 00:12:54 +03:00
|
|
|
BX_FD_THIS raise_interrupt();
|
2002-02-06 21:51:48 +03:00
|
|
|
BX_FD_THIS s.reset_sensei = 4;
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2002-02-27 21:16:30 +03:00
|
|
|
case 0x00: // nothing pending?
|
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
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));
|
2005-12-23 15:21:09 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2012-07-13 01:20:46 +04:00
|
|
|
Bit16u bx_floppy_ctrl_c::dma_write(Bit8u *buffer, Bit16u maxlen)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
// A DMA write is from I/O to Memory
|
2012-07-13 01:20:46 +04:00
|
|
|
// We need to return the next data byte(s) from the floppy buffer
|
2001-04-10 05:04:59 +04:00
|
|
|
// to be transfered via the DMA to memory. (read block from floppy)
|
2012-07-13 01:20:46 +04:00
|
|
|
//
|
|
|
|
// maxlen is the maximum length of the DMA transfer
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2012-07-13 01:20:46 +04:00
|
|
|
Bit8u drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
Bit16u len = 512 - BX_FD_THIS s.floppy_buffer_index;
|
|
|
|
if (len > maxlen) len = maxlen;
|
|
|
|
memcpy(buffer, &BX_FD_THIS s.floppy_buffer[BX_FD_THIS s.floppy_buffer_index], len);
|
|
|
|
BX_FD_THIS s.floppy_buffer_index += len;
|
|
|
|
BX_FD_THIS s.TC = get_tc() && (len == maxlen);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-25 15:14:13 +03:00
|
|
|
if ((BX_FD_THIS s.floppy_buffer_index >= 512) || (BX_FD_THIS s.TC)) {
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-25 15:14:13 +03:00
|
|
|
if (BX_FD_THIS s.floppy_buffer_index >= 512) {
|
|
|
|
increment_sector(); // increment to next sector before retrieving next one
|
|
|
|
BX_FD_THIS s.floppy_buffer_index = 0;
|
|
|
|
}
|
|
|
|
if (BX_FD_THIS s.TC) { // Terminal Count line, done
|
2002-07-26 20:39:18 +04:00
|
|
|
BX_FD_THIS s.status_reg0 = (BX_FD_THIS s.head[drive] << 2) | drive;
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.status_reg1 = 0;
|
|
|
|
BX_FD_THIS s.status_reg2 = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-04-24 18:57:25 +04:00
|
|
|
BX_DEBUG(("<<READ DONE>>"));
|
|
|
|
BX_DEBUG(("AFTER"));
|
|
|
|
BX_DEBUG((" drive = %u", drive));
|
|
|
|
BX_DEBUG((" cylinder = %u", BX_FD_THIS s.cylinder[drive]));
|
2015-01-12 21:52:39 +03:00
|
|
|
BX_DEBUG((" head = %u", BX_FD_THIS s.head[drive]));
|
2009-04-24 18:57:25 +04:00
|
|
|
BX_DEBUG((" sector = %u", BX_FD_THIS s.sector[drive]));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2007-02-09 17:23:50 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
2002-11-30 12:39:29 +03:00
|
|
|
enter_result_phase();
|
2005-08-31 23:48:03 +04:00
|
|
|
} else { // more data to transfer
|
|
|
|
Bit32u logical_sector, sector_time;
|
2003-02-07 02:16:56 +03:00
|
|
|
|
2007-02-09 17:23:50 +03:00
|
|
|
// remember that not all floppies have two sides, multiply by s.head[drive]
|
2003-02-07 02:16:56 +03:00
|
|
|
logical_sector = (BX_FD_THIS s.cylinder[drive] * BX_FD_THIS s.media[drive].heads *
|
2001-04-10 05:04:59 +04:00
|
|
|
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);
|
2003-02-07 02:16:56 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
floppy_xfer(drive, logical_sector*512, BX_FD_THIS s.floppy_buffer,
|
|
|
|
512, FROM_FLOPPY);
|
2007-02-09 17:23:50 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
2005-08-31 23:48:03 +04:00
|
|
|
// time to read one sector at 300 rpm
|
|
|
|
sector_time = 200000 / BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index,
|
|
|
|
sector_time , 0);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-08-31 23:48:03 +04:00
|
|
|
}
|
2012-07-13 01:20:46 +04:00
|
|
|
return len;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2012-07-13 01:20:46 +04:00
|
|
|
Bit16u bx_floppy_ctrl_c::dma_read(Bit8u *buffer, Bit16u maxlen)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
// 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)
|
2012-07-13 01:20:46 +04:00
|
|
|
//
|
|
|
|
// maxlen is the length of the DMA transfer (not implemented yet)
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2012-07-13 01:20:46 +04:00
|
|
|
Bit8u drive = BX_FD_THIS s.DOR & 0x03;
|
2005-09-03 21:20:18 +04:00
|
|
|
Bit32u logical_sector, sector_time;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-12-28 19:38:13 +03:00
|
|
|
if (BX_FD_THIS s.pending_command == 0x4d) { // format track in progress
|
2005-09-03 21:20:18 +04:00
|
|
|
BX_FD_THIS s.format_count--;
|
2001-12-28 19:38:13 +03:00
|
|
|
switch (3 - (BX_FD_THIS s.format_count & 0x03)) {
|
|
|
|
case 0:
|
2017-02-16 01:27:34 +03:00
|
|
|
if (*buffer < BX_FD_THIS s.media[drive].tracks) {
|
|
|
|
BX_FD_THIS s.cylinder[drive] = *buffer;
|
|
|
|
} else {
|
|
|
|
BX_ERROR(("format track: cylinder out of range"));
|
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
|
|
|
BX_FD_THIS s.status_reg0 = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive;
|
|
|
|
BX_FD_THIS s.status_reg1 = 0x04;
|
|
|
|
BX_FD_THIS s.status_reg2 = 0x00;
|
|
|
|
enter_result_phase();
|
|
|
|
return 1;
|
|
|
|
}
|
2001-12-28 19:38:13 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-07-13 01:20:46 +04:00
|
|
|
if (*buffer != BX_FD_THIS s.head[drive])
|
2001-12-28 19:38:13 +03:00
|
|
|
BX_ERROR(("head number does not match head field"));
|
|
|
|
break;
|
|
|
|
case 2:
|
2012-07-13 01:20:46 +04:00
|
|
|
BX_FD_THIS s.sector[drive] = *buffer;
|
2001-12-28 19:38:13 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-07-13 01:20:46 +04:00
|
|
|
if (*buffer != 2) BX_ERROR(("dma_read: sector size %d not supported", 128<<(*buffer)));
|
2001-12-28 19:38:13 +03:00
|
|
|
BX_DEBUG(("formatting cylinder %u head %u sector %u",
|
|
|
|
BX_FD_THIS s.cylinder[drive], BX_FD_THIS s.head[drive],
|
|
|
|
BX_FD_THIS s.sector[drive]));
|
|
|
|
for (unsigned i = 0; i < 512; i++) {
|
|
|
|
BX_FD_THIS s.floppy_buffer[i] = BX_FD_THIS s.format_fillbyte;
|
2005-09-03 21:20:18 +04:00
|
|
|
}
|
2003-02-07 02:16:56 +03:00
|
|
|
logical_sector = (BX_FD_THIS s.cylinder[drive] * BX_FD_THIS s.media[drive].heads * BX_FD_THIS s.media[drive].sectors_per_track) +
|
2001-12-28 19:38:13 +03:00
|
|
|
(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, TO_FLOPPY);
|
2007-02-09 17:23:50 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
2005-09-03 21:20:18 +04:00
|
|
|
// time to write one sector at 300 rpm
|
|
|
|
sector_time = 200000 / BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index,
|
|
|
|
sector_time , 0);
|
2001-12-28 19:38:13 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-07-13 01:20:46 +04:00
|
|
|
return 1;
|
2005-09-03 21:20:18 +04:00
|
|
|
} else { // write normal data
|
2012-07-13 01:20:46 +04:00
|
|
|
Bit16u len = 512 - BX_FD_THIS s.floppy_buffer_index;
|
|
|
|
if (len > maxlen) len = maxlen;
|
|
|
|
memcpy(&BX_FD_THIS s.floppy_buffer[BX_FD_THIS s.floppy_buffer_index], buffer, len);
|
|
|
|
BX_FD_THIS s.floppy_buffer_index += len;
|
|
|
|
BX_FD_THIS s.TC = get_tc() && (len == maxlen);
|
2001-12-28 19:38:13 +03:00
|
|
|
|
2006-03-25 15:14:13 +03:00
|
|
|
if ((BX_FD_THIS s.floppy_buffer_index >= 512) || (BX_FD_THIS s.TC)) {
|
2005-09-03 21:20:18 +04:00
|
|
|
logical_sector = (BX_FD_THIS s.cylinder[drive] * BX_FD_THIS s.media[drive].heads * 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);
|
|
|
|
if (BX_FD_THIS s.media[drive].write_protected) {
|
|
|
|
// write protected error
|
|
|
|
BX_INFO(("tried to write disk %u, which is write-protected", drive));
|
|
|
|
// ST0: IC1,0=01 (abnormal termination: started execution but failed)
|
|
|
|
BX_FD_THIS s.status_reg0 = 0x40 | (BX_FD_THIS s.head[drive]<<2) | drive;
|
|
|
|
// ST1: DataError=1, NDAT=1, NotWritable=1, NID=1
|
|
|
|
BX_FD_THIS s.status_reg1 = 0x27; // 0010 0111
|
|
|
|
// ST2: CRCE=1, SERR=1, BCYL=1, NDAM=1.
|
|
|
|
BX_FD_THIS s.status_reg2 = 0x31; // 0011 0001
|
2017-02-11 00:28:05 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 0);
|
|
|
|
} else {
|
|
|
|
BX_FD_THIS s.main_status_reg &= ~FD_MS_NDMA;
|
|
|
|
}
|
2005-09-03 21:20:18 +04:00
|
|
|
enter_result_phase();
|
2012-07-13 01:20:46 +04:00
|
|
|
return 1;
|
2005-09-03 21:20:18 +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;
|
2007-02-09 17:23:50 +03:00
|
|
|
if (!(BX_FD_THIS s.main_status_reg & FD_MS_NDMA)) {
|
|
|
|
DEV_dma_set_drq(FLOPPY_DMA_CHAN, 0);
|
|
|
|
}
|
2005-11-10 21:56:45 +03:00
|
|
|
// time to write one sector at 300 rpm
|
|
|
|
sector_time = 200000 / BX_FD_THIS s.media[drive].sectors_per_track;
|
|
|
|
bx_pc_system.activate_timer(BX_FD_THIS s.floppy_timer_index,
|
|
|
|
sector_time , 0);
|
2007-02-09 17:23:50 +03:00
|
|
|
// the following is a kludge; i (jc) don't know how to work with the timer
|
|
|
|
if ((BX_FD_THIS s.main_status_reg & FD_MS_NDMA) && BX_FD_THIS s.TC) {
|
|
|
|
enter_result_phase();
|
|
|
|
}
|
2005-09-03 21:20:18 +04:00
|
|
|
}
|
2012-07-13 01:20:46 +04:00
|
|
|
return len;
|
2005-09-03 21:20:18 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::raise_interrupt(void)
|
2002-02-06 21:51:48 +03:00
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_pic_raise_irq(6);
|
2002-02-06 21:51:48 +03:00
|
|
|
BX_FD_THIS s.pending_irq = 1;
|
|
|
|
BX_FD_THIS s.reset_sensei = 0;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::lower_interrupt(void)
|
2005-03-12 00:12:54 +03:00
|
|
|
{
|
2005-08-31 23:48:03 +04:00
|
|
|
if (BX_FD_THIS s.pending_irq) {
|
|
|
|
DEV_pic_lower_irq(6);
|
|
|
|
BX_FD_THIS s.pending_irq = 0;
|
|
|
|
}
|
2005-03-12 00:12:54 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::increment_sector(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
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] ++;
|
2005-10-27 11:38:20 +04:00
|
|
|
if ((BX_FD_THIS s.sector[drive] > BX_FD_THIS s.eot[drive]) ||
|
|
|
|
(BX_FD_THIS s.sector[drive] > BX_FD_THIS s.media[drive].sectors_per_track)) {
|
2001-12-28 19:38:13 +03:00
|
|
|
BX_FD_THIS s.sector[drive] = 1;
|
|
|
|
if (BX_FD_THIS s.multi_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] ++;
|
2005-11-20 17:15:28 +03:00
|
|
|
reset_changeline();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-10-27 11:38:20 +04:00
|
|
|
} else {
|
2001-12-28 19:38:13 +03:00
|
|
|
BX_FD_THIS s.cylinder[drive] ++;
|
2005-11-20 17:15:28 +03:00
|
|
|
reset_changeline();
|
2005-10-27 11:38:20 +04:00
|
|
|
}
|
2001-12-28 19:38:13 +03:00
|
|
|
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;
|
|
|
|
BX_INFO(("increment_sector: clamping cylinder to max"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-10-27 11:38:20 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2011-01-18 00:36:00 +03:00
|
|
|
unsigned bx_floppy_ctrl_c::set_media_status(unsigned drive, bx_bool status)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
unsigned type;
|
2013-12-08 15:32:13 +04:00
|
|
|
bx_list_c *floppy;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-08-04 12:42:34 +04:00
|
|
|
if (drive == 0)
|
2013-12-08 15:32:13 +04:00
|
|
|
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYA);
|
2002-08-04 12:42:34 +04:00
|
|
|
else
|
2013-12-08 15:32:13 +04:00
|
|
|
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYB);
|
2002-08-04 12:42:34 +04:00
|
|
|
|
2013-12-08 15:32:13 +04:00
|
|
|
type = SIM->get_param_enum("type", floppy)->get();
|
2001-04-10 05:04:59 +04:00
|
|
|
// if setting to the current value, nothing to do
|
2002-08-04 12:42:34 +04:00
|
|
|
if ((status == BX_FD_THIS s.media_present[drive]) &&
|
|
|
|
((status == 0) || (type == BX_FD_THIS s.media[drive].type)))
|
2013-12-08 15:32:13 +04:00
|
|
|
return status;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (status == 0) {
|
|
|
|
// eject floppy
|
2011-01-12 01:00:41 +03:00
|
|
|
close_media(&BX_FD_THIS s.media[drive]);
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.media_present[drive] = 0;
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
|
2002-08-13 16:02:37 +04:00
|
|
|
BX_FD_THIS s.DIR[drive] |= 0x80; // disk changed line
|
2013-12-08 15:32:13 +04:00
|
|
|
return 0;
|
2005-11-20 17:15:28 +03:00
|
|
|
} else {
|
2001-04-10 05:04:59 +04:00
|
|
|
// insert floppy
|
2013-12-08 15:32:13 +04:00
|
|
|
path = SIM->get_param_string("path", floppy)->getptr();
|
2003-11-22 21:22:45 +03:00
|
|
|
if (!strcmp(path, "none"))
|
2013-12-08 15:32:13 +04:00
|
|
|
return 0;
|
2005-11-22 21:34:51 +03:00
|
|
|
if (evaluate_media(BX_FD_THIS s.device_type[drive], type, path, & BX_FD_THIS s.media[drive])) {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.media_present[drive] = 1;
|
2002-03-17 23:55:27 +03:00
|
|
|
if (drive == 0) {
|
2003-12-18 23:04:49 +03:00
|
|
|
#define MED (BX_FD_THIS s.media[0])
|
2010-07-03 09:34:27 +04:00
|
|
|
BX_INFO(("fd0: '%s' ro=%d, h=%d,t=%d,spt=%d",
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_string("path", floppy)->getptr(),
|
2010-07-03 09:34:27 +04:00
|
|
|
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
|
|
|
|
if (MED.write_protected)
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_bool("readonly", floppy)->set(1);
|
2003-12-18 23:04:49 +03:00
|
|
|
#undef MED
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set(BX_INSERTED);
|
2002-03-17 23:55:27 +03:00
|
|
|
} else {
|
2003-12-18 23:04:49 +03:00
|
|
|
#define MED (BX_FD_THIS s.media[1])
|
2010-07-03 09:34:27 +04:00
|
|
|
BX_INFO(("fd1: '%s' ro=%d, h=%d,t=%d,spt=%d",
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_string("path", floppy)->getptr(),
|
2010-07-03 09:34:27 +04:00
|
|
|
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
|
|
|
|
if (MED.write_protected)
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_bool("readonly", floppy)->set(1);
|
2003-12-18 23:04:49 +03:00
|
|
|
#undef MED
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set(BX_INSERTED);
|
2002-03-17 23:55:27 +03:00
|
|
|
}
|
2013-12-08 15:32:13 +04:00
|
|
|
return 1;
|
2005-11-20 17:15:28 +03:00
|
|
|
} else {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_FD_THIS s.media_present[drive] = 0;
|
2013-12-08 15:32:13 +04:00
|
|
|
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
|
|
|
|
SIM->get_param_enum("type", floppy)->set(BX_FLOPPY_NONE);
|
|
|
|
return 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-11-20 17:15:28 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path, floppy_t *media)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
struct stat stat_buf;
|
2003-11-24 00:54:59 +03:00
|
|
|
int i, ret;
|
2005-11-22 21:34:51 +03:00
|
|
|
int type_idx = -1;
|
2003-12-07 18:59:32 +03:00
|
|
|
#ifdef __linux__
|
|
|
|
struct floppy_struct floppy_geom;
|
|
|
|
#endif
|
2002-10-13 13:40:05 +04:00
|
|
|
#ifdef WIN32
|
2001-04-10 05:04:59 +04:00
|
|
|
char sTemp[1024];
|
2003-11-22 21:22:45 +03:00
|
|
|
bx_bool raw_floppy = 0;
|
2003-12-07 18:59:32 +03:00
|
|
|
HANDLE hFile;
|
|
|
|
DWORD bytes;
|
|
|
|
DISK_GEOMETRY dg;
|
2006-04-05 21:23:51 +04:00
|
|
|
unsigned tracks = 0, heads = 0, spt = 0;
|
2001-12-27 12:30:31 +03:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-08-23 17:02:50 +04:00
|
|
|
//If media file is already open, close it before reopening.
|
2011-01-12 01:00:41 +03:00
|
|
|
close_media(media);
|
2001-08-23 17:02:50 +04:00
|
|
|
|
2005-11-22 21:34:51 +03:00
|
|
|
// check media type
|
|
|
|
if (type == BX_FLOPPY_NONE) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (type == floppy_type[i].id) type_idx = i;
|
|
|
|
}
|
|
|
|
if (type_idx == -1) {
|
|
|
|
BX_ERROR(("evaluate_media: unknown media type %d", type));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((floppy_type[type_idx].drive_mask & devtype) == 0) {
|
|
|
|
BX_ERROR(("evaluate_media: media type %d not valid for this floppy drive", type));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-13 01:35:32 +03:00
|
|
|
// use virtual VFAT support if requested
|
2011-01-11 23:14:21 +03:00
|
|
|
if (!strncmp(path, "vvfat:", 6) && (devtype == FDRIVE_350HD)) {
|
2011-01-13 01:35:32 +03:00
|
|
|
media->vvfat = DEV_hdimage_init_image(BX_HDIMAGE_MODE_VVFAT, 1474560, "");
|
2011-01-11 23:14:21 +03:00
|
|
|
if (media->vvfat != NULL) {
|
|
|
|
if (media->vvfat->open(path + 6) == 0) {
|
|
|
|
media->type = BX_FLOPPY_1_44;
|
|
|
|
media->tracks = media->vvfat->cylinders;
|
|
|
|
media->heads = media->vvfat->heads;
|
2011-11-26 19:09:00 +04:00
|
|
|
media->sectors_per_track = media->vvfat->spt;
|
2011-01-11 23:14:21 +03:00
|
|
|
media->sectors = 2880;
|
|
|
|
media->vvfat_floppy = 1;
|
|
|
|
media->fd = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (media->vvfat_floppy) return 1;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
// open media file (image file or device)
|
|
|
|
#ifdef macintosh
|
|
|
|
media->fd = 0;
|
2013-12-08 15:32:13 +04:00
|
|
|
if (strcmp(path, SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2002-10-13 13:40:05 +04:00
|
|
|
#ifdef WIN32
|
2011-08-22 21:57:21 +04:00
|
|
|
if ((isalpha(path[0])) && (path[1] == ':') && (strlen(path) == 2)) {
|
|
|
|
raw_floppy = 1;
|
|
|
|
wsprintf(sTemp, "\\\\.\\%s", path);
|
|
|
|
hFile = CreateFile(sTemp, GENERIC_READ, FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) {
|
|
|
|
BX_ERROR(("Cannot open floppy drive"));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if (!DeviceIoControl(hFile, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof(dg), &bytes, NULL)) {
|
|
|
|
BX_ERROR(("No media in floppy drive"));
|
2004-05-31 18:47:12 +04:00
|
|
|
CloseHandle(hFile);
|
2011-08-22 21:57:21 +04:00
|
|
|
return(0);
|
|
|
|
} else {
|
|
|
|
tracks = (unsigned)dg.Cylinders.QuadPart;
|
|
|
|
heads = (unsigned)dg.TracksPerCylinder;
|
|
|
|
spt = (unsigned)dg.SectorsPerTrack;
|
2010-11-13 16:00:26 +03:00
|
|
|
}
|
2011-08-22 21:57:21 +04:00
|
|
|
CloseHandle(hFile);
|
|
|
|
if (!media->write_protected)
|
|
|
|
media->fd = open(sTemp, BX_RDWR);
|
2010-11-13 16:00:26 +03:00
|
|
|
else
|
2011-08-22 21:57:21 +04:00
|
|
|
media->fd = open(sTemp, BX_RDONLY);
|
|
|
|
}
|
|
|
|
else
|
2010-11-13 16:00:26 +03:00
|
|
|
#endif
|
2011-08-22 21:57:21 +04:00
|
|
|
{
|
|
|
|
if (!media->write_protected)
|
|
|
|
media->fd = open(path, BX_RDWR);
|
|
|
|
else
|
|
|
|
media->fd = open(path, BX_RDONLY);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-08-22 21:57:21 +04:00
|
|
|
if (!media->write_protected && (media->fd < 0)) {
|
|
|
|
BX_INFO(("tried to open '%s' read/write: %s",path,strerror(errno)));
|
|
|
|
// try opening the file read-only
|
|
|
|
media->write_protected = 1;
|
2001-06-13 04:30:34 +04:00
|
|
|
#ifdef macintosh
|
2011-08-22 21:57:21 +04:00
|
|
|
media->fd = 0;
|
2013-12-08 15:32:13 +04:00
|
|
|
if (strcmp(path, SuperDrive))
|
2001-06-13 04:30:34 +04:00
|
|
|
#endif
|
2002-10-13 13:40:05 +04:00
|
|
|
#ifdef WIN32
|
2011-08-22 21:57:21 +04:00
|
|
|
if (raw_floppy == 1)
|
|
|
|
media->fd = open(sTemp, BX_RDONLY);
|
|
|
|
else
|
2010-11-13 16:06:00 +03:00
|
|
|
#endif
|
2011-08-22 21:57:21 +04:00
|
|
|
media->fd = open(path, BX_RDONLY);
|
2010-11-13 16:00:26 +03:00
|
|
|
|
2011-08-22 21:57:21 +04:00
|
|
|
if (media->fd < 0) {
|
|
|
|
// failed to open read-only too
|
|
|
|
BX_INFO(("tried to open '%s' read only: %s",path,strerror(errno)));
|
|
|
|
media->type = type;
|
|
|
|
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
|
2013-12-08 15:32:13 +04:00
|
|
|
if (!strcmp(path, SuperDrive))
|
2001-04-10 05:04:59 +04:00
|
|
|
ret = fd_stat(&stat_buf);
|
|
|
|
else
|
|
|
|
ret = fstat(media->fd, &stat_buf);
|
2002-10-13 13:40:05 +04:00
|
|
|
#elif defined(WIN32)
|
2003-11-22 21:22:45 +03:00
|
|
|
if (raw_floppy) {
|
2003-12-11 01:14:01 +03:00
|
|
|
memset (&stat_buf, 0, sizeof(stat_buf));
|
2001-10-01 21:20:08 +04:00
|
|
|
stat_buf.st_mode = S_IFCHR;
|
2003-12-07 18:59:32 +03:00
|
|
|
ret = 0;
|
2003-11-22 21:22:45 +03:00
|
|
|
}
|
2010-11-13 16:00:26 +03:00
|
|
|
else
|
2001-04-10 06:17:43 +04:00
|
|
|
#endif
|
2010-11-13 16:00:26 +03:00
|
|
|
{ // unix
|
|
|
|
ret = fstat(media->fd, &stat_buf);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (ret) {
|
2001-10-07 07:28:45 +04:00
|
|
|
BX_PANIC(("fstat floppy 0 drive image file returns error: %s", strerror(errno)));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
if (S_ISREG(stat_buf.st_mode)) {
|
2001-04-10 05:04:59 +04:00
|
|
|
// regular file
|
|
|
|
switch (type) {
|
2003-02-07 02:16:56 +03:00
|
|
|
// use CMOS reserved types
|
|
|
|
case BX_FLOPPY_160K: // 160K 5.25"
|
|
|
|
case BX_FLOPPY_180K: // 180K 5.25"
|
|
|
|
case BX_FLOPPY_320K: // 320K 5.25"
|
2003-11-24 00:54:59 +03:00
|
|
|
// standard floppy types
|
2002-08-01 11:37:56 +04:00
|
|
|
case BX_FLOPPY_360K: // 360K 5.25"
|
2001-04-10 05:04:59 +04:00
|
|
|
case BX_FLOPPY_720K: // 720K 3.5"
|
|
|
|
case BX_FLOPPY_1_2: // 1.2M 5.25"
|
2003-11-24 00:54:59 +03:00
|
|
|
case BX_FLOPPY_2_88: // 2.88M 3.5"
|
|
|
|
media->type = type;
|
2005-11-22 21:34:51 +03:00
|
|
|
media->tracks = floppy_type[type_idx].trk;
|
|
|
|
media->heads = floppy_type[type_idx].hd;
|
|
|
|
media->sectors_per_track = floppy_type[type_idx].spt;
|
|
|
|
media->sectors = floppy_type[type_idx].sectors;
|
2011-01-13 01:35:32 +03:00
|
|
|
if (stat_buf.st_size > (int)(media->sectors * 512)) {
|
2005-11-22 21:34:51 +03:00
|
|
|
BX_ERROR(("evaluate_media: size of file '%s' (%lu) too large for selected type",
|
2003-11-24 00:54:59 +03:00
|
|
|
path, (unsigned long) stat_buf.st_size));
|
2005-11-22 21:34:51 +03:00
|
|
|
return 0;
|
2003-11-24 00:54:59 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
2003-11-24 00:54:59 +03:00
|
|
|
default: // 1.44M 3.5"
|
|
|
|
media->type = type;
|
2001-04-10 05:04:59 +04:00
|
|
|
if (stat_buf.st_size <= 1474560) {
|
2005-11-22 21:34:51 +03:00
|
|
|
media->tracks = floppy_type[type_idx].trk;
|
|
|
|
media->heads = floppy_type[type_idx].hd;
|
|
|
|
media->sectors_per_track = floppy_type[type_idx].spt;
|
|
|
|
}
|
|
|
|
else if (stat_buf.st_size == 1720320)
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
media->sectors_per_track = 21;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
2005-11-22 21:34:51 +03:00
|
|
|
}
|
|
|
|
else if (stat_buf.st_size == 1763328)
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
media->sectors_per_track = 21;
|
|
|
|
media->tracks = 82;
|
|
|
|
media->heads = 2;
|
2005-11-22 21:34:51 +03:00
|
|
|
}
|
|
|
|
else if (stat_buf.st_size == 1884160)
|
|
|
|
{
|
2005-08-25 00:45:57 +04:00
|
|
|
media->sectors_per_track = 23;
|
|
|
|
media->tracks = 80;
|
|
|
|
media->heads = 2;
|
2005-11-22 21:34:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BX_ERROR(("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));
|
2005-11-22 21:34:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-24 00:54:59 +03:00
|
|
|
media->sectors = media->heads * media->tracks * media->sectors_per_track;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2007-08-21 18:18:16 +04:00
|
|
|
return (media->sectors > 0); // success
|
2006-03-08 00:11:20 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
else if (S_ISCHR(stat_buf.st_mode)
|
2001-04-10 05:04:59 +04:00
|
|
|
#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
|
2003-12-06 16:59:30 +03:00
|
|
|
media->type = type;
|
2003-12-07 18:59:32 +03:00
|
|
|
#ifdef __linux__
|
|
|
|
if (ioctl(media->fd, FDGETPRM, &floppy_geom) < 0) {
|
2005-01-16 18:58:40 +03:00
|
|
|
BX_ERROR(("cannot determine media geometry, trying to use defaults"));
|
2005-11-22 21:34:51 +03:00
|
|
|
media->tracks = floppy_type[type_idx].trk;
|
|
|
|
media->heads = floppy_type[type_idx].hd;
|
|
|
|
media->sectors_per_track = floppy_type[type_idx].spt;
|
|
|
|
media->sectors = floppy_type[type_idx].sectors;
|
2007-08-21 18:18:16 +04:00
|
|
|
return (media->sectors > 0);
|
2003-12-07 18:59:32 +03:00
|
|
|
}
|
|
|
|
media->tracks = floppy_geom.track;
|
|
|
|
media->heads = floppy_geom.head;
|
|
|
|
media->sectors_per_track = floppy_geom.sect;
|
|
|
|
media->sectors = floppy_geom.size;
|
|
|
|
#elif defined(WIN32)
|
|
|
|
media->tracks = tracks;
|
|
|
|
media->heads = heads;
|
|
|
|
media->sectors_per_track = spt;
|
|
|
|
media->sectors = media->heads * media->tracks * media->sectors_per_track;
|
|
|
|
#else
|
2005-11-22 21:34:51 +03:00
|
|
|
media->tracks = floppy_type[type_idx].trk;
|
|
|
|
media->heads = floppy_type[type_idx].hd;
|
|
|
|
media->sectors_per_track = floppy_type[type_idx].spt;
|
|
|
|
media->sectors = floppy_type[type_idx].sectors;
|
2003-12-07 18:59:32 +03:00
|
|
|
#endif
|
2007-08-21 18:18:16 +04:00
|
|
|
return (media->sectors > 0); // success
|
2005-11-22 21:34:51 +03:00
|
|
|
} else {
|
2001-04-10 05:04:59 +04:00
|
|
|
// unknown file type
|
2005-11-22 21:34:51 +03:00
|
|
|
BX_ERROR(("unknown mode type"));
|
|
|
|
return 0;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-10-01 21:20:08 +04:00
|
|
|
|
2011-01-12 01:00:41 +03:00
|
|
|
void bx_floppy_ctrl_c::close_media(floppy_t *media)
|
|
|
|
{
|
|
|
|
if (media->fd >= 0) {
|
|
|
|
if (media->vvfat_floppy) {
|
|
|
|
media->vvfat->close();
|
|
|
|
delete media->vvfat;
|
|
|
|
media->vvfat_floppy = 0;
|
2011-08-22 21:57:21 +04:00
|
|
|
} else {
|
2011-01-12 01:00:41 +03:00
|
|
|
close(media->fd);
|
|
|
|
}
|
|
|
|
media->fd = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::enter_result_phase(void)
|
2002-11-30 12:39:29 +03:00
|
|
|
{
|
|
|
|
Bit8u drive;
|
2005-11-17 00:21:35 +03:00
|
|
|
unsigned i;
|
2002-11-30 12:39:29 +03:00
|
|
|
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
|
|
|
|
/* these are always the same */
|
|
|
|
BX_FD_THIS s.result_index = 0;
|
2007-02-09 17:23:50 +03:00
|
|
|
// not necessary to clear any status bits, we're about to set them all
|
2005-08-31 23:48:03 +04:00
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_MRQ | FD_MS_DIO | FD_MS_BUSY;
|
2002-11-30 12:39:29 +03:00
|
|
|
|
2015-01-12 21:52:39 +03:00
|
|
|
// invalid command?
|
2002-11-30 12:39:29 +03:00
|
|
|
if ((BX_FD_THIS s.status_reg0 & 0xc0) == 0x80) {
|
|
|
|
BX_FD_THIS s.result_size = 1;
|
|
|
|
BX_FD_THIS s.result[0] = BX_FD_THIS s.status_reg0;
|
2015-01-12 21:52:39 +03:00
|
|
|
} else {
|
|
|
|
// might be a valid command
|
|
|
|
switch (BX_FD_THIS s.pending_command) {
|
|
|
|
case 0x04: // get status
|
|
|
|
BX_FD_THIS s.result_size = 1;
|
|
|
|
BX_FD_THIS s.result[0] = BX_FD_THIS s.status_reg3;
|
|
|
|
break;
|
|
|
|
case 0x08: // sense interrupt
|
|
|
|
BX_FD_THIS s.result_size = 2;
|
|
|
|
BX_FD_THIS s.result[0] = BX_FD_THIS s.status_reg0;
|
|
|
|
BX_FD_THIS s.result[1] = BX_FD_THIS s.cylinder[drive];
|
|
|
|
break;
|
|
|
|
case 0x0e: // dump registers
|
|
|
|
BX_FD_THIS s.result_size = 10;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
BX_FD_THIS s.result[i] = BX_FD_THIS s.cylinder[i];
|
|
|
|
}
|
|
|
|
BX_FD_THIS s.result[4] = (BX_FD_THIS s.SRT << 4) | BX_FD_THIS s.HUT;
|
|
|
|
BX_FD_THIS s.result[5] = (BX_FD_THIS s.HLT << 1) | ((BX_FD_THIS s.main_status_reg & FD_MS_NDMA) ? 1 : 0);
|
|
|
|
BX_FD_THIS s.result[6] = BX_FD_THIS s.eot[drive];
|
|
|
|
BX_FD_THIS s.result[7] = (BX_FD_THIS s.lock << 7) | (BX_FD_THIS s.perp_mode & 0x7f);
|
|
|
|
BX_FD_THIS s.result[8] = BX_FD_THIS s.config;
|
|
|
|
BX_FD_THIS s.result[9] = BX_FD_THIS s.pretrk;
|
|
|
|
break;
|
|
|
|
case 0x10: // version
|
|
|
|
BX_FD_THIS s.result_size = 1;
|
|
|
|
BX_FD_THIS s.result[0] = 0x90;
|
|
|
|
break;
|
|
|
|
case 0x14: // unlock
|
|
|
|
case 0x94: // lock
|
|
|
|
BX_FD_THIS s.lock = (BX_FD_THIS s.pending_command >> 7);
|
|
|
|
BX_FD_THIS s.result_size = 1;
|
|
|
|
BX_FD_THIS s.result[0] = (BX_FD_THIS s.lock << 4);
|
|
|
|
break;
|
|
|
|
case 0x4a: // read ID
|
|
|
|
case 0x4d: // format track
|
|
|
|
case 0x46: // read normal data
|
|
|
|
case 0x66:
|
|
|
|
case 0xc6:
|
|
|
|
case 0xe6:
|
|
|
|
case 0x45: // write normal data
|
|
|
|
case 0xc5:
|
|
|
|
BX_FD_THIS s.result_size = 7;
|
|
|
|
BX_FD_THIS s.result[0] = BX_FD_THIS s.status_reg0;
|
|
|
|
BX_FD_THIS s.result[1] = BX_FD_THIS s.status_reg1;
|
|
|
|
BX_FD_THIS s.result[2] = BX_FD_THIS s.status_reg2;
|
|
|
|
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 code */
|
|
|
|
BX_FD_THIS raise_interrupt();
|
|
|
|
break;
|
|
|
|
default: // invalid commands are to return a single result byte of 0x80
|
|
|
|
BX_FD_THIS s.result_size = 1;
|
|
|
|
BX_FD_THIS s.result[0] = BX_FD_THIS s.status_reg0;
|
|
|
|
}
|
2002-11-30 12:39:29 +03:00
|
|
|
}
|
2005-08-25 00:45:57 +04:00
|
|
|
|
2005-11-26 01:29:20 +03:00
|
|
|
// Print command result (max. 10 bytes)
|
|
|
|
char buf[8+(10*5)+1], *p = buf;
|
2005-08-25 00:45:57 +04:00
|
|
|
p += sprintf(p, "RESULT: ");
|
|
|
|
for (i=0; i<BX_FD_THIS s.result_size; i++) {
|
|
|
|
p += sprintf(p, "[%02x] ", (unsigned) BX_FD_THIS s.result[i]);
|
|
|
|
}
|
2010-03-02 10:07:57 +03:00
|
|
|
BX_DEBUG(("%s", buf));
|
2002-11-30 12:39:29 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_floppy_ctrl_c::enter_idle_phase(void)
|
2002-11-30 12:39:29 +03:00
|
|
|
{
|
2007-02-09 17:23:50 +03:00
|
|
|
BX_FD_THIS s.main_status_reg &= (FD_MS_NDMA | 0x0f); // leave drive status untouched
|
2002-11-30 12:39:29 +03:00
|
|
|
BX_FD_THIS s.main_status_reg |= FD_MS_MRQ; // data register ready
|
|
|
|
|
|
|
|
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;
|
2012-03-23 21:22:30 +04:00
|
|
|
BX_FD_THIS s.result_size = 0;
|
2002-11-30 12:39:29 +03:00
|
|
|
|
|
|
|
BX_FD_THIS s.floppy_buffer_index = 0;
|
|
|
|
}
|
|
|
|
|
2005-11-12 13:38:51 +03:00
|
|
|
Bit32u bx_floppy_ctrl_c::calculate_step_delay(Bit8u drive, Bit8u new_cylinder)
|
|
|
|
{
|
|
|
|
Bit8u steps;
|
|
|
|
Bit32u one_step_delay;
|
|
|
|
|
|
|
|
if (new_cylinder == BX_FD_THIS s.cylinder[drive]) {
|
|
|
|
steps = 1;
|
|
|
|
} else {
|
|
|
|
steps = abs(new_cylinder - BX_FD_THIS s.cylinder[drive]);
|
2005-11-20 17:15:28 +03:00
|
|
|
reset_changeline();
|
2005-11-12 13:38:51 +03:00
|
|
|
}
|
|
|
|
one_step_delay = ((BX_FD_THIS s.SRT ^ 0x0f) + 1) * 500000 / drate_in_k[BX_FD_THIS s.data_rate];
|
|
|
|
return (steps * one_step_delay);
|
|
|
|
}
|
2005-11-20 17:15:28 +03:00
|
|
|
|
|
|
|
void bx_floppy_ctrl_c::reset_changeline(void)
|
|
|
|
{
|
|
|
|
Bit8u drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
if (BX_FD_THIS s.media_present[drive])
|
|
|
|
BX_FD_THIS s.DIR[drive] &= ~0x80;
|
|
|
|
}
|
2007-02-09 17:23:50 +03:00
|
|
|
|
|
|
|
bx_bool bx_floppy_ctrl_c::get_tc(void)
|
|
|
|
{
|
|
|
|
Bit8u drive;
|
2007-04-06 19:22:17 +04:00
|
|
|
bx_bool terminal_count;
|
2007-02-09 17:23:50 +03:00
|
|
|
if (BX_FD_THIS s.main_status_reg & FD_MS_NDMA) {
|
|
|
|
drive = BX_FD_THIS s.DOR & 0x03;
|
|
|
|
/* figure out if we've sent all the data, in non-DMA mode...
|
|
|
|
* the drive stays on the same cylinder for a read or write, so that's
|
|
|
|
* not going to be an issue. EOT stands for the last sector to be I/Od.
|
|
|
|
* it does all the head 0 sectors first, then the second if any.
|
|
|
|
* now, regarding reaching the end of the sector:
|
|
|
|
* == 512 would make it more precise, allowing one to spot bugs...
|
|
|
|
* >= 512 makes it more robust, but allows for sloppy code...
|
|
|
|
* pick your poison?
|
|
|
|
* note: byte and head are 0-based; eot, sector, and heads are 1-based. */
|
2007-04-06 19:22:17 +04:00
|
|
|
terminal_count = ((BX_FD_THIS s.floppy_buffer_index == 512) &&
|
|
|
|
(BX_FD_THIS s.sector[drive] == BX_FD_THIS s.eot[drive]) &&
|
|
|
|
(BX_FD_THIS s.head[drive] == (BX_FD_THIS s.media[drive].heads - 1)));
|
2007-02-09 17:23:50 +03:00
|
|
|
} else {
|
|
|
|
terminal_count = DEV_dma_get_tc();
|
|
|
|
}
|
|
|
|
return terminal_count;
|
|
|
|
}
|
2011-01-18 00:36:00 +03:00
|
|
|
|
2011-08-22 21:57:21 +04:00
|
|
|
// floppy runtime parameter handling
|
|
|
|
|
2011-01-18 00:36:00 +03:00
|
|
|
Bit64s bx_floppy_ctrl_c::floppy_param_handler(bx_param_c *param, int set, Bit64s val)
|
|
|
|
{
|
2011-08-20 00:20:25 +04:00
|
|
|
bx_list_c *base = (bx_list_c*) param->get_parent();
|
|
|
|
Bit8u drive;
|
|
|
|
|
2011-01-18 00:36:00 +03:00
|
|
|
if (set) {
|
2011-08-20 00:20:25 +04:00
|
|
|
drive = atoi(base->get_name());
|
|
|
|
if (!strcmp(param->get_name(), "status")) {
|
|
|
|
BX_FD_THIS s.media[drive].status_changed = 1;
|
|
|
|
} else if (!strcmp(param->get_name(), "readonly")) {
|
|
|
|
BX_FD_THIS s.media[drive].write_protected = (bx_bool)val;
|
|
|
|
BX_FD_THIS s.media[drive].status_changed = 1;
|
2011-01-18 00:36:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
2011-01-19 00:04:44 +03:00
|
|
|
|
|
|
|
const char* bx_floppy_ctrl_c::floppy_param_string_handler(bx_param_string_c *param,
|
|
|
|
int set, const char *oldval, const char *val, int maxlen)
|
|
|
|
{
|
|
|
|
char pname[BX_PATHNAME_LEN];
|
2011-08-20 00:20:25 +04:00
|
|
|
Bit8u drive;
|
2011-01-19 00:04:44 +03:00
|
|
|
|
|
|
|
bx_list_c *base = (bx_list_c*) param->get_parent();
|
|
|
|
if ((strlen(val) < 1) || !strcmp ("none", val)) {
|
|
|
|
val = "none";
|
|
|
|
}
|
|
|
|
param->get_param_path(pname, BX_PATHNAME_LEN);
|
2013-12-08 15:32:13 +04:00
|
|
|
if ((!strncmp(pname, "floppy", 6)) && (!strcmp(param->get_name(), "path"))) {
|
2011-01-19 00:04:44 +03:00
|
|
|
if (set==1) {
|
2011-08-20 00:20:25 +04:00
|
|
|
drive = atoi(base->get_name());
|
|
|
|
if (SIM->get_param_enum("devtype", base)->get() == BX_FDD_NONE) {
|
|
|
|
BX_ERROR(("Cannot add a floppy drive at runtime"));
|
|
|
|
SIM->get_param_string("path", base)->set("none");
|
2011-01-19 00:04:44 +03:00
|
|
|
}
|
2013-01-23 21:56:57 +04:00
|
|
|
if (SIM->get_param_enum("status", base)->get() == BX_INSERTED) {
|
2011-01-19 00:04:44 +03:00
|
|
|
// tell the device model that we removed, then inserted the disk
|
2011-08-20 00:20:25 +04:00
|
|
|
BX_FD_THIS s.media[drive].status_changed = 1;
|
2011-01-19 00:04:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BX_PANIC(("floppy_param_string_handler called with unknown parameter '%s'", pname));
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
2012-03-23 21:22:30 +04:00
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
2012-04-23 21:06:19 +04:00
|
|
|
void bx_floppy_ctrl_c::debug_dump(int argc, char **argv)
|
2012-03-23 21:22:30 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dbg_printf("i82077AA FDC\n\n");
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
dbg_printf("fd%d: ", i);
|
|
|
|
if (BX_FD_THIS s.device_type[i] == FDRIVE_NONE) {
|
|
|
|
dbg_printf("not installed\n");
|
|
|
|
} else if (BX_FD_THIS s.media[i].type == BX_FLOPPY_NONE) {
|
|
|
|
dbg_printf("media not present\n");
|
|
|
|
} else {
|
|
|
|
#define MED (BX_FD_THIS s.media[i])
|
|
|
|
dbg_printf("tracks=%d, heads=%d, spt=%d, readonly=%d\n",
|
|
|
|
MED.tracks, MED.heads, MED.sectors_per_track, MED.write_protected);
|
|
|
|
#undef MED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbg_printf("\ncontroller status: ");
|
|
|
|
if (BX_FD_THIS s.pending_command == 0) {
|
|
|
|
if (BX_FD_THIS s.command_complete) {
|
|
|
|
dbg_printf("idle phase\n");
|
|
|
|
} else {
|
|
|
|
dbg_printf("command phase (command=0x%02x)\n", BX_FD_THIS s.command[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (BX_FD_THIS s.result_size == 0) {
|
|
|
|
dbg_printf("execution phase (command=0x%02x)\n", BX_FD_THIS s.pending_command);
|
|
|
|
} else {
|
|
|
|
dbg_printf("result phase (command=0x%02x)\n", BX_FD_THIS s.pending_command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbg_printf("DOR = 0x%02x\n", BX_FD_THIS s.DOR);
|
|
|
|
dbg_printf("MSR = 0x%02x\n", BX_FD_THIS s.main_status_reg);
|
|
|
|
dbg_printf("DSR = 0x%02x\n", BX_FD_THIS s.data_rate);
|
2012-04-23 21:06:19 +04:00
|
|
|
if (argc > 0) {
|
|
|
|
dbg_printf("\nAdditional options not supported\n");
|
|
|
|
}
|
2012-03-23 21:22:30 +04:00
|
|
|
}
|
|
|
|
#endif
|