mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-06-25 23:29:33 +00:00
Properly connect Superdrive to SWIM3 and machines.
This commit is contained in:
parent
b25b526582
commit
5e2f2b12e4
|
@ -26,11 +26,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <stdio.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static FlopImgType identify_image(FILE *img_file)
|
||||
static FlopImgType identify_image(std::ifstream& img_file)
|
||||
{
|
||||
// WOZ images identification strings
|
||||
static uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
|
@ -38,8 +37,8 @@ static FlopImgType identify_image(FILE *img_file)
|
|||
|
||||
uint8_t buf[8] = { 0 };
|
||||
|
||||
fseek(img_file, 0, SEEK_SET);
|
||||
fread(buf, sizeof(buf), 1, img_file);
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
// WOZ files are easily identified
|
||||
if (!std::memcmp(buf, WOZ1_SIG, sizeof(buf))) {
|
||||
|
@ -49,8 +48,8 @@ static FlopImgType identify_image(FILE *img_file)
|
|||
} else {
|
||||
for (int offset = 0; offset <=84; offset += 84) {
|
||||
// rewind to logical block 2
|
||||
fseek(img_file, 2*BLOCK_SIZE + offset, SEEK_SET);
|
||||
fread(buf, sizeof(buf), 1, img_file);
|
||||
img_file.seekg(2*BLOCK_SIZE + offset, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
// check for HFS/MFS signature at the start of the logical block 2
|
||||
if ((buf[0] == 0x42 && buf[1] == 0x44) ||
|
||||
|
@ -67,16 +66,6 @@ static FlopImgType identify_image(FILE *img_file)
|
|||
return FlopImgType::UNKNOWN;
|
||||
}
|
||||
|
||||
static int64_t get_img_file_size(const char *fname)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
|
||||
memset(&stat_buf, 0, sizeof(stat_buf));
|
||||
|
||||
int res = stat(fname, &stat_buf);
|
||||
return res == 0 ? stat_buf.st_size : -1;
|
||||
}
|
||||
|
||||
static int64_t get_hfs_vol_size(const uint8_t *mdb_data)
|
||||
{
|
||||
uint16_t drNmAlBlks = READ_WORD_BE_A(&mdb_data[18]);
|
||||
|
@ -89,7 +78,7 @@ static int64_t get_hfs_vol_size(const uint8_t *mdb_data)
|
|||
}
|
||||
|
||||
//======================= RAW IMAGE CONVERTER ============================
|
||||
RawFloppyImg::RawFloppyImg(const char *file_path) : FloppyImgConverter()
|
||||
RawFloppyImg::RawFloppyImg(std::string& file_path) : FloppyImgConverter()
|
||||
{
|
||||
this->img_path = file_path;
|
||||
}
|
||||
|
@ -100,20 +89,29 @@ RawFloppyImg::RawFloppyImg(const char *file_path) : FloppyImgConverter()
|
|||
*/
|
||||
int RawFloppyImg::validate()
|
||||
{
|
||||
FILE *img_file = fopen(this->img_path, "rb");
|
||||
if (img_file == NULL) {
|
||||
std::ifstream img_file;
|
||||
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine image size
|
||||
this->img_size = get_img_file_size(this->img_path);
|
||||
img_file.seekg(0, img_file.end);
|
||||
this->img_size = img_file.tellg();
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
// verify image size
|
||||
if (this->img_size < 5*BLOCK_SIZE) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: image too short!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this->img_size > MFM_HD_SIZE) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: image too big!");
|
||||
return -1;
|
||||
}
|
||||
|
@ -121,9 +119,9 @@ int RawFloppyImg::validate()
|
|||
// read Master Directory Block from logical block 2
|
||||
uint8_t buf[512] = { 0 };
|
||||
|
||||
fseek(img_file, 2*BLOCK_SIZE, SEEK_SET);
|
||||
fread(buf, sizeof(buf), 1, img_file);
|
||||
fclose(img_file);
|
||||
img_file.seekg(2*BLOCK_SIZE, img_file.beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
img_file.close();
|
||||
|
||||
uint64_t vol_size = 0;
|
||||
|
||||
|
@ -139,7 +137,7 @@ int RawFloppyImg::validate()
|
|||
|
||||
if (vol_size > this->img_size) {
|
||||
LOG_F(INFO, "RawFloppyImg: volume size > image size!");
|
||||
LOG_F(INFO, "Volume size: %llu, Image size: %llu", vol_size, this->img_size);
|
||||
LOG_F(INFO, "Volume size: %llu, Image size: %d", vol_size, this->img_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -168,19 +166,22 @@ int RawFloppyImg::export_data()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int open_floppy_image(const char* img_path)
|
||||
int open_floppy_image(std::string& img_path)
|
||||
{
|
||||
FloppyImgConverter *fconv;
|
||||
|
||||
FILE *img_file = fopen(img_path, "rb");
|
||||
if (img_file == NULL) {
|
||||
std::ifstream img_file;
|
||||
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FlopImgType itype = identify_image(img_file);
|
||||
|
||||
fclose(img_file);
|
||||
img_file.close();
|
||||
|
||||
switch(itype) {
|
||||
case FlopImgType::RAW:
|
||||
|
|
|
@ -25,7 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
#define FLOPPY_IMG_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#define BLOCK_SIZE 512 // size in bytes of a logical block
|
||||
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
/** Converter for raw floppy images. */
|
||||
class RawFloppyImg : public FloppyImgConverter {
|
||||
public:
|
||||
RawFloppyImg(const char *file_path);
|
||||
RawFloppyImg(std::string& file_path);
|
||||
~RawFloppyImg() = default;
|
||||
|
||||
int validate(void);
|
||||
|
@ -64,10 +64,10 @@ public:
|
|||
int export_data(void);
|
||||
|
||||
private:
|
||||
const char *img_path;
|
||||
int64_t img_size;
|
||||
std::string img_path;
|
||||
int img_size;
|
||||
};
|
||||
|
||||
extern int open_floppy_image(const char* img_path);
|
||||
extern int open_floppy_image(std::string& img_path);
|
||||
|
||||
#endif // FLOPPY_IMG_H
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
@ -21,7 +21,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
/** @file Macintosh Superdrive emulation. */
|
||||
|
||||
#include "superdrive.h"
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
@ -30,6 +31,9 @@ using namespace MacSuperdrive;
|
|||
|
||||
MacSuperDrive::MacSuperDrive()
|
||||
{
|
||||
this->name = "Superdrive";
|
||||
this->supported_types = HWCompType::FLOPPY_DRV;
|
||||
|
||||
this->media_kind = MediaKind::high_density;
|
||||
this->has_disk = 0; // drive is empty
|
||||
}
|
||||
|
@ -71,3 +75,11 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int MacSuperDrive::insert_disk(std::string& img_path)
|
||||
{
|
||||
//open_floppy_image(img_path.c_str());
|
||||
open_floppy_image(img_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
@ -24,7 +24,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
#ifndef MAC_SUPERDRIVE_H
|
||||
#define MAC_SUPERDRIVE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
namespace MacSuperdrive {
|
||||
|
||||
|
@ -48,13 +51,14 @@ enum MediaKind : uint8_t {
|
|||
low_density = 1
|
||||
};
|
||||
|
||||
class MacSuperDrive {
|
||||
class MacSuperDrive : public HWComponent {
|
||||
public:
|
||||
MacSuperDrive();
|
||||
~MacSuperDrive() = default;
|
||||
|
||||
void command(uint8_t addr, uint8_t value);
|
||||
uint8_t status(uint8_t addr);
|
||||
int insert_disk(std::string& img_path);
|
||||
|
||||
private:
|
||||
uint8_t media_kind;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
@ -21,9 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
/** @file Sander-Wozniak Machine 3 (SWIM3) emulation. */
|
||||
|
||||
#include "superdrive.h"
|
||||
#include "swim3.h"
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
@ -43,6 +44,7 @@ Swim3Ctrl::Swim3Ctrl()
|
|||
// TODO: make SWIM3/drive wiring user selectable
|
||||
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
|
||||
(new MacSuperdrive::MacSuperDrive());
|
||||
gMachineObj->add_subdevice("Superdrive", this->int_drive.get());
|
||||
}
|
||||
|
||||
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
|
|
|
@ -112,7 +112,7 @@ int create_gossamer(std::string& id) {
|
|||
/* check for a floppy image to be inserted into the virtual superdrive */
|
||||
std::string fdd_path = GET_STR_PROP("fdd_img");
|
||||
if (!fdd_path.empty()) {
|
||||
open_floppy_image(fdd_path.c_str());
|
||||
open_floppy_image(fdd_path);
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initialization complete.\n");
|
||||
|
|
|
@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
|
@ -97,10 +97,14 @@ int create_pdm(std::string& id) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* check for a floppy image to be inserted into the virtual superdrive */
|
||||
std::string fdd_path = GET_STR_PROP("fdd_img");
|
||||
if (!fdd_path.empty()) {
|
||||
open_floppy_image(fdd_path.c_str());
|
||||
// if a floppy image was given "insert" it into the virtual superdrive
|
||||
std::string fd_image_path = GET_STR_PROP("fdd_img");
|
||||
if (!fd_image_path.empty()) {
|
||||
using namespace MacSuperdrive;
|
||||
|
||||
MacSuperDrive* fdd = dynamic_cast<MacSuperDrive*>
|
||||
(gMachineObj->get_comp_by_name("Superdrive"));
|
||||
fdd->insert_disk(fd_image_path);
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initialization completed.\n");
|
||||
|
|
Loading…
Reference in New Issue
Block a user