Search
lxdream.org :: lxdream/src/gdrom/mmc.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/mmc.c
changeset 720:b5594d1ac80a
next722:1a16b3914508
author nkeynes
date Sat Jul 05 11:57:36 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Get OS X cdrom driver to the 'sort of working' stage. Hide most of the IOKit
fun in a separate osx_iokit module.
view annotate diff log raw
     1 /**
     2  * $Id: mmc.c 662 2008-03-02 11:38:08Z nkeynes $
     3  *
     4  * MMC host-side support functions.
     5  *
     6  * Copyright (c) 2008 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include "gdrom/gddriver.h"
    20 #include "gdrom/packet.h"
    22 #define MSFTOLBA( m,s,f ) (f + (s*CD_FRAMES_PER_SECOND) + (m*CD_FRAMES_PER_MINUTE))
    24 void mmc_make_read_cd_cmd( char *cmd, uint32_t real_sector, int mode )
    25 {
    26     cmd[0] = 0xBE;
    27     cmd[1] = (mode & 0x0E) << 1;
    28     cmd[2] = (real_sector >> 24) & 0xFF;
    29     cmd[3] = (real_sector >> 16) & 0xFF;
    30     cmd[4] = (real_sector >> 8) & 0xFF;
    31     cmd[5] = real_sector & 0xFF;
    32     cmd[6] = 0;
    33     cmd[7] = 0;
    34     cmd[8] = 1;
    36     if( READ_CD_RAW(mode) ) {
    37         cmd[9] = 0xF0;
    38     } else {
    39         if( READ_CD_HEADER(mode) ) {
    40             cmd[9] = 0xA0;
    41         }
    42         if( READ_CD_SUBHEAD(mode) ) {
    43             cmd[9] |= 0x40;
    44         }
    45         if( READ_CD_DATA(mode) ) {
    46             cmd[9] |= 0x10;
    47         }
    48     }
    49 }
    51 void mmc_parse_toc2( gdrom_image_t disc, unsigned char *buf )
    52 {
    53     int max_track = 0;
    54     int last_track = -1;
    55     int leadout = -1;
    56     int len = (buf[0] << 8) | buf[1];
    57     int session_type = -1;
    58     int i;
    59     for( i = 4; i<len; i+=11 ) {
    60         int session = buf[i];
    61         int adr = buf[i+1] >> 4;
    62         int point = buf[i+3];
    63         if( adr == 0x01 && point > 0 && point < 100 ) {
    64             /* Track info */
    65             int trackno = point-1;
    66             if( point > max_track ) {
    67                 max_track = point;
    68             }
    69             disc->track[trackno].flags = (buf[i+1] & 0x0F) << 4;
    70             disc->track[trackno].session = session - 1;
    71             disc->track[trackno].lba = MSFTOLBA(buf[i+8],buf[i+9],buf[i+10]);
    72             if( disc->track[trackno].flags & TRACK_DATA ) {
    73                 disc->track[trackno].mode = GDROM_MODE1;
    74             } else {
    75                 disc->track[trackno].mode = GDROM_CDDA;
    76             }
    77             if( last_track != -1 ) {
    78                 disc->track[last_track].sector_count = disc->track[trackno].lba -
    79                 disc->track[last_track].lba;
    80             }
    81             last_track = trackno;
    82         } else switch( (adr << 8) | point ) {
    83         case 0x1A0: /* session info */
    84             if( buf[i+9] == 0x20 ) {
    85                 session_type = IDE_DISC_CDROMXA;
    86             } else {
    87                 session_type = IDE_DISC_CDROM;
    88             }
    89             disc->disc_type = session_type;
    90             break;
    91         case 0x1A2: /* leadout */
    92             leadout = MSFTOLBA(buf[i+8], buf[i+9], buf[i+10]);
    93             break;
    94         }
    95     }
    96     disc->track_count = max_track;
    98     if( leadout != -1 && last_track != -1 ) {
    99         disc->track[last_track].sector_count = leadout - disc->track[last_track].lba;
   100     }
.