Search
lxdream.org :: lxdream/src/gdrom/mmc.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/mmc.c
changeset 788:eb238a77f3c0
prev729:4cc913eabd3d
author nkeynes
date Wed Jul 30 22:50:44 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Bug #61: OpenBSD support
(Modified) patch from bsdmaniak, thanks!
view annotate diff log raw
     1 /**
     2  * $Id$
     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;
    35     cmd[9] = 0;
    36     cmd[10]= 0;
    37     cmd[11]= 0;
    39     if( READ_CD_RAW(mode) ) {
    40         cmd[9] = 0xF0;
    41     } else {
    42         if( READ_CD_HEADER(mode) ) {
    43             cmd[9] = 0xA0;
    44         }
    45         if( READ_CD_SUBHEAD(mode) ) {
    46             cmd[9] |= 0x40;
    47         }
    48         if( READ_CD_DATA(mode) ) {
    49             cmd[9] |= 0x10;
    50         }
    51     }
    52 }
    54 void mmc_parse_toc2( gdrom_image_t disc, unsigned char *buf )
    55 {
    56     int max_track = 0;
    57     int last_track = -1;
    58     int leadout = -1;
    59     int len = (buf[0] << 8) | buf[1];
    60     int session_type = -1;
    61     int i;
    62     for( i = 4; i<len; i+=11 ) {
    63         int session = buf[i];
    64         int adr = buf[i+1] >> 4;
    65         int point = buf[i+3];
    66         if( adr == 0x01 && point > 0 && point < 100 ) {
    67             /* Track info */
    68             int trackno = point-1;
    69             if( point > max_track ) {
    70                 max_track = point;
    71             }
    72             disc->track[trackno].flags = (buf[i+1] & 0x0F) << 4;
    73             disc->track[trackno].session = session - 1;
    74             disc->track[trackno].lba = MSFTOLBA(buf[i+8],buf[i+9],buf[i+10]);
    75             if( disc->track[trackno].flags & TRACK_DATA ) {
    76                 disc->track[trackno].mode = GDROM_MODE1;
    77             } else {
    78                 disc->track[trackno].mode = GDROM_CDDA;
    79             }
    80             if( last_track != -1 ) {
    81                 disc->track[last_track].sector_count = disc->track[trackno].lba -
    82                 disc->track[last_track].lba;
    83             }
    84             last_track = trackno;
    85         } else switch( (adr << 8) | point ) {
    86         case 0x1A0: /* session info */
    87             if( buf[i+9] == 0x20 ) {
    88                 session_type = IDE_DISC_CDROMXA;
    89             } else {
    90                 session_type = IDE_DISC_CDROM;
    91             }
    92             disc->disc_type = session_type;
    93             break;
    94         case 0x1A2: /* leadout */
    95             leadout = MSFTOLBA(buf[i+8], buf[i+9], buf[i+10]);
    96             break;
    97         }
    98     }
    99     disc->track_count = max_track;
   101     if( leadout != -1 && last_track != -1 ) {
   102         disc->track[last_track].sector_count = leadout - disc->track[last_track].lba;
   103     }
   104 }
.