Simplified floppy parameter handling

wx floppy dialog now forces a media change by clicking OK (same as win32dialog)
wxdialog.cc: one more whitespace cleanup
wxdialog.h: removed unused members
This commit is contained in:
Volker Ruppert 2013-12-08 11:32:13 +00:00
parent a3de279d3a
commit f008f0989f
4 changed files with 163 additions and 159 deletions

View File

@ -535,19 +535,22 @@ END_EVENT_TABLE()
ParamDialog::ParamDialog(
wxWindow* parent,
wxWindowID id)
: wxDialog (parent, id, wxT(""), wxDefaultPosition, wxDefaultSize,
: wxDialog(parent, id, wxT(""), wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
idHash = new wxHashTable (wxKEY_INTEGER);
paramHash = new wxHashTable (wxKEY_INTEGER);
idHash = new wxHashTable(wxKEY_INTEGER);
paramHash = new wxHashTable(wxKEY_INTEGER);
nbuttons = 0;
runtime = 0;
// top level objects
mainSizer = new wxBoxSizer (wxVERTICAL);
mainSizer = new wxBoxSizer(wxVERTICAL);
// info sizer only used in floppy and log options dialog
infoSizer = NULL;
// create buttonSizer, which will hold all the buttons.
buttonSizer = new wxBoxSizer (wxHORIZONTAL);
buttonSizer = new wxBoxSizer(wxHORIZONTAL);
}
ParamDialog::~ParamDialog()
@ -565,25 +568,28 @@ ParamDialog::~ParamDialog()
delete paramHash;
}
wxButton*
ParamDialog::AddButton (int id, wxString label)
wxButton* ParamDialog::AddButton(int id, wxString label)
{
wxButton *btn = new wxButton (this, id, label);
buttonSizer->Add (btn, 0, wxALL, 5);
wxButton *btn = new wxButton(this, id, label);
buttonSizer->Add(btn, 0, wxALL, 5);
nbuttons++;
return btn;
}
// add the standard HELP, CANCEL, OK buttons.
void ParamDialog::AddDefaultButtons ()
void ParamDialog::AddDefaultButtons()
{
AddButton (wxID_HELP, BTNLABEL_HELP);
AddButton (wxID_CANCEL, BTNLABEL_CANCEL);
AddButton (wxID_OK, BTNLABEL_OK);
AddButton(wxID_HELP, BTNLABEL_HELP);
AddButton(wxID_CANCEL, BTNLABEL_CANCEL);
AddButton(wxID_OK, BTNLABEL_OK);
}
void ParamDialog::Init()
{
// add info sizer if present
if (infoSizer != NULL) {
mainSizer->Add(infoSizer, 0, wxALIGN_CENTER);
}
// if nobody has made any buttons, then create some now
if (nbuttons==0) AddDefaultButtons();
mainSizer->Add(buttonSizer, 0, wxALIGN_RIGHT);
@ -623,17 +629,17 @@ void ParamDialog::AddParamList(const char *nameList[], bx_param_c *base, wxFlexG
}
// support "legacy" addparam functions. Easier than changing them.
void ParamDialog::AddParam (bx_param_c *param, wxFlexGridSizer *sizer, bool plain)
void ParamDialog::AddParam(bx_param_c *param, wxFlexGridSizer *sizer, bool plain)
{
AddParamContext context;
context.depth = 0;
context.parent = this;
context.vertSizer = mainSizer;
context.gridSizer = sizer;
AddParam (param, plain, &context);
AddParam(param, plain, &context);
}
void ParamDialog::AddParam (
void ParamDialog::AddParam(
bx_param_c *param_generic,
bool plain,
AddParamContext *context)
@ -646,21 +652,21 @@ void ParamDialog::AddParam (
context->vertSizer = mainSizer;
context->gridSizer = NULL;
}
wxASSERT (context->parent != NULL);
wxASSERT (context->vertSizer != NULL);
wxASSERT(context->parent != NULL);
wxASSERT(context->vertSizer != NULL);
if (param_generic == NULL)
return; // param not registered, probably this option was not compiled in
wxLogDebug(wxT("AddParam for param '%s'"), param_generic->get_name());
if (context->gridSizer == NULL) {
// create a gridSizer if none exists yet. add it to default vertSizer.
context->gridSizer = new wxFlexGridSizer (3);
context->vertSizer->Add (context->gridSizer);
context->gridSizer = new wxFlexGridSizer(3);
context->vertSizer->Add(context->gridSizer);
}
wxFlexGridSizer *sizer = context->gridSizer;
ParamStruct *pstr = new ParamStruct ();
ParamStruct *pstr = new ParamStruct();
pstr->param = param_generic;
pstr->id = genId ();
pstr->id = genId();
pstr->label = NULL;
pstr->u.window = NULL;
pstr->browseButton = NULL;
@ -674,68 +680,72 @@ void ParamDialog::AddParam (
}
if (!prompt) prompt = pstr->param->get_name();
const char *description = pstr->param->get_description();
wxASSERT (prompt != NULL);
wxASSERT(prompt != NULL);
#define ADD_LABEL(x) sizer->Add(pstr->label = new wxStaticText(context->parent, -1, wxString(x, wxConvUTF8)), 0, wxALIGN_RIGHT|wxALL, 3)
switch (type) {
case BXT_PARAM_BOOL: {
bx_param_bool_c *param = (bx_param_bool_c*) param_generic;
if (!plain) ADD_LABEL(prompt);
wxCheckBox *ckbx = new wxCheckBox (context->parent, pstr->id, wxT(""));
ckbx->SetValue (param->get ());
case BXT_PARAM_BOOL:
{
bx_param_bool_c *param = (bx_param_bool_c*) param_generic;
if (!plain) ADD_LABEL(prompt);
wxCheckBox *ckbx = new wxCheckBox(context->parent, pstr->id, wxT(""));
ckbx->SetValue(param->get());
if (description) ckbx->SetToolTip(wxString(description, wxConvUTF8));
sizer->Add (ckbx, 0, wxALL, 2);
if (!plain) sizer->Add (1, 1); // spacer
pstr->u.checkbox = ckbx;
idHash->Put (pstr->id, pstr);
paramHash->Put (pstr->param->get_id (), pstr);
sizer->Add(ckbx, 0, wxALL, 2);
if (!plain) sizer->Add(1, 1); // spacer
pstr->u.checkbox = ckbx;
idHash->Put(pstr->id, pstr);
paramHash->Put(pstr->param->get_id(), pstr);
break;
}
case BXT_PARAM_NUM: {
bx_param_num_c *param = (bx_param_num_c*) param_generic;
if (!plain) ADD_LABEL (prompt);
if (param->get_options () & param->USE_SPIN_CONTROL) {
wxSpinCtrl *spinctrl = new wxSpinCtrl (context->parent, pstr->id);
spinctrl->SetValue (param->get ());
int max = (param->get_max () < (1<<24))?param->get_max ():(1<<24)-1;
spinctrl->SetRange (param->get_min (), SPINCTRL_FIX_MAX (max));
case BXT_PARAM_NUM:
{
bx_param_num_c *param = (bx_param_num_c*) param_generic;
if (!plain) ADD_LABEL(prompt);
if (param->get_options() & param->USE_SPIN_CONTROL) {
wxSpinCtrl *spinctrl = new wxSpinCtrl(context->parent, pstr->id);
spinctrl->SetValue(param->get());
int max = (param->get_max() < (1<<24))?param->get_max():(1<<24)-1;
spinctrl->SetRange(param->get_min(), SPINCTRL_FIX_MAX(max));
if (description) spinctrl->SetToolTip(wxString(description, wxConvUTF8));
sizer->Add (spinctrl, 0, wxALL, 2);
if (!plain) sizer->Add (1, 1); // spacer
sizer->Add(spinctrl, 0, wxALL, 2);
if (!plain) sizer->Add(1, 1); // spacer
pstr->u.spin = spinctrl;
} else {
wxTextCtrl *textctrl = new wxTextCtrl (context->parent, pstr->id, wxT(""), wxDefaultPosition, normalTextSize);
const char *format = param->get_format ();
wxTextCtrl *textctrl = new wxTextCtrl(context->parent, pstr->id, wxT(""), wxDefaultPosition, normalTextSize);
const char *format = param->get_format();
if (!format)
format = strdup(param->get_base () == 16 ? "0x%X" : "%d");
SetTextCtrl (textctrl, format, param->get ());
format = strdup(param->get_base() == 16 ? "0x%X" : "%d");
SetTextCtrl(textctrl, format, param->get());
if (description) textctrl->SetToolTip(wxString(description, wxConvUTF8));
sizer->Add (textctrl, 0, wxALL, 2);
if (!plain) sizer->Add (1, 1); // spacer
sizer->Add(textctrl, 0, wxALL, 2);
if (!plain) sizer->Add(1, 1); // spacer
pstr->u.text = textctrl;
}
idHash->Put (pstr->id, pstr);
paramHash->Put (pstr->param->get_id (), pstr);
idHash->Put(pstr->id, pstr);
paramHash->Put(pstr->param->get_id(), pstr);
break;
}
case BXT_PARAM_ENUM: {
bx_param_enum_c *param = (bx_param_enum_c*) param_generic;
if (!plain) ADD_LABEL (prompt);
wxChoice *choice = new wxChoice (context->parent, pstr->id);
case BXT_PARAM_ENUM:
{
bx_param_enum_c *param = (bx_param_enum_c*) param_generic;
if (!plain) ADD_LABEL(prompt);
wxChoice *choice = new wxChoice(context->parent, pstr->id);
if (description) choice->SetToolTip(wxString(description, wxConvUTF8));
sizer->Add (choice, 0, wxADJUST_MINSIZE, 2);
if (!plain) sizer->Add (1, 1); // spacer
// fill in the choices
int i=0;
const char *ptr;
while (NULL != (ptr = param->get_choice(i++)))
choice->Append(wxString(ptr, wxConvUTF8));
choice->SetSelection (param->get() - param->get_min());
pstr->u.choice = choice;
idHash->Put(pstr->id, pstr);
paramHash->Put(pstr->param->get_id(), pstr);
sizer->Add(choice, 0, wxADJUST_MINSIZE, 2);
if (!plain) sizer->Add(1, 1); // spacer
// fill in the choices
int i=0;
const char *ptr;
while (NULL != (ptr = param->get_choice(i++)))
choice->Append(wxString(ptr, wxConvUTF8));
choice->SetSelection(param->get() - param->get_min());
pstr->u.choice = choice;
idHash->Put(pstr->id, pstr);
paramHash->Put(pstr->param->get_id(), pstr);
break;
}
case BXT_PARAM_STRING: {
case BXT_PARAM_STRING:
{
bx_param_string_c *param = (bx_param_string_c*) param_generic;
char value[1024];
if (!plain) ADD_LABEL(prompt);
@ -765,7 +775,8 @@ void ParamDialog::AddParam (
paramHash->Put(pstr->param->get_id(), pstr);
break;
}
case BXT_LIST: {
case BXT_LIST:
{
bx_list_c *list = (bx_list_c*) param_generic;
if (list->get_options() & bx_list_c::USE_TAB_WINDOW) {
// put each item in a separate tab of a tabbed window
@ -928,7 +939,7 @@ bool ParamDialog::CopyGuiToParam(bx_param_c *param)
p++;
if (src[p] == 0) break;
// try to read a byte of hex
if (sscanf (src+p, "%02x", &n) == 1) {
if (sscanf(src+p, "%02x", &n) == 1) {
buf[i] = n;
p+=2;
} else {
@ -961,7 +972,7 @@ void ParamDialog::EnableChanged()
{
idHash->BeginFind();
wxNode *node;
while ((node = (wxNode*)idHash->Next ()) != NULL) {
while ((node = (wxNode*)idHash->Next()) != NULL) {
ParamStruct *pstr = (ParamStruct*) node->GetData();
if (runtime) {
if ((pstr->param->get_type() != BXT_LIST) && !pstr->param->get_runtime_param())
@ -1054,12 +1065,12 @@ void ParamDialog::ProcessDependentList(ParamStruct *pstrChanged, bool enabled)
void ParamDialog::CopyParamToGui()
{
// loop through all the parameters
idHash->BeginFind ();
idHash->BeginFind();
wxNode *node;
while ((node = (wxNode*)idHash->Next ()) != NULL) {
ParamStruct *pstr = (ParamStruct*) node->GetData ();
while ((node = (wxNode*)idHash->Next()) != NULL) {
ParamStruct *pstr = (ParamStruct*) node->GetData();
IFDBG_DLG(wxLogDebug(wxT("refresh param %s"), pstr->param->get_name()));
int type = pstr->param->get_type ();
int type = pstr->param->get_type();
switch (type) {
case BXT_PARAM_BOOL: {
bx_param_bool_c *boolp = (bx_param_bool_c*) pstr->param;
@ -1103,7 +1114,7 @@ void ParamDialog::OnEvent(wxCommandEvent& event)
}
if (id == pstr->id) {
IFDBG_DLG(wxLogDebug(wxT("event came from window %p (id=%d) controlled by parameter '%s'"), pstr->u.window, id, pstr->param->get_name()));
switch (pstr->param->get_type ()) {
switch (pstr->param->get_type()) {
case BXT_PARAM_BOOL:
case BXT_PARAM_NUM:
case BXT_PARAM_ENUM:
@ -1124,22 +1135,22 @@ void ParamDialog::OnEvent(wxCommandEvent& event)
case wxID_OK:
if (IsModal()) {
if (CopyGuiToParam())
EndModal (wxID_OK);
EndModal(wxID_OK);
} else {
CopyParamToGui();
}
break;
case wxID_CANCEL:
if (IsModal ())
EndModal (wxID_CANCEL);
if (IsModal())
EndModal(wxID_CANCEL);
else
Show (FALSE);
Show(FALSE);
break;
case wxID_HELP:
ShowHelp();
break;
default:
event.Skip ();
event.Skip();
}
}
@ -1165,6 +1176,8 @@ FloppyConfigDialog::FloppyConfigDialog(
wxWindowID id)
: ParamDialog(parent, id)
{
infoSizer = new wxBoxSizer(wxHORIZONTAL);
infoSizer->Add(new wxStaticText(this, -1, wxString("Clicking OK signals a media change for this drive.", wxConvUTF8)), 0, wxALIGN_CENTER|wxALL, 3);
createButton = AddButton(ID_Create, wxT("Create Image"));
AddDefaultButtons();
}
@ -1214,7 +1227,7 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
char name[1024];
strncpy(name, pstrPath->u.text->GetValue().mb_str(wxConvUTF8), sizeof(name));
if ((floppy_type_n_sectors[cap] > 0) && (strlen(name) > 0) && (strcmp(name, "none"))) {
if (CreateImage (0, floppy_type_n_sectors[cap], name)) {
if (CreateImage(0, floppy_type_n_sectors[cap], name)) {
wxString msg(wxT("Created a "));
msg += pstrMedia->u.choice->GetString(cap);
msg += wxT(" disk image called '");
@ -1225,6 +1238,9 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
}
}
break;
case wxID_OK:
// force a media change
((bx_param_enum_c*)pstrStatus->param)->set(BX_EJECTED);
default:
ParamDialog::OnEvent(event);
}
@ -1252,15 +1268,16 @@ LogOptionsDialog::LogOptionsDialog(
AddParam(SIM->get_param("log"));
wxStaticText *text = new wxStaticText(this, -1, LOG_OPTS_PROMPT);
mainSizer->Add(text, 0, wxALL, 10);
gridSizer = new wxFlexGridSizer (2);
gridSizer = new wxFlexGridSizer(2);
mainSizer->Add(gridSizer, 1, wxLEFT, 40);
text = new wxStaticText (this, -1, LOG_OPTS_ADV);
mainSizer->Add(text, 0, wxTOP|wxLEFT, 20);
infoSizer = new wxBoxSizer(wxHORIZONTAL);
text = new wxStaticText(this, -1, LOG_OPTS_ADV);
infoSizer->Add(text, 0, wxALIGN_CENTER|wxALL, 3);
// gridSizer contents
gridSizer->AddGrowableCol(1);
for (int evtype=0; evtype<LOG_OPTS_N_TYPES; evtype++) {
gridSizer->Add(new wxStaticText (this, -1, names[evtype]), 0, wxALL, 5);
gridSizer->Add(new wxStaticText(this, -1, names[evtype]), 0, wxALL, 5);
action[evtype] = makeLogOptionChoiceBox(this, -1, evtype, true);
gridSizer->Add(action[evtype], 1, wxALL|wxGROW|wxADJUST_MINSIZE, 5);
}
@ -1303,7 +1320,7 @@ int LogOptionsDialog::GetAction(int evtype)
// that the size has changed, and the layout is never updated. The
// SetItemMinSize trick was reported on comp.soft-sys.wxwindows by
// Dirk Birnhardt.
void ChangeStaticText (wxSizer *sizer, wxStaticText *win, wxString newtext)
void ChangeStaticText(wxSizer *sizer, wxStaticText *win, wxString newtext)
{
win->SetLabel(newtext);
wxSize sz = win->GetSize();
@ -1312,28 +1329,28 @@ void ChangeStaticText (wxSizer *sizer, wxStaticText *win, wxString newtext)
// CreateImage produces a disk image. It's in the utility function
// area because it's used by both floppy and hard disk image creation.
bool CreateImage (int harddisk, int sectors, const char *filename)
bool CreateImage(int harddisk, int sectors, const char *filename)
{
if (sectors<1) {
wxMessageBox(wxT("The disk size is invalid."), wxT("Invalid Size"), wxOK | wxICON_ERROR);
return false;
}
wxLogDebug(wxT("filename = '%s'\n"), filename);
if (strlen (filename) < 1) {
if (strlen(filename) < 1) {
wxMessageBox(wxT("You must type a file name for the new disk image."), wxT("Bad Filename"), wxOK | wxICON_ERROR);
return false;
}
// create disk image with name and capacity determined by the filename
// and sector args. Call SIM->create_image (filename, sectors, overwrite=0)
// and sector args. Call SIM->create_image(filename, sectors, overwrite=0)
// first which will create the file if it doesn't already exist. If it
// exists, it will instead return -1, and we can ask the user "are you sure
// you want to overwrite?". If yes, call again with overwrite=1.
int ret = SIM->create_disk_image (filename, sectors, 0);
int ret = SIM->create_disk_image(filename, sectors, 0);
if (ret == -1) { // already exists
int answer = wxMessageBox(wxT("File exists. Do you want to overwrite it?"),
wxT("File exists"), wxYES_NO | wxCENTER);
if (answer == wxYES)
ret = SIM->create_disk_image (filename, sectors, 1);
ret = SIM->create_disk_image(filename, sectors, 1);
else
return false; // wxNO
}
@ -1341,7 +1358,7 @@ bool CreateImage (int harddisk, int sectors, const char *filename)
wxMessageBox(wxT("I could not create the disk image. Check for permission problems or available disk space."), wxT("Failed"), wxOK | wxICON_ERROR);
return false;
}
wxASSERT (ret==0);
wxASSERT(ret==0);
return true;
}
@ -1352,12 +1369,12 @@ void SetTextCtrl(wxTextCtrl *ctrl, const char *format, int val)
ctrl->SetValue(tmp);
}
int GetTextCtrlInt (wxTextCtrl *ctrl,
int GetTextCtrlInt(wxTextCtrl *ctrl,
bool *valid,
bool complain,
wxString complaint)
{
wxString tmp (ctrl->GetValue());
wxString tmp(ctrl->GetValue());
char buf[1024];
strncpy(buf, tmp.mb_str(wxConvUTF8), sizeof(buf));
int n = strtol(buf, NULL, 0);
@ -1377,7 +1394,7 @@ bool BrowseTextCtrl(wxTextCtrl *text, wxString prompt, long style)
{
// try to configure the dialog to show hidden files
wxConfigBase::Get() ->Write(wxT("/wxWidgets/wxFileDialog/ShowHidden"), true);
wxFileDialog *fdialog = new wxFileDialog (text->GetParent(), prompt, wxT(""), text->GetValue(), wxT("*.*"), style);
wxFileDialog *fdialog = new wxFileDialog(text->GetParent(), prompt, wxT(""), text->GetValue(), wxT("*.*"), style);
int result = fdialog->ShowModal();
if (result == wxID_OK)
text->SetValue(fdialog->GetPath());
@ -1385,7 +1402,7 @@ bool BrowseTextCtrl(wxTextCtrl *text, wxString prompt, long style)
return (result == wxID_OK);
}
wxChoice *makeLogOptionChoiceBox (wxWindow *parent,
wxChoice *makeLogOptionChoiceBox(wxWindow *parent,
wxWindowID id,
int evtype,
bool includeNoChange)
@ -1405,7 +1422,7 @@ wxChoice *makeLogOptionChoiceBox (wxWindow *parent,
lastChoice++;
}
}
control->SetSelection (lastChoice-1);
control->SetSelection(lastChoice-1);
return control;
}

View File

@ -244,15 +244,12 @@ class ParamDialog: public wxDialog
{
private:
void ShowHelp();
wxChoice *type;
wxTextCtrl *serialDelay, *pasteDelay, *mappingFile;
wxCheckBox *enableKeymap;
int genId();
bool isShowing;
int nbuttons;
bool runtime;
protected:
wxBoxSizer *mainSizer, *buttonSizer;
wxBoxSizer *mainSizer, *buttonSizer, *infoSizer;
// hash table that maps the ID of a wxWidgets control (e.g. wxChoice,
// wxTextCtrl) to the associated ParamStruct object. Data in the hash table
// is of ParamStruct*.

View File

@ -152,6 +152,7 @@ void bx_floppy_ctrl_c::init(void)
{
Bit8u i, devtype, cmos_value;
char pname[10];
bx_list_c *floppy;
BX_DEBUG(("Init $Id$"));
DEV_dma_register_8bit_channel(2, dma_read, dma_write, "Floppy Drive");
@ -183,7 +184,8 @@ void bx_floppy_ctrl_c::init(void)
// Floppy A setup
//
devtype = SIM->get_param_enum(BXPN_FLOPPYA_DEVTYPE)->get();
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYA);
devtype = SIM->get_param_enum("devtype", floppy)->get();
cmos_value = (devtype << 4);
if (devtype != BX_FDD_NONE) {
BX_FD_THIS s.device_type[0] = 1 << (devtype - 1);
@ -193,21 +195,21 @@ void bx_floppy_ctrl_c::init(void)
BX_FD_THIS s.statusbar_id[0] = -1;
}
if (SIM->get_param_enum(BXPN_FLOPPYA_TYPE)->get() != BX_FLOPPY_NONE) {
if (SIM->get_param_enum(BXPN_FLOPPYA_STATUS)->get() == BX_INSERTED) {
BX_FD_THIS s.media[0].write_protected = SIM->get_param_bool(BXPN_FLOPPYA_READONLY)->get();
if (evaluate_media(BX_FD_THIS s.device_type[0], SIM->get_param_enum(BXPN_FLOPPYA_TYPE)->get(),
SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), & BX_FD_THIS s.media[0])) {
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])) {
BX_FD_THIS s.media_present[0] = 1;
#define MED (BX_FD_THIS s.media[0])
BX_INFO(("fd0: '%s' ro=%d, h=%d,t=%d,spt=%d",
SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(),
SIM->get_param_string("path", floppy)->getptr(),
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
if (MED.write_protected)
SIM->get_param_bool(BXPN_FLOPPYA_READONLY)->set(1);
SIM->get_param_bool("readonly", floppy)->set(1);
#undef MED
} else {
SIM->get_param_enum(BXPN_FLOPPYA_STATUS)->set(BX_EJECTED);
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
}
}
}
@ -216,7 +218,8 @@ void bx_floppy_ctrl_c::init(void)
// Floppy B setup
//
devtype = SIM->get_param_enum(BXPN_FLOPPYB_DEVTYPE)->get();
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYB);
devtype = SIM->get_param_enum("devtype", floppy)->get();
cmos_value |= devtype;
if (devtype != BX_FDD_NONE) {
BX_FD_THIS s.device_type[1] = 1 << (devtype - 1);
@ -226,21 +229,21 @@ void bx_floppy_ctrl_c::init(void)
BX_FD_THIS s.statusbar_id[1] = -1;
}
if (SIM->get_param_enum(BXPN_FLOPPYB_TYPE)->get() != BX_FLOPPY_NONE) {
if (SIM->get_param_enum(BXPN_FLOPPYB_STATUS)->get() == BX_INSERTED) {
BX_FD_THIS s.media[1].write_protected = SIM->get_param_bool(BXPN_FLOPPYB_READONLY)->get();
if (evaluate_media(BX_FD_THIS s.device_type[1], SIM->get_param_enum(BXPN_FLOPPYB_TYPE)->get(),
SIM->get_param_string(BXPN_FLOPPYB_PATH)->getptr(), & BX_FD_THIS s.media[1])) {
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])) {
BX_FD_THIS s.media_present[1] = 1;
#define MED (BX_FD_THIS s.media[1])
BX_INFO(("fd1: '%s' ro=%d, h=%d,t=%d,spt=%d",
SIM->get_param_string(BXPN_FLOPPYB_PATH)->getptr(),
SIM->get_param_string("path", floppy)->getptr(),
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
if (MED.write_protected)
SIM->get_param_bool(BXPN_FLOPPYB_READONLY)->set(1);
SIM->get_param_bool("readonly", floppy)->set(1);
#undef MED
} else {
SIM->get_param_enum(BXPN_FLOPPYB_STATUS)->set(BX_EJECTED);
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
}
}
}
@ -1093,7 +1096,8 @@ void bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
drive, offset, bytes, (direction==FROM_FLOPPY)? "from" : "to"));
#if BX_WITH_MACOS
if (strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
const char *pname = (drive == 0) ? BXPN_FLOPPYA_PATH : BXPN_FLOPPYB_PATH;
if (strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive))
#endif
{
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
@ -1111,7 +1115,7 @@ void bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
ret = BX_FD_THIS s.media[drive].vvfat->read(buffer, bytes);
#if BX_WITH_MACOS
} else if (!strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive))
ret = fd_read((char *) buffer, offset, bytes);
#endif
} else {
@ -1132,7 +1136,7 @@ void bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
ret = BX_FD_THIS s.media[drive].vvfat->write(buffer, bytes);
#if BX_WITH_MACOS
} else if (!strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive))
ret = fd_write((char *) buffer, offset, bytes);
#endif
} else {
@ -1444,69 +1448,58 @@ unsigned bx_floppy_ctrl_c::set_media_status(unsigned drive, bx_bool status)
{
char *path;
unsigned type;
bx_list_c *floppy;
if (drive == 0)
type = SIM->get_param_enum(BXPN_FLOPPYA_TYPE)->get();
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYA);
else
type = SIM->get_param_enum(BXPN_FLOPPYB_TYPE)->get();
floppy = (bx_list_c*)SIM->get_param(BXPN_FLOPPYB);
type = SIM->get_param_enum("type", floppy)->get();
// if setting to the current value, nothing to do
if ((status == BX_FD_THIS s.media_present[drive]) &&
((status == 0) || (type == BX_FD_THIS s.media[drive].type)))
return(status);
return status;
if (status == 0) {
// eject floppy
close_media(&BX_FD_THIS s.media[drive]);
BX_FD_THIS s.media_present[drive] = 0;
if (drive == 0) {
SIM->get_param_enum(BXPN_FLOPPYA_STATUS)->set(BX_EJECTED);
} else {
SIM->get_param_enum(BXPN_FLOPPYB_STATUS)->set(BX_EJECTED);
}
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
BX_FD_THIS s.DIR[drive] |= 0x80; // disk changed line
return(0);
return 0;
} else {
// insert floppy
if (drive == 0) {
path = SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr();
} else {
path = SIM->get_param_string(BXPN_FLOPPYB_PATH)->getptr();
}
path = SIM->get_param_string("path", floppy)->getptr();
if (!strcmp(path, "none"))
return(0);
return 0;
if (evaluate_media(BX_FD_THIS s.device_type[drive], type, path, & BX_FD_THIS s.media[drive])) {
BX_FD_THIS s.media_present[drive] = 1;
if (drive == 0) {
#define MED (BX_FD_THIS s.media[0])
BX_INFO(("fd0: '%s' ro=%d, h=%d,t=%d,spt=%d",
SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(),
SIM->get_param_string("path", floppy)->getptr(),
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
if (MED.write_protected)
SIM->get_param_bool(BXPN_FLOPPYA_READONLY)->set(1);
SIM->get_param_bool("readonly", floppy)->set(1);
#undef MED
SIM->get_param_enum(BXPN_FLOPPYA_STATUS)->set(BX_INSERTED);
SIM->get_param_enum("status", floppy)->set(BX_INSERTED);
} else {
#define MED (BX_FD_THIS s.media[1])
BX_INFO(("fd1: '%s' ro=%d, h=%d,t=%d,spt=%d",
SIM->get_param_string(BXPN_FLOPPYB_PATH)->getptr(),
SIM->get_param_string("path", floppy)->getptr(),
MED.write_protected, MED.heads, MED.tracks, MED.sectors_per_track));
if (MED.write_protected)
SIM->get_param_bool(BXPN_FLOPPYB_READONLY)->set(1);
SIM->get_param_bool("readonly", floppy)->set(1);
#undef MED
SIM->get_param_enum(BXPN_FLOPPYB_STATUS)->set(BX_INSERTED);
SIM->get_param_enum("status", floppy)->set(BX_INSERTED);
}
return(1);
return 1;
} else {
BX_FD_THIS s.media_present[drive] = 0;
if (drive == 0) {
SIM->get_param_enum(BXPN_FLOPPYA_STATUS)->set(BX_EJECTED);
SIM->get_param_enum(BXPN_FLOPPYA_TYPE)->set(BX_FLOPPY_NONE);
} else {
SIM->get_param_enum(BXPN_FLOPPYB_STATUS)->set(BX_EJECTED);
SIM->get_param_enum(BXPN_FLOPPYB_TYPE)->set(BX_FLOPPY_NONE);
}
return(0);
SIM->get_param_enum("status", floppy)->set(BX_EJECTED);
SIM->get_param_enum("type", floppy)->set(BX_FLOPPY_NONE);
return 0;
}
}
}
@ -1574,7 +1567,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path,
// open media file (image file or device)
#ifdef macintosh
media->fd = 0;
if (strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
if (strcmp(path, SuperDrive))
#endif
#ifdef WIN32
if ((isalpha(path[0])) && (path[1] == ':') && (strlen(path) == 2)) {
@ -1616,7 +1609,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path,
media->write_protected = 1;
#ifdef macintosh
media->fd = 0;
if (strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
if (strcmp(path, SuperDrive))
#endif
#ifdef WIN32
if (raw_floppy == 1)
@ -1634,7 +1627,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path,
}
#if BX_WITH_MACOS
if (!strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive))
if (!strcmp(path, SuperDrive))
ret = fd_stat(&stat_buf);
else
ret = fstat(media->fd, &stat_buf);
@ -1939,8 +1932,7 @@ const char* bx_floppy_ctrl_c::floppy_param_string_handler(bx_param_string_c *par
val = "none";
}
param->get_param_path(pname, BX_PATHNAME_LEN);
if ((!strcmp(pname, BXPN_FLOPPYA_PATH)) ||
(!strcmp(pname, BXPN_FLOPPYB_PATH))) {
if ((!strncmp(pname, "floppy", 6)) && (!strcmp(param->get_name(), "path"))) {
if (set==1) {
drive = atoi(base->get_name());
if (SIM->get_param_enum("devtype", base)->get() == BX_FDD_NONE) {

View File

@ -138,13 +138,11 @@
#define BXPN_FLOPPYA_DEVTYPE "floppy.0.devtype"
#define BXPN_FLOPPYA_PATH "floppy.0.path"
#define BXPN_FLOPPYA_TYPE "floppy.0.type"
#define BXPN_FLOPPYA_READONLY "floppy.0.readonly"
#define BXPN_FLOPPYA_STATUS "floppy.0.status"
#define BXPN_FLOPPYB "floppy.1"
#define BXPN_FLOPPYB_DEVTYPE "floppy.1.devtype"
#define BXPN_FLOPPYB_PATH "floppy.1.path"
#define BXPN_FLOPPYB_TYPE "floppy.1.type"
#define BXPN_FLOPPYB_READONLY "floppy.1.readonly"
#define BXPN_FLOPPYB_STATUS "floppy.1.status"
#define BXPN_ATA0_RES "ata.0.resources"
#define BXPN_ATA1_RES "ata.1.resources"