Search
lxdream.org :: lxdream/src/gdrom/mmc.c :: diff
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 (11 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
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gdrom/mmc.c Sat Jul 05 11:57:36 2008 +0000
1.3 @@ -0,0 +1,101 @@
1.4 +/**
1.5 + * $Id: mmc.c 662 2008-03-02 11:38:08Z nkeynes $
1.6 + *
1.7 + * MMC host-side support functions.
1.8 + *
1.9 + * Copyright (c) 2008 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include "gdrom/gddriver.h"
1.23 +#include "gdrom/packet.h"
1.24 +
1.25 +#define MSFTOLBA( m,s,f ) (f + (s*CD_FRAMES_PER_SECOND) + (m*CD_FRAMES_PER_MINUTE))
1.26 +
1.27 +void mmc_make_read_cd_cmd( char *cmd, uint32_t real_sector, int mode )
1.28 +{
1.29 + cmd[0] = 0xBE;
1.30 + cmd[1] = (mode & 0x0E) << 1;
1.31 + cmd[2] = (real_sector >> 24) & 0xFF;
1.32 + cmd[3] = (real_sector >> 16) & 0xFF;
1.33 + cmd[4] = (real_sector >> 8) & 0xFF;
1.34 + cmd[5] = real_sector & 0xFF;
1.35 + cmd[6] = 0;
1.36 + cmd[7] = 0;
1.37 + cmd[8] = 1;
1.38 +
1.39 + if( READ_CD_RAW(mode) ) {
1.40 + cmd[9] = 0xF0;
1.41 + } else {
1.42 + if( READ_CD_HEADER(mode) ) {
1.43 + cmd[9] = 0xA0;
1.44 + }
1.45 + if( READ_CD_SUBHEAD(mode) ) {
1.46 + cmd[9] |= 0x40;
1.47 + }
1.48 + if( READ_CD_DATA(mode) ) {
1.49 + cmd[9] |= 0x10;
1.50 + }
1.51 + }
1.52 +}
1.53 +
1.54 +void mmc_parse_toc2( gdrom_image_t disc, unsigned char *buf )
1.55 +{
1.56 + int max_track = 0;
1.57 + int last_track = -1;
1.58 + int leadout = -1;
1.59 + int len = (buf[0] << 8) | buf[1];
1.60 + int session_type = -1;
1.61 + int i;
1.62 + for( i = 4; i<len; i+=11 ) {
1.63 + int session = buf[i];
1.64 + int adr = buf[i+1] >> 4;
1.65 + int point = buf[i+3];
1.66 + if( adr == 0x01 && point > 0 && point < 100 ) {
1.67 + /* Track info */
1.68 + int trackno = point-1;
1.69 + if( point > max_track ) {
1.70 + max_track = point;
1.71 + }
1.72 + disc->track[trackno].flags = (buf[i+1] & 0x0F) << 4;
1.73 + disc->track[trackno].session = session - 1;
1.74 + disc->track[trackno].lba = MSFTOLBA(buf[i+8],buf[i+9],buf[i+10]);
1.75 + if( disc->track[trackno].flags & TRACK_DATA ) {
1.76 + disc->track[trackno].mode = GDROM_MODE1;
1.77 + } else {
1.78 + disc->track[trackno].mode = GDROM_CDDA;
1.79 + }
1.80 + if( last_track != -1 ) {
1.81 + disc->track[last_track].sector_count = disc->track[trackno].lba -
1.82 + disc->track[last_track].lba;
1.83 + }
1.84 + last_track = trackno;
1.85 + } else switch( (adr << 8) | point ) {
1.86 + case 0x1A0: /* session info */
1.87 + if( buf[i+9] == 0x20 ) {
1.88 + session_type = IDE_DISC_CDROMXA;
1.89 + } else {
1.90 + session_type = IDE_DISC_CDROM;
1.91 + }
1.92 + disc->disc_type = session_type;
1.93 + break;
1.94 + case 0x1A2: /* leadout */
1.95 + leadout = MSFTOLBA(buf[i+8], buf[i+9], buf[i+10]);
1.96 + break;
1.97 + }
1.98 + }
1.99 + disc->track_count = max_track;
1.100 +
1.101 + if( leadout != -1 && last_track != -1 ) {
1.102 + disc->track[last_track].sector_count = leadout - disc->track[last_track].lba;
1.103 + }
1.104 +}
1.105 \ No newline at end of file
.