src/cdrom/qnx/SDL_syscdrom.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@1635
    24
#ifdef SDL_CDROM_QNX
slouken@1635
    25
slouken@0
    26
/* Functions for system-level CD-ROM audio control */
slouken@0
    27
slouken@0
    28
#include <sys/types.h>
slouken@0
    29
#include <sys/stat.h>
slouken@0
    30
#include <sys/ioctl.h>
slouken@0
    31
#include <fcntl.h>
slouken@571
    32
#include <errno.h>
slouken@0
    33
#include <unistd.h>
slouken@0
    34
#include <sys/cdrom.h>
slouken@0
    35
#include <sys/dcmd_cam.h>
slouken@0
    36
slouken@1358
    37
#include "SDL_timer.h"
slouken@0
    38
#include "SDL_cdrom.h"
slouken@1361
    39
#include "../SDL_syscdrom.h"
slouken@0
    40
slouken@571
    41
/* The maximum number of CD-ROM drives we'll detect */
slouken@571
    42
#define MAX_DRIVES 16
slouken@0
    43
slouken@571
    44
#define QNX_CD_OPENMODE O_RDONLY | O_EXCL
slouken@0
    45
slouken@0
    46
/* A list of available CD-ROM drives */
slouken@0
    47
static char *SDL_cdlist[MAX_DRIVES];
slouken@0
    48
static dev_t SDL_cdmode[MAX_DRIVES];
slouken@1662
    49
static int SDL_cdopen[MAX_DRIVES];
slouken@0
    50
slouken@0
    51
/* The system-dependent CD control functions */
slouken@1668
    52
static const char *SDL_SYS_CDName(int drive);
slouken@1668
    53
static int SDL_SYS_CDOpen(int drive);
slouken@1668
    54
static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
slouken@1668
    55
static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
slouken@1668
    56
static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
slouken@1668
    57
static int SDL_SYS_CDPause(SDL_CD * cdrom);
slouken@1668
    58
static int SDL_SYS_CDResume(SDL_CD * cdrom);
slouken@1668
    59
static int SDL_SYS_CDStop(SDL_CD * cdrom);
slouken@1668
    60
static int SDL_SYS_CDEject(SDL_CD * cdrom);
slouken@1668
    61
static void SDL_SYS_CDClose(SDL_CD * cdrom);
slouken@0
    62
slouken@571
    63
/* Check a drive to see if it is a CD-ROM */
slouken@1662
    64
static int
slouken@1668
    65
CheckDrive(char *drive, struct stat *stbuf)
slouken@571
    66
{
slouken@571
    67
    int is_cd, cdfd;
slouken@571
    68
    cam_devinfo_t dinfo;
slouken@1662
    69
    int devctlret = 0;
slouken@0
    70
slouken@571
    71
    int atapi;
slouken@571
    72
    int removable;
slouken@571
    73
    int cdb10;
slouken@0
    74
slouken@571
    75
    /* If it doesn't exist, return -1 */
slouken@1668
    76
    if (stat(drive, stbuf) < 0) {
slouken@1662
    77
        return (-1);
slouken@571
    78
    }
slouken@0
    79
slouken@571
    80
    /* If it does exist, verify that it's an available CD-ROM */
slouken@571
    81
    is_cd = 0;
slouken@571
    82
slouken@1668
    83
    if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
slouken@1668
    84
        cdfd = open(drive, QNX_CD_OPENMODE);
slouken@1662
    85
        if (cdfd >= 0) {
slouken@1662
    86
            devctlret =
slouken@1668
    87
                devctl(cdfd, DCMD_CAM_DEVINFO, &dinfo,
slouken@1668
    88
                       sizeof(cam_devinfo_t), NULL);
slouken@571
    89
slouken@1662
    90
            if (devctlret == EOK) {
slouken@1662
    91
                atapi = dinfo.flags & DEV_ATAPI;
slouken@1662
    92
                removable = dinfo.flags & DEV_REMOVABLE;
slouken@1662
    93
                cdb10 = dinfo.flags & DEV_CDB_10;       /* I'm not sure about that flag */
slouken@571
    94
slouken@1662
    95
                /* in the near future need to add more checks for splitting cdroms from other devices */
slouken@1662
    96
                if ((atapi) && (removable)) {
slouken@1662
    97
                    is_cd = 1;
slouken@1662
    98
                }
slouken@571
    99
            }
slouken@571
   100
slouken@1668
   101
            close(cdfd);
slouken@571
   102
        }
slouken@571
   103
    }
slouken@1662
   104
    return (is_cd);
slouken@0
   105
}
slouken@0
   106
slouken@0
   107
/* Add a CD-ROM drive to our list of valid drives */
slouken@1662
   108
static void
slouken@1668
   109
AddDrive(char *drive, struct stat *stbuf)
slouken@0
   110
{
slouken@571
   111
    int i;
slouken@0
   112
slouken@1662
   113
    if (SDL_numcds < MAX_DRIVES) {
slouken@571
   114
        /* Check to make sure it's not already in our list.
slouken@1662
   115
           This can happen when we see a drive via symbolic link. */
slouken@0
   116
slouken@1662
   117
        for (i = 0; i < SDL_numcds; ++i) {
slouken@1662
   118
            if (stbuf->st_rdev == SDL_cdmode[i]) {
slouken@571
   119
                return;
slouken@571
   120
            }
slouken@571
   121
        }
slouken@571
   122
slouken@571
   123
        /* Add this drive to our list */
slouken@571
   124
slouken@571
   125
        i = SDL_numcds;
slouken@1668
   126
        SDL_cdlist[i] = SDL_strdup(drive);
slouken@1662
   127
        if (SDL_cdlist[i] == NULL) {
slouken@1668
   128
            SDL_OutOfMemory();
slouken@571
   129
            return;
slouken@571
   130
        }
slouken@571
   131
        SDL_cdmode[i] = stbuf->st_rdev;
slouken@571
   132
        ++SDL_numcds;
slouken@571
   133
    }
slouken@0
   134
}
slouken@0
   135
slouken@1662
   136
int
slouken@1668
   137
SDL_SYS_CDInit(void)
slouken@0
   138
{
slouken@571
   139
    /* checklist: /dev/cdrom, /dev/cd?, /dev/scd? */
slouken@1662
   140
    static char *checklist[] =
slouken@1662
   141
        { "cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL };
slouken@0
   142
slouken@571
   143
    char *SDLcdrom;
slouken@571
   144
    int i, j, exists;
slouken@571
   145
    char drive[32];
slouken@571
   146
    struct stat stbuf;
slouken@0
   147
slouken@571
   148
    /* Fill in our driver capabilities */
slouken@571
   149
    SDL_CDcaps.Name = SDL_SYS_CDName;
slouken@571
   150
    SDL_CDcaps.Open = SDL_SYS_CDOpen;
slouken@571
   151
    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
slouken@571
   152
    SDL_CDcaps.Status = SDL_SYS_CDStatus;
slouken@571
   153
    SDL_CDcaps.Play = SDL_SYS_CDPlay;
slouken@571
   154
    SDL_CDcaps.Pause = SDL_SYS_CDPause;
slouken@571
   155
    SDL_CDcaps.Resume = SDL_SYS_CDResume;
slouken@571
   156
    SDL_CDcaps.Stop = SDL_SYS_CDStop;
slouken@571
   157
    SDL_CDcaps.Eject = SDL_SYS_CDEject;
slouken@571
   158
    SDL_CDcaps.Close = SDL_SYS_CDClose;
slouken@0
   159
slouken@571
   160
    /* clearing device open status */
slouken@1662
   161
    for (i = 0; i < MAX_DRIVES; i++) {
slouken@1662
   162
        SDL_cdopen[i] = 0;
slouken@571
   163
    }
slouken@0
   164
slouken@571
   165
    /* Look in the environment for our CD-ROM drive list */
slouken@1668
   166
    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
slouken@1662
   167
    if (SDLcdrom != NULL) {
slouken@571
   168
        char *cdpath, *delim;
slouken@1668
   169
        size_t len = SDL_strlen(SDLcdrom) + 1;
slouken@1668
   170
        cdpath = SDL_stack_alloc(char, len);
slouken@1662
   171
        if (cdpath != NULL) {
slouken@1668
   172
            SDL_strlcpy(cdpath, SDLcdrom, len);
slouken@571
   173
            SDLcdrom = cdpath;
slouken@571
   174
            do {
slouken@1668
   175
                delim = SDL_strchr(SDLcdrom, ':');
slouken@1662
   176
                if (delim) {
slouken@571
   177
                    *delim++ = '\0';
slouken@571
   178
                }
slouken@1668
   179
                if (CheckDrive(SDLcdrom, &stbuf) > 0) {
slouken@1668
   180
                    AddDrive(SDLcdrom, &stbuf);
slouken@571
   181
                }
slouken@1662
   182
                if (delim) {
slouken@571
   183
                    SDLcdrom = delim;
slouken@1662
   184
                } else {
slouken@571
   185
                    SDLcdrom = NULL;
slouken@571
   186
                }
slouken@1662
   187
            }
slouken@1662
   188
            while (SDLcdrom);
slouken@1668
   189
            SDL_stack_free(cdpath);
slouken@571
   190
        }
slouken@571
   191
slouken@571
   192
        /* If we found our drives, there's nothing left to do */
slouken@1662
   193
        if (SDL_numcds > 0) {
slouken@1662
   194
            return (0);
slouken@571
   195
        }
slouken@571
   196
    }
slouken@571
   197
slouken@571
   198
    /* Scan the system for CD-ROM drives */
slouken@1662
   199
    for (i = 0; checklist[i]; ++i) {
slouken@1662
   200
        if (checklist[i][0] == '?') {
slouken@1662
   201
            char *insert;
slouken@571
   202
            exists = 1;
slouken@571
   203
slouken@1662
   204
            for (j = checklist[i][1]; exists; ++j) {
slouken@1668
   205
                SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
slouken@1668
   206
                             &checklist[i][3]);
slouken@1668
   207
                insert = SDL_strchr(drive, '?');
slouken@1662
   208
                if (insert != NULL) {
slouken@571
   209
                    *insert = j;
slouken@571
   210
                }
slouken@1668
   211
                switch (CheckDrive(drive, &stbuf)) {
slouken@571
   212
                    /* Drive exists and is a CD-ROM */
slouken@1662
   213
                case 1:
slouken@1668
   214
                    AddDrive(drive, &stbuf);
slouken@1662
   215
                    break;
slouken@571
   216
                    /* Drive exists, but isn't a CD-ROM */
slouken@1662
   217
                case 0:
slouken@1662
   218
                    break;
slouken@571
   219
                    /* Drive doesn't exist */
slouken@1662
   220
                case -1:
slouken@1662
   221
                    exists = 0;
slouken@1662
   222
                    break;
slouken@571
   223
                }
slouken@571
   224
            }
slouken@1662
   225
        } else {
slouken@1668
   226
            SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
slouken@1668
   227
                         checklist[i]);
slouken@1668
   228
            if (CheckDrive(drive, &stbuf) > 0) {
slouken@1668
   229
                AddDrive(drive, &stbuf);
slouken@571
   230
            }
slouken@571
   231
        }
slouken@571
   232
    }
slouken@1662
   233
    return (0);
slouken@0
   234
}
slouken@0
   235
slouken@1662
   236
static const char *
slouken@1668
   237
SDL_SYS_CDName(int drive)
slouken@0
   238
{
slouken@1662
   239
    return (SDL_cdlist[drive]);
slouken@0
   240
}
slouken@0
   241
slouken@1662
   242
static int
slouken@1668
   243
SDL_SYS_CDOpen(int drive)
slouken@0
   244
{
slouken@571
   245
    int handle;
slouken@571
   246
slouken@1668
   247
    handle = open(SDL_cdlist[drive], QNX_CD_OPENMODE);
slouken@571
   248
slouken@1662
   249
    if (handle > 0) {
slouken@1662
   250
        SDL_cdopen[drive] = handle;
slouken@571
   251
    }
slouken@571
   252
slouken@571
   253
    return (handle);
slouken@0
   254
}
slouken@0
   255
slouken@1662
   256
static int
slouken@1668
   257
SDL_SYS_CDGetTOC(SDL_CD * cdrom)
slouken@0
   258
{
slouken@571
   259
    cdrom_read_toc_t toc;
slouken@571
   260
    int i, okay;
slouken@0
   261
slouken@571
   262
    okay = 0;
slouken@1668
   263
    if (devctl(cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc), NULL) ==
slouken@1662
   264
        0) {
slouken@571
   265
        cdrom->numtracks = toc.last_track - toc.first_track + 1;
slouken@1662
   266
        if (cdrom->numtracks > SDL_MAX_TRACKS) {
slouken@571
   267
            cdrom->numtracks = SDL_MAX_TRACKS;
slouken@571
   268
        }
slouken@571
   269
        /* Read all the track TOC entries */
slouken@1662
   270
        for (i = 0; i <= cdrom->numtracks; ++i) {
slouken@1662
   271
            if (i == cdrom->numtracks) {
slouken@571
   272
                cdrom->track[i].id = CDROM_LEADOUT;
slouken@1662
   273
            } else {
slouken@1662
   274
                cdrom->track[i].id = toc.first_track + i;
slouken@571
   275
            }
slouken@571
   276
slouken@571
   277
            cdrom->track[i].type = toc.toc_entry[i].control_adr & 0x0F;
slouken@571
   278
            cdrom->track[i].offset = toc.toc_entry[i].addr.lba;
slouken@571
   279
            cdrom->track[i].length = 0;
slouken@571
   280
slouken@1662
   281
            if (i > 0) {
slouken@1662
   282
                cdrom->track[i - 1].length =
slouken@1662
   283
                    cdrom->track[i].offset - cdrom->track[i - 1].offset;
slouken@571
   284
            }
slouken@571
   285
        }
slouken@1662
   286
        if (i == (cdrom->numtracks + 1)) {
slouken@571
   287
            okay = 1;
slouken@571
   288
        }
slouken@571
   289
    }
slouken@571
   290
    return (okay ? 0 : -1);
slouken@0
   291
}
slouken@0
   292
slouken@0
   293
/* Get CD-ROM status */
slouken@1662
   294
static CDstatus
slouken@1668
   295
SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
slouken@0
   296
{
slouken@571
   297
    CDstatus status;
slouken@0
   298
slouken@571
   299
    cdrom_read_toc_t toc;
slouken@571
   300
    cdrom_subch_data_t info;
slouken@571
   301
    cam_devinfo_t dinfo;
slouken@571
   302
slouken@1662
   303
    int devctlret = 0;
slouken@1662
   304
    int drive = -1;
slouken@571
   305
    int i;
slouken@1662
   306
    int eagaincnt = 0;
slouken@571
   307
slouken@571
   308
    /* check media presence before read subchannel call, some cdroms can lockups */
slouken@571
   309
    /* if no media, while calling read subchannel functions.                     */
slouken@1662
   310
    devctlret =
slouken@1668
   311
        devctl(cdrom->id, DCMD_CAM_DEVINFO, &dinfo, sizeof(cam_devinfo_t),
slouken@1668
   312
               NULL);
slouken@571
   313
slouken@1662
   314
    if (devctlret == EOK) {
slouken@1662
   315
        if ((dinfo.flags & DEV_NO_MEDIA) != 0) {
slouken@571
   316
            status = CD_TRAYEMPTY;
slouken@1662
   317
            if (position) {
slouken@571
   318
                *position = 0;
slouken@571
   319
            }
slouken@571
   320
            return (status);
slouken@571
   321
        }
slouken@571
   322
    }
slouken@571
   323
slouken@571
   324
    /* if media exists, then do other stuff */
slouken@571
   325
slouken@1668
   326
    SDL_memset(&info, 0x00, sizeof(info));
slouken@571
   327
    info.subch_command.data_format = CDROM_SUBCH_CURRENT_POSITION;
slouken@571
   328
slouken@571
   329
    do {
slouken@1662
   330
        devctlret =
slouken@1668
   331
            devctl(cdrom->id, DCMD_CAM_CDROMSUBCHNL, &info, sizeof(info),
slouken@1668
   332
                   NULL);
slouken@1662
   333
        if (devctlret == EIO) {
slouken@571
   334
            /* big workaround for media change, handle is unusable after that,
slouken@571
   335
               that bug was found in QNX 6.2, 6.2.1 is not released yet.    */
slouken@571
   336
slouken@1662
   337
            for (i = 0; i < MAX_DRIVES; i++) {
slouken@1662
   338
                if (SDL_cdopen[i] == cdrom->id) {
slouken@1662
   339
                    drive = i;
slouken@571
   340
                    break;
slouken@571
   341
                }
slouken@571
   342
            }
slouken@1662
   343
            if (drive == -1) {
slouken@1662
   344
                /* that cannot happen, but ... */
slouken@1662
   345
                break;
slouken@571
   346
            }
slouken@1668
   347
            close(cdrom->id);
slouken@1668
   348
            cdrom->id = open(SDL_cdlist[drive], QNX_CD_OPENMODE);
slouken@1662
   349
            devctlret = EAGAIN;
slouken@571
   350
        }
slouken@1662
   351
        if (devctlret == EAGAIN) {
slouken@571
   352
            eagaincnt++;
slouken@571
   353
        }
slouken@1662
   354
        if (eagaincnt == 2) {
slouken@571
   355
            /* workaround for broken cdroms, which can return always EAGAIN when its not ready, */
slouken@571
   356
            /* that mean errornous media or just no media avail                                 */
slouken@1662
   357
            devctlret = ENXIO;
slouken@571
   358
            break;
slouken@571
   359
        }
slouken@1662
   360
    }
slouken@1662
   361
    while ((devctlret == EAGAIN) || (devctlret == ESTALE));
slouken@571
   362
slouken@1662
   363
    if (devctlret != 0) {
slouken@1662
   364
        if (devctlret == ENXIO) {
slouken@571
   365
            status = CD_TRAYEMPTY;
slouken@1662
   366
        } else {
slouken@571
   367
            status = CD_ERROR;
slouken@571
   368
        }
slouken@1662
   369
    } else {
slouken@1662
   370
        switch (info.current_position.header.audio_status) {
slouken@1662
   371
        case CDROM_AUDIO_INVALID:
slouken@1662
   372
        case CDROM_AUDIO_NO_STATUS:
slouken@1662
   373
            /* Try to determine if there's a CD available */
slouken@1662
   374
            if (devctl
slouken@1668
   375
                (cdrom->id, DCMD_CAM_CDROMREADTOC, &toc, sizeof(toc),
slouken@1662
   376
                 NULL) == 0)
slouken@1662
   377
                status = CD_STOPPED;
slouken@1662
   378
            else
slouken@1662
   379
                status = CD_TRAYEMPTY;
slouken@1662
   380
            break;
slouken@1662
   381
        case CDROM_AUDIO_COMPLETED:
slouken@1662
   382
            status = CD_STOPPED;
slouken@1662
   383
            break;
slouken@1662
   384
        case CDROM_AUDIO_PLAY:
slouken@1662
   385
            status = CD_PLAYING;
slouken@1662
   386
            break;
slouken@1662
   387
        case CDROM_AUDIO_PAUSED:
slouken@1662
   388
            /* Workaround buggy CD-ROM drive */
slouken@1662
   389
            if (info.current_position.data_format == CDROM_LEADOUT) {
slouken@1662
   390
                status = CD_STOPPED;
slouken@1662
   391
            } else {
slouken@1662
   392
                status = CD_PAUSED;
slouken@1662
   393
            }
slouken@1662
   394
            break;
slouken@1662
   395
        default:
slouken@1662
   396
            status = CD_ERROR;
slouken@1662
   397
            break;
slouken@571
   398
        }
slouken@571
   399
    }
slouken@571
   400
slouken@1662
   401
    if (position) {
slouken@1662
   402
        if (status == CD_PLAYING || (status == CD_PAUSED)) {
slouken@1662
   403
            *position =
slouken@1668
   404
                MSF_TO_FRAMES(info.current_position.addr.msf.minute,
slouken@1668
   405
                              info.current_position.addr.msf.second,
slouken@1668
   406
                              info.current_position.addr.msf.frame);
slouken@1662
   407
        } else {
slouken@1662
   408
            *position = 0;
slouken@1662
   409
        }
slouken@571
   410
    }
slouken@571
   411
slouken@571
   412
    return (status);
slouken@0
   413
}
slouken@0
   414
slouken@0
   415
/* Start play */
slouken@1662
   416
static int
slouken@1668
   417
SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
slouken@0
   418
{
slouken@571
   419
    cdrom_playmsf_t playtime;
slouken@0
   420
slouken@1668
   421
    FRAMES_TO_MSF(start, &playtime.start_minute, &playtime.start_second,
slouken@1668
   422
                  &playtime.start_frame);
slouken@1668
   423
    FRAMES_TO_MSF(start + length, &playtime.end_minute, &playtime.end_second,
slouken@1668
   424
                  &playtime.end_frame);
slouken@571
   425
slouken@1662
   426
    if (devctl
slouken@1668
   427
        (cdrom->id, DCMD_CAM_CDROMPLAYMSF, &playtime, sizeof(playtime),
slouken@1662
   428
         NULL) != 0) {
slouken@1662
   429
        return -1;
slouken@1662
   430
    } else {
slouken@1662
   431
        return 0;
slouken@571
   432
    }
slouken@0
   433
}
slouken@0
   434
slouken@0
   435
/* Pause play */
slouken@1662
   436
static int
slouken@1668
   437
SDL_SYS_CDPause(SDL_CD * cdrom)
slouken@0
   438
{
slouken@1668
   439
    if (devctl(cdrom->id, DCMD_CAM_CDROMPAUSE, NULL, 0, NULL) != 0) {
slouken@1662
   440
        return -1;
slouken@1662
   441
    } else {
slouken@1662
   442
        return 0;
slouken@571
   443
    }
slouken@0
   444
}
slouken@0
   445
slouken@0
   446
/* Resume play */
slouken@1662
   447
static int
slouken@1668
   448
SDL_SYS_CDResume(SDL_CD * cdrom)
slouken@0
   449
{
slouken@1668
   450
    if (devctl(cdrom->id, DCMD_CAM_CDROMRESUME, NULL, 0, NULL) != 0) {
slouken@1662
   451
        return -1;
slouken@1662
   452
    } else {
slouken@1662
   453
        return 0;
slouken@571
   454
    }
slouken@0
   455
}
slouken@0
   456
slouken@0
   457
/* Stop play */
slouken@1662
   458
static int
slouken@1668
   459
SDL_SYS_CDStop(SDL_CD * cdrom)
slouken@0
   460
{
slouken@1668
   461
    if (devctl(cdrom->id, DCMD_CAM_CDROMSTOP, NULL, 0, NULL) != 0) {
slouken@1662
   462
        return -1;
slouken@1662
   463
    } else {
slouken@1662
   464
        return 0;
slouken@571
   465
    }
slouken@0
   466
}
slouken@0
   467
slouken@0
   468
/* Eject the CD-ROM */
slouken@1662
   469
static int
slouken@1668
   470
SDL_SYS_CDEject(SDL_CD * cdrom)
slouken@0
   471
{
slouken@1668
   472
    if (devctl(cdrom->id, DCMD_CAM_EJECT_MEDIA, NULL, 0, NULL) != 0) {
slouken@1662
   473
        return -1;
slouken@1662
   474
    } else {
slouken@1662
   475
        return 0;
slouken@571
   476
    }
slouken@0
   477
}
slouken@0
   478
slouken@0
   479
/* Close the CD-ROM handle */
slouken@1662
   480
static void
slouken@1668
   481
SDL_SYS_CDClose(SDL_CD * cdrom)
slouken@0
   482
{
slouken@571
   483
    int i;
slouken@571
   484
slouken@1662
   485
    for (i = 0; i < MAX_DRIVES; i++) {
slouken@1662
   486
        if (SDL_cdopen[i] == cdrom->id) {
slouken@1662
   487
            SDL_cdopen[i] = 0;
slouken@1662
   488
            break;
slouken@1662
   489
        }
slouken@571
   490
    }
slouken@571
   491
slouken@1668
   492
    close(cdrom->id);
slouken@0
   493
}
slouken@0
   494
slouken@1662
   495
void
slouken@1668
   496
SDL_SYS_CDQuit(void)
slouken@0
   497
{
slouken@571
   498
    int i;
slouken@0
   499
slouken@1662
   500
    if (SDL_numcds > 0) {
slouken@1662
   501
        for (i = 0; i < SDL_numcds; ++i) {
slouken@1668
   502
            SDL_free(SDL_cdlist[i]);
slouken@571
   503
        }
slouken@571
   504
        SDL_numcds = 0;
slouken@571
   505
    }
slouken@0
   506
}
slouken@1635
   507
slouken@1635
   508
#endif /* SDL_CDROM_QNX */
slouken@1662
   509
/* vi: set ts=4 sw=4 expandtab: */