From: Holger Schemel Date: Mon, 30 Nov 1998 00:52:51 +0000 (+0100) Subject: rnd-19981130-1 X-Git-Tag: 1.2.0^2~8 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=0a87fde47bcff35f196024766f8d0d00319a28d1;p=rocksndiamonds.git rnd-19981130-1 --- diff --git a/src/events.c b/src/events.c index 2ef8fd6d..8d1de10d 100644 --- a/src/events.c +++ b/src/events.c @@ -258,9 +258,11 @@ void HandleFocusEvent(XFocusChangeEvent *event) void HandleClientMessageEvent(XClientMessageEvent *event) { +#ifndef MSDOS if ((event->window == window) && (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) CloseAllAndExit(0); +#endif } void HandleButton(int mx, int my, int button) @@ -600,8 +602,10 @@ void HandleNoXEvent() return; } +#ifndef MSDOS if (options.network) HandleNetworking(); +#endif HandleJoystick(); diff --git a/src/game.c b/src/game.c index a2aea40a..8b5d2a79 100644 --- a/src/game.c +++ b/src/game.c @@ -238,9 +238,11 @@ void InitGame() network_player_action_received = FALSE; +#ifndef MSDOS /* initial null action */ if (network_playing) SendToServer_MovePlayer(MV_NO_MOVING); +#endif ZX = ZY = -1; @@ -3122,8 +3124,44 @@ void GameActions() action_delay_value = (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay); + /* + if (tape.playing && tape.fast_forward) + { + char buf[100]; + + sprintf(buf, "FFWD: %ld ms", action_delay_value); + print_debug(buf); + } + */ + + /* main game synchronization point */ + + + + +#if 1 WaitUntilDelayReached(&action_delay, action_delay_value); +#else + /* + while (!DelayReached(&action_delay, action_delay_value)); + */ + + while (!DelayReached(&action_delay, action_delay_value)) + { + char buf[100]; + + sprintf(buf, "%ld %ld %ld", + Counter(), action_delay, action_delay_value); + print_debug(buf); + } + print_debug("done"); + + +#endif + + + if (network_playing && !network_player_action_received) { @@ -3133,8 +3171,10 @@ void GameActions() #endif */ +#ifndef MSDOS /* last chance to get network player actions without main loop delay */ HandleNetworking(); +#endif if (game_status != PLAYING) return; @@ -3176,8 +3216,10 @@ void GameActions() stored_player[i].effective_action = stored_player[i].action; } +#ifndef MSDOS if (network_playing) SendToServer_MovePlayer(summarized_player_action); +#endif if (!options.network && !setup.team_mode) local_player->effective_action = summarized_player_action; diff --git a/src/image.c b/src/image.c index 3cc85e34..c2785a24 100644 --- a/src/image.c +++ b/src/image.c @@ -14,6 +14,9 @@ #include "image.h" #include "misc.h" +/* exclude all except newImage() and freeImage() */ +#ifndef MSDOS + /* extra colors to try allocating in private color maps to minimize flashing */ #define NOFLASH_COLORS 256 @@ -34,10 +37,10 @@ static Pixmap Image_to_Mask(Image *image, Display *display, Window window) { - unsigned char *src_ptr, *dst_ptr, *dst_ptr2; + byte *src_ptr, *dst_ptr, *dst_ptr2; unsigned int bytes_per_row; unsigned int x, y; - unsigned char bitmask; + byte bitmask; byte *mask_data; Pixmap mask_pixmap; @@ -463,6 +466,8 @@ void freeXImage(Image *image, XImageInfo *ximageinfo) free(ximageinfo); } +#endif /* !MSDOS */ + Image *newImage(unsigned int width, unsigned int height, unsigned int depth) { Image *image; @@ -491,8 +496,10 @@ void freeImage(Image *image) free(image); } -int Read_PCX_to_Pixmaps(Display *display, Window window, GC gc, char *filename, - Pixmap *pixmap, Pixmap *pixmap_mask) +#ifndef MSDOS + +int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, + Pixmap *pixmap, Pixmap *pixmap_mask) { Image *image; XImageInfo *ximageinfo; @@ -542,3 +549,5 @@ int Read_PCX_to_Pixmaps(Display *display, Window window, GC gc, char *filename, return(PCX_Success); } + +#endif /* !MSDOS */ diff --git a/src/image.h b/src/image.h index 5f96d592..ac046dd1 100644 --- a/src/image.h +++ b/src/image.h @@ -56,7 +56,7 @@ typedef struct #define PCX_NoMemory -4 #define PCX_ColorFailed -5 -int Read_PCX_to_Pixmaps(Display *, Window, GC, char *, Pixmap *, Pixmap *); +int Read_PCX_to_Pixmap(Display *, Window, GC, char *, Pixmap *, Pixmap *); Image *Read_PCX_to_Image(char *); Image *newImage(unsigned int, unsigned int, unsigned int); diff --git a/src/init.c b/src/init.c index b93f6432..ce89416c 100644 --- a/src/init.c +++ b/src/init.c @@ -72,10 +72,19 @@ void OpenAll(int argc, char *argv[]) InitDisplay(); InitWindow(argc, argv); + print_debug("now map window"); + XMapWindow(display, window); XFlush(display); + print_debug("window mapped"); + + print_debug("now init gfx"); + InitGfx(); + + print_debug("gfx initialized"); + InitElementProperties(); DrawMainMenu(); @@ -105,11 +114,14 @@ void InitLevelAndPlayerInfo() void InitNetworkServer() { +#ifndef MSDOS int nr_wanted; +#endif if (!options.network) return; +#ifndef MSDOS nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); if (!ConnectToServer(options.server_host, options.server_port)) @@ -120,6 +132,7 @@ void InitNetworkServer() if (nr_wanted) SendToServer_NrWanted(nr_wanted); +#endif } void InitSound() @@ -214,7 +227,9 @@ void InitSoundServer() void InitJoysticks() { +#ifndef MSDOS int i; +#endif if (global_joystick_status == JOYSTICK_OFF) return; @@ -257,8 +272,10 @@ void InitJoysticks() void InitDisplay() { +#ifndef MSDOS XVisualInfo vinfo_template, *vinfo; int num_visuals; +#endif unsigned int depth; /* connect to X server */ @@ -271,6 +288,7 @@ void InitDisplay() depth = DefaultDepth(display, screen); cmap = DefaultColormap(display, screen); +#ifndef MSDOS /* look for good enough visual */ vinfo_template.screen = screen; vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor); @@ -295,25 +313,28 @@ void InitDisplay() printf("Sorry, cannot get appropriate visual.\n"); exit(-1); } +#endif } void InitWindow(int argc, char *argv[]) { unsigned int border_width = 4; + XGCValues gc_values; + unsigned long gc_valuemask; +#ifndef MSDOS + XTextProperty windowName, iconName; Pixmap icon_pixmap, iconmask_pixmap; - unsigned int icon_width,icon_height; - int icon_hot_x,icon_hot_y; + unsigned int icon_width, icon_height; + int icon_hot_x, icon_hot_y; char icon_filename[256]; XSizeHints size_hints; XWMHints wm_hints; XClassHint class_hints; - XTextProperty windowName, iconName; - XGCValues gc_values; - unsigned long gc_valuemask; char *window_name = WINDOWTITLE_STRING; char *icon_name = WINDOWTITLE_STRING; long window_event_mask; Atom proto_atom = None, delete_atom = None; +#endif int screen_width, screen_height; int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS; unsigned long pen_fg = WhitePixel(display,screen); @@ -409,6 +430,10 @@ void InitWindow(int argc, char *argv[]) gc_values.background = pen_bg; gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; gc = XCreateGC(display, window, gc_valuemask, &gc_values); + + + + print_debug("OpenWindow finished"); } void DrawInitText(char *text, int ypos, int color) @@ -628,9 +653,19 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) char *picturemask_ext = "Mask.xbm"; #else int pcx_err; + +#if 1 char *picture_ext = ".pcx"; +#else + char *picture_ext = ".gif"; +#endif + #endif + + print_debug("now load pic:"); + + /* Grafik laden */ if (pic->picture_filename) { @@ -674,26 +709,46 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) #else /* !USE_XPM_LIBRARY */ - pcx_err = Read_PCX_to_Pixmaps(display, window, gc, filename, - &pix[pos], &clipmask[pos]); + + + print_debug(filename); + + + + pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename, + &pix[pos], &clipmask[pos]); + + + print_debug("ok-1"); + + switch(pcx_err) { case PCX_Success: + print_debug("Success"); break; case PCX_OpenFailed: + print_debug("OpenFailed"); Error(ERR_EXIT, "cannot open PCX file '%s'", filename); case PCX_ReadFailed: + print_debug("ReadFailed"); Error(ERR_EXIT, "cannot read PCX file '%s'", filename); case PCX_FileInvalid: + print_debug("FileInvalid"); Error(ERR_EXIT, "invalid PCX file '%s'", filename); case PCX_NoMemory: + print_debug("NoMemory"); Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename); case PCX_ColorFailed: + print_debug("ColorFailed"); Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename); default: + print_debug("default"); break; } + print_debug("ok-2"); + #if DEBUG_TIMING printf("SUMMARY LOADING PCX FILE %s:", filename); debug_print_timestamp(1, ""); @@ -701,8 +756,16 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) #endif /* !USE_XPM_LIBRARY */ + + print_debug("-> 1"); + + + if (!pix[pos]) Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename); + + + print_debug("-> 2"); } /* zugehörige Maske laden (wenn vorhanden) */ @@ -743,9 +806,16 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) #endif /* USE_XPM_LIBRARY */ + + if (!clipmask[pos]) + print_debug("Oops -- no clipmask"); + if (!clipmask[pos]) Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); } + + + print_debug("LoadGfx done"); } void InitElementProperties() diff --git a/src/joystick.c b/src/joystick.c index 5e1cc132..7240e88c 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -42,6 +42,7 @@ void CheckJoystickData() } } +#ifndef MSDOS static int JoystickPosition(int middle, int margin, int actual) { long range, pos; @@ -61,9 +62,11 @@ static int JoystickPosition(int middle, int margin, int actual) return percentage; } +#endif int Joystick(int player_nr) { +#ifndef MSDOS #ifdef __FreeBSD__ struct joystick joy_ctrl; #else @@ -73,12 +76,16 @@ int Joystick(int player_nr) int x; int y; } joy_ctrl; +#endif #endif int joystick_fd = stored_player[player_nr].joystick_fd; + +#ifndef MSDOS int js_x,js_y, js_b1,js_b2; int left, right, up, down; int result = 0; +#endif if (joystick_status == JOYSTICK_OFF) return 0; diff --git a/src/main.h b/src/main.h index 0dcb8b96..719be55b 100644 --- a/src/main.h +++ b/src/main.h @@ -48,8 +48,8 @@ typedef unsigned char boolean; typedef unsigned char byte; #ifndef FALSE -#define FALSE 0 -#define TRUE (!FALSE) +#define FALSE 0 +#define TRUE (!FALSE) #endif #define WIN_XSIZE 672 diff --git a/src/misc.c b/src/misc.c index 5da20e36..19c90ac5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -27,9 +27,24 @@ #include "random.h" #include "joystick.h" + +#ifdef MSDOS +volatile unsigned long counter = 0; + +void increment_counter() +{ + counter++; +} + +END_OF_FUNCTION(increment_counter); +#endif + + + /* maximal allowed length of a command line option */ #define MAX_OPTION_LEN 256 +#ifndef MSDOS static unsigned long mainCounter(int mode) { static struct timeval base_time = { 0, 0 }; @@ -46,20 +61,39 @@ static unsigned long mainCounter(int mode) return counter_ms; /* return milliseconds since last init */ } +#endif void InitCounter() /* set counter back to zero */ { +#ifndef MSDOS mainCounter(INIT_COUNTER); +#else + LOCK_VARIABLE(counter); + LOCK_FUNCTION(increment_counter); + install_int_ex(increment_counter, BPS_TO_TIMER(100)); +#endif } unsigned long Counter() /* get milliseconds since last call of InitCounter() */ { - return(mainCounter(READ_COUNTER)); +#ifndef MSDOS + return mainCounter(READ_COUNTER); +#else + return (counter * 10); +#endif } static void sleep_milliseconds(unsigned long milliseconds_delay) { - if (milliseconds_delay < 5) + boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE); + +#ifdef MSDOS + /* donït use select() to perform waiting operations under DOS/Windows + environment; always use a busy loop for waiting instead */ + do_busy_waiting = TRUE; +#endif + + if (do_busy_waiting) { /* we want to wait only a few ms -- if we assume that we have a kernel timer resolution of 10 ms, we would wait far to long; @@ -209,6 +243,7 @@ char *getLoginName() char *getHomeDir() { +#ifndef MSDOS static char *home_dir = NULL; if (!home_dir) @@ -225,6 +260,9 @@ char *getHomeDir() } return home_dir; +#else + return "."; +#endif } char *getPath2(char *path1, char *path2) @@ -418,7 +456,6 @@ void GetOptions(char *argv[]) void Error(int mode, char *format, ...) { - FILE *output_stream = stderr; char *process_name = ""; if (mode & ERR_SOUND_SERVER) @@ -432,26 +469,30 @@ void Error(int mode, char *format, ...) { va_list ap; - fprintf(output_stream, "%s%s: ", program_name, process_name); + fprintf(stderr, "%s%s: ", program_name, process_name); if (mode & ERR_WARN) - fprintf(output_stream, "warning: "); + fprintf(stderr, "warning: "); va_start(ap, format); - vfprintf(output_stream, format, ap); + vfprintf(stderr, format, ap); va_end(ap); - fprintf(output_stream, "\n"); + fprintf(stderr, "\n"); } if (mode & ERR_HELP) - fprintf(output_stream, "%s: Try option '--help' for more information.\n", + fprintf(stderr, "%s: Try option '--help' for more information.\n", program_name); if (mode & ERR_EXIT) { - fprintf(output_stream, "%s%s: aborting\n", program_name, process_name); - CloseAllAndExit(1); + fprintf(stderr, "%s%s: aborting\n", program_name, process_name); + + if (mode & ERR_FROM_SERVER) + exit(1); /* child process: normal exit */ + else + CloseAllAndExit(1); /* main process: clean up stuff */ } } @@ -826,3 +867,28 @@ void debug_print_timestamp(int counter_nr, char *message) counter[counter_nr][1] = Counter(); } + +void print_debug(char *s) +{ + FILE *f; + + if (!s) + { + if ((f = fopen("debug.asc", "w")) == NULL) + { + printf("Cannot write to debug file!\n"); + exit(1); + } + fclose(f); + return; + } + + if ((f = fopen("debug.asc", "a")) == NULL) + { + printf("Cannot append to debug file!\n"); + exit(1); + } + + fprintf(f, "%s\r\n", s); + fclose(f); +} diff --git a/src/misc.h b/src/misc.h index f48bf346..1477f85d 100644 --- a/src/misc.h +++ b/src/misc.h @@ -28,6 +28,7 @@ #define ERR_SOUND_SERVER (1 << 3) #define ERR_NETWORK_SERVER (1 << 4) #define ERR_NETWORK_CLIENT (1 << 5) +#define ERR_FROM_SERVER (ERR_SOUND_SERVER | ERR_NETWORK_SERVER) #define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP) #define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER) #define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER) @@ -61,4 +62,6 @@ char *getJoyNameFromJoySymbol(int); int getJoySymbolFromJoyName(char *); void debug_print_timestamp(int, char *); +void print_debug(char *); + #endif /* MISC_H */ diff --git a/src/msdos.c b/src/msdos.c new file mode 100644 index 00000000..f1dcfa47 --- /dev/null +++ b/src/msdos.c @@ -0,0 +1,772 @@ +/*********************************************************** +* Rocks'n'Diamonds -- McDuffin Strikes Back! * +*----------------------------------------------------------* +* ©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 * +*----------------------------------------------------------* +* msdos.c * +***********************************************************/ + +#ifdef MSDOS + +#include "main.h" +#include "tools.h" +#include "sound.h" +#include "files.h" +#include "joystick.h" +#include "image.h" + +DECLARE_GFX_DRIVER_LIST(GFX_DRIVER_VBEAF GFX_DRIVER_VESA2L GFX_DRIVER_VESA1) +DECLARE_COLOR_DEPTH_LIST(COLOR_DEPTH_8) +DECLARE_DIGI_DRIVER_LIST(DIGI_DRIVER_SB) +DECLARE_MIDI_DRIVER_LIST() +DECLARE_JOYSTICK_DRIVER_LIST(JOYSTICK_DRIVER_STANDARD) + +static int key_buffer[OSD_MAX_KEY]; +static XEvent event_buffer[MAX_EVENT_BUFFER]; +static int pending_events; +static boolean joystick_event; +static boolean mouse_installed = FALSE; +static int last_mouse_pos; +static int last_mouse_b; +static int last_joystick_state; +static BITMAP* video_bitmap; + +static RGB global_colormap[MAX_COLORS]; +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_drivers() +{ + int i; + + for (i=0; i 0) + mouse_installed = TRUE; + install_joystick(JOY_TYPE_2PADS); + + load_joystick_data(JOYSTICK_FILENAME); + last_joystick_state = 0; + joystick_event = FALSE; + + reserve_voices(MAX_SOUNDS_PLAYING, 0); + if (install_sound(DIGI_AUTODETECT, MIDI_NONE, "ROCKS.SND") == -1) + if (install_sound(DIGI_SB, MIDI_NONE, NULL) == -1) + sound_status = SOUND_OFF; +} + +static boolean hide_mouse(Display *display, int x, int y, + unsigned int width, unsigned int height) +{ + if (mouse_x + display->mouse_ptr->w < x || mouse_x > x + width) + return FALSE; + if (mouse_y + display->mouse_ptr->h < y || mouse_y > y + height) + return FALSE; + + show_mouse(NULL); + + return TRUE; +} + +static void unhide_mouse(Display *display) +{ + if (mouse_installed) + show_mouse(video_bitmap); +} + +static int get_joystick_state() +{ + int state = 0; + + /*!!!*/ + int joystick_nr = 0; /* CHANGE THIS! */ + /*!!!*/ + + poll_joystick(); + + if (joy[joystick_nr].stick[0].axis[0].d1) + state |= JOY_LEFT; + if (joy[joystick_nr].stick[0].axis[0].d2) + state |= JOY_RIGHT; + if (joy[joystick_nr].stick[0].axis[1].d1) + state |= JOY_UP; + if (joy[joystick_nr].stick[0].axis[1].d2) + state |= JOY_DOWN; + if (joy[joystick_nr].button[0].b) + state |= JOY_BUTTON_1; + + switch (state) + { + case (JOY_DOWN | JOY_LEFT): + state = XK_KP_1; + break; + case (JOY_DOWN): + state = XK_KP_2; + break; + case (JOY_DOWN | JOY_RIGHT): + state = XK_KP_3; + break; + case (JOY_LEFT): + state = XK_KP_4; + break; + case (JOY_RIGHT): + state = XK_KP_6; + break; + case (JOY_UP | JOY_LEFT): + state = XK_KP_7; + break; + case (JOY_UP): + state = XK_KP_8; + break; + case (JOY_UP | JOY_RIGHT): + state = XK_KP_9; + break; + + case (JOY_DOWN | JOY_BUTTON_1): + state = XK_X; + break; + case (JOY_LEFT | JOY_BUTTON_1): + state = XK_S; + break; + case (JOY_RIGHT | JOY_BUTTON_1): + state = XK_D; + break; + case (JOY_UP | JOY_BUTTON_1): + state = XK_E; + break; + + default: + state = 0; + } + + return state; +} + +unsigned char get_ascii(KeySym key) +{ + switch(key) + { + case OSD_KEY_Q: return 'Q'; + case OSD_KEY_W: return 'W'; + case OSD_KEY_E: return 'E'; + case OSD_KEY_R: return 'R'; + case OSD_KEY_T: return 'T'; + case OSD_KEY_Y: return 'Y'; + case OSD_KEY_U: return 'U'; + case OSD_KEY_I: return 'I'; + case OSD_KEY_O: return 'O'; + case OSD_KEY_P: return 'P'; + case OSD_KEY_A: return 'A'; + case OSD_KEY_S: return 'S'; + case OSD_KEY_D: return 'D'; + case OSD_KEY_F: return 'F'; + case OSD_KEY_G: return 'G'; + case OSD_KEY_H: return 'H'; + case OSD_KEY_J: return 'J'; + case OSD_KEY_K: return 'K'; + case OSD_KEY_L: return 'L'; + case OSD_KEY_Z: return 'Z'; + case OSD_KEY_X: return 'X'; + case OSD_KEY_C: return 'C'; + case OSD_KEY_V: return 'V'; + case OSD_KEY_B: return 'B'; + case OSD_KEY_N: return 'N'; + case OSD_KEY_M: return 'M'; + case OSD_KEY_1: return '1'; + case OSD_KEY_2: return '2'; + case OSD_KEY_3: return '3'; + case OSD_KEY_4: return '4'; + case OSD_KEY_5: return '5'; + case OSD_KEY_6: return '6'; + case OSD_KEY_7: return '7'; + case OSD_KEY_8: return '8'; + case OSD_KEY_9: return '9'; + case OSD_KEY_0: return '0'; + case OSD_KEY_SPACE: return ' '; + } + + return 0; +} + +static long osd_key_pressed(int keycode) +{ + if (keycode == OSD_KEY_RCONTROL) + keycode = KEY_RCONTROL; + if (keycode == OSD_KEY_ALTGR) + keycode = KEY_ALTGR; + + if (key[keycode]) + return KeyPressMask; + else + return KeyReleaseMask; +} + +void XMapWindow(Display *display, Window window) +{ + int x, y; + unsigned int width, height; + boolean mouse_off; + + x = display->screens[display->default_screen].x; + y = display->screens[display->default_screen].y; + width = display->screens[display->default_screen].width; + height = display->screens[display->default_screen].height; + + mouse_off = hide_mouse(display, x, y, width, height); + blit((BITMAP *)window, video_bitmap, 0, 0, x, y, width, height); + + if (mouse_off) + unhide_mouse(display); +} + +Display *XOpenDisplay(char *display_name) +{ + Screen *screen; + Display *display; + BITMAP *mouse_bitmap = NULL; + + screen = malloc(sizeof(Screen)); + display = malloc(sizeof(Display)); + + if ((mouse_bitmap = Read_PCX_to_AllegroBitmap(MOUSE_PCX_FILENAME)) == NULL) + return NULL; + + screen[0].cmap = 0; + screen[0].root = 0; + screen[0].white_pixel = 0xFF; + screen[0].black_pixel = 0x00; + screen[0].video_bitmap = NULL; + + display->default_screen = 0; + display->screens = screen; + display->mouse_ptr = mouse_bitmap; + + allegro_init(); + allegro_drivers(); + set_color_depth(8); + + /* force Windows 95 to switch to fullscreen mode */ + set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0); + rest(200); + set_gfx_mode(GFX_AUTODETECT, XRES, YRES, 0, 0); + + return display; +} + +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) +{ + video_bitmap = create_video_bitmap(XRES, YRES); + clear_to_color(video_bitmap, background); + + display->screens[display->default_screen].video_bitmap = video_bitmap; + display->screens[display->default_screen].x = x; + display->screens[display->default_screen].y = y; + display->screens[display->default_screen].width = XRES; + display->screens[display->default_screen].height = YRES; + + set_mouse_sprite(display->mouse_ptr); + set_mouse_range(display->screens[display->default_screen].x + 1, + display->screens[display->default_screen].y + 1, + display->screens[display->default_screen].x + WIN_XSIZE + 1, + display->screens[display->default_screen].y + WIN_YSIZE + 1); + + show_video_bitmap(video_bitmap); + + return (Window)video_bitmap; +} + +Status XStringListToTextProperty(char **list, int count, + XTextProperty *text_prop_return) +{ + char *string; + + if (count >= 1) + { + string = malloc(strlen(list[0] + 1)); + strcpy(string, list[0]); + text_prop_return->value = (unsigned char *)string; + return 1; + } + else + text_prop_return = NULL; + + return 0; +} + +void XFree(void *data) +{ + if (data) + free(data); +} + +GC XCreateGC(Display *display, Drawable d, unsigned long value_mask, + XGCValues *values) +{ + XGCValues *gcv; + gcv = malloc(sizeof(XGCValues)); + gcv->foreground = values->foreground; + gcv->background = values->background; + gcv->graphics_exposures = values->graphics_exposures; + gcv->clip_mask = values->clip_mask; + gcv->clip_x_origin = values->clip_x_origin; + gcv->clip_y_origin = values->clip_y_origin; + gcv->value_mask = value_mask; + return (GC)gcv; +} + +void XSetClipMask(Display *display, GC gc, Pixmap pixmap) +{ + XGCValues *gcv = (XGCValues *)gc; + + gcv->clip_mask = pixmap; + gcv->value_mask |= GCClipMask; +} + +void XSetClipOrigin(Display *display, GC gc, int x, int y) +{ + XGCValues *gcv = (XGCValues *)gc; + + gcv->clip_x_origin = x; + gcv->clip_x_origin = y; +} + +void XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, + unsigned int width, unsigned int height) +{ + boolean mouse_off = FALSE; + + if ((BITMAP *)d == video_bitmap) + { + x += display->screens[display->default_screen].x; + y += display->screens[display->default_screen].y; + freeze_mouse_flag = TRUE; + mouse_off = hide_mouse(display, x, y, width, height); + } + + rectfill((BITMAP *)d, x, y, x + width, y + height, + ((XGCValues *)gc)->foreground); + + if (mouse_off) + unhide_mouse(display); + + freeze_mouse_flag = FALSE; +} + +Pixmap XCreatePixmap(Display *display, Drawable d, unsigned int width, + unsigned int height, unsigned int depth) +{ + BITMAP *bitmap = NULL; + + if (gfx_capabilities & GFX_HW_VRAM_BLIT && + width == FXSIZE && height == FYSIZE) + bitmap = create_video_bitmap(width, height); + + if (bitmap == NULL) + bitmap = create_bitmap(width, height); + + return (Pixmap)bitmap; +} + +void XSync(Display *display, Bool discard_events) +{ + wait_for_vsync = TRUE; +} + +inline void XCopyArea(Display *display, Drawable src, Drawable dest, GC gc, + int src_x, int src_y, + unsigned int width, unsigned int height, + int dest_x, int dest_y) +{ + boolean mouse_off = FALSE; + + if ((BITMAP *)src == video_bitmap) + { + src_x += display->screens[display->default_screen].x; + src_y += display->screens[display->default_screen].y; + } + + if ((BITMAP *)dest == video_bitmap) + { + dest_x += display->screens[display->default_screen].x; + dest_y += display->screens[display->default_screen].y; + freeze_mouse_flag = TRUE; + mouse_off = hide_mouse(display, dest_x, dest_y, width, height); + } + + if (wait_for_vsync) + { + wait_for_vsync = FALSE; + vsync(); + } + + if (((XGCValues *)gc)->value_mask & GCClipMask) + masked_blit((BITMAP *)src, (BITMAP *)dest, src_x, src_y, dest_x, dest_y, + width, height); + else + blit((BITMAP *)src, (BITMAP *)dest, src_x, src_y, dest_x, dest_y, + width, height); + + if (mouse_off) + unhide_mouse(display); + + freeze_mouse_flag = FALSE; +} + +static BITMAP *Image_to_AllegroBitmap(Image *image) +{ + BITMAP *bitmap; + byte *src_ptr = image->data; + byte pixel_mapping[MAX_COLORS]; + unsigned int depth = 8; + int i, j, x, y; + + /* allocate new allegro bitmap structure */ + if ((bitmap = create_bitmap_ex(depth, image->width, image->height)) == NULL) + return NULL; + + clear(bitmap); + + /* try to use existing colors from the global colormap */ + for (i=0; irgb.color_used[i]) + continue; + + r = image->rgb.red[i] >> 10; + g = image->rgb.green[i] >> 10; + b = image->rgb.blue[i] >> 10; + + for (j=0; jheight; y++) + for (x=0; xwidth; x++) + putpixel(bitmap, x, y, pixel_mapping[*src_ptr++]); + + return bitmap; +} + +static BITMAP *Read_PCX_to_AllegroBitmap(char *filename) +{ + BITMAP *bitmap; + Image *image; + + /* read the graphic file in PCX format to internal image structure */ + if ((image = Read_PCX_to_Image(filename)) == NULL) + return NULL; + + /* convert internal image structure to allegro bitmap structure */ + if ((bitmap = Image_to_AllegroBitmap(image)) == NULL) + return NULL; + + set_pallete(global_colormap); + + return bitmap; +} + +int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, + Pixmap *pixmap, Pixmap *pixmap_mask) +{ + BITMAP *bitmap; + + if ((bitmap = Read_PCX_to_AllegroBitmap(filename)) == NULL) + return PCX_FileInvalid; + + *pixmap = (Pixmap)bitmap; + *pixmap_mask = (Pixmap)bitmap; + + return PCX_Success; +} + +int XpmReadFileToPixmap(Display *display, Drawable d, char *filename, + Pixmap *pixmap_return, Pixmap *shapemask_return, + XpmAttributes *attributes) +{ + BITMAP *bitmap; + + if ((bitmap = Read_PCX_to_AllegroBitmap(filename)) == NULL) + return XpmOpenFailed; + + *pixmap_return = (Pixmap)bitmap; + + return XpmSuccess; +} + +int XReadBitmapFile(Display *display, Drawable d, char *filename, + unsigned int *width_return, unsigned int *height_return, + Pixmap *bitmap_return, + int *x_hot_return, int *y_hot_return) +{ + BITMAP *bitmap; + + if ((bitmap = Read_PCX_to_AllegroBitmap(filename)) == NULL) + return BitmapOpenFailed; + + *width_return = bitmap->w; + *height_return = bitmap->h; + *x_hot_return = -1; + *y_hot_return = -1; + *bitmap_return = (Pixmap)bitmap; + + return BitmapSuccess; +} + +void XFreePixmap(Display *display, Pixmap pixmap) +{ + if (pixmap != DUMMY_MASK && + (is_memory_bitmap((BITMAP *)pixmap) || + is_screen_bitmap((BITMAP *)pixmap))) + destroy_bitmap((BITMAP *)pixmap); +} + +void XFreeGC(Display *display, GC gc) +{ + XGCValues *gcv; + + gcv = (XGCValues *)gc; + if (gcv) + free(gcv); +} + +void XCloseDisplay(Display *display) +{ + BITMAP *bitmap = video_bitmap; + + if (is_screen_bitmap(bitmap)) + destroy_bitmap(bitmap); + if (display->screens) + free(display->screens); + if (display) + free(display); +} + +void XNextEvent(Display *display, XEvent *event_return) +{ + while (!pending_events) + XPending(display); + + memcpy(event_return, &event_buffer[pending_events], sizeof(XEvent)); + pending_events--; +} + +int XPending(Display *display) +{ + int i, state; + static boolean joy_button_2 = FALSE; + + /*!!!*/ + int joystick_nr = 0; /* CHANGE THIS! */ + /*!!!*/ + + XKeyEvent *xkey; + XButtonEvent *xbutton; + XMotionEvent *xmotion; + + /* joystick event (simulating keyboard event) */ + + state = get_joystick_state(); + + if (joy[joystick_nr].button[1].b && !joy_button_2) + { + pending_events++; + xkey = (XKeyEvent *)&event_buffer[pending_events]; + xkey->type = KeyPress; + xkey->state = XK_B; + joy_button_2 = TRUE; + } + else if (!joy[joystick_nr].button[1].b && joy_button_2) + { + pending_events++; + xkey = (XKeyEvent *)&event_buffer[pending_events]; + xkey->type = KeyRelease; + xkey->state = XK_B; + joy_button_2 = FALSE; + } + + if (state && !joystick_event) + { + pending_events++; + xkey = (XKeyEvent *)&event_buffer[pending_events]; + xkey->type = KeyPress; + xkey->state = state; + joystick_event = TRUE; + last_joystick_state = state; + } + else if ((state != last_joystick_state) && joystick_event) + { + pending_events++; + xkey = (XKeyEvent *)&event_buffer[pending_events]; + xkey->type = KeyRelease; + xkey->state = last_joystick_state; + joystick_event = FALSE; + } + + /* keyboard event */ + + for(i=0; itype = (state & KeyPressMask ? KeyPress : KeyRelease); + xkey->state = i; + } + } + + /* mouse motion event */ + + if (mouse_pos != last_mouse_pos && mouse_b != last_mouse_b) + { + last_mouse_pos = mouse_pos; + pending_events++; + xmotion = (XMotionEvent *)&event_buffer[pending_events]; + xmotion->type = MotionNotify; + xmotion->x = mouse_x - display->screens[display->default_screen].x; + xmotion->y = mouse_y - display->screens[display->default_screen].y; + + + /* + return; + */ + + } + + /* mouse button event */ + + if (mouse_b != last_mouse_b) + { + for(i=1; i<4; i<<=1) + { + if ((last_mouse_b & i) != (mouse_b & i)) + { + pending_events++; + xbutton = (XButtonEvent *)&event_buffer[pending_events]; + xbutton->type = (mouse_b & i ? ButtonPress : ButtonRelease); + xbutton->button = i; + xbutton->x = mouse_x - display->screens[display->default_screen].x; + xbutton->y = mouse_y - display->screens[display->default_screen].y; + } + } + last_mouse_b = mouse_b; + } + + return pending_events; +} + +KeySym XLookupKeysym(XKeyEvent *key_event, int index) +{ + return key_event->state; +} + +void sound_handler(struct SoundControl snd_ctrl) +{ + int i; + + if (snd_ctrl.fade_sound) + { + if (!playing_sounds) + return; + + for(i=0; i +#include + +#define XRES 800 +#define YRES 600 + +/* Allegro keyboard mapping */ + +#define OSD_KEY_ESC 1 /* keyboard scan codes */ +#define OSD_KEY_1 2 /* (courtesy of allegro.h) */ +#define OSD_KEY_2 3 +#define OSD_KEY_3 4 +#define OSD_KEY_4 5 +#define OSD_KEY_5 6 +#define OSD_KEY_6 7 +#define OSD_KEY_7 8 +#define OSD_KEY_8 9 +#define OSD_KEY_9 10 +#define OSD_KEY_0 11 +#define OSD_KEY_MINUS 12 +#define OSD_KEY_EQUALS 13 +#define OSD_KEY_BACKSPACE 14 +#define OSD_KEY_TAB 15 +#define OSD_KEY_Q 16 +#define OSD_KEY_W 17 +#define OSD_KEY_E 18 +#define OSD_KEY_R 19 +#define OSD_KEY_T 20 +#define OSD_KEY_Y 21 +#define OSD_KEY_U 22 +#define OSD_KEY_I 23 +#define OSD_KEY_O 24 +#define OSD_KEY_P 25 +#define OSD_KEY_OPENBRACE 26 +#define OSD_KEY_CLOSEBRACE 27 +#define OSD_KEY_ENTER 28 +#define OSD_KEY_LCONTROL 29 +#define OSD_KEY_A 30 +#define OSD_KEY_S 31 +#define OSD_KEY_D 32 +#define OSD_KEY_F 33 +#define OSD_KEY_G 34 +#define OSD_KEY_H 35 +#define OSD_KEY_J 36 +#define OSD_KEY_K 37 +#define OSD_KEY_L 38 +#define OSD_KEY_COLON 39 +#define OSD_KEY_QUOTE 40 +#define OSD_KEY_TILDE 41 +#define OSD_KEY_LSHIFT 42 +/* 43 */ +#define OSD_KEY_Z 44 +#define OSD_KEY_X 45 +#define OSD_KEY_C 46 +#define OSD_KEY_V 47 +#define OSD_KEY_B 48 +#define OSD_KEY_N 49 +#define OSD_KEY_M 50 +#define OSD_KEY_COMMA 51 +#define OSD_KEY_STOP 52 +#define OSD_KEY_SLASH 53 +#define OSD_KEY_RSHIFT 54 +#define OSD_KEY_ASTERISK 55 +#define OSD_KEY_ALT 56 +#define OSD_KEY_SPACE 57 +#define OSD_KEY_CAPSLOCK 58 +#define OSD_KEY_F1 59 +#define OSD_KEY_F2 60 +#define OSD_KEY_F3 61 +#define OSD_KEY_F4 62 +#define OSD_KEY_F5 63 +#define OSD_KEY_F6 64 +#define OSD_KEY_F7 65 +#define OSD_KEY_F8 66 +#define OSD_KEY_F9 67 +#define OSD_KEY_F10 68 +#define OSD_KEY_NUMLOCK 69 +#define OSD_KEY_SCRLOCK 70 +#define OSD_KEY_HOME 71 +#define OSD_KEY_UP 72 +#define OSD_KEY_PGUP 73 +#define OSD_KEY_MINUS_PAD 74 +#define OSD_KEY_LEFT 75 +#define OSD_KEY_5_PAD 76 +#define OSD_KEY_RIGHT 77 +#define OSD_KEY_PLUS_PAD 78 +#define OSD_KEY_END 79 +#define OSD_KEY_DOWN 80 +#define OSD_KEY_PGDN 81 +#define OSD_KEY_INSERT 82 +#define OSD_KEY_DEL 83 +#define OSD_KEY_RCONTROL 84 /* different from Allegro */ +#define OSD_KEY_ALTGR 85 /* different from Allegro */ +/* 86 */ +#define OSD_KEY_F11 87 +#define OSD_KEY_F12 88 +#define OSD_KEY_COMMAND 89 +#define OSD_KEY_OPTION 90 +/* 91 - 100 */ +/* The following are all undefined in Allegro */ +#define OSD_KEY_1_PAD 101 +#define OSD_KEY_2_PAD 102 +#define OSD_KEY_3_PAD 103 +#define OSD_KEY_4_PAD 104 +/* 105 */ +#define OSD_KEY_6_PAD 106 +#define OSD_KEY_7_PAD 107 +#define OSD_KEY_8_PAD 108 +#define OSD_KEY_9_PAD 109 +#define OSD_KEY_0_PAD 110 +#define OSD_KEY_STOP_PAD 111 +#define OSD_KEY_EQUALS_PAD 112 +#define OSD_KEY_SLASH_PAD 113 +#define OSD_KEY_ASTER_PAD 114 +#define OSD_KEY_ENTER_PAD 115 + +#define OSD_MAX_KEY 115 + +/* X11 keyboard mapping */ + +#define XK_KP_Enter OSD_KEY_ENTER_PAD +#define XK_KP_0 OSD_KEY_0_PAD +#define XK_KP_1 OSD_KEY_1_PAD +#define XK_KP_2 OSD_KEY_2_PAD +#define XK_KP_3 OSD_KEY_3_PAD +#define XK_KP_4 OSD_KEY_4_PAD +#define XK_KP_6 OSD_KEY_6_PAD +#define XK_KP_7 OSD_KEY_7_PAD +#define XK_KP_8 OSD_KEY_8_PAD +#define XK_KP_9 OSD_KEY_9_PAD +/* +#define XK_KP_Home OSD_KEY_7_PAD +#define XK_KP_Page_Up OSD_KEY_9_PAD +#define XK_KP_Page_Down OSD_KEY_3_PAD +#define XK_KP_End OSD_KEY_1_PAD +#define XK_KP_Left OSD_KEY_4_PAD +#define XK_KP_Up OSD_KEY_8_PAD +#define XK_KP_Right OSD_KEY_6_PAD +#define XK_KP_Down OSD_KEY_2_PAD +*/ +#define XK_0 OSD_KEY_1 +#define XK_1 OSD_KEY_2 +#define XK_2 OSD_KEY_3 +#define XK_3 OSD_KEY_4 +#define XK_4 OSD_KEY_5 +#define XK_5 OSD_KEY_6 +#define XK_6 OSD_KEY_7 +#define XK_7 OSD_KEY_8 +#define XK_8 OSD_KEY_9 +#define XK_9 OSD_KEY_0 +#define XK_A OSD_KEY_A +#define XK_B OSD_KEY_B +#define XK_C OSD_KEY_C +#define XK_D OSD_KEY_D +#define XK_E OSD_KEY_E +#define XK_F OSD_KEY_F +#define XK_G OSD_KEY_G +#define XK_H OSD_KEY_H +#define XK_I OSD_KEY_I +#define XK_J OSD_KEY_J +#define XK_K OSD_KEY_K +#define XK_L OSD_KEY_L +#define XK_M OSD_KEY_M +#define XK_N OSD_KEY_N +#define XK_O OSD_KEY_O +#define XK_P OSD_KEY_P +#define XK_Q OSD_KEY_Q +#define XK_R OSD_KEY_R +#define XK_S OSD_KEY_S +#define XK_T OSD_KEY_T +#define XK_U OSD_KEY_U +#define XK_V OSD_KEY_V +#define XK_W OSD_KEY_W +#define XK_X OSD_KEY_X +#define XK_Y OSD_KEY_Y +#define XK_Z OSD_KEY_Z +#define XK_a OSD_KEY_A +#define XK_b OSD_KEY_B +#define XK_c OSD_KEY_C +#define XK_d OSD_KEY_D +#define XK_e OSD_KEY_E +#define XK_f OSD_KEY_F +#define XK_g OSD_KEY_G +#define XK_h OSD_KEY_H +#define XK_i OSD_KEY_I +#define XK_j OSD_KEY_J +#define XK_k OSD_KEY_K +#define XK_l OSD_KEY_L +#define XK_m OSD_KEY_M +#define XK_n OSD_KEY_N +#define XK_o OSD_KEY_O +#define XK_p OSD_KEY_P +#define XK_q OSD_KEY_Q +#define XK_r OSD_KEY_R +#define XK_s OSD_KEY_S +#define XK_t OSD_KEY_T +#define XK_u OSD_KEY_U +#define XK_v OSD_KEY_V +#define XK_w OSD_KEY_W +#define XK_x OSD_KEY_X +#define XK_y OSD_KEY_Y +#define XK_z OSD_KEY_Z +#define XK_Return OSD_KEY_ENTER +#define XK_Escape OSD_KEY_ESC +#define XK_Shift_L OSD_KEY_LSHIFT +#define XK_Shift_R OSD_KEY_RSHIFT +#define XK_Left OSD_KEY_LEFT +#define XK_Up OSD_KEY_UP +#define XK_Right OSD_KEY_RIGHT +#define XK_Down OSD_KEY_DOWN +#define XK_BackSpace OSD_KEY_BACKSPACE +#define XK_Delete OSD_KEY_DEL +#define XK_Space OSD_KEY_SPACE +#define XK_F12 OSD_KEY_F12 +#define XK_F11 OSD_KEY_F11 +#define XK_F10 OSD_KEY_F10 + + +/*!!!*/ +#define XK_KP_Add OSD_KEY_PLUS_PAD +#define XK_KP_Subtract OSD_KEY_MINUS_PAD +#define XK_KP_Multiply OSD_KEY_ASTER_PAD +#define XK_KP_Divide OSD_KEY_SLASH_PAD +#define XK_KP_Separator OSD_KEY_STOP_PAD +#define XK_Control_L OSD_KEY_LCONTROL +#define XK_Control_R OSD_KEY_RCONTROL +#define XK_Meta_L OSD_KEY_ALT +#define XK_Meta_R OSD_KEY_ALTGR +#define XK_Alt_L OSD_KEY_ALT +#define XK_Alt_R OSD_KEY_ALTGR +#define XK_Mode_switch 0 /* unknown in allegro */ +#define XK_Multi_key 0 /* unknown in allegro */ +#define XK_Insert OSD_KEY_INSERT +#define XK_Tab OSD_KEY_TAB +#define XK_Home OSD_KEY_HOME +#define XK_End OSD_KEY_END +#define XK_Page_Up OSD_KEY_PGUP +#define XK_Page_Down OSD_KEY_PGDN +#define XK_space OSD_KEY_SPACE +#define XK_adiaeresis 0 /* unknown in allegro */ +#define XK_odiaeresis 0 /* unknown in allegro */ +#define XK_udiaeresis 0 /* unknown in allegro */ +#define XK_apostrophe 0 /* unknown in allegro */ +#define XK_plus 0 /* unknown in allegro */ +#define XK_minus OSD_KEY_MINUS +#define XK_comma OSD_KEY_COMMA +#define XK_period OSD_KEY_STOP +#define XK_numbersign 0 /* unknown in allegro */ +#define XK_less 0 /* unknown in allegro */ +#define XK_greater 0 /* unknown in allegro */ +#define XK_asciicircum 0 /* unknown in allegro */ +#define XK_ssharp 0 /* unknown in allegro */ +#define XK_F1 0 /* unknown in allegro */ +#define XK_F24 0 /* unknown in allegro */ +#define XK_VoidSymbol 0 /* unknown in allegro */ +/*!!!*/ + + +#define MOUSE_GIF_FILENAME "graphics\\mouse.gif" +#define MOUSE_PCX_FILENAME "graphics\\mouse.gif" +#define JOYSTICK_FILENAME "joystick.cnf" +#define screen myscreen + +#define XFlush(a) +#define XGetImage(a,b,c,d,e,f,g,h) ((XImage *) NULL) +#define XAutoRepeatOn(a) +#define XAutoRepeatOff(a) +#define XDisplayName(a) ((char *) NULL) +#define XFreeColors(a,b,c,d,e) +#define XpmFreeAttributes(a) +#define XSelectInput(a,b,c) +#define XDefaultDepth(a,b) (8) +#define XSetWMProperties(a,b,c,d,e,f,g,h,i) + +#define MAX_EVENT_BUFFER 256 + +#define True 1 +#define False 0 +#define None 0L + +#define DUMMY_FILE ((void *) -1) +#define DUMMY_MASK (-1) + +#define KeyPressMask (1L << 0) +#define KeyReleaseMask (1L << 1) +#define ButtonPressMask (1L << 2) +#define ButtonReleaseMask (1L << 3) +#define ButtonMotionMask (1L << 13) +#define ExposureMask (1L << 15) +#define StructureNotifyMask (1L << 17) +#define FocusChangeMask (1L << 21) + +#define KeyPress 2 +#define KeyRelease 3 +#define ButtonPress 4 +#define ButtonRelease 5 +#define MotionNotify 6 +#define FocusIn 9 +#define FocusOut 10 +#define Expose 12 +#define UnmapNotify 18 +#define MapNotify 19 +#define ClientMessage 33 + +#define GCForeground (1L << 2) +#define GCBackground (1L << 3) +#define GCGraphicsExposures (1L << 16) +#define GCClipMask (1L << 19) + +#define NormalState 1 /* most applications want to start this way */ +#define InputHint (1L << 0) +#define StateHint (1L << 1) +#define IconPixmapHint (1L << 2) +#define IconMaskHint (1L << 5) +#define PSize (1L << 3) /* program specified size */ +#define PMinSize (1L << 4) /* program specified minimum size */ +#define PMaxSize (1L << 5) /* program specified maximum size */ + +#define XpmSuccess 0 +#define XpmOpenFailed -1 +#define XpmFileInvalid -2 +#define XpmNoMemory -3 +#define XpmColorFailed -4 + +#define XpmCloseness (1L << 12) + +#define PCX_Success 0 +#define PCX_OpenFailed -1 +#define PCX_ReadFailed -2 +#define PCX_FileInvalid -3 +#define PCX_NoMemory -4 +#define PCX_ColorFailed -5 + +#define BitmapSuccess 0 +#define BitmapOpenFailed 1 +#define BitmapFileInvalid 2 +#define BitmapNoMemory 3 + +#define ZPixmap 2 /* depth == drawable depth */ + +#define DefaultScreen(dpy) (((_XPrivDisplay)dpy)->default_screen) +#define DefaultColormap(dpy, scr) (ScreenOfDisplay(dpy,scr)->cmap) +#define ScreenOfDisplay(dpy, scr) (&((_XPrivDisplay)dpy)->screens[scr]) +#define BlackPixel(dpy, scr) (ScreenOfDisplay(dpy,scr)->black_pixel) +#define WhitePixel(dpy, scr) (ScreenOfDisplay(dpy,scr)->white_pixel) +#define RootWindow(dpy, scr) (ScreenOfDisplay(dpy,scr)->root) +#define AllPlanes ((unsigned long)~0L) + +#define DefaultVisual(dpy, scr) (NULL) +#define DefaultDepth(dpy, scr) (NULL) +#define XDisplayWidth(dpy, scr) (XRES) +#define XDisplayHeight(dpy, scr) (YRES) + +#define XGetPixel(ximage, x, y) \ + ((*((ximage)->f.get_pixel))((ximage), (x), (y))) + +typedef unsigned long Pixel; /* Index into colormap */ +typedef unsigned long XID; +typedef XID Window; +typedef XID Drawable; +typedef XID Pixmap; +typedef XID Colormap; +typedef XID KeySym; +typedef XID GContext; +typedef struct _XDisplay Display; +typedef long Visual; +typedef long XVisualInfo; +typedef long Atom; +typedef int Status; +typedef int Bool; + +typedef struct _XGC +{ + GContext gid; /* protocol ID for graphics context */ +} *GC; + +typedef struct +{ + Colormap cmap; /* default color map */ + Window root; /* root window id */ + unsigned long white_pixel; /* white pixel value */ + unsigned long black_pixel; /* black pixel value */ + int x; + int y; + unsigned int width; + unsigned int height; + BITMAP *video_bitmap; +} Screen; + +typedef struct _XDisplay +{ + int default_screen; /* default screen for operations */ + Screen *screens; /* pointer to list of screens */ + BITMAP *mouse_ptr; +} *_XPrivDisplay; + +typedef struct _XImage +{ + struct funcs + { + unsigned long (*get_pixel) (struct _XImage *, int, int); + } f; +} XImage; + +typedef struct +{ + long flags; /* marks which fields in this structure are defined */ + int width, height; /* should set so old wm's don't mess up */ + int min_width, min_height; + int max_width, max_height; +} XSizeHints; + +typedef struct +{ + long flags; /* marks which fields in this structure are defined */ + Bool input; /* does this application rely on the window manager to + get keyboard input? */ + int initial_state; /* see below */ + Pixmap icon_pixmap; /* pixmap to be used as icon */ + Pixmap icon_mask; /* icon mask bitmap */ +} XWMHints; + +typedef struct +{ + char *res_name; + char *res_class; +} XClassHint; + +typedef struct +{ + unsigned char *value; /* same as Property routines */ +} XTextProperty; + +typedef struct +{ + unsigned long foreground; /* foreground pixel */ + unsigned long background; /* background pixel */ + Bool graphics_exposures; /* boolean, should exposures be generated */ + Pixmap clip_mask; /* bitmap clipping; other calls for rects */ + int clip_x_origin; /* x origin for clipping */ + int clip_y_origin; /* y origin for clipping */ + unsigned long value_mask; +} XGCValues; + +typedef struct +{ + unsigned long valuemask; /* specifies which attributes are */ + unsigned int closeness; /* allowable RGB deviation */ + Pixel *pixels; /* list of used color pixels */ + unsigned int npixels; /* number of used pixels */ +} XpmAttributes; + +typedef struct +{ + int type; + int x, y; + int width, height; +} XExposeEvent; + +typedef struct +{ + int type; /* of event */ + int x, y; /* pointer x, y coordinates in event window */ + unsigned int button; /* detail */ +} XButtonEvent; + +typedef struct +{ + int type; + int x, y; /* pointer x, y coordinates in event window */ +} XMotionEvent; + +typedef struct +{ + int type; /* of event */ + unsigned int state; /* key or button mask */ +} XKeyEvent; + +typedef struct +{ + int type; /* FocusIn or FocusOut */ +} XFocusChangeEvent; + +typedef struct +{ + int type; /* ClientMessage */ +} XClientMessageEvent; + +typedef union _XEvent +{ + int type; /* must not be changed; first element */ + XExposeEvent xexpose; + XButtonEvent xbutton; + XMotionEvent xmotion; + XKeyEvent xkey; +} XEvent; + +unsigned char get_ascii(KeySym); +void XMapWindow(Display *, Window); +Display *XOpenDisplay(char *); +Window XCreateSimpleWindow(Display *, Window, int, int, + unsigned int, unsigned int, unsigned int, + unsigned long, unsigned long); +Status XStringListToTextProperty(char **, int, XTextProperty *); +void XFree(void *); +GC XCreateGC(Display *, Drawable, unsigned long, XGCValues *); +void XSetClipMask(Display *, GC, Pixmap); +void XSetClipOrigin(Display *, GC, int, int); +void XFillRectangle(Display *, Drawable, GC, int, int, + unsigned int, unsigned int); +Pixmap XCreatePixmap(Display *, Drawable, unsigned int, unsigned int, + unsigned int); +void XSync(Display *, Bool); +inline void XCopyArea(Display *, Drawable, Drawable, GC, int, int, + unsigned int, unsigned int, int, int); +int Read_PCX_to_Pixmap(Display *, Window, GC, char *, Pixmap *, Pixmap *); +int XpmReadFileToPixmap(Display *, Drawable, char *, Pixmap *, Pixmap *, + XpmAttributes *); +int XReadBitmapFile(Display *, Drawable, char *, + unsigned int *, unsigned int *, Pixmap *, int *, int *); +void XFreePixmap(Display *, Pixmap); +void XFreeGC(Display *, GC); +void XCloseDisplay(Display *); +void XNextEvent(Display *, XEvent *); +int XPending(Display *); +KeySym XLookupKeysym(XKeyEvent *, int); +void NetworkServer(int, int); diff --git a/src/netserv.c b/src/netserv.c index 6f5a9a4c..178e89e3 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -11,6 +11,8 @@ * network.c * ***********************************************************/ +#ifndef MSDOS + #include #include #include @@ -28,7 +30,6 @@ static int clients = 0; static int onceonly = 0; -static int is_daemon = 0; struct NetworkServerPlayerInfo { @@ -38,20 +39,20 @@ struct NetworkServerPlayerInfo struct NetworkServerPlayerInfo *next; char active; char introduced; - unsigned char readbuf[MAX_BUFFER_SIZE]; - unsigned char writbuf[MAX_BUFFER_SIZE]; + unsigned char readbuffer[MAX_BUFFER_SIZE]; + unsigned char writbuffer[MAX_BUFFER_SIZE]; int nread, nwrite; byte action; boolean action_received; }; -static struct NetworkServerPlayerInfo *user0 = NULL; +static struct NetworkServerPlayerInfo *first_player = NULL; -#define NEXT(u) ((u)->next ? (u)->next : user0) +#define NEXT(player) ((player)->next ? (player)->next : first_player) static struct sockaddr_in saddr; static int lfd; -static unsigned char realbuf[512], *buf = realbuf + 4; +static unsigned char realbuffer[512], *buffer = realbuffer + 4; static int interrupt; static int tcp = -1; @@ -60,82 +61,76 @@ static unsigned long ServerFrameCounter = 0; static fd_set fds; -static void syserr(char *s) -{ - if (!is_daemon) - fprintf(stderr, "fatal: %s failed.\n", s); - exit(1); -} - -static void addtobuffer(struct NetworkServerPlayerInfo *u, +static void addtobuffer(struct NetworkServerPlayerInfo *player, unsigned char *b, int len) { - if (u->nwrite + len >= MAX_BUFFER_SIZE) - Error(ERR_EXIT, "internal error: network send buffer overflow"); + if (player->nwrite + len >= MAX_BUFFER_SIZE) + Error(ERR_EXIT_NETWORK_SERVER, + "internal error: network send buffer overflow"); - memcpy(u->writbuf + u->nwrite, b, len); - u->nwrite += len; + memcpy(player->writbuffer + player->nwrite, b, len); + player->nwrite += len; } -static void flushuser(struct NetworkServerPlayerInfo *u) +static void flushuser(struct NetworkServerPlayerInfo *player) { - if (u->nwrite) + if (player->nwrite) { - write(u->fd, u->writbuf, u->nwrite); - u->nwrite = 0; + write(player->fd, player->writbuffer, player->nwrite); + player->nwrite = 0; } } static void broadcast(struct NetworkServerPlayerInfo *except, int len, int activeonly) { - struct NetworkServerPlayerInfo *u; + struct NetworkServerPlayerInfo *player; - realbuf[0] = realbuf[1] = realbuf[2] = 0; - realbuf[3] = (unsigned char)len; - for (u=user0; u; u=u->next) - if (u != except && (u->active || !activeonly) && u->introduced) - addtobuffer(u, realbuf, 4 + len); + realbuffer[0] = realbuffer[1] = realbuffer[2] = 0; + realbuffer[3] = (unsigned char)len; + for (player=first_player; player; player=player->next) + if (player != except && (player->active || !activeonly) && player->introduced) + addtobuffer(player, realbuffer, 4 + len); } static void sendtoone(struct NetworkServerPlayerInfo *to, int len) { - realbuf[0] = realbuf[1] = realbuf[2] = 0; - realbuf[3] = (unsigned char)len; - addtobuffer(to, realbuf, 4 + len); + realbuffer[0] = realbuffer[1] = realbuffer[2] = 0; + realbuffer[3] = (unsigned char)len; + addtobuffer(to, realbuffer, 4 + len); } -static void dropuser(struct NetworkServerPlayerInfo *u) +static void RemovePlayer(struct NetworkServerPlayerInfo *player) { struct NetworkServerPlayerInfo *v; if (options.verbose) Error(ERR_NETWORK_SERVER, "dropping client %d (%s)", - u->number, u->player_name); + player->number, player->player_name); - if (u == user0) - user0 = u->next; + if (player == first_player) + first_player = player->next; else { - for (v=user0; v; v=v->next) + for (v=first_player; v; v=v->next) { - if (v->next && v->next == u) + if (v->next && v->next == player) { - v->next = u->next; + v->next = player->next; break; } } } - close(u->fd); + close(player->fd); - if (u->introduced) + if (player->introduced) { - buf[0] = u->number; - buf[1] = OP_PLAYER_DISCONNECTED; - broadcast(u, 2, 0); + buffer[0] = player->number; + buffer[1] = OP_PLAYER_DISCONNECTED; + broadcast(player, 2, 0); } - free(u); + free(player); clients--; if (onceonly && clients == 0) @@ -149,29 +144,29 @@ static void dropuser(struct NetworkServerPlayerInfo *u) } } -static void new_connect(int fd) +static void AddPlayer(int fd) { - struct NetworkServerPlayerInfo *u, *v; + struct NetworkServerPlayerInfo *player, *v; unsigned char nxn; - u = checked_malloc(sizeof (struct NetworkServerPlayerInfo)); + player = checked_malloc(sizeof (struct NetworkServerPlayerInfo)); - u->fd = fd; - u->player_name[0] = 0; - u->next = user0; - u->active = 0; - u->nread = 0; - u->nwrite = 0; - u->introduced = 0; - u->action = 0; - u->action_received = FALSE; + player->fd = fd; + player->player_name[0] = 0; + player->next = first_player; + player->active = 0; + player->nread = 0; + player->nwrite = 0; + player->introduced = 0; + player->action = 0; + player->action_received = FALSE; - user0 = u; + first_player = player; nxn = 1; again: - v = u->next; + v = player->next; while(v) { if (v->number == nxn) @@ -182,37 +177,39 @@ static void new_connect(int fd) v = v->next; } - u->number = nxn; + player->number = nxn; if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d connecting from %s", nxn, inet_ntoa(saddr.sin_addr)); clients++; - buf[0] = 0; - buf[1] = OP_YOUR_NUMBER; - buf[2] = u->number; - sendtoone(u, 3); + buffer[0] = 0; + buffer[1] = OP_YOUR_NUMBER; + buffer[2] = player->number; + sendtoone(player, 3); } -static void Handle_OP_PROTOCOL_VERSION(struct NetworkServerPlayerInfo *u, +static void Handle_OP_PROTOCOL_VERSION(struct NetworkServerPlayerInfo *player, unsigned int len) { - if (len != 5 || buf[2] != PROTOCOL_VERSION_1 || buf[3] != PROTOCOL_VERSION_2) + if (len != 5 || + buffer[2] != PROTOCOL_VERSION_1 || + buffer[3] != PROTOCOL_VERSION_2) { if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) has wrong protocol version %d.%d.%d", - u->number, u->player_name, buf[2], buf[3], buf[4]); + player->number, player->player_name, buffer[2], buffer[3], buffer[4]); - buf[0] = 0; - buf[1] = OP_BAD_PROTOCOL_VERSION; - buf[2] = PROTOCOL_VERSION_1; - buf[3] = PROTOCOL_VERSION_2; - buf[4] = PROTOCOL_VERSION_3; - sendtoone(u, 5); - flushuser(u); + buffer[0] = 0; + buffer[1] = OP_BAD_PROTOCOL_VERSION; + buffer[2] = PROTOCOL_VERSION_1; + buffer[3] = PROTOCOL_VERSION_2; + buffer[4] = PROTOCOL_VERSION_3; + sendtoone(player, 5); + flushuser(player); - dropuser(u); + RemovePlayer(player); interrupt = 1; } else @@ -220,22 +217,22 @@ static void Handle_OP_PROTOCOL_VERSION(struct NetworkServerPlayerInfo *u, if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) uses protocol version %d.%d.%d", - u->number, u->player_name, buf[2], buf[3], buf[4]); + player->number, player->player_name, buffer[2], buffer[3], buffer[4]); } } -static void Handle_OP_NUMBER_WANTED(struct NetworkServerPlayerInfo *u) +static void Handle_OP_NUMBER_WANTED(struct NetworkServerPlayerInfo *player) { struct NetworkServerPlayerInfo *v; - int client_nr = u->number; - int nr_wanted = buf[2]; + int client_nr = player->number; + int nr_wanted = buffer[2]; int nr_is_free = 1; if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) wants to switch to # %d", - u->number, u->player_name, nr_wanted); + player->number, player->player_name, nr_wanted); - for (v=user0; v; v=v->next) + for (v=first_player; v; v=v->next) { if (v->number == nr_wanted) { @@ -248,32 +245,32 @@ static void Handle_OP_NUMBER_WANTED(struct NetworkServerPlayerInfo *u) { if (nr_is_free) Error(ERR_NETWORK_SERVER, "client %d (%s) switches to # %d", - u->number, u->player_name, nr_wanted); - else if (u->number == nr_wanted) + player->number, player->player_name, nr_wanted); + else if (player->number == nr_wanted) Error(ERR_NETWORK_SERVER, "client %d (%s) still has # %d", - u->number, u->player_name, nr_wanted); + player->number, player->player_name, nr_wanted); else Error(ERR_NETWORK_SERVER, "client %d (%s) cannot switch (client %d still exists)", - u->number, u->player_name, nr_wanted); + player->number, player->player_name, nr_wanted); } if (nr_is_free) - u->number = nr_wanted; + player->number = nr_wanted; - buf[0] = client_nr; - buf[1] = OP_NUMBER_WANTED; - buf[2] = nr_wanted; - buf[3] = u->number; + buffer[0] = client_nr; + buffer[1] = OP_NUMBER_WANTED; + buffer[2] = nr_wanted; + buffer[3] = player->number; /* - sendtoone(u, 4); + sendtoone(player, 4); */ broadcast(NULL, 4, 0); } -static void Handle_OP_PLAYER_NAME(struct NetworkServerPlayerInfo *u, +static void Handle_OP_PLAYER_NAME(struct NetworkServerPlayerInfo *player, unsigned int len) { struct NetworkServerPlayerInfo *v; @@ -281,63 +278,63 @@ static void Handle_OP_PLAYER_NAME(struct NetworkServerPlayerInfo *u, if (len>16) len=16; - memcpy(u->player_name, &buf[2], len-2); - u->player_name[len-2] = 0; + memcpy(player->player_name, &buffer[2], len-2); + player->player_name[len-2] = 0; for (i=0; iplayer_name[i] < ' ' || - (u->player_name[i] > 0x7e && u->player_name[i] <= 0xa0)) + if (player->player_name[i] < ' ' || + (player->player_name[i] > 0x7e && player->player_name[i] <= 0xa0)) { - u->player_name[i] = 0; + player->player_name[i] = 0; break; } } - if (!u->introduced) + if (!player->introduced) { - buf[0] = u->number; - buf[1] = OP_PLAYER_CONNECTED; - broadcast(u, 2, 0); + buffer[0] = player->number; + buffer[1] = OP_PLAYER_CONNECTED; + broadcast(player, 2, 0); } if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d calls itself \"%s\"", - u->number, u->player_name); - buf[1] = OP_PLAYER_NAME; - broadcast(u, len, 0); + player->number, player->player_name); + buffer[1] = OP_PLAYER_NAME; + broadcast(player, len, 0); - if (!u->introduced) + if (!player->introduced) { - for (v=user0; v; v=v->next) + for (v=first_player; v; v=v->next) { - if (v != u && v->introduced) + if (v != player && v->introduced) { - buf[0] = v->number; - buf[1] = OP_PLAYER_CONNECTED; - sendtoone(u, 2); - buf[1] = OP_PLAYER_NAME; - memcpy(&buf[2], v->player_name, 14); - sendtoone(u, 2+strlen(v->player_name)); + buffer[0] = v->number; + buffer[1] = OP_PLAYER_CONNECTED; + sendtoone(player, 2); + buffer[1] = OP_PLAYER_NAME; + memcpy(&buffer[2], v->player_name, 14); + sendtoone(player, 2+strlen(v->player_name)); } } } - u->introduced = 1; + player->introduced = 1; } -static void Handle_OP_START_PLAYING(struct NetworkServerPlayerInfo *u) +static void Handle_OP_START_PLAYING(struct NetworkServerPlayerInfo *player) { struct NetworkServerPlayerInfo *v, *w; if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) starts game [level %d from levedir %d (%s)]", - u->number, u->player_name, - (buf[2] << 8) + buf[3], - (buf[4] << 8) + buf[5], - &buf[6]); + player->number, player->player_name, + (buffer[2] << 8) + buffer[3], + (buffer[4] << 8) + buffer[5], + &buffer[6]); - for (w=user0; w; w=w->next) + for (w=first_player; w; w=w->next) if (w->introduced) w->active = 1; @@ -345,57 +342,57 @@ static void Handle_OP_START_PLAYING(struct NetworkServerPlayerInfo *u) ServerFrameCounter = 0; /* reset player actions */ - for (v=user0; v; v=v->next) + for (v=first_player; v; v=v->next) { v->action = 0; v->action_received = FALSE; } - broadcast(NULL, 10 + strlen(&buf[10])+1, 0); + broadcast(NULL, 10 + strlen(&buffer[10])+1, 0); } -static void Handle_OP_PAUSE_PLAYING(struct NetworkServerPlayerInfo *u) +static void Handle_OP_PAUSE_PLAYING(struct NetworkServerPlayerInfo *player) { if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) pauses game", - u->number, u->player_name); + player->number, player->player_name); broadcast(NULL, 2, 0); } -static void Handle_OP_CONTINUE_PLAYING(struct NetworkServerPlayerInfo *u) +static void Handle_OP_CONTINUE_PLAYING(struct NetworkServerPlayerInfo *player) { if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) continues game", - u->number, u->player_name); + player->number, player->player_name); broadcast(NULL, 2, 0); } -static void Handle_OP_STOP_PLAYING(struct NetworkServerPlayerInfo *u) +static void Handle_OP_STOP_PLAYING(struct NetworkServerPlayerInfo *player) { if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) stops game", - u->number, u->player_name); + player->number, player->player_name); broadcast(NULL, 2, 0); } -static void Handle_OP_MOVE_FIGURE(struct NetworkServerPlayerInfo *u) +static void Handle_OP_MOVE_FIGURE(struct NetworkServerPlayerInfo *player) { struct NetworkServerPlayerInfo *v; int last_client_nr = 0; int i; /* store player action */ - for (v=user0; v; v=v->next) + for (v=first_player; v; v=v->next) { - if (v->number == u->number) + if (v->number == player->number) { - v->action = buf[2]; + v->action = buffer[2]; v->action_received = TRUE; } } /* check if server received action from each player */ - for (v=user0; v; v=v->next) + for (v=first_player; v; v=v->next) { if (!v->action_received) return; @@ -406,20 +403,20 @@ static void Handle_OP_MOVE_FIGURE(struct NetworkServerPlayerInfo *u) /* initialize all player actions to zero */ for (i=0; inext) + for (v=first_player; v; v=v->next) { - buf[6 + v->number-1] = v->action; + buffer[6 + v->number-1] = v->action; v->action = 0; v->action_received = FALSE; } - buf[2] = (unsigned char)((ServerFrameCounter >> 24) & 0xff); - buf[3] = (unsigned char)((ServerFrameCounter >> 16) & 0xff); - buf[4] = (unsigned char)((ServerFrameCounter >> 8) & 0xff); - buf[5] = (unsigned char)((ServerFrameCounter >> 0) & 0xff); + buffer[2] = (unsigned char)((ServerFrameCounter >> 24) & 0xff); + buffer[3] = (unsigned char)((ServerFrameCounter >> 16) & 0xff); + buffer[4] = (unsigned char)((ServerFrameCounter >> 8) & 0xff); + buffer[5] = (unsigned char)((ServerFrameCounter >> 0) & 0xff); broadcast(NULL, 6 + last_client_nr, 0); @@ -429,7 +426,7 @@ static void Handle_OP_MOVE_FIGURE(struct NetworkServerPlayerInfo *u) void NetworkServer(int port, int serveronly) { int i, sl, on; - struct NetworkServerPlayerInfo *u; + struct NetworkServerPlayerInfo *player; int mfd; int r; unsigned int len; @@ -460,18 +457,18 @@ void NetworkServer(int port, int serveronly) #endif - lfd = socket(PF_INET, SOCK_STREAM, 0); + if ((lfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) + Error(ERR_EXIT_NETWORK_SERVER, "socket() failed"); + saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = htonl(INADDR_ANY); saddr.sin_port = htons(port); - if (lfd < 0) - syserr("socket"); on = 1; setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(int)); if (bind(lfd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) - syserr("bind"); + Error(ERR_EXIT_NETWORK_SERVER, "bind() failed"); listen(lfd, 5); @@ -509,18 +506,18 @@ void NetworkServer(int port, int serveronly) { interrupt = 0; - for (u=user0; u; u=u->next) - flushuser(u); + for (player=first_player; player; player=player->next) + flushuser(player); FD_ZERO(&fds); mfd = lfd; - u = user0; - while (u) + player = first_player; + while (player) { - FD_SET(u->fd, &fds); - if (u->fd > mfd) - mfd = u->fd; - u = u->next; + FD_SET(player->fd, &fds); + if (player->fd > mfd) + mfd = player->fd; + player = player->next; } FD_SET(lfd, &fds); tv.tv_sec = 0; @@ -528,7 +525,7 @@ void NetworkServer(int port, int serveronly) if ((sl = select(mfd + 1, &fds, NULL, NULL, &tv)) < 0) { if (errno != EINTR) - syserr("select"); + Error(ERR_EXIT_NETWORK_SERVER, "select() failed"); else continue; } @@ -548,7 +545,7 @@ void NetworkServer(int port, int serveronly) if (newfd < 0) { if (errno != EINTR) - syserr("accept"); + Error(ERR_EXIT_NETWORK_SERVER, "accept() failed"); } else { @@ -557,110 +554,111 @@ void NetworkServer(int port, int serveronly) on = 1; setsockopt(newfd, tcp, TCP_NODELAY, (char *)&on, sizeof(int)); } - new_connect(newfd); + AddPlayer(newfd); } continue; } - u = user0; + player = first_player; do { - if (FD_ISSET(u->fd, &fds)) + if (FD_ISSET(player->fd, &fds)) { - r = read(u->fd, u->readbuf + u->nread, MAX_BUFFER_SIZE - u->nread); + r = read(player->fd, player->readbuffer + player->nread, MAX_BUFFER_SIZE - player->nread); if (r <= 0) { if (options.verbose) Error(ERR_NETWORK_SERVER, "EOF from client %d (%s)", - u->number, u->player_name); - dropuser(u); + player->number, player->player_name); + RemovePlayer(player); interrupt = 1; break; } - u->nread += r; - while (u->nread >= 4 && u->nread >= 4 + u->readbuf[3]) + player->nread += r; + while (player->nread >= 4 && player->nread >= 4 + player->readbuffer[3]) { - len = u->readbuf[3]; - if (u->readbuf[0] || u->readbuf[1] || u->readbuf[2]) + len = player->readbuffer[3]; + if (player->readbuffer[0] || player->readbuffer[1] || player->readbuffer[2]) { if (options.verbose) Error(ERR_NETWORK_SERVER, "crap from client %d (%s)", - u->number, u->player_name); - write(u->fd, "\033]50;kanji24\007\033#8\033(0", 19); - dropuser(u); + player->number, player->player_name); + RemovePlayer(player); interrupt = 1; break; } - memcpy(buf, &u->readbuf[4], len); - u->nread -= 4 + len; - memmove(u->readbuf, u->readbuf + 4 + len, u->nread); + memcpy(buffer, &player->readbuffer[4], len); + player->nread -= 4 + len; + memmove(player->readbuffer, player->readbuffer + 4 + len, player->nread); - buf[0] = u->number; - if (!u->introduced && buf[1] != OP_PLAYER_NAME) + buffer[0] = player->number; + if (!player->introduced && buffer[1] != OP_PLAYER_NAME) { if (options.verbose) - Error(ERR_NETWORK_SERVER, "!(client %d)->introduced && buf[1]==%d (expected OP_PLAYER_NAME)", buf[0], buf[1]); + Error(ERR_NETWORK_SERVER, "!(client %d)->introduced && buffer[1]==%d (expected OP_PLAYER_NAME)", buffer[0], buffer[1]); - dropuser(u); + RemovePlayer(player); interrupt = 1; break; } - switch(buf[1]) + switch(buffer[1]) { case OP_PLAYER_NAME: - Handle_OP_PLAYER_NAME(u, len); + Handle_OP_PLAYER_NAME(player, len); break; case OP_PROTOCOL_VERSION: - Handle_OP_PROTOCOL_VERSION(u, len); + Handle_OP_PROTOCOL_VERSION(player, len); break; case OP_NUMBER_WANTED: - Handle_OP_NUMBER_WANTED(u); + Handle_OP_NUMBER_WANTED(player); break; case OP_START_PLAYING: - Handle_OP_START_PLAYING(u); + Handle_OP_START_PLAYING(player); break; case OP_PAUSE_PLAYING: - Handle_OP_PAUSE_PLAYING(u); + Handle_OP_PAUSE_PLAYING(player); break; case OP_CONTINUE_PLAYING: - Handle_OP_CONTINUE_PLAYING(u); + Handle_OP_CONTINUE_PLAYING(player); break; case OP_STOP_PLAYING: - Handle_OP_STOP_PLAYING(u); + Handle_OP_STOP_PLAYING(player); break; case OP_MOVE_FIGURE: - Handle_OP_MOVE_FIGURE(u); + Handle_OP_MOVE_FIGURE(player); break; case OP_BROADCAST_MESSAGE: - buf[len] = '\0'; + buffer[len] = '\0'; if (options.verbose) Error(ERR_NETWORK_SERVER, "client %d (%s) sends message: %s", - u->number, u->player_name, &buf[2]); - broadcast(u, len, 0); + player->number, player->player_name, &buffer[2]); + broadcast(player, len, 0); break; default: if (options.verbose) Error(ERR_NETWORK_SERVER, "unknown opcode %d from client %d (%s)", - buf[0], u->number, u->player_name); + buffer[0], player->number, player->player_name); } } } - if (u && !interrupt) - u = u->next; + if (player && !interrupt) + player = player->next; } - while (u && !interrupt); + while (player && !interrupt); } } + +#endif /* !MSDOS */ diff --git a/src/network.c b/src/network.c index 9a58a7df..bd408a1e 100644 --- a/src/network.c +++ b/src/network.c @@ -11,6 +11,8 @@ * network.c * ***********************************************************/ +#ifndef MSDOS + #include #include #include @@ -604,3 +606,5 @@ void HandleNetworking() HandleNetworkingMessages(); } } + +#endif /* !MSDOS */ diff --git a/src/screens.c b/src/screens.c index a01b6b12..48f42a35 100644 --- a/src/screens.c +++ b/src/screens.c @@ -240,9 +240,11 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) if (setup.autorecord) TapeStartRecording(); +#ifndef MSDOS if (options.network) SendToServer_StartPlaying(); else +#endif { game_status = PLAYING; InitGame(); @@ -1202,6 +1204,11 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) SaveJoystickData(); */ +#ifdef MSDOS + save_joystick_data(JOYSTICK_FILENAME); +#endif + + } game_status = MAINMENU; @@ -1653,7 +1660,9 @@ void CalibrateJoystick(int player_nr) #endif #ifdef MSDOS + /* char joy_nr[4]; + */ #endif int joystick_fd = stored_player[player_nr].joystick_fd; @@ -1743,11 +1752,13 @@ void CalibrateJoystick(int player_nr) } } +#ifndef MSDOS if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) { joystick_status = JOYSTICK_OFF; goto error_out; } +#endif new_joystick_xleft = MIN(new_joystick_xleft, joy_ctrl.x); new_joystick_xright = MAX(new_joystick_xright, joy_ctrl.x); @@ -1815,7 +1826,9 @@ void CalibrateJoystick(int player_nr) while(Joystick(player_nr) & JOY_BUTTON); return; +#ifndef MSDOS error_out: +#endif ClearWindow(); DrawText(SX+16, SY+16, "NO JOYSTICK",FS_BIG,FC_YELLOW); @@ -2058,9 +2071,11 @@ void HandleVideoButtons(int mx, int my, int button) { TapeStartRecording(); +#ifndef MSDOS if (options.network) SendToServer_StartPlaying(); else +#endif { game_status = PLAYING; InitGame(); @@ -2203,9 +2218,11 @@ void HandleGameButtons(int mx, int my, int button) if (Request("Do you really want to quit the game ?", REQ_ASK | REQ_STAY_CLOSED)) { +#ifndef MSDOS if (options.network) SendToServer_StopPlaying(); else +#endif { game_status = MAINMENU; DrawMainMenu(); @@ -2218,10 +2235,12 @@ void HandleGameButtons(int mx, int my, int button) case BUTTON_GAME_PAUSE: if (options.network) { +#ifndef MSDOS if (tape.pausing) SendToServer_ContinuePlaying(); else SendToServer_PausePlaying(); +#endif } else TapeTogglePause(); @@ -2230,9 +2249,11 @@ void HandleGameButtons(int mx, int my, int button) case BUTTON_GAME_PLAY: if (tape.pausing) { +#ifndef MSDOS if (options.network) SendToServer_ContinuePlaying(); else +#endif { tape.pausing = FALSE; DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0); diff --git a/src/sound.c b/src/sound.c index b3818acb..3f150101 100644 --- a/src/sound.c +++ b/src/sound.c @@ -610,6 +610,7 @@ int ulaw_to_linear(unsigned char ulawbyte) /*** THE STUFF BELOW IS ONLY USED BY THE MAIN PROCESS ***/ +#ifndef MSDOS static unsigned long be2long(unsigned long *be) /* big-endian -> longword */ { unsigned char *ptr = (unsigned char *)be; @@ -623,14 +624,17 @@ static unsigned long le2long(unsigned long *be) /* little-endian -> longword */ return(ptr[3]<<24 | ptr[2]<<16 | ptr[1]<<8 | ptr[0]); } +#endif /* !MSDOS */ boolean LoadSound(struct SoundInfo *snd_info) { FILE *file; char filename[256]; char *sound_ext = "wav"; +#ifndef MSDOS struct SoundHeader_WAV *sound_header; int i; +#endif sprintf(filename, "%s/%s/%s.%s", options.base_directory, SOUNDS_DIRECTORY, snd_info->name, sound_ext); @@ -683,7 +687,7 @@ boolean LoadSound(struct SoundInfo *snd_info) for (i=0; idata_len; i++) snd_info->data_ptr[i] = snd_info->data_ptr[i]^0x80; -#else +#else /* MSDOS */ snd_info->sample_ptr = load_sample(filename); if (!snd_info->sample_ptr) @@ -702,12 +706,12 @@ boolean LoadSound_8SVX(struct SoundInfo *snd_info) FILE *file; char filename[256]; #ifndef MSDOS + struct SoundHeader_8SVX *sound_header; + unsigned char *ptr; char *sound_ext = "8svx"; #else char *sound_ext = "wav"; #endif - struct SoundHeader_8SVX *sound_header; - unsigned char *ptr; sprintf(filename, "%s/%s/%s.%s", options.base_directory, SOUNDS_DIRECTORY, snd_info->name, sound_ext); diff --git a/src/sound.h b/src/sound.h index 7bbac533..47807dde 100644 --- a/src/sound.h +++ b/src/sound.h @@ -79,9 +79,6 @@ extern void ioctl(long, long, void *); #define SSND_STOPPING(x) (x & (SSND_STOP_SOUND | SSND_STOP_ALL_SOUNDS)) #define SSND_ALL(x) (x&(SSND_FADE_ALL_SOUNDS|SSND_STOP_ALL_SOUNDS)) -#define TRUE 1 -#define FALSE 0 - /* settings for sound path, sound device, etc. */ #ifndef SND_PATH #define SND_PATH "./sounds" diff --git a/src/tools.c b/src/tools.c index e6b8d9a9..1d1c4dda 100644 --- a/src/tools.c +++ b/src/tools.c @@ -89,11 +89,13 @@ void BackToFront() this could mean that we have to wait for the graphics to complete, although we could go on doing calculations for the next frame */ - XSync(display,FALSE); + XSync(display, FALSE); + /* #ifdef MSDOS wait_for_vsync = TRUE; #endif + */ if (redraw_mask & REDRAW_ALL) { @@ -1338,11 +1340,13 @@ boolean Request(char *text, unsigned int req_state) int mx, my, ty, result = -1; unsigned int old_door_state; +#ifndef MSDOS /* pause network game while waiting for request to answer */ if (options.network && game_status == PLAYING && req_state & REQUEST_WAIT_FOR) SendToServer_PausePlaying(); +#endif old_door_state = GetDoorState(); @@ -1544,11 +1548,13 @@ boolean Request(char *text, unsigned int req_state) } } +#ifndef MSDOS /* continue network game after request */ if (options.network && game_status == PLAYING && req_state & REQUEST_WAIT_FOR) SendToServer_ContinuePlaying(); +#endif return(result); }