#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.
 */

/* START STOP UNIT COMMAND (6)
 *
 * 0 = op code (0x1b)
 * 1 = 0=immed, all other=reserved
 * 2 = reserved
 * 3 = reserved
 * 4 = 7654=power contitions, 32=reserved, 1=LoEj, 0=Start
 * 5 = control
 *
 *
 * LoEj | Start | operation
 *    0 |     0 | stop the disc
 *    1 |     0 | eject disc, if permitted
 *    1 |     1 | load disc, make ready for access
 *      |       | -> it's not an error, if no media is present
 */

void scmd_startstop(int loej, int start)
{
	scmd_ready(10, 0);
#if DEBUG_CDB
	if (!stralloc_copys(&cdb.name, "START STOP UNIT COMMAND (6)")) die_nomem();
#endif

	cdb.cmd.s[0] = 0x1b;
	if (start) set(cdb.cmd.s[4], 0x01);
	if (cd->ds != DS_OPEN && loej) set(cdb.cmd.s[4], 0x02);
	cdb.flags=D_NONE;
	cd->cmd(&cdb);

	return;
}

void scmd_stop(void)
{
	scmd_startstop(0,0);
}

void scmd_eject(void)
{
	scmd_startstop(1,0);
}

void scmd_close(void)
{
	scmd_startstop(1,1);
}

