This commit is contained in:
Wengier 2020-12-27 00:52:05 -05:00
parent 1b7710c48f
commit b704421915
13 changed files with 605 additions and 75 deletions

View File

@ -98,9 +98,10 @@
the mapperfile_sdl1 and mapperfile_sdl2 config
options to override mapperfile option. (Wengier)
- The menu functions "Load mapper file", "Quick edit
mode" and "Stop clipboard pasting" are added to the
mapper so that you can now define your own shortcut
keys to activate these functions. (Wengier)
mode", "Stop clipboard pasting" and "Display state
information" have been added to the key mapper so
that you can now define your own shortcut keys to
activate these functions. (Wengier)
- Added ttf.fontbold, ttf.fontital, and ttf.fontboit
config options so that you can specify actual bold
italic, and bold-italic TrueType fonts for use with
@ -131,6 +132,10 @@
show a warning dialog instead of exiting. (Wengier)
- Fixed the mouse sensitivity menu option (under the
"DOS" menu) not working. (Wengier)
- Fixed physical CD drives not working in the SDL2
version. Now commands like "MOUNT -CD" should work
in SDL2 builds just like SDL1 builds. Some code
is adoptped from the SDL2_CDROM library.(Wengier)
- Fixed the color palette problem when switching to
graphic mode from mono mode. (Wengier)
- Fixed full-screen TTF output may not fully cover

5
include/SDL_cdrom.h Normal file
View File

@ -0,0 +1,5 @@
#if defined(C_SDL2)
#include "vs2015/sdl/src/cdrom/compat_SDL_cdrom.h"
#else
#include "vs2015/sdl/include/SDL_cdrom.h"
#endif

View File

@ -30,15 +30,30 @@
#include "support.h"
#include "cdrom.h"
#if defined(C_SDL2)
#include "../../vs2015/sdl/src/cdrom/compat_SDL_cdrom.c"
#if defined(WIN32)
#define SDL_CDROM_WIN32
#include "../../vs2015/sdl/src/cdrom/win32/SDL_syscdrom.c"
#elif defined(LINUX)
#define SDL_CDROM_LINUX
#include "../../vs2015/sdl/src/cdrom/linux/SDL_syscdrom.c"
#elif defined(MACOSX)
#define SDL_CDROM_MACOSX
#include "../../vs2015/sdl/src/cdrom/macosx/SDL_syscdrom.c"
#else
#define SDL_CDROM_DUMMY
#include "../../vs2015/sdl/src/cdrom/dummy/SDL_syscdrom.c"
#endif
#endif
CDROM_Interface_SDL::CDROM_Interface_SDL(void) {
}
CDROM_Interface_SDL::~CDROM_Interface_SDL(void) {
CDROM_Interface_SDL::StopAudio();
#if !defined(C_SDL2)
SDL_CDClose(cd);
cd = 0;
#endif
}
bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
@ -47,7 +62,6 @@ bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
strcpy(buffer,path);
upcase(buffer);
#if !defined(C_SDL2)
int num = SDL_CDNumDrives();
if ((forceCD>=0) && (forceCD<num)) {
driveID = forceCD;
@ -66,7 +80,6 @@ bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
return true;
}
}
#endif
return false;
}
@ -84,31 +97,24 @@ bool CDROM_Interface_SDL::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut)
(void)leadOut;//POSSIBLY UNUSED
(void)stTrack;//POSSIBLY UNUSED
(void)end;//POSSIBLY UNUSED
#if !defined(C_SDL2)
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));
#else
return false;
#endif
}
bool CDROM_Interface_SDL::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
(void)track;//POSSIBLY UNUSED
(void)start;//POSSIBLY UNUSED
(void)attr;//POSSIBLY UNUSED
#if !defined(C_SDL2)
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));
#else
return false;
#endif
}
bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) {
@ -117,7 +123,6 @@ bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track,
(void)index;//POSSIBLY UNUSED
(void)track;//POSSIBLY UNUSED
(void)attr;//POSSIBLY UNUSED
#if !defined(C_SDL2)
if (CD_INDRIVE(SDL_CDStatus(cd))) {
track = cd->cur_track;
index = cd->cur_track;
@ -126,30 +131,23 @@ bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track,
FRAMES_TO_MSF((unsigned int)cd->cur_frame+cd->track[track].offset,&absPos.min,&absPos.sec,&absPos.fr);
}
return CD_INDRIVE(SDL_CDStatus(cd));
#else
return false;
#endif
}
bool CDROM_Interface_SDL::GetAudioStatus(bool& playing, bool& pause){
(void)playing;//POSSIBLY UNUSED
(void)pause;//POSSIBLY UNUSED
#if !defined(C_SDL2)
if (CD_INDRIVE(SDL_CDStatus(cd))) {
playing = (cd->status==CD_PLAYING);
pause = (cd->status==CD_PAUSED);
}
return CD_INDRIVE(SDL_CDStatus(cd));
#else
return false;
#endif
}
bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
(void)mediaPresent;//POSSIBLY UNUSED
(void)mediaChanged;//POSSIBLY UNUSED
(void)trayOpen;//POSSIBLY UNUSED
#if !defined(C_SDL2)
SDL_CDStatus(cd);
mediaPresent = (cd->status!=CD_TRAYEMPTY) && (cd->status!=CD_ERROR);
mediaChanged = (oldLeadOut!=cd->track[cd->numtracks].offset);
@ -157,57 +155,38 @@ bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChan
oldLeadOut = cd->track[cd->numtracks].offset;
if (mediaChanged) SDL_CDStatus(cd);
return true;
#else
return false;
#endif
}
bool CDROM_Interface_SDL::PlayAudioSector(unsigned long start,unsigned long len) {
(void)start;//POSSIBLY UNUSED
(void)len;//POSSIBLY UNUSED
#if !defined(C_SDL2)
// 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,int(start+150u),int(len))==0);
return success;
#else
return false;
#endif
}
bool CDROM_Interface_SDL::PauseAudio(bool resume) {
(void)resume;//POSSIBLY UNUSED
#if !defined(C_SDL2)
bool success;
if (resume) success = (SDL_CDResume(cd)==0);
else success = (SDL_CDPause (cd)==0);
return success;
#else
return false;
#endif
}
bool CDROM_Interface_SDL::StopAudio(void) {
#if !defined(C_SDL2)
// 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;
#else
return false;
#endif
}
bool CDROM_Interface_SDL::LoadUnloadMedia(bool unload) {
(void)unload;//UNUSED
#if !defined(C_SDL2)
bool success = (SDL_CDEject(cd)==0);
return success;
#else
return false;
#endif
}
int CDROM_GetMountType(const char* path, int forceCD) {
@ -224,7 +203,6 @@ int CDROM_GetMountType(const char* path, int forceCD) {
upcase(buffer);
#endif
#if !defined(C_SDL2)
const char* cdName;
int num = SDL_CDNumDrives();
// If cd drive is forced then check if its in range and return 0
@ -238,7 +216,6 @@ int CDROM_GetMountType(const char* path, int forceCD) {
cdName = SDL_CDName(i);
if (strcmp(buffer,cdName)==0) return 0;
}
#endif
// Detect ISO
struct pref_stat file_stat;

View File

@ -55,6 +55,7 @@
*(M) = value; \
}
#define MSF_TO_FRAMES(M, S, F) ((M)*60*CD_FPS+(S)*CD_FPS+(F))
#include "../../vs2015/sdl/src/cdrom/compat_SDL_cdrom.h"
#endif /* C_SDL2 */
#define RAW_SECTOR_SIZE 2352
@ -180,10 +181,8 @@ private:
//! \brief Close the device
void Close (void);
#if !defined(C_SDL2)
//! \brief SDL 1.x CD-ROM device object
SDL_CD* cd = NULL;
#endif
int driveID = 0;
Uint32 oldLeadOut = 0;
};

View File

@ -908,13 +908,11 @@ public:
}
/* Show list of cdroms */
if (cmd->FindExist("-cd",false)) {
#if !defined(C_SDL2)
int num = SDL_CDNumDrives();
if (!quiet) WriteOut(MSG_Get("PROGRAM_MOUNT_CDROMS_FOUND"),num);
for (int i=0; i<num; i++) {
if (!quiet) WriteOut("%2d. %s\n",i,SDL_CDName(i));
}
#endif
return;
}

View File

@ -220,6 +220,7 @@ extern double rtdelta;
static LoopHandler* loop;
void increaseticks();
bool systemmessagebox(char const * aTitle, char const * aMessage, char const * aDialogType, char const * aIconType, int aDefaultButton);
/* The whole load of startups for all the subfunctions */
void MEM_Init(Section *);
@ -787,13 +788,7 @@ SlotPos currentSlot;
void notifyError(const std::string& message, bool log=true)
{
if (log) LOG_MSG("%s",message.c_str());
#if !defined(HX_DOS)
MAPPER_ReleaseAllKeys();
GFX_LosingFocus();
tinyfd_messageBox("Error",message.c_str(),"ok","error", 1);
MAPPER_ReleaseAllKeys();
GFX_LosingFocus();
#endif
systemmessagebox("Error",message.c_str(),"ok","error", 1);
}
size_t GetGameState(void) {
@ -922,6 +917,12 @@ void LoadGameState_Run(void) { LoadGameState(true); }
void NextSaveSlot_Run(void) { NextSaveSlot(true); }
void PreviousSaveSlot_Run(void) { PreviousSaveSlot(true); }
void ShowStateInfo(bool pressed) {
if (!pressed) return;
std::string message = "Save to: "+(use_save_file&&savefilename.size()?"File "+savefilename:"Slot "+std::to_string(GetGameState_Run()+1))+"\n"+SaveState::instance().getName(GetGameState_Run(), true);
systemmessagebox("Saved state information", message.c_str(), "ok","info", 1);
}
/* TODO: move to utility header */
#ifdef _MSC_VER /* Microsoft C++ does not have strtoull */
# if _MSC_VER < 1800 /* But Visual Studio 2013 apparently does (https://www.vogons.org/viewtopic.php?f=41&t=31881&sid=49ff69ebc0459ed6523f5a250daa4d8c&start=400#p355770) */
@ -1100,6 +1101,8 @@ void DOSBOX_RealInit() {
}
//add support for loading/saving game states
MAPPER_AddHandler(ShowStateInfo, MK_nothing, 0,"showstate","Display state info", &item);
item->set_text("Display state information");
MAPPER_AddHandler(SaveGameState, MK_s, MMODHOST,"savestate","Save state", &item);
item->set_text("Save state");
MAPPER_AddHandler(LoadGameState, MK_l, MMODHOST,"loadstate","Load state", &item);
@ -5500,13 +5503,7 @@ delete_all:
void savestatecorrupt(const char* part) {
LOG_MSG("Save state corrupted! Program in inconsistent state! - %s", part);
#if !defined(HX_DOS)
MAPPER_ReleaseAllKeys();
GFX_LosingFocus();
tinyfd_messageBox("Error","Save state corrupted! Program may not work.","ok","error", 1);
MAPPER_ReleaseAllKeys();
GFX_LosingFocus();
#endif
systemmessagebox("Error","Save state corrupted! Program may not work.","ok","error", 1);
}
bool confres=false;

View File

@ -611,7 +611,7 @@ static const char *def_menu_capture[] =
"mapper_loadstate",
"saveslotmenu",
"browsesavefile",
"showstate",
"mapper_showstate",
NULL
};

View File

@ -1217,7 +1217,7 @@ void RENDER_Init() {
DOSBoxMenu::item *item;
MAPPER_AddHandler(&AspectRatio_mapper_shortcut, MK_nothing, 0, "aspratio", "Aspect ratio", &item);
MAPPER_AddHandler(&AspectRatio_mapper_shortcut, MK_nothing, 0, "aspratio", "Fit to aspect ratio", &item);
item->set_text("Fit to aspect ratio");
mainMenu.get_item("vga_9widetext").check(vga.draw.char9_set).refresh_item(mainMenu);

View File

@ -4168,7 +4168,7 @@ void BIND_MappingEvents(void) {
tmpl = 0;
#if defined(WIN32)
# if defined(C_SDL2)
# else
# elif defined(SDL_DOSBOX_X_SPECIAL)
{
char nm[256];

View File

@ -107,6 +107,7 @@ void GFX_OpenGLRedrawScreen(void);
#include "shell.h"
#include "glidedef.h"
#include "inout.h"
#include "../dos/cdrom.h"
#include "../ints/int10.h"
#if !defined(HX_DOS)
#if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR)
@ -10600,14 +10601,6 @@ bool use_save_file_menu_callback(DOSBoxMenu * const menu, DOSBoxMenu::item * con
return true;
}
bool show_save_state_menu_callback(DOSBoxMenu * const menu, DOSBoxMenu::item * const menuitem) {
(void)menu;//UNUSED
(void)menuitem;//UNUSED
std::string message = "Save to: "+(use_save_file&&savefilename.size()?"File "+savefilename:"Slot "+std::to_string(GetGameState_Run()+1))+"\n"+SaveState::instance().getName(GetGameState_Run(), true);
systemmessagebox("Saved state information", message.c_str(), "ok","info", 1);
return true;
}
void refresh_slots() {
mainMenu.get_item("current_page").set_text("Current page: "+to_string(page+1)+"/10").refresh_item(mainMenu);
for (unsigned int i=0; i<SaveState::SLOT_COUNT; i++) {
@ -11737,11 +11730,13 @@ int main(int argc, char* argv[]) SDL_MAIN_NOEXCEPT {
sdl.num_joysticks = 0;
}
#if !defined(C_SDL2)
#if defined(C_SDL2)
if (Compat_SDL_CDROMInit() < 0) {
#else
if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0) {
#endif
LOG(LOG_GUI,LOG_WARN)("Failed to init CD-ROM support");
}
#endif
/* must redraw after modeset */
sdl.must_redraw_all = true;
@ -12192,7 +12187,6 @@ int main(int argc, char* argv[]) SDL_MAIN_NOEXCEPT {
mainMenu.alloc_item(DOSBoxMenu::item_type_id,"refreshslot").set_text("Refresh display status").set_callback_function(refresh_slots_menu_callback);
mainMenu.alloc_item(DOSBoxMenu::item_type_id, "usesavefile").set_text("Use save file instead of save slot").set_callback_function(use_save_file_menu_callback).check(use_save_file);
mainMenu.alloc_item(DOSBoxMenu::item_type_id, "browsesavefile").set_text("Browse save file...").set_callback_function(browse_save_file_menu_callback).enable(use_save_file);
mainMenu.alloc_item(DOSBoxMenu::item_type_id, "showstate").set_text("Display state information").set_callback_function(show_save_state_menu_callback);
{
mainMenu.alloc_item(DOSBoxMenu::item_type_id,"current_page").set_text("Current page: 1/10").enable(false).set_callback_function(refresh_slots_menu_callback);
mainMenu.alloc_item(DOSBoxMenu::item_type_id,"prev_page").set_text("Previous page").set_callback_function(prev_page_menu_callback);
@ -13066,6 +13060,9 @@ fresh_boot:
sdl_hax_macosx_setmenu(NULL);
#endif
#if defined(C_SDL2)
Compat_SDL_CDROMQuit();
#endif
SDL_Quit();//Let's hope sdl will quit as well when it catches an exception
#if defined(WIN32) && !defined(HX_DOS)

View File

@ -23,6 +23,8 @@
/* This is the system specific header for the SDL CD-ROM API */
#if !defined(CDCAPSDEF)
#define CDCAPSDEF 1
/* Structure of CD audio control functions */
extern struct CDcaps {
/* Get the name of the specified drive */
@ -60,6 +62,7 @@ extern struct CDcaps {
/* Close the specified drive */
void (*Close)(SDL_CD *cdrom);
} SDL_CDcaps;
#endif
/* The number of available CD-ROM drives on the system */
extern int SDL_numcds;

View File

@ -0,0 +1,343 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/*#include "SDL_config.h"*/
/* This is the CD-audio control API for Simple DirectMedia Layer */
#include "config.h"
#include "compat_SDL_cdrom.h"
#include "SDL_syscdrom.h"
#if !defined(__MACOS__)
#define CLIP_FRAMES 10 /* Some CD-ROMs won't go all the way */
#endif
static int SDL_cdinitted = 0;
static SDL_CD *default_cdrom;
/* The system level CD-ROM control functions */
extern struct CDcaps SDL_CDcaps = {
NULL, /* Name */
NULL, /* Open */
NULL, /* GetTOC */
NULL, /* Status */
NULL, /* Play */
NULL, /* Pause */
NULL, /* Resume */
NULL, /* Stop */
NULL, /* Eject */
NULL, /* Close */
};
int SDL_numcds;
int Compat_SDL_CDROMInit(void)
{
int retval;
SDL_numcds = 0;
retval = SDL_SYS_CDInit();
if ( retval == 0 ) {
SDL_cdinitted = 1;
}
default_cdrom = NULL;
return(retval);
}
/* Check to see if the CD-ROM subsystem has been initialized */
static int CheckInit(int check_cdrom, SDL_CD **cdrom)
{
int okay;
okay = SDL_cdinitted;
if ( check_cdrom && (*cdrom == NULL) ) {
*cdrom = default_cdrom;
if ( *cdrom == NULL ) {
SDL_SetError("CD-ROM not opened");
okay = 0;
}
}
if ( ! SDL_cdinitted ) {
SDL_SetError("CD-ROM subsystem not initialized");
}
return(okay);
}
int SDL_CDNumDrives(void)
{
if ( ! CheckInit(0, NULL) ) {
return(-1);
}
return(SDL_numcds);
}
const char *SDL_CDName(int drive)
{
if ( ! CheckInit(0, NULL) ) {
return(NULL);
}
if ( drive >= SDL_numcds ) {
SDL_SetError("Invalid CD-ROM drive index");
return(NULL);
}
if ( SDL_CDcaps.Name ) {
return(SDL_CDcaps.Name(drive));
} else {
return("");
}
}
SDL_CD *SDL_CDOpen(int drive)
{
struct SDL_CD *cdrom;
if ( ! CheckInit(0, NULL) ) {
return(NULL);
}
if ( drive >= SDL_numcds ) {
SDL_SetError("Invalid CD-ROM drive index");
return(NULL);
}
cdrom = (SDL_CD *)SDL_malloc(sizeof(*cdrom));
if ( cdrom == NULL ) {
SDL_OutOfMemory();
return(NULL);
}
SDL_memset(cdrom, 0, sizeof(*cdrom));
cdrom->id = SDL_CDcaps.Open(drive);
if ( cdrom->id < 0 ) {
SDL_free(cdrom);
return(NULL);
}
default_cdrom = cdrom;
return(cdrom);
}
CDstatus SDL_CDStatus(SDL_CD *cdrom)
{
CDstatus status;
int i;
Uint32 position;
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return(CD_ERROR);
}
/* Get the current status of the drive */
cdrom->numtracks = 0;
cdrom->cur_track = 0;
cdrom->cur_frame = 0;
status = SDL_CDcaps.Status(cdrom, &i);
position = (Uint32)i;
cdrom->status = status;
/* Get the table of contents, if there's a CD available */
if ( CD_INDRIVE(status) ) {
if ( SDL_CDcaps.GetTOC(cdrom) < 0 ) {
status = CD_ERROR;
}
/* If the drive is playing, get current play position */
if ( (status == CD_PLAYING) || (status == CD_PAUSED) ) {
for ( i=1; cdrom->track[i].offset <= position; ++i ) {
/* Keep looking */;
}
#ifdef DEBUG_CDROM
fprintf(stderr, "Current position: %d, track = %d (offset is %d)\n",
position, i-1, cdrom->track[i-1].offset);
#endif
cdrom->cur_track = i-1;
position -= cdrom->track[cdrom->cur_track].offset;
cdrom->cur_frame = position;
}
}
return(status);
}
int SDL_CDPlayTracks(SDL_CD *cdrom,
int strack, int sframe, int ntracks, int nframes)
{
int etrack, eframe;
int start, length;
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return(CD_ERROR);
}
/* Determine the starting and ending tracks */
if ( (strack < 0) || (strack >= cdrom->numtracks) ) {
SDL_SetError("Invalid starting track");
return(CD_ERROR);
}
if ( ! ntracks && ! nframes ) {
etrack = cdrom->numtracks;
eframe = 0;
} else {
etrack = strack+ntracks;
if ( etrack == strack ) {
eframe = sframe + nframes;
} else {
eframe = nframes;
}
}
if ( etrack > cdrom->numtracks ) {
SDL_SetError("Invalid play length");
return(CD_ERROR);
}
/* Skip data tracks and verify frame offsets */
while ( (strack <= etrack) &&
(cdrom->track[strack].type == SDL_DATA_TRACK) ) {
++strack;
}
if ( sframe >= (int)cdrom->track[strack].length ) {
SDL_SetError("Invalid starting frame for track %d", strack);
return(CD_ERROR);
}
while ( (etrack > strack) &&
(cdrom->track[etrack-1].type == SDL_DATA_TRACK) ) {
--etrack;
}
if ( eframe > (int)cdrom->track[etrack].length ) {
SDL_SetError("Invalid ending frame for track %d", etrack);
return(CD_ERROR);
}
/* Determine start frame and play length */
start = (cdrom->track[strack].offset+sframe);
length = (cdrom->track[etrack].offset+eframe)-start;
#ifdef CLIP_FRAMES
/* I've never seen this necessary, but xmcd does it.. */
length -= CLIP_FRAMES; /* CLIP_FRAMES == 10 */
#endif
if ( length < 0 ) {
return(0);
}
/* Play! */
#ifdef DEBUG_CDROM
fprintf(stderr, "Playing %d frames at offset %d\n", length, start);
#endif
return(SDL_CDcaps.Play(cdrom, start, length));
}
int SDL_CDPlay(SDL_CD *cdrom, int sframe, int length)
{
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return(CD_ERROR);
}
return(SDL_CDcaps.Play(cdrom, sframe, length));
}
int SDL_CDPause(SDL_CD *cdrom)
{
CDstatus status;
int retval;
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return(CD_ERROR);
}
status = SDL_CDcaps.Status(cdrom, NULL);
switch (status) {
case CD_PLAYING:
retval = SDL_CDcaps.Pause(cdrom);
break;
default:
retval = 0;
break;
}
return(retval);
}
int SDL_CDResume(SDL_CD *cdrom)
{
CDstatus status;
int retval;
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return(CD_ERROR);
}
status = SDL_CDcaps.Status(cdrom, NULL);
switch (status) {
case CD_PAUSED:
retval = SDL_CDcaps.Resume(cdrom);
default:
retval = 0;
break;
}
return(retval);
}
int SDL_CDStop(SDL_CD *cdrom)
{
CDstatus status;
int retval;
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return(CD_ERROR);
}
status = SDL_CDcaps.Status(cdrom, NULL);
switch (status) {
case CD_PLAYING:
case CD_PAUSED:
retval = SDL_CDcaps.Stop(cdrom);
default:
retval = 0;
break;
}
return(retval);
}
int SDL_CDEject(SDL_CD *cdrom)
{
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return(CD_ERROR);
}
return(SDL_CDcaps.Eject(cdrom));
}
void SDL_CDClose(SDL_CD *cdrom)
{
/* Check if the CD-ROM subsystem has been initialized */
if ( ! CheckInit(1, &cdrom) ) {
return;
}
SDL_CDcaps.Close(cdrom);
SDL_free(cdrom);
default_cdrom = NULL;
}
void Compat_SDL_CDROMQuit(void)
{
SDL_SYS_CDQuit();
SDL_cdinitted = 0;
}

View File

@ -0,0 +1,206 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/**
* @file SDL_cdrom.h
* This is the CD-audio control API for Simple DirectMedia Layer
*/
#ifndef _SDL_cdrom_h
#define _SDL_cdrom_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
/*#include "begin_code.h"*/
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file SDL_cdrom.h
* In order to use these functions (original SDL 1.2 revision), SDL_Init()
* must have been called with the SDL_INIT_CDROM flag. This causes SDL to
* scan the system for CD-ROM drives, and load appropriate drivers.
*/
/** The maximum number of CD-ROM tracks on a disk */
#define SDL_MAX_TRACKS 99
/** @name Track Types
* The types of CD-ROM track possible
*/
/*@{*/
#define SDL_AUDIO_TRACK 0x00
#define SDL_DATA_TRACK 0x04
/*@}*/
/** The possible states which a CD-ROM drive can be in. */
typedef enum {
CD_TRAYEMPTY,
CD_STOPPED,
CD_PLAYING,
CD_PAUSED,
CD_ERROR = -1
} CDstatus;
/** Given a status, returns true if there's a disk in the drive */
#define CD_INDRIVE(status) ((int)(status) > 0)
typedef struct SDL_CDtrack {
Uint8 id; /**< Track number */
Uint8 type; /**< Data or audio track */
Uint16 unused;
Uint32 length; /**< Length, in frames, of this track */
Uint32 offset; /**< Offset, in frames, from start of disk */
} SDL_CDtrack;
/** This structure is only current as of the last call to SDL_CDStatus() */
typedef struct SDL_CD {
int id; /**< Private drive identifier */
CDstatus status; /**< Current drive status */
/** The rest of this structure is only valid if there's a CD in drive */
/*@{*/
int numtracks; /**< Number of tracks on disk */
int cur_track; /**< Current track position */
int cur_frame; /**< Current frame offset within current track */
SDL_CDtrack track[SDL_MAX_TRACKS+1];
/*@}*/
} SDL_CD;
/** @name Frames / MSF Conversion Functions
* Conversion functions from frames to Minute/Second/Frames and vice versa
*/
/*@{*/
#define CD_FPS 75
#define FRAMES_TO_MSF(f, M,S,F) { \
int value = f; \
*(F) = value%CD_FPS; \
value /= CD_FPS; \
*(S) = value%60; \
value /= 60; \
*(M) = value; \
}
#define MSF_TO_FRAMES(M, S, F) ((M)*60*CD_FPS+(S)*CD_FPS+(F))
/*@}*/
/* Compatibility functions (used separately from the SDL_InitQuit rountines) */
extern int Compat_SDL_CDROMInit(void);
extern void Compat_SDL_CDROMQuit(void);
/* CD-audio API functions: */
/**
* Returns the number of CD-ROM drives on the system, or -1 if
* SDL_Init() has not been called with the SDL_INIT_CDROM flag.
*/
extern /*DECLSPEC*/ int /*SDLCALL*/ SDL_CDNumDrives(void);
/**
* Returns a human-readable, system-dependent identifier for the CD-ROM.
* Example:
* - "/dev/cdrom"
* - "E:"
* - "/dev/disk/ide/1/master"
*/
extern /*DECLSPEC*/ const char * /*SDLCALL*/ SDL_CDName(int drive);
/**
* Opens a CD-ROM drive for access. It returns a drive handle on success,
* or NULL if the drive was invalid or busy. This newly opened CD-ROM
* becomes the default CD used when other CD functions are passed a NULL
* CD-ROM handle.
* Drives are numbered starting with 0. Drive 0 is the system default CD-ROM.
*/
extern /*DECLSPEC*/ SDL_CD * /*SDLCALL*/ SDL_CDOpen(int drive);
/**
* This function returns the current status of the given drive.
* If the drive has a CD in it, the table of contents of the CD and current
* play position of the CD will be stored in the SDL_CD structure.
*/
extern /*DECLSPEC*/ CDstatus /*SDLCALL*/ SDL_CDStatus(SDL_CD *cdrom);
/**
* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
* tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play
* until the end of the CD. This function will skip data tracks.
* This function should only be called after calling SDL_CDStatus() to
* get track information about the CD.
* For example:
* @code
* // Play entire CD:
* if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
* SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
* // Play last track:
* if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
* SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
* }
* // Play first and second track and 10 seconds of third track:
* if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
* SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
* @endcode
*
* @return This function returns 0, or -1 if there was an error.
*/
extern /*DECLSPEC*/ int /*SDLCALL*/ SDL_CDPlayTracks(SDL_CD *cdrom,
int start_track, int start_frame, int ntracks, int nframes);
/**
* Play the given CD starting at 'start' frame for 'length' frames.
* @return It returns 0, or -1 if there was an error.
*/
extern /*DECLSPEC*/ int /*SDLCALL*/ SDL_CDPlay(SDL_CD *cdrom, int start, int length);
/** Pause play
* @return returns 0, or -1 on error
*/
extern /*DECLSPEC*/ int /*SDLCALL*/ SDL_CDPause(SDL_CD *cdrom);
/** Resume play
* @return returns 0, or -1 on error
*/
extern DECLSPEC int /*SDLCALL*/ SDL_CDResume(SDL_CD *cdrom);
/** Stop play
* @return returns 0, or -1 on error
*/
extern /*DECLSPEC*/ int /*SDLCALL*/ SDL_CDStop(SDL_CD *cdrom);
/** Eject CD-ROM
* @return returns 0, or -1 on error
*/
extern /*DECLSPEC*/ int /*SDLCALL*/ SDL_CDEject(SDL_CD *cdrom);
/** Closes the handle for the CD-ROM drive */
extern /*DECLSPEC*/ void /*SDLCALL*/ SDL_CDClose(SDL_CD *cdrom);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
/*#include "close_code.h"*/
#endif /* _SDL_video_h */