From 2eca3a4ddbadd2cb29631dcc9e5ca4bb37a10973 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 9 Jan 2025 11:07:10 +0100 Subject: [PATCH] enhancement: populate more fields in Hardfile dialog (fixes #1578) --- src/cfgfile.cpp | 3 +- src/include/options.h | 2 +- src/osdep/amiberry_gui.cpp | 57 ++++++++- src/osdep/gui/EditFilesysHardDrive.cpp | 6 +- src/osdep/gui/EditFilesysHardfile.cpp | 163 ++++++++++++++++++++----- 5 files changed, 193 insertions(+), 38 deletions(-) diff --git a/src/cfgfile.cpp b/src/cfgfile.cpp index f728f50fd..e23bdaa15 100644 --- a/src/cfgfile.cpp +++ b/src/cfgfile.cpp @@ -7621,7 +7621,8 @@ static void parse_hardfile_spec (struct uae_prefs *p, const TCHAR *spec) const std::string x2 = parameter.substr(pos + 1, parameter.length()); #ifdef FILESYS default_hfdlg(¤t_hfdlg, false); - updatehdfinfo(true, false, false); + std::string txt1, txt2; + updatehdfinfo(true, false, false, txt1, txt2); current_hfdlg.ci.type = UAEDEV_HDF; _tcscpy(current_hfdlg.ci.devname, x1.c_str()); diff --git a/src/include/options.h b/src/include/options.h index be1ee7db7..5686c577c 100644 --- a/src/include/options.h +++ b/src/include/options.h @@ -1277,7 +1277,7 @@ extern void hardfile_testrdb(struct hfdlg_vals* hdf); extern void default_tapedlg(struct tapedlg_vals* f); extern void default_fsvdlg(struct fsvdlg_vals* f); extern void default_hfdlg(struct hfdlg_vals* f, bool rdb); -extern void updatehdfinfo(bool force, bool defaults, bool realdrive); +extern void updatehdfinfo(bool force, bool defaults, bool realdrive, std::string& txtHdfInfo, std::string& txtHdfInfo2); #ifdef AMIBERRY struct amiberry_customised_layout diff --git a/src/osdep/amiberry_gui.cpp b/src/osdep/amiberry_gui.cpp index f5ec25109..80cd81566 100644 --- a/src/osdep/amiberry_gui.cpp +++ b/src/osdep/amiberry_gui.cpp @@ -1461,10 +1461,12 @@ void default_rdb_hfdlg(struct hfdlg_vals* f, const TCHAR* filename) hardfile_testrdb(f); } -void updatehdfinfo(bool force, bool defaults, bool realdrive) +void updatehdfinfo(bool force, bool defaults, bool realdrive, std::string& txtHdfInfo, std::string& txtHdfInfo2) { - uae_u8 id[512] = { 0 }; - uae_u32 i; + uae_u8 id[512] = { }; + uae_u32 blocks, cyls, i; + TCHAR tmp[200], tmp2[200]; + TCHAR idtmp[17]; bool phys = is_hdf_rdb(); uae_u64 bsize = 0; @@ -1528,6 +1530,55 @@ void updatehdfinfo(bool force, bool defaults, bool realdrive) if (current_hfdlg.ci.unit_feature_level == HD_LEVEL_ATA_1 && bsize >= 4 * static_cast(0x40000000)) current_hfdlg.ci.unit_feature_level = HD_LEVEL_ATA_2; } + + cyls = phys ? current_hfdlg.ci.pcyls : current_hfdlg.forcedcylinders; + int heads = phys ? current_hfdlg.ci.pheads : current_hfdlg.ci.surfaces; + int secs = phys ? current_hfdlg.ci.psecs : current_hfdlg.ci.sectors; + if (!cyls && current_hfdlg.ci.blocksize && secs && heads) { + cyls = (uae_u32)(bsize / ((uae_u64)current_hfdlg.ci.blocksize * secs * heads)); + } + blocks = cyls * (secs * heads); + if (!blocks && current_hfdlg.ci.blocksize) + blocks = (uae_u32)(bsize / current_hfdlg.ci.blocksize); + if (current_hfdlg.ci.max_lba) + blocks = (uae_u32)current_hfdlg.ci.max_lba; + + for (i = 0; i < sizeof (idtmp) / sizeof (TCHAR) - 1; i++) { + TCHAR c = id[i]; + if (c < 32 || c > 126) + c = '.'; + idtmp[i] = c; + idtmp[i + 1] = 0; + } + + tmp[0] = 0; + if (bsize) { + _sntprintf (tmp2, sizeof tmp2, _T(" %s [%02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X]"), idtmp, + id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7], + id[8], id[9], id[10], id[11], id[12], id[13], id[14], id[15]); + if (!blocks) { + _sntprintf (tmp, sizeof tmp, _T("%uMB"), (unsigned int)(bsize / (1024 * 1024))); + } else if (blocks && !cyls) { + _sntprintf (tmp, sizeof tmp, _T("%u blocks, %.1fMB"), + blocks, + (double)bsize / (1024.0 * 1024.0)); + } else { + _sntprintf (tmp, sizeof tmp, _T("%u/%u/%u, %u/%u blocks, %.1fMB/%.1fMB"), + cyls, heads, secs, + blocks, (int)(bsize / current_hfdlg.ci.blocksize), + (double)blocks * 1.0 * current_hfdlg.ci.blocksize / (1024.0 * 1024.0), + (double)bsize / (1024.0 * 1024.0)); + if ((uae_u64)cyls * heads * secs > bsize / current_hfdlg.ci.blocksize) { + _tcscat (tmp2, _T(" [Geometry larger than drive!]")); + } else if (cyls > 65535) { + _tcscat (tmp2, _T(" [Too many cyls]")); + } + } + if (txtHdfInfo.empty() && txtHdfInfo2.empty()) { + txtHdfInfo = std::string(tmp); + txtHdfInfo2 = std::string(tmp2); + } + } } void new_filesys(int entry) diff --git a/src/osdep/gui/EditFilesysHardDrive.cpp b/src/osdep/gui/EditFilesysHardDrive.cpp index cf6660ccc..ced49d124 100644 --- a/src/osdep/gui/EditFilesysHardDrive.cpp +++ b/src/osdep/gui/EditFilesysHardDrive.cpp @@ -131,7 +131,8 @@ class FilesysHardDriveActionListener : public gcn::ActionListener current_hfdlg.ci.controller_type_unit = posn / HD_CONTROLLER_NEXT_UNIT; current_hfdlg.forcedcylinders = 0; current_hfdlg.ci.cyls = current_hfdlg.ci.highcyl = current_hfdlg.ci.sectors = current_hfdlg.ci.surfaces = 0; - updatehdfinfo(true, true, true); + std::string txt1, txt2; + updatehdfinfo(true, true, true, txt1, txt2); inithdcontroller(current_hfdlg.ci.controller_type, current_hfdlg.ci.controller_type_unit, UAEDEV_HDF, current_hfdlg.ci.rootdir[0] != 0); setharddrive(); } @@ -596,7 +597,8 @@ bool EditFilesysHardDrive(const int unit_no) fileSelected = false; } - updatehdfinfo(true, false, true); + std::string txt1, txt2; + updatehdfinfo(true, false, true, txt1, txt2); // Prepare the screen once uae_gui->logic(); diff --git a/src/osdep/gui/EditFilesysHardfile.cpp b/src/osdep/gui/EditFilesysHardfile.cpp index 7efaaf070..99a410565 100644 --- a/src/osdep/gui/EditFilesysHardfile.cpp +++ b/src/osdep/gui/EditFilesysHardfile.cpp @@ -2,6 +2,7 @@ #include #include + #include #include #include "SelectorEntry.hpp" @@ -16,6 +17,7 @@ #include "gui_handling.h" #include "amiberry_gfx.h" #include "amiberry_input.h" +#include "rommgr.h" enum { @@ -59,12 +61,13 @@ static gcn::DropDown* cboUnit; static gcn::DropDown* cboHdfControllerType; static gcn::DropDown* cboHdfFeatureLevel; -static gcn::TextField* txtHdfLine1; -static gcn::TextField* txtHdfLine2; +static gcn::TextField* txtHdfInfo; +static gcn::TextField* txtHdfInfo2; static gcn::Button *cmdOK; static gcn::Button *cmdCancel; +static gcn::CheckBox* chkManualGeometry; static gcn::Label *lblSurfaces; static gcn::TextField *txtSurfaces; static gcn::Label *lblReserved; @@ -74,10 +77,43 @@ static gcn::TextField *txtSectors; static gcn::Label *lblBlocksize; static gcn::TextField *txtBlocksize; +std::string txt1, txt2; + +static void sethardfilegeo() +{ + if (current_hfdlg.ci.geometry[0]) { + current_hfdlg.ci.physical_geometry = true; + chkManualGeometry->setSelected(true); + chkManualGeometry->setEnabled(false); + get_hd_geometry(¤t_hfdlg.ci); + } else if (current_hfdlg.ci.chs) { + current_hfdlg.ci.physical_geometry = true; + chkManualGeometry->setSelected(true); + chkManualGeometry->setEnabled(false); + txtSectors->setEnabled(false); + txtSurfaces->setEnabled(false); + txtReserved->setEnabled(false); + txtBlocksize->setEnabled(false); + } else { + chkManualGeometry->setEnabled(true); + } +} + static void sethd() { const bool rdb = is_hdf_rdb(); - const bool enablegeo = !rdb; + const bool physgeo = (rdb && chkManualGeometry->isSelected()) || current_hfdlg.ci.chs; + const bool enablegeo = (!rdb || (physgeo && current_hfdlg.ci.geometry[0] == 0)) && !current_hfdlg.ci.chs; + const struct expansionromtype *ert = get_unit_expansion_rom(current_hfdlg.ci.controller_type); + if (ert && current_hfdlg.ci.controller_unit >= 8) { + if (!_tcscmp(ert->name, _T("a2091"))) { + current_hfdlg.ci.unit_feature_level = HD_LEVEL_SASI_CHS; + } else if (!_tcscmp(ert->name, _T("a2090a"))) { + current_hfdlg.ci.unit_feature_level = HD_LEVEL_SCSI_1; + } + } + if (!physgeo) + current_hfdlg.ci.physical_geometry = false; txtSectors->setEnabled(enablegeo); txtSurfaces->setEnabled(enablegeo); txtReserved->setEnabled(enablegeo); @@ -104,9 +140,12 @@ static void sethardfile() std::string rootdir, filesys, strdevname; char tmp[32]; + sethardfilegeo(); + auto ide = current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_IDE_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_IDE_LAST; bool scsi = current_hfdlg.ci.controller_type >= HD_CONTROLLER_TYPE_SCSI_FIRST && current_hfdlg.ci.controller_type <= HD_CONTROLLER_TYPE_SCSI_LAST; auto rdb = is_hdf_rdb(); + bool physgeo = rdb && chkManualGeometry->isSelected(); auto disables = !rdb || current_hfdlg.ci.controller_type == HD_CONTROLLER_TYPE_UAE; bool rdsk = current_hfdlg.rdb; @@ -134,6 +173,10 @@ static void sethardfile() chkDoNotMount->setSelected(!ISAUTOMOUNT(¤t_hfdlg.ci)); chkVirtBootable->setEnabled(disables); chkDoNotMount->setEnabled(disables); + chkVirtBootable->setVisible(!disables); + chkDoNotMount->setVisible(!disables); + txtBootPri->setVisible(!disables); + chkManualGeometry->setVisible(!rdb); if (rdb) { chkRdbMode->setEnabled(!rdsk); @@ -144,6 +187,9 @@ static void sethardfile() chkRdbMode->setEnabled(true); chkRdbMode->setSelected(false); } + if (!rdb) { + chkManualGeometry->setSelected(false); + } auto selIndex = 0; for (auto i = 0; i < controller.size(); ++i) { if (controller[i].type == current_hfdlg.ci.controller_type) @@ -154,6 +200,16 @@ static void sethardfile() sethardfiletypes(); } +static void set_phys_cyls() +{ + if (chkManualGeometry->isSelected()) { + int v = (current_hfdlg.ci.pheads * current_hfdlg.ci.psecs * current_hfdlg.ci.blocksize); + current_hfdlg.ci.pcyls = (int)(v ? current_hfdlg.size / v : 0); + current_hfdlg.ci.physical_geometry = true; + txtReserved->setText(std::to_string(current_hfdlg.ci.pcyls)); + } +} + static gcn::StringListModel controllerListModel; static gcn::StringListModel unitListModel; static gcn::StringListModel hdfTypeListModel; @@ -183,7 +239,9 @@ class FilesysHardfileActionListener : public gcn::ActionListener strncpy(current_hfdlg.ci.geometry, tmp.c_str(), sizeof(current_hfdlg.ci.geometry) - 1); current_hfdlg.ci.geometry[sizeof(current_hfdlg.ci.geometry) - 1] = '\0'; sethardfile(); - updatehdfinfo(true, false, false); + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); } wndEditFilesysHardfile->requestModalFocus(); } @@ -206,7 +264,9 @@ class FilesysHardfileActionListener : public gcn::ActionListener strncpy(current_hfdlg.ci.filesys, tmp.c_str(), sizeof(current_hfdlg.ci.filesys) - 1); current_hfdlg.ci.filesys[sizeof(current_hfdlg.ci.filesys) - 1] = '\0'; sethardfile(); - updatehdfinfo(true, false, false); + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); } wndEditFilesysHardfile->requestModalFocus(); } @@ -232,8 +292,13 @@ class FilesysHardfileActionListener : public gcn::ActionListener if (current_hfdlg.ci.devname[0] == 0) CreateDefaultDevicename(current_hfdlg.ci.devname); - + hardfile_testrdb(¤t_hfdlg); + updatehdfinfo (true, true, false, txt1, txt2); + get_hd_geometry (¤t_hfdlg.ci); + updatehdfinfo (false, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); sethardfile(); } wndEditFilesysHardfile->requestModalFocus(); @@ -304,6 +369,14 @@ class FilesysHardfileActionListener : public gcn::ActionListener } sethardfile(); } + else if (actionEvent.getSource() == chkManualGeometry) + { + current_hfdlg.ci.physical_geometry = chkManualGeometry->isSelected(); + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); + sethardfile(); + } else { if (actionEvent.getSource() == cmdOK) @@ -352,31 +425,43 @@ class FilesysHardfileFocusListener : public gcn::FocusListener } else if (event.getSource() == txtSurfaces) { - p = ¤t_hfdlg.ci.surfaces; + p = chkManualGeometry->isSelected() ? ¤t_hfdlg.ci.pheads : ¤t_hfdlg.ci.surfaces; v = *p; *p = atoi(txtSurfaces->getText().c_str()); if (v != *p) { - updatehdfinfo(true, false, false); + set_phys_cyls(); + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); chkRdbMode->setSelected(!is_hdf_rdb()); } } else if (event.getSource() == txtReserved) { - p = ¤t_hfdlg.ci.reserved; + p = chkManualGeometry->isSelected() ? ¤t_hfdlg.ci.pcyls : ¤t_hfdlg.ci.reserved; v = *p; *p = atoi(txtReserved->getText().c_str()); if (v != *p) { - updatehdfinfo(true, false, false); + if (chkManualGeometry->isSelected()) + { + current_hfdlg.ci.physical_geometry = true; + } + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); chkRdbMode->setSelected(!is_hdf_rdb()); } } else if (event.getSource() == txtSectors) { - p = ¤t_hfdlg.ci.sectors; + p = chkManualGeometry->isSelected() ? ¤t_hfdlg.ci.psecs : ¤t_hfdlg.ci.sectors; v = *p; *p = atoi(txtSectors->getText().c_str()); if (v != *p) { - updatehdfinfo(true, false, false); + set_phys_cyls(); + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); chkRdbMode->setSelected(!is_hdf_rdb()); } @@ -385,7 +470,11 @@ class FilesysHardfileFocusListener : public gcn::FocusListener v = current_hfdlg.ci.blocksize; current_hfdlg.ci.blocksize = atoi(txtBlocksize->getText().c_str()); if (v != current_hfdlg.ci.blocksize) - updatehdfinfo(true, false, false); + { + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); + } } } }; @@ -487,6 +576,13 @@ static void InitEditFilesysHardfile() chkVirtBootable->setForegroundColor(gui_foreground_color); chkVirtBootable->addActionListener(filesysHardfileActionListener); + chkManualGeometry = new gcn::CheckBox("Manual geometry", false); + chkManualGeometry->setId("chkHdfManualGeometry"); + chkManualGeometry->setBaseColor(gui_base_color); + chkManualGeometry->setBackgroundColor(gui_background_color); + chkManualGeometry->setForegroundColor(gui_foreground_color); + chkManualGeometry->addActionListener(filesysHardfileActionListener); + chkDoNotMount = new gcn::CheckBox("Do not mount"); chkDoNotMount->setId("chkHdfDoNotMount"); chkDoNotMount->setBaseColor(gui_base_color); @@ -539,19 +635,19 @@ static void InitEditFilesysHardfile() cboHdfFeatureLevel->setId("cboHdfFeatureLevel"); cboHdfFeatureLevel->addActionListener(filesysHardfileActionListener); - txtHdfLine1 = new gcn::TextField(); - txtHdfLine1->setSize(DIALOG_WIDTH - DISTANCE_BORDER * 2, TEXTFIELD_HEIGHT); - txtHdfLine1->setBaseColor(gui_base_color); - txtHdfLine1->setBackgroundColor(gui_background_color); - txtHdfLine1->setForegroundColor(gui_foreground_color); - txtHdfLine1->setEnabled(false); + txtHdfInfo = new gcn::TextField(); + txtHdfInfo->setSize(DIALOG_WIDTH - DISTANCE_BORDER * 2, TEXTFIELD_HEIGHT); + txtHdfInfo->setBaseColor(gui_base_color); + txtHdfInfo->setBackgroundColor(gui_background_color); + txtHdfInfo->setForegroundColor(gui_foreground_color); + txtHdfInfo->setEnabled(false); - txtHdfLine2 = new gcn::TextField(); - txtHdfLine2->setSize(DIALOG_WIDTH - DISTANCE_BORDER * 2, TEXTFIELD_HEIGHT); - txtHdfLine2->setBaseColor(gui_base_color); - txtHdfLine2->setBackgroundColor(gui_background_color); - txtHdfLine2->setForegroundColor(gui_foreground_color); - txtHdfLine2->setEnabled(false); + txtHdfInfo2 = new gcn::TextField(); + txtHdfInfo2->setSize(DIALOG_WIDTH - DISTANCE_BORDER * 2, TEXTFIELD_HEIGHT); + txtHdfInfo2->setBaseColor(gui_base_color); + txtHdfInfo2->setBackgroundColor(gui_background_color); + txtHdfInfo2->setForegroundColor(gui_foreground_color); + txtHdfInfo2->setEnabled(false); lblSurfaces = new gcn::Label("Surfaces:"); lblSurfaces->setAlignment(gcn::Graphics::Right); @@ -631,6 +727,7 @@ static void InitEditFilesysHardfile() wndEditFilesysHardfile->add(lblBootPri, posX, posY); wndEditFilesysHardfile->add(txtBootPri, posX + lblBootPri->getWidth() + 8, posY); + wndEditFilesysHardfile->add(chkManualGeometry, txtBootPri->getX() + txtBootPri->getWidth() + DISTANCE_NEXT_X * 4, posY); posY += txtBootPri->getHeight() + DISTANCE_NEXT_Y; posX = txtDevice->getX(); @@ -666,9 +763,9 @@ static void InitEditFilesysHardfile() posY = cboController->getY() + cboController->getHeight() + DISTANCE_NEXT_Y; - wndEditFilesysHardfile->add(txtHdfLine1, DISTANCE_BORDER, posY); - posY += txtHdfLine1->getHeight() + DISTANCE_NEXT_Y; - wndEditFilesysHardfile->add(txtHdfLine2, DISTANCE_BORDER, posY); + wndEditFilesysHardfile->add(txtHdfInfo, DISTANCE_BORDER, posY); + posY += txtHdfInfo->getHeight() + DISTANCE_NEXT_Y; + wndEditFilesysHardfile->add(txtHdfInfo2, DISTANCE_BORDER, posY); wndEditFilesysHardfile->add(cmdOK); wndEditFilesysHardfile->add(cmdCancel); @@ -707,14 +804,15 @@ static void ExitEditFilesysHardfile() delete chkVirtBootable; delete chkDoNotMount; delete chkRdbMode; + delete chkManualGeometry; delete lblController; delete cboController; delete cboUnit; delete cboHdfControllerType; delete cboHdfFeatureLevel; - delete txtHdfLine1; - delete txtHdfLine2; + delete txtHdfInfo; + delete txtHdfInfo2; delete lblSurfaces; delete txtSurfaces; @@ -1061,7 +1159,10 @@ bool EditFilesysHardfile(const int unit_no) fileSelected = false; } - updatehdfinfo(true, false, false); + chkManualGeometry->setSelected(current_hfdlg.ci.physical_geometry); + updatehdfinfo(true, false, false, txt1, txt2); + txtHdfInfo->setText(txt1); + txtHdfInfo2->setText(txt2); sethardfile(); // Prepare the screen once