1
0
Fork 0

Remove SDL_cdrom 1.2 based CD-ROM interfaces

This removes a feature of mounting physical CD-ROMs in DOSBox.

SDL 2.0 removed SDL_cdrom from supported libraries, so to bring this
code back, either the functionality will need to be reimplemented or
SDL_cdrom code modernized for SDL 2.0, and bundled with the repo (the
same way SDL_sound is already bundled).
This commit is contained in:
Patryk Obara 2019-12-01 16:09:24 +01:00 committed by Patryk Obara
parent 12ee84cfd4
commit e1286efca9
7 changed files with 9 additions and 299 deletions

View file

@ -6,5 +6,5 @@ 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 drive_fat.cpp \
drive_iso.cpp dev_con.h dos_mscdex.cpp dos_keyboard_layout.cpp \
cdrom.h cdrom.cpp cdrom_ioctl_linux.cpp cdrom_image.cpp \
cdrom.h cdrom.cpp cdrom_image.cpp \
drive_overlay.cpp

View file

@ -26,150 +26,14 @@
#include <unistd.h>
#include "dosbox.h"
#include "SDL.h"
#include "support.h"
#include "cdrom.h"
CDROM_Interface_SDL::CDROM_Interface_SDL(void) {
driveID = 0;
oldLeadOut = 0;
cd = 0;
}
CDROM_Interface_SDL::~CDROM_Interface_SDL(void) {
StopAudio();
SDL_CDClose(cd);
cd = 0;
}
bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
char buffer[512];
strcpy(buffer,path);
upcase(buffer);
int num = SDL_CDNumDrives();
if ((forceCD>=0) && (forceCD<num)) {
driveID = forceCD;
cd = SDL_CDOpen(driveID);
SDL_CDStatus(cd);
return true;
};
const char* cdname = 0;
for (int i=0; i<num; i++) {
cdname = SDL_CDName(i);
if (strcmp(buffer,cdname)==0) {
cd = SDL_CDOpen(i);
SDL_CDStatus(cd);
driveID = i;
return true;
};
};
return false;
}
bool CDROM_Interface_SDL::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) {
if (CD_INDRIVE(SDL_CDStatus(cd))) {
stTrack = 1;
end = cd->numtracks;
frames_to_msf(cd->track[cd->numtracks].offset, &leadOut.min, &leadOut.sec, &leadOut.fr);
}
return CD_INDRIVE(SDL_CDStatus(cd));
}
bool CDROM_Interface_SDL::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
if (CD_INDRIVE(SDL_CDStatus(cd))) {
frames_to_msf(cd->track[track-1].offset, &start.min, &start.sec, &start.fr);
attr = cd->track[track-1].type<<4;//sdl uses 0 for audio and 4 for data. instead of 0x00 and 0x40
}
return CD_INDRIVE(SDL_CDStatus(cd));
}
bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) {
if (CD_INDRIVE(SDL_CDStatus(cd))) {
track = cd->cur_track;
index = cd->cur_track;
attr = cd->track[track].type<<4;
frames_to_msf(cd->cur_frame, &relPos.min, &relPos.sec, &relPos.fr);
frames_to_msf(cd->cur_frame+cd->track[track].offset, &absPos.min, &absPos.sec, &absPos.fr);
}
return CD_INDRIVE(SDL_CDStatus(cd));
}
bool CDROM_Interface_SDL::GetAudioStatus(bool& playing, bool& pause){
if (CD_INDRIVE(SDL_CDStatus(cd))) {
playing = (cd->status==CD_PLAYING);
pause = (cd->status==CD_PAUSED);
}
return CD_INDRIVE(SDL_CDStatus(cd));
}
bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
SDL_CDStatus(cd);
mediaPresent = (cd->status!=CD_TRAYEMPTY) && (cd->status!=CD_ERROR);
mediaChanged = (oldLeadOut!=cd->track[cd->numtracks].offset);
trayOpen = !mediaPresent;
oldLeadOut = cd->track[cd->numtracks].offset;
if (mediaChanged) SDL_CDStatus(cd);
return true;
}
bool CDROM_Interface_SDL::PlayAudioSector(unsigned long start,unsigned long len) {
// Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
SDL_CDClose(cd);
cd = SDL_CDOpen(driveID);
bool success = (SDL_CDPlay(cd,start+150,len)==0);
return success;
}
bool CDROM_Interface_SDL::PauseAudio(bool resume) {
bool success;
if (resume) success = (SDL_CDResume(cd)==0);
else success = (SDL_CDPause (cd)==0);
return success;
}
bool CDROM_Interface_SDL::StopAudio(void) {
// Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
SDL_CDClose(cd);
cd = SDL_CDOpen(driveID);
bool success = (SDL_CDStop(cd)==0);
return success;
}
bool CDROM_Interface_SDL::LoadUnloadMedia(bool unload) {
bool success = (SDL_CDEject(cd)==0);
return success;
}
int CDROM_GetMountType(char* path, int forceCD) {
// 0 - physical CDROM
int CDROM_GetMountType(char* path, int) {
// 1 - Iso file
// 2 - subdirectory
// 1. Smells like a real cdrom
// if ((strlen(path)<=3) && (path[2]=='\\') && (strchr(path,'\\')==strrchr(path,'\\')) && (GetDriveType(path)==DRIVE_CDROM)) return 0;
const char* cdName;
char buffer[512];
strcpy(buffer,path);
#if defined (WIN32)
upcase(buffer);
#endif
int num = SDL_CDNumDrives();
// If cd drive is forced then check if its in range and return 0
if ((forceCD>=0) && (forceCD<num)) {
LOG(LOG_ALL,LOG_ERROR)("CDROM: Using drive %d",forceCD);
return 0;
}
// compare names
for (int i=0; i<num; i++) {
cdName = SDL_CDName(i);
if (strcmp(buffer,cdName)==0) return 0;
};
// Detect ISO
struct stat file_stat;
if ((stat(path, &file_stat) == 0) && (file_stat.st_mode & S_IFREG)) return 1;

View file

@ -99,35 +99,6 @@ public:
virtual void InitNewMedia (void) {};
};
class CDROM_Interface_SDL : public CDROM_Interface
{
public:
CDROM_Interface_SDL (void);
virtual ~CDROM_Interface_SDL (void);
virtual bool SetDevice (char* path, int forceCD);
virtual bool GetUPC (unsigned char& attr, char* upc) { attr = 0; strcpy(upc,"UPC"); return true; };
virtual bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
virtual bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
virtual bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
virtual bool GetAudioStatus (bool& playing, bool& pause);
virtual bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
virtual bool PlayAudioSector (unsigned long start,unsigned long len);
virtual bool PauseAudio (bool resume);
virtual bool StopAudio (void);
virtual void ChannelControl (TCtrl ctrl) { (void)ctrl; // unused but part of the API
return; };
virtual bool ReadSectors (PhysPt /*buffer*/, bool /*raw*/, unsigned long /*sector*/, unsigned long /*num*/) { return false; };
virtual bool LoadUnloadMedia (bool unload);
private:
bool Open (void);
void Close (void);
SDL_CD* cd;
int driveID;
Uint32 oldLeadOut;
};
class CDROM_Interface_Fake : public CDROM_Interface
{
public:
@ -271,21 +242,4 @@ private:
Bit8u subUnit;
};
#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__ */

View file

@ -1,97 +0,0 @@
/*
* Copyright (C) 2002-2019 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 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include "cdrom.h"
#include "support.h"
#if defined (LINUX)
#include <fcntl.h>
#include <unistd.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
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 == -1) 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;
safe_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 == -1) return false;
Bits 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) safe_strncpy(device_name, tmp, 512);
else success = false;
}
return success;
}
#endif

View file

@ -253,18 +253,11 @@ int CMscdex::AddDrive(Bit16u _drive, char* physicalPath, Bit8u& subUnit)
int result = 0;
// Get Mounttype and init needed cdrom interface
switch (CDROM_GetMountType(physicalPath,forceCD)) {
case 0x00: {
case 0x00:
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: Mounting physical cdrom: %s" ,physicalPath);
#if defined (LINUX)
// Always use IOCTL in Linux
cdrom[numDrives] = new CDROM_Interface_Ioctl();
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: IOCTL Interface.");
#else
// Default case windows and other oses
cdrom[numDrives] = new CDROM_Interface_SDL();
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: SDL Interface.");
#endif
} break;
// TODO: support for mounting physical CD-ROMs removed, provide
// warnings/explanations for users
return 2;
case 0x01: // iso cdrom interface
LOG(LOG_MISC,LOG_NORMAL)("MSCDEX: Mounting iso file as cdrom: %s", physicalPath);
cdrom[numDrives] = new CDROM_Interface_Image((Bit8u)numDrives);

View file

@ -199,11 +199,8 @@ public:
/* Show list of cdroms */
if (cmd->FindExist("-cd",false)) {
int num = SDL_CDNumDrives();
WriteOut(MSG_Get("PROGRAM_MOUNT_CDROMS_FOUND"),num);
for (int i=0; i<num; i++) {
WriteOut("%2d. %s\n",i,SDL_CDName(i));
};
// TODO: implement write out
// WriteOut("Physical CD-ROMs not supported any more");
return;
}

View file

@ -2049,8 +2049,7 @@ int main(int argc, char* argv[]) {
#endif
// Don't init timers, GetTicks seems to work fine and they can use a fair amount of power (Macs again)
// Please report problems with audio and other things.
if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO | /*SDL_INIT_TIMER |*/ SDL_INIT_CDROM
|SDL_INIT_NOPARACHUTE
if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
) < 0 ) E_Exit("Can't init SDL %s",SDL_GetError());
sdl.inited = true;