2022-09-02 05:10:52 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-12-04 21:41:01 +00:00
|
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
2022-09-02 05:10:52 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-10-22 21:41:19 +00:00
|
|
|
/** @file SCSI hard drive definitions. */
|
2022-09-02 05:10:52 +00:00
|
|
|
|
|
|
|
#ifndef SCSI_HD_H
|
|
|
|
#define SCSI_HD_H
|
|
|
|
|
|
|
|
#include <devices/common/scsi/scsi.h>
|
2023-09-16 21:17:27 +00:00
|
|
|
#include <utils/imgfile.h>
|
2022-11-10 17:22:44 +00:00
|
|
|
|
2022-09-02 05:10:52 +00:00
|
|
|
#include <cinttypes>
|
2022-11-10 17:22:44 +00:00
|
|
|
#include <memory>
|
2022-09-02 05:10:52 +00:00
|
|
|
#include <string>
|
|
|
|
|
2022-10-22 18:41:52 +00:00
|
|
|
class ScsiHardDisk : public ScsiDevice {
|
2022-09-02 05:10:52 +00:00
|
|
|
public:
|
2023-12-04 21:41:01 +00:00
|
|
|
ScsiHardDisk(std::string name, int my_id);
|
2022-10-22 18:41:52 +00:00
|
|
|
~ScsiHardDisk() = default;
|
2022-09-02 05:10:52 +00:00
|
|
|
|
2022-10-30 22:38:09 +00:00
|
|
|
static std::unique_ptr<HWComponent> create() {
|
2023-12-04 21:41:01 +00:00
|
|
|
return std::unique_ptr<ScsiHardDisk>(new ScsiHardDisk("SCSI_HD", 0));
|
2022-10-30 22:38:09 +00:00
|
|
|
}
|
2022-11-02 20:27:18 +00:00
|
|
|
|
2022-10-30 22:38:09 +00:00
|
|
|
void insert_image(std::string filename);
|
2022-10-27 12:07:20 +00:00
|
|
|
void process_command();
|
2022-11-02 20:27:18 +00:00
|
|
|
bool prepare_data();
|
2023-12-08 10:05:03 +00:00
|
|
|
bool get_more_data() { return false; };
|
2022-09-02 05:10:52 +00:00
|
|
|
|
2022-11-10 17:22:44 +00:00
|
|
|
protected:
|
2023-11-09 11:30:07 +00:00
|
|
|
int test_unit_ready();
|
|
|
|
int req_sense(uint16_t alloc_len);
|
|
|
|
int send_diagnostic();
|
|
|
|
void mode_select_6(uint8_t param_len);
|
2022-10-22 18:41:52 +00:00
|
|
|
|
2023-08-02 14:53:19 +00:00
|
|
|
void mode_sense_6();
|
2022-09-02 05:10:52 +00:00
|
|
|
void format();
|
2023-08-02 14:53:19 +00:00
|
|
|
void inquiry();
|
2022-10-23 23:45:58 +00:00
|
|
|
void read_capacity_10();
|
2022-10-26 16:18:32 +00:00
|
|
|
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
|
|
|
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
2022-09-02 05:10:52 +00:00
|
|
|
void seek(uint32_t lba);
|
|
|
|
void rewind();
|
2023-11-01 15:18:48 +00:00
|
|
|
void read_buffer();
|
2022-09-02 05:10:52 +00:00
|
|
|
|
2022-10-31 22:17:08 +00:00
|
|
|
private:
|
2023-10-31 09:49:23 +00:00
|
|
|
ImgFile disk_img;
|
2022-11-10 17:22:44 +00:00
|
|
|
uint64_t img_size;
|
2022-12-14 15:14:37 +00:00
|
|
|
int total_blocks;
|
2022-11-10 17:22:44 +00:00
|
|
|
uint64_t file_offset = 0;
|
2023-08-02 14:53:19 +00:00
|
|
|
int bytes_out = 0;
|
2022-11-10 17:22:44 +00:00
|
|
|
|
2024-03-10 05:17:20 +00:00
|
|
|
uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
|
2022-11-10 17:22:44 +00:00
|
|
|
|
2023-11-09 11:30:07 +00:00
|
|
|
uint32_t cur_buf_cnt = 0;
|
|
|
|
uint8_t error = ScsiError::NO_ERROR;
|
|
|
|
uint8_t msg_code = 0;
|
2022-10-31 22:17:08 +00:00
|
|
|
|
2022-10-22 18:41:52 +00:00
|
|
|
//inquiry info
|
|
|
|
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
|
|
|
|
char prod_info[16] = {'E', 'm', 'u', 'l', 'a', 't', 'e', 'd', ' ', 'D', 'i', 's', 'k', '\0'};
|
2023-08-02 14:53:19 +00:00
|
|
|
char rev_info[4] = {'d', 'i', '0', '1'};
|
2022-10-08 23:51:54 +00:00
|
|
|
};
|
2022-09-02 05:10:52 +00:00
|
|
|
|
2022-11-10 17:22:44 +00:00
|
|
|
#endif // SCSI_HD_H
|