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,
133 Bitmap *field_save_buffer)
139 gfx.real_sx = real_sx;
140 gfx.real_sy = real_sy;
141 gfx.full_sxsize = full_sxsize;
142 gfx.full_sysize = full_sysize;
144 gfx.field_save_buffer = field_save_buffer;
146 gfx.background_bitmap = NULL;
147 gfx.background_bitmap_mask = REDRAW_NONE;
149 SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */
150 SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */
153 void InitGfxDoor1Info(int dx, int dy, int dxsize, int dysize)
161 void InitGfxDoor2Info(int vx, int vy, int vxsize, int vysize)
169 void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height)
171 /* currently only used by MSDOS code to alloc VRAM buffer, if available */
172 gfx.scrollbuffer_width = scrollbuffer_width;
173 gfx.scrollbuffer_height = scrollbuffer_height;
176 void SetDrawDeactivationMask(int draw_deactivation_mask)
178 gfx.draw_deactivation_mask = draw_deactivation_mask;
181 void SetDrawBackgroundMask(int draw_background_mask)
183 gfx.draw_background_mask = draw_background_mask;
186 static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile,
187 int dest_x, int dest_y, int width, int height)
189 int bitmap_xsize = width;
190 int bitmap_ysize = height;
191 int tile_xsize = tile->width;
192 int tile_ysize = tile->height;
193 int tile_xsteps = (bitmap_xsize + tile_xsize - 1) / tile_xsize;
194 int tile_ysteps = (bitmap_ysize + tile_ysize - 1) / tile_ysize;
197 for (y=0; y < tile_ysteps; y++)
199 for (x=0; x < tile_xsteps; x++)
201 int draw_x = dest_x + x * tile_xsize;
202 int draw_y = dest_y + y * tile_ysize;
203 int draw_xsize = MIN(tile_xsize, bitmap_xsize - x * tile_xsize);
204 int draw_ysize = MIN(tile_ysize, bitmap_ysize - y * tile_ysize);
206 BlitBitmap(tile, bitmap, 0, 0, draw_xsize, draw_ysize, draw_x, draw_y);
211 void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask)
213 static Bitmap *main_bitmap_tile = NULL;
214 static Bitmap *door_bitmap_tile = NULL;
216 if (mask == REDRAW_FIELD)
218 if (background_bitmap_tile == main_bitmap_tile)
219 return; /* main background tile has not changed */
221 main_bitmap_tile = background_bitmap_tile;
223 else if (mask == REDRAW_DOOR_1)
225 if (background_bitmap_tile == door_bitmap_tile)
226 return; /* main background tile has not changed */
228 door_bitmap_tile = background_bitmap_tile;
230 else /* should not happen */
233 if (background_bitmap_tile)
234 gfx.background_bitmap_mask |= mask;
236 gfx.background_bitmap_mask &= ~mask;
238 if (gfx.background_bitmap == NULL)
239 gfx.background_bitmap = CreateBitmap(video.width, video.height,
242 if (background_bitmap_tile == NULL) /* empty background requested */
245 if (mask == REDRAW_FIELD)
246 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
247 gfx.real_sx, gfx.real_sy,
248 gfx.full_sxsize, gfx.full_sysize);
250 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
252 gfx.dxsize, gfx.dysize);
255 void SetMainBackgroundBitmap(Bitmap *background_bitmap_tile)
257 SetBackgroundBitmap(background_bitmap_tile, REDRAW_FIELD);
260 void SetDoorBackgroundBitmap(Bitmap *background_bitmap_tile)
262 SetBackgroundBitmap(background_bitmap_tile, REDRAW_DOOR_1);
266 /* ========================================================================= */
267 /* video functions */
268 /* ========================================================================= */
270 inline static int GetRealDepth(int depth)
272 return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
275 inline void InitVideoDisplay(void)
277 #if defined(TARGET_SDL)
278 SDLInitVideoDisplay();
280 X11InitVideoDisplay();
284 inline void CloseVideoDisplay(void)
286 KeyboardAutoRepeatOn();
288 #if defined(TARGET_SDL)
289 SDL_QuitSubSystem(SDL_INIT_VIDEO);
293 XCloseDisplay(display);
297 inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
298 int width, int height, int depth,
302 video.height = height;
303 video.depth = GetRealDepth(depth);
304 video.fullscreen_available = FULLSCREEN_STATUS;
305 video.fullscreen_enabled = FALSE;
308 SDLInitVideoBuffer(backbuffer, window, fullscreen);
310 X11InitVideoBuffer(backbuffer, window);
314 inline Bitmap *CreateBitmapStruct(void)
317 return checked_calloc(sizeof(struct SDLSurfaceInfo));
319 return checked_calloc(sizeof(struct X11DrawableInfo));
323 inline Bitmap *CreateBitmap(int width, int height, int depth)
325 Bitmap *new_bitmap = CreateBitmapStruct();
326 int real_depth = GetRealDepth(depth);
329 SDL_Surface *surface_tmp, *surface_native;
331 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
332 real_depth, 0, 0, 0, 0))
334 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
336 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
337 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
339 SDL_FreeSurface(surface_tmp);
341 new_bitmap->surface = surface_native;
345 if ((pixmap = XCreatePixmap(display, window->drawable,
346 width, height, real_depth))
348 Error(ERR_EXIT, "cannot create pixmap");
350 new_bitmap->drawable = pixmap;
353 Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first");
355 new_bitmap->gc = window->gc;
357 new_bitmap->line_gc[0] = window->line_gc[0];
358 new_bitmap->line_gc[1] = window->line_gc[1];
361 new_bitmap->width = width;
362 new_bitmap->height = height;
367 inline static void FreeBitmapPointers(Bitmap *bitmap)
374 SDL_FreeSurface(bitmap->surface);
375 if (bitmap->surface_masked)
376 SDL_FreeSurface(bitmap->surface_masked);
377 bitmap->surface = NULL;
378 bitmap->surface_masked = NULL;
380 /* The X11 version seems to have a memory leak here -- although
381 "XFreePixmap()" is called, the corresponding memory seems not
382 to be freed (according to "ps"). The SDL version apparently
383 does not have this problem. */
385 if (bitmap->drawable)
386 XFreePixmap(display, bitmap->drawable);
387 if (bitmap->clip_mask)
388 XFreePixmap(display, bitmap->clip_mask);
389 if (bitmap->stored_clip_gc)
390 XFreeGC(display, bitmap->stored_clip_gc);
391 /* the other GCs are only pointers to GCs used elsewhere */
392 bitmap->drawable = None;
393 bitmap->clip_mask = None;
394 bitmap->stored_clip_gc = None;
397 if (bitmap->source_filename)
398 free(bitmap->source_filename);
399 bitmap->source_filename = NULL;
402 inline static void TransferBitmapPointers(Bitmap *src_bitmap,
405 if (src_bitmap == NULL || dst_bitmap == NULL)
408 FreeBitmapPointers(dst_bitmap);
410 *dst_bitmap = *src_bitmap;
413 inline void FreeBitmap(Bitmap *bitmap)
418 FreeBitmapPointers(bitmap);
423 inline void CloseWindow(DrawWindow *window)
426 if (window->drawable)
428 XUnmapWindow(display, window->drawable);
429 XDestroyWindow(display, window->drawable);
432 XFreeGC(display, window->gc);
436 static inline boolean CheckDrawingArea(int x, int y, int width, int height,
439 if (draw_mask == REDRAW_NONE)
442 if (draw_mask & REDRAW_ALL)
445 if ((draw_mask & REDRAW_FIELD) && x < gfx.real_sx + gfx.full_sxsize)
448 if ((draw_mask & REDRAW_DOOR_1) && x >= gfx.dx && y < gfx.dy + gfx.dysize)
451 if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy)
457 inline boolean DrawingDeactivated(int x, int y, int width, int height)
459 return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
462 inline boolean DrawingOnBackground(int x, int y)
464 return ((gfx.draw_background_mask & gfx.background_bitmap_mask) &&
465 CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
468 inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
469 int src_x, int src_y,
470 int width, int height,
471 int dst_x, int dst_y)
473 if (DrawingDeactivated(dst_x, dst_y, width, height))
477 SDLCopyArea(src_bitmap, dst_bitmap,
478 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_OPAQUE);
480 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
481 dst_bitmap->gc, src_x, src_y, width, height, dst_x, dst_y);
485 inline void DrawRectangle(Bitmap *bitmap, int x, int y, int width, int height,
488 if (DrawingDeactivated(x, y, width, height))
492 SDLFillRectangle(bitmap, x, y, width, height, color);
494 XSetForeground(display, bitmap->gc, color);
495 XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height);
496 XSetForeground(display, bitmap->gc, BlackPixel(display, screen));
501 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
504 DrawRectangle(bitmap, x, y, width, height, 0x000000);
506 DrawRectangle(bitmap, x, y, width, height, 0x000000);
510 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
512 if (DrawingDeactivated(x, y, width, height))
516 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
518 XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height);
523 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
524 int width, int height)
526 if (DrawingOnBackground(x, y))
527 BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
529 ClearRectangle(bitmap, x, y, width, height);
534 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
538 inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap)
543 bitmap->clip_gc = clip_gc;
544 XSetClipMask(display, bitmap->clip_gc, clip_pixmap);
547 last_clip_gc = clip_gc;
552 inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y)
557 bitmap->clip_gc = clip_gc;
558 XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y);
561 last_clip_gc = clip_gc;
566 inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
567 int src_x, int src_y,
568 int width, int height,
569 int dst_x, int dst_y)
571 if (DrawingDeactivated(dst_x, dst_y, width, height))
575 SDLCopyArea(src_bitmap, dst_bitmap,
576 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_MASKED);
578 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
579 src_bitmap->clip_gc, src_x, src_y, width, height, dst_x, dst_y);
583 inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
584 int src_x, int src_y,
585 int width, int height,
586 int dst_x, int dst_y)
588 if (DrawingOnBackground(dst_x, dst_y))
590 /* draw background */
591 BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
594 /* draw foreground */
595 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
596 dst_x - src_x, dst_y - src_y);
597 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
601 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
605 inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
609 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
611 XSetForeground(display, bitmap->gc, WhitePixel(display, screen));
612 XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y);
613 XSetForeground(display, bitmap->gc, BlackPixel(display, screen));
617 #if !defined(TARGET_X11_NATIVE)
618 inline void DrawLine(Bitmap *bitmap, int from_x, int from_y,
619 int to_x, int to_y, Pixel pixel, int line_width)
623 for (x=0; x<line_width; x++)
625 for (y=0; y<line_width; y++)
627 int dx = x - line_width / 2;
628 int dy = y - line_width / 2;
630 if ((x == 0 && y == 0) ||
631 (x == 0 && y == line_width - 1) ||
632 (x == line_width - 1 && y == 0) ||
633 (x == line_width - 1 && y == line_width - 1))
636 #if defined(TARGET_SDL)
638 from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
639 #elif defined(TARGET_ALLEGRO)
640 AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy,
641 to_x + dx, to_y + dy, pixel);
648 inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points,
651 #if !defined(TARGET_X11_NATIVE)
655 for (i=0; i<num_points - 1; i++)
656 DrawLine(bitmap, points[i].x, points[i].y,
657 points[i + 1].x, points[i + 1].y, pixel, line_width);
660 SDLDrawLines(bitmap->surface, points, num_points, pixel);
663 XSetForeground(display, bitmap->line_gc[1], pixel);
664 XDrawLines(display, bitmap->drawable, bitmap->line_gc[1],
665 (XPoint *)points, num_points, CoordModeOrigin);
667 XSetForeground(display, gc, BlackPixel(display, screen));
672 inline Pixel GetPixel(Bitmap *bitmap, int x, int y)
674 #if defined(TARGET_SDL)
675 return SDLGetPixel(bitmap, x, y);
676 #elif defined(TARGET_ALLEGRO)
677 return AllegroGetPixel(bitmap->drawable, x, y);
679 unsigned long pixel_value;
682 pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1,
684 pixel_value = XGetPixel(pixel_image, 0, 0);
686 XDestroyImage(pixel_image);
692 inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
693 unsigned int color_g, unsigned int color_b)
697 #if defined(TARGET_SDL)
698 pixel = SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
699 #elif defined(TARGET_ALLEGRO)
700 pixel = AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8);
701 #elif defined(TARGET_X11_NATIVE)
704 xcolor.flags = DoRed | DoGreen | DoBlue;
705 xcolor.red = (color_r << 8);
706 xcolor.green = (color_g << 8);
707 xcolor.blue = (color_b << 8);
708 XAllocColor(display, cmap, &xcolor);
709 pixel = xcolor.pixel;
715 inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
717 unsigned int color_r = (color >> 16) & 0xff;
718 unsigned int color_g = (color >> 8) & 0xff;
719 unsigned int color_b = (color >> 0) & 0xff;
721 return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
724 /* execute all pending screen drawing operations */
725 inline void FlushDisplay(void)
732 /* execute and wait for all pending screen drawing operations */
733 inline void SyncDisplay(void)
736 XSync(display, FALSE);
740 inline void KeyboardAutoRepeatOn(void)
743 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
744 SDL_DEFAULT_REPEAT_INTERVAL / 2);
745 SDL_EnableUNICODE(1);
748 XAutoRepeatOn(display);
752 inline void KeyboardAutoRepeatOff(void)
755 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
756 SDL_EnableUNICODE(0);
759 XAutoRepeatOff(display);
763 inline boolean PointerInWindow(DrawWindow *window)
773 /* if XQueryPointer() returns False, the pointer
774 is not on the same screen as the specified window */
775 return XQueryPointer(display, window->drawable, &root, &child,
776 &root_x, &root_y, &win_x, &win_y, &mask);
780 inline boolean SetVideoMode(boolean fullscreen)
783 return SDLSetVideoMode(&backbuffer, fullscreen);
785 boolean success = TRUE;
787 if (fullscreen && video.fullscreen_available)
789 Error(ERR_WARN, "fullscreen not available in X11 version");
791 /* display error message only once */
792 video.fullscreen_available = FALSE;
801 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
804 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
805 (!fullscreen && video.fullscreen_enabled))
806 fullscreen = SetVideoMode(fullscreen);
812 Bitmap *LoadImage(char *filename)
816 #if defined(TARGET_SDL)
817 new_bitmap = SDLLoadImage(filename);
819 new_bitmap = X11LoadImage(filename);
823 new_bitmap->source_filename = getStringCopy(filename);
828 Bitmap *LoadCustomImage(char *basename)
830 char *filename = getCustomImageFilename(basename);
833 if (filename == NULL)
834 Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
836 if ((new_bitmap = LoadImage(filename)) == NULL)
837 Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
842 void ReloadCustomImage(Bitmap *bitmap, char *basename)
844 char *filename = getCustomImageFilename(basename);
847 if (filename == NULL) /* (should never happen) */
849 Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
853 if (strcmp(filename, bitmap->source_filename) == 0)
855 /* The old and new image are the same (have the same filename and path).
856 This usually means that this image does not exist in this graphic set
857 and a fallback to the existing image is done. */
862 if ((new_bitmap = LoadImage(filename)) == NULL)
864 Error(ERR_WARN, "LoadImage() failed: %s", GetError());
868 if (bitmap->width != new_bitmap->width ||
869 bitmap->height != new_bitmap->height)
871 Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions",
873 FreeBitmap(new_bitmap);
877 TransferBitmapPointers(new_bitmap, bitmap);
881 Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
883 Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH);
885 #if defined(TARGET_SDL)
886 SDLZoomBitmap(src_bitmap, dst_bitmap);
888 X11ZoomBitmap(src_bitmap, dst_bitmap);
894 void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap)
896 Bitmap *tmp_bitmap, *tmp_bitmap_2, *tmp_bitmap_8;
897 int src_width, src_height;
898 int tmp_width, tmp_height;
900 src_width = src_bitmap->width;
901 src_height = src_bitmap->height;
903 tmp_width = src_width;
904 tmp_height = src_height + src_height / 2;
906 tmp_bitmap = CreateBitmap(tmp_width, tmp_height, DEFAULT_DEPTH);
908 tmp_bitmap_2 = ZoomBitmap(src_bitmap, src_width / 2, src_height / 2);
909 tmp_bitmap_8 = ZoomBitmap(src_bitmap, src_width / 8, src_height / 8);
911 BlitBitmap(src_bitmap, tmp_bitmap, 0, 0, src_width, src_height, 0, 0);
912 BlitBitmap(tmp_bitmap_2, tmp_bitmap, 0, 0, src_width / 2, src_height / 2,
914 BlitBitmap(tmp_bitmap_8, tmp_bitmap, 0, 0, src_width / 8, src_height / 8,
915 3 * src_width / 4, src_height);
917 FreeBitmap(tmp_bitmap_2);
918 FreeBitmap(tmp_bitmap_8);
921 src_bitmap->surface = tmp_bitmap->surface;
922 tmp_bitmap->surface = NULL;
924 src_bitmap->drawable = tmp_bitmap->drawable;
925 tmp_bitmap->drawable = None;
928 src_bitmap->height = tmp_bitmap->height;
930 FreeBitmap(tmp_bitmap);
934 /* ========================================================================= */
935 /* audio functions */
936 /* ========================================================================= */
938 inline void OpenAudio(void)
940 /* always start with reliable default values */
941 audio.sound_available = FALSE;
942 audio.music_available = FALSE;
943 audio.loops_available = FALSE;
945 audio.sound_enabled = FALSE;
946 audio.sound_deactivated = FALSE;
948 audio.mixer_pipe[0] = audio.mixer_pipe[1] = 0;
950 audio.device_name = NULL;
951 audio.device_fd = -1;
953 audio.num_channels = 0;
954 audio.music_channel = 0;
955 audio.first_sound_channel = 0;
957 #if defined(TARGET_SDL)
959 #elif defined(PLATFORM_UNIX)
961 #elif defined(PLATFORM_MSDOS)
966 inline void CloseAudio(void)
968 #if defined(TARGET_SDL)
970 #elif defined(PLATFORM_UNIX)
972 #elif defined(PLATFORM_MSDOS)
976 audio.sound_enabled = FALSE;
979 inline void SetAudioMode(boolean enabled)
981 if (!audio.sound_available)
984 audio.sound_enabled = enabled;
988 /* ========================================================================= */
989 /* event functions */
990 /* ========================================================================= */
992 inline void InitEventFilter(EventFilter filter_function)
995 /* set event filter to filter out certain events */
996 SDL_SetEventFilter(filter_function);
1000 inline boolean PendingEvent(void)
1003 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
1005 return (XPending(display) ? TRUE : FALSE);
1009 inline void NextEvent(Event *event)
1012 SDLNextEvent(event);
1014 XNextEvent(display, event);
1018 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
1022 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
1023 (int)event->keysym.unicode,
1024 (int)event->keysym.sym,
1025 (int)SDL_GetModState());
1028 if (with_modifiers &&
1029 event->keysym.unicode > 0x0000 &&
1030 event->keysym.unicode < 0x2000)
1031 return event->keysym.unicode;
1033 return event->keysym.sym;
1036 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
1037 (int)XLookupKeysym(event, event->state),
1038 (int)XLookupKeysym(event, 0));
1042 return XLookupKeysym(event, event->state);
1044 return XLookupKeysym(event, 0);
1048 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
1050 if (event->type != EVENT_CLIENTMESSAGE)
1053 #if defined(TARGET_SDL)
1054 return TRUE; /* the only possible message here is SDL_QUIT */
1055 #elif defined(PLATFORM_UNIX)
1056 if ((event->window == window->drawable) &&
1057 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
1065 /* ========================================================================= */
1066 /* joystick functions */
1067 /* ========================================================================= */
1069 inline void InitJoysticks()
1074 return; /* joysticks generally deactivated by compile-time directive */
1077 /* always start with reliable default values */
1078 joystick.status = JOYSTICK_NOT_AVAILABLE;
1079 for (i=0; i<MAX_PLAYERS; i++)
1080 joystick.fd[i] = -1; /* joystick device closed */
1082 #if defined(TARGET_SDL)
1084 #elif defined(PLATFORM_UNIX)
1085 UnixInitJoysticks();
1086 #elif defined(PLATFORM_MSDOS)
1087 MSDOSInitJoysticks();
1091 inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
1093 #if defined(TARGET_SDL)
1094 return SDLReadJoystick(nr, x, y, b1, b2);
1095 #elif defined(PLATFORM_UNIX)
1096 return UnixReadJoystick(nr, x, y, b1, b2);
1097 #elif defined(PLATFORM_MSDOS)
1098 return MSDOSReadJoystick(nr, x, y, b1, b2);