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