make sdl.hidd build against recent iconv-aware sdls
[tangerine.git] / arch / all-hosted / hidd / sdl / sdl_hostlib.c
blob1b87d94007808ed12bbcf5d5d05992456802e852
1 /*
2 * sdl.hidd - SDL graphics/sound/keyboard for AROS hosted
3 * Copyright (c) 2007 Robert Norris. All rights reserved.
4 * Copyright (c) 2007-2009 The AROS Development Team
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
8 */
10 #include <aros/bootloader.h>
11 #include <aros/symbolsets.h>
13 #include <exec/types.h>
14 #include <exec/semaphores.h>
16 #include <proto/bootloader.h>
17 #include <proto/exec.h>
18 #include <proto/hostlib.h>
20 #include LC_LIBDEFS_FILE
22 #include "sdl_intern.h"
24 #define DEBUG 1
25 #include <aros/debug.h>
27 struct sdl_funcs sdl_funcs;
29 static const char *sdl_func_names[] = {
30 "SDL_SetError",
31 "SDL_GetError",
32 "SDL_ClearError",
33 "SDL_Error",
34 "SDL_CreateMutex",
35 "SDL_mutexP",
36 "SDL_mutexV",
37 "SDL_DestroyMutex",
38 "SDL_CreateSemaphore",
39 "SDL_DestroySemaphore",
40 "SDL_SemWait",
41 "SDL_SemTryWait",
42 "SDL_SemWaitTimeout",
43 "SDL_SemPost",
44 "SDL_SemValue",
45 "SDL_CreateCond",
46 "SDL_DestroyCond",
47 "SDL_CondSignal",
48 "SDL_CondBroadcast",
49 "SDL_CondWait",
50 "SDL_CondWaitTimeout",
51 "SDL_CreateThread",
52 "SDL_ThreadID",
53 "SDL_GetThreadID",
54 "SDL_WaitThread",
55 "SDL_KillThread",
56 "SDL_RWFromFile",
57 "SDL_RWFromFP",
58 "SDL_RWFromMem",
59 "SDL_RWFromConstMem",
60 "SDL_AllocRW",
61 "SDL_FreeRW",
62 "SDL_ReadLE16",
63 "SDL_ReadBE16",
64 "SDL_ReadLE32",
65 "SDL_ReadBE32",
66 "SDL_ReadLE64",
67 "SDL_ReadBE64",
68 "SDL_WriteLE16",
69 "SDL_WriteBE16",
70 "SDL_WriteLE32",
71 "SDL_WriteBE32",
72 "SDL_WriteLE64",
73 "SDL_WriteBE64",
74 "SDL_AudioInit",
75 "SDL_AudioQuit",
76 "SDL_AudioDriverName",
77 "SDL_OpenAudio",
78 "SDL_GetAudioStatus",
79 "SDL_PauseAudio",
80 "SDL_LoadWAV_RW",
81 "SDL_FreeWAV",
82 "SDL_BuildAudioCVT",
83 "SDL_ConvertAudio",
84 "SDL_MixAudio",
85 "SDL_LockAudio",
86 "SDL_UnlockAudio",
87 "SDL_CloseAudio",
88 "SDL_CDNumDrives",
89 "SDL_CDName",
90 "SDL_CDOpen",
91 "SDL_CDStatus",
92 "SDL_CDPlayTracks",
93 "SDL_CDPlay",
94 "SDL_CDPause",
95 "SDL_CDResume",
96 "SDL_CDStop",
97 "SDL_CDEject",
98 "SDL_CDClose",
99 "SDL_HasRDTSC",
100 "SDL_HasMMX",
101 "SDL_HasMMXExt",
102 "SDL_Has3DNow",
103 "SDL_Has3DNowExt",
104 "SDL_HasSSE",
105 "SDL_HasSSE2",
106 "SDL_HasAltiVec",
107 "SDL_GetAppState",
108 "SDL_EnableUNICODE",
109 "SDL_EnableKeyRepeat",
110 "SDL_GetKeyRepeat",
111 "SDL_GetKeyState",
112 "SDL_GetModState",
113 "SDL_SetModState",
114 "SDL_GetKeyName",
115 "SDL_VideoInit",
116 "SDL_VideoQuit",
117 "SDL_VideoDriverName",
118 "SDL_GetVideoSurface",
119 "SDL_GetVideoInfo",
120 "SDL_VideoModeOK",
121 "SDL_ListModes",
122 "SDL_SetVideoMode",
123 "SDL_UpdateRects",
124 "SDL_UpdateRect",
125 "SDL_Flip",
126 "SDL_SetGamma",
127 "SDL_SetGammaRamp",
128 "SDL_GetGammaRamp",
129 "SDL_SetColors",
130 "SDL_SetPalette",
131 "SDL_MapRGB",
132 "SDL_MapRGBA",
133 "SDL_GetRGB",
134 "SDL_GetRGBA",
135 "SDL_CreateRGBSurface",
136 "SDL_CreateRGBSurfaceFrom",
137 "SDL_FreeSurface",
138 "SDL_LockSurface",
139 "SDL_UnlockSurface",
140 "SDL_LoadBMP_RW",
141 "SDL_SaveBMP_RW",
142 "SDL_SetColorKey",
143 "SDL_SetAlpha",
144 "SDL_SetClipRect",
145 "SDL_GetClipRect",
146 "SDL_ConvertSurface",
147 "SDL_UpperBlit",
148 "SDL_LowerBlit",
149 "SDL_FillRect",
150 "SDL_DisplayFormat",
151 "SDL_DisplayFormatAlpha",
152 "SDL_CreateYUVOverlay",
153 "SDL_LockYUVOverlay",
154 "SDL_UnlockYUVOverlay",
155 "SDL_DisplayYUVOverlay",
156 "SDL_FreeYUVOverlay",
157 "SDL_GL_LoadLibrary",
158 "SDL_GL_GetProcAddress",
159 "SDL_GL_SetAttribute",
160 "SDL_GL_GetAttribute",
161 "SDL_GL_SwapBuffers",
162 "SDL_GL_UpdateRects",
163 "SDL_GL_Lock",
164 "SDL_GL_Unlock",
165 "SDL_WM_SetCaption",
166 "SDL_WM_GetCaption",
167 "SDL_WM_SetIcon",
168 "SDL_WM_IconifyWindow",
169 "SDL_WM_ToggleFullScreen",
170 "SDL_WM_GrabInput",
171 "SDL_SoftStretch",
172 "SDL_GetMouseState",
173 "SDL_GetRelativeMouseState",
174 "SDL_WarpMouse",
175 "SDL_CreateCursor",
176 "SDL_SetCursor",
177 "SDL_GetCursor",
178 "SDL_FreeCursor",
179 "SDL_ShowCursor",
180 "SDL_NumJoysticks",
181 "SDL_JoystickName",
182 "SDL_JoystickOpen",
183 "SDL_JoystickOpened",
184 "SDL_JoystickIndex",
185 "SDL_JoystickNumAxes",
186 "SDL_JoystickNumBalls",
187 "SDL_JoystickNumHats",
188 "SDL_JoystickNumButtons",
189 "SDL_JoystickUpdate",
190 "SDL_JoystickEventState",
191 "SDL_JoystickGetAxis",
192 "SDL_JoystickGetHat",
193 "SDL_JoystickGetBall",
194 "SDL_JoystickGetButton",
195 "SDL_JoystickClose",
196 "SDL_PumpEvents",
197 "SDL_PeepEvents",
198 "SDL_PollEvent",
199 "SDL_WaitEvent",
200 "SDL_PushEvent",
201 "SDL_SetEventFilter",
202 "SDL_GetEventFilter",
203 "SDL_EventState",
204 "SDL_LoadObject",
205 "SDL_LoadFunction",
206 "SDL_UnloadObject",
207 "SDL_GetTicks",
208 "SDL_Delay",
209 "SDL_SetTimer",
210 "SDL_AddTimer",
211 "SDL_RemoveTimer",
212 "SDL_Linked_Version",
213 "SDL_Init",
214 "SDL_InitSubSystem",
215 "SDL_QuitSubSystem",
216 "SDL_WasInit",
217 "SDL_Quit",
218 NULL
221 APTR HostLibBase;
223 static void *sdl_hostlib_load_so(const char *sofile, const char **names, void **funcptr) {
224 void *handle;
225 char *err;
226 int i;
228 D(bug("[sdl] loading functions from %s\n", sofile));
230 if ((handle = HostLib_Open(sofile, &err)) == NULL) {
231 kprintf("[sdl] couldn't open '%s': %s\n", sofile, err);
232 return NULL;
235 for (i = 0; names[i]; i++) {
236 funcptr[i] = HostLib_GetPointer(handle, names[i], &err);
237 if (err != NULL) {
238 kprintf("[sdl] couldn't get symbol '%s' from '%s': %s\n", names[i], sofile, err);
239 HostLib_FreeErrorStr(err);
240 HostLib_Close(handle, NULL);
241 return NULL;
245 D(bug("[sdl] done\n"));
247 return handle;
250 static int sdl_hostlib_init(LIBBASETYPEPTR LIBBASE)
252 STRPTR LibraryFile = SDL_SOFILE;
253 APTR BootLoaderBase;
254 STRPTR BootLoaderName;
256 D(bug("[sdl] hostlib init\n"));
258 if ((HostLibBase = OpenResource("hostlib.resource")) == NULL) {
259 kprintf("[sdl] couldn't open hostlib.resource\n");
260 return FALSE;
263 BootLoaderBase = OpenResource("bootloader.resource");
264 if (BootLoaderBase) {
265 BootLoaderName = GetBootInfo(BL_LoaderName);
266 if (BootLoaderName) {
267 D(bug("[sdl] Host operating system: %s\n", BootLoaderName));
268 if (!strncasecmp(BootLoaderName, "Windows", 7))
269 LibraryFile = SDL_DLLFILE;
273 if ((LIBBASE->sdl_handle = sdl_hostlib_load_so(LibraryFile, sdl_func_names, (void **) &sdl_funcs)) == NULL)
274 return FALSE;
276 return TRUE;
279 static int sdl_hostlib_expunge(LIBBASETYPEPTR LIBBASE) {
280 D(bug("[sdl] hostlib expunge\n"));
282 if (LIBBASE->sdl_handle != NULL)
283 HostLib_Close(LIBBASE->sdl_handle, NULL);
285 return TRUE;
288 ADD2INITLIB(sdl_hostlib_init, 0)
289 ADD2EXPUNGELIB(sdl_hostlib_expunge, 0)