2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)cd_misc.c 1.10 01/10/29 Copyright 1997 J. Schilling */
15 * Misc CD support routines
17 * Copyright (c) 1997 J. Schilling
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License version 2
22 * as published by the Free Software Foundation.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along with
30 * this program; see the file COPYING. If not, write to the Free Software
31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <utypes.h> /* Includes <sys/types.h> for caddr_t */
44 long msf_to_lba(int m, int s, int f, BOOL force_positive);
45 BOOL lba_to_msf(long lba, msf_t *mp);
46 void sec_to_msf(long sec, msf_t *mp);
47 void print_min_atip(long li, long lo);
52 return ((b & 0x0F) + 10 * (((b)>> 4) & 0x0F));
58 return (i % 10 | ((i / 10) % 10) << 4);
62 msf_to_lba(int m, int s, int f, BOOL force_positive)
64 long ret = m * 60 + s;
68 if (m < 90 || force_positive)
76 lba_to_msf(long lba, msf_t *mp)
82 #ifdef __follow_redbook__
83 if (lba >= -150 && lba < 405000) { /* lba <= 404849 */
87 m = (lba + 150) / 60 / 75;
88 s = (lba + 150 - m*60*75) / 75;
89 f = (lba + 150 - m*60*75 - s*75);
91 } else if (lba >= -45150 && lba <= -151) {
92 m = (lba + 450150) / 60 / 75;
93 s = (lba + 450150 - m*60*75) / 75;
94 f = (lba + 450150 - m*60*75 - s*75);
107 if (lba > 404849) /* 404850 -> 404999: lead out */
113 sec_to_msf(long sec, msf_t *mp)
120 s = (sec - m*60*75) / 75;
121 f = (sec - m*60*75 - s*75);
129 print_min_atip(long li, long lo)
134 lba_to_msf(li, &msf);
136 printf(" ATIP start of lead in: %ld (%02d:%02d/%02d)\n",
137 li, msf.msf_min, msf.msf_sec, msf.msf_frame);
140 lba_to_msf(lo, &msf);
141 printf(" ATIP start of lead out: %ld (%02d:%02d/%02d)\n",
142 lo, msf.msf_min, msf.msf_sec, msf.msf_frame);