4 * MMC host-side support functions.
6 * Copyright (c) 2008 Nathan Keynes.
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.
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.
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 )
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;
39 if( READ_CD_RAW(mode) ) {
42 if( READ_CD_HEADER(mode) ) {
45 if( READ_CD_SUBHEAD(mode) ) {
48 if( READ_CD_DATA(mode) ) {
54 void mmc_parse_toc2( gdrom_image_t disc, unsigned char *buf )
59 int len = (buf[0] << 8) | buf[1];
60 int session_type = -1;
62 for( i = 4; i<len; i+=11 ) {
64 int adr = buf[i+1] >> 4;
66 if( adr == 0x01 && point > 0 && point < 100 ) {
68 int trackno = point-1;
69 if( point > max_track ) {
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;
78 disc->track[trackno].mode = GDROM_CDDA;
80 if( last_track != -1 ) {
81 disc->track[last_track].sector_count = disc->track[trackno].lba -
82 disc->track[last_track].lba;
85 } else switch( (adr << 8) | point ) {
86 case 0x1A0: /* session info */
87 if( buf[i+9] == 0x20 ) {
88 session_type = IDE_DISC_CDROMXA;
90 session_type = IDE_DISC_CDROM;
92 disc->disc_type = session_type;
94 case 0x1A2: /* leadout */
95 leadout = MSFTOLBA(buf[i+8], buf[i+9], buf[i+10]);
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;
.