1 /*
2 	Metados
3 
4 	Copyright (C) 2002	Patrice Mandin
5 
6 	This library is free software; you can redistribute it and/or
7 	modify it under the terms of the GNU Lesser General Public
8 	License as published by the Free Software Foundation; either
9 	version 2.1 of the License, or (at your option) any later version.
10 
11 	This library is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 	Lesser General Public License for more details.
15 
16 	You should have received a copy of the GNU Lesser General Public
17 	License along with this library; if not, write to the Free Software
18 	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
19 */
20 
21 #ifndef _METADOS_H
22 #define _METADOS_H
23 
24 #include <mint/falcon.h>	/* for trap_14_xxx macros */
25 
26 #ifndef OSBIND_CLOBBER_LIST
27 #define OSBIND_CLOBBER_LIST	"d0", "d1", "d2", "a0", "a1", "a2", "memory"
28 #endif
29 
30 #ifndef trap_14_wwllw
31 #define trap_14_wwllw(n, a, b, c, d)					\
32 __extension__								\
33 ({									\
34 	register long retvalue __asm__("d0");				\
35 	short _a = (short)(a);						\
36 	long  _b = (long) (b);						\
37 	long  _c = (long) (c);						\
38 	short _d = (short)(d);						\
39 	    								\
40 	__asm__ volatile						\
41 	("\
42 		movw    %5,sp@-; \
43 		movl    %4,sp@-; \
44 		movl    %3,sp@-; \
45 		movw    %2,sp@-; \
46 		movw    %1,sp@-; \
47 		trap    #14;	\
48 		lea	sp@(14),sp "					\
49 	: "=r"(retvalue)			/* outputs */		\
50 	: "g"(n),							\
51 	  "r"(_a), "r"(_b), "r"(_c), "r"(_d)    /* inputs  */		\
52 	: __CLOBBER_RETURN("d0")					\
53 	  "d1", "d2", "a0", "a1", "a2", "memory"			\
54 	);								\
55 	retvalue;							\
56 })
57 #endif
58 
59 #ifndef trap_14_wwlwl
60 #define trap_14_wwlwl(n,a,b,c,d)	\
61 __extension__	\
62 ({	\
63 	register long retvalue __asm__("d0");	\
64 	short _a = (short)(a);	\
65 	long _b = (long)(b);	\
66 	short _c = (short)(c);	\
67 	long _d = (long)(d);	\
68 	\
69 	__asm__ volatile (	\
70 		"movl	%5,sp@-\n\t"	\
71 		"movw	%4,sp@-\n\t"	\
72 		"movl	%3,sp@-\n\t"	\
73 		"movw	%2,sp@-\n\t"	\
74 		"movw	%1,sp@-\n\t"	\
75 		"trap	#14\n\t"	\
76 		"lea	sp@(14),sp"	\
77 		: "=r"(retvalue)	\
78 		: "g"(n), "r"(_a), "r"(_b), "r"(_c), "r"(_d)	\
79 		: OSBIND_CLOBBER_LIST	\
80 	);	\
81 	retvalue;	\
82 })
83 #endif
84 
85 /*--- Functions prototypes ---*/
86 
87 #define Metainit(buffer)	\
88 	(void)trap_14_wl((short)0x30,(long)buffer)
89 #define Metaopen(drive,buffer)	\
90 	(long)trap_14_wwl((short)0x31,(short)drive,(long)buffer)
91 #define Metaclose(drive)	\
92 	(void)trap_14_ww((short)0x32,(short)drive)
93 #define Metaread(drive,buffer,first_block,nb_blocks)	\
94 	(long)trap_14_wwllw((short)0x33,(short)drive,(long)buffer,(long)first_block,(short)nb_blocks)
95 #define Metawrite(drive,buffer,first_block,nb_blocks)	\
96 	(long)trap_14_wwllw((short)0x34,(short)drive,(long)buffer,(long)first_block,(short)nb_blocks)
97 #define Metaseek(drive,dummy,offset)	\
98 	(long)trap_14_wwll((short)0x35,(short)(drive),(long)(dummy),(long)(offset))
99 #define Metastatus(void)	\
100 	(long)trap_14_wl((short)0x36,(long)(buffer))
101 #define Metaioctl(drive,magic,opcode,buffer)	\
102 	(long)trap_14_wwlwl((short)(0x37),(short)(drive),(long)(magic),(short)(opcode),(long)(buffer))
103 
104 #define Metastartaudio(drive,dummy,metatracks_t_p)	\
105 	(long)trap_14_wwwl((short)(0x3b),(short)(drive),(short)(dummy),(long)(metatracks_t_p))
106 #define Metastopaudio(drive)	\
107 	(long)trap_14_ww((short)(0x3c),(short)(drive))
108 #define Metasetsongtime(drive,dummy,start,end)	\
109 	(long)trap_14_wwwll((short)(0x3d),(short)(drive),(short)(dummy),(long)(start),(long)(end))
110 #define Metagettoc(drive,dummy,metatocentry_t_p)	\
111 	(long)trap_14_wwwl((short)(0x3e),(short)(drive),(short)(dummy),(long)(metatocentry_t_p))
112 #define Metadiscinfo(drive,metadiscinfo_t_p)	\
113 	(long)trap_14_wwl((short)(0x3f),(short)(drive),(long)(metadiscinfo_t_p))
114 
115 #define METADOS_IOCTL_MAGIC	(((unsigned long)'F'<<24)|((unsigned long)'C'<<16)|('T'<<8)|'L')
116 
117 /* bos_info_t returning ioctl */
118 #define METADOS_IOCTL_BOSINFO	(('B'<<8)|'I')
119 
120 /*--- Types ---*/
121 
122 typedef struct {
123 	unsigned short version;
124 	unsigned long magic;
125 	char *log2phys;
126 } __attribute__((packed)) metainfo_t;
127 
128 typedef struct {
129 	unsigned long drives_map;
130 	char *version;
131 	unsigned long reserved;
132 	metainfo_t *info;
133 } __attribute__((packed)) metainit_t;
134 
135 typedef struct {
136 	char *name;
137 	unsigned long reserved[3];
138 } __attribute__((packed)) metaopen_t;
139 
140 typedef struct {
141 	char ext_status[32];
142 } __attribute__((packed)) metastatus_t;
143 
144 typedef struct {
145 	unsigned char count;
146 	unsigned char first;
147 } __attribute__((packed)) metatracks_t;
148 
149 typedef struct {	/* TOC entry for MetaGetToc() function */
150 	unsigned char track;
151 	unsigned char minute;
152 	unsigned char second;
153 	unsigned char frame;
154 } __attribute__((packed)) metatocentry_t;
155 
156 typedef struct {
157 	unsigned char reserved;
158 	unsigned char minute;
159 	unsigned char second;
160 	unsigned char frame;
161 } __attribute__((packed)) metadisc_msf_t;
162 
163 typedef struct {	/* Discinfo for MetaDiscInfo() function */
164 	unsigned char disctype, first, last, current;
165 	metadisc_msf_t	relative;
166 	metadisc_msf_t	absolute;
167 	metadisc_msf_t	end;
168 	unsigned char index, reserved1[3];
169 	unsigned long reserved2[123];
170 } __attribute__((packed)) metadiscinfo_t;
171 
172 
173 /* METADOS_IOCTL_BOSINFO ioctl() .bos driver info */
174 
175 /** the devide is a character device (all the block values in API are
176  *  meant as byte values for these */
177 #define BOS_INFO_ISTTY			0x00001UL
178 /** the device will not be visible in the x:\dev nor in x:\dev\bos */
179 #define BOS_INFO_BOSHIDDEN		0x10000UL
180 /** the device will not be visible in the x:\dev but will be in x:\dev\bos */
181 #define BOS_INFO_DEVHIDDEN		0x20000UL
182 
183 typedef struct {
184 	unsigned long	flags;
185 } __attribute__((packed)) bos_info_t;
186 
187 
188 #endif /* _METADOS_H */
189