File indexing completed on 2024-04-21 08:44:22

0001 /*
0002  * This file is part of WorkMan, the civilized CD player library
0003  * Copyright (C) 1991-1997 by Steven Grimm (original author)
0004  * Copyright (C) by Dirk Försterling <milliByte@DeathsDoor.com>
0005  * Copyright (C) 2004-2006 Alexander Kern <alex.kern@gmx.de>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public
0018  * License along with this library; if not, write to the Free
0019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0020  *
0021  *
0022  * Vendor-specific drive control routines for Toshiba XM-3401 series.
0023  */
0024 
0025 #include <stdio.h>
0026 #include <errno.h>
0027 #include "include/wm_config.h"
0028 #include "include/wm_struct.h"
0029 #include "include/wm_scsi.h"
0030 
0031 #define SCMD_TOSH_EJECT 0xc4
0032 
0033 /* local prototypes */
0034 /* static int min_volume = 0, max_volume = 255; */
0035 
0036 /*
0037  * Undo the transformation above using a binary search (so no floating-point
0038  * math is required.)
0039  */
0040 static int unscale_volume(int cd_vol, int max)
0041 {
0042     int vol = 0, top = max, bot = 0, scaled = 0;
0043 
0044     /*cd_vol = (cd_vol * 100 + (max_volume - 1)) / max_volume;*/
0045 
0046     while (bot <= top)
0047     {
0048         vol = (top + bot) / 2;
0049         scaled = (vol * vol) / max;
0050         if (cd_vol <= scaled)
0051             top = vol - 1;
0052         else
0053             bot = vol + 1;
0054     }
0055 
0056     /* Might have looked down too far for repeated scaled values */
0057     if (cd_vol < scaled)
0058         vol++;
0059 
0060     if (vol < 0)
0061         vol = 0;
0062     else if (vol > max)
0063         vol = max;
0064 
0065     return (vol);
0066 }
0067 
0068 /*
0069  * Send the Toshiba code to eject the CD.
0070  */
0071 static int tosh_eject(struct wm_drive *d)
0072 {
0073     return sendscsi(d, NULL, 0, 0, SCMD_TOSH_EJECT, 1, 0,0,0,0,0,0,0,0,0,0);
0074 }
0075 
0076 /*
0077  * Set the volume.  The low end of the scale is more sensitive than the high
0078  * end, so make up for that by transforming the volume parameters to a square
0079  * curve.
0080  */
0081 static int tosh_scale_volume(int *left, int *right)
0082 {
0083     *left = (*left * *left * *left) / 10000;
0084     *right = (*right * *right * *right) / 10000;
0085 
0086     return 0;
0087 }
0088 
0089 static int tosh_unscale_volume(int *left, int *right)
0090 {
0091     *left = unscale_volume(*left, 100);
0092     *right = unscale_volume(*right, 100);
0093 
0094     return 0;
0095 }
0096 
0097 int toshiba_fixup(struct wm_drive *d)
0098 {
0099     d->proto.eject = tosh_eject;
0100     d->proto.scale_volume = tosh_scale_volume;
0101     d->proto.unscale_volume = tosh_unscale_volume;
0102 
0103     return 0;
0104 }