X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmsdos.c;h=c4c6ff4f4cceca78a66b418d0a00ed3ba78eff67;hb=61c3da024802ecc0268bab42d7499fc0346e4fd3;hp=b3137b4a5bc7ecc98eb20e536503e1614b6f205b;hpb=49221e59bff18cdfbef8c877b588280266ae5037;p=rocksndiamonds.git diff --git a/src/libgame/msdos.c b/src/libgame/msdos.c index b3137b4a..c4c6ff4f 100644 --- a/src/libgame/msdos.c +++ b/src/libgame/msdos.c @@ -1,21 +1,27 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Artsoft Retro-Game Library * *----------------------------------------------------------* -* ©1995 Artsoft Development * -* Holger Schemel * -* 33659 Bielefeld-Senne * -* Telefon: (0521) 493245 * -* eMail: aeglos@valinor.owl.de * -* aeglos@uni-paderborn.de * -* q99492@pbhrzx.uni-paderborn.de * +* (c) 1994-2006 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* msdos.c * +* msdos.c * ***********************************************************/ -#include "libgame.h" +#include "system.h" + #if defined(PLATFORM_MSDOS) +#include "sound.h" +#include "joystick.h" +#include "misc.h" +#include "setup.h" +#include "pcx.h" + #define AllegroDefaultScreen() (display->screens[display->default_screen]) /* allegro driver declarations */ @@ -48,22 +54,16 @@ static int global_colormap_entries_used = 0; boolean wait_for_vsync; -/* -extern int playing_sounds; -extern struct SoundControl playlist[MAX_SOUNDS_PLAYING]; -extern struct SoundControl emptySoundControl; -*/ - static BITMAP *Read_PCX_to_AllegroBitmap(char *); static void allegro_init_drivers() { int i; - for (i=0; i>= 10; /* try to use existing colors from the global colormap */ - for (i=0; idefault_screen = 0; @@ -330,8 +329,8 @@ Display *XOpenDisplay(char *display_name) Window XCreateSimpleWindow(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, - unsigned int border_width, unsigned long border, - unsigned long background) + unsigned int border_width, unsigned int border, + unsigned int background) { video_bitmap = create_video_bitmap(XRES, YRES); clear_to_color(video_bitmap, background); @@ -379,11 +378,10 @@ Status XStringListToTextProperty(char **list, int count, void XFree(void *data) { - if (data) - free(data); + checked_free(data); } -GC XCreateGC(Display *display, Drawable d, unsigned long value_mask, +GC XCreateGC(Display *display, Drawable d, unsigned int value_mask, XGCValues *values) { XGCValues *gcv; @@ -442,7 +440,7 @@ Pixmap XCreatePixmap(Display *display, Drawable d, unsigned int width, BITMAP *bitmap = NULL; if (gfx_capabilities & GFX_HW_VRAM_BLIT && - width == gfx.scrollbuffer_width && height == gfx.scrollbuffer_height) + width == gfx.scrollbuffer_width && height == gfx.scrollbuffer_height) bitmap = create_video_bitmap(width, height); if (bitmap == NULL) @@ -502,12 +500,10 @@ static BITMAP *Image_to_AllegroBitmap(Image *image) byte *src_ptr = image->data; byte pixel_mapping[MAX_COLORS]; unsigned int depth = 8; - -#if 0 - int i, j, x, y; -#else int i, x, y; -#endif + + if (image->type == IMAGETYPE_TRUECOLOR && depth == 8) + Error(ERR_EXIT, "cannot handle true-color images on 8-bit display"); /* allocate new allegro bitmap structure */ if ((bitmap = create_bitmap_ex(depth, image->width, image->height)) == NULL) @@ -519,55 +515,19 @@ static BITMAP *Image_to_AllegroBitmap(Image *image) clear(bitmap); /* try to use existing colors from the global colormap */ - for (i=0; irgb.color_used[i]) continue; - -#if 0 - r = image->rgb.red[i] >> 10; - g = image->rgb.green[i] >> 10; - b = image->rgb.blue[i] >> 10; - - for (j=0; jrgb.red[i], - image->rgb.green[i], - image->rgb.blue[i]); -#endif - + pixel_mapping[i] = AllegroAllocColorCell(image->rgb.red[i], + image->rgb.green[i], + image->rgb.blue[i]); } /* copy bitmap data */ - for (y=0; yheight; y++) - for (x=0; xwidth; x++) + for (y = 0; y < image->height; y++) + for (x = 0; x < image->width; x++) putpixel(bitmap, x, y, pixel_mapping[*src_ptr++]); return bitmap; @@ -600,7 +560,10 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, return errno_pcx; *pixmap = (Pixmap)bitmap; - *pixmap_mask = (Pixmap)bitmap; + + /* pixmap_mask will never be used in Allegro (which uses masked_blit()), + so use non-NULL dummy pointer to empty Pixmap */ + *pixmap_mask = (Pixmap)DUMMY_MASK; return PCX_Success; } @@ -634,11 +597,9 @@ void XFreePixmap(Display *display, Pixmap pixmap) void XFreeGC(Display *display, GC gc) { - XGCValues *gcv; + XGCValues *gcv = (XGCValues *)gc; - gcv = (XGCValues *)gc; - if (gcv) - free(gcv); + checked_free(gcv); } void XUnmapWindow(Display *display, Window window) @@ -652,11 +613,8 @@ void XCloseDisplay(Display *display) if (is_screen_bitmap(bitmap)) destroy_bitmap(bitmap); - if (display->screens) - free(display->screens); - - if (display) - free(display); + checked_free(display->screens); + checked_free(display); /* return to text mode (or DOS box on Windows screen) */ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); @@ -707,7 +665,7 @@ static void HandleKeyboardRaw(int mode) { int i; - for (i=0; i= num_joysticks) + joystick_nr = -1; + + /* misuse joystick file descriptor variable to store joystick number */ + joystick.fd[i] = joystick_nr; + } +} + +boolean MSDOSReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) +{ + /* the allegro global variable 'num_joysticks' contains the number + of joysticks found at initialization under MS-DOS / Windows */ + + if (nr < 0 || nr >= num_joysticks) + return FALSE; + + poll_joystick(); + + if (x != NULL) + *x = joy[nr].stick[0].axis[0].pos; + if (y != NULL) + *y = joy[nr].stick[0].axis[1].pos; + + if (b1 != NULL) + *b1 = joy[nr].button[0].b; + if (b2 != NULL) + *b2 = joy[nr].button[1].b; + + return TRUE; +} + #endif /* PLATFORM_MSDOS */