Added a test for MUIA_Listview_SelectChange.
[AROS.git] / arch / all-hosted / hidd / sdl / sdl_hostlib.c
blob5d77b06518ebb0e8ced2cca38aa1e9c6034bc5d4
1 /*
2 * sdl.hidd - SDL graphics/sound/keyboard for AROS hosted
3 * Copyright (c) 2007 Robert Norris. All rights reserved.
4 * Copyright (c) 2007-2011 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/kernel.h>
11 #include <aros/symbolsets.h>
12 #include <exec/semaphores.h>
14 #include <proto/bootloader.h>
15 #include <proto/exec.h>
16 #include <proto/hostlib.h>
17 #include <proto/kernel.h>
19 #include "sdl_intern.h"
21 #define DEBUG 0
22 #include <aros/debug.h>
24 struct sdl_funcs sdl_funcs;
26 static const char *sdl_func_names[] = {
27 "SDL_GetError",
28 "SDL_VideoDriverName",
29 "SDL_GetVideoSurface",
30 "SDL_GetVideoInfo",
31 "SDL_ListModes",
32 "SDL_SetVideoMode",
33 "SDL_UpdateRect",
34 "SDL_SetColors",
35 "SDL_CreateRGBSurface",
36 "SDL_CreateRGBSurfaceFrom",
37 "SDL_FreeSurface",
38 "SDL_LockSurface",
39 "SDL_UnlockSurface",
40 "SDL_UpperBlit",
41 "SDL_FillRect",
42 "SDL_WM_SetCaption",
43 "SDL_WM_SetIcon",
44 "SDL_ShowCursor",
45 "SDL_PumpEvents",
46 "SDL_PeepEvents",
47 "SDL_Linked_Version",
48 "SDL_Init",
49 "SDL_Quit",
50 NULL
53 APTR HostLibBase;
55 static void *sdl_hostlib_load_so(const char *sofile, const char **names, void **funcptr) {
56 void *handle;
57 char *err;
58 int i;
60 D(bug("[sdl] loading functions from %s\n", sofile));
62 if ((handle = HostLib_Open(sofile, &err)) == NULL) {
63 kprintf("[sdl] couldn't open '%s': %s\n", sofile, err);
64 return NULL;
67 for (i = 0; names[i]; i++) {
68 funcptr[i] = HostLib_GetPointer(handle, names[i], &err);
69 if (err != NULL) {
70 kprintf("[sdl] couldn't get symbol '%s' from '%s': %s\n", names[i], sofile, err);
71 HostLib_FreeErrorStr(err);
72 HostLib_Close(handle, NULL);
73 return NULL;
77 D(bug("[sdl] done\n"));
79 return handle;
82 int sdl_hostlib_init(LIBBASETYPEPTR LIBBASE)
84 STRPTR LibraryFile = SDL_SOFILE;
85 APTR KernelBase;
86 const char *arch;
88 D(bug("[sdl] hostlib init\n"));
90 if ((HostLibBase = OpenResource("hostlib.resource")) == NULL) {
91 kprintf("[sdl] couldn't open hostlib.resource\n");
92 return FALSE;
95 KernelBase = OpenResource("kernel.resource");
96 if (!KernelBase)
97 return FALSE;
99 arch = (const char *)KrnGetSystemAttr(KATTR_Architecture);
100 D(bug("[sdl] Host operating system: %s\n", arch));
102 if (!strcmp(arch, "mingw32-i386"))
103 LibraryFile = SDL_DLLFILE;
104 else if (!strncmp(arch, "darwin", 6))
105 LibraryFile = SDL_DYLIBFILE;
107 if ((LIBBASE->sdl_handle = sdl_hostlib_load_so(LibraryFile, sdl_func_names, (void **) &sdl_funcs)) == NULL)
108 return FALSE;
110 return TRUE;
113 int sdl_hostlib_expunge(LIBBASETYPEPTR LIBBASE) {
114 D(bug("[sdl] hostlib expunge\n"));
116 if (LIBBASE->sdl_handle != NULL)
117 HostLib_Close(LIBBASE->sdl_handle, NULL);
119 return TRUE;