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());
125 void ClosePlatformDependentStuff(void)
127 #if defined(PLATFORM_MSDOS)
132 void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
133 int real_sx, int real_sy,
134 int full_sxsize, int full_sysize,
135 Bitmap *field_save_buffer)
141 gfx.real_sx = real_sx;
142 gfx.real_sy = real_sy;
143 gfx.full_sxsize = full_sxsize;
144 gfx.full_sysize = full_sysize;
146 gfx.field_save_buffer = field_save_buffer;
148 gfx.background_bitmap = NULL;
149 gfx.background_bitmap_mask = REDRAW_NONE;
151 SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */
152 SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */
155 void InitGfxDoor1Info(int dx, int dy, int dxsize, int dysize)
163 void InitGfxDoor2Info(int vx, int vy, int vxsize, int vysize)
171 void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height)
173 /* currently only used by MSDOS code to alloc VRAM buffer, if available */
174 gfx.scrollbuffer_width = scrollbuffer_width;
175 gfx.scrollbuffer_height = scrollbuffer_height;
178 void SetDrawDeactivationMask(int draw_deactivation_mask)
180 gfx.draw_deactivation_mask = draw_deactivation_mask;
183 void SetDrawBackgroundMask(int draw_background_mask)
185 gfx.draw_background_mask = draw_background_mask;
188 static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile,
189 int dest_x, int dest_y, int width, int height)
191 int bitmap_xsize = width;
192 int bitmap_ysize = height;
193 int tile_xsize = tile->width;
194 int tile_ysize = tile->height;
195 int tile_xsteps = (bitmap_xsize + tile_xsize - 1) / tile_xsize;
196 int tile_ysteps = (bitmap_ysize + tile_ysize - 1) / tile_ysize;
199 for (y = 0; y < tile_ysteps; y++)
201 for (x = 0; x < tile_xsteps; x++)
203 int draw_x = dest_x + x * tile_xsize;
204 int draw_y = dest_y + y * tile_ysize;
205 int draw_xsize = MIN(tile_xsize, bitmap_xsize - x * tile_xsize);
206 int draw_ysize = MIN(tile_ysize, bitmap_ysize - y * tile_ysize);
208 BlitBitmap(tile, bitmap, 0, 0, draw_xsize, draw_ysize, draw_x, draw_y);
213 void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask)
215 static Bitmap *main_bitmap_tile = NULL;
216 static Bitmap *door_bitmap_tile = NULL;
218 if (mask == REDRAW_FIELD)
220 if (background_bitmap_tile == main_bitmap_tile)
221 return; /* main background tile has not changed */
223 main_bitmap_tile = background_bitmap_tile;
225 else if (mask == REDRAW_DOOR_1)
227 if (background_bitmap_tile == door_bitmap_tile)
228 return; /* main background tile has not changed */
230 door_bitmap_tile = background_bitmap_tile;
232 else /* should not happen */
235 if (background_bitmap_tile)
236 gfx.background_bitmap_mask |= mask;
238 gfx.background_bitmap_mask &= ~mask;
240 if (gfx.background_bitmap == NULL)
241 gfx.background_bitmap = CreateBitmap(video.width, video.height,
244 if (background_bitmap_tile == NULL) /* empty background requested */
247 if (mask == REDRAW_FIELD)
248 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
249 gfx.real_sx, gfx.real_sy,
250 gfx.full_sxsize, gfx.full_sysize);
252 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
254 gfx.dxsize, gfx.dysize);
257 void SetMainBackgroundBitmap(Bitmap *background_bitmap_tile)
259 SetBackgroundBitmap(background_bitmap_tile, REDRAW_FIELD);
262 void SetDoorBackgroundBitmap(Bitmap *background_bitmap_tile)
264 SetBackgroundBitmap(background_bitmap_tile, REDRAW_DOOR_1);
268 /* ========================================================================= */
269 /* video functions */
270 /* ========================================================================= */
272 inline static int GetRealDepth(int depth)
274 return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
277 inline static void sysFillRectangle(Bitmap *bitmap, int x, int y,
278 int width, int height, Pixel color)
280 #if defined(TARGET_SDL)
281 SDLFillRectangle(bitmap, x, y, width, height, color);
283 X11FillRectangle(bitmap, x, y, width, height, color);
287 inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap,
288 int src_x, int src_y, int width, int height,
289 int dst_x, int dst_y, int mask_mode)
291 #if defined(TARGET_SDL)
292 SDLCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
293 dst_x, dst_y, mask_mode);
295 X11CopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
296 dst_x, dst_y, mask_mode);
300 inline void InitVideoDisplay(void)
302 #if defined(TARGET_SDL)
303 SDLInitVideoDisplay();
305 X11InitVideoDisplay();
309 inline void CloseVideoDisplay(void)
311 KeyboardAutoRepeatOn();
313 #if defined(TARGET_SDL)
314 SDL_QuitSubSystem(SDL_INIT_VIDEO);
317 XCloseDisplay(display);
321 inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
322 int width, int height, int depth,
326 video.height = height;
327 video.depth = GetRealDepth(depth);
328 video.fullscreen_available = FULLSCREEN_STATUS;
329 video.fullscreen_enabled = FALSE;
331 #if defined(TARGET_SDL)
332 SDLInitVideoBuffer(backbuffer, window, fullscreen);
334 X11InitVideoBuffer(backbuffer, window);
338 inline Bitmap *CreateBitmapStruct(void)
340 #if defined(TARGET_SDL)
341 return checked_calloc(sizeof(struct SDLSurfaceInfo));
343 return checked_calloc(sizeof(struct X11DrawableInfo));
347 inline Bitmap *CreateBitmap(int width, int height, int depth)
349 Bitmap *new_bitmap = CreateBitmapStruct();
350 int real_depth = GetRealDepth(depth);
352 #if defined(TARGET_SDL)
353 SDLCreateBitmapContent(new_bitmap, width, height, real_depth);
355 X11CreateBitmapContent(new_bitmap, width, height, real_depth);
358 new_bitmap->width = width;
359 new_bitmap->height = height;
364 inline static void FreeBitmapPointers(Bitmap *bitmap)
369 #if defined(TARGET_SDL)
370 SDLFreeBitmapPointers(bitmap);
372 X11FreeBitmapPointers(bitmap);
375 checked_free(bitmap->source_filename);
376 bitmap->source_filename = NULL;
379 inline static void TransferBitmapPointers(Bitmap *src_bitmap,
382 if (src_bitmap == NULL || dst_bitmap == NULL)
385 FreeBitmapPointers(dst_bitmap);
387 *dst_bitmap = *src_bitmap;
390 inline void FreeBitmap(Bitmap *bitmap)
395 FreeBitmapPointers(bitmap);
400 inline void CloseWindow(DrawWindow *window)
402 #if defined(TARGET_X11)
403 if (window->drawable)
405 XUnmapWindow(display, window->drawable);
406 XDestroyWindow(display, window->drawable);
409 XFreeGC(display, window->gc);
413 static inline boolean CheckDrawingArea(int x, int y, int width, int height,
416 if (draw_mask == REDRAW_NONE)
419 if (draw_mask & REDRAW_ALL)
422 if ((draw_mask & REDRAW_FIELD) && x < gfx.real_sx + gfx.full_sxsize)
425 if ((draw_mask & REDRAW_DOOR_1) && x >= gfx.dx && y < gfx.dy + gfx.dysize)
428 if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy)
434 inline boolean DrawingDeactivated(int x, int y, int width, int height)
436 return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
439 inline boolean DrawingOnBackground(int x, int y)
441 return ((gfx.draw_background_mask & gfx.background_bitmap_mask) &&
442 CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
445 inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
446 int src_x, int src_y, int width, int height,
447 int dst_x, int dst_y)
449 if (DrawingDeactivated(dst_x, dst_y, width, height))
452 sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
453 dst_x, dst_y, BLIT_OPAQUE);
456 inline void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height,
459 if (DrawingDeactivated(x, y, width, height))
462 sysFillRectangle(bitmap, x, y, width, height, color);
465 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
467 FillRectangle(bitmap, x, y, width, height, BLACK_PIXEL);
470 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
471 int width, int height)
473 if (DrawingOnBackground(x, y))
474 BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
476 ClearRectangle(bitmap, x, y, width, height);
481 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
485 inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap)
487 #if defined(TARGET_X11)
490 bitmap->clip_gc = clip_gc;
491 XSetClipMask(display, bitmap->clip_gc, clip_pixmap);
494 last_clip_gc = clip_gc;
499 inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y)
501 #if defined(TARGET_X11)
504 bitmap->clip_gc = clip_gc;
505 XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y);
508 last_clip_gc = clip_gc;
513 inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
514 int src_x, int src_y,
515 int width, int height,
516 int dst_x, int dst_y)
518 if (DrawingDeactivated(dst_x, dst_y, width, height))
521 sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
522 dst_x, dst_y, BLIT_MASKED);
525 inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
526 int src_x, int src_y,
527 int width, int height,
528 int dst_x, int dst_y)
530 if (DrawingOnBackground(dst_x, dst_y))
532 /* draw background */
533 BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
536 /* draw foreground */
537 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
538 dst_x - src_x, dst_y - src_y);
539 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
543 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
547 inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
550 #if defined(TARGET_SDL)
551 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL);
553 X11DrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL);
557 #if !defined(TARGET_X11_NATIVE)
558 inline void DrawLine(Bitmap *bitmap, int from_x, int from_y,
559 int to_x, int to_y, Pixel pixel, int line_width)
563 for (x = 0; x < line_width; x++)
565 for (y = 0; y < line_width; y++)
567 int dx = x - line_width / 2;
568 int dy = y - line_width / 2;
570 if ((x == 0 && y == 0) ||
571 (x == 0 && y == line_width - 1) ||
572 (x == line_width - 1 && y == 0) ||
573 (x == line_width - 1 && y == line_width - 1))
576 #if defined(TARGET_SDL)
578 from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
579 #elif defined(TARGET_ALLEGRO)
580 AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy,
581 to_x + dx, to_y + dy, pixel);
588 inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points,
591 #if !defined(TARGET_X11_NATIVE)
595 for (i = 0; i < num_points - 1; i++)
596 DrawLine(bitmap, points[i].x, points[i].y,
597 points[i + 1].x, points[i + 1].y, pixel, line_width);
600 SDLDrawLines(bitmap->surface, points, num_points, pixel);
603 XSetForeground(display, bitmap->line_gc[1], pixel);
604 XDrawLines(display, bitmap->drawable, bitmap->line_gc[1],
605 (XPoint *)points, num_points, CoordModeOrigin);
609 inline Pixel GetPixel(Bitmap *bitmap, int x, int y)
611 if (x < 0 || x >= bitmap->width ||
612 y < 0 || y >= bitmap->height)
615 #if defined(TARGET_SDL)
616 return SDLGetPixel(bitmap, x, y);
617 #elif defined(TARGET_ALLEGRO)
618 return AllegroGetPixel(bitmap->drawable, x, y);
620 return X11GetPixel(bitmap, x, y);
624 inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
625 unsigned int color_g, unsigned int color_b)
627 #if defined(TARGET_SDL)
628 return SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
629 #elif defined(TARGET_ALLEGRO)
630 return AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8);
632 return X11GetPixelFromRGB(color_r, color_g, color_b);
636 inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
638 unsigned int color_r = (color >> 16) & 0xff;
639 unsigned int color_g = (color >> 8) & 0xff;
640 unsigned int color_b = (color >> 0) & 0xff;
642 return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
645 /* execute all pending screen drawing operations */
646 inline void FlushDisplay(void)
653 /* execute and wait for all pending screen drawing operations */
654 inline void SyncDisplay(void)
657 XSync(display, FALSE);
661 inline void KeyboardAutoRepeatOn(void)
663 #if defined(TARGET_SDL)
664 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
665 SDL_DEFAULT_REPEAT_INTERVAL / 2);
666 SDL_EnableUNICODE(1);
669 XAutoRepeatOn(display);
673 inline void KeyboardAutoRepeatOff(void)
675 #if defined(TARGET_SDL)
676 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
677 SDL_EnableUNICODE(0);
680 XAutoRepeatOff(display);
684 inline boolean PointerInWindow(DrawWindow *window)
686 #if defined(TARGET_SDL)
694 /* if XQueryPointer() returns False, the pointer
695 is not on the same screen as the specified window */
696 return XQueryPointer(display, window->drawable, &root, &child,
697 &root_x, &root_y, &win_x, &win_y, &mask);
701 inline boolean SetVideoMode(boolean fullscreen)
703 #if defined(TARGET_SDL)
704 return SDLSetVideoMode(&backbuffer, fullscreen);
706 boolean success = TRUE;
708 if (fullscreen && video.fullscreen_available)
710 Error(ERR_WARN, "fullscreen not available in X11 version");
712 /* display error message only once */
713 video.fullscreen_available = FALSE;
722 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
724 #if defined(TARGET_SDL)
725 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
726 (!fullscreen && video.fullscreen_enabled))
727 fullscreen = SetVideoMode(fullscreen);
733 Bitmap *LoadImage(char *filename)
737 #if defined(TARGET_SDL)
738 new_bitmap = SDLLoadImage(filename);
740 new_bitmap = X11LoadImage(filename);
744 new_bitmap->source_filename = getStringCopy(filename);
749 Bitmap *LoadCustomImage(char *basename)
751 char *filename = getCustomImageFilename(basename);
754 if (filename == NULL)
755 Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
757 if ((new_bitmap = LoadImage(filename)) == NULL)
758 Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
763 void ReloadCustomImage(Bitmap *bitmap, char *basename)
765 char *filename = getCustomImageFilename(basename);
768 if (filename == NULL) /* (should never happen) */
770 Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
774 if (strcmp(filename, bitmap->source_filename) == 0)
776 /* The old and new image are the same (have the same filename and path).
777 This usually means that this image does not exist in this graphic set
778 and a fallback to the existing image is done. */
783 if ((new_bitmap = LoadImage(filename)) == NULL)
785 Error(ERR_WARN, "LoadImage() failed: %s", GetError());
789 if (bitmap->width != new_bitmap->width ||
790 bitmap->height != new_bitmap->height)
792 Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions",
794 FreeBitmap(new_bitmap);
798 TransferBitmapPointers(new_bitmap, bitmap);
802 Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
804 Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH);
806 #if defined(TARGET_SDL)
807 SDLZoomBitmap(src_bitmap, dst_bitmap);
809 X11ZoomBitmap(src_bitmap, dst_bitmap);
815 void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap)
817 Bitmap *tmp_bitmap, *tmp_bitmap_2, *tmp_bitmap_8;
818 int src_width, src_height;
819 int tmp_width, tmp_height;
821 src_width = src_bitmap->width;
822 src_height = src_bitmap->height;
824 tmp_width = src_width;
825 tmp_height = src_height + (src_height + 1) / 2; /* prevent odd height */
827 tmp_bitmap = CreateBitmap(tmp_width, tmp_height, DEFAULT_DEPTH);
829 tmp_bitmap_2 = ZoomBitmap(src_bitmap, src_width / 2, src_height / 2);
830 tmp_bitmap_8 = ZoomBitmap(src_bitmap, src_width / 8, src_height / 8);
832 BlitBitmap(src_bitmap, tmp_bitmap, 0, 0, src_width, src_height, 0, 0);
833 BlitBitmap(tmp_bitmap_2, tmp_bitmap, 0, 0, src_width / 2, src_height / 2,
835 BlitBitmap(tmp_bitmap_8, tmp_bitmap, 0, 0, src_width / 8, src_height / 8,
836 3 * src_width / 4, src_height);
838 FreeBitmap(tmp_bitmap_2);
839 FreeBitmap(tmp_bitmap_8);
841 #if defined(TARGET_SDL)
842 /* !!! what about the old src_bitmap->surface ??? FIX ME !!! */
843 src_bitmap->surface = tmp_bitmap->surface;
844 tmp_bitmap->surface = NULL;
846 /* !!! see above !!! */
847 src_bitmap->drawable = tmp_bitmap->drawable;
848 tmp_bitmap->drawable = None;
851 src_bitmap->height = tmp_bitmap->height;
853 FreeBitmap(tmp_bitmap);
857 /* ------------------------------------------------------------------------- */
858 /* mouse pointer functions */
859 /* ------------------------------------------------------------------------- */
861 #if !defined(PLATFORM_MSDOS)
863 static const char *cursor_image_playfield[] =
865 /* width height num_colors chars_per_pixel */
874 /* some people complained about a "white dot" on the screen and thought it
875 was a graphical error... OK, let's just remove the whole pointer :-) */
921 #if defined(TARGET_SDL)
922 static const int cursor_bit_order = BIT_ORDER_MSB;
923 #elif defined(TARGET_X11_NATIVE)
924 static const int cursor_bit_order = BIT_ORDER_LSB;
927 static struct MouseCursorInfo *get_cursor_from_image(const char **image)
929 struct MouseCursorInfo *cursor;
930 boolean bit_order_msb = (cursor_bit_order == BIT_ORDER_MSB);
931 int header_lines = 4;
934 cursor = checked_calloc(sizeof(struct MouseCursorInfo));
936 sscanf(image[0], " %d %d ", &cursor->width, &cursor->height);
939 for (y = 0; y < cursor->width; y++)
941 for (x = 0; x < cursor->height; x++)
944 int bit_mask = 0x01 << (bit_order_msb ? 7 - bit_nr : bit_nr );
949 cursor->data[i] = cursor->mask[i] = 0;
952 switch (image[header_lines + y][x])
955 cursor->data[i] |= bit_mask;
956 cursor->mask[i] |= bit_mask;
960 cursor->mask[i] |= bit_mask;
969 sscanf(image[header_lines + y], "%d,%d", &cursor->hot_x, &cursor->hot_y);
973 #endif /* !PLATFORM_MSDOS */
975 void SetMouseCursor(int mode)
977 #if !defined(PLATFORM_MSDOS)
978 static struct MouseCursorInfo *cursor_playfield = NULL;
980 if (cursor_playfield == NULL)
981 cursor_playfield = get_cursor_from_image(cursor_image_playfield);
983 #if defined(TARGET_SDL)
984 SDLSetMouseCursor(mode == CURSOR_PLAYFIELD ? cursor_playfield : NULL);
985 #elif defined(TARGET_X11_NATIVE)
986 X11SetMouseCursor(mode == CURSOR_PLAYFIELD ? cursor_playfield : NULL);
992 /* ========================================================================= */
993 /* audio functions */
994 /* ========================================================================= */
996 inline void OpenAudio(void)
998 /* always start with reliable default values */
999 audio.sound_available = FALSE;
1000 audio.music_available = FALSE;
1001 audio.loops_available = FALSE;
1003 audio.sound_enabled = FALSE;
1004 audio.sound_deactivated = FALSE;
1006 audio.mixer_pipe[0] = audio.mixer_pipe[1] = 0;
1007 audio.mixer_pid = 0;
1008 audio.device_name = NULL;
1009 audio.device_fd = -1;
1011 audio.num_channels = 0;
1012 audio.music_channel = 0;
1013 audio.first_sound_channel = 0;
1015 #if defined(TARGET_SDL)
1017 #elif defined(PLATFORM_UNIX)
1019 #elif defined(PLATFORM_MSDOS)
1024 inline void CloseAudio(void)
1026 #if defined(TARGET_SDL)
1028 #elif defined(PLATFORM_UNIX)
1030 #elif defined(PLATFORM_MSDOS)
1034 audio.sound_enabled = FALSE;
1037 inline void SetAudioMode(boolean enabled)
1039 if (!audio.sound_available)
1042 audio.sound_enabled = enabled;
1046 /* ========================================================================= */
1047 /* event functions */
1048 /* ========================================================================= */
1050 inline void InitEventFilter(EventFilter filter_function)
1052 #if defined(TARGET_SDL)
1053 /* set event filter to filter out certain events */
1054 SDL_SetEventFilter(filter_function);
1058 inline boolean PendingEvent(void)
1060 #if defined(TARGET_SDL)
1061 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
1063 return (XPending(display) ? TRUE : FALSE);
1067 inline void NextEvent(Event *event)
1069 #if defined(TARGET_SDL)
1070 SDLNextEvent(event);
1072 XNextEvent(display, event);
1076 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
1078 #if defined(TARGET_SDL)
1080 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
1081 (int)event->keysym.unicode,
1082 (int)event->keysym.sym,
1083 (int)SDL_GetModState());
1086 if (with_modifiers &&
1087 event->keysym.unicode > 0x0000 &&
1088 event->keysym.unicode < 0x2000)
1089 return event->keysym.unicode;
1091 return event->keysym.sym;
1094 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
1095 (int)XLookupKeysym(event, event->state),
1096 (int)XLookupKeysym(event, 0));
1100 return XLookupKeysym(event, event->state);
1102 return XLookupKeysym(event, 0);
1106 inline KeyMod HandleKeyModState(Key key, int key_status)
1108 static KeyMod current_modifiers = KMOD_None;
1110 #if !defined(TARGET_SDL)
1111 if (key != KSYM_UNDEFINED) /* new key => check for modifier key change */
1113 KeyMod new_modifier = KMOD_None;
1118 new_modifier = KMOD_Shift_L;
1121 new_modifier = KMOD_Shift_R;
1123 case KSYM_Control_L:
1124 new_modifier = KMOD_Control_L;
1126 case KSYM_Control_R:
1127 new_modifier = KMOD_Control_R;
1130 new_modifier = KMOD_Meta_L;
1133 new_modifier = KMOD_Meta_R;
1136 new_modifier = KMOD_Alt_L;
1139 new_modifier = KMOD_Alt_R;
1145 if (key_status == KEY_PRESSED)
1146 current_modifiers |= new_modifier;
1148 current_modifiers &= ~new_modifier;
1152 return current_modifiers;
1155 inline KeyMod GetKeyModState()
1157 #if defined(TARGET_SDL)
1158 return (KeyMod)SDL_GetModState();
1160 return HandleKeyModState(KSYM_UNDEFINED, 0);
1164 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
1166 if (event->type != EVENT_CLIENTMESSAGE)
1169 #if defined(TARGET_SDL)
1170 return TRUE; /* the only possible message here is SDL_QUIT */
1171 #elif defined(PLATFORM_UNIX)
1172 if ((event->window == window->drawable) &&
1173 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
1181 /* ========================================================================= */
1182 /* joystick functions */
1183 /* ========================================================================= */
1185 inline void InitJoysticks()
1189 #if defined(NO_JOYSTICK)
1190 return; /* joysticks generally deactivated by compile-time directive */
1193 /* always start with reliable default values */
1194 joystick.status = JOYSTICK_NOT_AVAILABLE;
1195 for (i = 0; i < MAX_PLAYERS; i++)
1196 joystick.fd[i] = -1; /* joystick device closed */
1198 #if defined(TARGET_SDL)
1200 #elif defined(PLATFORM_UNIX)
1201 UnixInitJoysticks();
1202 #elif defined(PLATFORM_MSDOS)
1203 MSDOSInitJoysticks();
1207 inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
1209 #if defined(TARGET_SDL)
1210 return SDLReadJoystick(nr, x, y, b1, b2);
1211 #elif defined(PLATFORM_UNIX)
1212 return UnixReadJoystick(nr, x, y, b1, b2);
1213 #elif defined(PLATFORM_MSDOS)
1214 return MSDOSReadJoystick(nr, x, y, b1, b2);