diff options
| author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2011-01-02 22:53:54 +0100 |
|---|---|---|
| committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2011-01-02 22:53:54 +0100 |
| commit | ef3b84d78197acbd45d73a9b1ae44b47b5904290 (patch) | |
| tree | c964dc8184163c1afbc345ea922177f3c15f2d80 | |
| parent | 59168bedd25cd2d3e91feccc15fdcbfac59b60ea (diff) | |
| download | qipackages-fork-ef3b84d78197acbd45d73a9b1ae44b47b5904290.tar.gz | |
backport SDL driver into links2 & fixed build system
| -rw-r--r-- | links/Makefile | 11 | ||||
| -rw-r--r-- | links/patches/001-libpng.patch | 22 | ||||
| -rw-r--r-- | links/patches/002-no-gxx.patch | 11 | ||||
| -rw-r--r-- | links/patches/100-add-sdl-driver.patch | 1510 |
4 files changed, 1550 insertions, 4 deletions
diff --git a/links/Makefile b/links/Makefile index 3028528..a031b88 100644 --- a/links/Makefile +++ b/links/Makefile @@ -26,7 +26,7 @@ define Package/links SECTION:=net CATEGORY:=Network URL:=http://links.twibright.com/ - DEPENDS:=+libpng +libtiff + DEPENDS:=+libpng +libtiff +libsdl endef define Package/links/description @@ -42,10 +42,13 @@ CONFIGURE_ARGS += --enable-graphics \ --without-x \ --without-fb -TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include/directfb - CONFIGURE_VARS += \ - DIRECTFB_CONFIG="$(STAGING_DIR)/root-xburst/usr/bin/directfb-config" + DIRECTFB_CONFIG="$(STAGING_DIR)/root-xburst/usr/bin/directfb-config --prefix=$(STAGING_DIR)/usr" + +define Build/Configure + (cd $(PKG_BUILD_DIR); autoreconf -fi ); + $(call Build/Configure/Default) +endef define Package/links/install $(INSTALL_DIR) $(1)/usr/bin diff --git a/links/patches/001-libpng.patch b/links/patches/001-libpng.patch new file mode 100644 index 0000000..74daa1b --- /dev/null +++ b/links/patches/001-libpng.patch @@ -0,0 +1,22 @@ +--- a/configure.in 2010-09-22 03:19:02.547735166 +0200 ++++ b/configure.in 2010-09-22 03:19:39.237745564 +0200 +@@ -580,14 +580,15 @@ + LIBS="$LIBPNG12_LIBS $LIBS" + fi + fi +- AC_CHECK_HEADERS(png.h libpng/png.h) ++# AC_CHECK_HEADERS(png.h libpng/png.h) ++ AC_DEFINE(HAVE_PNG_H, [], [foo]) + AC_HAVE_FUNCS(png_create_info_struct) + if test "$ac_cv_func_png_create_info_struct" != yes; then + AC_CHECK_LIB(png, png_create_info_struct) + fi +- if test "$ac_cv_header_png_h" != yes -a "$ac_cv_header_libpng_png_h" != yes || test "$ac_cv_func_png_create_info_struct" != yes -a "$ac_cv_lib_png_png_create_info_struct" != yes; then +- AC_ERROR([You need libpng to compile Links in graphics mode]) +- fi ++# if test "$ac_cv_header_png_h" != yes -a "$ac_cv_header_libpng_png_h" != yes || test "$ac_cv_func_png_create_info_struct" != yes -a "$ac_cv_lib_png_png_create_info_struct" != yes; then ++# AC_ERROR([You need libpng to compile Links in graphics mode]) ++# fi + + AC_HAVE_FUNCS(png_set_rgb_to_gray) + AC_HAVE_FUNCS(png_get_image_width png_get_image_height png_get_gAMA png_get_color_type png_get_bit_depth png_set_strip_alpha png_get_valid png_get_sRGB) diff --git a/links/patches/002-no-gxx.patch b/links/patches/002-no-gxx.patch new file mode 100644 index 0000000..e9ead47 --- /dev/null +++ b/links/patches/002-no-gxx.patch @@ -0,0 +1,11 @@ +--- a/configure.in.bck 2010-09-24 02:41:10.254510175 +0200 ++++ b/configure.in 2010-09-24 02:41:49.755749857 +0200 +@@ -560,7 +560,7 @@ + AC_CHECK_LIB(stdc++, main) + AC_CHECK_LIB(atheos, main) + if test "$ac_cv_lib_atheos_main" = yes; then +- AC_PROG_CXX ++# AC_PROG_CXX + AC_DEFINE(GRDRV_ATHEOS) + drivers="$drivers ATHEOS" + cf_have_atheos=yes diff --git a/links/patches/100-add-sdl-driver.patch b/links/patches/100-add-sdl-driver.patch new file mode 100644 index 0000000..d73e276 --- /dev/null +++ b/links/patches/100-add-sdl-driver.patch @@ -0,0 +1,1510 @@ +--- a/configure.in 2010-09-25 18:50:12.247566685 +0200 ++++ b/configure.in 2010-09-25 18:49:59.867570133 +0200 +@@ -430,7 +430,7 @@ + AC_ARG_WITH(x, [ --without-x compile without X Window System graphics driver],[if test "$withval" = no; then disable_x=yes; else disable_x=no; fi]) + AC_ARG_WITH(fb, [ --without-fb compile without Linux Framebuffer graphics driver],[if test "$withval" = no; then disable_fb=yes; else disable_fb=no; fi]) + AC_ARG_WITH(directfb, [ --without-directfb compile without DirectFB graphics driver],[if test "$withval" = no; then disable_directfb=yes; else disable_directfb=no; fi]) +-dnl AC_ARG_WITH(sdl, [ --without-sdl compile without SDL graphics driver],[if test "$withval" = no; then disable_sdl=yes; else disable_sdl=no; fi]) ++AC_ARG_WITH(sdl, [ --without-sdl compile without SDL graphics driver],[if test "$withval" = no; then disable_sdl=yes; else disable_sdl=no; fi]) + AC_ARG_WITH(pmshell, [ --without-pmshell compile without PMShell graphics driver],[if test "$withval" = no; then disable_pmshell=yes; else disable_pmshell=no; fi]) + AC_ARG_WITH(atheos, [ --without-atheos compile without Atheos graphics driver],[if test "$withval" = no; then disable_atheos=yes; else disable_atheos; fi]) + +@@ -501,25 +501,25 @@ + fi + fi + +-dnl if test "$disable_sdl" != yes ; then +-dnl AC_PATH_PROG(SDL_CONFIG, sdl-config, no) +-dnl if test "$SDL_CONFIG" != "no"; then +-dnl AC_MSG_CHECKING(for SDL >= 1.2.0) +-dnl sdl_version="`$SDL_CONFIG --version`" +-dnl if expr "$sdl_version" \>= 1.2.0 >/dev/null; then +-dnl AC_MSG_RESULT(yes) +-dnl SDL_CFLAGS="`$SDL_CONFIG --cflags`" +-dnl SDL_LIBS="`$SDL_CONFIG --libs`" +-dnl AC_DEFINE(GRDRV_SDL) +-dnl drivers="$drivers SDL" +-dnl CPPFLAGS="$CPPFLAGS $SDL_CFLAGS" +-dnl AC_CHECK_LIB(Xext, XextAddDisplay) +-dnl LIBS="$SDL_LIBS $LIBS" +-dnl else +-dnl AC_MSG_RESULT(no) +-dnl fi +-dnl fi +-dnl fi ++if test "$disable_sdl" != yes ; then ++ AC_PATH_PROG(SDL_CONFIG, sdl-config, no) ++ if test "$SDL_CONFIG" != "no"; then ++ AC_MSG_CHECKING(for SDL >= 1.2.0) ++ sdl_version="`$SDL_CONFIG --version`" ++ if expr "$sdl_version" \>= 1.2.0 >/dev/null; then ++ AC_MSG_RESULT(yes) ++ SDL_CFLAGS="`$SDL_CONFIG --cflags`" ++ SDL_LIBS="`$SDL_CONFIG --libs`" ++ AC_DEFINE(GRDRV_SDL) ++ drivers="$drivers SDL" ++ CPPFLAGS="$CPPFLAGS $SDL_CFLAGS" ++ AC_CHECK_LIB(Xext, XextAddDisplay) ++ LIBS="$SDL_LIBS $LIBS" ++ else ++ AC_MSG_RESULT(no) ++ fi ++ fi ++fi + + if test "$disable_pmshell" != yes ; then + AC_CACHE_CHECK([for pmshell], ac_cv_have_pmshell, +--- a/Makefile.am 2010-09-25 18:42:40.087568555 +0200 ++++ b/Makefile.am 2010-09-25 18:42:51.917570410 +0200 +@@ -13,7 +13,7 @@ + else + endif + +-links_SOURCES=af_unix.c auth.c beos.c bfu.c block.c bookmarks.c cache.c charsets.c connect.c cookies.c default.c dip.c directfb.c directfb_cursors.h dither.c dns.c drivers.c error.c file.c finger.c font_include.c framebuffer.c ftp.c gif.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c links_icon.c listedit.c lru.c mailto.c main.c menu.c memory.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c x.c xbm.c links.h cfg.h os_dep.h os_depx.h setup.h codepage.h language.h codepage.inc entity.inc uni_7b.inc language.inc upcase.inc arrow.inc bits.h ++links_SOURCES=af_unix.c auth.c beos.c bfu.c block.c bookmarks.c cache.c charsets.c connect.c cookies.c default.c dip.c directfb.c directfb_cursors.h dither.c dns.c drivers.c error.c file.c finger.c font_include.c framebuffer.c ftp.c gif.c html.c html_gr.c html_r.c html_tbl.c http.c https.c img.c imgcache.c jpeg.c jsint.c kbd.c language.c links_icon.c listedit.c lru.c mailto.c main.c menu.c memory.c objreq.c os_dep.c pmshell.c png.c sched.c select.c session.c smb.c svgalib.c terminal.c tiff.c types.c url.c view.c view_gr.c x.c xbm.c links.h cfg.h os_dep.h os_depx.h setup.h codepage.h language.h codepage.inc entity.inc uni_7b.inc language.inc upcase.inc arrow.inc bits.h sdl.c sdl_data.inc + + dist-hook: + #remove the symlinka: +--- a/sdl.c 1970-01-01 01:00:00.000000000 +0100 ++++ b/sdl.c 2010-09-25 18:38:37.887567087 +0200 +@@ -0,0 +1,1161 @@ ++/*sdl.c ++ -- SDL graphic driver for Links (version 0.2.0) ++ ++ Copyright (C) 2004 Samuel Behan <sam(at)frida(dot)fri(dot)utc(dot)sk> ++ ++ This driver is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License ++ as published by the Free Software Foundation; either version 2 ++ of the License, or (at your option) any later version. ++ ++ This driver is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ General Public License for more details. ++ ++ --- ++ I've wrote this driver just as a proof of concept for using SDL library. I wanted ++ to use something easy, so i've decided for the world's best web browser :) ++ ++ TODO: ++ - keyboard input system doesn't handles all characters, because sdl ignores any ++ system mappings and provides something like `raw keyboard access' ++ - *_strip functions are possibly bad implemented, actualy i don't understand what ++ they should do, or better i'm too lazy to find it out :) ++ - BUGBUG: aa-lib nor caca lib, dont display nicely - they actualy display nothing ;( ++ This needs to be fixed, becase links over aa-lib as that what i've been ++ dreaming of [ try set env SDL_VIDEODRIVER="aalib" ] ++ ...and many more, not found yet :) ++*/ ++ ++ ++#include "cfg.h" ++ ++#ifdef GRDRV_SDL ++ ++#ifdef TEXT ++#undef TEXT ++#endif ++ ++#include "links.h" ++#include <signal.h> ++/* #include "arrow.inc" */ ++ ++/*sdl inclusions*/ ++#include <SDL.h> ++/*#include <SDL_gfxPrimitives.h>*/ ++ ++ ++/* ------ some config options -------- */ ++/*#define sdl_HAVE_DOUBLEBUF */ ++ ++ ++/* ---------- helper tools ----------- */ ++/* FIXME: enabled debug mode */ ++#undef DEBUG ++#ifdef DEBUG ++#include <assert.h> ++#define S_ASSERT(code) assert((code)) ++#define S_ON_DEBUG(code) code ++#define S_ON_DEBUG_TRACE(str) fprintf(stderr, "[%s:%s:%d] %s\n", __FILE__, __PRETTY_FUNCTION__, __LINE__, str); ++#else ++#define S_ASSERT(code) ++#define S_ON_DEBUG(code) ++#define S_ON_DEBUG_TRACE(str) ++#endif ++ ++/* internal types */ ++typedef unsigned char u_char_t; ++typedef unsigned short int u_short_t; ++struct graphics_driver sdl_driver; ++ ++/* keysyms */ ++#include "sdl_data.inc" ++ ++static struct t_sdl_driver_data { ++ u_char_t *video_drv; /* used video driver name */ ++ SDL_VideoInfo *video_info; /* video informations */ ++ SDL_Cursor *cursor; /* cursor */ ++ int event_timer; /* event timer id */ ++ int input_encoding; /* input encoding codepage */ ++ struct { ++ long int flags; /* video flags */ ++ short int width; ++ short int height; ++ short int depth; ++ short int bpp; /* bytes per pixel */ ++ } video; ++} sdl_data = { ++ NULL, ++ NULL, ++ NULL, ++ -1, ++ 0, ++ { 0, 0, 0, 0, 0 }, ++}; ++#define sdl_VIDEO_WIDTH sdl_DATA.video.width ++#define sdl_VIDEO_HEIGHT sdl_DATA.video.height ++#define sdl_VIDEO_DEPTH sdl_DATA.video.depth ++#define sdl_VIDEO_BPP sdl_DATA.video.bpp ++#define sdl_VIDEO_FLAGS sdl_DATA.video.flags ++ ++/* DRIVER DATA HELPERS */ ++#define sdl_DATA sdl_data ++#define sdl_DATA_pfmt (sdl_DATA.video_info->vfmt) /* pixel format */ ++#define sdl_DATA_FREE() if(sdl_DATA.video_drv != NULL) mem_free(sdl_DATA.video_drv); \ ++ if(sdl_DATA.video_info != NULL) mem_free(sdl_DATA.video_info); ++ ++struct t_sdl_device_data { ++ SDL_Surface *p_surf; /* primary surface */ ++ struct graphics_device *g_dev; /* draphic device */ ++ short u_pending; /* update pending */ ++ SDL_Rect u_rect; /* update rectangle */ ++}; ++#define sdl_SURFACE(ptr) (ptr)->p_surf ++#define sdl_GD(ptr) (ptr)->g_dev ++#define sdl_URECT(ptr) (ptr)->u_rect ++#define sdl_UPENDING(ptr) (ptr)->u_pending ++ ++/* HELPER FUNCTIONS */ ++#define sdl_COLOR(col) (((col) << 2) | 0x00) ++ ++#define sdl_SETUP_TIMER(dev) \ ++ if (sdl_DATA.event_timer == -1) sdl_DATA.event_timer = install_timer(20, sdl_catch_event, (dev)) ++#define sdl_KILL_TIMER() \ ++ if (sdl_DATA.event_timer != -1) kill_timer(sdl_DATA.event_timer), sdl_DATA.event_timer = -1 ++ ++/* event catch helpers */ ++#define sdl_CATCH_EVENTS_NUM 30 ++#if defined(SDL_BUTTON_WHEELUP) && defined(SDL_BUTTON_WHEELDOWN) ++#define sdl_MOUSE_STATE(var_in, var_out, def) \ ++ if(var_in == SDL_BUTTON(SDL_BUTTON_LEFT)) \ ++ var_out |= B_LEFT; \ ++ else if(var_in == SDL_BUTTON(SDL_BUTTON_RIGHT)) \ ++ var_out |= B_RIGHT; \ ++ else if(var_in == SDL_BUTTON(SDL_BUTTON_MIDDLE)) \ ++ var_out |= B_MIDDLE; \ ++ else if(var_in == SDL_BUTTON(SDL_BUTTON_WHEELUP)) \ ++ var_out |= B_WHEELUP; \ ++ else if(var_in == SDL_BUTTON(SDL_BUTTON_WHEELDOWN)) \ ++ var_out |= B_WHEELDOWN; \ ++ else var_out = (def); ++#else ++#define sdl_MOUSE_STATE(var_in, var_out, def) \ ++ if(var_in == SDL_BUTTON(SDL_BUTTON_LEFT)) \ ++ var_out |= B_LEFT; \ ++ else if(var_in == SDL_BUTTON(SDL_BUTTON_RIGHT)) \ ++ var_out |= B_RIGHT; \ ++ else if(var_in == SDL_BUTTON(SDL_BUTTON_MIDDLE)) \ ++ var_out |= B_MIDDLE; \ ++ else var_out = (def); ++#endif ++ ++ ++/* tha event handler */ ++static void sdl_catch_event(void *data) ++{ ++ register int i = 0; ++ register int ev_num = 0; ++ register u_short_t fl = 0; ++ register struct t_sdl_device_data *dev = NULL; ++ SDL_Event events[sdl_CATCH_EVENTS_NUM]; ++ ++ /* speedup (BUGGY, not thread safe !?!) */ ++ static u_short_t o_x = 0, o_y = 0, o_fl = 0; ++ ++ sdl_DATA.event_timer = -1; ++ ++ SDL_PumpEvents(); ++ ev_num = SDL_PeepEvents(events, sdl_CATCH_EVENTS_NUM, SDL_GETEVENT, SDL_ALLEVENTS); ++ ++ S_ASSERT(ev_num != -1); ++ /* get dev data */ ++ dev = (struct t_sdl_device_data *) data; ++ for(i = 0; i < ev_num; i++) ++ { ++#define event events[i] ++ switch (event.type) ++ { ++/* case SDL_ACTIVEEVENT: */ ++ /* mouse motion */ ++ case SDL_MOUSEMOTION: ++ /* mose btn state */ ++ /* S_ON_DEBUG_TRACE("event: mouse motion"); */ ++ fl = B_DRAG; ++ sdl_MOUSE_STATE(event.motion.state, fl, B_MOVE); ++ /* save som calls (SDL generates many similar events) */ ++ if(event.motion.x == o_x && event.motion.y == o_y && fl == o_fl) ++ break; ++ /* call handler */ ++ sdl_GD(dev)->mouse_handler(sdl_GD(dev), event.motion.x, event.motion.y, fl); ++ o_x = event.motion.x; ++ o_y = event.motion.y; ++ o_fl = fl; ++ break; ++ /* mouse click */ ++ case SDL_MOUSEBUTTONUP: ++ case SDL_MOUSEBUTTONDOWN: ++#if defined(SDL_BUTTON_WHEELUP) && defined(SDL_BUTTON_WHEELDOWN) ++ if(event.button.button == SDL_BUTTON_WHEELUP) ++ fl = B_WHEELUP | B_MOVE; ++ else if(event.button.button == SDL_BUTTON_WHEELDOWN) ++ fl = B_WHEELDOWN | B_MOVE; ++ else ++#endif ++ { ++ if(event.type == SDL_MOUSEBUTTONDOWN) ++ fl = B_DOWN; ++ else ++ fl = B_UP; ++ } ++ ++ /* S_ON_DEBUG_TRACE("event: mouse click"); */ ++ /* sdl_MOUSE_STATE(event.button.state, fl, fl); */ ++ sdl_GD(dev)->mouse_handler(sdl_GD(dev), event.button.x, event.button.y, fl); ++ break; ++ ++ /* keyboard */ ++ case SDL_KEYUP: ++ /* S_ON_DEBUG_TRACE("event: key up"); */ ++ break; ++ case SDL_KEYDOWN: ++ { /*translate */ ++ int k = 0; ++ int key = 0; ++/* ++* ////////////////////////// ++* //FIXME: needs rework !!! ++* // -- sdl works at low-level ignoring any system keymappings ++* // i've no idea how to do it (easily):( ++* ////////////////////////// ++*/ ++ /* S_ON_DEBUG_TRACE("event: key down"); */ ++ while(sdl_keysyms[k].sym != event.key.keysym.sym && sdl_keysyms[k].sym != SDLK_LAST) ++ k++; ++ S_ASSERT(sdl_keysyms[k].sym != SDLK_LAST); ++ /* FIXME: hope nobody changes enumeration values in SDL libs */ ++ if(sdl_keysyms[k].sym >= SDLK_NUMLOCK && sdl_keysyms[k].sym <= SDLK_COMPOSE) ++ break; /* aka ignore modifiers */ ++ /* find modifiers */ ++ fl = 0; ++ if(event.key.keysym.mod & KMOD_SHIFT) ++ fl |= KBD_SHIFT; ++ if(event.key.keysym.mod & KMOD_ALT) ++ fl |= KBD_ALT; ++ if(event.key.keysym.mod & KMOD_CTRL) ++ fl |= KBD_CTRL; ++ /* key re-map */ ++ key = sdl_keysyms[k].key; ++ /* upper letters fix (not handled directly by SDL) */ ++ if(key >= 97 && key <= 122 && fl & KBD_SHIFT) ++ { key -= 32; ++ fl &= ~KBD_SHIFT; } ++ /* find modifiers */ ++ fl = 0; ++ if(event.key.keysym.mod & KMOD_SHIFT) ++ fl |= KBD_SHIFT; ++ if(event.key.keysym.mod & KMOD_ALT) ++ fl |= KBD_ALT; ++ if(event.key.keysym.mod & KMOD_CTRL) ++ fl |= KBD_CTRL; ++ /* send keyb */ ++ /* S_ON_DEBUG(fprintf(stderr, "KEY(%d) = %c&%d\n", k, key, fl);); */ ++ if(fl & KBD_CTRL && sdl_keysyms[k].sym == SDLK_c) ++ sdl_GD(dev)->keyboard_handler(sdl_GD(dev), KBD_CTRL_C, 0); ++ else ++ sdl_GD(dev)->keyboard_handler(sdl_GD(dev), key, fl); ++ }break; ++ case SDL_VIDEORESIZE: ++ /* new dims */ ++ sdl_GD(dev)->size.x2 = event.resize.w; ++ sdl_GD(dev)->size.y2 = event.resize.h; ++ sdl_driver.x = event.resize.w; ++ sdl_driver.y = event.resize.h; ++ /* resize */ ++ /* ++ S_ON_DEBUG(fprintf(stderr, "RESIZE(%dx%d)\n", event.resize.w, event.resize.h)); ++ */ ++ /* info resize */ ++ sdl_GD(dev)->resize_handler(sdl_GD(dev)); ++ break; ++/* ++ case SDL_VIDEOEXPOSE: ++*/ ++ case SDL_QUIT: ++ sdl_GD(dev)->keyboard_handler(sdl_GD(dev), KBD_CLOSE, 0); ++ break; ++ default: ++ /* printf("Unhandled event: %d !\n", event.type); */ ++ break; ++ } ++ } ++#undef event ++ sdl_SETUP_TIMER((void *)dev); ++ return; ++} ++ ++static void sdl_update_sc(void *data) ++{ ++ register struct t_sdl_device_data *dev; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ /* assign struct */ ++ if(data == NULL) ++ return; ++ dev = (struct t_sdl_device_data *)data; ++ /* check if update neccesary */ ++#ifdef __NOT_DEF ++ if(dev == NULL || sdl_SURFACE(dev) == NULL) ++ return; ++ if(sdl_UPENDING(dev) == 0) ++ return; ++#endif ++ ++#ifndef sdl_HAVE_DOUBLEBUF ++ /*update screen*/ ++ S_ON_DEBUG(fprintf(stderr, "rel-update(%dx%dX%dx%d)\n", sdl_URECT(dev).x, sdl_URECT(dev).y, sdl_URECT(dev).w, sdl_URECT(dev).h)); ++ /* bound check */ ++ if(sdl_URECT(dev).x + sdl_URECT(dev).w > sdl_VIDEO_WIDTH) ++ sdl_URECT(dev).w = sdl_VIDEO_WIDTH - sdl_URECT(dev).x; ++ if(sdl_URECT(dev).y + sdl_URECT(dev).h > sdl_VIDEO_HEIGHT) ++ sdl_URECT(dev).h = sdl_VIDEO_HEIGHT - sdl_URECT(dev).y; ++ /* perform screen update */ ++ SDL_UpdateRect(sdl_SURFACE(dev), sdl_URECT(dev).x, sdl_URECT(dev).y, sdl_URECT(dev).w, sdl_URECT(dev).h); ++#else ++ SDL_Flip(sdl_SURFACE(dev)); ++#endif ++ /* remove pending flag */ ++ sdl_UPENDING(dev) = 0; ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++ ++/* quite stuppit function */ ++#define sdl_NORM_UPDATE 0 ++#define sdl_FULL_UPDATE 1 ++static inline void sdl_register_update(struct t_sdl_device_data *dev, ++ const int x, const int y, const int w, const int h, const int opt) ++{ ++#ifdef __NOT_DEF ++ if (x < 0 || y < 0 || w < 1 || h < 1) ++ return; ++#endif ++#ifndef sdl_HAVE_DOUBLEBUF ++ ++ if (sdl_UPENDING(dev)) ++ { ++/* S_ON_DEBUG(fprintf(stderr, "<<rect-in1(%dx%dX%dx%d)\t[%dx%dX%dx%d]\n", sdl_URECT(dev).x,sdl_URECT(dev).y, sdl_URECT(dev).x + sdl_URECT(dev).w, sdl_URECT(dev).y + sdl_URECT(dev).h, ++ sdl_URECT(dev).x,sdl_URECT(dev).y, sdl_URECT(dev).x, sdl_URECT(dev).y)); ++ S_ON_DEBUG(fprintf(stderr, "<<rect-in2(%dx%dX%dx%d)\t[%dx%dX%dx%d]\n", x, y, x + w, y + h, ++ x, y, w, h)); ++*/ ++ /* compute correct update rectangle */ ++ if(sdl_URECT(dev).w < w) ++ sdl_URECT(dev).w = w; ++ if(sdl_URECT(dev).h < h) ++ sdl_URECT(dev).h = h; ++ if(sdl_URECT(dev).x > x) ++ { sdl_URECT(dev).w += sdl_URECT(dev).x - x; ++ sdl_URECT(dev).x = x; } ++ if(sdl_URECT(dev).y > y) ++ { sdl_URECT(dev).h += sdl_URECT(dev).y - y; ++ sdl_URECT(dev).y = y; } ++ if(x + w > sdl_URECT(dev).w) ++ sdl_URECT(dev).w = x + w - 1; ++ if(y + h > sdl_URECT(dev).h) ++ sdl_URECT(dev).h = y + h - 1; ++/* S_ON_DEBUG(fprintf(stderr, ">>rect-out(%dx%dX%dx%d)\t[%dx%dX%dx%d]\n", sdl_URECT(dev).x,sdl_URECT(dev).y, sdl_URECT(dev).x + sdl_URECT(dev).w, sdl_URECT(dev).y + sdl_URECT(dev).h, ++ sdl_URECT(dev).x,sdl_URECT(dev).y, sdl_URECT(dev).x, sdl_URECT(dev).y)); ++*/ ++ return; ++ } ++ /* create update rectangle */ ++ sdl_URECT(dev).x = x; ++ sdl_URECT(dev).y = y; ++ sdl_URECT(dev).w = w; ++ sdl_URECT(dev).h = h; ++#else ++ if(sdl_UPENDING(dev)) ++ return; ++#endif ++ sdl_UPENDING(dev) = 1; ++ /* register update */ ++ register_bottom_half(sdl_update_sc, dev); ++ return; ++} ++ ++/* partialy stolen from documentation :) ++ XXX: we can quite easily add here alpha blending :))) */ ++static inline void sdl_putpixel(const SDL_Surface *s, const int x, const int y, const unsigned long pixel) ++{ ++ register Uint8 *p; ++ ++ /* check our clip rect */ ++ if(!((s->clip_rect.x < x && (s->clip_rect.x + s->clip_rect.w) > x) ++ && (s->clip_rect.y < y && (s->clip_rect.y + s->clip_rect.h) > y))) ++ return; ++ /* our sanity (fight int overflow :) */ ++/* ++ pixel &= (1<<(s->format->BytesPerPixel)) - 1; ++*/ ++ /* our point */ ++ p = (Uint8 *)s->pixels + y * s->pitch + x * s->format->BytesPerPixel; ++ switch(s->format->BytesPerPixel) { ++ case 1: ++ *p = pixel; ++ break; ++ case 2: ++ *(Uint16 *)p = pixel; ++ break; ++ ++ case 3: ++ if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { ++ p[0] = (pixel >> 16) & 0xff; ++ p[1] = (pixel >> 8) & 0xff; ++ p[2] = pixel & 0xff; ++ } else { ++ p[0] = pixel & 0xff; ++ p[1] = (pixel >> 8) & 0xff; ++ p[2] = (pixel >> 16) & 0xff; ++ } ++ break; ++ case 4: ++ *(Uint32 *)p = pixel; ++ break; ++ } ++ return; ++} ++ ++ ++/* DRIVER FUNCTIONS */ ++ ++ /* findout avibles video mode */ ++static u_char_t *sdl_list_videomodes(void) ++{ ++ SDL_Rect **modes; ++ ++ modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); ++ /* check if any mode avaible */ ++ if(modes == (SDL_Rect **) 0) ++ return stracpy("No modes available!\n"); ++ /* any dimenstion possible */ ++ else if(modes == (SDL_Rect **) -1) ++ return stracpy("All resolutions available.\n"); ++ else /* list possible modes */ ++ { ++ int i; ++ printf("Available Modes: \n"); ++ for(i = 0; modes[i] != NULL; ++i) ++ printf("\t%dx%d\n", modes[i]->w, modes[i]->h); ++ } ++ return NULL; ++} ++ ++#define sdl_DRV_MAXLEN 15 ++#define sdl_RES_MAXLEN 5 ++#define sdl_DEPTH_MAXLEN 2 ++/* init driver */ ++static u_char_t *sdl_init_driver(u_char_t *param, u_char_t *display) ++{ ++ unsigned long video_bw_suggest = 0; ++ ++ S_ON_DEBUG_TRACE("in"); ++ ++ /* determine required video mode (we are going to parse input string -- BE AWARE !!!) ++ LITTLE BIT PARANOID IMPLEMENTATION :) */ ++ if(param != NULL) ++ { ++ int p_pos = 0; ++ u_char_t *m = NULL; ++ u_char_t *m2 = NULL; ++ u_char_t *p = NULL; ++ unsigned long res_x = 0; ++ unsigned long res_y = 0; ++ unsigned long res_bw = 0; ++ u_char_t drv[sdl_DRV_MAXLEN] = ""; ++ ++ m = stracpy(param); ++ m2 = m; ++ ++ /* S_ON_DEBUG(fprintf(stderr, "parse> input = %s\n", m)); */ ++ ++ /* look for driver name to use */ ++ p = strchr(m2, ':'); ++ if(p != NULL) ++ { /* calc length */ ++ p_pos = (int) p - (int) m2; ++ if(p_pos > sdl_DRV_MAXLEN) ++ goto bugbug; ++ strncpy(drv, m2, p_pos); ++ drv[p_pos] = '\0'; ++ /* move fwd */ ++ m2 = (u_char_t *) (m2 + p_pos + 1); ++ } ++ ++ /* find 'x' character (FOR X_RES)*/ ++ p = strchr(m2, 'x'); ++ /* calculate length*/ ++ if(p != NULL) ++ p_pos = (int) p - (int) m2; ++ else ++ p_pos = strlen(m2); ++ /*check max length*/ ++ if(p_pos > sdl_RES_MAXLEN) ++ goto bugbug; ++ ++ /* S_ON_DEBUG(fprintf(stderr,"parse> input(x) = %s\n", m2)); */ ++ res_x = atoi(m2); ++ /* S_ON_DEBUG(fprintf(stderr,"parse> res_x = %d\n", res_x)); */ ++ /* move fwd */ ++ ++ if(m2[p_pos] == 'x') ++ m2 = (u_char_t *) (m2 + p_pos + 1); ++ else ++ goto bugbug; ++ ++ /* find 'x' character (FOR Y_RES)*/ ++ p = strchr(m2, 'x'); ++ /* calculate length*/ ++ if(p != NULL) ++ p_pos = (int) p - (int) m2; ++ else ++ p_pos = strlen(m2); ++ /*check max length*/ ++ if(p_pos > sdl_RES_MAXLEN) ++ goto bugbug; ++ ++ /* S_ON_DEBUG(fprintf(stderr,"parse> input(y) = %s\n", m2)); */ ++ res_y = atoi(m2); ++ /* S_ON_DEBUG(fprintf(stderr,"parse> res_y = %d\n", res_y)); */ ++ /* move fwd */ ++ if(m2[p_pos] == 'x') ++ { /* findout bits-per-pixel*/ ++ m2 = (u_char_t *) (m2 + p_pos + 1); ++ ++ /* S_ON_DEBUG(fprintf(stderr,"parse> input(bw) = %s\n", m2)); */ ++ ++ /* check length */ ++ if(strlen(m) - (int) (m2 - m) == 0) ++ goto no_bugbug; ++ if(strlen(m) - (int) (m2 - m) > sdl_DEPTH_MAXLEN) ++ goto bugbug; ++ ++ res_bw = atoi(m2); ++ } ++ ++ /* S_ON_DEBUG(fprintf(stderr,"parse> depth = %d\n", res_bw)); */ ++ goto no_bugbug; ++ ++ bugbug: ++ mem_free(m); ++ return stracpy("ERROR: bad mode given for `-mode' param (use: [<sdl_driver>:]<width>x<height>[x<bpp>])\n"); ++ no_bugbug: ++ mem_free(m); ++ /* ++ if(drv[0] != '\0') ++ fprintf(stderr, "VIDEO(%s):\t %ldx%ldx%ldbpp [requested]\n", drv, res_x, res_y, res_bw); ++ else fprintf(stderr, "VIDEO(auto):\t %ldx%ldx%ldbpp [requested]\n", res_x, res_y, res_bw); ++ */ ++ ++ /* set them */ ++ sdl_VIDEO_WIDTH = res_x; ++ sdl_VIDEO_HEIGHT = res_y; ++ sdl_VIDEO_DEPTH = res_bw; /* 0 - means current depth */ ++ if(drv[0] != '\0') /* set driver name to env */ ++ { u_char_t en[20 + sdl_DRV_MAXLEN]; ++ ++ sprintf(en, "%s=%s", "SDL_VIDEODRIVER", drv); ++ putenv(en); } ++ } ++ ++ /* pass some opts to sdl via enviroment*/ ++ putenv("SDL_VIDEO_CENTERED=1"); ++ ++ /* init sdl video */ ++ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0) { ++ u_char_t *u = stracpy((u_char_t *)SDL_GetError()); ++ add_to_strn(&u, "\n"); ++ return u; ++ } ++ ++ /* fetch current video hw informations */ ++ sdl_DATA.video_info = (SDL_VideoInfo *) mem_alloc(sizeof(SDL_VideoInfo)); ++ S_ASSERT(sdl_DATA.video_info != NULL); ++ memcpy(sdl_DATA.video_info, SDL_GetVideoInfo(), (sizeof(SDL_VideoInfo))); ++ /* fetch driver name */ ++ sdl_DATA.video_drv = (u_char_t *)mem_alloc(sizeof(u_char_t) * 11); ++ S_ASSERT(sdl_DATA.video_drv != NULL); ++ SDL_VideoDriverName((char *)sdl_DATA.video_drv, 11); ++ ++ /* setup defaults */ ++ sdl_VIDEO_FLAGS |= SDL_HWSURFACE | SDL_HWPALETTE | SDL_RESIZABLE | SDL_RLEACCEL | SDL_ASYNCBLIT; ++#ifdef sdl_HAVE_DOUBLEBUF ++ sdl_VIDEO_FLAGS |= SDL_DOUBLEBUF; ++#endif ++ if(sdl_VIDEO_WIDTH == 0) ++ sdl_VIDEO_WIDTH = 800; ++ if(sdl_VIDEO_HEIGHT == 0) ++ sdl_VIDEO_HEIGHT= 600; ++ if(sdl_VIDEO_DEPTH == 0) ++ sdl_VIDEO_DEPTH = sdl_DATA.video_info->vfmt->BitsPerPixel; ++ ++ /* FIXME: not sure if this is correct !!!*/ ++ sdl_VIDEO_BPP = (sdl_VIDEO_DEPTH / 8); ++ if(sdl_VIDEO_DEPTH % 8 != 0) ++ sdl_VIDEO_BPP += 1; ++ ++ /* set driv config */ ++ sdl_driver.x = sdl_VIDEO_WIDTH; ++ sdl_driver.y = sdl_VIDEO_HEIGHT; ++/* sdl_driver.depth = ((sdl_DATA.video_info->vfmt->BytesPerPixel & 0x7) | ++ (((sdl_DATA.video_info->vfmt->BitsPerPixel > 24 ? 24 : sdl_DATA.video_info->vfmt->BitsPerPixel) & 0x1F) << 3)); ++*/ ++ sdl_driver.depth = ((sdl_VIDEO_BPP & 0x7) | ++ (((sdl_VIDEO_DEPTH > 24 ? 24 : sdl_VIDEO_DEPTH) & 0x1F) << 3)); ++ ++ S_ON_DEBUG(fprintf(stderr, "display = %d@%d [%d] (requested)\n", sdl_VIDEO_DEPTH, sdl_VIDEO_BPP, sdl_driver.depth)); ++ ++ ++ /* check if video mode ok*/ ++ video_bw_suggest = SDL_VideoModeOK(sdl_VIDEO_WIDTH, sdl_VIDEO_HEIGHT, sdl_VIDEO_DEPTH, sdl_VIDEO_FLAGS); ++ if(video_bw_suggest == 0) ++ { ++ sdl_list_videomodes(); ++ sdl_DATA_FREE(); ++ return stracpy("ERROR: Requested video mode not OK !\n"); ++ } ++ ++ /* check */ ++ if(video_bw_suggest != (unsigned long)sdl_VIDEO_DEPTH) ++ fprintf(stderr, "WARNING: Video driver suggested '%ldbpp' video depth...\n", video_bw_suggest); ++ ++ ++ /* endianness (stolen from directfb.c) */ ++ if (htons (0x1234) == 0x1234) ++ sdl_driver.depth |= 0x100; ++ ++ switch (sdl_driver.depth) { ++ case 33: ++ case 65: ++ case 122: ++ case 130: ++ case 386: ++ case 451: ++ case 195: ++ case 452: ++ case 196: ++ case 708: ++ break; ++ default: ++ sdl_DATA_FREE(); ++ SDL_Quit(); ++ return stracpy("ERROR: Unsupported display pixel format\n"); ++ } ++ ++ /* create cursor :) (need nice one) */ ++#ifdef sdl_HAVE_CURSOR ++ if(sdl_DATA.cursor == NULL) ++ { ++ /* sdl_DATA.cursor = SDL_CreateCursor((void *)arrow, (void *)arrow, 32, 32, 0, 0); ++ */ ++ S_ASSERT(sdl_DATA.cursor != NULL); ++ } ++#endif ++ /* key repeat */ ++ SDL_EnableUNICODE(1); ++ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); ++ ++ ++ sdl_DATA.input_encoding = -1; ++#if defined(HAVE_NL_LANGINFO) && defined(HAVE_LANGINFO_H) && defined(CODESET) ++ { ++ unsigned char *cp; ++ cp = nl_langinfo(CODESET); ++ sdl_DATA.input_encoding = get_cp_index(cp); ++ } ++#endif ++ return NULL; ++} ++ ++/* shutdown driver */ ++static void sdl_shutdown_driver(void) ++{ ++ S_ON_DEBUG_TRACE("in"); ++ sdl_KILL_TIMER(); ++ sdl_DATA_FREE(); ++ SDL_Quit(); ++ return; ++} ++ ++/* create new graph device */ ++static struct graphics_device *sdl_init_device(void) ++{ ++ struct graphics_device *dev = NULL; ++ struct t_sdl_device_data *data = NULL; ++ ++ S_ON_DEBUG_TRACE("in"); ++ ++ /* device data */ ++ data = (struct t_sdl_device_data *) mem_alloc(sizeof(struct t_sdl_device_data)); ++ S_ASSERT(data != NULL); ++ memset(data, 0, sizeof(struct t_sdl_device_data)); ++ ++ /* init video mode */ ++ sdl_SURFACE(data) = SDL_SetVideoMode(sdl_VIDEO_WIDTH, sdl_VIDEO_HEIGHT, sdl_VIDEO_DEPTH, ++ sdl_VIDEO_FLAGS); ++ ++ if(sdl_SURFACE(data) == NULL) ++ return NULL; ++ /* set display alpha */ ++ /* SDL_SetAlpha(sdl_SURFACE(data), SDL_SRCALPHA, 0xff); */ ++ ++ /* re-updating video mode informations */ ++ memcpy(sdl_DATA.video_info, SDL_GetVideoInfo(), (sizeof(SDL_VideoInfo))); ++ ++ /* re-update depth (to use the one we realy got from SDL) */ ++#ifdef __NOT_DEF ++ sdl_driver.depth = ((sdl_DATA.video_info->vfmt->BytesPerPixel & 0x7) | ++ (((sdl_DATA.video_info->vfmt->BitsPerPixel > 24 ? 24 : sdl_DATA.video_info->vfmt->BitsPerPixel) & 0x1F) << 3)); ++#endif ++ S_ON_DEBUG(fprintf(stderr, "display = %d@%d [%d]\n", sdl_DATA.video_info->vfmt->BitsPerPixel, sdl_DATA.video_info->vfmt->BytesPerPixel, sdl_driver.depth)); ++ ++ /* alloc gd */ ++ dev = (struct graphics_device *) mem_alloc(sizeof(struct graphics_device)); ++ S_ASSERT(dev != NULL); ++ ++ /* setup gdS */ ++ dev->size.x1 = 0; ++ dev->size.y1 = 0; ++ dev->size.x2 = sdl_VIDEO_WIDTH; ++ dev->size.y2 = sdl_VIDEO_HEIGHT; ++ dev->clip = dev->size; ++ ++ /*driver */ ++ sdl_GD(data) = dev; ++ ++ /* input encoding flags */ ++ if (sdl_DATA.input_encoding < 0) ++ sdl_driver.flags |= GD_NEED_CODEPAGE; ++ ++ /*driver */ ++ dev->drv = &sdl_driver; ++ dev->driver_data = (void *) data; ++ dev->user_data = NULL; ++ ++ /*set my cursor */ ++ if(sdl_DATA.cursor != NULL) ++ SDL_SetCursor(sdl_DATA.cursor); ++ ++ /*init timer */ ++ sdl_SETUP_TIMER((void *)data); ++ /* print device video info */ ++ /*fprintf(stderr, "VIDEO(%s):\t %dx%dx%dbpp [%d]\n", sdl_DATA.video_drv, ++ sdl_VIDEO_WIDTH, sdl_VIDEO_HEIGHT, sdl_VIDEO_DEPTH, sdl_driver.depth);*/ ++ ++ S_ON_DEBUG_TRACE("out"); ++ return dev; ++} ++ ++/* destroy device */ ++static void sdl_shutdown_device(struct graphics_device *drv) ++{ ++ struct t_sdl_device_data *dev = NULL; ++ ++ S_ON_DEBUG_TRACE("in"); ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ S_ASSERT(dev != NULL); ++ ++ /* unregister bh */ ++ unregister_bottom_half(sdl_update_sc, dev); ++ ++ /* deinit video */ ++ SDL_FreeSurface(sdl_SURFACE(dev)); ++ sdl_SURFACE(dev) = NULL; ++ mem_free(dev); ++ drv->driver_data = NULL; ++ mem_free(drv); ++ S_ON_DEBUG_TRACE("out"); ++ return; ++} ++ ++/* get driver parameters ++ XXX: what is this fx() for ??? */ ++static u_char_t *sdl_get_driver_param(void) ++{ ++ S_ON_DEBUG_TRACE("in"); ++ S_ASSERT(0); ++ return NULL; ++} ++ ++/* GRAPHICS */ ++ ++/* create empty bitmap */ ++static int sdl_get_empty_bitmap(struct bitmap *bmp) ++{ ++ SDL_Surface *s = NULL; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ ++ /* null */ ++ bmp->data = bmp->flags = bmp->user = NULL; ++ bmp->skip = 0; ++ ++ /* alloc surface */ ++ /* FIXED: ignoring byteorder here (taking from video info) */ ++ s = (SDL_Surface *)SDL_CreateRGBSurface(sdl_VIDEO_FLAGS, bmp->x, bmp->y, sdl_VIDEO_DEPTH, ++ sdl_DATA.video_info->vfmt->Rmask, sdl_DATA.video_info->vfmt->Gmask, ++ sdl_DATA.video_info->vfmt->Bmask, sdl_DATA.video_info->vfmt->Amask); ++ S_ASSERT(s != NULL); ++ ++ /* copy data */ ++ bmp->data = (void *)s->pixels; ++ bmp->skip = s->pitch; ++ bmp->flags = (void *)s; ++ ++ /* lock if required */ ++ if(SDL_MUSTLOCK(s)) ++ SDL_LockSurface(s); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return 0; ++} ++ ++/* create filled bitmap */ ++/* ++int sdl_get_filled_bitmap(struct bitmap *bmp, long color) ++{ ++ S_ASSERT(0); ++ return 0; ++} ++*/ ++ ++/* register bitmap */ ++static void sdl_register_bitmap(struct bitmap *bmp) ++{ ++ SDL_Surface *s = NULL; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ ++ /* unlock surface */ ++ s = (SDL_Surface *)bmp->flags; ++ if(SDL_MUSTLOCK(s)) ++ SDL_UnlockSurface(s); ++ /* hide pixel mem */ ++ bmp->data = NULL; ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++ ++/* prepare strip */ ++static void *sdl_prepare_strip(struct bitmap *bmp, int top, int lines) ++{ ++ SDL_Surface *s = NULL; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ ++ /* unlock surface */ ++ s = (SDL_Surface *)bmp->flags; ++ if(SDL_MUSTLOCK(s)) ++ SDL_LockSurface(s); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return (void *)(s->pixels + (top * s->pitch)); ++} ++ ++/* commit strip */ ++static void sdl_commit_strip(struct bitmap *bmp, int top, int lines) ++{ ++ SDL_Surface *s = NULL; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ ++ /* unlock surface */ ++ s = (SDL_Surface *)bmp->flags; ++ if(SDL_MUSTLOCK(s)) ++ SDL_UnlockSurface(s); ++ return; ++} ++ ++/* unregister bitmap */ ++static void sdl_unregister_bitmap(struct bitmap *bmp) ++{ ++ SDL_Surface *s = NULL; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ ++ s = (SDL_Surface *)bmp->flags; ++ S_ASSERT(s != 0); ++ /* delete data */ ++ SDL_FreeSurface(s); ++ /* null data */ ++ bmp->data = NULL; ++ bmp->flags = NULL; ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++/* draw bmp */ ++static void sdl_draw_bitmap(struct graphics_device *drv, struct bitmap *bmp, int x, int y) ++{ ++ SDL_Surface *s = NULL; ++ struct t_sdl_device_data *dev = NULL; ++ SDL_Rect rect; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ s = (SDL_Surface *)bmp->flags; ++ memset(&rect, 0, sizeof(SDL_Rect)); ++ ++ /* blit :) */ ++ rect.x = x; ++ rect.y = y; ++ SDL_BlitSurface(s, NULL, sdl_SURFACE(dev), &rect); ++ sdl_register_update(dev, rect.x, rect.y, rect.w, rect.h, 0); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++/* draw more bmps */ ++static void sdl_draw_bitmaps(struct graphics_device *drv, struct bitmap **bmps, int n, int x, int y) ++{ ++ int i = 0; ++ ++ struct t_sdl_device_data *dev = NULL; ++ SDL_Rect rect; ++ ++ /* FIXME: this functions seems not to be correct !!! */ ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ /* check */ ++ if(n < 1) ++ return; ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ memset(&rect, 0, sizeof(SDL_Rect)); ++ ++ /* blit */ ++ rect.x = x; ++ rect.y = y; ++ for(i = 0; i < n; i++) ++ { SDL_BlitSurface((SDL_Surface *)bmps[i]->flags, NULL, sdl_SURFACE(dev), &rect); ++ rect.x += bmps[i]->x; } ++ /* FIXME: this should care about updating area, and possibly not update everythink */ ++ sdl_register_update(dev, 0, 0, sdl_VIDEO_WIDTH, sdl_VIDEO_HEIGHT, 0); ++ return; ++} ++ ++/* fill some area */ ++static void sdl_fill_area(struct graphics_device *drv, int x1, int y1, int x2, int y2, long color) ++{ ++ struct t_sdl_device_data *dev = NULL; ++ SDL_Rect rect; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ ++ ++ rect.x = x1; ++ rect.y = y1; ++ rect.w = x2 - x1; ++ rect.h = y2 - y1; ++ if(SDL_MUSTLOCK(sdl_SURFACE(dev))) ++ SDL_LockSurface(sdl_SURFACE(dev)); ++ SDL_FillRect(sdl_SURFACE(dev), &rect, color); ++ if(SDL_MUSTLOCK(sdl_SURFACE(dev))) ++ SDL_UnlockSurface(sdl_SURFACE(dev)); ++ /* S_ON_DEBUG(fprintf(stderr, "sdl_fill_area-update(%dx%dx%dx%d)\n", rect.x, rect.y, rect.w, rect.h)); */ ++ sdl_register_update(dev, rect.x, rect.y, rect.w, rect.h, 0); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++/* draw horizontal line */ ++static void sdl_draw_hline(struct graphics_device *drv, int left, int y, int right, long color) ++{ ++ register int i = 0; ++ struct t_sdl_device_data *dev = NULL; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ if(SDL_MUSTLOCK(sdl_SURFACE(dev))) ++ SDL_LockSurface(sdl_SURFACE(dev)); ++ for(i = left; i <= right; i++) ++ sdl_putpixel(sdl_SURFACE(dev), i, y, color); ++ if(SDL_MUSTLOCK(sdl_SURFACE(dev))) ++ SDL_UnlockSurface(sdl_SURFACE(dev)); ++ sdl_register_update(dev, left, y, right - left + 1, 1, 0); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++/* draw vertical line */ ++static void sdl_draw_vline(struct graphics_device *drv, int x, int top, int bottom, long color) ++{ ++ register int i = 0; ++ struct t_sdl_device_data *dev = NULL; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ /* get ptr */ ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ if(SDL_MUSTLOCK(sdl_SURFACE(dev))) ++ SDL_LockSurface(sdl_SURFACE(dev)); ++ for(i = top; i <= bottom; i++) ++ sdl_putpixel(sdl_SURFACE(dev), x, i, color); ++ if(SDL_MUSTLOCK(sdl_SURFACE(dev))) ++ SDL_UnlockSurface(sdl_SURFACE(dev)); ++ ++ sdl_register_update(dev, x, top, 1, bottom - top + 1, 0); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++/* horizontal scroll */ ++static int sdl_hscroll(struct graphics_device *drv, struct rect_set **set, int sc) ++{ ++ struct t_sdl_device_data *dev = NULL; ++ SDL_Rect rect1, rect2; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ ++ /* rect1 */ ++ rect1.x = drv->clip.x1; ++ rect1.y = drv->clip.y1; ++ rect1.w = drv->clip.x2 - rect1.x; ++ rect1.h = drv->clip.y2 - rect1.y; ++ ++ /* rect2 */ ++ rect2.x = drv->clip.x1 + sc; ++ rect2.y = drv->clip.y1; ++#ifdef __NOT_DEF ++ rect2.w = drv->clip.x2 - rect1.x; ++ rect2.h = drv->clip.y2 - rect1.y; ++#endif ++ ++ SDL_BlitSurface(sdl_SURFACE(dev), &rect1, sdl_SURFACE(dev), &rect2); ++ sdl_register_update(dev, rect1.x, rect1.y, rect1.w, rect1.h, 0); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return 1; ++} ++ ++/* vertical scroll */ ++static int sdl_vscroll(struct graphics_device *drv, struct rect_set **set, int sc) ++{ ++ struct t_sdl_device_data *dev = NULL; ++ SDL_Rect rect1, rect2; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ /* get ptr */ ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ ++ /* rect1 */ ++ rect1.x = drv->clip.x1; ++ rect1.y = drv->clip.y1; ++ rect1.w = drv->clip.x2 - rect1.x; ++ rect1.h = drv->clip.y2 - rect1.y; ++ ++ /* rect2 */ ++ rect2.x = drv->clip.x1; ++ rect2.y = drv->clip.y1 + sc; ++#ifdef __NOT_DEF ++ rect2.w = drv->clip.x2 - rect1.x; ++ rect2.h = drv->clip.y2 - rect1.y; ++#endif ++ ++ SDL_BlitSurface(sdl_SURFACE(dev), &rect1, sdl_SURFACE(dev), &rect2); ++ sdl_register_update(dev, rect1.x, rect1.y, rect1.w, rect1.h, 0); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return 1; ++} ++ ++/* set cliping area */ ++static void sdl_set_clip_area(struct graphics_device *drv, struct rect *r) ++{ ++ struct t_sdl_device_data *dev = NULL; ++ SDL_Rect rect; ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ /* get ptr */ ++ dev = (struct t_sdl_device_data *) drv->driver_data; ++ /* set rect */ ++ rect.x = r->x1; ++ rect.y = r->y1; ++ rect.w = r->x2 - r->x1; ++ rect.h = r->y2 - r->y1; ++ /* dev clipp */ ++ drv->clip = *r; ++ /* clipp */ ++ SDL_SetClipRect(sdl_SURFACE(dev), &rect); ++ /* S_ON_DEBUG_TRACE("out"); */ ++ return; ++} ++ ++/* return rgb color */ ++static long sdl_get_color(int rgb) ++{ ++ /* call depth specific function (going like this enables us to use multiple screens with various depths) [someday] */ ++ static long (*gc)(int rgb) = NULL; ++ ++ if(gc == NULL) ++ gc = get_color_fn(sdl_driver.depth); ++ /*return rgb specific*/ ++ if(gc != NULL) ++ return gc(rgb); ++ else ++ return (rgb); ++} ++ ++/* set window title (tittle utf-8 encoded !!!!) */ ++static void sdl_set_title(struct graphics_device *drv, u_char_t *title) ++{ ++ struct conv_table *ct = get_translation_table(utf8_table, sdl_DATA.input_encoding >= 0 ? sdl_DATA.input_encoding:0); ++ unsigned char *t; ++ ++ /* convert tittle */ ++ t = convert_string(ct, title, strlen(title), NULL); ++ ++ /* S_ON_DEBUG_TRACE("in"); */ ++ SDL_WM_SetCaption((const char *)t, NULL); ++ mem_free(t); ++ return; ++} ++ ++ ++ ++/* driver definition data */ ++struct graphics_driver sdl_driver={ ++ "sdl", ++ sdl_init_driver, ++ sdl_init_device, ++ sdl_shutdown_device, ++ sdl_shutdown_driver, ++ sdl_get_driver_param, ++ sdl_get_empty_bitmap, ++ /*sdl_get_filled_bitmap,*/ ++ sdl_register_bitmap, ++ sdl_prepare_strip, ++ sdl_commit_strip, ++ sdl_unregister_bitmap, ++ sdl_draw_bitmap, ++ sdl_draw_bitmaps, ++ sdl_get_color, /* sdl_get_color */ ++ sdl_fill_area, ++ sdl_draw_hline, ++ sdl_draw_vline, ++ sdl_hscroll, ++ sdl_vscroll, ++ sdl_set_clip_area, ++ dummy_block, ++ dummy_unblock, ++ sdl_set_title, /* set_title */ ++ NULL, /* exec */ ++ 0, /* depth (filled in sdl_init_driver function) */ ++ 0, 0, /* size (in X is empty) */ ++ GD_ONLY_1_WINDOW | GD_NOAUTO, /* flags */ ++ 0, /* codepage */ ++ NULL /* shell */ ++}; ++ ++ ++ ++#endif /* GRDRV_SDL */ ++ +--- a/sdl_data.inc 1970-01-01 01:00:00.000000000 +0100 ++++ b/sdl_data.inc 2010-09-25 18:38:37.887567087 +0200 +@@ -0,0 +1,276 @@ ++/** ++ sdl key syms ++ ++ XXX: i'know this is stupit but i'm preparing for some good solution :) ++ ++*/ ++ ++ ++#ifndef _SDL_KEYS_INC ++#define _SDL_KEYS_INC ++ ++struct t_sdl_keysym ++{ ++ unsigned short sym; ++ int key; ++}; ++ ++/* big mapping SDL->LINKS */ ++static struct t_sdl_keysym sdl_keysyms[] = ++{ ++ { SDLK_UNKNOWN ,0 }, ++ { SDLK_FIRST ,0 }, ++ { SDLK_BACKSPACE ,KBD_BS }, ++ { SDLK_TAB ,KBD_TAB }, ++ { SDLK_CLEAR ,12 }, ++ { SDLK_RETURN ,KBD_ENTER }, ++ { SDLK_PAUSE ,19 }, ++ { SDLK_ESCAPE ,KBD_ESC }, ++ { SDLK_SPACE ,32 }, ++ { SDLK_EXCLAIM ,33 }, ++ { SDLK_QUOTEDBL ,34 }, ++ { SDLK_HASH ,35 }, ++ { SDLK_DOLLAR ,36 }, ++ { SDLK_AMPERSAND ,38 }, ++ { SDLK_QUOTE ,39 }, ++ { SDLK_LEFTPAREN ,40 }, ++ { SDLK_RIGHTPAREN ,41 }, ++ { SDLK_ASTERISK ,42 }, ++ { SDLK_PLUS ,43 }, ++ { SDLK_COMMA ,44 }, ++ { SDLK_MINUS ,45 }, ++ { SDLK_PERIOD ,46 }, ++ { SDLK_SLASH ,47 }, ++ { SDLK_0 ,48 }, ++ { SDLK_1 ,49 }, ++ { SDLK_2 ,50 }, ++ { SDLK_3 ,51 }, ++ { SDLK_4 ,52 }, ++ { SDLK_5 ,53 }, ++ { SDLK_6 ,54 }, ++ { SDLK_7 ,55 }, ++ { SDLK_8 ,56 }, ++ { SDLK_9 ,57 }, ++ { SDLK_COLON ,58 }, ++ { SDLK_SEMICOLON ,59 }, ++ { SDLK_LESS ,60 }, ++ { SDLK_EQUALS ,61 }, ++ { SDLK_GREATER ,62 }, ++ { SDLK_QUESTION ,63 }, ++ { SDLK_AT ,64 }, ++ /* ++ Skip uppercase letters ++ */ ++ { SDLK_LEFTBRACKET ,91 }, ++ { SDLK_BACKSLASH ,92 }, ++ { SDLK_RIGHTBRACKET ,93 }, ++ { SDLK_CARET ,94 }, ++ { SDLK_UNDERSCORE ,95 }, ++ { SDLK_BACKQUOTE ,96 }, ++ { SDLK_a ,97 }, ++ { SDLK_b ,98 }, ++ { SDLK_c ,99 }, ++ { SDLK_d ,100 }, ++ { SDLK_e ,101 }, ++ { SDLK_f ,102 }, ++ { SDLK_g ,103 }, ++ { SDLK_h ,104 }, ++ { SDLK_i ,105 }, ++ { SDLK_j ,106 }, ++ { SDLK_k ,107 }, ++ { SDLK_l ,108 }, ++ { SDLK_m ,109 }, ++ { SDLK_n ,110 }, ++ { SDLK_o ,111 }, ++ { SDLK_p ,112 }, ++ { SDLK_q ,113 }, ++ { SDLK_r ,114 }, ++ { SDLK_s ,115 }, ++ { SDLK_t ,116 }, ++ { SDLK_u ,117 }, ++ { SDLK_v ,118 }, ++ { SDLK_w ,119 }, ++ { SDLK_x ,120 }, ++ { SDLK_y ,121 }, ++ { SDLK_z ,122 }, ++ { SDLK_DELETE ,127 }, ++ /* End of ASCII mapped keysyms */ ++ ++ /* International keyboard syms */ ++ { SDLK_WORLD_0 ,160 }, /* 0xA0 */ ++ { SDLK_WORLD_1 ,161 }, ++ { SDLK_WORLD_2 ,162 }, ++ { SDLK_WORLD_3 ,163 }, ++ { SDLK_WORLD_4 ,164 }, ++ { SDLK_WORLD_5 ,165 }, ++ { SDLK_WORLD_6 ,166 }, ++ { SDLK_WORLD_7 ,167 }, ++ { SDLK_WORLD_8 ,168 }, ++ { SDLK_WORLD_9 ,169 }, ++ { SDLK_WORLD_10 ,170 }, ++ { SDLK_WORLD_11 ,171 }, ++ { SDLK_WORLD_12 ,172 }, ++ { SDLK_WORLD_13 ,173 }, ++ { SDLK_WORLD_14 ,174 }, ++ { SDLK_WORLD_15 ,175 }, ++ { SDLK_WORLD_16 ,176 }, ++ { SDLK_WORLD_17 ,177 }, ++ { SDLK_WORLD_18 ,178 }, ++ { SDLK_WORLD_19 ,179 }, ++ { SDLK_WORLD_20 ,180 }, ++ { SDLK_WORLD_21 ,181 }, ++ { SDLK_WORLD_22 ,182 }, ++ { SDLK_WORLD_23 ,183 }, ++ { SDLK_WORLD_24 ,184 }, ++ { SDLK_WORLD_25 ,185 }, ++ { SDLK_WORLD_26 ,186 }, ++ { SDLK_WORLD_27 ,187 }, ++ { SDLK_WORLD_28 ,188 }, ++ { SDLK_WORLD_29 ,189 }, ++ { SDLK_WORLD_30 ,190 }, ++ { SDLK_WORLD_31 ,191 }, ++ { SDLK_WORLD_32 ,192 }, ++ { SDLK_WORLD_33 ,193 }, ++ { SDLK_WORLD_34 ,194 }, ++ { SDLK_WORLD_35 ,195 }, ++ { SDLK_WORLD_36 ,196 }, ++ { SDLK_WORLD_37 ,197 }, ++ { SDLK_WORLD_38 ,198 }, ++ { SDLK_WORLD_39 ,199 }, ++ { SDLK_WORLD_40 ,200 }, ++ { SDLK_WORLD_41 ,201 }, ++ { SDLK_WORLD_42 ,202 }, ++ { SDLK_WORLD_43 ,203 }, ++ { SDLK_WORLD_44 ,204 }, ++ { SDLK_WORLD_45 ,205 }, ++ { SDLK_WORLD_46 ,206 }, ++ { SDLK_WORLD_47 ,207 }, ++ { SDLK_WORLD_48 ,208 }, ++ { SDLK_WORLD_49 ,209 }, ++ { SDLK_WORLD_50 ,210 }, ++ { SDLK_WORLD_51 ,211 }, ++ { SDLK_WORLD_52 ,212 }, ++ { SDLK_WORLD_53 ,213 }, ++ { SDLK_WORLD_54 ,214 }, ++ { SDLK_WORLD_55 ,215 }, ++ { SDLK_WORLD_56 ,216 }, ++ { SDLK_WORLD_57 ,217 }, ++ { SDLK_WORLD_58 ,218 }, ++ { SDLK_WORLD_59 ,219 }, ++ { SDLK_WORLD_60 ,220 }, ++ { SDLK_WORLD_61 ,221 }, ++ { SDLK_WORLD_62 ,222 }, ++ { SDLK_WORLD_63 ,223 }, ++ { SDLK_WORLD_64 ,224 }, ++ { SDLK_WORLD_65 ,225 }, ++ { SDLK_WORLD_66 ,226 }, ++ { SDLK_WORLD_67 ,227 }, ++ { SDLK_WORLD_68 ,228 }, ++ { SDLK_WORLD_69 ,229 }, ++ { SDLK_WORLD_70 ,230 }, ++ { SDLK_WORLD_71 ,231 }, ++ { SDLK_WORLD_72 ,232 }, ++ { SDLK_WORLD_73 ,233 }, ++ { SDLK_WORLD_74 ,234 }, ++ { SDLK_WORLD_75 ,235 }, ++ { SDLK_WORLD_76 ,236 }, ++ { SDLK_WORLD_77 ,237 }, ++ { SDLK_WORLD_78 ,238 }, ++ { SDLK_WORLD_79 ,239 }, ++ { SDLK_WORLD_80 ,240 }, ++ { SDLK_WORLD_81 ,241 }, ++ { SDLK_WORLD_82 ,242 }, ++ { SDLK_WORLD_83 ,243 }, ++ { SDLK_WORLD_84 ,244 }, ++ { SDLK_WORLD_85 ,245 }, ++ { SDLK_WORLD_86 ,246 }, ++ { SDLK_WORLD_87 ,247 }, ++ { SDLK_WORLD_88 ,248 }, ++ { SDLK_WORLD_89 ,249 }, ++ { SDLK_WORLD_90 ,250 }, ++ { SDLK_WORLD_91 ,251 }, ++ { SDLK_WORLD_92 ,252 }, ++ { SDLK_WORLD_93 ,253 }, ++ { SDLK_WORLD_94 ,254 }, ++ { SDLK_WORLD_95 ,255 }, /* 0xFF */ ++ ++ /* Numeric keypad */ ++ { SDLK_KP0 ,256 }, ++ { SDLK_KP1 ,257 }, ++ { SDLK_KP2 ,258 }, ++ { SDLK_KP3 ,259 }, ++ { SDLK_KP4 ,260 }, ++ { SDLK_KP5 ,261 }, ++ { SDLK_KP6 ,262 }, ++ { SDLK_KP7 ,263 }, ++ { SDLK_KP8 ,264 }, ++ { SDLK_KP9 ,265 }, ++ { SDLK_KP_PERIOD ,266 }, ++ { SDLK_KP_DIVIDE ,267 }, ++ { SDLK_KP_MULTIPLY ,268 }, ++ { SDLK_KP_MINUS ,269 }, ++ { SDLK_KP_PLUS ,270 }, ++ { SDLK_KP_ENTER ,KBD_ENTER }, ++ { SDLK_KP_EQUALS ,272 }, ++ ++ /* Arrows + Home/End pad */ ++ { SDLK_UP ,KBD_UP }, ++ { SDLK_DOWN ,KBD_DOWN }, ++ { SDLK_RIGHT ,KBD_RIGHT }, ++ { SDLK_LEFT ,KBD_LEFT }, ++ { SDLK_INSERT ,KBD_INS }, ++ { SDLK_HOME ,KBD_HOME }, ++ { SDLK_END ,KBD_END }, ++ { SDLK_PAGEUP ,KBD_PAGE_UP }, ++ { SDLK_PAGEDOWN ,KBD_PAGE_DOWN }, ++ ++ /* Function keys */ ++ { SDLK_F1 ,KBD_F1 }, ++ { SDLK_F2 ,KBD_F2 }, ++ { SDLK_F3 ,KBD_F3 }, ++ { SDLK_F4 ,KBD_F4 }, ++ { SDLK_F5 ,KBD_F5 }, ++ { SDLK_F6 ,KBD_F6 }, ++ { SDLK_F7 ,KBD_F7 }, ++ { SDLK_F8 ,KBD_F8 }, ++ { SDLK_F9 ,KBD_F9 }, ++ { SDLK_F10 ,KBD_F10 }, ++ { SDLK_F11 ,KBD_F11 }, ++ { SDLK_F12 ,KBD_F12 }, ++ { SDLK_F13 ,294 }, ++ { SDLK_F14 ,295 }, ++ { SDLK_F15 ,296 }, ++ ++ /* Key state modifier keys */ ++ { SDLK_NUMLOCK ,300 }, ++ { SDLK_CAPSLOCK ,301 }, ++ { SDLK_SCROLLOCK ,302 }, ++ { SDLK_RSHIFT ,303 }, ++ { SDLK_LSHIFT ,304 }, ++ { SDLK_RCTRL ,305 }, ++ { SDLK_LCTRL ,306 }, ++ { SDLK_RALT ,307 }, ++ { SDLK_LALT ,308 }, ++ { SDLK_RMETA ,309 }, ++ { SDLK_LMETA ,310 }, ++ { SDLK_LSUPER ,311 }, /* Left "Windows" key */ ++ { SDLK_RSUPER ,312 }, /* Right "Windows" key */ ++ { SDLK_MODE ,313 }, /* "Alt Gr" key */ ++ { SDLK_COMPOSE ,314 }, /* Multi-key compose key */ ++ ++ /* Miscellaneous function keys */ ++ { SDLK_HELP ,315 }, ++ { SDLK_PRINT ,316 }, ++ { SDLK_SYSREQ ,317 }, ++ { SDLK_BREAK ,318 }, ++ { SDLK_MENU ,KBD_F9 }, ++ { SDLK_POWER ,320 }, /* Power Macintosh power key */ ++ { SDLK_EURO ,321 }, /* Some european keyboards */ ++ { SDLK_UNDO ,322 }, /* Atari keyboard has Undo */ ++ ++ /* Add any other keys here */ ++ ++ { SDLK_LAST ,0 }, ++}; ++ ++#endif |
