atahd: cosmetic improvements.

This commit is contained in:
Maxim Poliakovski 2023-04-17 09:56:03 +02:00
parent a7f4d418fc
commit ed48766e5f
2 changed files with 62 additions and 64 deletions

View File

@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@ -52,14 +52,13 @@ int AtaHardDisk::perform_command()
{ {
LOG_F(INFO, "%s: command 0x%x requested", this->name.c_str(), this->r_command); LOG_F(INFO, "%s: command 0x%x requested", this->name.c_str(), this->r_command);
this->r_status |= BSY; this->r_status |= BSY;
this->r_status &= ~(DRDY); this->r_status &= ~DRDY;
switch (this->r_command) { switch (this->r_command) {
case NOP: case NOP:
break; break;
case RESET_ATAPI: { case RESET_ATAPI:
device_reset(); device_reset();
break; break;
}
case RECALIBRATE: case RECALIBRATE:
hdd_img.seekg(0, std::ios::beg); hdd_img.seekg(0, std::ios::beg);
this->r_error = 0; this->r_error = 0;
@ -72,46 +71,45 @@ int AtaHardDisk::perform_command()
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count; uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
uint32_t sector = (r_sect_num << 16); uint32_t sector = (r_sect_num << 16);
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi); sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
uint64_t offset = sector * 512; uint64_t offset = sector * ATA_HD_SEC_SIZE;
hdd_img.seekg(offset, std::ios::beg); hdd_img.seekg(offset, std::ios::beg);
hdd_img.read(buffer, sec_count * 512); hdd_img.read(buffer, sec_count * ATA_HD_SEC_SIZE);
this->r_status &= ~(DRQ); this->r_status &= ~DRQ;
break;
} }
break;
case WRITE_SECTOR: case WRITE_SECTOR:
case WRITE_SECTOR_NR: { case WRITE_SECTOR_NR: {
this->r_status |= DRQ; this->r_status |= DRQ;
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count; uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
uint32_t sector = (r_sect_num << 16); uint32_t sector = (r_sect_num << 16);
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi); sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
uint64_t offset = sector * 512; uint64_t offset = sector * ATA_HD_SEC_SIZE;
hdd_img.seekg(offset, std::ios::beg); hdd_img.seekg(offset, std::ios::beg);
hdd_img.write(buffer, sec_count * 512); hdd_img.write(buffer, sec_count * ATA_HD_SEC_SIZE);
this->r_status &= ~(DRQ); this->r_status &= ~DRQ;
break;
} }
break;
case INIT_DEV_PARAM: case INIT_DEV_PARAM:
break; break;
case DIAGNOSTICS: { case DIAGNOSTICS: {
this->r_status |= DRQ; this->r_status |= DRQ;
int ret_code = this->r_error; int ret_code = this->r_error;
this->r_status &= ~(DRQ); this->r_status &= ~DRQ;
return ret_code; return ret_code;
break;
} }
case IDENTIFY_DEVICE: { break;
case IDENTIFY_DEVICE:
this->r_status |= DRQ; this->r_status |= DRQ;
std::memcpy(buffer, ide_hd_id, 512); std::memcpy(buffer, this->hd_id_data, ATA_HD_SEC_SIZE);
this->r_status &= ~(DRQ); this->r_status &= ~DRQ;
break; break;
}
default: default:
LOG_F(INFO, "Unknown ATA command 0x%x", this->r_command); LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
this->r_status &= ~(BSY); this->r_status &= ~BSY;
this->r_status |= ERR; this->r_status |= ERR;
return -1; return -1;
} }
this->r_status &= ~(BSY); this->r_status &= ~BSY;
this->r_status |= DRDY; this->r_status |= DRDY;
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/** @file TA hard disk definitions. */ /** @file ATA hard disk definitions. */
#ifndef ATA_HARD_DISK_H #ifndef ATA_HARD_DISK_H
#define ATA_HARD_DISK_H #define ATA_HARD_DISK_H
@ -28,6 +28,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string> #include <string>
#include <fstream> #include <fstream>
#define ATA_HD_SEC_SIZE 512
class AtaHardDisk : public AtaBaseDevice class AtaHardDisk : public AtaBaseDevice
{ {
public: public:
@ -42,9 +44,7 @@ private:
uint64_t img_size; uint64_t img_size;
char * buffer = new char[1 <<17]; char * buffer = new char[1 <<17];
char* ide_hd_id = { uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
0x0
};
}; };
#endif // ATA_HARD_DISK_H #endif // ATA_HARD_DISK_H