1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Michael Sevakis
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 int round_value_to_list32(unsigned long value
,
24 const unsigned long list
[],
28 unsigned long dmin
= ULONG_MAX
;
31 for (i
= 0; i
< count
; i
++)
41 if (signd
? ((long)list
[i
] < (long)value
) : (list
[i
] < value
))
42 diff
= value
- list
[i
];
44 diff
= list
[i
] - value
;
54 } /* round_value_to_list32 */
56 /* Number of bits set in src_mask should equal src_list length */
57 int make_list_from_caps32(unsigned long src_mask
,
58 const unsigned long *src_list
,
59 unsigned long caps_mask
,
60 unsigned long *caps_list
)
65 for (mask
= src_mask
, count
= 0, i
= 0;
69 unsigned long test_bit
;
70 mask
&= mask
- 1; /* Zero lowest bit set */
71 test_bit
= mask
^ src_mask
; /* Isolate the bit */
72 if (test_bit
& caps_mask
) /* Add item if caps has test bit set */
73 caps_list
[count
++] = src_list
? src_list
[i
] : (unsigned long)i
;
77 } /* make_list_from_caps32 */