#include "mcdp.h"

/**
 * Copyright (C) 2001-2006 Tino Reichardt
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* PLAY AUDIO COMMAND (10)
 *
 * 0 = op code (0x45)
 * 1 = 0=reladr, all others=reserved
 * 2 = lba start (msb)
 * 3 = lba start
 * 4 = lba start
 * 5 = lba start (lsb)
 * 6 = reserved
 * 7 = lba len (msb)
 * 8 = lba len (lsb)
 * 9 = control
 */

void scmd_play(int track)
{
	u32 lba;
	u16 len;

	scmd_ready(10,0);
#if DEBUG_CDB
	if (!stralloc_copys(&cdb.name, "PLAY AUDIO COMMAND (10)")) die_nomem();
#endif

	if (track == 0) {
		/* play a special part */
		lba = cd->lba;
		len = cd->len;
	} else {
		if (track > 0) {
			/* we play just the next track */
			cd->current++;
		} else {
			/* we play just the previous track */
			cd->current--;
		}
		lba = cd->t[cd->current].lba;
		len = cd->t[cd->current].len;
	}

#if 0
	#include <stdio.h>
	printf("play() from %lu to %lu (len = %d)\n", lba, lba+len, len);
	fflush(stdout);
#endif

	cdb.cmd.s[0]=0x45;
	cdb.cmd.s[2]=(lba >> 24) & 0xff;
	cdb.cmd.s[3]=(lba >> 16) & 0xff;
	cdb.cmd.s[4]=(lba >>  8) & 0xff;
	cdb.cmd.s[5]=lba & 0xff;
	cdb.cmd.s[7]=msb(len); /* (len >>  8) & 0xff; */
	cdb.cmd.s[8]=lsb(len); /* len & 0xff; */
	cdb.flags=D_NONE;
	cd->cmd(&cdb);

	return;
}

