Skip to content

Commit

Permalink
1500 add physical cd drive support (#1609)
Browse files Browse the repository at this point in the history
* feat: Add physical CD drive support
  • Loading branch information
midwan authored Jan 23, 2025
1 parent 231468d commit f7f19a9
Show file tree
Hide file tree
Showing 19 changed files with 1,845 additions and 114 deletions.
2 changes: 2 additions & 0 deletions cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ set(SOURCE_FILES
src/osdep/amiberry_serial.cpp
src/osdep/amiberry_uaenet.cpp
src/osdep/amiberry_whdbooter.cpp
src/osdep/blkdev_ioctl.cpp
src/osdep/ioport.cpp
src/osdep/sigsegv_handler.cpp
src/osdep/socket.cpp
Expand Down Expand Up @@ -331,6 +332,7 @@ set(SOURCE_FILES
src/osdep/gui/SelectFolder.cpp
src/osdep/gui/SelectFile.cpp
src/osdep/gui/CreateFilesysHardfile.cpp
src/osdep/gui/EditCDDrive.cpp
src/osdep/gui/EditFilesysVirtual.cpp
src/osdep/gui/EditFilesysHardfile.cpp
src/osdep/gui/EditFilesysHardDrive.cpp
Expand Down
4 changes: 4 additions & 0 deletions src/blkdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ void blkdev_fix_prefs (struct uae_prefs *p)
continue;
if (p->cdslots[i].inuse || p->cdslots[i].name[0]) {
TCHAR *name = p->cdslots[i].name;
#ifdef _WIN32
if (_tcslen (name) == 3 && name[1] == ':' && name[2] == '\\') {
#else
if (name[0] == '/' && name[1] == 'd' && name[2] == 'e' && name[3] == 'v' && name[4] == '/') {
#endif
if (currprefs.scsi && (currprefs.uaescsimode == UAESCSI_SPTI || currprefs.uaescsimode == UAESCSI_SPTISCAN))
cdscsidevicetype[i] = SCSI_UNIT_SPTI;
else
Expand Down
4 changes: 4 additions & 0 deletions src/expansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,10 @@ static uaecptr check_boot_rom (struct uae_prefs *p, int *boot_rom_type)
#ifdef WIN32
if (p->win32_automount_drives || p->win32_automount_cddrives || p->win32_automount_netdrives || p->win32_automount_removable)
return b;
#endif
#ifdef AMIBERRY
if (p->automount_cddrives || p->automount_removable)
return b;
#endif
if (p->socket_emu)
return b;
Expand Down
6 changes: 5 additions & 1 deletion src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,11 @@ static int set_filesys_unit (int nr, struct uaedev_config_info *ci, bool custom)
return ret;
}

static int add_filesys_unit (struct uaedev_config_info *ci, bool custom)
// we want to reference this from amiberry_filesys.cpp also
#ifndef AMIBERRY
static
#endif
int add_filesys_unit (struct uaedev_config_info *ci, bool custom)
{
int nr;

Expand Down
4 changes: 4 additions & 0 deletions src/include/uae.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,9 @@ extern void uaerandomizeseed(void);

int get_guid_target (uae_u8 *out);
void filesys_addexternals (void);
#ifdef AMIBERRY
extern std::vector<std::string> get_cd_drives();
extern int add_filesys_unit(struct uaedev_config_info* ci, bool custom);
#endif

#endif /* UAE_UAE_H */
21 changes: 20 additions & 1 deletion src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,25 @@ void read_controller_mapping_from_file(controller_mapping& input, const std::str
in_file.close();
}

std::vector<std::string> get_cd_drives()
{
char path[MAX_DPATH];
std::vector<std::string> results{};

FILE* fp = popen("lsblk -o NAME,TYPE | grep 'rom' | awk '{print \"/dev/\" $1}'", "r");
if (fp == nullptr) {
write_log("Failed to run 'lsblk' command, cannot auto-detect CD drives in system\n");
return results;
}

while (fgets(path, sizeof(path), fp) != nullptr) {
path[strcspn(path, "\n")] = 0;
results.emplace_back(path);
}
pclose(fp);
return results;
}

void target_setdefaultstatefilename(const TCHAR* name)
{
TCHAR path[MAX_DPATH];
Expand Down Expand Up @@ -4932,4 +4951,4 @@ void target_setdefaultstatefilename(const TCHAR* name)
}
}
_tcscpy(savestate_fname, path);
}
}
42 changes: 30 additions & 12 deletions src/osdep/amiberry_filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "filesys.h"
#include "zfile.h"
#include <unistd.h>
#include <algorithm>
#include <list>
#include <dirent.h>
#include <iconv.h>
Expand Down Expand Up @@ -49,7 +50,7 @@ void utf8_to_latin1_string(std::string& input, std::string& output)
std::string dst;

auto* iconv_ = iconv_open("ISO-8859-1//TRANSLIT", "UTF-8");
if (iconv_ == (iconv_t)-1) {
if (iconv_ == iconv_t(-1)) {
if (!has_logged_iconv_fail) {
write_log("iconv_open failed: will be copying directory entries verbatim\n");
has_logged_iconv_fail = true;
Expand All @@ -61,7 +62,7 @@ void utf8_to_latin1_string(std::string& input, std::string& output)
char* dst_ptr = buf.data();
size_t dst_size = buf.size();
size_t res = ::iconv(iconv_, &src_ptr, &src_size, &dst_ptr, &dst_size);
if (res == (size_t)-1) {
if (res == size_t(-1)) {
if (errno != E2BIG) {
// skip character
++src_ptr;
Expand Down Expand Up @@ -142,7 +143,7 @@ std::string prefix_with_application_directory_path(std::string currentpath)
}


std::string prefix_with_data_path(std::string filename)
std::string prefix_with_data_path(const std::string& filename)
{
#ifdef __MACH__
CFBundleRef mainBundle = CFBundleGetMainBundle();
Expand Down Expand Up @@ -172,7 +173,7 @@ std::string prefix_with_data_path(std::string filename)
#endif
}

std::string prefix_with_whdboot_path(std::string filename)
std::string prefix_with_whdboot_path(const std::string& filename)
{
#ifdef __MACH__
CFBundleRef mainBundle = CFBundleGetMainBundle();
Expand Down Expand Up @@ -828,8 +829,7 @@ int my_issamevolume(const TCHAR* path1, const TCHAR* path2, TCHAR* path)
my_canonicalize_path(path2, p2, sizeof p2 / sizeof(TCHAR));

unsigned int len = _tcslen(p1);
if (len > _tcslen(p2))
len = _tcslen(p2);
len = std::min<size_t>(len, _tcslen(p2));

if (_tcsnicmp(p1, p2, len))
return 0;
Expand Down Expand Up @@ -895,18 +895,36 @@ int target_get_volume_name(struct uaedev_mount_info* mtinf, struct uaedev_config
bool copyfile(const char* target, const char* source, const bool replace)
{
#ifdef USE_OLDGCC
std::experimental::filesystem::copy_options options = {};
options = replace ? experimental::filesystem::copy_options::overwrite_existing : experimental::filesystem::copy_options::none;
std::experimental::filesystem::copy_options options = replace
? experimental::filesystem::copy_options::overwrite_existing
: experimental::filesystem::copy_options::none;
#else
std::filesystem::copy_options options = {};
options = replace ? filesystem::copy_options::overwrite_existing : filesystem::copy_options::none;
std::filesystem::copy_options options = replace
? filesystem::copy_options::overwrite_existing
: filesystem::copy_options::none;
#endif
return copy_file(source, target, options);
}

void filesys_addexternals(void)
{
// this would mount system drives on Windows
if (!currprefs.automount_cddrives)
return;

const auto cd_drives = get_cd_drives();
if (!cd_drives.empty())
{
int drvnum = 0;
for (auto& drive : cd_drives)
{
struct uaedev_config_info ci = { 0 };
_tcscpy(ci.rootdir, drive.c_str());
ci.readonly = true;
ci.bootpri = -20 - drvnum;
add_filesys_unit(&ci, true);
drvnum++;
}
}
}

std::string my_get_sha1_of_file(const char* filepath)
Expand All @@ -916,7 +934,7 @@ std::string my_get_sha1_of_file(const char* filepath)
return "";
}

int fd = open(filepath, O_RDONLY);
const int fd = open(filepath, O_RDONLY);
if (fd < 0) {
write_log("my_get_sha1_of_file: open on file %s failed\n", filepath);
return "";
Expand Down
4 changes: 3 additions & 1 deletion src/osdep/amiberry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,6 @@ void CreateDefaultDevicename(char* name)
}
}


int tweakbootpri(int bp, int ab, int dnm)
{
if (dnm)
Expand Down Expand Up @@ -1601,6 +1600,9 @@ void new_cddrive(int entry)
ci.device_emu_unit = 0;
ci.controller_type = current_cddlg.ci.controller_type;
ci.controller_unit = current_cddlg.ci.controller_unit;
#ifdef AMIBERRY
_tcscpy(ci.rootdir, current_cddlg.ci.rootdir);
#endif
ci.type = UAEDEV_CD;
ci.readonly = true;
ci.blocksize = 2048;
Expand Down
Loading

0 comments on commit f7f19a9

Please sign in to comment.