1 #ifndef __GNUC__
2 #error "this file is for GNU-C only"
3 #endif
4 #include <osbind.h>
5 #include "nfosmesa_nfapi.h"
6 #include <mint/basepage.h>
7 #include "lib-osmesa.h"
8 #include "lib-oldmesa.h"
9 #include "lib-misc.h"
10 
11 
12 #define __CDECL
13 
14 typedef long __CDECL (*SLB_LFUNC)(BASEPAGE *pd, long fn, long nargs, ...);
15 
16 #ifndef __STRINGIFY
17 #define __STRINGIFY(x) __STRINGIFY1(x)
18 #define __STRINGIFY1(x) #x
19 #endif
20 
21 /* generate the prototypes */
22 #define varargs(proto...) proto
23 #undef NOTHING
24 #undef AND
25 #define NOTHING
26 #define AND ,
27 #define NO_PROC
28 #define GL_PROC(type, gl, name, export, upper, proto, args, first, ret) static type __CDECL slb_ ## gl ## name(BASEPAGE *__basepage, long __fn, long __nwords, gl_private *private, void *first_param);
29 #define GL_PROC64(type, gl, name, export, upper, proto, args, first, ret) static void __CDECL slb_ ## gl ## name(BASEPAGE *__basepage, long __fn, long __nwords, gl_private *private, void *first_param, GLuint64 *retval);
30 #define LENGL_PROC(type, glx, name, export, upper, proto, args, first, ret) static const GLubyte *__CDECL slb_ ## gl ## name(BASEPAGE *__basepage, long __fn, long __nwords, gl_private *private, void *first_param);
31 #define PUTGL_PROC(type, glx, name, export, upper, proto, args, first, ret) NO_PROC
32 #define OSMESA_PROC(type, gl, name, export, upper, proto, args, first, ret) static type __CDECL slb_ ## OSMesa ## name(BASEPAGE *__basepage, long __fn, long __nwords, gl_private *private, void *first_param);
33 #define TINYGL_PROC(type, gl, name, export, upper, proto, args, first, ret) static type __CDECL slb_ ## name(BASEPAGE *__basepage, long __fn, long __nwords, gl_private *private, void *first_param);
34 #include "glfuncs-bynum.h"
35 
36 static long __CDECL slb_libinit(BASEPAGE *base, long fn, long nwords, gl_private *private);
37 
38 /* The file header of a shared library */
39 struct slb_head
40 {
41 	long		slh_magic;								/* Magic value (0x70004afc) */
42 	const char	*slh_name;								/* Name of the library */
43 	long		slh_version;							/* Version number */
44 	long		slh_flags;								/* Flags, currently 0L and unused */
45 	long		__CDECL (*slh_slb_init)(void);			/* Pointer to init()-function */
46 	void		__CDECL (*slh_slb_exit)(void);			/* Pointer to exit()-function */
47 	long		__CDECL (*slh_slb_open)(BASEPAGE *b);	/* Pointer to open()-function */
48 	long		__CDECL (*slh_slb_close)(BASEPAGE *b);	/* Pointer to close()-function */
49 	const char	*const *slh_names;						/* Pointer to functions names, or 0L */
50 	void        *sl_next;                               /* used by MetaDOS loader */
51 	long		slh_reserved[7];						/* Currently 0L and unused */
52 	long		slh_no_funcs;							/* Number of functions */
53 	SLB_LFUNC	slh_functions[NFOSMESA_LAST];			/* The function pointers */
54 };
55 
56 
57 static char const slh_name[];
58 static char const *const slh_names[];
59 
60 static long __CDECL slb_init(void);
61 static void __CDECL slb_exit(void);
62 static long __CDECL slb_open(BASEPAGE *bp);
63 static long __CDECL slb_close(BASEPAGE *bp);
64 
65 static void __CDECL slb_nop(void);
66 
67 /*
68  * The file header of a shared library
69  *
70  * This replaces the startup code, and must be the first thing in this file,
71  * and also in the resulting executable.
72  * Make sure your binutils put this into the text section.
73  */
74 struct slb_head const _start = {
75 	0x70004afc,
76 	slh_name,
77 	ARANFOSMESA_NFAPI_VERSION,
78 	0,
79 	slb_init,
80 	slb_exit,
81 	slb_open,
82 	slb_close,
83 	slh_names,
84 	0,
85 	{ 0, 0, 0, 0, 0, 0, 0 },
86 	NFOSMESA_LAST,
87 	{
88 		(SLB_LFUNC)slb_libinit,
89 /* generate the function table */
90 #define GL_PROC(type, gl, name, export, upper, proto, args, first, ret) (SLB_LFUNC)slb_ ## gl ## name,
91 #define LENGL_PROC(type, glx, name, export, upper, proto, args, first, ret) (SLB_LFUNC)slb_ ## gl ## name,
92 #define PUTGL_PROC(type, glx, name, export, upper, proto, args, first, ret) NO_PROC
93 #define OSMESA_PROC(type, gl, name, export, upper, proto, args, first, ret) (SLB_LFUNC)slb_ ## OSMesa ## name,
94 #define TINYGL_PROC(type, gl, name, export, upper, proto, args, first, ret) (SLB_LFUNC)slb_ ## name,
95 #define NO_PROC (SLB_LFUNC)slb_nop,
96 #include "glfuncs-bynum.h"
97 	}
98 };
99 
100 static char const slh_name[] = "osmesa.slb";
101 
102 #define unused __attribute__((__unused__))
103 
slb_libinit(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private)104 static long __CDECL slb_libinit(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private)
105 {
106 	internal_glInit(private);
107 	return sizeof(*private);
108 }
109 
110 
111 /* generate the function names */
112 static char const *const slh_names[] = {
113 	"glInit", /* slb_libinit */
114 #define GL_PROC(type, gl, name, export, upper, proto, args, first, ret) #gl #name,
115 #define LENGL_PROC(type, glx, name, export, upper, proto, args, first, ret) "gl" #name,
116 #define PUTGL_PROC(type, glx, name, export, upper, proto, args, first, ret) NO_PROC
117 #define OSMESA_PROC(type, gl, name, export, upper, proto, args, first, ret) #gl #name,
118 #define TINYGL_PROC(type, gl, name, export, upper, proto, args, first, ret) #name,
119 #define NO_PROC 0,
120 #include "glfuncs-bynum.h"
121 	0
122 };
123 
124 
125 
126 /* generate the wrapper functions */
127 #define voidf /**/
128 #define GL_PROC(type, gl, name, export, upper, proto, args, first, ret) \
129 static type __CDECL slb_ ## gl ## name(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param) \
130 { \
131 	ret (*HostCall_p)(NFOSMESA_GL ## upper, private->cur_context, first_param); \
132 }
133 #define GL_PROC64(type, gl, name, export, upper, proto, args, first, ret) \
134 static void __CDECL slb_ ## gl ## name(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param, GLuint64 *retval) \
135 { \
136 	(*HostCall64_p)(NFOSMESA_GL ## upper, private->cur_context, first_param, retval); \
137 }
138 #define GLU_PROC(type, gl, name, export, upper, proto, args, first, ret) \
139 static type __CDECL slb_ ## gl ## name(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param) \
140 { \
141 	ret (*HostCall_p)(NFOSMESA_GLU ## upper, private->cur_context, first_param); \
142 }
143 #define OSMESA_PROC(type, gl, name, export, upper, proto, args, first, ret) \
144 static type __CDECL slb_ ## gl ## name(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param) \
145 { \
146 	ret (*HostCall_p)(NFOSMESA_OSMESA ## upper, private->cur_context, first_param); \
147 }
148 #define NO_OSMESAGETCURRENTCONTEXT
149 #define NO_OSMESADESTROYCONTEXT
150 #define NO_OSMESAMAKECURRENT
151 #define NO_OSMESAGETPROCADDRESS
152 #define NO_GLGETSTRING
153 #define NO_GLGETSTRINGI
154 #include "glfuncs.h"
155 
156 
slb_nop(void)157 static void __CDECL slb_nop(void)
158 {
159 }
160 
161 
162 /* some functions do need special work */
163 
slb_glGetString(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)164 static const GLubyte *__CDECL slb_glGetString(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
165 {
166 	GLenum *args = (GLenum *)first_param;
167 	return internal_glGetString(private, args[0]);
168 }
169 
170 
slb_glGetStringi(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)171 static const GLubyte *__CDECL slb_glGetStringi(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
172 {
173 	GLenum *args = (GLenum *)first_param;
174 	return internal_glGetStringi(private, args[0], args[1]);
175 }
176 
177 
slb_OSMesaGetCurrentContext(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param unused)178 static OSMesaContext __CDECL slb_OSMesaGetCurrentContext(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param unused)
179 {
180 	return internal_OSMesaGetCurrentContext(private);
181 }
182 
slb_OSMesaDestroyContext(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)183 static void __CDECL slb_OSMesaDestroyContext(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
184 {
185 	OSMesaContext ctx = *((OSMesaContext *)first_param);
186 	return internal_OSMesaDestroyContext(private, ctx);
187 }
188 
189 
slb_OSMesaMakeCurrent(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)190 static GLboolean __CDECL slb_OSMesaMakeCurrent(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
191 {
192 	GLboolean ret = (GLboolean)(*HostCall_p)(NFOSMESA_OSMESAMAKECURRENT, private->cur_context, first_param);
193 	if (ret)
194 	{
195 		OSMesaContext ctx = *((OSMesaContext *)first_param);
196 		private->cur_context = ctx;
197 	}
198 	return ret;
199 }
200 
201 
slb_OSMesaGetProcAddress(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)202 static OSMESAproc __CDECL slb_OSMesaGetProcAddress(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
203 {
204 	const char *funcname = *((const char *const *)first_param);
205 	return internal_OSMesaGetProcAddress(private, funcname);
206 }
207 
208 
209 
210 /* entry points of TinyGL functions */
slb_OSMesaCreateLDG(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)211 static void *__CDECL slb_OSMesaCreateLDG(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
212 {
213 	GLenum *args = (GLenum *)first_param;
214 	return internal_OSMesaCreateLDG(private, args[0], args[1], args[2], args[3]);
215 }
216 
217 
slb_OSMesaDestroyLDG(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param unused)218 static void __CDECL slb_OSMesaDestroyLDG(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param unused)
219 {
220 	internal_OSMesaDestroyLDG(private);
221 }
222 
223 
slb_max_width(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param unused)224 static GLsizei __CDECL slb_max_width(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param unused)
225 {
226 	return internal_max_width(private);
227 }
228 
229 
slb_max_height(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param unused)230 static GLsizei __CDECL slb_max_height(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param unused)
231 {
232 	return internal_max_height(private);
233 }
234 
235 
slb_gluLookAtf(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)236 static void __CDECL slb_gluLookAtf(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
237 {
238 	(*HostCall_p)(NFOSMESA_GLULOOKATF, private->cur_context, first_param);
239 }
240 
241 
slb_glFrustumf(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)242 static void __CDECL slb_glFrustumf(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
243 {
244 	(*HostCall_p)(NFOSMESA_GLFRUSTUMF, private->cur_context, first_param);
245 }
246 
247 
slb_glOrthof(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)248 static void __CDECL slb_glOrthof(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
249 {
250 	(*HostCall_p)(NFOSMESA_GLORTHOF, private->cur_context, first_param);
251 }
252 
253 
slb_exception_error(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)254 static void __CDECL slb_exception_error(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
255 {
256 	void CALLBACK (*exception)(GLenum param) = *((void CALLBACK (**)(GLenum))first_param);
257 	internal_tinyglexception_error(private, exception);
258 }
259 
260 
slb_swapbuffer(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private,void * first_param)261 static void __CDECL slb_swapbuffer(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private, void *first_param)
262 {
263 	void *buf = *((void **)first_param);
264 	internal_tinyglswapbuffer(private, buf);
265 }
266 
267 
slb_information(BASEPAGE * __bp unused,long __fn unused,long __nwords unused,gl_private * private unused,void * first_param unused)268 static void __CDECL slb_information(BASEPAGE *__bp unused, long __fn unused, long __nwords unused, gl_private *private unused, void *first_param unused)
269 {
270 	tinyglinformation();
271 }
272 
273 
274 
err_old_nfapi(void)275 int err_old_nfapi(void)
276 {
277 	/* an error for Mesa_GL */
278 	return 1;
279 }
280 
281 
282 /*
283  * these are not optional and cannot be set
284  * to zero in the header, even if they
285  * currently don't do anything
286  */
slb_init(void)287 static long __CDECL slb_init(void)
288 {
289 	return 0;
290 }
291 
292 
slb_exit(void)293 static void __CDECL slb_exit(void)
294 {
295 }
296 
297 
slb_open(BASEPAGE * pd)298 static long __CDECL slb_open(BASEPAGE *pd)
299 {
300 	(void) pd;
301 	return 0;
302 }
303 
304 
slb_close(BASEPAGE * pd)305 static long __CDECL slb_close(BASEPAGE *pd)
306 {
307 	(void) pd;
308 	return 0;
309 }
310 
311 
312 #include "versinfo.h"
313 
tinyglinformation(void)314 void APIENTRY tinyglinformation(void)
315 {
316 	(void) Cconws("Mesa library NFOSMesa API Version " __STRINGIFY(ARANFOSMESA_NFAPI_VERSION) " " ASCII_ARCH_TARGET " " ASCII_COMPILER "\r\n");
317 }
318