1 /*
2  *   cda - Command-line CD Audio Player/Ripper
3  *
4  *   Copyright (C) 1993-2004  Ti Kan
5  *   E-mail: xmcd@amb.org
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 2 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #ifndef __CDA_H__
23 #define __CDA_H__
24 
25 #ifndef lint
26 static char *_cda_h_ident_ = "@(#)cda.h	6.48 04/04/20";
27 #endif
28 
29 
30 #if !defined(USE_TERMIOS) && !defined(USE_TERMIO) && !defined(USE_SGTTY)
31 #define USE_TERMIOS	/* Make USE_TERMIOS the default if not specified */
32 #endif
33 
34 #ifdef USE_TERMIOS
35 #include <termios.h>
36 #endif
37 #ifdef USE_TERMIO
38 #include <termio.h>
39 #endif
40 #ifdef USE_SGTTY
41 #include <sgtty.h>
42 #endif
43 
44 
45 /* Program name string */
46 #define PROGNAME		"cda"
47 
48 
49 /* Macros */
50 #define CDA_FATAL(msg)		cda_fatal_msg(app_data.str_fatal, (msg))
51 #define CDA_WARNING(msg)	cda_warning_msg(app_data.str_warning, (msg))
52 #define CDA_INFO(msg)		cda_info_msg(app_data.str_info, (msg))
53 
54 
55 /* CDA packet magic number */
56 #define CDA_MAGIC		0xcda2
57 
58 
59 /* CDA commands */
60 #define CDA_ON			0x100
61 #define CDA_OFF			0x101
62 #define CDA_DISC		0x102
63 #define CDA_LOCK		0x103
64 #define CDA_PLAY		0x104
65 #define CDA_PAUSE		0x105
66 #define CDA_STOP		0x106
67 #define CDA_TRACK		0x107
68 #define CDA_INDEX		0x108
69 #define CDA_VOLUME		0x109
70 #define CDA_BALANCE		0x10a
71 #define CDA_ROUTE		0x10b
72 #define CDA_OUTPORT		0x10c
73 #define CDA_CDDA_ATT		0x10d
74 #define CDA_PROGRAM		0x10e
75 #define CDA_SHUFFLE		0x10f
76 #define CDA_REPEAT		0x110
77 #define CDA_STATUS		0x111
78 #define CDA_TOC			0x112
79 #define CDA_EXTINFO		0x113
80 #define CDA_DEVICE		0x114
81 #define CDA_VERSION		0x115
82 #define CDA_DEBUG		0x116
83 #define CDA_TOC2		0x117
84 #define CDA_ON_LOAD		0x118
85 #define CDA_ON_EXIT		0x119
86 #define CDA_ON_DONE		0x11a
87 #define CDA_ON_EJECT		0x11b
88 #define CDA_CHGR		0x11c
89 #define CDA_NOTES		0x11d
90 #define CDA_CDDBREG		0x11e
91 #define CDA_CDDBHINT		0x11f
92 #define CDA_MODE		0x120
93 #define CDA_JITTER		0x121
94 #define CDA_TRKFILE		0x122
95 #define CDA_SUBST		0x123
96 #define CDA_FILEFMT		0x124
97 #define CDA_FILE		0x125
98 #define CDA_PIPEPROG		0x126
99 #define CDA_COMPRESS		0x127
100 #define CDA_BRATE		0x128
101 #define CDA_CODING		0x129
102 #define CDA_FILTER		0x12a
103 #define CDA_FLAGS		0x12b
104 #define CDA_TAG			0x12c
105 #define CDA_AUTHUSER		0x12d
106 #define CDA_AUTHPASS		0x12e
107 #define CDA_LAMEOPTS		0x12f
108 #define CDA_MOTD		0x130
109 
110 
111 
112 /* CDA return code */
113 #define CDA_UNKNOWN		0x00
114 #define CDA_OK			0x01
115 #define CDA_INVALID		0x02
116 #define CDA_PARMERR		0x03
117 #define CDA_FAILED		0x04
118 #define CDA_REFUSED		0x05
119 #define CDA_DAEMON_EXIT		0x06
120 
121 
122 /* Max number of 32-bit arguments */
123 #define CDA_NARGS		101
124 
125 
126 /* CDA_STAT return argument macros */
127 #define RD_ARG_MODE(x)		(((x) & 0xff000000) >> 24)	/* arg[0] */
128 
129 #define RD_ARG_LOCK(x)		((x) & 0x00010000)		/* arg[0] */
130 #define RD_ARG_SHUF(x)		((x) & 0x00020000)		/* arg[0] */
131 #define RD_ARG_PROG(x)		((x) & 0x00040000)		/* arg[0] */
132 #define RD_ARG_REPT(x)		((x) & 0x00080000)		/* arg[0] */
133 
134 #define RD_ARG_SEC(x)		((x) & 0xff)			/* arg[1] */
135 #define RD_ARG_MIN(x)		(((x) >> 8) & 0xff)		/* arg[1] */
136 #define RD_ARG_IDX(x)		(((x) >> 16) & 0xff)		/* arg[1] */
137 #define RD_ARG_TRK(x)		(((x) >> 24) & 0xff)		/* arg[1] */
138 
139 #define WR_ARG_MODE(x,v)	((x) |= (((v) & 0xff) << 24))	/* arg[0] */
140 
141 #define WR_ARG_LOCK(x)		((x) |= 0x00010000)		/* arg[0] */
142 #define WR_ARG_SHUF(x)		((x) |= 0x00020000)		/* arg[0] */
143 #define WR_ARG_PROG(x)		((x) |= 0x00040000)		/* arg[0] */
144 #define WR_ARG_REPT(x)		((x) |= 0x00080000)		/* arg[0] */
145 
146 #define WR_ARG_SEC(x,v)		((x) |= ((v) & 0xff))		/* arg[1] */
147 #define WR_ARG_MIN(x,v)		((x) |= (((v) & 0xff) << 8))	/* arg[1] */
148 #define WR_ARG_IDX(x,v)		((x) |= (((v) & 0xff) << 16))	/* arg[1] */
149 #define WR_ARG_TRK(x,v)		((x) |= (((v) & 0xff) << 24))	/* arg[1] */
150 
151 
152 /* CDA_TOC return argument macros */
153 #define RD_ARG_TOC(x,t,p,m,s)	{	\
154 	(p) = (bool_t) ((x) >> 24);	\
155 	((t) = ((x) >> 16) & 0xff);	\
156 	((m) = ((x) >> 8) & 0xff);	\
157 	((s) = (x) & 0xff);		\
158 }								/* arg[n] */
159 
160 #define WR_ARG_TOC(x,t,p,m,s)	{	\
161 	if ((p) == (t))			\
162 		(x) |= 1 << 24;		\
163 	(x) |= (((t) & 0xff) << 16);	\
164 	(x) |= (((m) & 0xff) << 8);	\
165 	(x) |= ((s) & 0xff);		\
166 }								/* arg[n] */
167 
168 /* CDA_TOC2 return argument macros */
169 #define RD_ARG_TOC2(x,t,m,s,f)	{	\
170 	((t) = ((x) >> 24) & 0xff);	\
171 	((m) = ((x) >> 16) & 0xff);	\
172 	((s) = ((x) >> 8) & 0xff);	\
173 	((f) = (x) & 0xff);		\
174 }								/* arg[n] */
175 
176 #define WR_ARG_TOC2(x,t,m,s,f)	{	\
177 	(x) |= (((t) & 0xff) << 24);	\
178 	(x) |= (((m) & 0xff) << 16);	\
179 	(x) |= (((s) & 0xff) << 8);	\
180 	(x) |= ((f) & 0xff);		\
181 }								/* arg[n] */
182 
183 /* CDA pipe protocol packet */
184 typedef struct cda_pkt {
185 	word32_t	magic;
186 	word32_t	pktid;
187 	word32_t	cmd;
188 	word32_t	retcode;
189 	word32_t	rejcnt;
190 	word32_t	arg[CDA_NARGS];
191 	byte_t		pad[88];
192 } cdapkt_t;
193 
194 
195 /* Public function prototypes */
196 extern void		cda_echo(FILE *, bool_t);
197 extern curstat_t	*curstat_addr(void);
198 extern void		cda_quit(curstat_t *);
199 extern void		cda_warning_msg(char *, char *);
200 extern void		cda_info_msg(char *, char *);
201 extern void		cda_fatal_msg(char *, char *);
202 extern void		cda_parse_devlist(curstat_t *);
203 extern void		cda_dbclear(curstat_t *, bool_t);
204 extern bool_t		cda_dbload(word32_t, int (*)(cdinfo_match_t *),
205 				   int (*)(int), int);
206 extern bool_t		cda_sendcmd(word32_t, word32_t [], int *);
207 extern bool_t		cda_daemon_alive(void);
208 extern bool_t		cda_daemon(curstat_t *);
209 
210 #endif	/* __CDA_H__ */
211