X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fmsdos.c;h=d9dd5e7921a0cda09b312e4f6b5c7de7856a4086;hp=6c6c525ca7c42949fea52af7a4a435c403a5303a;hb=370a25a79d2e8df1e6e3e4cb4be39496d0190c28;hpb=34efaa3925a28cb95ecb05bf2c693c16f6edfe2f diff --git a/src/msdos.c b/src/msdos.c index 6c6c525c..d9dd5e79 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -21,6 +21,7 @@ #include "files.h" #include "joystick.h" #include "image.h" +#include "pcx.h" /* allegro driver declarations */ DECLARE_GFX_DRIVER_LIST(GFX_DRIVER_VBEAF GFX_DRIVER_VESA2L GFX_DRIVER_VESA1) @@ -36,6 +37,7 @@ extern JOYSTICK_INFO joy[]; extern int i_love_bill; /* internal variables of msdos.c */ +static boolean keyboard_auto_repeat = TRUE; static int key_press_state[MAX_SCANCODES]; static XEvent event_buffer[MAX_EVENT_BUFFER]; static int pending_events; @@ -51,9 +53,11 @@ 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 *); @@ -85,7 +89,7 @@ static void allegro_drivers() joystick_event = FALSE; reserve_voices(MAX_SOUNDS_PLAYING, 0); - if (install_sound(DIGI_AUTODETECT, MIDI_NONE, "ROCKS.SND") == -1) + if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1) if (install_sound(DIGI_SB, MIDI_NONE, NULL) == -1) sound_status = SOUND_OFF; } @@ -247,6 +251,42 @@ void XMapWindow(Display *display, Window window) unhide_mouse(display); } +static unsigned long AllocColorCell(int r, int g, int b) +{ + byte pixel_mapping = 0; + int i; + + r >>= 10; + g >>= 10; + b >>= 10; + + /* try to use existing colors from the global colormap */ + for (i=0; idefault_screen = 0; @@ -303,6 +348,11 @@ Window XCreateSimpleWindow(Display *display, Window parent, int x, int y, display->screens[display->default_screen].height = YRES; set_mouse_sprite(display->mouse_ptr); + +#if 0 + set_mouse_sprite_focus(1, 1); +#endif + set_mouse_speed(1, 1); set_mouse_range(display->screens[display->default_screen].x + 1, display->screens[display->default_screen].y + 1, @@ -382,7 +432,7 @@ void XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, mouse_off = hide_mouse(display, x, y, width, height); } - rectfill((BITMAP *)d, x, y, x + width, y + height, + rectfill((BITMAP *)d, x, y, x + width - 1, y + height - 1, ((XGCValues *)gc)->foreground); if (mouse_off) @@ -457,22 +507,35 @@ 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 /* allocate new allegro bitmap structure */ if ((bitmap = create_bitmap_ex(depth, image->width, image->height)) == NULL) + { + errno_pcx = PCX_NoMemory; return NULL; + } 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; @@ -499,6 +562,12 @@ static BITMAP *Image_to_AllegroBitmap(Image *image) pixel_mapping[i] = j; } +#else + pixel_mapping[i] = AllocColorCell(image->rgb.red[i], + image->rgb.green[i], + image->rgb.blue[i]); +#endif + } /* copy bitmap data */ @@ -522,7 +591,7 @@ static BITMAP *Read_PCX_to_AllegroBitmap(char *filename) if ((bitmap = Image_to_AllegroBitmap(image)) == NULL) return NULL; - set_pallete(global_colormap); + set_palette(global_colormap); return bitmap; } @@ -533,7 +602,7 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, BITMAP *bitmap; if ((bitmap = Read_PCX_to_AllegroBitmap(filename)) == NULL) - return PCX_FileInvalid; + return errno_pcx; *pixmap = (Pixmap)bitmap; *pixmap_mask = (Pixmap)bitmap; @@ -630,7 +699,7 @@ static void NewKeyEvent(int key_press_state, KeySym keysym) xkey->state = (unsigned int)keysym; } -#define HANDLE_RAW_KB_ALL_KEYS 0 +#define HANDLE_RAW_KB_ALL_KEYS 0 #define HANDLE_RAW_KB_MODIFIER_KEYS_ONLY 1 static int modifier_scancode[] = @@ -698,6 +767,26 @@ static void HandleKeyboardEvent() else if (ascii == '.') keysym = XK_KP_Separator; } + else if (ascii >= ' ' && ascii <= 'Z') + keysym = XK_space + (KeySym)(ascii - ' '); + else if (ascii == '^') + keysym = XK_asciicircum; + else if (ascii == '_') + keysym = XK_underscore; + else if (ascii == 'Ä') + keysym = XK_Adiaeresis; + else if (ascii == 'Ö') + keysym = XK_Odiaeresis; + else if (ascii == 'Ü') + keysym = XK_Udiaeresis; + else if (ascii == 'ä') + keysym = XK_adiaeresis; + else if (ascii == 'ö') + keysym = XK_odiaeresis; + else if (ascii == 'ü') + keysym = XK_udiaeresis; + else if (ascii == 'ß') + keysym = XK_ssharp; NewKeyEvent(KeyPress, keysym); } @@ -717,15 +806,22 @@ int XPending(Display *display) XMotionEvent *xmotion; int i; + /* When using 'HandleKeyboardRaw()', keyboard input is also stored in + the allegro keyboard input buffer and would be available a second + time by calling 'HandleKeyboardEvent()'. To avoid double keyboard + events, the allegro function 'clear_keybuf()' must be called each + time when switching from calling 'HandleKeyboardRaw()' to calling + 'HandleKeyboardEvent()' to get keyboard input, which is actually + done by 'XAutoRepeatOn()' which sets keyboard_auto_repeat to TRUE. */ + /* keyboard event */ - if (game_status == PLAYING) - HandleKeyboardRaw(HANDLE_RAW_KB_ALL_KEYS); - else + if (keyboard_auto_repeat) HandleKeyboardEvent(); + else + HandleKeyboardRaw(HANDLE_RAW_KB_ALL_KEYS); /* mouse motion event */ - /* generate mouse motion event only if any mouse buttons are pressed */ - if (mouse_pos != last_mouse_pos && mouse_b) + if (mouse_pos != last_mouse_pos) { last_mouse_pos = mouse_pos; pending_events++; @@ -738,14 +834,18 @@ int XPending(Display *display) /* mouse button event */ if (mouse_b != last_mouse_b) { - for (i=1; i<4; i<<=1) + for (i=0; i<3; i++) /* check all three mouse buttons */ { - if ((last_mouse_b & i) != (mouse_b & i)) + int bitmask = (1 << i); + + if ((last_mouse_b & bitmask) != (mouse_b & bitmask)) { + int mapping[3] = { 1, 3, 2 }; + pending_events++; xbutton = (XButtonEvent *)&event_buffer[pending_events]; - xbutton->type = (mouse_b & i ? ButtonPress : ButtonRelease); - xbutton->button = i; + xbutton->type = (mouse_b & bitmask ? ButtonPress : ButtonRelease); + xbutton->button = mapping[i]; xbutton->x = mouse_x - display->screens[display->default_screen].x; xbutton->y = mouse_y - display->screens[display->default_screen].y; } @@ -761,55 +861,69 @@ KeySym XLookupKeysym(XKeyEvent *key_event, int index) return key_event->state; } -void sound_handler(struct SoundControl snd_ctrl) +int XLookupString(XKeyEvent *key_event, char *buffer, int buffer_size, + KeySym *key, XComposeStatus *compose) { - int i; + *key = key_event->state; + return 0; +} - if (snd_ctrl.fade_sound) - { - if (!playing_sounds) - return; +void XSetForeground(Display *display, GC gc, unsigned long pixel) +{ + XGCValues *gcv = (XGCValues *)gc; - for (i=0; iforeground = pixel; +} + +void XDrawLine(Display *display, Drawable d, GC gc, + int x1, int y1, int x2, int y2) +{ + XGCValues *gcv = (XGCValues *)gc; + boolean mouse_off = FALSE; + + if ((BITMAP *)d == video_bitmap) { - if (!playing_sounds) - return; - SoundServer_StopSound(snd_ctrl.nr); + x1 += display->screens[display->default_screen].x; + y1 += display->screens[display->default_screen].y; + x2 += display->screens[display->default_screen].x; + y2 += display->screens[display->default_screen].y; + freeze_mouse_flag = TRUE; + mouse_off = hide_mouse(display, MIN(x1, x2), MIN(y1, y2), + MAX(x1, x2) - MIN(x1, x2), + MAX(y1, y2) - MIN(y1, y2)); } - for (i=0; iforeground); - playlist[i].playingpos = voice_get_position(playlist[i].voice); - playlist[i].volume = voice_get_volume(playlist[i].voice); - if (playlist[i].playingpos == -1 || !playlist[i].volume) - { - deallocate_voice(playlist[i].voice); - playlist[i] = emptySoundControl; - playing_sounds--; - } - } + if (mouse_off) + unhide_mouse(display); + + freeze_mouse_flag = FALSE; +} + +void XDestroyImage(XImage *ximage) +{ +} - if (snd_ctrl.active) - SoundServer_InsertNewSound(snd_ctrl); +Bool XQueryPointer(Display *display, Window window, + Window *root, Window *child, int *root_x, int *root_y, + int *win_x, int *win_y, unsigned int *mask) +{ + *win_x = mouse_x - display->screens[display->default_screen].x; + *win_y = mouse_y - display->screens[display->default_screen].y; + + return True; +} + +void XAutoRepeatOn(Display *display) +{ + keyboard_auto_repeat = TRUE; + clear_keybuf(); +} + +void XAutoRepeatOff(Display *display) +{ + keyboard_auto_repeat = FALSE; } void NetworkServer(int port, int serveronly)