Linux implementation. Include changes for gcc x64.

This commit is contained in:
LuisAntonRebollo 2015-01-24 22:08:26 +01:00
parent 4e52824a42
commit 4e9034854d
56 changed files with 1108 additions and 3075 deletions

View file

@ -20,8 +20,6 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Not needed on dedicated (SDL is not not linked against when dedicated)
#ifndef TORQUE_DEDICATED
#include "console/console.h"
#include "platformX86UNIX/platformX86UNIX.h"
#include "platform/platformRedBook.h"
@ -34,7 +32,9 @@
#include <string.h>
#endif
#include <SDL/SDL.h>
#include <SDL.h>
class SDL_CD; // TODO SDL remove
class UnixRedBookDevice : public RedBookDevice
{
@ -93,24 +93,7 @@ UnixRedBookDevice::~UnixRedBookDevice()
//------------------------------------------------------------------------------
bool UnixRedBookDevice::updateStatus()
{
#if !defined(__FreeBSD__)
AssertFatal(mCD, "mCD is NULL");
CDstatus status = SDL_CDStatus(mCD);
if (status == CD_ERROR)
{
setLastError("Error accessing device");
return(false);
}
else if (status == CD_TRAYEMPTY)
{
setLastError("CD tray empty");
return false;
}
mPlaying = (status == CD_PLAYING);
return true;
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
@ -126,134 +109,31 @@ void UnixRedBookDevice::setDeviceInfo(S32 deviceId, const char *deviceName)
//------------------------------------------------------------------------------
bool UnixRedBookDevice::open()
{
#if !defined(__FreeBSD__)
if(mAcquired)
{
setLastError("Device is already open.");
return(false);
}
// open the device
mCD = SDL_CDOpen(mDeviceId);
if (mCD == NULL)
{
setLastError(SDL_GetError());
return false;
}
mAcquired = true;
openVolume();
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::close()
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
stop();
closeVolume();
if (mCD != NULL)
{
SDL_CDClose(mCD);
mCD = NULL;
}
mAcquired = false;
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::play(U32 track)
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
U32 numTracks;
if(!getTrackCount(&numTracks))
return(false);
if(track >= numTracks)
{
setLastError("Track index is out of range");
return(false);
}
if (!updateStatus())
return false;
AssertFatal(mCD, "mCD is NULL");
if (SDL_CDPlayTracks(mCD, track, 0, 1, 0) == -1)
{
setLastError(SDL_GetError());
return false;
}
mPlaying = true;
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::stop()
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
AssertFatal(mCD, "mCD is NULL");
if (SDL_CDStop(mCD) == -1)
{
setLastError(SDL_GetError());
return(false);
}
mPlaying = false;
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::getTrackCount(U32 * numTracks)
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
if (!updateStatus())
return false;
AssertFatal(mCD, "mCD is NULL");
*numTracks = mCD->numtracks;
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
template <class Type>
@ -283,18 +163,7 @@ bool UnixRedBookDevice::getVolume(F32 * volume)
}
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
cdrom_volctrl sysvol;
if (ioctl(mCD->id, CDROMVOLREAD, &sysvol) == -1)
{
setLastError(strerror(errno));
return(false);
}
U8 maxVol = max(sysvol.channel0, sysvol.channel1);
// JMQTODO: support different left/right channel volumes?
*volume = static_cast<F32>(maxVol) / 255.f;
AssertFatal(0, "SDL CD not implemented");
return true;
#else
return(false);
@ -319,21 +188,7 @@ bool UnixRedBookDevice::setVolume(F32 volume)
}
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
cdrom_volctrl sysvol;
volume = volume * 255.f;
if (volume > 255)
volume = 255;
if (volume < 0)
volume = 0;
sysvol.channel0 = sysvol.channel1 = static_cast<__u8>(volume);
if (ioctl(mCD->id, CDROMVOLCTRL, &sysvol) == -1)
{
setLastError(strerror(errno));
return(false);
}
AssertFatal(0, "SDL CD not implemented");
return true;
#else
return(false);
@ -348,17 +203,7 @@ void UnixRedBookDevice::openVolume()
// Its unforunate that we have to do it this way, but SDL does not currently
// support setting CD audio volume
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
if (ioctl(mCD->id, CDROMVOLREAD, &mOriginalVolume) == -1)
{
setLastError(strerror(errno));
return;
}
mVolumeInitialized = true;
AssertFatal(0, "SDL CD not implemented");
#else
setLastError("Volume failed to initialize");
#endif
@ -372,15 +217,7 @@ void UnixRedBookDevice::closeVolume()
return;
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
if (ioctl(mCD->id, CDROMVOLCTRL, &mOriginalVolume) == -1)
{
setLastError(strerror(errno));
return;
}
AssertFatal(0, "SDL CD not implemented");
#endif
mVolumeInitialized = false;
@ -398,33 +235,7 @@ void UnixRedBookDevice::setLastError(const char * error)
//------------------------------------------------------------------------------
void InstallRedBookDevices()
{
#if !defined(__FreeBSD__)
Con::printf("CD Audio Init:");
if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
{
Con::printf(" Unable to initialize CD Audio: %s", SDL_GetError());
return;
}
S32 numDrives = SDL_CDNumDrives();
if (numDrives == 0)
{
Con::printf(" No drives found.");
return;
}
for (int i = 0; i < numDrives; ++i)
{
const char * deviceName = SDL_CDName(i);
Con::printf(" Installing CD Audio device: %s", deviceName);
UnixRedBookDevice * device = new UnixRedBookDevice;
device->setDeviceInfo(i, deviceName);
RedBook::installDevice(device);
}
Con::printf(" ");
#endif // !defined(__FreeBSD__)
}
//------------------------------------------------------------------------------
@ -455,4 +266,3 @@ void PollRedbookDevices()
}
#endif // !defined(__FreeBSD__)
}
#endif