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;
41 struct ArtworkInfo artwork;
42 struct JoystickInfo joystick;
43 struct SetupInfo setup;
45 LevelDirTree *leveldir_first = NULL;
46 LevelDirTree *leveldir_current = NULL;
49 Display *display = NULL;
50 Visual *visual = NULL;
54 DrawWindow *window = NULL;
55 DrawBuffer *backbuffer = NULL;
56 DrawBuffer *drawto = NULL;
58 int button_status = MB_NOT_PRESSED;
59 boolean motion_status = FALSE;
61 int redraw_mask = REDRAW_NONE;
67 /* ========================================================================= */
68 /* init/close functions */
69 /* ========================================================================= */
71 void InitCommandName(char *argv0)
73 program.command_basename =
74 (strrchr(argv0, '/') ? strrchr(argv0, '/') + 1 : argv0);
77 void InitExitFunction(void (*exit_function)(int))
79 program.exit_function = exit_function;
81 /* set signal handlers to custom exit function */
82 signal(SIGINT, exit_function);
83 signal(SIGTERM, exit_function);
85 #if defined(TARGET_SDL)
86 /* set exit function to automatically cleanup SDL stuff after exit() */
91 void InitPlatformDependantStuff(void)
93 #if defined(PLATFORM_MSDOS)
97 #if !defined(PLATFORM_UNIX)
98 program.userdata_directory = "userdata";
101 #if defined(PLATFORM_MSDOS)
105 #if defined(TARGET_SDL)
106 if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0)
107 Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
111 void ClosePlatformDependantStuff(void)
113 #if defined(PLATFORM_MSDOS)
118 void InitProgramInfo(char *unix_userdata_directory, char *program_title,
119 char *window_title, char *icon_title,
120 char *x11_icon_filename, char *x11_iconmask_filename,
121 char *msdos_pointer_filename,
122 char *cookie_prefix, char *filename_prefix,
125 #if defined(PLATFORM_UNIX)
126 program.userdata_directory = unix_userdata_directory;
128 program.userdata_directory = "userdata";
131 program.program_title = program_title;
132 program.window_title = window_title;
133 program.icon_title = icon_title;
134 program.x11_icon_filename = x11_icon_filename;
135 program.x11_iconmask_filename = x11_iconmask_filename;
136 program.msdos_pointer_filename = msdos_pointer_filename;
138 program.cookie_prefix = cookie_prefix;
139 program.filename_prefix = filename_prefix;
141 program.version_major = VERSION_MAJOR(program_version);
142 program.version_minor = VERSION_MINOR(program_version);
143 program.version_patch = VERSION_PATCH(program_version);
146 void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
147 int real_sx, int real_sy,
148 int full_sxsize, int full_sysize)
154 gfx.real_sx = real_sx;
155 gfx.real_sy = real_sy;
156 gfx.full_sxsize = full_sxsize;
157 gfx.full_sysize = full_sysize;
159 gfx.background_bitmap = NULL;
160 gfx.background_bitmap_mask = REDRAW_NONE;
162 SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */
163 SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */
166 void InitGfxDoor1Info(int dx, int dy, int dxsize, int dysize)
174 void InitGfxDoor2Info(int vx, int vy, int vxsize, int vysize)
182 void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height)
184 /* currently only used by MSDOS code to alloc VRAM buffer, if available */
185 gfx.scrollbuffer_width = scrollbuffer_width;
186 gfx.scrollbuffer_height = scrollbuffer_height;
189 void SetDrawDeactivationMask(int draw_deactivation_mask)
191 gfx.draw_deactivation_mask = draw_deactivation_mask;
194 void SetDrawBackgroundMask(int draw_background_mask)
196 gfx.draw_background_mask = draw_background_mask;
199 static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile,
200 int dest_x, int dest_y, int width, int height)
202 int bitmap_xsize = width;
203 int bitmap_ysize = height;
204 int tile_xsize = tile->width;
205 int tile_ysize = tile->height;
206 int tile_xsteps = (bitmap_xsize + tile_xsize - 1) / tile_xsize;
207 int tile_ysteps = (bitmap_ysize + tile_ysize - 1) / tile_ysize;
210 for (y=0; y < tile_ysteps; y++)
212 for (x=0; x < tile_xsteps; x++)
214 int draw_x = dest_x + x * tile_xsize;
215 int draw_y = dest_y + y * tile_ysize;
216 int draw_xsize = MIN(tile_xsize, bitmap_xsize - x * tile_xsize);
217 int draw_ysize = MIN(tile_ysize, bitmap_ysize - y * tile_ysize);
219 BlitBitmap(tile, bitmap, 0, 0, draw_xsize, draw_ysize, draw_x, draw_y);
224 void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask)
226 static Bitmap *main_bitmap_tile = NULL;
227 static Bitmap *door_bitmap_tile = NULL;
229 if (mask == REDRAW_FIELD)
231 if (background_bitmap_tile == main_bitmap_tile)
232 return; /* main background tile has not changed */
234 main_bitmap_tile = background_bitmap_tile;
236 else if (mask == REDRAW_DOOR_1)
238 if (background_bitmap_tile == door_bitmap_tile)
239 return; /* main background tile has not changed */
241 door_bitmap_tile = background_bitmap_tile;
243 else /* should not happen */
246 if (background_bitmap_tile)
247 gfx.background_bitmap_mask |= mask;
249 gfx.background_bitmap_mask &= ~mask;
251 if (gfx.background_bitmap == NULL)
252 gfx.background_bitmap = CreateBitmap(video.width, video.height,
255 if (background_bitmap_tile == NULL) /* empty background requested */
258 if (mask == REDRAW_FIELD)
259 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
260 gfx.real_sx, gfx.real_sy,
261 gfx.full_sxsize, gfx.full_sysize);
263 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
265 gfx.dxsize, gfx.dysize);
268 void SetMainBackgroundBitmap(Bitmap *background_bitmap_tile)
270 SetBackgroundBitmap(background_bitmap_tile, REDRAW_FIELD);
273 void SetDoorBackgroundBitmap(Bitmap *background_bitmap_tile)
275 SetBackgroundBitmap(background_bitmap_tile, REDRAW_DOOR_1);
279 /* ========================================================================= */
280 /* video functions */
281 /* ========================================================================= */
283 inline static int GetRealDepth(int depth)
285 return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
288 inline void InitVideoDisplay(void)
290 #if defined(TARGET_SDL)
291 SDLInitVideoDisplay();
293 X11InitVideoDisplay();
297 inline void CloseVideoDisplay(void)
299 KeyboardAutoRepeatOn();
301 #if defined(TARGET_SDL)
302 SDL_QuitSubSystem(SDL_INIT_VIDEO);
306 XCloseDisplay(display);
310 inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
311 int width, int height, int depth,
315 video.height = height;
316 video.depth = GetRealDepth(depth);
317 video.fullscreen_available = FULLSCREEN_STATUS;
318 video.fullscreen_enabled = FALSE;
321 SDLInitVideoBuffer(backbuffer, window, fullscreen);
323 X11InitVideoBuffer(backbuffer, window);
327 inline Bitmap *CreateBitmapStruct(void)
330 return checked_calloc(sizeof(struct SDLSurfaceInfo));
332 return checked_calloc(sizeof(struct X11DrawableInfo));
336 inline Bitmap *CreateBitmap(int width, int height, int depth)
338 Bitmap *new_bitmap = CreateBitmapStruct();
339 int real_depth = GetRealDepth(depth);
342 SDL_Surface *surface_tmp, *surface_native;
344 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
345 real_depth, 0, 0, 0, 0))
347 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
349 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
350 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
352 SDL_FreeSurface(surface_tmp);
354 new_bitmap->surface = surface_native;
358 if ((pixmap = XCreatePixmap(display, window->drawable,
359 width, height, real_depth))
361 Error(ERR_EXIT, "cannot create pixmap");
363 new_bitmap->drawable = pixmap;
366 Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first");
368 new_bitmap->gc = window->gc;
370 new_bitmap->line_gc[0] = window->line_gc[0];
371 new_bitmap->line_gc[1] = window->line_gc[1];
374 new_bitmap->width = width;
375 new_bitmap->height = height;
380 inline static void FreeBitmapPointers(Bitmap *bitmap)
387 SDL_FreeSurface(bitmap->surface);
388 if (bitmap->surface_masked)
389 SDL_FreeSurface(bitmap->surface_masked);
390 bitmap->surface = NULL;
391 bitmap->surface_masked = NULL;
393 /* The X11 version seems to have a memory leak here -- although
394 "XFreePixmap()" is called, the correspondig memory seems not
395 to be freed (according to "ps"). The SDL version apparently
396 does not have this problem. */
398 if (bitmap->drawable)
399 XFreePixmap(display, bitmap->drawable);
400 if (bitmap->clip_mask)
401 XFreePixmap(display, bitmap->clip_mask);
402 if (bitmap->stored_clip_gc)
403 XFreeGC(display, bitmap->stored_clip_gc);
404 /* the other GCs are only pointers to GCs used elsewhere */
405 bitmap->drawable = None;
406 bitmap->clip_mask = None;
407 bitmap->stored_clip_gc = None;
410 if (bitmap->source_filename)
411 free(bitmap->source_filename);
412 bitmap->source_filename = NULL;
415 inline static void TransferBitmapPointers(Bitmap *src_bitmap,
418 if (src_bitmap == NULL || dst_bitmap == NULL)
421 FreeBitmapPointers(dst_bitmap);
423 *dst_bitmap = *src_bitmap;
426 inline void FreeBitmap(Bitmap *bitmap)
431 FreeBitmapPointers(bitmap);
436 inline void CloseWindow(DrawWindow *window)
439 if (window->drawable)
441 XUnmapWindow(display, window->drawable);
442 XDestroyWindow(display, window->drawable);
445 XFreeGC(display, window->gc);
449 static inline boolean CheckDrawingArea(int x, int y, int width, int height,
452 if (draw_mask == REDRAW_NONE)
455 if (draw_mask & REDRAW_ALL)
458 if ((draw_mask & REDRAW_FIELD) && x < gfx.real_sx + gfx.full_sxsize)
461 if ((draw_mask & REDRAW_DOOR_1) && x >= gfx.dx && y < gfx.dy + gfx.dysize)
464 if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy)
470 inline boolean DrawingDeactivated(int x, int y, int width, int height)
472 return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
475 inline boolean DrawingOnBackground(int x, int y)
477 return ((gfx.draw_background_mask & gfx.background_bitmap_mask) &&
478 CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
481 inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
482 int src_x, int src_y,
483 int width, int height,
484 int dst_x, int dst_y)
486 if (DrawingDeactivated(dst_x, dst_y, width, height))
490 SDLCopyArea(src_bitmap, dst_bitmap,
491 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_OPAQUE);
493 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
494 dst_bitmap->gc, src_x, src_y, width, height, dst_x, dst_y);
498 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
500 if (DrawingDeactivated(x, y, width, height))
504 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
506 XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height);
510 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
511 int width, int height)
513 if (DrawingOnBackground(x, y))
514 BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
516 ClearRectangle(bitmap, x, y, width, height);
521 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
525 inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap)
530 bitmap->clip_gc = clip_gc;
531 XSetClipMask(display, bitmap->clip_gc, clip_pixmap);
534 last_clip_gc = clip_gc;
539 inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y)
544 bitmap->clip_gc = clip_gc;
545 XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y);
548 last_clip_gc = clip_gc;
553 inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
554 int src_x, int src_y,
555 int width, int height,
556 int dst_x, int dst_y)
558 if (DrawingDeactivated(dst_x, dst_y, width, height))
562 SDLCopyArea(src_bitmap, dst_bitmap,
563 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_MASKED);
565 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
566 src_bitmap->clip_gc, src_x, src_y, width, height, dst_x, dst_y);
570 inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
571 int src_x, int src_y,
572 int width, int height,
573 int dst_x, int dst_y)
575 if (DrawingOnBackground(src_x, src_y))
577 /* draw background */
578 BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
581 /* draw foreground */
582 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
583 dst_x - src_x, dst_y - src_y);
584 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
588 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
592 inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
596 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
598 XSetForeground(display, bitmap->gc, WhitePixel(display, screen));
599 XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y);
600 XSetForeground(display, bitmap->gc, BlackPixel(display, screen));
604 #if !defined(TARGET_X11_NATIVE)
605 inline void DrawLine(Bitmap *bitmap, int from_x, int from_y,
606 int to_x, int to_y, Pixel pixel, int line_width)
610 for (x=0; x<line_width; x++)
612 for (y=0; y<line_width; y++)
614 int dx = x - line_width / 2;
615 int dy = y - line_width / 2;
617 if ((x == 0 && y == 0) ||
618 (x == 0 && y == line_width - 1) ||
619 (x == line_width - 1 && y == 0) ||
620 (x == line_width - 1 && y == line_width - 1))
623 #if defined(TARGET_SDL)
625 from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
626 #elif defined(TARGET_ALLEGRO)
627 AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy,
628 to_x + dx, to_y + dy, pixel);
635 inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points,
638 #if !defined(TARGET_X11_NATIVE)
642 for (i=0; i<num_points - 1; i++)
643 DrawLine(bitmap, points[i].x, points[i].y,
644 points[i + 1].x, points[i + 1].y, pixel, line_width);
647 SDLDrawLines(bitmap->surface, points, num_points, pixel);
650 XSetForeground(display, bitmap->line_gc[1], pixel);
651 XDrawLines(display, bitmap->drawable, bitmap->line_gc[1],
652 (XPoint *)points, num_points, CoordModeOrigin);
654 XSetForeground(display, gc, BlackPixel(display, screen));
659 inline Pixel GetPixel(Bitmap *bitmap, int x, int y)
661 #if defined(TARGET_SDL)
662 return SDLGetPixel(bitmap, x, y);
663 #elif defined(TARGET_ALLEGRO)
664 return AllegroGetPixel(bitmap->drawable, x, y);
666 unsigned long pixel_value;
669 pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1,
671 pixel_value = XGetPixel(pixel_image, 0, 0);
673 XDestroyImage(pixel_image);
679 inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
680 unsigned int color_g, unsigned int color_b)
684 #if defined(TARGET_SDL)
685 pixel = SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
686 #elif defined(TARGET_ALLEGRO)
687 pixel = AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8);
688 #elif defined(TARGET_X11_NATIVE)
691 xcolor.flags = DoRed | DoGreen | DoBlue;
692 xcolor.red = (color_r << 8);
693 xcolor.green = (color_g << 8);
694 xcolor.blue = (color_b << 8);
695 XAllocColor(display, cmap, &xcolor);
696 pixel = xcolor.pixel;
702 inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
704 unsigned int color_r = (color >> 16) & 0xff;
705 unsigned int color_g = (color >> 8) & 0xff;
706 unsigned int color_b = (color >> 0) & 0xff;
708 return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
711 /* execute all pending screen drawing operations */
712 inline void FlushDisplay(void)
719 /* execute and wait for all pending screen drawing operations */
720 inline void SyncDisplay(void)
723 XSync(display, FALSE);
727 inline void KeyboardAutoRepeatOn(void)
730 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
731 SDL_DEFAULT_REPEAT_INTERVAL / 2);
732 SDL_EnableUNICODE(1);
735 XAutoRepeatOn(display);
739 inline void KeyboardAutoRepeatOff(void)
742 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
743 SDL_EnableUNICODE(0);
746 XAutoRepeatOff(display);
750 inline boolean PointerInWindow(DrawWindow *window)
760 /* if XQueryPointer() returns False, the pointer
761 is not on the same screen as the specified window */
762 return XQueryPointer(display, window->drawable, &root, &child,
763 &root_x, &root_y, &win_x, &win_y, &mask);
767 inline boolean SetVideoMode(boolean fullscreen)
770 return SDLSetVideoMode(&backbuffer, fullscreen);
772 boolean success = TRUE;
774 if (fullscreen && video.fullscreen_available)
776 Error(ERR_WARN, "fullscreen not available in X11 version");
778 /* display error message only once */
779 video.fullscreen_available = FALSE;
788 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
791 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
792 (!fullscreen && video.fullscreen_enabled))
793 fullscreen = SetVideoMode(fullscreen);
799 Bitmap *LoadImage(char *filename)
803 #if defined(TARGET_SDL)
804 new_bitmap = SDLLoadImage(filename);
806 new_bitmap = X11LoadImage(filename);
810 new_bitmap->source_filename = getStringCopy(filename);
815 Bitmap *LoadCustomImage(char *basename)
817 char *filename = getCustomImageFilename(basename);
820 if (filename == NULL)
821 Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
823 if ((new_bitmap = LoadImage(filename)) == NULL)
824 Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
829 void ReloadCustomImage(Bitmap *bitmap, char *basename)
831 char *filename = getCustomImageFilename(basename);
834 if (filename == NULL) /* (should never happen) */
836 Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
840 if (strcmp(filename, bitmap->source_filename) == 0)
842 /* The old and new image are the same (have the same filename and path).
843 This usually means that this image does not exist in this graphic set
844 and a fallback to the existing image is done. */
849 if ((new_bitmap = LoadImage(filename)) == NULL)
851 Error(ERR_WARN, "LoadImage() failed: %s", GetError());
855 if (bitmap->width != new_bitmap->width ||
856 bitmap->height != new_bitmap->height)
858 Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions",
860 FreeBitmap(new_bitmap);
864 TransferBitmapPointers(new_bitmap, bitmap);
868 Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
870 Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH);
872 #if defined(TARGET_SDL)
873 SDLZoomBitmap(src_bitmap, dst_bitmap);
875 X11ZoomBitmap(src_bitmap, dst_bitmap);
882 /* ========================================================================= */
883 /* audio functions */
884 /* ========================================================================= */
886 inline void OpenAudio(void)
888 /* always start with reliable default values */
889 audio.sound_available = FALSE;
890 audio.music_available = FALSE;
891 audio.loops_available = FALSE;
893 audio.sound_enabled = FALSE;
894 audio.sound_deactivated = FALSE;
896 audio.mixer_pipe[0] = audio.mixer_pipe[1] = 0;
897 audio.mixer_pid = -1;
898 audio.device_name = NULL;
899 audio.device_fd = -1;
901 audio.num_channels = 0;
902 audio.music_channel = 0;
903 audio.first_sound_channel = 0;
905 #if defined(TARGET_SDL)
907 #elif defined(PLATFORM_UNIX)
909 #elif defined(PLATFORM_MSDOS)
914 inline void CloseAudio(void)
916 #if defined(TARGET_SDL)
918 #elif defined(PLATFORM_UNIX)
920 #elif defined(PLATFORM_MSDOS)
924 audio.sound_enabled = FALSE;
927 inline void SetAudioMode(boolean enabled)
929 if (!audio.sound_available)
932 audio.sound_enabled = enabled;
936 /* ========================================================================= */
937 /* event functions */
938 /* ========================================================================= */
940 inline void InitEventFilter(EventFilter filter_function)
943 /* set event filter to filter out certain events */
944 SDL_SetEventFilter(filter_function);
948 inline boolean PendingEvent(void)
951 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
953 return (XPending(display) ? TRUE : FALSE);
957 inline void NextEvent(Event *event)
962 XNextEvent(display, event);
966 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
970 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
971 (int)event->keysym.unicode,
972 (int)event->keysym.sym,
973 (int)SDL_GetModState());
976 if (with_modifiers &&
977 event->keysym.unicode > 0x0000 &&
978 event->keysym.unicode < 0x2000)
979 return event->keysym.unicode;
981 return event->keysym.sym;
984 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
985 (int)XLookupKeysym(event, event->state),
986 (int)XLookupKeysym(event, 0));
990 return XLookupKeysym(event, event->state);
992 return XLookupKeysym(event, 0);
996 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
998 if (event->type != EVENT_CLIENTMESSAGE)
1001 #if defined(TARGET_SDL)
1002 return TRUE; /* the only possible message here is SDL_QUIT */
1003 #elif defined(PLATFORM_UNIX)
1004 if ((event->window == window->drawable) &&
1005 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
1013 /* ========================================================================= */
1014 /* joystick functions */
1015 /* ========================================================================= */
1017 inline void InitJoysticks()
1022 return; /* joysticks generally deactivated by compile-time directive */
1025 /* always start with reliable default values */
1026 joystick.status = JOYSTICK_NOT_AVAILABLE;
1027 for (i=0; i<MAX_PLAYERS; i++)
1028 joystick.fd[i] = -1; /* joystick device closed */
1030 #if defined(TARGET_SDL)
1032 #elif defined(PLATFORM_UNIX)
1033 UnixInitJoysticks();
1034 #elif defined(PLATFORM_MSDOS)
1035 MSDOSInitJoysticks();
1039 inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
1041 #if defined(TARGET_SDL)
1042 return SDLReadJoystick(nr, x, y, b1, b2);
1043 #elif defined(PLATFORM_UNIX)
1044 return UnixReadJoystick(nr, x, y, b1, b2);
1045 #elif defined(PLATFORM_MSDOS)
1046 return MSDOSReadJoystick(nr, x, y, b1, b2);