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

@ -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;