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;
40 struct ArtworkInfo artwork;
41 struct JoystickInfo joystick;
42 struct SetupInfo setup;
44 LevelDirTree *leveldir_first = NULL;
45 LevelDirTree *leveldir_current = NULL;
48 Display *display = NULL;
49 Visual *visual = NULL;
53 DrawWindow *window = NULL;
54 DrawBuffer *backbuffer = NULL;
55 DrawBuffer *drawto = NULL;
57 int button_status = MB_NOT_PRESSED;
58 boolean motion_status = FALSE;
60 int redraw_mask = REDRAW_NONE;
66 /* ========================================================================= */
67 /* init/close functions */
68 /* ========================================================================= */
70 void InitCommandName(char *argv0)
72 program.command_basename =
73 (strrchr(argv0, '/') ? strrchr(argv0, '/') + 1 : argv0);
76 void InitExitFunction(void (*exit_function)(int))
78 program.exit_function = exit_function;
80 /* set signal handlers to custom exit function */
81 signal(SIGINT, exit_function);
82 signal(SIGTERM, exit_function);
84 #if defined(TARGET_SDL)
85 /* set exit function to automatically cleanup SDL stuff after exit() */
90 void InitPlatformDependantStuff(void)
92 #if defined(PLATFORM_MSDOS)
96 #if !defined(PLATFORM_UNIX)
97 program.userdata_directory = "userdata";
100 #if defined(PLATFORM_MSDOS)
104 #if defined(TARGET_SDL)
105 if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0)
106 Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
110 void ClosePlatformDependantStuff(void)
112 #if defined(PLATFORM_MSDOS)
117 void InitProgramInfo(char *unix_userdata_directory, char *program_title,
118 char *window_title, char *icon_title,
119 char *x11_icon_filename, char *x11_iconmask_filename,
120 char *msdos_pointer_filename,
121 char *cookie_prefix, char *filename_prefix,
124 #if defined(PLATFORM_UNIX)
125 program.userdata_directory = unix_userdata_directory;
127 program.userdata_directory = "userdata";
130 program.program_title = program_title;
131 program.window_title = window_title;
132 program.icon_title = icon_title;
133 program.x11_icon_filename = x11_icon_filename;
134 program.x11_iconmask_filename = x11_iconmask_filename;
135 program.msdos_pointer_filename = msdos_pointer_filename;
137 program.cookie_prefix = cookie_prefix;
138 program.filename_prefix = filename_prefix;
140 program.version_major = VERSION_MAJOR(program_version);
141 program.version_minor = VERSION_MINOR(program_version);
142 program.version_patch = VERSION_PATCH(program_version);
145 void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
146 int real_sx, int real_sy,
147 int full_sxsize, int full_sysize)
153 gfx.real_sx = real_sx;
154 gfx.real_sy = real_sy;
155 gfx.full_sxsize = full_sxsize;
156 gfx.full_sysize = full_sysize;
158 gfx.background_bitmap = NULL;
159 gfx.background_bitmap_mask = REDRAW_NONE;
161 SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */
162 SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */
165 void InitGfxDoor1Info(int dx, int dy, int dxsize, int dysize)
173 void InitGfxDoor2Info(int vx, int vy, int vxsize, int vysize)
181 void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height)
183 /* currently only used by MSDOS code to alloc VRAM buffer, if available */
184 gfx.scrollbuffer_width = scrollbuffer_width;
185 gfx.scrollbuffer_height = scrollbuffer_height;
188 void SetDrawDeactivationMask(int draw_deactivation_mask)
190 gfx.draw_deactivation_mask = draw_deactivation_mask;
193 void SetDrawBackgroundMask(int draw_background_mask)
195 gfx.draw_background_mask = draw_background_mask;
198 static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile,
199 int dest_x, int dest_y, int width, int height)
201 int bitmap_xsize = width;
202 int bitmap_ysize = height;
203 int tile_xsize = tile->width;
204 int tile_ysize = tile->height;
205 int tile_xsteps = (bitmap_xsize + tile_xsize - 1) / tile_xsize;
206 int tile_ysteps = (bitmap_ysize + tile_ysize - 1) / tile_ysize;
209 for (y=0; y < tile_ysteps; y++)
211 for (x=0; x < tile_xsteps; x++)
213 int draw_x = dest_x + x * tile_xsize;
214 int draw_y = dest_y + y * tile_ysize;
215 int draw_xsize = MIN(tile_xsize, bitmap_xsize - x * tile_xsize);
216 int draw_ysize = MIN(tile_ysize, bitmap_ysize - y * tile_ysize);
218 BlitBitmap(tile, bitmap, 0, 0, draw_xsize, draw_ysize, draw_x, draw_y);
223 void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask)
225 static Bitmap *main_bitmap_tile = NULL;
226 static Bitmap *door_bitmap_tile = NULL;
228 if (mask == REDRAW_FIELD)
230 if (background_bitmap_tile == main_bitmap_tile)
231 return; /* main background tile has not changed */
233 main_bitmap_tile = background_bitmap_tile;
235 else if (mask == REDRAW_DOOR_1)
237 if (background_bitmap_tile == door_bitmap_tile)
238 return; /* main background tile has not changed */
240 door_bitmap_tile = background_bitmap_tile;
242 else /* should not happen */
245 if (background_bitmap_tile)
246 gfx.background_bitmap_mask |= mask;
248 gfx.background_bitmap_mask &= ~mask;
250 if (gfx.background_bitmap == NULL)
251 gfx.background_bitmap = CreateBitmap(video.width, video.height,
254 if (background_bitmap_tile == NULL) /* empty background requested */
257 if (mask == REDRAW_FIELD)
258 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
259 gfx.real_sx, gfx.real_sy,
260 gfx.full_sxsize, gfx.full_sysize);
262 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
264 gfx.dxsize, gfx.dysize);
267 void SetMainBackgroundBitmap(Bitmap *background_bitmap_tile)
269 SetBackgroundBitmap(background_bitmap_tile, REDRAW_FIELD);
272 void SetDoorBackgroundBitmap(Bitmap *background_bitmap_tile)
274 SetBackgroundBitmap(background_bitmap_tile, REDRAW_DOOR_1);
278 /* ========================================================================= */
279 /* video functions */
280 /* ========================================================================= */
282 inline static int GetRealDepth(int depth)
284 return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
287 inline void InitVideoDisplay(void)
289 #if defined(TARGET_SDL)
290 SDLInitVideoDisplay();
292 X11InitVideoDisplay();
296 inline void CloseVideoDisplay(void)
298 KeyboardAutoRepeatOn();
300 #if defined(TARGET_SDL)
301 SDL_QuitSubSystem(SDL_INIT_VIDEO);
305 XCloseDisplay(display);
309 inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
310 int width, int height, int depth,
314 video.height = height;
315 video.depth = GetRealDepth(depth);
316 video.fullscreen_available = FULLSCREEN_STATUS;
317 video.fullscreen_enabled = FALSE;
320 SDLInitVideoBuffer(backbuffer, window, fullscreen);
322 X11InitVideoBuffer(backbuffer, window);
326 inline Bitmap *CreateBitmapStruct(void)
329 return checked_calloc(sizeof(struct SDLSurfaceInfo));
331 return checked_calloc(sizeof(struct X11DrawableInfo));
335 inline Bitmap *CreateBitmap(int width, int height, int depth)
337 Bitmap *new_bitmap = CreateBitmapStruct();
338 int real_depth = GetRealDepth(depth);
341 SDL_Surface *surface_tmp, *surface_native;
343 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
344 real_depth, 0, 0, 0, 0))
346 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
348 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
349 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
351 SDL_FreeSurface(surface_tmp);
353 new_bitmap->surface = surface_native;
357 if ((pixmap = XCreatePixmap(display, window->drawable,
358 width, height, real_depth))
360 Error(ERR_EXIT, "cannot create pixmap");
362 new_bitmap->drawable = pixmap;
365 Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first");
367 new_bitmap->gc = window->gc;
369 new_bitmap->line_gc[0] = window->line_gc[0];
370 new_bitmap->line_gc[1] = window->line_gc[1];
373 new_bitmap->width = width;
374 new_bitmap->height = height;
379 inline static void FreeBitmapPointers(Bitmap *bitmap)
386 SDL_FreeSurface(bitmap->surface);
387 if (bitmap->surface_masked)
388 SDL_FreeSurface(bitmap->surface_masked);
389 bitmap->surface = NULL;
390 bitmap->surface_masked = NULL;
392 /* The X11 version seems to have a memory leak here -- although
393 "XFreePixmap()" is called, the correspondig memory seems not
394 to be freed (according to "ps"). The SDL version apparently
395 does not have this problem. */
397 if (bitmap->drawable)
398 XFreePixmap(display, bitmap->drawable);
399 if (bitmap->clip_mask)
400 XFreePixmap(display, bitmap->clip_mask);
401 if (bitmap->stored_clip_gc)
402 XFreeGC(display, bitmap->stored_clip_gc);
403 /* the other GCs are only pointers to GCs used elsewhere */
404 bitmap->drawable = None;
405 bitmap->clip_mask = None;
406 bitmap->stored_clip_gc = None;
409 if (bitmap->source_filename)
410 free(bitmap->source_filename);
411 bitmap->source_filename = NULL;
414 inline static void TransferBitmapPointers(Bitmap *src_bitmap,
417 if (src_bitmap == NULL || dst_bitmap == NULL)
420 FreeBitmapPointers(dst_bitmap);
422 *dst_bitmap = *src_bitmap;
425 inline void FreeBitmap(Bitmap *bitmap)
430 FreeBitmapPointers(bitmap);
435 inline void CloseWindow(DrawWindow *window)
438 if (window->drawable)
440 XUnmapWindow(display, window->drawable);
441 XDestroyWindow(display, window->drawable);
444 XFreeGC(display, window->gc);
448 static inline boolean CheckDrawingArea(int x, int y, int width, int height,
451 if (draw_mask == REDRAW_NONE)
454 if (draw_mask & REDRAW_ALL)
457 if ((draw_mask & REDRAW_FIELD) && x < gfx.real_sx + gfx.full_sxsize)
460 if ((draw_mask & REDRAW_DOOR_1) && x >= gfx.dx && y < gfx.dy + gfx.dysize)
463 if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy)
469 inline boolean DrawingDeactivated(int x, int y, int width, int height)
471 return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
474 inline boolean DrawingOnBackground(int x, int y)
476 return ((gfx.draw_background_mask & gfx.background_bitmap_mask) &&
477 CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
480 inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
481 int src_x, int src_y,
482 int width, int height,
483 int dst_x, int dst_y)
485 if (DrawingDeactivated(dst_x, dst_y, width, height))
489 SDLCopyArea(src_bitmap, dst_bitmap,
490 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_OPAQUE);
492 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
493 dst_bitmap->gc, src_x, src_y, width, height, dst_x, dst_y);
497 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
499 if (DrawingDeactivated(x, y, width, height))
503 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
505 XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height);
509 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
510 int width, int height)
512 if (DrawingOnBackground(x, y))
513 BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
515 ClearRectangle(bitmap, x, y, width, height);
520 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
524 inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap)
529 bitmap->clip_gc = clip_gc;
530 XSetClipMask(display, bitmap->clip_gc, clip_pixmap);
533 last_clip_gc = clip_gc;
538 inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y)
543 bitmap->clip_gc = clip_gc;
544 XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y);
547 last_clip_gc = clip_gc;
552 inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
553 int src_x, int src_y,
554 int width, int height,
555 int dst_x, int dst_y)
557 if (DrawingDeactivated(dst_x, dst_y, width, height))
561 SDLCopyArea(src_bitmap, dst_bitmap,
562 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_MASKED);
564 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
565 src_bitmap->clip_gc, src_x, src_y, width, height, dst_x, dst_y);
569 inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
570 int src_x, int src_y,
571 int width, int height,
572 int dst_x, int dst_y)
574 if (DrawingOnBackground(src_x, src_y))
576 /* draw background */
577 BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
580 /* draw foreground */
581 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
582 dst_x - src_x, dst_y - src_y);
583 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
587 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
591 inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
595 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
597 XSetForeground(display, bitmap->gc, WhitePixel(display, screen));
598 XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y);
599 XSetForeground(display, bitmap->gc, BlackPixel(display, screen));
603 #if !defined(TARGET_X11_NATIVE)
604 inline void DrawLine(Bitmap *bitmap, int from_x, int from_y,
605 int to_x, int to_y, Pixel pixel, int line_width)
609 for (x=0; x<line_width; x++)
611 for (y=0; y<line_width; y++)
613 int dx = x - line_width / 2;
614 int dy = y - line_width / 2;
616 if ((x == 0 && y == 0) ||
617 (x == 0 && y == line_width - 1) ||
618 (x == line_width - 1 && y == 0) ||
619 (x == line_width - 1 && y == line_width - 1))
622 #if defined(TARGET_SDL)
624 from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
625 #elif defined(TARGET_ALLEGRO)
626 AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy,
627 to_x + dx, to_y + dy, pixel);
634 inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points,
637 #if !defined(TARGET_X11_NATIVE)
641 for (i=0; i<num_points - 1; i++)
642 DrawLine(bitmap, points[i].x, points[i].y,
643 points[i + 1].x, points[i + 1].y, pixel, line_width);
646 SDLDrawLines(bitmap->surface, points, num_points, pixel);
649 XSetForeground(display, bitmap->line_gc[1], pixel);
650 XDrawLines(display, bitmap->drawable, bitmap->line_gc[1],
651 (XPoint *)points, num_points, CoordModeOrigin);
653 XSetForeground(display, gc, BlackPixel(display, screen));
658 inline Pixel GetPixel(Bitmap *bitmap, int x, int y)
660 #if defined(TARGET_SDL)
661 return SDLGetPixel(bitmap, x, y);
662 #elif defined(TARGET_ALLEGRO)
663 return AllegroGetPixel(bitmap->drawable, x, y);
665 unsigned long pixel_value;
668 pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1,
670 pixel_value = XGetPixel(pixel_image, 0, 0);
672 XDestroyImage(pixel_image);
678 inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
679 unsigned int color_g, unsigned int color_b)
683 #if defined(TARGET_SDL)
684 pixel = SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
685 #elif defined(TARGET_ALLEGRO)
686 pixel = AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8);
687 #elif defined(TARGET_X11_NATIVE)
690 xcolor.flags = DoRed | DoGreen | DoBlue;
691 xcolor.red = (color_r << 8);
692 xcolor.green = (color_g << 8);
693 xcolor.blue = (color_b << 8);
694 XAllocColor(display, cmap, &xcolor);
695 pixel = xcolor.pixel;
701 inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
703 unsigned int color_r = (color >> 16) & 0xff;
704 unsigned int color_g = (color >> 8) & 0xff;
705 unsigned int color_b = (color >> 0) & 0xff;
707 return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
710 /* execute all pending screen drawing operations */
711 inline void FlushDisplay(void)
718 /* execute and wait for all pending screen drawing operations */
719 inline void SyncDisplay(void)
722 XSync(display, FALSE);
726 inline void KeyboardAutoRepeatOn(void)
729 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
730 SDL_DEFAULT_REPEAT_INTERVAL / 2);
731 SDL_EnableUNICODE(1);
734 XAutoRepeatOn(display);
738 inline void KeyboardAutoRepeatOff(void)
741 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
742 SDL_EnableUNICODE(0);
745 XAutoRepeatOff(display);
749 inline boolean PointerInWindow(DrawWindow *window)
759 /* if XQueryPointer() returns False, the pointer
760 is not on the same screen as the specified window */
761 return XQueryPointer(display, window->drawable, &root, &child,
762 &root_x, &root_y, &win_x, &win_y, &mask);
766 inline boolean SetVideoMode(boolean fullscreen)
769 return SDLSetVideoMode(&backbuffer, fullscreen);
771 boolean success = TRUE;
773 if (fullscreen && video.fullscreen_available)
775 Error(ERR_WARN, "fullscreen not available in X11 version");
777 /* display error message only once */
778 video.fullscreen_available = FALSE;
787 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
790 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
791 (!fullscreen && video.fullscreen_enabled))
792 fullscreen = SetVideoMode(fullscreen);
798 Bitmap *LoadImage(char *filename)
802 #if defined(TARGET_SDL)
803 new_bitmap = SDLLoadImage(filename);
805 new_bitmap = X11LoadImage(filename);
809 new_bitmap->source_filename = getStringCopy(filename);
814 Bitmap *LoadCustomImage(char *basename)
816 char *filename = getCustomImageFilename(basename);
819 if (filename == NULL)
820 Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
822 if ((new_bitmap = LoadImage(filename)) == NULL)
823 Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
828 void ReloadCustomImage(Bitmap *bitmap, char *basename)
830 char *filename = getCustomImageFilename(basename);
833 if (filename == NULL) /* (should never happen) */
835 Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
839 if (strcmp(filename, bitmap->source_filename) == 0)
841 /* The old and new image are the same (have the same filename and path).
842 This usually means that this image does not exist in this graphic set
843 and a fallback to the existing image is done. */
848 if ((new_bitmap = LoadImage(filename)) == NULL)
850 Error(ERR_WARN, "LoadImage() failed: %s", GetError());
854 if (bitmap->width != new_bitmap->width ||
855 bitmap->height != new_bitmap->height)
857 Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions",
859 FreeBitmap(new_bitmap);
863 TransferBitmapPointers(new_bitmap, bitmap);
868 /* ========================================================================= */
869 /* audio functions */
870 /* ========================================================================= */
872 inline void OpenAudio(void)
874 /* always start with reliable default values */
875 audio.sound_available = FALSE;
876 audio.music_available = FALSE;
877 audio.loops_available = FALSE;
879 audio.sound_enabled = FALSE;
880 audio.sound_deactivated = FALSE;
882 audio.mixer_pipe[0] = audio.mixer_pipe[1] = 0;
883 audio.mixer_pid = -1;
884 audio.device_name = NULL;
885 audio.device_fd = -1;
887 audio.num_channels = 0;
888 audio.music_channel = 0;
889 audio.first_sound_channel = 0;
891 #if defined(TARGET_SDL)
893 #elif defined(PLATFORM_UNIX)
895 #elif defined(PLATFORM_MSDOS)
900 inline void CloseAudio(void)
902 #if defined(TARGET_SDL)
904 #elif defined(PLATFORM_UNIX)
906 #elif defined(PLATFORM_MSDOS)
910 audio.sound_enabled = FALSE;
913 inline void SetAudioMode(boolean enabled)
915 if (!audio.sound_available)
918 audio.sound_enabled = enabled;
922 /* ========================================================================= */
923 /* event functions */
924 /* ========================================================================= */
926 inline void InitEventFilter(EventFilter filter_function)
929 /* set event filter to filter out certain events */
930 SDL_SetEventFilter(filter_function);
934 inline boolean PendingEvent(void)
937 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
939 return (XPending(display) ? TRUE : FALSE);
943 inline void NextEvent(Event *event)
948 XNextEvent(display, event);
952 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
956 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
957 (int)event->keysym.unicode,
958 (int)event->keysym.sym,
959 (int)SDL_GetModState());
962 if (with_modifiers &&
963 event->keysym.unicode > 0x0000 &&
964 event->keysym.unicode < 0x2000)
965 return event->keysym.unicode;
967 return event->keysym.sym;
970 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
971 (int)XLookupKeysym(event, event->state),
972 (int)XLookupKeysym(event, 0));
976 return XLookupKeysym(event, event->state);
978 return XLookupKeysym(event, 0);
982 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
984 if (event->type != EVENT_CLIENTMESSAGE)
987 #if defined(TARGET_SDL)
988 return TRUE; /* the only possible message here is SDL_QUIT */
989 #elif defined(PLATFORM_UNIX)
990 if ((event->window == window->drawable) &&
991 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
999 /* ========================================================================= */
1000 /* joystick functions */
1001 /* ========================================================================= */
1003 inline void InitJoysticks()
1008 return; /* joysticks generally deactivated by compile-time directive */
1011 /* always start with reliable default values */
1012 joystick.status = JOYSTICK_NOT_AVAILABLE;
1013 for (i=0; i<MAX_PLAYERS; i++)
1014 joystick.fd[i] = -1; /* joystick device closed */
1016 #if defined(TARGET_SDL)
1018 #elif defined(PLATFORM_UNIX)
1019 UnixInitJoysticks();
1020 #elif defined(PLATFORM_MSDOS)
1021 MSDOSInitJoysticks();
1025 inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
1027 #if defined(TARGET_SDL)
1028 return SDLReadJoystick(nr, x, y, b1, b2);
1029 #elif defined(PLATFORM_UNIX)
1030 return UnixReadJoystick(nr, x, y, b1, b2);
1031 #elif defined(PLATFORM_MSDOS)
1032 return MSDOSReadJoystick(nr, x, y, b1, b2);