File: vu_tosh.c

package info (click to toggle)
xmcd 2.6-17sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,464 kB
  • ctags: 5,075
  • sloc: ansic: 51,322; sh: 4,039; makefile: 82; pascal: 67
file content (469 lines) | stat: -rw-r--r-- 10,795 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/*
 *   libdi - CD Audio Player Device Interface Library
 *
 *   Copyright (C) 1993-2000  Ti Kan
 *   E-mail: ti@amb.org
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Library General Public
 *   License as published by the Free Software Foundation; either
 *   version 2 of the License, or (at your option) any later version.
 *
 *   This library 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
 *   Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this library; if not, write to the Free
 *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 *   Toshiba vendor-unique support
 *
 *   The name "Toshiba" is a trademark of Toshiba Corporation, and is
 *   used here for identification purposes only.
 */
#ifndef LINT
static char *_vu_tosh_c_ident_ = "@(#)vu_tosh.c	6.25 99/12/27";
#endif

#include "common_d/appenv.h"
#include "common_d/util.h"
#include "libdi_d/libdi.h"
#include "libdi_d/scsipt.h"

#ifdef VENDOR_TOSHIBA

extern appdata_t	app_data;
extern di_client_t	*di_clinfo;
extern vu_tbl_t		scsipt_vutbl[];
extern byte_t		cdb[];
extern int		devfd;

STATIC bool_t		tosh_audio_muted;	/* Is audio muted? */


/*
 * tosh_playaudio
 *	Play audio function: send vendor-unique play audio command
 *	to the drive.
 *
 * Args:
 *	addr_fmt - Flags indicating which address formats are passed in
 *	If ADDR_BLK, then:
 *	    start_addr - The logical block starting address
 *	    end_addr - The logical block ending address
 *	If ADD_MSF, then:
 *	    start_msf - Pointer to the starting MSF address structure
 *	    end_msf - Pointer to the ending MSF address structure
 *	If ADDR_TRKIDX, then:
 *	    trk - The starting track number
 *	    idx - The starting index number
 *	If ADDR_OPTEND, then the ending address, if specified, can be
 *	ignored if possible.
 *
 * Return:
 *	TRUE - success
 *	FALSE - failure
 */
/*ARGSUSED*/
bool_t
tosh_playaudio(
	byte_t		addr_fmt,
	word32_t	start_addr,
	word32_t	end_addr,
	msf_t		*start_msf,
	msf_t		*end_msf,
	byte_t		trk,
	byte_t		idx
)
{
	bool_t		ret = FALSE;

	if (!ret && addr_fmt & ADDR_MSF) {
		/* Position laser head at desired location
		 * and start play.
		 */
		SCSICDB_RESET(cdb);
		cdb[0] = OP_VT_AUDSRCH;
		cdb[1] = 0x01;
		cdb[2] = (byte_t) util_ltobcd(start_msf->min);
		cdb[3] = (byte_t) util_ltobcd(start_msf->sec);
		cdb[4] = (byte_t) util_ltobcd(start_msf->frame);
		cdb[9] = 0x40;

		ret = pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA, 10, TRUE);

		if (ret && !(addr_fmt & ADDR_OPTEND)) {
			/* Specify end location, muting, and start play */
			SCSICDB_RESET(cdb);
			cdb[0] = OP_VT_AUDPLAY;
			cdb[1] = tosh_audio_muted ? 0x00 : 0x03;
			cdb[2] = (byte_t) util_ltobcd(end_msf->min);
			cdb[3] = (byte_t) util_ltobcd(end_msf->sec);
			cdb[4] = (byte_t) util_ltobcd(end_msf->frame);
			cdb[9] = 0x40;

			ret = pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA,
					 10, TRUE);
		}
	}

	if (!ret && addr_fmt & ADDR_BLK) {
		/* Position laser head at desired location
		 * and start play.
		 */
		SCSICDB_RESET(cdb);
		cdb[0] = OP_VT_AUDSRCH;
		cdb[1] = 0x01;
		cdb[2] = (start_addr & 0xff000000) >> 24;
		cdb[3] = (start_addr & 0x00ff0000) >> 16;
		cdb[4] = (start_addr & 0x0000ff00) >> 8;
		cdb[5] = (start_addr & 0x000000ff);
		cdb[9] = 0x00;

		ret = pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA, 10, TRUE);

		if (ret && !(addr_fmt & ADDR_OPTEND)) {
			/* Specify end location, muting, and start play */
			SCSICDB_RESET(cdb);
			cdb[0] = OP_VT_AUDPLAY;
			cdb[1] = tosh_audio_muted ? 0x00 : 0x03;
			cdb[2] = (end_addr & 0xff000000) >> 24;
			cdb[3] = (end_addr & 0x00ff0000) >> 16;
			cdb[4] = (end_addr & 0x0000ff00) >> 8;
			cdb[5] = (end_addr & 0x000000ff);
			cdb[9] = 0x00;

			ret = pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA,
					 10, TRUE);
		}
	}

	return (ret);
}


/*
 * tosh_pause_resume
 *	Pause/resume function: send vendor-unique commands to implement
 *	the pause and resume capability.
 *
 * Args:
 *	resume - TRUE: resume, FALSE: pause
 *
 * Return:
 *	TRUE - success
 *	FALSE - failure
 */
bool_t
tosh_pause_resume(bool_t resume)
{
	SCSICDB_RESET(cdb);

	if (resume) {
		cdb[0] = OP_VT_AUDPLAY;
		cdb[1] = tosh_audio_muted ? 0x00 : 0x03;
		cdb[9] = 0xc0;

		return (
			pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA, 5, TRUE)
		);
	}
	else {
		cdb[0] = OP_VT_STILL;

		return (
			pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA, 5, TRUE)
		);
	}
}


/*
 * tosh_get_playstatus
 *	Send vendor-unique command to obtain current audio playback
 *	status.
 *
 * Args:
 *	s - Pointer to the curstat_t structure
 *	audio_status - Address where a current status code (SCSI-2
 *		       style) is to be returned.
 *
 * Return:
 *	TRUE - success
 *	FALSE - failure
 */
bool_t
tosh_get_playstatus(curstat_t *s, byte_t *audio_status)
{
	int		i,
			trkno,
			idxno;
	byte_t		buf[sizeof(tsubq_data_t)];
	tsubq_data_t	*d;


	(void) memset(buf, 0, sizeof(buf));

	SCSICDB_RESET(cdb);
	cdb[0] = OP_VT_RDSUBQ;
	cdb[1] = SZ_VT_RDSUBQ & 0x1f;

	if (!pthru_send(devfd, cdb, 10, buf, SZ_VT_RDSUBQ, OP_DATAIN, 5, TRUE))
		return FALSE;

	DBGDUMP("tosh: Read Subchannel data bytes", buf, SZ_VT_RDSUBQ);

	d = (tsubq_data_t *)(void *) buf;

	trkno = util_bcdtol((word32_t) d->trkno);
	if (s->cur_trk != trkno) {
		s->cur_trk = trkno;
		DPY_TRACK(s);
	}

	idxno = util_bcdtol((word32_t) d->idxno);
	if (s->cur_idx != idxno) {
		s->cur_idx = idxno;
		s->sav_iaddr = s->cur_tot_addr;
		DPY_INDEX(s);
	}

	if ((i = di_curtrk_pos(s)) >= 0)
		s->trkinfo[i].type = (d->trktype == 0) ? TYP_AUDIO : TYP_DATA;

	s->cur_tot_min = (byte_t) util_bcdtol(d->abs_min);
	s->cur_tot_sec = (byte_t) util_bcdtol(d->abs_sec);
	s->cur_tot_frame = (byte_t) util_bcdtol(d->abs_frame);
	s->cur_trk_min = (byte_t) util_bcdtol(d->rel_min);
	s->cur_trk_sec = (byte_t) util_bcdtol(d->rel_sec);
	s->cur_trk_frame = (byte_t) util_bcdtol(d->rel_frame);
	util_msftoblk(
		s->cur_tot_min, s->cur_tot_sec, s->cur_tot_frame,
		&s->cur_tot_addr, MSF_OFFSET
	);
	util_msftoblk(
		s->cur_trk_min, s->cur_trk_sec, s->cur_trk_frame,
		&s->cur_trk_addr, 0
	);

	/* Translate Toshiba audio status to SCSI-2 audio status */
	switch (d->audio_status) {
	case TAUD_PLAYING:
		*audio_status = AUDIO_PLAYING;
		break;

	case TAUD_SRCH_PAUSED:
	case TAUD_PAUSED:
		*audio_status = AUDIO_PAUSED;
		break;

	case TAUD_OTHER:
		*audio_status = AUDIO_COMPLETED;
		break;
	}

	return TRUE;
}


/*
 * tosh_get_toc
 *	Send vendor-unique command to obtain the disc table-of-contents
 *
 * Args:
 *	s - Pointer to the curstat_t structure, which contains the TOC
 *	    table to be updated.
 *
 * Return:
 *	TRUE - success
 *	FALSE - failure
 */
bool_t
tosh_get_toc(curstat_t *s)
{
	int		i,
			j;
	byte_t		buf[SZ_VT_RDINFO];
	tinfo_00_t	*t0;
	tinfo_01_t	*t1;
	tinfo_02_t	*t2;


	(void) memset(buf, 0, sizeof(buf));

	/* Find number of tracks */
	SCSICDB_RESET(cdb);
	cdb[0] = OP_VT_RDINFO;
	cdb[1] = 0x00;

	if (!pthru_send(devfd, cdb, 10, buf, SZ_VT_RDINFO, OP_DATAIN, 5, TRUE))
		return FALSE;

	DBGDUMP("tosh: Read Disc Info data bytes", buf, SZ_VT_RDINFO);

	t0 = (tinfo_00_t *) buf;
	s->first_trk = (byte_t) util_bcdtol(t0->first_trk);
	s->last_trk = (byte_t) util_bcdtol(t0->last_trk);

	/* Get the starting position of each track */
	for (i = 0, j = (int) s->first_trk; j <= (int) s->last_trk; i++, j++) {
		(void) memset(buf, 0, sizeof(buf));

		SCSICDB_RESET(cdb);
		cdb[0] = OP_VT_RDINFO;
		cdb[1] = 0x02;
		cdb[2] = (byte_t) util_ltobcd(j);

		if (!pthru_send(devfd, cdb, 10, buf, SZ_VT_RDINFO, OP_DATAIN,
				5, TRUE))
			return FALSE;

		DBGDUMP("tosh: Read Disc Info data bytes", buf, SZ_VT_RDINFO);

		t2 = (tinfo_02_t *) buf;

		s->trkinfo[i].trkno = j;
		s->trkinfo[i].min = (byte_t) util_bcdtol(t2->min);
		s->trkinfo[i].sec = (byte_t) util_bcdtol(t2->sec);
		s->trkinfo[i].frame = (byte_t) util_bcdtol(t2->frame);
		util_msftoblk(
			s->trkinfo[i].min,
			s->trkinfo[i].sec,
			s->trkinfo[i].frame,
			&s->trkinfo[i].addr,
			MSF_OFFSET
		);
	}
	s->tot_trks = (byte_t) i;

	(void) memset(buf, 0, sizeof(buf));

	/* Get the lead out track position */
	SCSICDB_RESET(cdb);
	cdb[0] = OP_VT_RDINFO;
	cdb[1] = 0x01;

	if (!pthru_send(devfd, cdb, 10, buf, SZ_VT_RDINFO, OP_DATAIN, 5, TRUE))
		return FALSE;

	DBGDUMP("tosh: Read Disc Info data bytes", buf, SZ_VT_RDINFO);

	t1 = (tinfo_01_t *) buf;

	s->trkinfo[i].trkno = LEAD_OUT_TRACK;
	s->tot_min = s->trkinfo[i].min = (byte_t) util_bcdtol(t1->min);
	s->tot_sec = s->trkinfo[i].sec = (byte_t) util_bcdtol(t1->sec);
	s->tot_frame = s->trkinfo[i].frame = (byte_t) util_bcdtol(t1->frame);
	util_msftoblk(
		s->trkinfo[i].min,
		s->trkinfo[i].sec,
		s->trkinfo[i].frame,
		&s->trkinfo[i].addr,
		MSF_OFFSET
	);
	s->tot_addr = s->trkinfo[i].addr;

	return TRUE;
}


/*
 * tosh_mute
 *	Send vendor-unique command to mute/unmute the audio
 *
 * Args:
 *	mute - TRUE: mute audio, FALSE: unmute audio
 *
 * Return:
 *	TRUE - success
 *	FALSE - failure
 */
bool_t
tosh_mute(bool_t mute)
{
	curstat_t	*s = di_clinfo->curstat_addr();

	if (tosh_audio_muted != mute) {
		switch (s->mode) {
		case MOD_BUSY:
		case MOD_NODISC:
		case MOD_STOP:
		case MOD_PAUSE:
			break;

		default:
			SCSICDB_RESET(cdb);
			cdb[0] = OP_VT_AUDPLAY;
			cdb[1] = mute ? 0x00 : 0x03;
			cdb[9] = 0xc0;

			if (!pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA,
					5, TRUE))
				return FALSE;
			break;
		}

		tosh_audio_muted = mute;
	}

	return TRUE;
}


/*
 * tosh_eject
 *	Send vendor-unique command to eject the caddy
 *
 * Args:
 *	Nothing.
 *
 * Return:
 *	TRUE - success
 *	FALSE - failure
 */
bool_t
tosh_eject(void)
{
	SCSICDB_RESET(cdb);
	cdb[0] = OP_VT_EJECT;
	cdb[1] = 0x01;	/* Set immediate bit */

	return (pthru_send(devfd, cdb, 10, NULL, 0, OP_NODATA, 20, TRUE));
}


/*
 * tosh_init
 *	Initialize the vendor-unique support module
 *
 * Args:
 *	Nothing.
 *
 * Return:
 *	Nothing.
 */
void
tosh_init(void)
{
	/* Register vendor_unique module entry points */
	scsipt_vutbl[VENDOR_TOSHIBA].vendor = "Toshiba";
	scsipt_vutbl[VENDOR_TOSHIBA].playaudio = tosh_playaudio;
	scsipt_vutbl[VENDOR_TOSHIBA].pause_resume = tosh_pause_resume;
	scsipt_vutbl[VENDOR_TOSHIBA].start_stop = NULL;
	scsipt_vutbl[VENDOR_TOSHIBA].get_playstatus = tosh_get_playstatus;
	scsipt_vutbl[VENDOR_TOSHIBA].volume = NULL;
	scsipt_vutbl[VENDOR_TOSHIBA].route = NULL;
	scsipt_vutbl[VENDOR_TOSHIBA].mute = tosh_mute;
	scsipt_vutbl[VENDOR_TOSHIBA].get_toc = tosh_get_toc;
	scsipt_vutbl[VENDOR_TOSHIBA].eject = tosh_eject;
	scsipt_vutbl[VENDOR_TOSHIBA].start = NULL;
	scsipt_vutbl[VENDOR_TOSHIBA].halt = NULL;
}


#endif	/* VENDOR_TOSHIBA */