A bit more clang-format
This commit is contained in:
@@ -45,9 +45,9 @@ extern "C" {
|
||||
#include "qt_models_common.hpp"
|
||||
#include "qt_util.hpp"
|
||||
|
||||
HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::HarddiskDialog)
|
||||
HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::HarddiskDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -86,7 +86,7 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) :
|
||||
});
|
||||
}
|
||||
|
||||
auto* model = ui->comboBoxFormat->model();
|
||||
auto *model = ui->comboBoxFormat->model();
|
||||
model->insertRows(0, 6);
|
||||
model->setData(model->index(0, 0), tr("Raw image (.img)"));
|
||||
model->setData(model->index(1, 0), tr("HDI image (.hdi)"));
|
||||
@@ -108,9 +108,9 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) :
|
||||
|
||||
model = ui->comboBoxType->model();
|
||||
for (int i = 0; i < 127; i++) {
|
||||
uint64_t size = ((uint64_t) hdd_table[i][0]) * hdd_table[i][1] * hdd_table[i][2];
|
||||
uint64_t size = ((uint64_t) hdd_table[i][0]) * hdd_table[i][1] * hdd_table[i][2];
|
||||
uint32_t size_mb = size >> 11LL;
|
||||
//QString text = QString("%1 MiB (CHS: %2, %3, %4)").arg(size_mb).arg(hdd_table[i][0]).arg(hdd_table[i][1]).arg(hdd_table[i][2]);
|
||||
// QString text = QString("%1 MiB (CHS: %2, %3, %4)").arg(size_mb).arg(hdd_table[i][0]).arg(hdd_table[i][1]).arg(hdd_table[i][2]);
|
||||
QString text = QString::asprintf(tr("%u MB (CHS: %i, %i, %i)").toUtf8().constData(), (size_mb), (hdd_table[i][0]), (hdd_table[i][1]), (hdd_table[i][2]));
|
||||
Models::AddEntry(model, text, i);
|
||||
}
|
||||
@@ -126,23 +126,33 @@ HarddiskDialog::~HarddiskDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
uint8_t HarddiskDialog::bus() const {
|
||||
uint8_t
|
||||
HarddiskDialog::bus() const
|
||||
{
|
||||
return static_cast<uint8_t>(ui->comboBoxBus->currentData().toUInt());
|
||||
}
|
||||
|
||||
uint8_t HarddiskDialog::channel() const {
|
||||
uint8_t
|
||||
HarddiskDialog::channel() const
|
||||
{
|
||||
return static_cast<uint8_t>(ui->comboBoxChannel->currentData().toUInt());
|
||||
}
|
||||
|
||||
QString HarddiskDialog::fileName() const {
|
||||
QString
|
||||
HarddiskDialog::fileName() const
|
||||
{
|
||||
return ui->fileField->fileName();
|
||||
}
|
||||
|
||||
uint32_t HarddiskDialog::speed() const {
|
||||
uint32_t
|
||||
HarddiskDialog::speed() const
|
||||
{
|
||||
return static_cast<uint32_t>(ui->comboBoxSpeed->currentData().toUInt());
|
||||
}
|
||||
|
||||
void HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index) {
|
||||
void
|
||||
HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index)
|
||||
{
|
||||
bool enabled;
|
||||
if (index == 5) { /* They switched to a diff VHD; disable the geometry fields. */
|
||||
enabled = false;
|
||||
@@ -177,12 +187,13 @@ void HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index) {
|
||||
* of about 21 MB, and should only be necessary for VHDs larger than 31.5 GB, so should never be more
|
||||
* than a tenth of a percent change in size.
|
||||
*/
|
||||
static void adjust_86box_geometry_for_vhd(MVHDGeom *_86box_geometry, MVHDGeom *vhd_geometry)
|
||||
static void
|
||||
adjust_86box_geometry_for_vhd(MVHDGeom *_86box_geometry, MVHDGeom *vhd_geometry)
|
||||
{
|
||||
if (_86box_geometry->cyl <= 65535) {
|
||||
vhd_geometry->cyl = _86box_geometry->cyl;
|
||||
vhd_geometry->cyl = _86box_geometry->cyl;
|
||||
vhd_geometry->heads = _86box_geometry->heads;
|
||||
vhd_geometry->spt = _86box_geometry->spt;
|
||||
vhd_geometry->spt = _86box_geometry->spt;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -194,33 +205,35 @@ static void adjust_86box_geometry_for_vhd(MVHDGeom *_86box_geometry, MVHDGeom *v
|
||||
if (remainder > 0)
|
||||
desired_sectors += (85680 - remainder);
|
||||
|
||||
_86box_geometry->cyl = desired_sectors / (16 * 63);
|
||||
_86box_geometry->cyl = desired_sectors / (16 * 63);
|
||||
_86box_geometry->heads = 16;
|
||||
_86box_geometry->spt = 63;
|
||||
_86box_geometry->spt = 63;
|
||||
|
||||
vhd_geometry->cyl = desired_sectors / (16 * 255);
|
||||
vhd_geometry->cyl = desired_sectors / (16 * 255);
|
||||
vhd_geometry->heads = 16;
|
||||
vhd_geometry->spt = 255;
|
||||
vhd_geometry->spt = 255;
|
||||
}
|
||||
|
||||
static HarddiskDialog* callbackPtr = nullptr;
|
||||
static MVHDGeom create_drive_vhd_fixed(const QString& fileName, HarddiskDialog* p, uint16_t cyl, uint8_t heads, uint8_t spt) {
|
||||
static HarddiskDialog *callbackPtr = nullptr;
|
||||
static MVHDGeom
|
||||
create_drive_vhd_fixed(const QString &fileName, HarddiskDialog *p, uint16_t cyl, uint8_t heads, uint8_t spt)
|
||||
{
|
||||
MVHDGeom _86box_geometry = { .cyl = cyl, .heads = heads, .spt = spt };
|
||||
MVHDGeom vhd_geometry;
|
||||
adjust_86box_geometry_for_vhd(&_86box_geometry, &vhd_geometry);
|
||||
|
||||
int vhd_error = 0;
|
||||
int vhd_error = 0;
|
||||
QByteArray filenameBytes = fileName.toUtf8();
|
||||
callbackPtr = p;
|
||||
MVHDMeta *vhd = mvhd_create_fixed(filenameBytes.data(), vhd_geometry, &vhd_error, [](uint32_t current_sector, uint32_t total_sectors) {
|
||||
callbackPtr = p;
|
||||
MVHDMeta *vhd = mvhd_create_fixed(filenameBytes.data(), vhd_geometry, &vhd_error, [](uint32_t current_sector, uint32_t total_sectors) {
|
||||
callbackPtr->fileProgress((current_sector * 100) / total_sectors);
|
||||
});
|
||||
callbackPtr = nullptr;
|
||||
callbackPtr = nullptr;
|
||||
|
||||
if (vhd == NULL) {
|
||||
_86box_geometry.cyl = 0;
|
||||
_86box_geometry.cyl = 0;
|
||||
_86box_geometry.heads = 0;
|
||||
_86box_geometry.spt = 0;
|
||||
_86box_geometry.spt = 0;
|
||||
} else {
|
||||
mvhd_close(vhd);
|
||||
}
|
||||
@@ -228,24 +241,26 @@ static MVHDGeom create_drive_vhd_fixed(const QString& fileName, HarddiskDialog*
|
||||
return _86box_geometry;
|
||||
}
|
||||
|
||||
static MVHDGeom create_drive_vhd_dynamic(const QString& fileName, uint16_t cyl, uint8_t heads, uint8_t spt, int blocksize) {
|
||||
static MVHDGeom
|
||||
create_drive_vhd_dynamic(const QString &fileName, uint16_t cyl, uint8_t heads, uint8_t spt, int blocksize)
|
||||
{
|
||||
MVHDGeom _86box_geometry = { .cyl = cyl, .heads = heads, .spt = spt };
|
||||
MVHDGeom vhd_geometry;
|
||||
adjust_86box_geometry_for_vhd(&_86box_geometry, &vhd_geometry);
|
||||
int vhd_error = 0;
|
||||
QByteArray filenameBytes = fileName.toUtf8();
|
||||
int vhd_error = 0;
|
||||
QByteArray filenameBytes = fileName.toUtf8();
|
||||
MVHDCreationOptions options;
|
||||
options.block_size_in_sectors = blocksize;
|
||||
options.path = filenameBytes.data();
|
||||
options.size_in_bytes = 0;
|
||||
options.geometry = vhd_geometry;
|
||||
options.type = MVHD_TYPE_DYNAMIC;
|
||||
options.path = filenameBytes.data();
|
||||
options.size_in_bytes = 0;
|
||||
options.geometry = vhd_geometry;
|
||||
options.type = MVHD_TYPE_DYNAMIC;
|
||||
|
||||
MVHDMeta *vhd = mvhd_create_ex(options, &vhd_error);
|
||||
if (vhd == NULL) {
|
||||
_86box_geometry.cyl = 0;
|
||||
_86box_geometry.cyl = 0;
|
||||
_86box_geometry.heads = 0;
|
||||
_86box_geometry.spt = 0;
|
||||
_86box_geometry.spt = 0;
|
||||
} else {
|
||||
mvhd_close(vhd);
|
||||
}
|
||||
@@ -253,29 +268,31 @@ static MVHDGeom create_drive_vhd_dynamic(const QString& fileName, uint16_t cyl,
|
||||
return _86box_geometry;
|
||||
}
|
||||
|
||||
static MVHDGeom create_drive_vhd_diff(const QString& fileName, const QString& parentFileName, int blocksize) {
|
||||
int vhd_error = 0;
|
||||
QByteArray filenameBytes = fileName.toUtf8();
|
||||
QByteArray parentFilenameBytes = parentFileName.toUtf8();
|
||||
static MVHDGeom
|
||||
create_drive_vhd_diff(const QString &fileName, const QString &parentFileName, int blocksize)
|
||||
{
|
||||
int vhd_error = 0;
|
||||
QByteArray filenameBytes = fileName.toUtf8();
|
||||
QByteArray parentFilenameBytes = parentFileName.toUtf8();
|
||||
MVHDCreationOptions options;
|
||||
options.block_size_in_sectors = blocksize;
|
||||
options.path = filenameBytes.data();
|
||||
options.parent_path = parentFilenameBytes.data();
|
||||
options.type = MVHD_TYPE_DIFF;
|
||||
options.path = filenameBytes.data();
|
||||
options.parent_path = parentFilenameBytes.data();
|
||||
options.type = MVHD_TYPE_DIFF;
|
||||
|
||||
MVHDMeta *vhd = mvhd_create_ex(options, &vhd_error);
|
||||
MVHDGeom vhd_geometry;
|
||||
MVHDGeom vhd_geometry;
|
||||
if (vhd == NULL) {
|
||||
vhd_geometry.cyl = 0;
|
||||
vhd_geometry.cyl = 0;
|
||||
vhd_geometry.heads = 0;
|
||||
vhd_geometry.spt = 0;
|
||||
vhd_geometry.spt = 0;
|
||||
} else {
|
||||
vhd_geometry = mvhd_get_geometry(vhd);
|
||||
|
||||
if (vhd_geometry.spt > 63) {
|
||||
vhd_geometry.cyl = mvhd_calc_size_sectors(&vhd_geometry) / (16 * 63);
|
||||
vhd_geometry.cyl = mvhd_calc_size_sectors(&vhd_geometry) / (16 * 63);
|
||||
vhd_geometry.heads = 16;
|
||||
vhd_geometry.spt = 63;
|
||||
vhd_geometry.spt = 63;
|
||||
}
|
||||
|
||||
mvhd_close(vhd);
|
||||
@@ -284,11 +301,13 @@ static MVHDGeom create_drive_vhd_diff(const QString& fileName, const QString& pa
|
||||
return vhd_geometry;
|
||||
}
|
||||
|
||||
void HarddiskDialog::onCreateNewFile() {
|
||||
void
|
||||
HarddiskDialog::onCreateNewFile()
|
||||
{
|
||||
|
||||
for (auto& curObject : children())
|
||||
{
|
||||
if (qobject_cast<QWidget*>(curObject)) qobject_cast<QWidget*>(curObject)->setDisabled(true);
|
||||
for (auto &curObject : children()) {
|
||||
if (qobject_cast<QWidget *>(curObject))
|
||||
qobject_cast<QWidget *>(curObject)->setDisabled(true);
|
||||
}
|
||||
|
||||
ui->progressBar->setEnabled(true);
|
||||
@@ -299,27 +318,27 @@ void HarddiskDialog::onCreateNewFile() {
|
||||
return;
|
||||
}
|
||||
|
||||
int img_format = ui->comboBoxFormat->currentIndex();
|
||||
uint32_t zero = 0;
|
||||
uint32_t base = 0x1000;
|
||||
int img_format = ui->comboBoxFormat->currentIndex();
|
||||
uint32_t zero = 0;
|
||||
uint32_t base = 0x1000;
|
||||
uint32_t sector_size = 512;
|
||||
|
||||
auto fileName = ui->fileField->fileName();
|
||||
auto fileName = ui->fileField->fileName();
|
||||
QString expectedSuffix;
|
||||
switch (img_format) {
|
||||
case IMG_FMT_HDI:
|
||||
expectedSuffix = "hdi";
|
||||
break;
|
||||
case IMG_FMT_HDX:
|
||||
expectedSuffix = "hdx";
|
||||
break;
|
||||
case IMG_FMT_VHD_FIXED:
|
||||
case IMG_FMT_VHD_DYNAMIC:
|
||||
case IMG_FMT_VHD_DIFF:
|
||||
expectedSuffix = "vhd";
|
||||
break;
|
||||
case IMG_FMT_HDI:
|
||||
expectedSuffix = "hdi";
|
||||
break;
|
||||
case IMG_FMT_HDX:
|
||||
expectedSuffix = "hdx";
|
||||
break;
|
||||
case IMG_FMT_VHD_FIXED:
|
||||
case IMG_FMT_VHD_DYNAMIC:
|
||||
case IMG_FMT_VHD_DIFF:
|
||||
expectedSuffix = "vhd";
|
||||
break;
|
||||
}
|
||||
if (! expectedSuffix.isEmpty()) {
|
||||
if (!expectedSuffix.isEmpty()) {
|
||||
QFileInfo fileInfo(fileName);
|
||||
if (fileInfo.suffix().compare(expectedSuffix, Qt::CaseInsensitive) != 0) {
|
||||
fileName = QString("%1.%2").arg(fileName, expectedSuffix);
|
||||
@@ -331,7 +350,7 @@ void HarddiskDialog::onCreateNewFile() {
|
||||
ui->fileField->setFileName(fileName);
|
||||
|
||||
QFile file(fileName);
|
||||
if (! file.open(QIODevice::WriteOnly)) {
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
QMessageBox::critical(this, tr("Unable to write file"), tr("Make sure the file is being saved to a writable directory."));
|
||||
return;
|
||||
}
|
||||
@@ -344,14 +363,14 @@ void HarddiskDialog::onCreateNewFile() {
|
||||
return;
|
||||
}
|
||||
uint32_t s = static_cast<uint32_t>(size);
|
||||
stream << zero; /* 00000000: Zero/unknown */
|
||||
stream << zero; /* 00000004: Zero/unknown */
|
||||
stream << base; /* 00000008: Offset at which data starts */
|
||||
stream << s; /* 0000000C: Full size of the data (32-bit) */
|
||||
stream << sector_size; /* 00000010: Sector size in bytes */
|
||||
stream << sectors_; /* 00000014: Sectors per cylinder */
|
||||
stream << heads_; /* 00000018: Heads per cylinder */
|
||||
stream << cylinders_; /* 0000001C: Cylinders */
|
||||
stream << zero; /* 00000000: Zero/unknown */
|
||||
stream << zero; /* 00000004: Zero/unknown */
|
||||
stream << base; /* 00000008: Offset at which data starts */
|
||||
stream << s; /* 0000000C: Full size of the data (32-bit) */
|
||||
stream << sector_size; /* 00000010: Sector size in bytes */
|
||||
stream << sectors_; /* 00000014: Sectors per cylinder */
|
||||
stream << heads_; /* 00000018: Heads per cylinder */
|
||||
stream << cylinders_; /* 0000001C: Cylinders */
|
||||
|
||||
for (int i = 0; i < 0x3f8; i++) {
|
||||
stream << zero;
|
||||
@@ -360,57 +379,50 @@ void HarddiskDialog::onCreateNewFile() {
|
||||
QDataStream stream(&file);
|
||||
stream.setByteOrder(QDataStream::LittleEndian);
|
||||
quint64 signature = 0xD778A82044445459;
|
||||
stream << signature; /* 00000000: Signature */
|
||||
stream << size; /* 00000008: Full size of the data (64-bit) */
|
||||
stream << sector_size; /* 00000010: Sector size in bytes */
|
||||
stream << sectors_; /* 00000014: Sectors per cylinder */
|
||||
stream << heads_; /* 00000018: Heads per cylinder */
|
||||
stream << cylinders_; /* 0000001C: Cylinders */
|
||||
stream << zero; /* 00000020: [Translation] Sectors per cylinder */
|
||||
stream << zero; /* 00000004: [Translation] Heads per cylinder */
|
||||
stream << signature; /* 00000000: Signature */
|
||||
stream << size; /* 00000008: Full size of the data (64-bit) */
|
||||
stream << sector_size; /* 00000010: Sector size in bytes */
|
||||
stream << sectors_; /* 00000014: Sectors per cylinder */
|
||||
stream << heads_; /* 00000018: Heads per cylinder */
|
||||
stream << cylinders_; /* 0000001C: Cylinders */
|
||||
stream << zero; /* 00000020: [Translation] Sectors per cylinder */
|
||||
stream << zero; /* 00000004: [Translation] Heads per cylinder */
|
||||
} else if (img_format >= IMG_FMT_VHD_FIXED) { /* VHD file */
|
||||
file.close();
|
||||
|
||||
MVHDGeom _86box_geometry{};
|
||||
int block_size = ui->comboBoxBlockSize->currentIndex() == 0 ? MVHD_BLOCK_LARGE : MVHD_BLOCK_SMALL;
|
||||
MVHDGeom _86box_geometry {};
|
||||
int block_size = ui->comboBoxBlockSize->currentIndex() == 0 ? MVHD_BLOCK_LARGE : MVHD_BLOCK_SMALL;
|
||||
switch (img_format) {
|
||||
case IMG_FMT_VHD_FIXED:
|
||||
{
|
||||
connect(this, &HarddiskDialog::fileProgress, this, [this] (int value) { ui->progressBar->setValue(value); QApplication::processEvents(); } );
|
||||
ui->progressBar->setVisible(true);
|
||||
[&_86box_geometry, fileName, this] {
|
||||
_86box_geometry = create_drive_vhd_fixed(fileName, this, cylinders_, heads_, sectors_);
|
||||
}();
|
||||
}
|
||||
break;
|
||||
case IMG_FMT_VHD_DYNAMIC:
|
||||
_86box_geometry = create_drive_vhd_dynamic(fileName, cylinders_, heads_, sectors_, block_size);
|
||||
break;
|
||||
case IMG_FMT_VHD_DIFF:
|
||||
QString vhdParent = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Select the parent VHD"),
|
||||
QString(),
|
||||
tr("VHD files") %
|
||||
util::DlgFilter({ "vhd" }) %
|
||||
tr("All files") %
|
||||
util::DlgFilter({ "*" }, true));
|
||||
case IMG_FMT_VHD_FIXED:
|
||||
{
|
||||
connect(this, &HarddiskDialog::fileProgress, this, [this](int value) { ui->progressBar->setValue(value); QApplication::processEvents(); });
|
||||
ui->progressBar->setVisible(true);
|
||||
[&_86box_geometry, fileName, this] {
|
||||
_86box_geometry = create_drive_vhd_fixed(fileName, this, cylinders_, heads_, sectors_);
|
||||
}();
|
||||
}
|
||||
break;
|
||||
case IMG_FMT_VHD_DYNAMIC:
|
||||
_86box_geometry = create_drive_vhd_dynamic(fileName, cylinders_, heads_, sectors_, block_size);
|
||||
break;
|
||||
case IMG_FMT_VHD_DIFF:
|
||||
QString vhdParent = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Select the parent VHD"),
|
||||
QString(),
|
||||
tr("VHD files") % util::DlgFilter({ "vhd" }) % tr("All files") % util::DlgFilter({ "*" }, true));
|
||||
|
||||
if (vhdParent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
_86box_geometry = create_drive_vhd_diff(fileName, vhdParent, block_size);
|
||||
break;
|
||||
if (vhdParent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
_86box_geometry = create_drive_vhd_diff(fileName, vhdParent, block_size);
|
||||
break;
|
||||
}
|
||||
|
||||
if (_86box_geometry.cyl == 0 &&
|
||||
_86box_geometry.heads == 0 &&
|
||||
_86box_geometry.spt == 0)
|
||||
{
|
||||
if (_86box_geometry.cyl == 0 && _86box_geometry.heads == 0 && _86box_geometry.spt == 0) {
|
||||
QMessageBox::critical(this, tr("Unable to write file"), tr("Make sure the file is being saved to a writable directory."));
|
||||
return;
|
||||
}
|
||||
else if (img_format != IMG_FMT_VHD_DIFF) {
|
||||
} else if (img_format != IMG_FMT_VHD_DIFF) {
|
||||
QMessageBox::information(this, tr("Disk image created"), tr("Remember to partition and format the newly-created drive."));
|
||||
}
|
||||
|
||||
@@ -418,23 +430,23 @@ void HarddiskDialog::onCreateNewFile() {
|
||||
ui->lineEditHeads->setText(QString::number(_86box_geometry.heads));
|
||||
ui->lineEditSectors->setText(QString::number(_86box_geometry.spt));
|
||||
cylinders_ = _86box_geometry.cyl;
|
||||
heads_ = _86box_geometry.heads;
|
||||
sectors_ = _86box_geometry.spt;
|
||||
heads_ = _86box_geometry.heads;
|
||||
sectors_ = _86box_geometry.spt;
|
||||
setResult(QDialog::Accepted);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// formats 0, 1 and 2
|
||||
connect(this, &HarddiskDialog::fileProgress, this, [this] (int value) { ui->progressBar->setValue(value); QApplication::processEvents(); } );
|
||||
connect(this, &HarddiskDialog::fileProgress, this, [this](int value) { ui->progressBar->setValue(value); QApplication::processEvents(); });
|
||||
ui->progressBar->setVisible(true);
|
||||
[size, &file, this] {
|
||||
QDataStream stream(&file);
|
||||
stream.setByteOrder(QDataStream::LittleEndian);
|
||||
|
||||
QByteArray buf(1048576, 0);
|
||||
uint64_t mibBlocks = size >> 20;
|
||||
uint64_t restBlock = size & 0xfffff;
|
||||
uint64_t mibBlocks = size >> 20;
|
||||
uint64_t restBlock = size & 0xfffff;
|
||||
|
||||
if (restBlock) {
|
||||
stream.writeRawData(buf.data(), restBlock);
|
||||
@@ -453,7 +465,9 @@ void HarddiskDialog::onCreateNewFile() {
|
||||
setResult(QDialog::Accepted);
|
||||
}
|
||||
|
||||
static void adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry) {
|
||||
static void
|
||||
adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry)
|
||||
{
|
||||
if (vhd_geometry->spt <= 63)
|
||||
return;
|
||||
|
||||
@@ -465,17 +479,17 @@ static void adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry) {
|
||||
if (remainder > 0)
|
||||
desired_sectors -= remainder;
|
||||
|
||||
vhd_geometry->cyl = desired_sectors / (16 * 63);
|
||||
vhd_geometry->cyl = desired_sectors / (16 * 63);
|
||||
vhd_geometry->heads = 16;
|
||||
vhd_geometry->spt = 63;
|
||||
vhd_geometry->spt = 63;
|
||||
}
|
||||
|
||||
void HarddiskDialog::recalcSelection() {
|
||||
void
|
||||
HarddiskDialog::recalcSelection()
|
||||
{
|
||||
int selection = 127;
|
||||
for (int i = 0; i < 127; i++) {
|
||||
if ((cylinders_ == hdd_table[i][0]) &&
|
||||
(heads_ == hdd_table[i][1]) &&
|
||||
(sectors_ == hdd_table[i][2]))
|
||||
if ((cylinders_ == hdd_table[i][0]) && (heads_ == hdd_table[i][1]) && (sectors_ == hdd_table[i][2]))
|
||||
selection = i;
|
||||
}
|
||||
if ((selection == 127) && (heads_ == 16) && (sectors_ == 63)) {
|
||||
@@ -484,7 +498,9 @@ void HarddiskDialog::recalcSelection() {
|
||||
ui->comboBoxType->setCurrentIndex(selection);
|
||||
}
|
||||
|
||||
void HarddiskDialog::onExistingFileSelected(const QString &fileName) {
|
||||
void
|
||||
HarddiskDialog::onExistingFileSelected(const QString &fileName)
|
||||
{
|
||||
// TODO : Over to non-existing file selected
|
||||
/*
|
||||
if (!(existing & 1)) {
|
||||
@@ -505,16 +521,16 @@ void HarddiskDialog::onExistingFileSelected(const QString &fileName) {
|
||||
}
|
||||
*/
|
||||
|
||||
uint64_t size = 0;
|
||||
uint64_t size = 0;
|
||||
uint32_t sector_size = 0;
|
||||
uint32_t sectors = 0;
|
||||
uint32_t heads = 0;
|
||||
uint32_t cylinders = 0;
|
||||
int vhd_error = 0;
|
||||
uint32_t sectors = 0;
|
||||
uint32_t heads = 0;
|
||||
uint32_t cylinders = 0;
|
||||
int vhd_error = 0;
|
||||
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
QFile file(fileName);
|
||||
if (! file.open(QIODevice::ReadOnly)) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
QMessageBox::critical(this, tr("Unable to read file"), tr("Make sure the file exists and is readable."));
|
||||
return;
|
||||
}
|
||||
@@ -536,7 +552,7 @@ void HarddiskDialog::onExistingFileSelected(const QString &fileName) {
|
||||
stream >> heads;
|
||||
stream >> cylinders;
|
||||
} else if (image_is_vhd(fileNameUtf8.data(), 1)) {
|
||||
MVHDMeta* vhd = mvhd_open(fileNameUtf8.data(), 0, &vhd_error);
|
||||
MVHDMeta *vhd = mvhd_open(fileNameUtf8.data(), 0, &vhd_error);
|
||||
if (vhd == nullptr) {
|
||||
QMessageBox::critical(this, tr("Unable to read file"), tr("Make sure the file exists and is readable"));
|
||||
return;
|
||||
@@ -558,9 +574,9 @@ void HarddiskDialog::onExistingFileSelected(const QString &fileName) {
|
||||
MVHDGeom vhd_geom = mvhd_get_geometry(vhd);
|
||||
adjust_vhd_geometry_for_86box(&vhd_geom);
|
||||
cylinders = vhd_geom.cyl;
|
||||
heads = vhd_geom.heads;
|
||||
sectors = vhd_geom.spt;
|
||||
size = static_cast<uint64_t>(cylinders * heads * sectors * 512);
|
||||
heads = vhd_geom.heads;
|
||||
sectors = vhd_geom.spt;
|
||||
size = static_cast<uint64_t>(cylinders * heads * sectors * 512);
|
||||
mvhd_close(vhd);
|
||||
} else {
|
||||
size = file.size();
|
||||
@@ -582,7 +598,7 @@ void HarddiskDialog::onExistingFileSelected(const QString &fileName) {
|
||||
}
|
||||
} else {
|
||||
sectors = 63;
|
||||
heads = 16;
|
||||
heads = 16;
|
||||
}
|
||||
|
||||
cylinders = ((size >> 9) / heads) / sectors;
|
||||
@@ -593,8 +609,8 @@ void HarddiskDialog::onExistingFileSelected(const QString &fileName) {
|
||||
return;
|
||||
}
|
||||
|
||||
heads_ = heads;
|
||||
sectors_ = sectors;
|
||||
heads_ = heads;
|
||||
sectors_ = sectors;
|
||||
cylinders_ = cylinders;
|
||||
ui->lineEditCylinders->setText(QString::number(cylinders));
|
||||
ui->lineEditHeads->setText(QString::number(heads));
|
||||
@@ -610,13 +626,18 @@ void HarddiskDialog::onExistingFileSelected(const QString &fileName) {
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
}
|
||||
|
||||
void HarddiskDialog::recalcSize() {
|
||||
if (disallowSizeModifications) return;
|
||||
void
|
||||
HarddiskDialog::recalcSize()
|
||||
{
|
||||
if (disallowSizeModifications)
|
||||
return;
|
||||
uint64_t size = (static_cast<uint64_t>(cylinders_) * static_cast<uint64_t>(heads_) * static_cast<uint64_t>(sectors_)) << 9;
|
||||
ui->lineEditSize->setText(QString::number(size >> 20));
|
||||
}
|
||||
|
||||
bool HarddiskDialog::checkAndAdjustSectors() {
|
||||
bool
|
||||
HarddiskDialog::checkAndAdjustSectors()
|
||||
{
|
||||
if (sectors_ > max_sectors) {
|
||||
sectors_ = max_sectors;
|
||||
ui->lineEditSectors->setText(QString::number(max_sectors));
|
||||
@@ -627,7 +648,9 @@ bool HarddiskDialog::checkAndAdjustSectors() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HarddiskDialog::checkAndAdjustHeads() {
|
||||
bool
|
||||
HarddiskDialog::checkAndAdjustHeads()
|
||||
{
|
||||
if (heads_ > max_heads) {
|
||||
heads_ = max_heads;
|
||||
ui->lineEditHeads->setText(QString::number(max_heads));
|
||||
@@ -638,7 +661,9 @@ bool HarddiskDialog::checkAndAdjustHeads() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HarddiskDialog::checkAndAdjustCylinders() {
|
||||
bool
|
||||
HarddiskDialog::checkAndAdjustCylinders()
|
||||
{
|
||||
if (cylinders_ > max_cylinders) {
|
||||
cylinders_ = max_cylinders;
|
||||
ui->lineEditCylinders->setText(QString::number(max_cylinders));
|
||||
@@ -649,44 +674,45 @@ bool HarddiskDialog::checkAndAdjustCylinders() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void HarddiskDialog::on_comboBoxBus_currentIndexChanged(int index) {
|
||||
void
|
||||
HarddiskDialog::on_comboBoxBus_currentIndexChanged(int index)
|
||||
{
|
||||
int chanIdx = 0;
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ui->comboBoxBus->currentData().toInt()) {
|
||||
case HDD_BUS_DISABLED:
|
||||
default:
|
||||
max_sectors = max_heads = max_cylinders = 0;
|
||||
break;
|
||||
case HDD_BUS_MFM:
|
||||
max_sectors = 26; /* 17 for MFM, 26 for RLL. */
|
||||
max_heads = 15;
|
||||
max_cylinders = 2047;
|
||||
break;
|
||||
case HDD_BUS_XTA:
|
||||
max_sectors = 63;
|
||||
max_heads = 16;
|
||||
max_cylinders = 1023;
|
||||
break;
|
||||
case HDD_BUS_ESDI:
|
||||
max_sectors = 99; /* ESDI drives usually had 32 to 43 sectors per track. */
|
||||
max_heads = 16;
|
||||
max_cylinders = 266305;
|
||||
break;
|
||||
case HDD_BUS_IDE:
|
||||
max_sectors = 63;
|
||||
max_heads = 255;
|
||||
max_cylinders = 266305;
|
||||
break;
|
||||
case HDD_BUS_ATAPI:
|
||||
case HDD_BUS_SCSI:
|
||||
max_sectors = 99;
|
||||
max_heads = 255;
|
||||
max_cylinders = 266305;
|
||||
break;
|
||||
case HDD_BUS_DISABLED:
|
||||
default:
|
||||
max_sectors = max_heads = max_cylinders = 0;
|
||||
break;
|
||||
case HDD_BUS_MFM:
|
||||
max_sectors = 26; /* 17 for MFM, 26 for RLL. */
|
||||
max_heads = 15;
|
||||
max_cylinders = 2047;
|
||||
break;
|
||||
case HDD_BUS_XTA:
|
||||
max_sectors = 63;
|
||||
max_heads = 16;
|
||||
max_cylinders = 1023;
|
||||
break;
|
||||
case HDD_BUS_ESDI:
|
||||
max_sectors = 99; /* ESDI drives usually had 32 to 43 sectors per track. */
|
||||
max_heads = 16;
|
||||
max_cylinders = 266305;
|
||||
break;
|
||||
case HDD_BUS_IDE:
|
||||
max_sectors = 63;
|
||||
max_heads = 255;
|
||||
max_cylinders = 266305;
|
||||
break;
|
||||
case HDD_BUS_ATAPI:
|
||||
case HDD_BUS_SCSI:
|
||||
max_sectors = 99;
|
||||
max_heads = 255;
|
||||
max_cylinders = 266305;
|
||||
break;
|
||||
}
|
||||
|
||||
checkAndAdjustCylinders();
|
||||
@@ -710,8 +736,7 @@ void HarddiskDialog::on_comboBoxBus_currentIndexChanged(int index) {
|
||||
Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt());
|
||||
Harddrives::populateSpeeds(ui->comboBoxSpeed->model(), ui->comboBoxBus->currentData().toInt());
|
||||
|
||||
switch (ui->comboBoxBus->currentData().toInt())
|
||||
{
|
||||
switch (ui->comboBoxBus->currentData().toInt()) {
|
||||
case HDD_BUS_MFM:
|
||||
chanIdx = (Harddrives::busTrackClass->next_free_mfm_channel());
|
||||
break;
|
||||
@@ -730,13 +755,16 @@ void HarddiskDialog::on_comboBoxBus_currentIndexChanged(int index) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (chanIdx == 0xFF) chanIdx = 0;
|
||||
if (chanIdx == 0xFF)
|
||||
chanIdx = 0;
|
||||
ui->comboBoxChannel->setCurrentIndex(chanIdx);
|
||||
}
|
||||
|
||||
void HarddiskDialog::on_lineEditSize_textEdited(const QString &text) {
|
||||
void
|
||||
HarddiskDialog::on_lineEditSize_textEdited(const QString &text)
|
||||
{
|
||||
disallowSizeModifications = true;
|
||||
uint32_t size = text.toUInt();
|
||||
uint32_t size = text.toUInt();
|
||||
/* This is needed to ensure VHD standard compliance. */
|
||||
hdd_image_calc_chs(&cylinders_, &heads_, §ors_, size);
|
||||
ui->lineEditCylinders->setText(QString::number(cylinders_));
|
||||
@@ -751,7 +779,9 @@ void HarddiskDialog::on_lineEditSize_textEdited(const QString &text) {
|
||||
disallowSizeModifications = false;
|
||||
}
|
||||
|
||||
void HarddiskDialog::on_lineEditCylinders_textEdited(const QString &text) {
|
||||
void
|
||||
HarddiskDialog::on_lineEditCylinders_textEdited(const QString &text)
|
||||
{
|
||||
cylinders_ = text.toUInt();
|
||||
if (checkAndAdjustCylinders()) {
|
||||
recalcSize();
|
||||
@@ -759,7 +789,9 @@ void HarddiskDialog::on_lineEditCylinders_textEdited(const QString &text) {
|
||||
}
|
||||
}
|
||||
|
||||
void HarddiskDialog::on_lineEditHeads_textEdited(const QString &text) {
|
||||
void
|
||||
HarddiskDialog::on_lineEditHeads_textEdited(const QString &text)
|
||||
{
|
||||
heads_ = text.toUInt();
|
||||
if (checkAndAdjustHeads()) {
|
||||
recalcSize();
|
||||
@@ -767,7 +799,9 @@ void HarddiskDialog::on_lineEditHeads_textEdited(const QString &text) {
|
||||
}
|
||||
}
|
||||
|
||||
void HarddiskDialog::on_lineEditSectors_textEdited(const QString &text) {
|
||||
void
|
||||
HarddiskDialog::on_lineEditSectors_textEdited(const QString &text)
|
||||
{
|
||||
sectors_ = text.toUInt();
|
||||
if (checkAndAdjustSectors()) {
|
||||
recalcSize();
|
||||
@@ -775,21 +809,23 @@ void HarddiskDialog::on_lineEditSectors_textEdited(const QString &text) {
|
||||
}
|
||||
}
|
||||
|
||||
void HarddiskDialog::on_comboBoxType_currentIndexChanged(int index) {
|
||||
void
|
||||
HarddiskDialog::on_comboBoxType_currentIndexChanged(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((index != 127) && (index != 128)) {
|
||||
cylinders_ = hdd_table[index][0];
|
||||
heads_ = hdd_table[index][1];
|
||||
sectors_ = hdd_table[index][2];
|
||||
heads_ = hdd_table[index][1];
|
||||
sectors_ = hdd_table[index][2];
|
||||
ui->lineEditCylinders->setText(QString::number(cylinders_));
|
||||
ui->lineEditHeads->setText(QString::number(heads_));
|
||||
ui->lineEditSectors->setText(QString::number(sectors_));
|
||||
recalcSize();
|
||||
} else if (index == 128) {
|
||||
heads_ = 16;
|
||||
heads_ = 16;
|
||||
sectors_ = 63;
|
||||
ui->lineEditHeads->setText(QString::number(heads_));
|
||||
ui->lineEditSectors->setText(QString::number(sectors_));
|
||||
@@ -801,9 +837,12 @@ void HarddiskDialog::on_comboBoxType_currentIndexChanged(int index) {
|
||||
checkAndAdjustSectors();
|
||||
}
|
||||
|
||||
void HarddiskDialog::accept()
|
||||
void
|
||||
HarddiskDialog::accept()
|
||||
{
|
||||
if (ui->fileField->createFile()) onCreateNewFile();
|
||||
else setResult(QDialog::Accepted);
|
||||
if (ui->fileField->createFile())
|
||||
onCreateNewFile();
|
||||
else
|
||||
setResult(QDialog::Accepted);
|
||||
QDialog::done(result());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user