1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
19 #if defined(PLATFORM_MSDOS)
30 /* ========================================================================= */
31 /* exported variables */
32 /* ========================================================================= */
34 struct ProgramInfo program;
35 struct OptionInfo options;
36 struct VideoSystemInfo video;
37 struct AudioSystemInfo audio;
39 struct ArtworkInfo artwork;
40 struct JoystickInfo joystick;
41 struct SetupInfo setup;
43 LevelDirTree *leveldir_first = NULL;
44 LevelDirTree *leveldir_current = NULL;
47 Display *display = NULL;
48 Visual *visual = NULL;
52 DrawWindow *window = NULL;
53 DrawBuffer *backbuffer = NULL;
54 DrawBuffer *drawto = NULL;
56 int button_status = MB_NOT_PRESSED;
57 boolean motion_status = FALSE;
59 int redraw_mask = REDRAW_NONE;
65 /* ========================================================================= */
66 /* init/close functions */
67 /* ========================================================================= */
69 void InitProgramInfo(char *argv0,
70 char *userdata_directory, char *program_title,
71 char *window_title, char *icon_title,
72 char *x11_icon_filename, char *x11_iconmask_filename,
73 char *msdos_pointer_filename,
74 char *cookie_prefix, char *filename_prefix,
77 program.command_basename =
78 (strrchr(argv0, '/') ? strrchr(argv0, '/') + 1 : argv0);
80 program.userdata_directory = userdata_directory;
81 program.program_title = program_title;
82 program.window_title = window_title;
83 program.icon_title = icon_title;
84 program.x11_icon_filename = x11_icon_filename;
85 program.x11_iconmask_filename = x11_iconmask_filename;
86 program.msdos_pointer_filename = msdos_pointer_filename;
88 program.cookie_prefix = cookie_prefix;
89 program.filename_prefix = filename_prefix;
91 program.version_major = VERSION_MAJOR(program_version);
92 program.version_minor = VERSION_MINOR(program_version);
93 program.version_patch = VERSION_PATCH(program_version);
96 void InitExitFunction(void (*exit_function)(int))
98 program.exit_function = exit_function;
100 /* set signal handlers to custom exit function */
101 signal(SIGINT, exit_function);
102 signal(SIGTERM, exit_function);
104 #if defined(TARGET_SDL)
105 /* set exit function to automatically cleanup SDL stuff after exit() */
110 void InitPlatformDependantStuff(void)
112 #if defined(PLATFORM_MSDOS)
117 #if defined(TARGET_SDL)
118 if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0)
119 Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
123 void ClosePlatformDependantStuff(void)
125 #if defined(PLATFORM_MSDOS)
130 void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
131 int real_sx, int real_sy,
132 int full_sxsize, int full_sysize)
138 gfx.real_sx = real_sx;
139 gfx.real_sy = real_sy;
140 gfx.full_sxsize = full_sxsize;
141 gfx.full_sysize = full_sysize;
143 gfx.background_bitmap = NULL;
144 gfx.background_bitmap_mask = REDRAW_NONE;
146 SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */
147 SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */
150 void InitGfxDoor1Info(int dx, int dy, int dxsize, int dysize)
158 void InitGfxDoor2Info(int vx, int vy, int vxsize, int vysize)
166 void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height)
168 /* currently only used by MSDOS code to alloc VRAM buffer, if available */
169 gfx.scrollbuffer_width = scrollbuffer_width;
170 gfx.scrollbuffer_height = scrollbuffer_height;
173 void SetDrawDeactivationMask(int draw_deactivation_mask)
175 gfx.draw_deactivation_mask = draw_deactivation_mask;
178 void SetDrawBackgroundMask(int draw_background_mask)
180 gfx.draw_background_mask = draw_background_mask;
183 static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile,
184 int dest_x, int dest_y, int width, int height)
186 int bitmap_xsize = width;
187 int bitmap_ysize = height;
188 int tile_xsize = tile->width;
189 int tile_ysize = tile->height;
190 int tile_xsteps = (bitmap_xsize + tile_xsize - 1) / tile_xsize;
191 int tile_ysteps = (bitmap_ysize + tile_ysize - 1) / tile_ysize;
194 for (y=0; y < tile_ysteps; y++)
196 for (x=0; x < tile_xsteps; x++)
198 int draw_x = dest_x + x * tile_xsize;
199 int draw_y = dest_y + y * tile_ysize;
200 int draw_xsize = MIN(tile_xsize, bitmap_xsize - x * tile_xsize);
201 int draw_ysize = MIN(tile_ysize, bitmap_ysize - y * tile_ysize);
203 BlitBitmap(tile, bitmap, 0, 0, draw_xsize, draw_ysize, draw_x, draw_y);
208 void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask)
210 static Bitmap *main_bitmap_tile = NULL;
211 static Bitmap *door_bitmap_tile = NULL;
213 if (mask == REDRAW_FIELD)
215 if (background_bitmap_tile == main_bitmap_tile)
216 return; /* main background tile has not changed */
218 main_bitmap_tile = background_bitmap_tile;
220 else if (mask == REDRAW_DOOR_1)
222 if (background_bitmap_tile == door_bitmap_tile)
223 return; /* main background tile has not changed */
225 door_bitmap_tile = background_bitmap_tile;
227 else /* should not happen */
230 if (background_bitmap_tile)
231 gfx.background_bitmap_mask |= mask;
233 gfx.background_bitmap_mask &= ~mask;
235 if (gfx.background_bitmap == NULL)
236 gfx.background_bitmap = CreateBitmap(video.width, video.height,
239 if (background_bitmap_tile == NULL) /* empty background requested */
242 if (mask == REDRAW_FIELD)
243 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
244 gfx.real_sx, gfx.real_sy,
245 gfx.full_sxsize, gfx.full_sysize);
247 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
249 gfx.dxsize, gfx.dysize);
252 void SetMainBackgroundBitmap(Bitmap *background_bitmap_tile)
254 SetBackgroundBitmap(background_bitmap_tile, REDRAW_FIELD);
257 void SetDoorBackgroundBitmap(Bitmap *background_bitmap_tile)
259 SetBackgroundBitmap(background_bitmap_tile, REDRAW_DOOR_1);
263 /* ========================================================================= */
264 /* video functions */
265 /* ========================================================================= */
267 inline static int GetRealDepth(int depth)
269 return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
272 inline void InitVideoDisplay(void)
274 #if defined(TARGET_SDL)
275 SDLInitVideoDisplay();
277 X11InitVideoDisplay();
281 inline void CloseVideoDisplay(void)
283 KeyboardAutoRepeatOn();
285 #if defined(TARGET_SDL)
286 SDL_QuitSubSystem(SDL_INIT_VIDEO);
290 XCloseDisplay(display);
294 inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
295 int width, int height, int depth,
299 video.height = height;
300 video.depth = GetRealDepth(depth);
301 video.fullscreen_available = FULLSCREEN_STATUS;
302 video.fullscreen_enabled = FALSE;
305 SDLInitVideoBuffer(backbuffer, window, fullscreen);
307 X11InitVideoBuffer(backbuffer, window);
311 inline Bitmap *CreateBitmapStruct(void)
314 return checked_calloc(sizeof(struct SDLSurfaceInfo));
316 return checked_calloc(sizeof(struct X11DrawableInfo));
320 inline Bitmap *CreateBitmap(int width, int height, int depth)
322 Bitmap *new_bitmap = CreateBitmapStruct();
323 int real_depth = GetRealDepth(depth);
326 SDL_Surface *surface_tmp, *surface_native;
328 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
329 real_depth, 0, 0, 0, 0))
331 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
333 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
334 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
336 SDL_FreeSurface(surface_tmp);
338 new_bitmap->surface = surface_native;
342 if ((pixmap = XCreatePixmap(display, window->drawable,
343 width, height, real_depth))
345 Error(ERR_EXIT, "cannot create pixmap");
347 new_bitmap->drawable = pixmap;
350 Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first");
352 new_bitmap->gc = window->gc;
354 new_bitmap->line_gc[0] = window->line_gc[0];
355 new_bitmap->line_gc[1] = window->line_gc[1];
358 new_bitmap->width = width;
359 new_bitmap->height = height;
364 inline static void FreeBitmapPointers(Bitmap *bitmap)
371 SDL_FreeSurface(bitmap->surface);
372 if (bitmap->surface_masked)
373 SDL_FreeSurface(bitmap->surface_masked);
374 bitmap->surface = NULL;
375 bitmap->surface_masked = NULL;
377 /* The X11 version seems to have a memory leak here -- although
378 "XFreePixmap()" is called, the corresponding memory seems not
379 to be freed (according to "ps"). The SDL version apparently
380 does not have this problem. */
382 if (bitmap->drawable)
383 XFreePixmap(display, bitmap->drawable);
384 if (bitmap->clip_mask)
385 XFreePixmap(display, bitmap->clip_mask);
386 if (bitmap->stored_clip_gc)
387 XFreeGC(display, bitmap->stored_clip_gc);
388 /* the other GCs are only pointers to GCs used elsewhere */
389 bitmap->drawable = None;
390 bitmap->clip_mask = None;
391 bitmap->stored_clip_gc = None;
394 if (bitmap->source_filename)
395 free(bitmap->source_filename);
396 bitmap->source_filename = NULL;
399 inline static void TransferBitmapPointers(Bitmap *src_bitmap,
402 if (src_bitmap == NULL || dst_bitmap == NULL)
405 FreeBitmapPointers(dst_bitmap);
407 *dst_bitmap = *src_bitmap;
410 inline void FreeBitmap(Bitmap *bitmap)
415 FreeBitmapPointers(bitmap);
420 inline void CloseWindow(DrawWindow *window)
423 if (window->drawable)
425 XUnmapWindow(display, window->drawable);
426 XDestroyWindow(display, window->drawable);
429 XFreeGC(display, window->gc);
433 static inline boolean CheckDrawingArea(int x, int y, int width, int height,
436 if (draw_mask == REDRAW_NONE)
439 if (draw_mask & REDRAW_ALL)
442 if ((draw_mask & REDRAW_FIELD) && x < gfx.real_sx + gfx.full_sxsize)
445 if ((draw_mask & REDRAW_DOOR_1) && x >= gfx.dx && y < gfx.dy + gfx.dysize)
448 if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy)
454 inline boolean DrawingDeactivated(int x, int y, int width, int height)
456 return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
459 inline boolean DrawingOnBackground(int x, int y)
461 return ((gfx.draw_background_mask & gfx.background_bitmap_mask) &&
462 CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
465 inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
466 int src_x, int src_y,
467 int width, int height,
468 int dst_x, int dst_y)
470 if (DrawingDeactivated(dst_x, dst_y, width, height))
474 SDLCopyArea(src_bitmap, dst_bitmap,
475 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_OPAQUE);
477 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
478 dst_bitmap->gc, src_x, src_y, width, height, dst_x, dst_y);
482 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
484 if (DrawingDeactivated(x, y, width, height))
488 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
490 XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height);
494 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
495 int width, int height)
497 if (DrawingOnBackground(x, y))
498 BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
500 ClearRectangle(bitmap, x, y, width, height);
505 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
509 inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap)
514 bitmap->clip_gc = clip_gc;
515 XSetClipMask(display, bitmap->clip_gc, clip_pixmap);
518 last_clip_gc = clip_gc;
523 inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y)
528 bitmap->clip_gc = clip_gc;
529 XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y);
532 last_clip_gc = clip_gc;
537 inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
538 int src_x, int src_y,
539 int width, int height,
540 int dst_x, int dst_y)
542 if (DrawingDeactivated(dst_x, dst_y, width, height))
546 SDLCopyArea(src_bitmap, dst_bitmap,
547 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_MASKED);
549 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
550 src_bitmap->clip_gc, src_x, src_y, width, height, dst_x, dst_y);
554 inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
555 int src_x, int src_y,
556 int width, int height,
557 int dst_x, int dst_y)
559 if (DrawingOnBackground(dst_x, dst_y))
561 /* draw background */
562 BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
565 /* draw foreground */
566 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
567 dst_x - src_x, dst_y - src_y);
568 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
572 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
576 inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
580 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
582 XSetForeground(display, bitmap->gc, WhitePixel(display, screen));
583 XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y);
584 XSetForeground(display, bitmap->gc, BlackPixel(display, screen));
588 #if !defined(TARGET_X11_NATIVE)
589 inline void DrawLine(Bitmap *bitmap, int from_x, int from_y,
590 int to_x, int to_y, Pixel pixel, int line_width)
594 for (x=0; x<line_width; x++)
596 for (y=0; y<line_width; y++)
598 int dx = x - line_width / 2;
599 int dy = y - line_width / 2;
601 if ((x == 0 && y == 0) ||
602 (x == 0 && y == line_width - 1) ||
603 (x == line_width - 1 && y == 0) ||
604 (x == line_width - 1 && y == line_width - 1))
607 #if defined(TARGET_SDL)
609 from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
610 #elif defined(TARGET_ALLEGRO)
611 AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy,
612 to_x + dx, to_y + dy, pixel);
619 inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points,
622 #if !defined(TARGET_X11_NATIVE)
626 for (i=0; i<num_points - 1; i++)
627 DrawLine(bitmap, points[i].x, points[i].y,
628 points[i + 1].x, points[i + 1].y, pixel, line_width);
631 SDLDrawLines(bitmap->surface, points, num_points, pixel);
634 XSetForeground(display, bitmap->line_gc[1], pixel);
635 XDrawLines(display, bitmap->drawable, bitmap->line_gc[1],
636 (XPoint *)points, num_points, CoordModeOrigin);
638 XSetForeground(display, gc, BlackPixel(display, screen));
643 inline Pixel GetPixel(Bitmap *bitmap, int x, int y)
645 #if defined(TARGET_SDL)
646 return SDLGetPixel(bitmap, x, y);
647 #elif defined(TARGET_ALLEGRO)
648 return AllegroGetPixel(bitmap->drawable, x, y);
650 unsigned long pixel_value;
653 pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1,
655 pixel_value = XGetPixel(pixel_image, 0, 0);
657 XDestroyImage(pixel_image);
663 inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
664 unsigned int color_g, unsigned int color_b)
668 #if defined(TARGET_SDL)
669 pixel = SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
670 #elif defined(TARGET_ALLEGRO)
671 pixel = AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8);
672 #elif defined(TARGET_X11_NATIVE)
675 xcolor.flags = DoRed | DoGreen | DoBlue;
676 xcolor.red = (color_r << 8);
677 xcolor.green = (color_g << 8);
678 xcolor.blue = (color_b << 8);
679 XAllocColor(display, cmap, &xcolor);
680 pixel = xcolor.pixel;
686 inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
688 unsigned int color_r = (color >> 16) & 0xff;
689 unsigned int color_g = (color >> 8) & 0xff;
690 unsigned int color_b = (color >> 0) & 0xff;
692 return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
695 /* execute all pending screen drawing operations */
696 inline void FlushDisplay(void)
703 /* execute and wait for all pending screen drawing operations */
704 inline void SyncDisplay(void)
707 XSync(display, FALSE);
711 inline void KeyboardAutoRepeatOn(void)
714 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
715 SDL_DEFAULT_REPEAT_INTERVAL / 2);
716 SDL_EnableUNICODE(1);
719 XAutoRepeatOn(display);
723 inline void KeyboardAutoRepeatOff(void)
726 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
727 SDL_EnableUNICODE(0);
730 XAutoRepeatOff(display);
734 inline boolean PointerInWindow(DrawWindow *window)
744 /* if XQueryPointer() returns False, the pointer
745 is not on the same screen as the specified window */
746 return XQueryPointer(display, window->drawable, &root, &child,
747 &root_x, &root_y, &win_x, &win_y, &mask);
751 inline boolean SetVideoMode(boolean fullscreen)
754 return SDLSetVideoMode(&backbuffer, fullscreen);
756 boolean success = TRUE;
758 if (fullscreen && video.fullscreen_available)
760 Error(ERR_WARN, "fullscreen not available in X11 version");
762 /* display error message only once */
763 video.fullscreen_available = FALSE;
772 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
775 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
776 (!fullscreen && video.fullscreen_enabled))
777 fullscreen = SetVideoMode(fullscreen);
783 Bitmap *LoadImage(char *filename)
787 #if defined(TARGET_SDL)
788 new_bitmap = SDLLoadImage(filename);
790 new_bitmap = X11LoadImage(filename);
794 new_bitmap->source_filename = getStringCopy(filename);
799 Bitmap *LoadCustomImage(char *basename)
801 char *filename = getCustomImageFilename(basename);
804 if (filename == NULL)
805 Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
807 if ((new_bitmap = LoadImage(filename)) == NULL)
808 Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
813 void ReloadCustomImage(Bitmap *bitmap, char *basename)
815 char *filename = getCustomImageFilename(basename);
818 if (filename == NULL) /* (should never happen) */
820 Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
824 if (strcmp(filename, bitmap->source_filename) == 0)
826 /* The old and new image are the same (have the same filename and path).
827 This usually means that this image does not exist in this graphic set
828 and a fallback to the existing image is done. */
833 if ((new_bitmap = LoadImage(filename)) == NULL)
835 Error(ERR_WARN, "LoadImage() failed: %s", GetError());
839 if (bitmap->width != new_bitmap->width ||
840 bitmap->height != new_bitmap->height)
842 Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions",
844 FreeBitmap(new_bitmap);
848 TransferBitmapPointers(new_bitmap, bitmap);
852 Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
854 Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH);
856 #if defined(TARGET_SDL)
857 SDLZoomBitmap(src_bitmap, dst_bitmap);
859 X11ZoomBitmap(src_bitmap, dst_bitmap);
865 void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap)
867 Bitmap *tmp_bitmap, *tmp_bitmap_2, *tmp_bitmap_8;
868 int src_width, src_height;
869 int tmp_width, tmp_height;
871 src_width = src_bitmap->width;
872 src_height = src_bitmap->height;
874 tmp_width = src_width;
875 tmp_height = src_height + src_height / 2;
877 tmp_bitmap = CreateBitmap(tmp_width, tmp_height, DEFAULT_DEPTH);
879 tmp_bitmap_2 = ZoomBitmap(src_bitmap, src_width / 2, src_height / 2);
880 tmp_bitmap_8 = ZoomBitmap(src_bitmap, src_width / 8, src_height / 8);
882 BlitBitmap(src_bitmap, tmp_bitmap, 0, 0, src_width, src_height, 0, 0);
883 BlitBitmap(tmp_bitmap_2, tmp_bitmap, 0, 0, src_width / 2, src_height / 2,
885 BlitBitmap(tmp_bitmap_8, tmp_bitmap, 0, 0, src_width / 8, src_height / 8,
886 3 * src_width / 4, src_height);
888 FreeBitmap(tmp_bitmap_2);
889 FreeBitmap(tmp_bitmap_8);
892 src_bitmap->surface = tmp_bitmap->surface;
893 tmp_bitmap->surface = NULL;
895 src_bitmap->drawable = tmp_bitmap->drawable;
896 tmp_bitmap->drawable = None;
899 src_bitmap->height = tmp_bitmap->height;
901 FreeBitmap(tmp_bitmap);
905 /* ========================================================================= */
906 /* audio functions */
907 /* ========================================================================= */
909 inline void OpenAudio(void)
911 /* always start with reliable default values */
912 audio.sound_available = FALSE;
913 audio.music_available = FALSE;
914 audio.loops_available = FALSE;
916 audio.sound_enabled = FALSE;
917 audio.sound_deactivated = FALSE;
919 audio.mixer_pipe[0] = audio.mixer_pipe[1] = 0;
921 audio.device_name = NULL;
922 audio.device_fd = -1;
924 audio.num_channels = 0;
925 audio.music_channel = 0;
926 audio.first_sound_channel = 0;
928 #if defined(TARGET_SDL)
930 #elif defined(PLATFORM_UNIX)
932 #elif defined(PLATFORM_MSDOS)
937 inline void CloseAudio(void)
939 #if defined(TARGET_SDL)
941 #elif defined(PLATFORM_UNIX)
943 #elif defined(PLATFORM_MSDOS)
947 audio.sound_enabled = FALSE;
950 inline void SetAudioMode(boolean enabled)
952 if (!audio.sound_available)
955 audio.sound_enabled = enabled;
959 /* ========================================================================= */
960 /* event functions */
961 /* ========================================================================= */
963 inline void InitEventFilter(EventFilter filter_function)
966 /* set event filter to filter out certain events */
967 SDL_SetEventFilter(filter_function);
971 inline boolean PendingEvent(void)
974 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
976 return (XPending(display) ? TRUE : FALSE);
980 inline void NextEvent(Event *event)
985 XNextEvent(display, event);
989 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
993 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
994 (int)event->keysym.unicode,
995 (int)event->keysym.sym,
996 (int)SDL_GetModState());
999 if (with_modifiers &&
1000 event->keysym.unicode > 0x0000 &&
1001 event->keysym.unicode < 0x2000)
1002 return event->keysym.unicode;
1004 return event->keysym.sym;
1007 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
1008 (int)XLookupKeysym(event, event->state),
1009 (int)XLookupKeysym(event, 0));
1013 return XLookupKeysym(event, event->state);
1015 return XLookupKeysym(event, 0);
1019 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
1021 if (event->type != EVENT_CLIENTMESSAGE)
1024 #if defined(TARGET_SDL)
1025 return TRUE; /* the only possible message here is SDL_QUIT */
1026 #elif defined(PLATFORM_UNIX)
1027 if ((event->window == window->drawable) &&
1028 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
1036 /* ========================================================================= */
1037 /* joystick functions */
1038 /* ========================================================================= */
1040 inline void InitJoysticks()
1045 return; /* joysticks generally deactivated by compile-time directive */
1048 /* always start with reliable default values */
1049 joystick.status = JOYSTICK_NOT_AVAILABLE;
1050 for (i=0; i<MAX_PLAYERS; i++)
1051 joystick.fd[i] = -1; /* joystick device closed */
1053 #if defined(TARGET_SDL)
1055 #elif defined(PLATFORM_UNIX)
1056 UnixInitJoysticks();
1057 #elif defined(PLATFORM_MSDOS)
1058 MSDOSInitJoysticks();
1062 inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
1064 #if defined(TARGET_SDL)
1065 return SDLReadJoystick(nr, x, y, b1, b2);
1066 #elif defined(PLATFORM_UNIX)
1067 return UnixReadJoystick(nr, x, y, b1, b2);
1068 #elif defined(PLATFORM_MSDOS)
1069 return MSDOSReadJoystick(nr, x, y, b1, b2);