wmmisc: Bump to version 1.2.
[dockapps.git] / ascd / libworkman / drv_toshiba.c
blobd535f3ee8a5924ce91754fa132609b150c455993
1 /*
2 * $Id: drv_toshiba.c,v 1.3 1999/02/14 09:50:42 dirk Exp $
4 * This file is part of WorkMan, the civilized CD player library
5 * (c) 1991-1997 by Steven Grimm (original author)
6 * (c) by Dirk Försterling (current 'author' = maintainer)
7 * The maintainer can be contacted by his e-mail address:
8 * milliByte@DeathsDoor.com
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Vendor-specific drive control routines for Toshiba XM-3401 series.
28 static char drv_toshiba_id[] = "$Id: drv_toshiba.c,v 1.3 1999/02/14 09:50:42 dirk Exp $";
30 #include <stdio.h>
31 #include <errno.h>
32 #include "include/wm_config.h"
33 #include "include/wm_struct.h"
34 #include "include/wm_scsi.h"
36 #define SCMD_TOSH_EJECT 0xc4
38 /* local prototypes */
39 static int tosh_init( struct wm_drive *d );
40 static int tosh_eject( struct wm_drive *d );
41 static int tosh_set_volume( struct wm_drive *d, int left, int right );
42 static int tosh_get_volume( struct wm_drive *d, int *left, int *right );
44 struct wm_drive toshiba_proto = {
45 -1, /* fd */
46 "Toshiba", /* vendor */
47 "", /* model */
48 "", /* revision */
49 NULL, /* aux */
50 NULL, /* daux */
52 tosh_init, /* functions... */
53 gen_get_trackcount,
54 gen_get_cdlen,
55 gen_get_trackinfo,
56 gen_get_drive_status,
57 tosh_get_volume,
58 tosh_set_volume,
59 gen_pause,
60 gen_resume,
61 gen_stop,
62 gen_play,
63 tosh_eject,
64 gen_closetray
68 * Initialize the driver.
70 static int
71 tosh_init( struct wm_drive *d )
73 extern int min_volume;
75 /* Sun use Toshiba drives as well */
76 #if defined(SYSV) && defined(CODEC)
77 codec_init();
78 #endif
79 min_volume = 0;
80 return ( 0 );
84 * Send the Toshiba code to eject the CD.
86 static int
87 tosh_eject( struct wm_drive *d )
89 return (sendscsi(d, NULL, 0, 0, SCMD_TOSH_EJECT, 1, 0,0,0,0,0,0,0,0,0,0));
93 * Set the volume. The low end of the scale is more sensitive than the high
94 * end, so make up for that by transforming the volume parameters to a square
95 * curve.
97 static int
98 tosh_set_volume( struct wm_drive *d, int left, int right )
100 left = (left * left * left) / 10000;
101 right = (right * right * right) / 10000;
102 return (gen_set_volume(d, left, right));
106 * Undo the transformation above using a binary search (so no floating-point
107 * math is required.)
109 static int
110 unscale_volume(cd_vol, max)
111 int cd_vol, max;
113 int vol = 0, top = max, bot = 0, scaled = 0;
115 /*cd_vol = (cd_vol * 100 + (max_volume - 1)) / max_volume;*/
117 while (bot <= top)
119 vol = (top + bot) / 2;
120 scaled = (vol * vol) / max;
121 if (cd_vol <= scaled)
122 top = vol - 1;
123 else
124 bot = vol + 1;
127 /* Might have looked down too far for repeated scaled values */
128 if (cd_vol < scaled)
129 vol++;
131 if (vol < 0)
132 vol = 0;
133 else if (vol > max)
134 vol = max;
136 return (vol);
140 * Get the volume.
142 static int
143 tosh_get_volume( struct wm_drive *d, int *left, int *right )
145 int status;
147 status = gen_get_volume(d, left, right);
148 if (status < 0)
149 return (status);
150 *left = unscale_volume(*left, 100);
151 *right = unscale_volume(*right, 100);
153 return (0);