Skip to content

Commit

Permalink
2300b9
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioni committed Aug 3, 2010
1 parent bd01e5b commit 3649b67
Show file tree
Hide file tree
Showing 40 changed files with 997 additions and 678 deletions.
32 changes: 22 additions & 10 deletions akiko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,9 @@ static void cdaudiostop_do (void)

static void cdaudiostop (void)
{
cdrom_playing = 0;
cdrom_audiotimeout = 0;
cdrom_paused = 0;
cdrom_playing = 0;
write_comm_pipe_u32 (&requests, 0x0104, 1);
}

Expand Down Expand Up @@ -543,7 +544,7 @@ static int cd_play_audio (int startlsn, int endlsn, int scan)

if (!cdrom_toc_cd_buffer.points)
return 0;
for (i = 0; i < cdrom_toc_cd_buffer.points; i++) {
for (i = cdrom_toc_cd_buffer.first_track_offset; i <= cdrom_toc_cd_buffer.last_track_offset; i++) {
s = &cdrom_toc_cd_buffer.toc[i];
addr = s->paddress;
if (s->track > 0 && s->track < 100 && addr >= startlsn)
Expand All @@ -557,6 +558,7 @@ static int cd_play_audio (int startlsn, int endlsn, int scan)
endlsn = s->paddress;
return 0;
}
qcode_valid = 0;
last_play_end = endlsn;
cdrom_audiotimeout = 0;
cdrom_paused = 0;
Expand All @@ -579,6 +581,9 @@ static int cd_qcode (uae_u8 *d)
last_play_pos = 0;
buf = qcode_buf;
as = buf[1];
buf[2] = 0x80;
if (!qcode_valid)
return 0;
if (cdrom_playing) // fake it!
as = AUDIO_STATUS_IN_PROGRESS;
if (as != AUDIO_STATUS_IN_PROGRESS && as != AUDIO_STATUS_PAUSED && as != AUDIO_STATUS_PLAY_COMPLETE && as != AUDIO_STATUS_NO_STATUS) /* audio status ok? */
Expand All @@ -587,6 +592,7 @@ static int cd_qcode (uae_u8 *d)
last_play_pos = msf2lsn (fromlongbcd (s + 7));
if (!d)
return 0;
buf[2] = 0;
/* ??? */
d[0] = 0;
/* CtlAdr */
Expand Down Expand Up @@ -614,6 +620,8 @@ static int cd_qcode (uae_u8 *d)
d[10] = tobcd ((uae_u8)(msf >> 0));
}
}
// write_log (L"%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X\n",
// d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11]);
return 0;
}

Expand Down Expand Up @@ -869,11 +877,11 @@ static int cdrom_command_multi (void)
write_log (L"PLAY FROM %06X (%d) to %06X (%d) SCAN=%d\n",
seekpos, msf2lsn (seekpos), endpos, msf2lsn (endpos), scan);
#endif
cdrom_playing = 1;
cdrom_result_buffer[1] |= CDS_PLAYING;
if (!cd_play_audio (seekpos, endpos, 0)) {
cdrom_result_buffer[1] = CDS_ERROR;
} else {
cdrom_playing = 1;
cdrom_result_buffer[1] |= CDS_PLAYING;
// play didn't start, report it in next status packet
cdrom_audiotimeout = -3;
}
} else {
#if AKIKO_DEBUG_IO_CMD
Expand All @@ -887,10 +895,10 @@ static int cdrom_command_multi (void)
return 2;
}

static int cdrom_playend_notify (void)
static int cdrom_playend_notify (int err)
{
cdrom_result_buffer[0] = 4;
cdrom_result_buffer[1] = 0x80;
cdrom_result_buffer[1] = err ? 0x80 : 0x00;
return 2;
}

Expand Down Expand Up @@ -1093,7 +1101,11 @@ static void akiko_handler (void)
}
}
if (cdrom_audiotimeout == -2 && qcode_buf[1] != AUDIO_STATUS_IN_PROGRESS) {
cdrom_start_return_data (cdrom_playend_notify ());
cdrom_start_return_data (cdrom_playend_notify (0));
cdrom_audiotimeout = 0;
}
if (cdrom_audiotimeout == -3) {
cdrom_start_return_data (cdrom_playend_notify (1));
cdrom_audiotimeout = 0;
}

Expand Down Expand Up @@ -1616,7 +1628,7 @@ void akiko_reset (void)
cdcomtxinx = 0;
cdcomrxinx = 0;
cdcomtxcmp = 0;
lastmediastate = 0;
lastmediastate = -1;
}
cdrom_led = 0;
cdrom_receive_started = 0;
Expand Down
6 changes: 4 additions & 2 deletions audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ void audio_sampleripper (int mode)
rs->changed = 0;
fetch_ripperpath (path, sizeof (path));
name[0] = 0;
if (currprefs.dfxtype[0] >= 0)
_tcscpy (name, currprefs.df[0]);
if (currprefs.floppyslots[0].dfxtype >= 0)
_tcscpy (name, currprefs.floppyslots[0].df);
else if (currprefs.cdslots[0].inuse)
_tcscpy (name, currprefs.cdslots[0].name);
if (!name[0])
underline[0] = 0;
namesplit (name);
Expand Down
115 changes: 77 additions & 38 deletions blkdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
#include "rp.h"
#endif

#define PRE_INSERT_DELAY (3 * (currprefs.ntscmode ? 60 : 50))

static int scsiemu[MAX_TOTAL_SCSI_DEVICES];

static struct device_functions *device_func[MAX_TOTAL_SCSI_DEVICES];
static int openlist[MAX_TOTAL_SCSI_DEVICES];
static int waspaused[MAX_TOTAL_SCSI_DEVICES], wasslow[MAX_TOTAL_SCSI_DEVICES];
static int delayed[MAX_TOTAL_SCSI_DEVICES];

/* convert minutes, seconds and frames -> logical sector number */
int msf2lsn (int msf)
Expand Down Expand Up @@ -232,61 +235,69 @@ static int sys_command_open_internal (int unitnum, const TCHAR *ident, cd_standa
return ret;
}

int get_standard_cd_unit (enum cd_standard_unit csu)
static int getunitinfo (int unitnum, int drive, cd_standard_unit csu, int *isaudio)
{
struct device_info di;
if (sys_command_info (unitnum, &di, 0)) {
write_log (L"Scanning drive %s: ", di.label);
if (di.media_inserted) {
if (isaudiotrack (&di.toc, 0)) {
if (*isaudio == 0)
*isaudio = drive;
write_log (L"CDA");
}
uae_u8 buffer[2048];
if (sys_command_cd_read (unitnum, buffer, 16, 1)) {
if (!memcmp (buffer + 8, "CDTV", 4) || !memcmp (buffer + 8, "CD32", 4)) {
uae_u32 crc;
write_log (L"CD32 or CDTV");
if (sys_command_cd_read (unitnum, buffer, 21, 1)) {
crc = get_crc32 (buffer, sizeof buffer);
if (crc == 0xe56c340f) {
write_log (L" [CD32.TM]");
if (csu == CD_STANDARD_UNIT_CD32) {
write_log (L"\n");
return 1;
}
}
}
if (csu == CD_STANDARD_UNIT_CDTV || csu == CD_STANDARD_UNIT_CD32) {
write_log (L"\n");
return 1;
}
}
}
} else {
write_log (L"no media");
}
}
write_log (L"\n");
return 0;
}

static int get_standard_cd_unit2 (cd_standard_unit csu)
{
int unitnum = 0;
int isaudio = 0;
if (currprefs.cdslots[unitnum].name[0] || currprefs.cdslots[unitnum].inuse) {
device_func_init (SCSI_UNIT_IOCTL);
if (!sys_command_open_internal (unitnum, currprefs.cdslots[unitnum].name, csu)) {
device_func_init (SCSI_UNIT_IMAGE);
if (!sys_command_open_internal (unitnum, currprefs.cdslots[unitnum].name, csu))
goto fallback;
}
getunitinfo (unitnum, 0, csu, &isaudio);
return unitnum;
}
int isaudio = 0;
device_func_init (SCSI_UNIT_IOCTL);
for (int drive = 'C'; drive <= 'Z'; ++drive) {
TCHAR vol[100];
_stprintf (vol, L"%c:\\", drive);
int drivetype = GetDriveType (vol);
if (drivetype == DRIVE_CDROM) {
if (sys_command_open_internal (unitnum, vol, csu)) {
struct device_info di;
write_log (L"Scanning drive %s: ", vol);
if (sys_command_info (unitnum, &di, 0)) {
if (di.media_inserted) {
if (isaudiotrack (&di.toc, 0)) {
if (isaudio == 0)
isaudio = drive;
write_log (L"CDA");
}
uae_u8 buffer[2048];
if (sys_command_cd_read (unitnum, buffer, 16, 1)) {
if (!memcmp (buffer + 8, "CDTV", 4) || !memcmp (buffer + 8, "CD32", 4)) {
uae_u32 crc;
write_log (L"CD32 or CDTV");
if (sys_command_cd_read (unitnum, buffer, 21, 1)) {
crc = get_crc32 (buffer, sizeof buffer);
if (crc == 0xe56c340f) {
write_log (L" [CD32.TM]");
if (csu == CD_STANDARD_UNIT_CD32) {
write_log (L"\n");
return unitnum;
}
}
}
if (csu == CD_STANDARD_UNIT_CDTV || csu == CD_STANDARD_UNIT_CD32) {
write_log (L"\n");
return unitnum;
}
}
}
} else {
write_log (L"no media");
}
}
write_log (L"\n");
if (getunitinfo (unitnum, drive, csu, &isaudio))
return unitnum;
sys_command_close (unitnum);
}
}
Expand All @@ -305,6 +316,19 @@ int get_standard_cd_unit (enum cd_standard_unit csu)
}
return unitnum;
}

int get_standard_cd_unit (cd_standard_unit csu)
{
int unitnum = get_standard_cd_unit2 (csu);
if (unitnum < 0)
return -1;
delayed[unitnum] = 0;
if (currprefs.cdslots[unitnum].delayed) {
delayed[unitnum] = PRE_INSERT_DELAY;
}
return unitnum;
}

void close_standard_cd_unit (int unitnum)
{
sys_command_close (unitnum);
Expand Down Expand Up @@ -390,6 +414,16 @@ static void check_changes (int unitnum)
{
bool changed = false;

if (device_func[unitnum] == NULL)
return;

if (delayed[unitnum]) {
delayed[unitnum]--;
if (delayed[unitnum] == 0)
write_log (L"CD: startup delayed insert '%s'\n", currprefs.cdslots[unitnum].name[0] ? currprefs.cdslots[unitnum].name : L"<EMPTY>");
return;
}

if (_tcscmp (changed_prefs.cdslots[unitnum].name, currprefs.cdslots[unitnum].name) != 0)
changed = true;
if (!changed && changed_prefs.cdslots[unitnum].name[0] == 0 && changed_prefs.cdslots[unitnum].inuse != currprefs.cdslots[unitnum].inuse)
Expand Down Expand Up @@ -676,6 +710,8 @@ int sys_command_ismedia (int unitnum, int quick)
{
if (failunit (unitnum))
return -1;
if (delayed[unitnum])
return 0;
if (device_func[unitnum] == NULL) {
uae_u8 cmd[6] = { 0, 0, 0, 0, 0, 0 };
return do_scsi (unitnum, cmd, sizeof cmd);
Expand All @@ -688,7 +724,10 @@ struct device_info *sys_command_info (int unitnum, struct device_info *di, int q
{
if (failunit (unitnum))
return NULL;
return device_func[unitnum]->info (unitnum, di, quick);
struct device_info *di2 = device_func[unitnum]->info (unitnum, di, quick);
if (di2 && delayed[unitnum])
di2->media_inserted = 0;
return di2;
}

#define MODE_SELECT_6 0x15
Expand Down
Loading

0 comments on commit 3649b67

Please sign in to comment.