CD-ROM changes from Battler, including :
- New disc change handling - Additional ATAPI commands - CD drive-level volume control
This commit is contained in:
parent
5b3d307181
commit
0faa803061
13 changed files with 1600 additions and 378 deletions
139
src/cdrom-iso.c
139
src/cdrom-iso.c
|
|
@ -11,6 +11,7 @@ static uint32_t last_block = 0;
|
|||
static uint64_t image_size = 0;
|
||||
static int iso_inited = 0;
|
||||
char iso_path[1024];
|
||||
void iso_close(void);
|
||||
static FILE *iso_image = NULL;
|
||||
static int iso_changed = 0;
|
||||
|
||||
|
|
@ -65,15 +66,23 @@ static void iso_seek(uint32_t pos)
|
|||
|
||||
static int iso_ready(void)
|
||||
{
|
||||
if (iso_changed)
|
||||
{
|
||||
iso_changed = 0;
|
||||
if (strlen(iso_path) == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (old_cdrom_drive != cdrom_drive)
|
||||
return 1;
|
||||
|
||||
iso_changed = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Always return 0, because there is no way to change the ISO without unmounting and remounting it. */
|
||||
static int iso_medium_changed(void)
|
||||
{
|
||||
iso_changed = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t iso_getcurrentsubchannel(uint8_t *b, int msf)
|
||||
{
|
||||
pclog("iso_getcurrentsubchannel stub\n");
|
||||
|
|
@ -102,7 +111,26 @@ static void lba_to_msf(uint8_t *buf, int lba)
|
|||
lba += 150;
|
||||
buf[0] = (lba / 75) / 60;
|
||||
buf[1] = (lba / 75) % 60;
|
||||
buf[2] = lba & 75;
|
||||
buf[2] = lba % 75;
|
||||
}
|
||||
|
||||
static void iso_readsector_raw(uint8_t *b, int sector)
|
||||
{
|
||||
uint32_t temp;
|
||||
if (!cdrom_drive) return;
|
||||
fseek(iso_image, sector*2048, SEEK_SET);
|
||||
fread(b+16, 2048, 1, iso_image);
|
||||
|
||||
/* sync bytes */
|
||||
b[0] = 0;
|
||||
memset(b + 1, 0xff, 10);
|
||||
b[11] = 0;
|
||||
b += 12;
|
||||
lba_to_msf(b, sector);
|
||||
b[3] = 1; /* mode 1 data */
|
||||
b += 4;
|
||||
b += 2048;
|
||||
memset(b, 0, 288);
|
||||
}
|
||||
|
||||
static int iso_readtoc(unsigned char *buf, unsigned char start_track, int msf, int maxlen, int single)
|
||||
|
|
@ -161,7 +189,7 @@ static int iso_readtoc(unsigned char *buf, unsigned char start_track, int msf, i
|
|||
return len;
|
||||
}
|
||||
|
||||
static void iso_readtoc_session(unsigned char *buf, int msf, int maxlen)
|
||||
static int iso_readtoc_session(unsigned char *buf, int msf, int maxlen)
|
||||
{
|
||||
uint8_t *q;
|
||||
|
||||
|
|
@ -177,6 +205,73 @@ static void iso_readtoc_session(unsigned char *buf, int msf, int maxlen)
|
|||
*q++ = 0; /* sec */
|
||||
*q++ = 0; /* frame */
|
||||
*q++ = 0;
|
||||
|
||||
return 12;
|
||||
}
|
||||
|
||||
static int iso_readtoc_raw(unsigned char *buf, int maxlen)
|
||||
{
|
||||
uint8_t *q;
|
||||
int len;
|
||||
|
||||
q = buf + 2;
|
||||
*q++ = 1; /* first session */
|
||||
*q++ = 1; /* last session */
|
||||
|
||||
*q++ = 1; /* session number */
|
||||
*q++ = 0x14; /* data track */
|
||||
*q++ = 0; /* track number */
|
||||
*q++ = 0xa0; /* lead-in */
|
||||
*q++ = 0; /* min */
|
||||
*q++ = 0; /* sec */
|
||||
*q++ = 0; /* frame */
|
||||
*q++ = 0;
|
||||
*q++ = 1; /* first track */
|
||||
*q++ = 0x00; /* disk type */
|
||||
*q++ = 0x00;
|
||||
|
||||
*q++ = 1; /* session number */
|
||||
*q++ = 0x14; /* data track */
|
||||
*q++ = 0; /* track number */
|
||||
*q++ = 0xa1;
|
||||
*q++ = 0; /* min */
|
||||
*q++ = 0; /* sec */
|
||||
*q++ = 0; /* frame */
|
||||
*q++ = 0;
|
||||
*q++ = 1; /* last track */
|
||||
*q++ = 0x00;
|
||||
*q++ = 0x00;
|
||||
|
||||
*q++ = 1; /* session number */
|
||||
*q++ = 0x14; /* data track */
|
||||
*q++ = 0; /* track number */
|
||||
*q++ = 0xa2; /* lead-out */
|
||||
*q++ = 0; /* min */
|
||||
*q++ = 0; /* sec */
|
||||
*q++ = 0; /* frame */
|
||||
last_block = image_size >> 11;
|
||||
/* this is raw, must be msf */
|
||||
*q++ = 0; /* reserved */
|
||||
lba_to_msf(q, last_block);
|
||||
q += 3;
|
||||
|
||||
*q++ = 1; /* session number */
|
||||
*q++ = 0x14; /* ADR, control */
|
||||
*q++ = 0; /* track number */
|
||||
*q++ = 1; /* point */
|
||||
*q++ = 0; /* min */
|
||||
*q++ = 0; /* sec */
|
||||
*q++ = 0; /* frame */
|
||||
/* same here */
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
|
||||
len = q - buf;
|
||||
buf[0] = (uint8_t)(((len-2) >> 8) & 0xff);
|
||||
buf[1] = (uint8_t)((len-2) & 0xff);
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint32_t iso_size()
|
||||
|
|
@ -188,6 +283,14 @@ static uint32_t iso_size()
|
|||
return last_block;
|
||||
}
|
||||
|
||||
static int iso_status()
|
||||
{
|
||||
if (!(iso_ready()) && (cdrom_drive != 200))
|
||||
return CD_STATUS_EMPTY;
|
||||
|
||||
return CD_STATUS_DATA_ONLY;
|
||||
}
|
||||
|
||||
void iso_reset()
|
||||
{
|
||||
}
|
||||
|
|
@ -199,10 +302,13 @@ int iso_open(char *fn)
|
|||
if (iso_image)
|
||||
fclose(iso_image);
|
||||
|
||||
iso_changed = 1;
|
||||
if (strcmp(fn, iso_path) != 0)
|
||||
iso_changed = 1;
|
||||
|
||||
sprintf(iso_path, "%s", fn);
|
||||
pclog("Path is %s\n", iso_path);
|
||||
/* Make sure iso_changed stays when changing from ISO to another ISO. */
|
||||
if (cdrom_drive != CDROM_ISO)
|
||||
iso_changed = 1;
|
||||
strcpy(iso_path, fn);
|
||||
|
||||
iso_image = fopen(iso_path, "rb");
|
||||
atapi = &iso_atapi;
|
||||
|
|
@ -213,29 +319,36 @@ int iso_open(char *fn)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void iso_close(void)
|
||||
void iso_close(void)
|
||||
{
|
||||
if (iso_image)
|
||||
{
|
||||
fclose(iso_image);
|
||||
iso_image = NULL;
|
||||
}
|
||||
memset(iso_path, 0, 1024);
|
||||
}
|
||||
|
||||
static void iso_exit(void)
|
||||
{
|
||||
iso_stop();
|
||||
iso_inited = 0;
|
||||
iso_close();
|
||||
}
|
||||
|
||||
static int iso_is_track_audio(uint32_t pos, int ismsf)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ATAPI iso_atapi =
|
||||
{
|
||||
iso_ready,
|
||||
iso_medium_changed,
|
||||
iso_readtoc,
|
||||
iso_readtoc_session,
|
||||
iso_readtoc_raw,
|
||||
iso_getcurrentsubchannel,
|
||||
iso_readsector,
|
||||
iso_readsector_raw,
|
||||
iso_playaudio,
|
||||
iso_seek,
|
||||
iso_load,
|
||||
|
|
@ -243,6 +356,8 @@ static ATAPI iso_atapi =
|
|||
iso_pause,
|
||||
iso_resume,
|
||||
iso_size,
|
||||
iso_status,
|
||||
iso_is_track_audio,
|
||||
iso_stop,
|
||||
iso_exit
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue