mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-10 13:29:38 +00:00
scsi_hd: cosmetic improvements.
This commit is contained in:
parent
3de89eaaf7
commit
db17e19699
@ -21,20 +21,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Generic SCSI Hard Disk emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsi_hd.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define sector_size 512
|
||||
#define HDD_SECTOR_SIZE 512
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -137,8 +136,6 @@ void ScsiHardDisk::process_command() {
|
||||
}
|
||||
|
||||
bool ScsiHardDisk::prepare_data() {
|
||||
cur_buf_pos = 0;
|
||||
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
@ -238,11 +235,12 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
|
||||
std::memset(img_buffer, 0, sizeof(img_buffer));
|
||||
|
||||
if (cmd_len == 6)
|
||||
transfer_size = (transfer_len == 0) ? 256 : transfer_len;
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= sector_size;
|
||||
uint64_t device_offset = lba * sector_size;
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
this->hdd_img.read(img_buffer, transfer_size);
|
||||
@ -256,11 +254,12 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
if (cmd_len == 6)
|
||||
transfer_size = (transfer_len == 0) ? 256 : transfer_len;
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= sector_size;
|
||||
uint64_t device_offset = lba * sector_size;
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->incoming_size = transfer_size;
|
||||
|
||||
@ -272,7 +271,7 @@ void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
}
|
||||
|
||||
void ScsiHardDisk::seek(uint32_t lba) {
|
||||
uint64_t device_offset = lba * sector_size;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define SCSI_HD_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
@ -42,8 +44,8 @@ public:
|
||||
void insert_image(std::string filename);
|
||||
void process_command();
|
||||
bool prepare_data();
|
||||
bool send_bytes(uint8_t* dst_ptr, int count);
|
||||
|
||||
protected:
|
||||
int test_unit_ready();
|
||||
int req_sense(uint16_t alloc_len);
|
||||
int send_diagnostic();
|
||||
@ -59,14 +61,12 @@ public:
|
||||
void rewind();
|
||||
|
||||
private:
|
||||
std::string img_path;
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
char img_buffer[1 << 17];
|
||||
uint64_t file_offset = 0;
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
uint64_t file_offset = 0;
|
||||
|
||||
char img_buffer[1 << 17]; // TODO: add proper buffer management!
|
||||
|
||||
// SCSI transfer pointers
|
||||
uint32_t cur_buf_pos = 0;
|
||||
uint32_t cur_buf_cnt = 0;
|
||||
uint8_t error = ScsiError::NO_ERROR;
|
||||
uint8_t msg_code = 0;
|
||||
@ -78,4 +78,4 @@ private:
|
||||
char serial_info[8] = {'0', '0', '0', '0', '0', '0', '0', '0'};
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // SCSI_HD_H
|
||||
|
@ -86,10 +86,9 @@ int initialize_pdm(std::string& id)
|
||||
std::string hd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (!hd_image_path.empty()) {
|
||||
// attach SCSI HD to the main bus, ID #0
|
||||
gMachineObj->add_device("SCSI_HD", std::unique_ptr<ScsiHardDisk>(new ScsiHardDisk(0)));
|
||||
scsi_bus->register_device(0, dynamic_cast<ScsiDevice*>(gMachineObj->get_comp_by_name("SCSI_HD")));
|
||||
auto my_hd = dynamic_cast<ScsiHardDisk*>(gMachineObj->get_comp_by_name("ScsiHD"));
|
||||
scsi_bus->register_device(0, my_hd);
|
||||
// insert specified disk image
|
||||
auto my_hd = dynamic_cast<ScsiHardDisk*>(gMachineObj->get_comp_by_name("SCSI_HD"));
|
||||
my_hd->insert_image(hd_image_path);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user