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_cursor_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_cursor_filename = msdos_cursor_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 InitPlatformDependentStuff(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 ClosePlatformDependentStuff(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 static void sysFillRectangle(Bitmap *bitmap, int x, int y,
276 int width, int height, Pixel color)
278 #if defined(TARGET_SDL)
279 SDLFillRectangle(bitmap, x, y, width, height, color);
281 X11FillRectangle(bitmap, x, y, width, height, color);
285 inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap,
286 int src_x, int src_y, int width, int height,
287 int dst_x, int dst_y, int mask_mode)
289 #if defined(TARGET_SDL)
290 SDLCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
291 dst_x, dst_y, mask_mode);
293 X11CopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
294 dst_x, dst_y, mask_mode);
298 inline void InitVideoDisplay(void)
300 #if defined(TARGET_SDL)
301 SDLInitVideoDisplay();
303 X11InitVideoDisplay();
307 inline void CloseVideoDisplay(void)
309 KeyboardAutoRepeatOn();
311 #if defined(TARGET_SDL)
312 SDL_QuitSubSystem(SDL_INIT_VIDEO);
315 XCloseDisplay(display);
319 inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
320 int width, int height, int depth,
324 video.height = height;
325 video.depth = GetRealDepth(depth);
326 video.fullscreen_available = FULLSCREEN_STATUS;
327 video.fullscreen_enabled = FALSE;
329 #if defined(TARGET_SDL)
330 SDLInitVideoBuffer(backbuffer, window, fullscreen);
332 X11InitVideoBuffer(backbuffer, window);
336 inline Bitmap *CreateBitmapStruct(void)
338 #if defined(TARGET_SDL)
339 return checked_calloc(sizeof(struct SDLSurfaceInfo));
341 return checked_calloc(sizeof(struct X11DrawableInfo));
345 inline Bitmap *CreateBitmap(int width, int height, int depth)
347 Bitmap *new_bitmap = CreateBitmapStruct();
348 int real_depth = GetRealDepth(depth);
350 #if defined(TARGET_SDL)
351 SDLCreateBitmapContent(new_bitmap, width, height, real_depth);
353 X11CreateBitmapContent(new_bitmap, width, height, real_depth);
356 new_bitmap->width = width;
357 new_bitmap->height = height;
362 inline static void FreeBitmapPointers(Bitmap *bitmap)
367 #if defined(TARGET_SDL)
368 SDLFreeBitmapPointers(bitmap);
370 X11FreeBitmapPointers(bitmap);
373 if (bitmap->source_filename)
374 free(bitmap->source_filename);
375 bitmap->source_filename = NULL;
378 inline static void TransferBitmapPointers(Bitmap *src_bitmap,
381 if (src_bitmap == NULL || dst_bitmap == NULL)
384 FreeBitmapPointers(dst_bitmap);
386 *dst_bitmap = *src_bitmap;
389 inline void FreeBitmap(Bitmap *bitmap)
394 FreeBitmapPointers(bitmap);
399 inline void CloseWindow(DrawWindow *window)
401 #if defined(TARGET_X11)
402 if (window->drawable)
404 XUnmapWindow(display, window->drawable);
405 XDestroyWindow(display, window->drawable);
408 XFreeGC(display, window->gc);
412 static inline boolean CheckDrawingArea(int x, int y, int width, int height,
415 if (draw_mask == REDRAW_NONE)
418 if (draw_mask & REDRAW_ALL)
421 if ((draw_mask & REDRAW_FIELD) && x < gfx.real_sx + gfx.full_sxsize)
424 if ((draw_mask & REDRAW_DOOR_1) && x >= gfx.dx && y < gfx.dy + gfx.dysize)
427 if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy)
433 inline boolean DrawingDeactivated(int x, int y, int width, int height)
435 return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
438 inline boolean DrawingOnBackground(int x, int y)
440 return ((gfx.draw_background_mask & gfx.background_bitmap_mask) &&
441 CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
444 inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
445 int src_x, int src_y, int width, int height,
446 int dst_x, int dst_y)
448 if (DrawingDeactivated(dst_x, dst_y, width, height))
451 sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
452 dst_x, dst_y, BLIT_OPAQUE);
455 inline void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height,
458 if (DrawingDeactivated(x, y, width, height))
461 sysFillRectangle(bitmap, x, y, width, height, color);
464 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
466 FillRectangle(bitmap, x, y, width, height, BLACK_PIXEL);
469 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
470 int width, int height)
472 if (DrawingOnBackground(x, y))
473 BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
475 ClearRectangle(bitmap, x, y, width, height);
480 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
484 inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap)
486 #if defined(TARGET_X11)
489 bitmap->clip_gc = clip_gc;
490 XSetClipMask(display, bitmap->clip_gc, clip_pixmap);
493 last_clip_gc = clip_gc;
498 inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y)
500 #if defined(TARGET_X11)
503 bitmap->clip_gc = clip_gc;
504 XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y);
507 last_clip_gc = clip_gc;
512 inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
513 int src_x, int src_y,
514 int width, int height,
515 int dst_x, int dst_y)
517 if (DrawingDeactivated(dst_x, dst_y, width, height))
520 sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
521 dst_x, dst_y, BLIT_MASKED);
524 inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
525 int src_x, int src_y,
526 int width, int height,
527 int dst_x, int dst_y)
529 if (DrawingOnBackground(dst_x, dst_y))
531 /* draw background */
532 BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
535 /* draw foreground */
536 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
537 dst_x - src_x, dst_y - src_y);
538 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
542 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
546 inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
549 #if defined(TARGET_SDL)
550 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL);
552 X11DrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL);
556 #if !defined(TARGET_X11_NATIVE)
557 inline void DrawLine(Bitmap *bitmap, int from_x, int from_y,
558 int to_x, int to_y, Pixel pixel, int line_width)
562 for (x=0; x<line_width; x++)
564 for (y=0; y<line_width; y++)
566 int dx = x - line_width / 2;
567 int dy = y - line_width / 2;
569 if ((x == 0 && y == 0) ||
570 (x == 0 && y == line_width - 1) ||
571 (x == line_width - 1 && y == 0) ||
572 (x == line_width - 1 && y == line_width - 1))
575 #if defined(TARGET_SDL)
577 from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
578 #elif defined(TARGET_ALLEGRO)
579 AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy,
580 to_x + dx, to_y + dy, pixel);
587 inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points,
590 #if !defined(TARGET_X11_NATIVE)
594 for (i=0; i<num_points - 1; i++)
595 DrawLine(bitmap, points[i].x, points[i].y,
596 points[i + 1].x, points[i + 1].y, pixel, line_width);
599 SDLDrawLines(bitmap->surface, points, num_points, pixel);
602 XSetForeground(display, bitmap->line_gc[1], pixel);
603 XDrawLines(display, bitmap->drawable, bitmap->line_gc[1],
604 (XPoint *)points, num_points, CoordModeOrigin);
608 inline Pixel GetPixel(Bitmap *bitmap, int x, int y)
610 if (x < 0 || x >= bitmap->width ||
611 y < 0 || y >= bitmap->height)
614 #if defined(TARGET_SDL)
615 return SDLGetPixel(bitmap, x, y);
616 #elif defined(TARGET_ALLEGRO)
617 return AllegroGetPixel(bitmap->drawable, x, y);
619 return X11GetPixel(bitmap, x, y);
623 inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
624 unsigned int color_g, unsigned int color_b)
626 #if defined(TARGET_SDL)
627 return SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
628 #elif defined(TARGET_ALLEGRO)
629 return AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8);
631 return X11GetPixelFromRGB(color_r, color_g, color_b);
635 inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
637 unsigned int color_r = (color >> 16) & 0xff;
638 unsigned int color_g = (color >> 8) & 0xff;
639 unsigned int color_b = (color >> 0) & 0xff;
641 return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
644 /* execute all pending screen drawing operations */
645 inline void FlushDisplay(void)
652 /* execute and wait for all pending screen drawing operations */
653 inline void SyncDisplay(void)
656 XSync(display, FALSE);
660 inline void KeyboardAutoRepeatOn(void)
662 #if defined(TARGET_SDL)
663 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
664 SDL_DEFAULT_REPEAT_INTERVAL / 2);
665 SDL_EnableUNICODE(1);
668 XAutoRepeatOn(display);
672 inline void KeyboardAutoRepeatOff(void)
674 #if defined(TARGET_SDL)
675 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
676 SDL_EnableUNICODE(0);
679 XAutoRepeatOff(display);
683 inline boolean PointerInWindow(DrawWindow *window)
685 #if defined(TARGET_SDL)
693 /* if XQueryPointer() returns False, the pointer
694 is not on the same screen as the specified window */
695 return XQueryPointer(display, window->drawable, &root, &child,
696 &root_x, &root_y, &win_x, &win_y, &mask);
700 inline boolean SetVideoMode(boolean fullscreen)
702 #if defined(TARGET_SDL)
703 return SDLSetVideoMode(&backbuffer, fullscreen);
705 boolean success = TRUE;
707 if (fullscreen && video.fullscreen_available)
709 Error(ERR_WARN, "fullscreen not available in X11 version");
711 /* display error message only once */
712 video.fullscreen_available = FALSE;
721 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
723 #if defined(TARGET_SDL)
724 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
725 (!fullscreen && video.fullscreen_enabled))
726 fullscreen = SetVideoMode(fullscreen);
732 Bitmap *LoadImage(char *filename)
736 #if defined(TARGET_SDL)
737 new_bitmap = SDLLoadImage(filename);
739 new_bitmap = X11LoadImage(filename);
743 new_bitmap->source_filename = getStringCopy(filename);
748 Bitmap *LoadCustomImage(char *basename)
750 char *filename = getCustomImageFilename(basename);
753 if (filename == NULL)
754 Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
756 if ((new_bitmap = LoadImage(filename)) == NULL)
757 Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
762 void ReloadCustomImage(Bitmap *bitmap, char *basename)
764 char *filename = getCustomImageFilename(basename);
767 if (filename == NULL) /* (should never happen) */
769 Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
773 if (strcmp(filename, bitmap->source_filename) == 0)
775 /* The old and new image are the same (have the same filename and path).
776 This usually means that this image does not exist in this graphic set
777 and a fallback to the existing image is done. */
782 if ((new_bitmap = LoadImage(filename)) == NULL)
784 Error(ERR_WARN, "LoadImage() failed: %s", GetError());
788 if (bitmap->width != new_bitmap->width ||
789 bitmap->height != new_bitmap->height)
791 Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions",
793 FreeBitmap(new_bitmap);
797 TransferBitmapPointers(new_bitmap, bitmap);
801 Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
803 Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH);
805 #if defined(TARGET_SDL)
806 SDLZoomBitmap(src_bitmap, dst_bitmap);
808 X11ZoomBitmap(src_bitmap, dst_bitmap);
814 void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap)
816 Bitmap *tmp_bitmap, *tmp_bitmap_2, *tmp_bitmap_8;
817 int src_width, src_height;
818 int tmp_width, tmp_height;
820 src_width = src_bitmap->width;
821 src_height = src_bitmap->height;
823 tmp_width = src_width;
824 tmp_height = src_height + (src_height + 1) / 2; /* prevent odd height */
826 tmp_bitmap = CreateBitmap(tmp_width, tmp_height, DEFAULT_DEPTH);
828 tmp_bitmap_2 = ZoomBitmap(src_bitmap, src_width / 2, src_height / 2);
829 tmp_bitmap_8 = ZoomBitmap(src_bitmap, src_width / 8, src_height / 8);
831 BlitBitmap(src_bitmap, tmp_bitmap, 0, 0, src_width, src_height, 0, 0);
832 BlitBitmap(tmp_bitmap_2, tmp_bitmap, 0, 0, src_width / 2, src_height / 2,
834 BlitBitmap(tmp_bitmap_8, tmp_bitmap, 0, 0, src_width / 8, src_height / 8,
835 3 * src_width / 4, src_height);
837 FreeBitmap(tmp_bitmap_2);
838 FreeBitmap(tmp_bitmap_8);
840 #if defined(TARGET_SDL)
841 /* !!! what about the old src_bitmap->surface ??? FIX ME !!! */
842 src_bitmap->surface = tmp_bitmap->surface;
843 tmp_bitmap->surface = NULL;
845 /* !!! see above !!! */
846 src_bitmap->drawable = tmp_bitmap->drawable;
847 tmp_bitmap->drawable = None;
850 src_bitmap->height = tmp_bitmap->height;
852 FreeBitmap(tmp_bitmap);
856 /* ------------------------------------------------------------------------- */
857 /* mouse pointer functions */
858 /* ------------------------------------------------------------------------- */
860 #if !defined(PLATFORM_MSDOS)
862 static const char *cursor_image_playfield[] =
864 /* width height num_colors chars_per_pixel */
894 #if defined(TARGET_SDL)
895 static const int cursor_bit_order = BIT_ORDER_MSB;
896 #elif defined(TARGET_X11_NATIVE)
897 static const int cursor_bit_order = BIT_ORDER_LSB;
900 static struct MouseCursorInfo *get_cursor_from_image(const char **image)
902 struct MouseCursorInfo *cursor;
903 boolean bit_order_msb = (cursor_bit_order == BIT_ORDER_MSB);
904 int header_lines = 4;
907 cursor = checked_calloc(sizeof(struct MouseCursorInfo));
909 sscanf(image[0], " %d %d ", &cursor->width, &cursor->height);
912 for (y=0; y < cursor->width; y++)
914 for (x=0; x < cursor->height; x++)
917 int bit_mask = 0x01 << (bit_order_msb ? 7 - bit_nr : bit_nr );
922 cursor->data[i] = cursor->mask[i] = 0;
925 switch (image[header_lines + y][x])
928 cursor->data[i] |= bit_mask;
929 cursor->mask[i] |= bit_mask;
933 cursor->mask[i] |= bit_mask;
942 sscanf(image[header_lines + y], "%d,%d", &cursor->hot_x, &cursor->hot_y);
946 #endif /* !PLATFORM_MSDOS */
948 void SetMouseCursor(int mode)
950 #if !defined(PLATFORM_MSDOS)
951 static struct MouseCursorInfo *cursor_playfield = NULL;
953 if (cursor_playfield == NULL)
954 cursor_playfield = get_cursor_from_image(cursor_image_playfield);
956 #if defined(TARGET_SDL)
957 SDLSetMouseCursor(mode == CURSOR_PLAYFIELD ? cursor_playfield : NULL);
958 #elif defined(TARGET_X11_NATIVE)
959 X11SetMouseCursor(mode == CURSOR_PLAYFIELD ? cursor_playfield : NULL);
965 /* ========================================================================= */
966 /* audio functions */
967 /* ========================================================================= */
969 inline void OpenAudio(void)
971 /* always start with reliable default values */
972 audio.sound_available = FALSE;
973 audio.music_available = FALSE;
974 audio.loops_available = FALSE;
976 audio.sound_enabled = FALSE;
977 audio.sound_deactivated = FALSE;
979 audio.mixer_pipe[0] = audio.mixer_pipe[1] = 0;
981 audio.device_name = NULL;
982 audio.device_fd = -1;
984 audio.num_channels = 0;
985 audio.music_channel = 0;
986 audio.first_sound_channel = 0;
988 #if defined(TARGET_SDL)
990 #elif defined(PLATFORM_UNIX)
992 #elif defined(PLATFORM_MSDOS)
997 inline void CloseAudio(void)
999 #if defined(TARGET_SDL)
1001 #elif defined(PLATFORM_UNIX)
1003 #elif defined(PLATFORM_MSDOS)
1007 audio.sound_enabled = FALSE;
1010 inline void SetAudioMode(boolean enabled)
1012 if (!audio.sound_available)
1015 audio.sound_enabled = enabled;
1019 /* ========================================================================= */
1020 /* event functions */
1021 /* ========================================================================= */
1023 inline void InitEventFilter(EventFilter filter_function)
1025 #if defined(TARGET_SDL)
1026 /* set event filter to filter out certain events */
1027 SDL_SetEventFilter(filter_function);
1031 inline boolean PendingEvent(void)
1033 #if defined(TARGET_SDL)
1034 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
1036 return (XPending(display) ? TRUE : FALSE);
1040 inline void NextEvent(Event *event)
1042 #if defined(TARGET_SDL)
1043 SDLNextEvent(event);
1045 XNextEvent(display, event);
1049 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
1051 #if defined(TARGET_SDL)
1053 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
1054 (int)event->keysym.unicode,
1055 (int)event->keysym.sym,
1056 (int)SDL_GetModState());
1059 if (with_modifiers &&
1060 event->keysym.unicode > 0x0000 &&
1061 event->keysym.unicode < 0x2000)
1062 return event->keysym.unicode;
1064 return event->keysym.sym;
1067 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
1068 (int)XLookupKeysym(event, event->state),
1069 (int)XLookupKeysym(event, 0));
1073 return XLookupKeysym(event, event->state);
1075 return XLookupKeysym(event, 0);
1079 inline KeyMod HandleKeyModState(Key key, int key_status)
1081 static KeyMod current_modifiers = KMOD_None;
1083 #if !defined(TARGET_SDL)
1084 if (key != KSYM_UNDEFINED) /* new key => check for modifier key change */
1086 KeyMod new_modifier = KMOD_None;
1091 new_modifier = KMOD_Shift_L;
1094 new_modifier = KMOD_Shift_R;
1096 case KSYM_Control_L:
1097 new_modifier = KMOD_Control_L;
1099 case KSYM_Control_R:
1100 new_modifier = KMOD_Control_R;
1103 new_modifier = KMOD_Meta_L;
1106 new_modifier = KMOD_Meta_R;
1109 new_modifier = KMOD_Alt_L;
1112 new_modifier = KMOD_Alt_R;
1118 if (key_status == KEY_PRESSED)
1119 current_modifiers |= new_modifier;
1121 current_modifiers &= ~new_modifier;
1125 return current_modifiers;
1128 inline KeyMod GetKeyModState()
1130 #if defined(TARGET_SDL)
1131 return (KeyMod)SDL_GetModState();
1133 return HandleKeyModState(KSYM_UNDEFINED, 0);
1137 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
1139 if (event->type != EVENT_CLIENTMESSAGE)
1142 #if defined(TARGET_SDL)
1143 return TRUE; /* the only possible message here is SDL_QUIT */
1144 #elif defined(PLATFORM_UNIX)
1145 if ((event->window == window->drawable) &&
1146 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
1154 /* ========================================================================= */
1155 /* joystick functions */
1156 /* ========================================================================= */
1158 inline void InitJoysticks()
1162 #if defined(NO_JOYSTICK)
1163 return; /* joysticks generally deactivated by compile-time directive */
1166 /* always start with reliable default values */
1167 joystick.status = JOYSTICK_NOT_AVAILABLE;
1168 for (i=0; i<MAX_PLAYERS; i++)
1169 joystick.fd[i] = -1; /* joystick device closed */
1171 #if defined(TARGET_SDL)
1173 #elif defined(PLATFORM_UNIX)
1174 UnixInitJoysticks();
1175 #elif defined(PLATFORM_MSDOS)
1176 MSDOSInitJoysticks();
1180 inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
1182 #if defined(TARGET_SDL)
1183 return SDLReadJoystick(nr, x, y, b1, b2);
1184 #elif defined(PLATFORM_UNIX)
1185 return UnixReadJoystick(nr, x, y, b1, b2);
1186 #elif defined(PLATFORM_MSDOS)
1187 return MSDOSReadJoystick(nr, x, y, b1, b2);