dosbox-wii/src/dos/cdrom.h

317 lines
9.4 KiB
C
Raw Normal View History

2009-05-02 23:35:44 +02:00
#ifndef __CDROM_INTERFACE__
#define __CDROM_INTERFACE__
#define MAX_ASPI_CDROM 5
#include <string.h>
2009-05-03 00:08:43 +02:00
#include <string>
2009-05-03 00:02:15 +02:00
#include <iostream>
#include <vector>
2009-05-03 00:08:43 +02:00
#include <fstream>
#include <sstream>
2009-05-02 23:53:27 +02:00
#include "dosbox.h"
2009-05-02 23:43:00 +02:00
#include "mem.h"
2009-05-03 00:02:15 +02:00
#include "mixer.h"
2009-05-02 23:35:44 +02:00
#include "SDL.h"
2009-05-03 00:02:15 +02:00
#include "SDL_thread.h"
2009-05-02 23:35:44 +02:00
2009-05-03 00:02:15 +02:00
#if defined(C_SDL_SOUND)
#include "SDL_sound.h"
#endif
2009-05-02 23:53:27 +02:00
2009-05-02 23:35:44 +02:00
#define RAW_SECTOR_SIZE 2352
#define COOKED_SECTOR_SIZE 2048
enum { CDROM_USE_SDL, CDROM_USE_ASPI, CDROM_USE_IOCTL };
typedef struct SMSF {
unsigned char min;
unsigned char sec;
unsigned char fr;
} TMSF;
extern int CDROM_GetMountType(char* path, int force);
class CDROM_Interface
{
public:
// CDROM_Interface (void);
virtual ~CDROM_Interface (void) {};
virtual bool SetDevice (char* path, int forceCD) = 0;
virtual bool GetUPC (unsigned char& attr, char* upc) = 0;
virtual bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut) = 0;
virtual bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr) = 0;
virtual bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) = 0;
virtual bool GetAudioStatus (bool& playing, bool& pause) = 0;
virtual bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen) = 0;
virtual bool PlayAudioSector (unsigned long start,unsigned long len) = 0;
virtual bool PauseAudio (bool resume) = 0;
virtual bool StopAudio (void) = 0;
2009-05-02 23:43:00 +02:00
virtual bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num) = 0;
2009-05-02 23:35:44 +02:00
virtual bool LoadUnloadMedia (bool unload) = 0;
2009-05-03 00:02:15 +02:00
virtual void InitNewMedia (void) {};
2009-05-02 23:35:44 +02:00
};
class CDROM_Interface_SDL : public CDROM_Interface
{
public:
CDROM_Interface_SDL (void);
2009-05-03 00:02:15 +02:00
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 bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num) { return false; };
virtual bool LoadUnloadMedia (bool unload);
2009-05-02 23:35:44 +02:00
private:
bool Open (void);
void Close (void);
SDL_CD* cd;
int driveID;
Uint32 oldLeadOut;
};
class CDROM_Interface_Fake : public CDROM_Interface
{
public:
bool SetDevice (char* path, int forceCD) { return true; };
bool GetUPC (unsigned char& attr, char* upc) { attr = 0; strcpy(upc,"UPC"); return true; };
bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
bool GetAudioStatus (bool& playing, bool& pause);
bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
bool PlayAudioSector (unsigned long start,unsigned long len) { return true; };
bool PauseAudio (bool resume) { return true; };
bool StopAudio (void) { return true; };
2009-05-02 23:43:00 +02:00
bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num) { return true; };
2009-05-02 23:35:44 +02:00
bool LoadUnloadMedia (bool unload) { return true; };
};
2009-05-03 00:02:15 +02:00
class CDROM_Interface_Image : public CDROM_Interface
{
private:
class TrackFile {
public:
virtual bool read(Bit8u *buffer, int seek, int count) = 0;
virtual int getLength() = 0;
};
class BinaryFile : public TrackFile {
public:
BinaryFile(const char *filename, bool &error);
~BinaryFile();
bool read(Bit8u *buffer, int seek, int count);
int getLength();
private:
BinaryFile();
std::ifstream *file;
};
#if defined(C_SDL_SOUND)
class AudioFile : public TrackFile {
public:
AudioFile(const char *filename, bool &error);
~AudioFile();
bool read(Bit8u *buffer, int seek, int count);
int getLength();
private:
AudioFile();
Sound_Sample *sample;
int lastCount;
int lastSeek;
};
#endif
struct Track {
int number;
int attr;
int start;
int length;
int skip;
int sectorSize;
bool mode2;
TrackFile *file;
};
public:
CDROM_Interface_Image (Bit8u subUnit);
virtual ~CDROM_Interface_Image (void);
void InitNewMedia (void);
bool SetDevice (char* path, int forceCD);
bool GetUPC (unsigned char& attr, char* upc);
bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
bool GetAudioStatus (bool& playing, bool& pause);
bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
bool PlayAudioSector (unsigned long start,unsigned long len);
bool PauseAudio (bool resume);
bool StopAudio (void);
bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num);
bool LoadUnloadMedia (bool unload);
bool ReadSector (Bit8u *buffer, bool raw, unsigned long sector);
static CDROM_Interface_Image* images[26];
private:
// player
static void CDAudioCallBack(Bitu len);
int GetTrack(int sector);
static struct imagePlayer {
CDROM_Interface_Image *cd;
MixerChannel *channel;
SDL_mutex *mutex;
Bit8u buffer[8192];
int bufLen;
int currFrame;
int targetFrame;
bool isPlaying;
bool isPaused;
} player;
void ClearTracks();
bool LoadIsoFile(char *filename);
bool CanReadPVD(TrackFile *file, int sectorSize, bool mode2);
// cue sheet processing
bool LoadCueSheet(char *cuefile);
bool GetRealFileName(std::string& filename, std::string& pathname);
bool GetCueKeyword(std::string &keyword, std::istream &in);
bool GetCueFrame(int &frames, std::istream &in);
bool GetCueString(std::string &str, std::istream &in);
bool AddTrack(Track &curr, int &shift, int prestart, int &totalPregap, int currPregap);
static int refCount;
std::vector<Track> tracks;
std::string mcn;
Bit8u subUnit;
};
2009-05-02 23:35:44 +02:00
#if defined (WIN32) /* Win 32 */
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include "wnaspi32.h" // Aspi stuff
class CDROM_Interface_Aspi : public CDROM_Interface
{
public:
CDROM_Interface_Aspi (void);
2009-05-03 00:02:15 +02:00
virtual ~CDROM_Interface_Aspi(void);
2009-05-02 23:35:44 +02:00
bool SetDevice (char* path, int forceCD);
bool GetUPC (unsigned char& attr, char* upc);
bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
bool GetAudioStatus (bool& playing, bool& pause);
bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
bool PlayAudioSector (unsigned long start,unsigned long len);
bool PauseAudio (bool resume);
bool StopAudio (void);
2009-05-02 23:43:00 +02:00
bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num);
2009-05-02 23:35:44 +02:00
bool LoadUnloadMedia (bool unload);
private:
DWORD GetTOC (LPTOC toc);
HANDLE OpenIOCTLFile (char cLetter, BOOL bAsync);
void GetIOCTLAdapter (HANDLE hF,int * iDA,int * iDT,int * iDL);
bool ScanRegistryFindKey (HKEY& hKeyBase);
bool ScanRegistry (HKEY& hKeyBase);
BYTE GetHostAdapter (char* hardwareID);
bool GetVendor (BYTE HA_num, BYTE SCSI_Id, BYTE SCSI_Lun, char* szBuffer);
// ASPI stuff
BYTE haId;
BYTE target;
BYTE lun;
char letter;
// Windows stuff
HINSTANCE hASPI;
HANDLE hEvent; // global event
DWORD (*pGetASPI32SupportInfo) (void); // ptrs to aspi funcs
DWORD (*pSendASPI32Command) (LPSRB);
TMSF oldLeadOut;
};
class CDROM_Interface_Ioctl : public CDROM_Interface
{
public:
CDROM_Interface_Ioctl (void);
2009-05-03 00:02:15 +02:00
virtual ~CDROM_Interface_Ioctl(void);
2009-05-02 23:35:44 +02:00
bool SetDevice (char* path, int forceCD);
bool GetUPC (unsigned char& attr, char* upc);
bool GetAudioTracks (int& stTrack, int& end, TMSF& leadOut);
bool GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr);
bool GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos);
bool GetAudioStatus (bool& playing, bool& pause);
bool GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen);
bool PlayAudioSector (unsigned long start,unsigned long len);
bool PauseAudio (bool resume);
bool StopAudio (void);
2009-05-02 23:43:00 +02:00
bool ReadSectors (PhysPt buffer, bool raw, unsigned long sector, unsigned long num);
2009-05-02 23:35:44 +02:00
bool LoadUnloadMedia (bool unload);
2009-05-03 00:02:15 +02:00
void InitNewMedia (void) { Close(); Open(); };
2009-05-02 23:35:44 +02:00
private:
bool Open (void);
void Close (void);
char pathname[32];
HANDLE hIOCTL;
TMSF oldLeadOut;
};
#endif /* WIN 32 */
2009-05-03 00:18:08 +02:00
#if defined (LINUX) || defined(OS2)
2009-05-02 23:53:27 +02:00
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 */
2009-05-02 23:35:44 +02:00
#endif /* __CDROM_INTERFACE__ */