From 3e170dbdcf168bd94fac6b72223ad285979ff8df Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Tue, 27 Jan 2004 20:23:13 +0000 Subject: [PATCH] Added patch 884060 from Martin Battig Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1607 --- configure.in | 3 ++ src/dos/Makefile.am | 2 +- src/dos/cdrom.h | 19 +++++++ src/dos/cdrom_ioctl_linux.cpp | 96 +++++++++++++++++++++++++++++++++++ src/dos/dos_mscdex.cpp | 7 +++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/dos/cdrom_ioctl_linux.cpp diff --git a/configure.in b/configure.in index f1cd15eb..12a1512d 100644 --- a/configure.in +++ b/configure.in @@ -166,6 +166,9 @@ case "$target" in AC_DEFINE(MACOSX, 1, [Compiling on Mac OS X]) LIBS="$LIBS -framework AudioUnit" ;; + *-*-linux-gnu*) + AC_DEFINE(LINUX, 1, [Compiling on GNU/Linux]) + ;; esac AC_OUTPUT([ diff --git a/src/dos/Makefile.am b/src/dos/Makefile.am index 14cd2780..7bd9b5af 100644 --- a/src/dos/Makefile.am +++ b/src/dos/Makefile.am @@ -6,4 +6,4 @@ libdos_a_SOURCES = dos.cpp dos_devices.cpp dos_execute.cpp dos_files.cpp dos_ioc dos_misc.cpp dos_classes.cpp dos_programs.cpp dos_tables.cpp \ drives.cpp drives.h drive_virtual.cpp drive_local.cpp drive_cache.cpp \ dev_con.h dos_mscdex.cpp \ - cdrom.h cdrom.cpp cdrom_ioctl_win32.cpp cdrom_aspi_win32.cpp + cdrom.h cdrom.cpp cdrom_ioctl_win32.cpp cdrom_aspi_win32.cpp cdrom_ioctl_linux.cpp diff --git a/src/dos/cdrom.h b/src/dos/cdrom.h index 3c307cfb..0159d86a 100644 --- a/src/dos/cdrom.h +++ b/src/dos/cdrom.h @@ -5,9 +5,11 @@ #define MAX_ASPI_CDROM 5 #include +#include "dosbox.h" #include "mem.h" #include "SDL.h" + #define RAW_SECTOR_SIZE 2352 #define COOKED_SECTOR_SIZE 2048 @@ -181,4 +183,21 @@ private: #endif /* WIN 32 */ +#if defined (LINUX) + +class CDROM_Interface_Ioctl : public CDROM_Interface_SDL +{ +public: + CDROM_Interface_Ioctl (void); + + bool SetDevice (char* path, int forceCD); + bool GetUPC (unsigned char& attr, char* upc); + bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num); + +private: + char device_name[512]; +}; + +#endif /* LINUX */ + #endif /* __CDROM_INTERFACE__ */ diff --git a/src/dos/cdrom_ioctl_linux.cpp b/src/dos/cdrom_ioctl_linux.cpp new file mode 100644 index 00000000..f5050799 --- /dev/null +++ b/src/dos/cdrom_ioctl_linux.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2002-2004 The DOSBox Team + * + * 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 2 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 Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#include +#include "cdrom.h" + +#if defined (LINUX) +#include +#include +#include +#include +#include +#include + +CDROM_Interface_Ioctl::CDROM_Interface_Ioctl(void) : CDROM_Interface_SDL() +{ + strcpy(device_name, ""); +} + +bool CDROM_Interface_Ioctl::GetUPC(unsigned char& attr, char* upc) +{ + int cdrom_fd = open(device_name, O_RDONLY | O_NONBLOCK); + if (cdrom_fd <= 0) return false; + + struct cdrom_mcn cdrom_mcn; + int ret = ioctl(cdrom_fd, CDROM_GET_MCN, &cdrom_mcn); + + close(cdrom_fd); + + if (ret > 0) { + attr = 0; + strncpy(upc, (char*)cdrom_mcn.medium_catalog_number, 14); + } + + return (ret > 0); +} + +bool CDROM_Interface_Ioctl::ReadSectors(PhysPt buffer, bool raw, unsigned long sector, unsigned long num) +{ + int cdrom_fd = open(device_name, O_RDONLY | O_NONBLOCK); + if (cdrom_fd <= 0) return false; + + Bitu buflen = raw ? num * CD_FRAMESIZE_RAW : num * CD_FRAMESIZE; + Bit8u* buf = new Bit8u[buflen]; + int ret; + + if (raw) { + struct cdrom_read cdrom_read; + cdrom_read.cdread_lba = sector; + cdrom_read.cdread_bufaddr = (char*)buf; + cdrom_read.cdread_buflen = buflen; + + ret = ioctl(cdrom_fd, CDROMREADRAW, &cdrom_read); + } else { + ret = lseek(cdrom_fd, sector * CD_FRAMESIZE, SEEK_SET); + if (ret >= 0) ret = read(cdrom_fd, buf, buflen); + if (ret != buflen) ret = -1; + } + close(cdrom_fd); + + MEM_BlockWrite(buffer, buf, buflen); + delete[] buf; + + return (ret > 0); +} + +bool CDROM_Interface_Ioctl::SetDevice(char* path, int forceCD) +{ + bool success = CDROM_Interface_SDL::SetDevice(path, forceCD); + + if (success) { + const char* tmp = SDL_CDName(forceCD); + if (tmp) strncpy(device_name, tmp, 512); + else success = false; + } + + return success; +} + +#endif diff --git a/src/dos/dos_mscdex.cpp b/src/dos/dos_mscdex.cpp index 5ee7c56f..f6f93650 100644 --- a/src/dos/dos_mscdex.cpp +++ b/src/dos/dos_mscdex.cpp @@ -260,6 +260,13 @@ int CMscdex::AddDrive(Bit16u _drive, char* physicalPath, Bit8u& subUnit) break; } #endif + #if defined (LINUX) + if (useCdromInterface==CDROM_USE_IOCTL) { + cdrom[numDrives] = new CDROM_Interface_Ioctl(); + LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: IOCTL Interface."); + break; + } + #endif cdrom[numDrives] = new CDROM_Interface_SDL(); LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: SDL Interface."); } break;