mirror of
https://github.com/holub/mame
synced 2025-04-22 08:22:15 +03:00
hard_disk_file: classify
This commit is contained in:
parent
50fc1c3a58
commit
e818533b16
@ -826,12 +826,12 @@ void ide_hdd_device::device_reset()
|
||||
|
||||
if (m_disk != nullptr && !m_can_identify_device)
|
||||
{
|
||||
const hard_disk_info *hdinfo = hard_disk_get_info(m_disk);
|
||||
if (hdinfo->sectorbytes == IDE_DISK_SECTOR_SIZE)
|
||||
const auto &hdinfo = m_disk->get_info();
|
||||
if (hdinfo.sectorbytes == IDE_DISK_SECTOR_SIZE)
|
||||
{
|
||||
m_num_cylinders = hdinfo->cylinders;
|
||||
m_num_sectors = hdinfo->sectors;
|
||||
m_num_heads = hdinfo->heads;
|
||||
m_num_cylinders = hdinfo.cylinders;
|
||||
m_num_sectors = hdinfo.sectors;
|
||||
m_num_heads = hdinfo.heads;
|
||||
if (PRINTF_IDE_COMMANDS) osd_printf_debug("CHS: %u %u %u\n", m_num_cylinders, m_num_heads, m_num_sectors);
|
||||
osd_printf_debug("CHS: %u %u %u\n", m_num_cylinders, m_num_heads, m_num_sectors);
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ protected:
|
||||
// optional information overrides
|
||||
virtual void device_add_mconfig(machine_config &config) override;
|
||||
|
||||
virtual int read_sector(uint32_t lba, void *buffer) override { return !m_disk ? 0 : hard_disk_read(m_disk, lba, buffer); }
|
||||
virtual int write_sector(uint32_t lba, const void *buffer) override { return !m_disk ? 0 : hard_disk_write(m_disk, lba, buffer); }
|
||||
virtual int read_sector(uint32_t lba, void *buffer) override { return !m_disk ? 0 : m_disk->read(lba, buffer); }
|
||||
virtual int write_sector(uint32_t lba, const void *buffer) override { return !m_disk ? 0 : m_disk->write(lba, buffer); }
|
||||
virtual uint8_t calculate_status() override;
|
||||
|
||||
chd_file *m_handle;
|
||||
|
@ -279,17 +279,15 @@ int xt_hdc_device::no_dma(void)
|
||||
|
||||
int xt_hdc_device::get_lbasector()
|
||||
{
|
||||
hard_disk_info *info;
|
||||
hard_disk_file *file;
|
||||
int lbasector;
|
||||
|
||||
file = pc_hdc_file(drv);
|
||||
info = hard_disk_get_info(file);
|
||||
hard_disk_file *file = pc_hdc_file(drv);
|
||||
const auto &info = file->get_info();
|
||||
|
||||
lbasector = cylinder[drv];
|
||||
lbasector *= info->heads;
|
||||
lbasector *= info.heads;
|
||||
lbasector += head[drv];
|
||||
lbasector *= info->sectors;
|
||||
lbasector *= info.sectors;
|
||||
lbasector += sector[drv];
|
||||
return lbasector;
|
||||
}
|
||||
@ -307,17 +305,15 @@ int xt_hdc_device::get_lbasector()
|
||||
int xt_hdc_device::dack_r()
|
||||
{
|
||||
uint8_t result;
|
||||
hard_disk_info *info;
|
||||
hard_disk_file *file;
|
||||
|
||||
file = pc_hdc_file(drv);
|
||||
hard_disk_file *file = pc_hdc_file(drv);
|
||||
if (!file)
|
||||
return 0;
|
||||
info = hard_disk_get_info(file);
|
||||
const auto &info = file->get_info();
|
||||
|
||||
if (hdcdma_read == 0)
|
||||
{
|
||||
hard_disk_read(file, get_lbasector(), hdcdma_data);
|
||||
file->read(get_lbasector(), hdcdma_data);
|
||||
hdcdma_read = 512;
|
||||
hdcdma_size -= 512;
|
||||
hdcdma_src = hdcdma_data;
|
||||
@ -329,10 +325,10 @@ int xt_hdc_device::dack_r()
|
||||
if( --hdcdma_read == 0 )
|
||||
{
|
||||
/* end of cylinder ? */
|
||||
if (sector[drv] >= info->sectors)
|
||||
if (sector[drv] >= info.sectors)
|
||||
{
|
||||
sector[drv] = 0;
|
||||
if (++head[drv] >= info->heads) /* beyond heads? */
|
||||
if (++head[drv] >= info.heads) /* beyond heads? */
|
||||
{
|
||||
head[drv] = 0; /* reset head */
|
||||
cylinder[drv]++; /* next cylinder */
|
||||
@ -379,27 +375,24 @@ int xt_hdc_device::dack_rs()
|
||||
|
||||
void xt_hdc_device::dack_w(int data)
|
||||
{
|
||||
hard_disk_info *info;
|
||||
hard_disk_file *file;
|
||||
|
||||
file = pc_hdc_file(drv);
|
||||
hard_disk_file *file = pc_hdc_file(drv);
|
||||
if (!file)
|
||||
return;
|
||||
info = hard_disk_get_info(file);
|
||||
const auto &info = file->get_info();
|
||||
|
||||
*(hdcdma_dst++) = data;
|
||||
|
||||
if( --hdcdma_write == 0 )
|
||||
{
|
||||
hard_disk_write(file, get_lbasector(), hdcdma_data);
|
||||
file->write(get_lbasector(), hdcdma_data);
|
||||
hdcdma_write = 512;
|
||||
hdcdma_size -= 512;
|
||||
|
||||
/* end of cylinder ? */
|
||||
if( ++sector[drv] >= info->sectors )
|
||||
if( ++sector[drv] >= info.sectors )
|
||||
{
|
||||
sector[drv] = 0;
|
||||
if (++head[drv] >= info->heads) /* beyond heads? */
|
||||
if (++head[drv] >= info.heads) /* beyond heads? */
|
||||
{
|
||||
head[drv] = 0; /* reset head */
|
||||
cylinder[drv]++; /* next cylinder */
|
||||
|
@ -43,8 +43,8 @@ void nscsi_harddisk_device::device_reset()
|
||||
scsi_id = -1;
|
||||
bytes_per_sector = 0;
|
||||
} else {
|
||||
const hard_disk_info *hdinfo = hard_disk_get_info(harddisk);
|
||||
bytes_per_sector = hdinfo->sectorbytes;
|
||||
const auto &hdinfo = harddisk->get_info();
|
||||
bytes_per_sector = hdinfo.sectorbytes;
|
||||
|
||||
chd_file *chd = image->get_chd_file();
|
||||
if(chd != nullptr)
|
||||
@ -70,7 +70,7 @@ uint8_t nscsi_harddisk_device::scsi_get_data(int id, int pos)
|
||||
int clba = lba + pos / bytes_per_sector;
|
||||
if(clba != cur_lba) {
|
||||
cur_lba = clba;
|
||||
if(!hard_disk_read(harddisk, cur_lba, block)) {
|
||||
if(!harddisk->read(cur_lba, block)) {
|
||||
LOG("HD READ ERROR !\n");
|
||||
memset(block, 0, sizeof(block));
|
||||
}
|
||||
@ -93,7 +93,7 @@ void nscsi_harddisk_device::scsi_put_data(int id, int pos, uint8_t data)
|
||||
block[offset] = data;
|
||||
cur_lba = lba + pos / bytes_per_sector;
|
||||
if(offset == bytes_per_sector-1) {
|
||||
if(!hard_disk_write(harddisk, cur_lba, block))
|
||||
if(!harddisk->write(cur_lba, block))
|
||||
LOG("HD WRITE ERROR !\n");
|
||||
}
|
||||
}
|
||||
@ -120,7 +120,7 @@ void nscsi_harddisk_device::scsi_command()
|
||||
|
||||
LOG("command READ start=%08x blocks=%04x\n", lba, blocks);
|
||||
|
||||
if(hard_disk_read(harddisk, lba, block)) {
|
||||
if(harddisk->read(lba, block)) {
|
||||
scsi_data_in(2, blocks*bytes_per_sector);
|
||||
scsi_status_complete(SS_GOOD);
|
||||
}
|
||||
@ -222,17 +222,17 @@ void nscsi_harddisk_device::scsi_command()
|
||||
scsi_cmdbuf[pos++] = 0x00; // medium type
|
||||
scsi_cmdbuf[pos++] = 0x00; // WP, cache
|
||||
|
||||
hard_disk_info *info = hard_disk_get_info(harddisk);
|
||||
uint32_t dsize = info->cylinders * info->heads * info->sectors - 1;
|
||||
const auto &info = harddisk->get_info();
|
||||
uint32_t dsize = info.cylinders * info.heads * info.sectors - 1;
|
||||
scsi_cmdbuf[pos++] = 0x08; // Block descriptor length
|
||||
scsi_cmdbuf[pos++] = 0x00;
|
||||
scsi_cmdbuf[pos++] = (dsize>>16) & 0xff;
|
||||
scsi_cmdbuf[pos++] = (dsize>>8) & 0xff;
|
||||
scsi_cmdbuf[pos++] = (dsize & 0xff);
|
||||
scsi_cmdbuf[pos++] = 0x00;
|
||||
scsi_cmdbuf[pos++] = (info->sectorbytes>>16)&0xff;
|
||||
scsi_cmdbuf[pos++] = (info->sectorbytes>>8)&0xff;
|
||||
scsi_cmdbuf[pos++] = (info->sectorbytes & 0xff);
|
||||
scsi_cmdbuf[pos++] = (info.sectorbytes>>16)&0xff;
|
||||
scsi_cmdbuf[pos++] = (info.sectorbytes>>8)&0xff;
|
||||
scsi_cmdbuf[pos++] = (info.sectorbytes & 0xff);
|
||||
|
||||
int pmax = page == 0x3f ? 0x3e : page;
|
||||
int pmin = page == 0x3f ? 0x00 : page;
|
||||
@ -284,18 +284,18 @@ void nscsi_harddisk_device::scsi_command()
|
||||
case 0x03: { // Format parameters page
|
||||
scsi_cmdbuf[pos++] = 0x83; // PS, page id
|
||||
scsi_cmdbuf[pos++] = 0x16; // Page length
|
||||
scsi_cmdbuf[pos++] = (info->cylinders * info->heads) >> 8; // Track/zone
|
||||
scsi_cmdbuf[pos++] = info->cylinders * info->heads; // Track/zone
|
||||
scsi_cmdbuf[pos++] = (info.cylinders * info.heads) >> 8; // Track/zone
|
||||
scsi_cmdbuf[pos++] = info.cylinders * info.heads; // Track/zone
|
||||
scsi_cmdbuf[pos++] = 0x00; // Alt sect/zone
|
||||
scsi_cmdbuf[pos++] = 0x00; // Alt sect/zone
|
||||
scsi_cmdbuf[pos++] = 0x00; // Alt track/zone
|
||||
scsi_cmdbuf[pos++] = 0x00; // Alt track/zone
|
||||
scsi_cmdbuf[pos++] = 0x00; // Alt track/volume
|
||||
scsi_cmdbuf[pos++] = 0x00; // Alt track/volume
|
||||
scsi_cmdbuf[pos++] = info->sectors >> 8; // Sectors/track
|
||||
scsi_cmdbuf[pos++] = info->sectors; // Sectors/track
|
||||
scsi_cmdbuf[pos++] = info->sectorbytes >> 8; // Bytes/sector
|
||||
scsi_cmdbuf[pos++] = info->sectorbytes; // Bytes/sector
|
||||
scsi_cmdbuf[pos++] = info.sectors >> 8; // Sectors/track
|
||||
scsi_cmdbuf[pos++] = info.sectors; // Sectors/track
|
||||
scsi_cmdbuf[pos++] = info.sectorbytes >> 8; // Bytes/sector
|
||||
scsi_cmdbuf[pos++] = info.sectorbytes; // Bytes/sector
|
||||
scsi_cmdbuf[pos++] = 0x00; // Interleave
|
||||
scsi_cmdbuf[pos++] = 0x00; // Interleave
|
||||
scsi_cmdbuf[pos++] = 0x00; // Track skew
|
||||
@ -312,10 +312,10 @@ void nscsi_harddisk_device::scsi_command()
|
||||
case 0x04: { // Rigid drive geometry page
|
||||
scsi_cmdbuf[pos++] = 0x84; // PS, page id
|
||||
scsi_cmdbuf[pos++] = 0x16; // Page length
|
||||
scsi_cmdbuf[pos++] = info->cylinders >> 16; // Cylinders
|
||||
scsi_cmdbuf[pos++] = info->cylinders >> 8; // Cylinders
|
||||
scsi_cmdbuf[pos++] = info->cylinders; // Cylinders
|
||||
scsi_cmdbuf[pos++] = info->heads; // Heads
|
||||
scsi_cmdbuf[pos++] = info.cylinders >> 16; // Cylinders
|
||||
scsi_cmdbuf[pos++] = info.cylinders >> 8; // Cylinders
|
||||
scsi_cmdbuf[pos++] = info.cylinders; // Cylinders
|
||||
scsi_cmdbuf[pos++] = info.heads; // Heads
|
||||
scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp
|
||||
scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp
|
||||
scsi_cmdbuf[pos++] = 0x00; // Starting cylinder - write precomp
|
||||
@ -453,17 +453,17 @@ void nscsi_harddisk_device::scsi_command()
|
||||
case SC_READ_CAPACITY: {
|
||||
LOG("command READ CAPACITY\n");
|
||||
|
||||
hard_disk_info *info = hard_disk_get_info(harddisk);
|
||||
uint32_t size = info->cylinders * info->heads * info->sectors - 1;
|
||||
const auto &info = harddisk->get_info();
|
||||
uint32_t size = info.cylinders * info.heads * info.sectors - 1;
|
||||
|
||||
scsi_cmdbuf[0] = (size>>24) & 0xff;
|
||||
scsi_cmdbuf[1] = (size>>16) & 0xff;
|
||||
scsi_cmdbuf[2] = (size>>8) & 0xff;
|
||||
scsi_cmdbuf[3] = (size & 0xff);
|
||||
scsi_cmdbuf[4] = (info->sectorbytes>>24)&0xff;
|
||||
scsi_cmdbuf[5] = (info->sectorbytes>>16)&0xff;
|
||||
scsi_cmdbuf[6] = (info->sectorbytes>>8)&0xff;
|
||||
scsi_cmdbuf[7] = (info->sectorbytes & 0xff);
|
||||
scsi_cmdbuf[4] = (info.sectorbytes>>24)&0xff;
|
||||
scsi_cmdbuf[5] = (info.sectorbytes>>16)&0xff;
|
||||
scsi_cmdbuf[6] = (info.sectorbytes>>8)&0xff;
|
||||
scsi_cmdbuf[7] = (info.sectorbytes & 0xff);
|
||||
|
||||
scsi_data_in(0, 8);
|
||||
scsi_status_complete(SS_GOOD);
|
||||
@ -476,7 +476,7 @@ void nscsi_harddisk_device::scsi_command()
|
||||
|
||||
LOG("command READ EXTENDED start=%08x blocks=%04x\n",lba, blocks);
|
||||
|
||||
if(hard_disk_read(harddisk, lba, block)) {
|
||||
if(harddisk->read(lba, block)) {
|
||||
scsi_data_in(2, blocks*bytes_per_sector);
|
||||
scsi_status_complete(SS_GOOD);
|
||||
}
|
||||
@ -505,12 +505,12 @@ void nscsi_harddisk_device::scsi_command()
|
||||
(scsi_cmdbuf[1] & 0x10) ? " FMTDATA" : "",
|
||||
(scsi_cmdbuf[1] & 0x08) ? " CMPLIST" : "");
|
||||
{
|
||||
hard_disk_info *info = hard_disk_get_info(harddisk);
|
||||
auto block = std::make_unique<uint8_t[]>(info->sectorbytes);
|
||||
for(int cyl = 0; cyl < info->cylinders; cyl++) {
|
||||
for(int head = 0; head < info->heads; head++) {
|
||||
for(int sector = 0; sector < info->sectors; sector++) {
|
||||
hard_disk_write(harddisk, cyl * head * sector, block.get());
|
||||
const auto &info = harddisk->get_info();
|
||||
auto block = std::make_unique<uint8_t[]>(info.sectorbytes);
|
||||
for(int cyl = 0; cyl < info.cylinders; cyl++) {
|
||||
for(int head = 0; head < info.heads; head++) {
|
||||
for(int sector = 0; sector < info.sectors; sector++) {
|
||||
harddisk->write(cyl * head * sector, block.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,12 +57,12 @@ void nscsi_s1410_device::scsi_command()
|
||||
case SC_FORMAT_UNIT:
|
||||
LOG("command FORMAT UNIT\n");
|
||||
{
|
||||
hard_disk_info *info = hard_disk_get_info(harddisk);
|
||||
auto block = std::make_unique<uint8_t[]>(info->sectorbytes);
|
||||
memset(&block[0], 0x6c, info->sectorbytes);
|
||||
const auto &info = harddisk->get_info();
|
||||
auto block = std::make_unique<uint8_t[]>(info.sectorbytes);
|
||||
memset(&block[0], 0x6c, info.sectorbytes);
|
||||
lba = ((scsi_cmdbuf[1] & 0x1f)<<16) | (scsi_cmdbuf[2]<<8) | scsi_cmdbuf[3];
|
||||
for(; lba < (info->cylinders * info->heads * info->sectors); lba++) {
|
||||
hard_disk_write(harddisk, lba, block.get());
|
||||
for(; lba < (info.cylinders * info.heads * info.sectors); lba++) {
|
||||
harddisk->write(lba, block.get());
|
||||
}
|
||||
}
|
||||
scsi_status_complete(SS_GOOD);
|
||||
@ -81,7 +81,7 @@ void nscsi_s1410_device::scsi_command()
|
||||
auto block = std::make_unique<uint8_t[]>(track_length);
|
||||
memset(&block[0], 0x6c, track_length);
|
||||
|
||||
if(!hard_disk_write(harddisk, lba, &block[0])) {
|
||||
if(!harddisk->write(lba, &block[0])) {
|
||||
logerror("%s: HD WRITE ERROR !\n", tag());
|
||||
scsi_status_complete(SS_FORMAT_ERROR);
|
||||
} else {
|
||||
|
@ -54,7 +54,7 @@ void omti5100_device::ExecCommand()
|
||||
m_transfer_length = 0;
|
||||
return;
|
||||
}
|
||||
hard_disk_info *info = hard_disk_get_info(image);
|
||||
const auto &info = image->get_info();
|
||||
switch(command[0])
|
||||
{
|
||||
case OMTI_READ_DATA_BUFFER:
|
||||
@ -77,7 +77,7 @@ void omti5100_device::ExecCommand()
|
||||
{
|
||||
int track = ((command[1]&0x1f)<<16 | command[2]<<8 | command[3]) / (m_param[drive].sectors ? m_param[drive].sectors : 1);
|
||||
int heads = m_param[drive].heads ? m_param[drive].heads : 1;
|
||||
if(((track % heads) > info->heads) || (track >= (info->cylinders * heads)))
|
||||
if(((track % heads) > info.heads) || (track >= (info.cylinders * heads)))
|
||||
{
|
||||
m_phase = SCSI_PHASE_STATUS;
|
||||
m_status_code = SCSI_STATUS_CODE_CHECK_CONDITION;
|
||||
@ -94,15 +94,15 @@ void omti5100_device::ExecCommand()
|
||||
case OMTI_FORMAT_TRACK:
|
||||
{
|
||||
int track = ((command[1]&0x1f)<<16 | command[2]<<8 | command[3]) / m_param[drive].sectors;
|
||||
if(((track % m_param[drive].heads) <= info->heads) && (track < (info->cylinders * m_param[drive].heads)))
|
||||
if(((track % m_param[drive].heads) <= info.heads) && (track < (info.cylinders * m_param[drive].heads)))
|
||||
{
|
||||
std::vector<uint8_t> sector(info->sectorbytes);
|
||||
memset(§or[0], 0xe5, info->sectorbytes);
|
||||
std::vector<uint8_t> sector(info.sectorbytes);
|
||||
memset(§or[0], 0xe5, info.sectorbytes);
|
||||
m_phase = SCSI_PHASE_STATUS;
|
||||
m_status_code = SCSI_STATUS_CODE_GOOD;
|
||||
m_transfer_length = 0;
|
||||
for(int i = 0; i < info->sectors; i++)
|
||||
hard_disk_write(image, track * info->sectors + i, §or[0]);
|
||||
for(int i = 0; i < info.sectors; i++)
|
||||
image->write(track * info.sectors + i, §or[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -149,7 +149,7 @@ void omti5100_device::WriteData( uint8_t *data, int dataLength )
|
||||
m_param[drive].cylinders = ((data[4] << 8) | data[5]) + 1;
|
||||
if(!data[8] && image)
|
||||
{
|
||||
switch(hard_disk_get_info(image)->sectorbytes)
|
||||
switch(image->get_info().sectorbytes)
|
||||
{
|
||||
case 128:
|
||||
m_param[drive].sectors = 53;
|
||||
|
@ -24,7 +24,7 @@ protected:
|
||||
private:
|
||||
required_device<harddisk_image_device> m_image0;
|
||||
required_device<harddisk_image_device> m_image1;
|
||||
hard_disk_info m_param[2];
|
||||
hard_disk_file::info m_param[2];
|
||||
};
|
||||
|
||||
DECLARE_DEVICE_TYPE(OMTI5100, omti5100_device)
|
||||
|
@ -255,7 +255,7 @@ void s1410_device::ExecCommand()
|
||||
|
||||
while (m_blocks > 0)
|
||||
{
|
||||
if (!hard_disk_write(m_disk, m_lba, &data[0]))
|
||||
if (!m_disk->write(m_lba, &data[0]))
|
||||
{
|
||||
logerror("S1410: HD write error!\n");
|
||||
}
|
||||
|
@ -175,18 +175,16 @@ DEVICE_IMAGE_LOAD_MEMBER( ti990_hdc_device::load_hd )
|
||||
|
||||
if ( hd_file )
|
||||
{
|
||||
const hard_disk_info *standard_header;
|
||||
|
||||
d->format = format_mame;
|
||||
d->hd_handle = hd_file;
|
||||
|
||||
/* use standard hard disk image header. */
|
||||
standard_header = hard_disk_get_info(d->hd_handle);
|
||||
const auto &standard_header = d->hd_handle->get_info();
|
||||
|
||||
d->cylinders = standard_header->cylinders;
|
||||
d->heads = standard_header->heads;
|
||||
d->sectors_per_track = standard_header->sectors;
|
||||
d->bytes_per_sector = standard_header->sectorbytes;
|
||||
d->cylinders = standard_header.cylinders;
|
||||
d->heads = standard_header.heads;
|
||||
d->sectors_per_track = standard_header.sectors;
|
||||
d->bytes_per_sector = standard_header.sectorbytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -365,7 +363,7 @@ int ti990_hdc_device::read_sector(int unit, unsigned int lba, void *buffer, unsi
|
||||
switch (m_d[unit].format)
|
||||
{
|
||||
case format_mame:
|
||||
bytes_read = m_d[unit].bytes_per_sector * hard_disk_read(m_d[unit].hd_handle, lba, buffer);
|
||||
bytes_read = m_d[unit].bytes_per_sector * m_d[unit].hd_handle->read(lba, buffer);
|
||||
if (bytes_read > bytes_to_read)
|
||||
bytes_read = bytes_to_read;
|
||||
break;
|
||||
@ -395,7 +393,7 @@ int ti990_hdc_device::write_sector(int unit, unsigned int lba, const void *buffe
|
||||
switch (m_d[unit].format)
|
||||
{
|
||||
case format_mame:
|
||||
bytes_written = m_d[unit].bytes_per_sector * hard_disk_write(m_d[unit].hd_handle, lba, buffer);
|
||||
bytes_written = m_d[unit].bytes_per_sector * m_d[unit].hd_handle->write(lba, buffer);
|
||||
if (bytes_written > bytes_to_write)
|
||||
bytes_written = bytes_to_write;
|
||||
break;
|
||||
|
@ -83,7 +83,7 @@ void diablo_image_device::device_start()
|
||||
chd_file *handle = machine().rom_load().get_disk_handle(tag());
|
||||
if (handle != nullptr)
|
||||
{
|
||||
m_hard_disk_handle = hard_disk_open(handle);
|
||||
m_hard_disk_handle = new hard_disk_file(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -94,7 +94,7 @@ void diablo_image_device::device_start()
|
||||
void diablo_image_device::device_stop()
|
||||
{
|
||||
if (m_hard_disk_handle)
|
||||
hard_disk_close(m_hard_disk_handle);
|
||||
delete m_hard_disk_handle;
|
||||
}
|
||||
|
||||
image_init_result diablo_image_device::call_load()
|
||||
@ -154,7 +154,7 @@ void diablo_image_device::call_unload()
|
||||
|
||||
if (m_hard_disk_handle != nullptr)
|
||||
{
|
||||
hard_disk_close(m_hard_disk_handle);
|
||||
delete m_hard_disk_handle;
|
||||
m_hard_disk_handle = nullptr;
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ image_init_result diablo_image_device::internal_load_dsk()
|
||||
m_chd = nullptr;
|
||||
|
||||
if (m_hard_disk_handle)
|
||||
hard_disk_close(m_hard_disk_handle);
|
||||
delete m_hard_disk_handle;
|
||||
|
||||
/* open the CHD file */
|
||||
if (loaded_through_softlist())
|
||||
@ -249,7 +249,7 @@ image_init_result diablo_image_device::internal_load_dsk()
|
||||
if (m_chd != nullptr)
|
||||
{
|
||||
/* open the hard disk file */
|
||||
m_hard_disk_handle = hard_disk_open(m_chd);
|
||||
m_hard_disk_handle = new hard_disk_file(m_chd);
|
||||
if (m_hard_disk_handle != nullptr)
|
||||
return image_init_result::PASS;
|
||||
}
|
||||
@ -275,6 +275,6 @@ chd_file *diablo_image_device::get_chd_file()
|
||||
chd_file *result = nullptr;
|
||||
hard_disk_file *hd_file = get_hard_disk_file();
|
||||
if (hd_file)
|
||||
result = hard_disk_get_chd(hd_file);
|
||||
result = hd_file->get_chd();
|
||||
return result;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ void harddisk_image_device::device_start()
|
||||
chd_file *handle = machine().rom_load().get_disk_handle(tag());
|
||||
if (handle != nullptr)
|
||||
{
|
||||
m_hard_disk_handle = hard_disk_open(handle);
|
||||
m_hard_disk_handle = new hard_disk_file(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -123,7 +123,7 @@ void harddisk_image_device::device_stop()
|
||||
{
|
||||
if (m_hard_disk_handle != nullptr)
|
||||
{
|
||||
hard_disk_close(m_hard_disk_handle);
|
||||
delete m_hard_disk_handle;
|
||||
m_hard_disk_handle = nullptr;
|
||||
}
|
||||
}
|
||||
@ -184,7 +184,7 @@ void harddisk_image_device::call_unload()
|
||||
|
||||
if (m_hard_disk_handle)
|
||||
{
|
||||
hard_disk_close(m_hard_disk_handle);
|
||||
delete m_hard_disk_handle;
|
||||
m_hard_disk_handle = nullptr;
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ image_init_result harddisk_image_device::internal_load_hd()
|
||||
|
||||
if (m_hard_disk_handle)
|
||||
{
|
||||
hard_disk_close(m_hard_disk_handle);
|
||||
delete m_hard_disk_handle;
|
||||
m_hard_disk_handle = nullptr;
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ image_init_result harddisk_image_device::internal_load_hd()
|
||||
if (m_chd)
|
||||
{
|
||||
/* open the hard disk file */
|
||||
m_hard_disk_handle = hard_disk_open(m_chd);
|
||||
m_hard_disk_handle = new hard_disk_file(m_chd);
|
||||
if (m_hard_disk_handle)
|
||||
return image_init_result::PASS;
|
||||
}
|
||||
@ -325,7 +325,7 @@ image_init_result harddisk_image_device::internal_load_hd()
|
||||
}
|
||||
}
|
||||
|
||||
m_hard_disk_handle = hard_disk_open(image_core_file(), skip);
|
||||
m_hard_disk_handle = new hard_disk_file(image_core_file(), skip);
|
||||
if (m_hard_disk_handle)
|
||||
return image_init_result::PASS;
|
||||
}
|
||||
@ -354,6 +354,6 @@ chd_file *harddisk_image_device::get_chd_file()
|
||||
chd_file *result = nullptr;
|
||||
hard_disk_file *hd_file = get_hard_disk_file();
|
||||
if (hd_file)
|
||||
result = hard_disk_get_chd(hd_file);
|
||||
result = hd_file->get_chd();
|
||||
return result;
|
||||
}
|
||||
|
@ -444,12 +444,12 @@ uint8_t corvus_hdc_device::corvus_write_sector(uint8_t drv, uint32_t sector, uin
|
||||
// wonderful functionality.
|
||||
//
|
||||
if(len == 512) {
|
||||
hard_disk_write(disk, sector, buffer);
|
||||
disk->write(sector, buffer);
|
||||
} else {
|
||||
hard_disk_read(disk, sector, tbuffer); // Read the existing data into our temporary buffer
|
||||
disk->read(sector, tbuffer); // Read the existing data into our temporary buffer
|
||||
memcpy(tbuffer, buffer, len); // Overlay the data with the buffer passed
|
||||
m_delay += INTERSECTOR_DELAY; // Add another delay because of the Read / Write
|
||||
hard_disk_write(disk, sector, tbuffer); // Re-write the data
|
||||
disk->write(sector, tbuffer); // Re-write the data
|
||||
}
|
||||
|
||||
m_last_cylinder = cylinder;
|
||||
@ -545,7 +545,7 @@ uint8_t corvus_hdc_device::corvus_read_sector(uint8_t drv, uint32_t sector, uint
|
||||
cylinder = (double) sector / (double) m_sectors_per_track / (double) m_tracks_per_cylinder;
|
||||
m_delay = abs(m_last_cylinder - cylinder) * TRACK_SEEK_TIME + INTERSECTOR_DELAY;
|
||||
|
||||
hard_disk_read(disk, sector, tbuffer);
|
||||
disk->read(sector, tbuffer);
|
||||
|
||||
memcpy(buffer, tbuffer, len);
|
||||
|
||||
@ -1119,12 +1119,12 @@ hard_disk_file *corvus_hdc_device::corvus_hdc_file(int drv) {
|
||||
|
||||
// Pick up the Head/Cylinder/Sector info
|
||||
hard_disk_file *file = img->get_hard_disk_file();
|
||||
hard_disk_info *info = hard_disk_get_info(file);
|
||||
m_sectors_per_track = info->sectors;
|
||||
m_tracks_per_cylinder = info->heads;
|
||||
m_cylinders_per_drive = info->cylinders;
|
||||
const auto &info = file->get_info();
|
||||
m_sectors_per_track = info.sectors;
|
||||
m_tracks_per_cylinder = info.heads;
|
||||
m_cylinders_per_drive = info.cylinders;
|
||||
|
||||
LOG(("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", drv, info->heads, info->cylinders, info->sectors));
|
||||
LOG(("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", drv, info.heads, info.cylinders, info.sectors));
|
||||
|
||||
return file;
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ void diablo_hd_device::read_sector()
|
||||
// allocate a buffer for this page
|
||||
m_cache[m_page] = std::make_unique<uint8_t[]>(sizeof(diablo_sector_t));
|
||||
// and read the page from the hard_disk image
|
||||
if (hard_disk_read(m_disk, m_page, m_cache[m_page].get())) {
|
||||
if (m_disk->read(m_page, m_cache[m_page].get())) {
|
||||
LOG_DRIVE(2,"[DHD%u] CHS:%03d/%d/%02d => page:%d loaded\n", m_unit, m_cylinder, m_head, m_sector, m_page);
|
||||
} else {
|
||||
LOG_DRIVE(0,"[DHD%u] CHS:%03d/%d/%02d => page:%d read failed\n", m_unit, m_cylinder, m_head, m_sector, m_page);
|
||||
@ -770,7 +770,7 @@ void diablo_hd_device::squeeze_sector()
|
||||
m_bits[m_page].reset();
|
||||
|
||||
if (m_disk) {
|
||||
if (!hard_disk_write(m_disk, m_page, m_cache[m_page].get())) {
|
||||
if (!m_disk->write(m_page, m_cache[m_page].get())) {
|
||||
LOG_DRIVE(0,"[DHD%u] write failed for page #%d\n", m_unit, m_page);
|
||||
}
|
||||
} else {
|
||||
|
@ -163,7 +163,7 @@ void spi_sdcard_device::spi_clock_w(int state)
|
||||
}
|
||||
|
||||
LOGMASKED(LOG_GENERAL, "writing LBA %x, data %02x %02x %02x %02x\n", blk, m_data[0], m_data[1], m_data[2], m_data[3]);
|
||||
if (hard_disk_write(m_harddisk, blk, &m_data[0]))
|
||||
if (m_harddisk->write(blk, &m_data[0]))
|
||||
{
|
||||
m_data[0] = DATA_RESPONSE_OK;
|
||||
}
|
||||
@ -182,7 +182,7 @@ void spi_sdcard_device::spi_clock_w(int state)
|
||||
if (m_state == SD_STATE_DATA_MULTI && m_out_count == 0)
|
||||
{
|
||||
m_data[0] = 0xfe; // data token
|
||||
hard_disk_read(m_harddisk, m_blknext++, &m_data[1]);
|
||||
m_harddisk->read(m_blknext++, &m_data[1]);
|
||||
util::crc16_t crc16 = util::crc16_creator::simple(
|
||||
&m_data[1], m_blksize);
|
||||
m_data[m_blksize + 1] = (crc16 >> 8) & 0xff;
|
||||
@ -292,7 +292,7 @@ void spi_sdcard_device::do_command()
|
||||
|
||||
case 16: // CMD16 - SET_BLOCKLEN
|
||||
m_blksize = (u16(m_cmd[3]) << 8) | u16(m_cmd[4]);
|
||||
if (hard_disk_set_block_size(m_harddisk, m_blksize))
|
||||
if (m_harddisk->set_block_size(m_blksize))
|
||||
{
|
||||
m_data[0] = 0;
|
||||
}
|
||||
@ -322,7 +322,7 @@ void spi_sdcard_device::do_command()
|
||||
blk /= m_blksize;
|
||||
}
|
||||
LOGMASKED(LOG_GENERAL, "reading LBA %x\n", blk);
|
||||
hard_disk_read(m_harddisk, blk, &m_data[3]);
|
||||
m_harddisk->read(blk, &m_data[3]);
|
||||
{
|
||||
util::crc16_t crc16 = util::crc16_creator::simple(&m_data[3], m_blksize);
|
||||
m_data[m_blksize + 3] = (crc16 >> 8) & 0xff;
|
||||
|
@ -28,8 +28,7 @@ void t10sbc::t10_reset()
|
||||
else
|
||||
{
|
||||
// get hard disk sector size from CHD metadata
|
||||
const hard_disk_info *hdinfo = hard_disk_get_info(m_disk);
|
||||
m_sector_bytes = hdinfo->sectorbytes;
|
||||
m_sector_bytes = m_disk->get_info().sectorbytes;
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,7 +277,7 @@ void t10sbc::ReadData( uint8_t *data, int dataLength )
|
||||
m_device->logerror("T10SBC: Reading %d bytes from HD\n", dataLength);
|
||||
while (dataLength > 0)
|
||||
{
|
||||
if (!hard_disk_read(m_disk, m_lba, data))
|
||||
if (!m_disk->read(m_lba, data))
|
||||
{
|
||||
m_device->logerror("T10SBC: HD read error!\n");
|
||||
}
|
||||
@ -320,7 +319,7 @@ void t10sbc::WriteData( uint8_t *data, int dataLength )
|
||||
m_device->logerror("T10SBC: Writing %d bytes to HD\n", dataLength);
|
||||
while (dataLength > 0)
|
||||
{
|
||||
if (!hard_disk_write(m_disk, m_lba, data))
|
||||
if (!m_disk->write(m_lba, data))
|
||||
{
|
||||
m_device->logerror("T10SBC: HD write error!\n");
|
||||
}
|
||||
@ -350,46 +349,46 @@ void t10sbc::SetDevice( void *_disk )
|
||||
|
||||
void t10sbc::GetFormatPage( format_page_t *page )
|
||||
{
|
||||
hard_disk_info *info = hard_disk_get_info(m_disk);
|
||||
const auto &info = m_disk->get_info();
|
||||
|
||||
memset(page, 0, sizeof(format_page_t));
|
||||
page->m_page_code = 0x03;
|
||||
page->m_page_length = 0x16;
|
||||
page->m_sectors_per_track_msb = (uint8_t)(info->sectors >> 8);
|
||||
page->m_sectors_per_track_lsb = (uint8_t)info->sectors;
|
||||
page->m_bytes_per_sector_msb = (uint8_t)(info->sectorbytes >> 8);
|
||||
page->m_bytes_per_sector_lsb = (uint8_t)info->sectorbytes;
|
||||
page->m_sectors_per_track_msb = (uint8_t)(info.sectors >> 8);
|
||||
page->m_sectors_per_track_lsb = (uint8_t)info.sectors;
|
||||
page->m_bytes_per_sector_msb = (uint8_t)(info.sectorbytes >> 8);
|
||||
page->m_bytes_per_sector_lsb = (uint8_t)info.sectorbytes;
|
||||
page->m_format = 0x80; // SSEC, Soft-Sectored
|
||||
}
|
||||
|
||||
void t10sbc::GetGeometryPage( geometry_page_t *page )
|
||||
{
|
||||
hard_disk_info *info = hard_disk_get_info(m_disk);
|
||||
const auto &info = m_disk->get_info();
|
||||
|
||||
memset(page, 0, sizeof(geometry_page_t));
|
||||
page->m_page_code = 0x04;
|
||||
page->m_page_length = 0x16;
|
||||
page->m_num_cylinders_msb = (uint8_t)(info->cylinders >> 16);
|
||||
page->m_num_cylinders_2nd = (uint8_t)(info->cylinders >> 8);
|
||||
page->m_num_cylinders_lsb = (uint8_t)info->cylinders;
|
||||
page->m_num_heads = (uint8_t)info->heads;
|
||||
page->m_num_cylinders_msb = (uint8_t)(info.cylinders >> 16);
|
||||
page->m_num_cylinders_2nd = (uint8_t)(info.cylinders >> 8);
|
||||
page->m_num_cylinders_lsb = (uint8_t)info.cylinders;
|
||||
page->m_num_heads = (uint8_t)info.heads;
|
||||
page->m_rot_rate_msb = (uint8_t)(3600 >> 8);
|
||||
page->m_rot_rate_lsb = (uint8_t)3600;
|
||||
}
|
||||
|
||||
void t10sbc::ReadCapacity( uint8_t *data )
|
||||
{
|
||||
hard_disk_info *info = hard_disk_get_info(m_disk);
|
||||
const auto &info = m_disk->get_info();
|
||||
|
||||
// get # of sectors
|
||||
uint32_t temp = info->cylinders * info->heads * info->sectors - 1;
|
||||
uint32_t temp = info.cylinders * info.heads * info.sectors - 1;
|
||||
|
||||
data[0] = (temp>>24) & 0xff;
|
||||
data[1] = (temp>>16) & 0xff;
|
||||
data[2] = (temp>>8) & 0xff;
|
||||
data[3] = (temp & 0xff);
|
||||
data[4] = (info->sectorbytes>>24)&0xff;
|
||||
data[5] = (info->sectorbytes>>16)&0xff;
|
||||
data[6] = (info->sectorbytes>>8)&0xff;
|
||||
data[7] = (info->sectorbytes & 0xff);
|
||||
data[4] = (info.sectorbytes>>24)&0xff;
|
||||
data[5] = (info.sectorbytes>>16)&0xff;
|
||||
data[6] = (info.sectorbytes>>8)&0xff;
|
||||
data[7] = (info.sectorbytes & 0xff);
|
||||
}
|
||||
|
@ -241,35 +241,35 @@ void wd1000_device::end_command()
|
||||
int wd1000_device::get_lbasector()
|
||||
{
|
||||
hard_disk_file *file = m_drives[drive()]->get_hard_disk_file();
|
||||
hard_disk_info *info = hard_disk_get_info(file);
|
||||
const auto &info = file->get_info();
|
||||
int lbasector;
|
||||
|
||||
if (m_cylinder > info->cylinders)
|
||||
if (m_cylinder > info.cylinders)
|
||||
{
|
||||
logerror("%s: Unexpected cylinder %d for range 0 to %d\n", machine().describe_context(), m_cylinder, info->cylinders - 1);
|
||||
logerror("%s: Unexpected cylinder %d for range 0 to %d\n", machine().describe_context(), m_cylinder, info.cylinders - 1);
|
||||
}
|
||||
|
||||
if (head() >= info->heads)
|
||||
if (head() >= info.heads)
|
||||
{
|
||||
logerror("%s: Unexpected head %d for range 0 to %d\n", machine().describe_context(), head(), info->heads - 1);
|
||||
logerror("%s: Unexpected head %d for range 0 to %d\n", machine().describe_context(), head(), info.heads - 1);
|
||||
}
|
||||
|
||||
int16_t sector = m_sector_number - m_sector_base;
|
||||
|
||||
if (sector < 0 || sector >= info->sectors)
|
||||
if (sector < 0 || sector >= info.sectors)
|
||||
{
|
||||
logerror("%s: Unexpected sector number %d for range %d to %d\n", machine().describe_context(), m_sector_number, m_sector_base, info->sectors + m_sector_base);
|
||||
logerror("%s: Unexpected sector number %d for range %d to %d\n", machine().describe_context(), m_sector_number, m_sector_base, info.sectors + m_sector_base);
|
||||
}
|
||||
|
||||
if (sector_bytes() != info->sectorbytes)
|
||||
if (sector_bytes() != info.sectorbytes)
|
||||
{
|
||||
logerror("%s: Unexpected sector bytes %d, expected %d\n", machine().describe_context(), sector_bytes(), info->sectorbytes);
|
||||
logerror("%s: Unexpected sector bytes %d, expected %d\n", machine().describe_context(), sector_bytes(), info.sectorbytes);
|
||||
}
|
||||
|
||||
lbasector = m_cylinder;
|
||||
lbasector *= info->heads;
|
||||
lbasector *= info.heads;
|
||||
lbasector += head();
|
||||
lbasector *= info->sectors;
|
||||
lbasector *= info.sectors;
|
||||
lbasector += sector;
|
||||
|
||||
return lbasector;
|
||||
@ -578,7 +578,7 @@ void wd1000_device::cmd_read_sector()
|
||||
hard_disk_file *file = m_drives[drive()]->get_hard_disk_file();
|
||||
uint8_t dma = BIT(m_command, 3);
|
||||
|
||||
hard_disk_read(file, get_lbasector(), m_buffer);
|
||||
file->read(get_lbasector(), m_buffer);
|
||||
|
||||
m_buffer_index = 0;
|
||||
m_buffer_end = 512;
|
||||
@ -603,7 +603,7 @@ void wd1000_device::cmd_write_sector()
|
||||
logerror("%s: Unexpected unfilled buffer on write, only %d or %d bytes filled\n", machine().describe_context(), m_buffer_index, sector_bytes());
|
||||
}
|
||||
|
||||
hard_disk_write(file, get_lbasector(), m_buffer);
|
||||
file->write(get_lbasector(), m_buffer);
|
||||
|
||||
end_command();
|
||||
}
|
||||
@ -619,7 +619,7 @@ void wd1000_device::cmd_format_sector()
|
||||
for (int i = 0; i < m_sector_count; i++)
|
||||
{
|
||||
std::fill(std::begin(buffer), std::end(buffer), 0);
|
||||
hard_disk_write(file, get_lbasector(), buffer);
|
||||
file->write(get_lbasector(), buffer);
|
||||
}
|
||||
|
||||
m_sector_count = 0;
|
||||
|
@ -303,13 +303,13 @@ void wd1010_device::end_command()
|
||||
int wd1010_device::get_lbasector()
|
||||
{
|
||||
hard_disk_file *file = m_drives[drive()].drive->get_hard_disk_file();
|
||||
hard_disk_info *info = hard_disk_get_info(file);
|
||||
const auto &info = file->get_info();
|
||||
int lbasector;
|
||||
|
||||
lbasector = m_cylinder;
|
||||
lbasector *= info->heads;
|
||||
lbasector *= info.heads;
|
||||
lbasector += head();
|
||||
lbasector *= info->sectors;
|
||||
lbasector *= info.sectors;
|
||||
lbasector += m_sector_number;
|
||||
|
||||
return lbasector;
|
||||
@ -535,10 +535,10 @@ void wd1010_device::cmd_read_sector()
|
||||
}
|
||||
|
||||
hard_disk_file *file = m_drives[drive()].drive->get_hard_disk_file();
|
||||
hard_disk_info *info = hard_disk_get_info(file);
|
||||
const auto &info = file->get_info();
|
||||
|
||||
// verify that we can read
|
||||
if (head() > info->heads)
|
||||
if (head() > info.heads)
|
||||
{
|
||||
// out of range
|
||||
LOG("--> Head out of range, aborting\n");
|
||||
@ -557,7 +557,7 @@ void wd1010_device::cmd_read_sector()
|
||||
|
||||
LOGDATA("--> Transferring sector to buffer (lba = %08x)\n", get_lbasector());
|
||||
|
||||
hard_disk_read(file, get_lbasector(), buffer);
|
||||
file->read(get_lbasector(), buffer);
|
||||
|
||||
for (int i = 0; i < 512; i++)
|
||||
m_out_data_cb(buffer[i]);
|
||||
@ -626,7 +626,7 @@ void wd1010_device::cmd_write_sector()
|
||||
buffer[i] = m_in_data_cb();
|
||||
}
|
||||
|
||||
hard_disk_write(file, get_lbasector(), buffer);
|
||||
file->write(get_lbasector(), buffer);
|
||||
|
||||
// save last read head and sector number
|
||||
m_drives[drive()].head = head();
|
||||
|
@ -15,88 +15,51 @@
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
TYPE DEFINITIONS
|
||||
***************************************************************************/
|
||||
|
||||
struct hard_disk_file
|
||||
{
|
||||
chd_file * chd; // CHD file
|
||||
util::random_read_write * fhandle; // file if not a CHD
|
||||
hard_disk_info info; // hard disk info
|
||||
};
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
CORE IMPLEMENTATION
|
||||
***************************************************************************/
|
||||
|
||||
/*-------------------------------------------------
|
||||
hard_disk_open - open a hard disk handle,
|
||||
constructor - open a hard disk handle,
|
||||
given a chd_file
|
||||
-------------------------------------------------*/
|
||||
|
||||
hard_disk_file *hard_disk_open(chd_file *chd)
|
||||
hard_disk_file::hard_disk_file(chd_file *_chd)
|
||||
{
|
||||
int cylinders, heads, sectors, sectorbytes;
|
||||
hard_disk_file *file;
|
||||
chd = _chd;
|
||||
fhandle = nullptr;
|
||||
hdinfo.fileoffset = 0;
|
||||
|
||||
std::string metadata;
|
||||
std::error_condition err;
|
||||
|
||||
/* punt if no CHD */
|
||||
if (chd == nullptr)
|
||||
return nullptr;
|
||||
throw nullptr;
|
||||
|
||||
/* read the hard disk metadata */
|
||||
err = chd->read_metadata(HARD_DISK_METADATA_TAG, 0, metadata);
|
||||
err = _chd->read_metadata(HARD_DISK_METADATA_TAG, 0, metadata);
|
||||
if (err)
|
||||
return nullptr;
|
||||
throw nullptr;
|
||||
|
||||
/* parse the metadata */
|
||||
if (sscanf(metadata.c_str(), HARD_DISK_METADATA_FORMAT, &cylinders, &heads, §ors, §orbytes) != 4)
|
||||
return nullptr;
|
||||
|
||||
/* allocate memory for the hard disk file */
|
||||
file = (hard_disk_file *)malloc(sizeof(hard_disk_file));
|
||||
if (file == nullptr)
|
||||
return nullptr;
|
||||
|
||||
/* fill in the data */
|
||||
file->chd = chd;
|
||||
file->fhandle = nullptr;
|
||||
file->info.cylinders = cylinders;
|
||||
file->info.heads = heads;
|
||||
file->info.sectors = sectors;
|
||||
file->info.sectorbytes = sectorbytes;
|
||||
file->info.fileoffset = 0;
|
||||
return file;
|
||||
if (sscanf(metadata.c_str(), HARD_DISK_METADATA_FORMAT, &hdinfo.cylinders, &hdinfo.heads, &hdinfo.sectors, &hdinfo.sectorbytes) != 4)
|
||||
throw nullptr;
|
||||
}
|
||||
|
||||
hard_disk_file *hard_disk_open(util::random_read_write &corefile, uint32_t skipoffs)
|
||||
hard_disk_file::hard_disk_file(util::random_read_write &corefile, uint32_t skipoffs)
|
||||
{
|
||||
// bail if getting the file length fails
|
||||
std::uint64_t length;
|
||||
if (corefile.length(length))
|
||||
return nullptr;
|
||||
throw nullptr;
|
||||
|
||||
hard_disk_file *file;
|
||||
|
||||
// allocate memory for the hard disk file
|
||||
file = (hard_disk_file *)malloc(sizeof(hard_disk_file));
|
||||
if (file == nullptr)
|
||||
return nullptr;
|
||||
|
||||
file->chd = nullptr;
|
||||
file->fhandle = &corefile;
|
||||
file->info.sectorbytes = 512;
|
||||
file->info.cylinders = 0;
|
||||
file->info.heads = 0;
|
||||
file->info.sectors = 0;
|
||||
file->info.fileoffset = skipoffs;
|
||||
chd = nullptr;
|
||||
fhandle = &corefile;
|
||||
hdinfo.sectorbytes = 512;
|
||||
hdinfo.cylinders = 0;
|
||||
hdinfo.heads = 0;
|
||||
hdinfo.sectors = 0;
|
||||
hdinfo.fileoffset = skipoffs;
|
||||
|
||||
// attempt to guess geometry in case this is an ATA situation
|
||||
for (uint32_t totalsectors = (length - skipoffs) / file->info.sectorbytes; ; totalsectors++)
|
||||
for (uint32_t totalsectors = (length - skipoffs) / hdinfo.sectorbytes; ; totalsectors++)
|
||||
for (uint32_t cursectors = 63; cursectors > 1; cursectors--)
|
||||
if (totalsectors % cursectors == 0)
|
||||
{
|
||||
@ -104,146 +67,103 @@ hard_disk_file *hard_disk_open(util::random_read_write &corefile, uint32_t skipo
|
||||
for (uint32_t curheads = 16; curheads > 1; curheads--)
|
||||
if (totalheads % curheads == 0)
|
||||
{
|
||||
file->info.cylinders = totalheads / curheads;
|
||||
file->info.heads = curheads;
|
||||
file->info.sectors = cursectors;
|
||||
osd_printf_verbose("Guessed CHS of %d/%d/%d\n", file->info.cylinders, file->info.heads, file->info.sectors);
|
||||
return file;
|
||||
hdinfo.cylinders = totalheads / curheads;
|
||||
hdinfo.heads = curheads;
|
||||
hdinfo.sectors = cursectors;
|
||||
osd_printf_verbose("Guessed CHS of %d/%d/%d\n", hdinfo.cylinders, hdinfo.heads, hdinfo.sectors);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
hard_disk_close - close a hard disk handle
|
||||
destructor - close a hard disk handle
|
||||
-------------------------------------------------*/
|
||||
|
||||
void hard_disk_close(hard_disk_file *file)
|
||||
hard_disk_file::~hard_disk_file()
|
||||
{
|
||||
if (file->fhandle)
|
||||
file->fhandle->flush();
|
||||
|
||||
free(file);
|
||||
if (fhandle)
|
||||
fhandle->flush();
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
hard_disk_get_chd - get a handle to a CHD
|
||||
from a hard disk
|
||||
-------------------------------------------------*/
|
||||
|
||||
chd_file *hard_disk_get_chd(hard_disk_file *file)
|
||||
{
|
||||
return file->chd;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
hard_disk_get_info - return information about
|
||||
a hard disk
|
||||
read - read sectors from a hard disk
|
||||
-------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @fn hard_disk_info *hard_disk_get_info(hard_disk_file *file)
|
||||
*
|
||||
* @brief Hard disk get information.
|
||||
*
|
||||
* @param [in,out] file The hard disk file object to operate on.
|
||||
*
|
||||
* @return null if it fails, else a hard_disk_info*.
|
||||
*/
|
||||
|
||||
hard_disk_info *hard_disk_get_info(hard_disk_file *file)
|
||||
{
|
||||
return &file->info;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
hard_disk_read - read sectors from a hard
|
||||
disk
|
||||
-------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @fn bool hard_disk_read(hard_disk_file *file, uint32_t lbasector, void *buffer)
|
||||
* @fn bool read(uint32_t lbasector, void *buffer)
|
||||
*
|
||||
* @brief Hard disk read.
|
||||
*
|
||||
* @param [in,out] file The hard disk file object to operate on.
|
||||
* @param lbasector The sector number (Linear Block Address) to read.
|
||||
* @param buffer The buffer where the hard disk data will be placed.
|
||||
*
|
||||
* @return True if the operation succeeded
|
||||
*/
|
||||
|
||||
bool hard_disk_read(hard_disk_file *file, uint32_t lbasector, void *buffer)
|
||||
bool hard_disk_file::read(uint32_t lbasector, void *buffer)
|
||||
{
|
||||
std::error_condition err;
|
||||
if (file->chd)
|
||||
if (chd)
|
||||
{
|
||||
err = file->chd->read_units(lbasector, buffer);
|
||||
std::error_condition err = chd->read_units(lbasector, buffer);
|
||||
return !err;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t actual = 0;
|
||||
err = file->fhandle->seek(file->info.fileoffset + (lbasector * file->info.sectorbytes), SEEK_SET);
|
||||
std::error_condition err = fhandle->seek(hdinfo.fileoffset + (lbasector * hdinfo.sectorbytes), SEEK_SET);
|
||||
if (!err)
|
||||
err = file->fhandle->read(buffer, file->info.sectorbytes, actual);
|
||||
return !err && (actual == file->info.sectorbytes);
|
||||
err = fhandle->read(buffer, hdinfo.sectorbytes, actual);
|
||||
return !err && (actual == hdinfo.sectorbytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
hard_disk_write - write sectors to a hard
|
||||
disk
|
||||
write - write sectors to a hard disk
|
||||
-------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @fn bool hard_disk_write(hard_disk_file *file, uint32_t lbasector, const void *buffer)
|
||||
* @fn bool write(uint32_t lbasector, const void *buffer)
|
||||
*
|
||||
* @brief Hard disk write.
|
||||
*
|
||||
* @param [in,out] file The hard disk file object to operate on.
|
||||
* @param lbasector The sector number (Linear Block Address) to write.
|
||||
* @param buffer The buffer containing the data to write.
|
||||
*
|
||||
* @return True if the operation succeeded
|
||||
*/
|
||||
|
||||
bool hard_disk_write(hard_disk_file *file, uint32_t lbasector, const void *buffer)
|
||||
bool hard_disk_file::write(uint32_t lbasector, const void *buffer)
|
||||
{
|
||||
std::error_condition err;
|
||||
if (file->chd)
|
||||
if (chd)
|
||||
{
|
||||
err = file->chd->write_units(lbasector, buffer);
|
||||
std::error_condition err = chd->write_units(lbasector, buffer);
|
||||
return !err;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t actual = 0;
|
||||
err = file->fhandle->seek(file->info.fileoffset + (lbasector * file->info.sectorbytes), SEEK_SET);
|
||||
std::error_condition err = fhandle->seek(hdinfo.fileoffset + (lbasector * hdinfo.sectorbytes), SEEK_SET);
|
||||
if (!err)
|
||||
err = file->fhandle->write(buffer, file->info.sectorbytes, actual);
|
||||
return !err && (actual == file->info.sectorbytes);
|
||||
err = fhandle->write(buffer, hdinfo.sectorbytes, actual);
|
||||
return !err && (actual == hdinfo.sectorbytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
hard_disk_set_block_size - sets the block size
|
||||
set_block_size - sets the block size
|
||||
for a non-CHD-backed hard disk (a bare file).
|
||||
-------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @fn bool hard_disk_set_block_size(hard_disk_file *file, uint32_t blocksize)
|
||||
* @fn bool set_block_size(uint32_t blocksize)
|
||||
*
|
||||
* @brief Hard disk set block size (works only for non-CHD-files)
|
||||
*
|
||||
* @param [in,out] file The hard_disk_file object to operate on.
|
||||
* @param blocksize The block size of this hard disk, in bytes.
|
||||
*
|
||||
* @return true on success, false on failure. Failure means a CHD is in use and the CHD
|
||||
@ -251,12 +171,12 @@ bool hard_disk_write(hard_disk_file *file, uint32_t lbasector, const void *buffe
|
||||
* sizes match, success is returned).
|
||||
*/
|
||||
|
||||
bool hard_disk_set_block_size(hard_disk_file *file, uint32_t blocksize)
|
||||
bool hard_disk_file::set_block_size(uint32_t blocksize)
|
||||
{
|
||||
if (file->chd)
|
||||
if (chd)
|
||||
{
|
||||
// if the CHD block size matches our block size, we're OK.
|
||||
if (file->chd->unit_bytes() == blocksize)
|
||||
if (chd->unit_bytes() == blocksize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -266,7 +186,7 @@ bool hard_disk_set_block_size(hard_disk_file *file, uint32_t blocksize)
|
||||
}
|
||||
else
|
||||
{
|
||||
file->info.sectorbytes = blocksize;
|
||||
hdinfo.sectorbytes = blocksize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,38 +19,35 @@
|
||||
#include "osdcore.h"
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
TYPE DEFINITIONS
|
||||
***************************************************************************/
|
||||
class hard_disk_file {
|
||||
public:
|
||||
struct info
|
||||
{
|
||||
uint32_t cylinders;
|
||||
uint32_t heads;
|
||||
uint32_t sectors;
|
||||
uint32_t sectorbytes;
|
||||
uint32_t fileoffset; // offset in the file where the HDD image starts. not valid for CHDs.
|
||||
};
|
||||
|
||||
struct hard_disk_file;
|
||||
|
||||
struct hard_disk_info
|
||||
{
|
||||
uint32_t cylinders;
|
||||
uint32_t heads;
|
||||
uint32_t sectors;
|
||||
uint32_t sectorbytes;
|
||||
uint32_t fileoffset; // offset in the file where the HDD image starts. not valid for CHDs.
|
||||
hard_disk_file(chd_file *chd);
|
||||
hard_disk_file(util::random_read_write &corefile, uint32_t skipoffs);
|
||||
|
||||
~hard_disk_file();
|
||||
|
||||
chd_file *get_chd() const { return chd; }
|
||||
const info &get_info() const { return hdinfo; }
|
||||
|
||||
bool set_block_size(uint32_t blocksize);
|
||||
|
||||
bool read(uint32_t lbasector, void *buffer);
|
||||
bool write(uint32_t lbasector, const void *buffer);
|
||||
|
||||
private:
|
||||
chd_file * chd; // CHD file
|
||||
util::random_read_write * fhandle; // file if not a CHD
|
||||
info hdinfo; // hard disk info
|
||||
};
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
FUNCTION PROTOTYPES
|
||||
***************************************************************************/
|
||||
|
||||
hard_disk_file *hard_disk_open(chd_file *chd);
|
||||
hard_disk_file *hard_disk_open(util::random_read_write &corefile, uint32_t skipoffs);
|
||||
|
||||
void hard_disk_close(hard_disk_file *file);
|
||||
|
||||
chd_file *hard_disk_get_chd(hard_disk_file *file);
|
||||
hard_disk_info *hard_disk_get_info(hard_disk_file *file);
|
||||
|
||||
bool hard_disk_set_block_size(hard_disk_file *file, uint32_t blocksize);
|
||||
|
||||
bool hard_disk_read(hard_disk_file *file, uint32_t lbasector, void *buffer);
|
||||
bool hard_disk_write(hard_disk_file *file, uint32_t lbasector, const void *buffer);
|
||||
|
||||
#endif // MAME_LIB_UTIL_HARDDISK_H
|
||||
|
@ -105,7 +105,7 @@ private:
|
||||
int m_secoff;
|
||||
u8 m_cmd, m_stat;
|
||||
bool m_cylhi, m_sechi;
|
||||
const struct hard_disk_info* m_geom;
|
||||
const struct hard_disk_file::info* m_geom;
|
||||
u8 m_sector[512];
|
||||
};
|
||||
|
||||
@ -136,7 +136,7 @@ void altos8600_state::machine_start()
|
||||
save_item(NAME(m_sector));
|
||||
|
||||
if(m_hdd->get_hard_disk_file())
|
||||
m_geom = hard_disk_get_info(m_hdd->get_hard_disk_file());
|
||||
m_geom = &m_hdd->get_hard_disk_file()->get_info();
|
||||
else
|
||||
m_geom = nullptr;
|
||||
}
|
||||
@ -152,7 +152,7 @@ void altos8600_state::machine_reset()
|
||||
m_cylhi = m_sechi = false;
|
||||
m_stat = 0;
|
||||
if(m_hdd->get_hard_disk_file())
|
||||
m_geom = hard_disk_get_info(m_hdd->get_hard_disk_file());
|
||||
m_geom = &m_hdd->get_hard_disk_file()->get_info();
|
||||
else
|
||||
m_geom = nullptr;
|
||||
}
|
||||
@ -198,7 +198,7 @@ u8 altos8600_state::read_sector()
|
||||
secoff -= 3;
|
||||
}
|
||||
if(!secoff)
|
||||
hard_disk_read(m_hdd->get_hard_disk_file(), m_lba, m_sector);
|
||||
m_hdd->get_hard_disk_file()->read(m_lba, m_sector);
|
||||
if(secoff >= 511)
|
||||
{
|
||||
m_dmac->drq1_w(CLEAR_LINE);
|
||||
@ -220,7 +220,7 @@ bool altos8600_state::write_sector(u8 data)
|
||||
{
|
||||
m_stat &= ~1;
|
||||
m_stat |= 2;
|
||||
hard_disk_write(m_hdd->get_hard_disk_file(), m_lba, m_sector);
|
||||
m_hdd->get_hard_disk_file()->write(m_lba, m_sector);
|
||||
m_dmac->drq1_w(CLEAR_LINE);
|
||||
m_pic[1]->ir0_w(ASSERT_LINE);
|
||||
return true;
|
||||
|
@ -202,14 +202,14 @@ void ceres1_state::wfc_command(u8 command)
|
||||
LOG("read sector drive %d chs %d,%d,%d count %d\n",
|
||||
(m_wfc_sdh >> 3) & 3, m_wfc_cylinder & 0x3ff, (m_wfc_sdh >> 0) & 7, m_wfc_sector, m_wfc_count);
|
||||
if (hdf)
|
||||
hard_disk_read(hdf, get_lbasector(hdf), m_wfc_sram);
|
||||
hdf->read(get_lbasector(hdf), m_wfc_sram);
|
||||
m_wfc_offset = 0;
|
||||
break;
|
||||
case 3:
|
||||
LOG("write sector drive %d chs %d,%d,%d count %d\n",
|
||||
(m_wfc_sdh >> 3) & 3, m_wfc_cylinder & 0x3ff, (m_wfc_sdh >> 0) & 7, m_wfc_sector, m_wfc_count);
|
||||
if (hdf)
|
||||
hard_disk_write(hdf, get_lbasector(hdf), m_wfc_sram);
|
||||
hdf->write(get_lbasector(hdf), m_wfc_sram);
|
||||
m_wfc_offset = 0;
|
||||
break;
|
||||
case 4:
|
||||
@ -229,12 +229,12 @@ void ceres1_state::wfc_command(u8 command)
|
||||
|
||||
int ceres1_state::get_lbasector(hard_disk_file *hdf)
|
||||
{
|
||||
hard_disk_info const *info = hard_disk_get_info(hdf);
|
||||
const auto &info = hdf->get_info();
|
||||
|
||||
int lbasector = m_wfc_cylinder & 0x3ff;
|
||||
lbasector *= info->heads;
|
||||
lbasector *= info.heads;
|
||||
lbasector += (m_wfc_sdh >> 0) & 7;
|
||||
lbasector *= info->sectors;
|
||||
lbasector *= info.sectors;
|
||||
lbasector += m_wfc_sector;
|
||||
|
||||
return lbasector;
|
||||
|
@ -1199,20 +1199,17 @@ void rainbow_base_state::machine_reset()
|
||||
|
||||
if (local_hard_disk)
|
||||
{
|
||||
hard_disk_info *info;
|
||||
if ((info = hard_disk_get_info(local_hard_disk)))
|
||||
{
|
||||
m_leds[0] = 1;
|
||||
const auto &info = local_hard_disk->get_info();
|
||||
m_leds[0] = 1;
|
||||
|
||||
uint32_t max_sector = (info->cylinders) * (info->heads) * (info->sectors);
|
||||
popmessage("DEC %u (%3.2f) MB HARD DISK MOUNTED.\nGEOMETRY: %d HEADS (1..%d ARE OK).\n%d CYLINDERS (151 to %d ARE OK).\n%d SECTORS / TRACK (up to %d ARE OK). \n%d BYTES / SECTOR (128 to 1024 ARE OK).\n",
|
||||
max_sector * info->sectorbytes / 1000000,
|
||||
(float)max_sector * (float)info->sectorbytes / 1048576.0f,
|
||||
info->heads, RD51_MAX_HEAD,
|
||||
info->cylinders, RD51_MAX_CYLINDER,
|
||||
info->sectors, RD51_SECTORS_PER_TRACK,
|
||||
info->sectorbytes);
|
||||
}
|
||||
uint32_t max_sector = (info.cylinders) * (info.heads) * (info.sectors);
|
||||
popmessage("DEC %u (%3.2f) MB HARD DISK MOUNTED.\nGEOMETRY: %d HEADS (1..%d ARE OK).\n%d CYLINDERS (151 to %d ARE OK).\n%d SECTORS / TRACK (up to %d ARE OK). \n%d BYTES / SECTOR (128 to 1024 ARE OK).\n",
|
||||
max_sector * info.sectorbytes / 1000000,
|
||||
(float)max_sector * (float)info.sectorbytes / 1048576.0f,
|
||||
info.heads, RD51_MAX_HEAD,
|
||||
info.cylinders, RD51_MAX_CYLINDER,
|
||||
info.sectors, RD51_SECTORS_PER_TRACK,
|
||||
info.sectorbytes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1693,42 +1690,39 @@ hard_disk_file *rainbow_base_state::rainbow_hdc_file(int drv)
|
||||
return nullptr;
|
||||
|
||||
hard_disk_file *file = img->get_hard_disk_file();
|
||||
hard_disk_info *info = hard_disk_get_info(file);
|
||||
const auto &info = file->get_info();
|
||||
|
||||
// MFM ALLOWS UP TO 17 SECTORS / TRACK.
|
||||
// CYLINDERS: 151 (~ 5 MB) to 1024 (max. cylinders on WD1010 controller)
|
||||
if (((info->sectors <= RD51_SECTORS_PER_TRACK)) &&
|
||||
((info->heads >= 1) && (info->heads <= RD51_MAX_HEAD)) && // HEADS WITHIN 1...8
|
||||
((info->cylinders > 150) && (info->cylinders <= RD51_MAX_CYLINDER)))
|
||||
if (((info.sectors <= RD51_SECTORS_PER_TRACK)) &&
|
||||
((info.heads >= 1) && (info.heads <= RD51_MAX_HEAD)) && // HEADS WITHIN 1...8
|
||||
((info.cylinders > 150) && (info.cylinders <= RD51_MAX_CYLINDER)))
|
||||
{
|
||||
m_hdc_drive_ready = true;
|
||||
return file; // HAS SANE GEOMETRY
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t max_sector = info->cylinders * info->heads * info->sectors;
|
||||
uint32_t max_sector = info.cylinders * info.heads * info.sectors;
|
||||
popmessage("DEC %u (%3.2f) MB HARD DISK REJECTED.\nGEOMETRY: %d HEADS (1..%d ARE OK).\n%d CYLINDERS (151 to %d ARE OK).\n%d SECTORS / TRACK (up to %d ARE OK). \n%d BYTES / SECTOR (128 to 1024 ARE OK).\n",
|
||||
max_sector * info->sectorbytes / 1000000,
|
||||
(float)max_sector * (float)info->sectorbytes / 1048576.0f,
|
||||
info->heads, RD51_MAX_HEAD,
|
||||
info->cylinders, RD51_MAX_CYLINDER,
|
||||
info->sectors, RD51_SECTORS_PER_TRACK,
|
||||
info->sectorbytes);
|
||||
max_sector * info.sectorbytes / 1000000,
|
||||
(float)max_sector * (float)info.sectorbytes / 1048576.0f,
|
||||
info.heads, RD51_MAX_HEAD,
|
||||
info.cylinders, RD51_MAX_CYLINDER,
|
||||
info.sectors, RD51_SECTORS_PER_TRACK,
|
||||
info.sectorbytes);
|
||||
logerror("<<< === HARD DISK IMAGE REJECTED = (invalid geometry) === >>>\n");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// LBA sector from CHS
|
||||
static uint32_t get_and_print_lbasector(device_t *device, hard_disk_info *info, uint16_t cylinder, uint8_t head, uint8_t sector_number)
|
||||
static uint32_t get_and_print_lbasector(device_t *device, const hard_disk_file::info &info, uint16_t cylinder, uint8_t head, uint8_t sector_number)
|
||||
{
|
||||
if (info == nullptr)
|
||||
return 0;
|
||||
|
||||
// LBA_ADDRESS = (C * HEADS + H) * NUMBER_SECTORS + (S - 1)
|
||||
uint32_t lbasector = (double)cylinder * info->heads; // LBA : ( x 4 )
|
||||
uint32_t lbasector = (double)cylinder * info.heads; // LBA : ( x 4 )
|
||||
lbasector += head;
|
||||
lbasector *= info->sectors; // LBA : ( x 16 )
|
||||
lbasector *= info.sectors; // LBA : ( x 16 )
|
||||
lbasector += (sector_number - 1); // + (sector number - 1)
|
||||
|
||||
// device->logerror(" CYLINDER %u - HEAD %u - SECTOR NUMBER %u (LBA-SECTOR %u) ", cylinder, head, sector_number, lbasector);
|
||||
@ -1756,30 +1750,26 @@ WRITE_LINE_MEMBER(rainbow_base_state::hdc_read_sector)
|
||||
uint16_t cylinder = (m_hdc->read(0x04)) | (hi << 8);
|
||||
uint8_t sector_number = m_hdc->read(0x03);
|
||||
|
||||
hard_disk_file *local_hard_disk;
|
||||
local_hard_disk = rainbow_hdc_file(0); // one hard disk for now.
|
||||
hard_disk_file *local_hard_disk = rainbow_hdc_file(0); // one hard disk for now.
|
||||
|
||||
if (local_hard_disk)
|
||||
{
|
||||
read_status = 3;
|
||||
|
||||
hard_disk_info *info;
|
||||
if ((info = hard_disk_get_info(local_hard_disk)))
|
||||
const auto &info = local_hard_disk->get_info();
|
||||
read_status = 4;
|
||||
m_leds[0] = 1;
|
||||
|
||||
// Pointer to info + C + H + S
|
||||
uint32_t lbasector = get_and_print_lbasector(this, info, cylinder, sdh & 0x07, sector_number);
|
||||
|
||||
if ((cylinder <= info.cylinders) && // filter invalid ranges
|
||||
(SECTOR_SIZES[(sdh >> 5) & 0x03] == info.sectorbytes) // may not vary in image!
|
||||
)
|
||||
{
|
||||
read_status = 4;
|
||||
m_leds[0] = 1;
|
||||
|
||||
// Pointer to info + C + H + S
|
||||
uint32_t lbasector = get_and_print_lbasector(this, info, cylinder, sdh & 0x07, sector_number);
|
||||
|
||||
if ((cylinder <= info->cylinders) && // filter invalid ranges
|
||||
(SECTOR_SIZES[(sdh >> 5) & 0x03] == info->sectorbytes) // may not vary in image!
|
||||
)
|
||||
{
|
||||
read_status = 5;
|
||||
if (hard_disk_read(local_hard_disk, lbasector, m_hdc_buffer)) // accepts LBA sector (uint32_t) !
|
||||
read_status = 0; // logerror("...success!\n");
|
||||
}
|
||||
read_status = 5;
|
||||
if (local_hard_disk->read(lbasector, m_hdc_buffer)) // accepts LBA sector (uint32_t) !
|
||||
read_status = 0; // logerror("...success!\n");
|
||||
}
|
||||
m_hdc_buf_offset = 0;
|
||||
m_hdc->buffer_ready(true);
|
||||
@ -1862,40 +1852,37 @@ int rainbow_base_state::do_write_sector()
|
||||
|
||||
if (local_hard_disk)
|
||||
{
|
||||
hard_disk_info *info = hard_disk_get_info(local_hard_disk);
|
||||
if (info)
|
||||
const auto &info = local_hard_disk->get_info();
|
||||
feedback = 10;
|
||||
m_leds[0] = 1; // OFF
|
||||
|
||||
uint8_t sdh = (m_hdc->read(0x06));
|
||||
|
||||
int hi = (m_hdc->read(0x05)) & 0x07;
|
||||
uint16_t cylinder = (m_hdc->read(0x04)) | (hi << 8);
|
||||
|
||||
int sector_number = m_hdc->read(0x03);
|
||||
int sector_count = m_hdc->read(0x02); // (1 = single sector)
|
||||
|
||||
if (!(cylinder <= info.cylinders && // filter invalid cylinders
|
||||
SECTOR_SIZES[(sdh >> 5) & 0x03] == info.sectorbytes // 512, may not vary
|
||||
))
|
||||
{
|
||||
feedback = 10;
|
||||
m_leds[0] = 1; // OFF
|
||||
logerror("...*** SANITY CHECK FAILED (CYLINDER %u vs. info.cylinders %u - - SECTOR_SIZE %u vs. info.sectorbytes %u) ***\n",
|
||||
cylinder, info.cylinders, SECTOR_SIZES[(sdh >> 5) & 0x03], info.sectorbytes);
|
||||
return 50;
|
||||
}
|
||||
// Pointer to info + C + H + S
|
||||
uint32_t lbasector = get_and_print_lbasector(this, info, cylinder, sdh & 0x07, sector_number);
|
||||
|
||||
uint8_t sdh = (m_hdc->read(0x06));
|
||||
if (sector_count != 1) // ignore all SECTOR_COUNTS != 1
|
||||
return 88; // logerror(" - ** IGNORED (SECTOR_COUNT !=1) **\n");
|
||||
|
||||
int hi = (m_hdc->read(0x05)) & 0x07;
|
||||
uint16_t cylinder = (m_hdc->read(0x04)) | (hi << 8);
|
||||
if (local_hard_disk->write(lbasector, m_hdc_buffer)) // accepts LBA sector (uint32_t) !
|
||||
feedback = 99; // success
|
||||
else
|
||||
logerror("...FAILURE **** \n");
|
||||
|
||||
int sector_number = m_hdc->read(0x03);
|
||||
int sector_count = m_hdc->read(0x02); // (1 = single sector)
|
||||
|
||||
if (!(cylinder <= info->cylinders && // filter invalid cylinders
|
||||
SECTOR_SIZES[(sdh >> 5) & 0x03] == info->sectorbytes // 512, may not vary
|
||||
))
|
||||
{
|
||||
logerror("...*** SANITY CHECK FAILED (CYLINDER %u vs. info->cylinders %u - - SECTOR_SIZE %u vs. info->sectorbytes %u) ***\n",
|
||||
cylinder, info->cylinders, SECTOR_SIZES[(sdh >> 5) & 0x03], info->sectorbytes);
|
||||
return 50;
|
||||
}
|
||||
// Pointer to info + C + H + S
|
||||
uint32_t lbasector = get_and_print_lbasector(this, info, cylinder, sdh & 0x07, sector_number);
|
||||
|
||||
if (sector_count != 1) // ignore all SECTOR_COUNTS != 1
|
||||
return 88; // logerror(" - ** IGNORED (SECTOR_COUNT !=1) **\n");
|
||||
|
||||
if (hard_disk_write(local_hard_disk, lbasector, m_hdc_buffer)) // accepts LBA sector (uint32_t) !
|
||||
feedback = 99; // success
|
||||
else
|
||||
logerror("...FAILURE **** \n");
|
||||
|
||||
} // IF 'info' not nullptr
|
||||
} // IF hard disk present
|
||||
return feedback;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ uint16_t isbc_215g_device::read_sector()
|
||||
uint16_t wps = 64 << ((m_idcompare[0] >> 4) & 3);
|
||||
harddisk_image_device *drive = (m_drive ? m_hdd1 : m_hdd0);
|
||||
if(!m_secoffset)
|
||||
hard_disk_read(drive->get_hard_disk_file(), m_lba[m_drive], m_sector);
|
||||
drive->get_hard_disk_file()->read(m_lba[m_drive], m_sector);
|
||||
if(m_secoffset >= wps)
|
||||
return 0;
|
||||
return m_sector[m_secoffset++];
|
||||
@ -79,7 +79,7 @@ bool isbc_215g_device::write_sector(uint16_t data)
|
||||
m_sector[m_secoffset++] = data;
|
||||
if(m_secoffset == wps)
|
||||
{
|
||||
hard_disk_write(drive->get_hard_disk_file(), m_lba[m_drive], m_sector);
|
||||
drive->get_hard_disk_file()->write(m_lba[m_drive], m_sector);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -387,11 +387,11 @@ const tiny_rom_entry *isbc_215g_device::device_rom_region() const
|
||||
void isbc_215g_device::device_reset()
|
||||
{
|
||||
if(m_hdd0->get_hard_disk_file())
|
||||
m_geom[0] = hard_disk_get_info(m_hdd0->get_hard_disk_file());
|
||||
m_geom[0] = &m_hdd0->get_hard_disk_file()->get_info();
|
||||
else
|
||||
m_geom[0] = nullptr;
|
||||
if(m_hdd1->get_hard_disk_file())
|
||||
m_geom[1] = hard_disk_get_info(m_hdd1->get_hard_disk_file());
|
||||
m_geom[1] = &m_hdd1->get_hard_disk_file()->get_info();
|
||||
else
|
||||
m_geom[1] = nullptr;
|
||||
|
||||
|
@ -76,7 +76,7 @@ private:
|
||||
bool m_step;
|
||||
bool m_format;
|
||||
|
||||
const struct hard_disk_info* m_geom[2];
|
||||
const struct hard_disk_file::info* m_geom[2];
|
||||
|
||||
DECLARE_WRITE_LINE_MEMBER(isbx_irq_00_w);
|
||||
DECLARE_WRITE_LINE_MEMBER(isbx_irq_01_w);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "formats/fsmgr.h"
|
||||
#include "harddisk.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
@ -120,7 +120,7 @@ imgtoolerr_t imghd_open(imgtool::stream &stream, struct mess_hard_disk_file *har
|
||||
goto done;
|
||||
}
|
||||
|
||||
hard_disk->hard_disk = hard_disk_open(&hard_disk->chd);
|
||||
hard_disk->hard_disk = new hard_disk_file(&hard_disk->chd);
|
||||
if (!hard_disk->hard_disk)
|
||||
{
|
||||
err = IMGTOOLERR_UNEXPECTED;
|
||||
@ -145,7 +145,7 @@ void imghd_close(struct mess_hard_disk_file *disk)
|
||||
{
|
||||
if (disk->hard_disk)
|
||||
{
|
||||
hard_disk_close(disk->hard_disk);
|
||||
delete disk->hard_disk;
|
||||
disk->hard_disk = nullptr;
|
||||
}
|
||||
if (disk->stream)
|
||||
@ -164,7 +164,7 @@ void imghd_close(struct mess_hard_disk_file *disk)
|
||||
*/
|
||||
imgtoolerr_t imghd_read(struct mess_hard_disk_file *disk, uint32_t lbasector, void *buffer)
|
||||
{
|
||||
uint32_t reply = hard_disk_read(disk->hard_disk, lbasector, buffer);
|
||||
uint32_t reply = disk->hard_disk->read(lbasector, buffer);
|
||||
return reply ? IMGTOOLERR_SUCCESS : IMGTOOLERR_READERROR;
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ imgtoolerr_t imghd_read(struct mess_hard_disk_file *disk, uint32_t lbasector, vo
|
||||
*/
|
||||
imgtoolerr_t imghd_write(struct mess_hard_disk_file *disk, uint32_t lbasector, const void *buffer)
|
||||
{
|
||||
uint32_t reply = hard_disk_write(disk->hard_disk, lbasector, buffer);
|
||||
uint32_t reply = disk->hard_disk->write(lbasector, buffer);
|
||||
return reply ? IMGTOOLERR_SUCCESS : IMGTOOLERR_WRITEERROR;
|
||||
}
|
||||
|
||||
@ -188,11 +188,9 @@ imgtoolerr_t imghd_write(struct mess_hard_disk_file *disk, uint32_t lbasector, c
|
||||
|
||||
Return pointer to the header of MAME HD image
|
||||
*/
|
||||
const hard_disk_info *imghd_get_header(struct mess_hard_disk_file *disk)
|
||||
const hard_disk_file::info &imghd_get_header(struct mess_hard_disk_file *disk)
|
||||
{
|
||||
const hard_disk_info *reply;
|
||||
reply = hard_disk_get_info(disk->hard_disk);
|
||||
return reply;
|
||||
return disk->hard_disk->get_info();
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,6 +45,6 @@ imgtoolerr_t imghd_read(struct mess_hard_disk_file *disk, uint32_t lbasector, vo
|
||||
imgtoolerr_t imghd_write(struct mess_hard_disk_file *disk, uint32_t lbasector, const void *buffer);
|
||||
|
||||
/* gets the header from a hard disk */
|
||||
const hard_disk_info *imghd_get_header(struct mess_hard_disk_file *disk);
|
||||
const hard_disk_file::info &imghd_get_header(struct mess_hard_disk_file *disk);
|
||||
|
||||
#endif /* IMGHD_H */
|
||||
|
@ -105,15 +105,12 @@ static pc_chd_image_info *pc_chd_get_image_info(imgtool::image &image)
|
||||
|
||||
static void pc_chd_locate_block(imgtool::image &image, uint64_t block, uint32_t *cylinder, uint32_t *head, uint32_t *sector)
|
||||
{
|
||||
pc_chd_image_info *info;
|
||||
const hard_disk_info *hd_info;
|
||||
pc_chd_image_info *info = pc_chd_get_image_info(image);
|
||||
const auto &hd_info = imghd_get_header(&info->hard_disk);
|
||||
|
||||
info = pc_chd_get_image_info(image);
|
||||
hd_info = imghd_get_header(&info->hard_disk);
|
||||
|
||||
*sector = block % hd_info->sectors;
|
||||
*head = (block / hd_info->sectors) % hd_info->heads;
|
||||
*cylinder = block / hd_info->sectors / hd_info->heads;
|
||||
*sector = block % hd_info.sectors;
|
||||
*head = (block / hd_info.sectors) % hd_info.heads;
|
||||
*cylinder = block / hd_info.sectors / hd_info.heads;
|
||||
}
|
||||
|
||||
|
||||
@ -311,15 +308,12 @@ static void pc_chd_image_close(imgtool::image &image)
|
||||
|
||||
static imgtoolerr_t pc_chd_image_get_geometry(imgtool::image &image, uint32_t *tracks, uint32_t *heads, uint32_t *sectors)
|
||||
{
|
||||
pc_chd_image_info *info;
|
||||
const hard_disk_info *hd_info;
|
||||
pc_chd_image_info *info = pc_chd_get_image_info(image);
|
||||
const auto &hd_info = imghd_get_header(&info->hard_disk);
|
||||
|
||||
info = pc_chd_get_image_info(image);
|
||||
hd_info = imghd_get_header(&info->hard_disk);
|
||||
|
||||
*tracks = hd_info->cylinders;
|
||||
*heads = hd_info->heads;
|
||||
*sectors = hd_info->sectors;
|
||||
*tracks = hd_info.cylinders;
|
||||
*heads = hd_info.heads;
|
||||
*sectors = hd_info.sectors;
|
||||
return IMGTOOLERR_SUCCESS;
|
||||
}
|
||||
|
||||
@ -328,13 +322,11 @@ static imgtoolerr_t pc_chd_image_get_geometry(imgtool::image &image, uint32_t *t
|
||||
static uint32_t pc_chd_calc_lbasector(pc_chd_image_info &info, uint32_t track, uint32_t head, uint32_t sector)
|
||||
{
|
||||
uint32_t lbasector;
|
||||
const hard_disk_info *hd_info;
|
||||
|
||||
hd_info = imghd_get_header(&info.hard_disk);
|
||||
const auto &hd_info = imghd_get_header(&info.hard_disk);
|
||||
lbasector = track;
|
||||
lbasector *= hd_info->heads;
|
||||
lbasector *= hd_info.heads;
|
||||
lbasector += head;
|
||||
lbasector *= hd_info->sectors;
|
||||
lbasector *= hd_info.sectors;
|
||||
lbasector += sector;
|
||||
return lbasector;
|
||||
}
|
||||
@ -346,7 +338,7 @@ static imgtoolerr_t pc_chd_image_readsector(imgtool::image &image, uint32_t trac
|
||||
pc_chd_image_info *info = pc_chd_get_image_info(image);
|
||||
|
||||
// get the sector size and resize the buffer
|
||||
uint32_t sector_size = imghd_get_header(&info->hard_disk)->sectorbytes;
|
||||
uint32_t sector_size = imghd_get_header(&info->hard_disk).sectorbytes;
|
||||
try { buffer.resize(sector_size); }
|
||||
catch (std::bad_alloc const &) { return IMGTOOLERR_OUTOFMEMORY; }
|
||||
|
||||
|
@ -979,17 +979,15 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream::ptr &&file_handle, ti99_img
|
||||
|
||||
if (img_format == if_harddisk)
|
||||
{
|
||||
const hard_disk_info *info;
|
||||
|
||||
err = imghd_open(*file_handle, &l1_img->harddisk_handle);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
info = imghd_get_header(&l1_img->harddisk_handle);
|
||||
l1_img->geometry.cylinders = info->cylinders;
|
||||
l1_img->geometry.heads = info->heads;
|
||||
l1_img->geometry.secspertrack = info->sectors;
|
||||
if (info->sectorbytes != 256)
|
||||
const auto &info = imghd_get_header(&l1_img->harddisk_handle);
|
||||
l1_img->geometry.cylinders = info.cylinders;
|
||||
l1_img->geometry.heads = info.heads;
|
||||
l1_img->geometry.secspertrack = info.sectors;
|
||||
if (info.sectorbytes != 256)
|
||||
{
|
||||
imghd_close(&l1_img->harddisk_handle);
|
||||
return IMGTOOLERR_CORRUPTIMAGE; /* TODO: support 512-byte sectors */
|
||||
|
Loading…
Reference in New Issue
Block a user