This commit is contained in:
OBattler
2025-05-30 10:33:03 +02:00
2 changed files with 45 additions and 28 deletions

View File

@@ -199,7 +199,7 @@ HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index)
* than a tenth of a percent change in size. * than a tenth of a percent change in size.
*/ */
static void static void
adjust_86box_geometry_for_vhd(MVHDGeom *_86box_geometry, MVHDGeom *vhd_geometry) adjust_86box_geometry_for_vhd(_86BoxGeom *_86box_geometry, MVHDGeom *vhd_geometry)
{ {
if (_86box_geometry->cyl <= 65535) { if (_86box_geometry->cyl <= 65535) {
vhd_geometry->cyl = _86box_geometry->cyl; vhd_geometry->cyl = _86box_geometry->cyl;
@@ -226,10 +226,10 @@ adjust_86box_geometry_for_vhd(MVHDGeom *_86box_geometry, MVHDGeom *vhd_geometry)
} }
static HarddiskDialog *callbackPtr = nullptr; static HarddiskDialog *callbackPtr = nullptr;
static MVHDGeom static _86BoxGeom
create_drive_vhd_fixed(const QString &fileName, HarddiskDialog *p, uint16_t cyl, uint8_t heads, uint8_t spt) create_drive_vhd_fixed(const QString &fileName, HarddiskDialog *p, uint32_t cyl, uint32_t heads, uint32_t spt)
{ {
MVHDGeom _86box_geometry = { _86BoxGeom _86box_geometry = {
.cyl = cyl, .cyl = cyl,
.heads = heads, .heads = heads,
.spt = spt .spt = spt
@@ -256,10 +256,10 @@ create_drive_vhd_fixed(const QString &fileName, HarddiskDialog *p, uint16_t cyl,
return _86box_geometry; return _86box_geometry;
} }
static MVHDGeom static _86BoxGeom
create_drive_vhd_dynamic(const QString &fileName, uint16_t cyl, uint8_t heads, uint8_t spt, int blocksize) create_drive_vhd_dynamic(const QString &fileName, uint32_t cyl, uint32_t heads, uint32_t spt, int blocksize)
{ {
MVHDGeom _86box_geometry = { _86BoxGeom _86box_geometry = {
.cyl = cyl, .cyl = cyl,
.heads = heads, .heads = heads,
.spt = spt .spt = spt
@@ -287,7 +287,7 @@ create_drive_vhd_dynamic(const QString &fileName, uint16_t cyl, uint8_t heads, u
return _86box_geometry; return _86box_geometry;
} }
static MVHDGeom static _86BoxGeom
create_drive_vhd_diff(const QString &fileName, const QString &parentFileName, int blocksize) create_drive_vhd_diff(const QString &fileName, const QString &parentFileName, int blocksize)
{ {
int vhd_error = 0; int vhd_error = 0;
@@ -299,25 +299,31 @@ create_drive_vhd_diff(const QString &fileName, const QString &parentFileName, in
options.parent_path = parentFilenameBytes.data(); options.parent_path = parentFilenameBytes.data();
options.type = MVHD_TYPE_DIFF; options.type = MVHD_TYPE_DIFF;
MVHDMeta *vhd = mvhd_create_ex(options, &vhd_error); MVHDMeta *vhd = mvhd_create_ex(options, &vhd_error);
MVHDGeom vhd_geometry; MVHDGeom vhd_geometry;
_86BoxGeom _86box_geometry;
if (vhd == NULL) { if (vhd == NULL) {
vhd_geometry.cyl = 0; _86box_geometry.cyl = 0;
vhd_geometry.heads = 0; _86box_geometry.heads = 0;
vhd_geometry.spt = 0; _86box_geometry.spt = 0;
} else { } else {
vhd_geometry = mvhd_get_geometry(vhd); vhd_geometry = mvhd_get_geometry(vhd);
if (vhd_geometry.spt > 63) { if (vhd_geometry.spt > 63) {
vhd_geometry.cyl = mvhd_calc_size_sectors(&vhd_geometry) / (16 * 63); _86box_geometry.cyl = mvhd_calc_size_sectors(&vhd_geometry) / (16 * 63);
vhd_geometry.heads = 16; _86box_geometry.heads = 16;
vhd_geometry.spt = 63; _86box_geometry.spt = 63;
} else {
_86box_geometry.cyl = vhd_geometry.cyl;
_86box_geometry.heads = vhd_geometry.heads;
_86box_geometry.spt = vhd_geometry.spt;
} }
mvhd_close(vhd); mvhd_close(vhd);
} }
return vhd_geometry; return _86box_geometry;
} }
void void
@@ -409,7 +415,7 @@ HarddiskDialog::onCreateNewFile()
} else if (img_format >= IMG_FMT_VHD_FIXED) { /* VHD file */ } else if (img_format >= IMG_FMT_VHD_FIXED) { /* VHD file */
file.close(); file.close();
MVHDGeom _86box_geometry {}; _86BoxGeom _86box_geometry {};
int block_size = ui->comboBoxBlockSize->currentIndex() == 0 ? MVHD_BLOCK_LARGE : MVHD_BLOCK_SMALL; int block_size = ui->comboBoxBlockSize->currentIndex() == 0 ? MVHD_BLOCK_LARGE : MVHD_BLOCK_SMALL;
switch (img_format) { switch (img_format) {
case IMG_FMT_VHD_FIXED: case IMG_FMT_VHD_FIXED:
@@ -493,10 +499,14 @@ HarddiskDialog::onCreateNewFile()
} }
static void static void
adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry) adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry, _86BoxGeom *_86box_geometry)
{ {
if (vhd_geometry->spt <= 63) if (vhd_geometry->spt <= 63) {
_86box_geometry->cyl = vhd_geometry->cyl;
_86box_geometry->heads = vhd_geometry->heads;
_86box_geometry->spt = vhd_geometry->spt;
return; return;
}
int desired_sectors = vhd_geometry->cyl * vhd_geometry->heads * vhd_geometry->spt; int desired_sectors = vhd_geometry->cyl * vhd_geometry->heads * vhd_geometry->spt;
if (desired_sectors > 267321600) if (desired_sectors > 267321600)
@@ -506,9 +516,9 @@ adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry)
if (remainder > 0) if (remainder > 0)
desired_sectors -= remainder; desired_sectors -= remainder;
vhd_geometry->cyl = desired_sectors / (16 * 63); _86box_geometry->cyl = desired_sectors / (16 * 63);
vhd_geometry->heads = 16; _86box_geometry->heads = 16;
vhd_geometry->spt = 63; _86box_geometry->spt = 63;
} }
void void
@@ -602,11 +612,12 @@ HarddiskDialog::onExistingFileSelected(const QString &fileName, bool precheck)
} }
} }
MVHDGeom vhd_geom = mvhd_get_geometry(vhd); MVHDGeom vhd_geom = mvhd_get_geometry(vhd);
adjust_vhd_geometry_for_86box(&vhd_geom); _86BoxGeom _86box_geom;
cylinders = vhd_geom.cyl; adjust_vhd_geometry_for_86box(&vhd_geom, &_86box_geom);
heads = vhd_geom.heads; cylinders = _86box_geom.cyl;
sectors = vhd_geom.spt; heads = _86box_geom.heads;
sectors = _86box_geom.spt;
size = static_cast<uint64_t>(cylinders * heads * sectors * 512); size = static_cast<uint64_t>(cylinders * heads * sectors * 512);
mvhd_close(vhd); mvhd_close(vhd);
} else { } else {

View File

@@ -64,4 +64,10 @@ private:
void recalcSelection(); void recalcSelection();
}; };
typedef struct _86BoxGeom {
uint32_t cyl;
uint32_t heads;
uint32_t spt;
} _86BoxGeom;
#endif // QT_HARDDISKDIALOG_HPP #endif // QT_HARDDISKDIALOG_HPP