Added initial support for Nano-X (thanks Hsieh-Fu!)
authorSam Lantinga <slouken@lokigames.com>
Fri, 11 May 2001 01:13:35 +0000
changeset 3057bf11a5efd7
parent 29 a8360daed17d
child 31 667aa8b373a4
Added initial support for Nano-X (thanks Hsieh-Fu!)
README.NanoX
configure.in
docs.html
include/SDL_syswm.h
src/video/Makefile.am
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/nanox/Makefile.am
src/video/nanox/SDL_nxevents.c
src/video/nanox/SDL_nxevents_c.h
src/video/nanox/SDL_nximage.c
src/video/nanox/SDL_nximage_c.h
src/video/nanox/SDL_nxmodes.c
src/video/nanox/SDL_nxmodes_c.h
src/video/nanox/SDL_nxmouse.c
src/video/nanox/SDL_nxmouse_c.h
src/video/nanox/SDL_nxvideo.c
src/video/nanox/SDL_nxvideo.h
src/video/nanox/SDL_nxwm.c
src/video/nanox/SDL_nxwm_c.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/README.NanoX	Fri May 11 01:13:35 2001 +0000
     1.3 @@ -0,0 +1,81 @@
     1.4 +  =================================================================
     1.5 +  Patch version 0.8 of SDL(Simple DirectMedia Layer) for Nano-X API
     1.6 +  =================================================================
     1.7 +  
     1.8 +  Author: Hsieh-Fu Tsai, clare@setabox.com
     1.9 +
    1.10 +  There are two patch files in this package. 
    1.11 +
    1.12 +  1. The first patch file, nanox.patch, is to fix a bug in Nano-X. 
    1.13 +     This patch is proposed by Gary James (gjames@twcny.rr.com).
    1.14 +
    1.15 +  It fixes the client side GrClose(). In the original version, 
    1.16 +  GrOpen() can only be called once. When the GrOpen() is called at 
    1.17 +  the second time, the program will terminate. In order to prevent
    1.18 +  this situation, we need to insert "nxSocket = -1" after 
    1.19 +  "close(nxSocket)" in GrClose(). If you do not have this problem,
    1.20 +  you may skip this step. 
    1.21 +
    1.22 +  =============
    1.23 +  Quick Install 
    1.24 +  =============
    1.25 +
    1.26 +  1. ./configure --disable-video-x11 --disable-video-fbcon \ 
    1.27 +       --enable-video-nanox \ 
    1.28 +       --with-nanox-pixel-type=[rgb/0888/888/565/555/332/pal] 
    1.29 +  2. make clean 
    1.30 +  3. make 
    1.31 +  4. make install (as root) 
    1.32 +
    1.33 +  ============
    1.34 +  Nitty-gritty 
    1.35 +  ============
    1.36 +
    1.37 +  --with-nanox-pixel-type=[rgb/0888/888/565/555/332/pal] 
    1.38 +
    1.39 +  If the wrong pixel type is used, the program will crash when the 
    1.40 +  sub-routine updates the screen. This option depends on SCREEN_PIXTYPE 
    1.41 +  which is defined in Microwin0.89pre7/src/config. SCREEN_PIXTYPE 
    1.42 +  is used to define the pixel type in Microwindows/Nano-X. 
    1.43 +  I only test the program when the pixel type is in "rgb" 
    1.44 +  (Microwin under X11) or "888" (framebuffer in 24-bit).
    1.45 +
    1.46 +  --enable-nanox-debug           Show debug messages 
    1.47 +  --enable-nanox-share-memory    Use shared-memory to speed up 
    1.48 +
    1.49 +  =============================================
    1.50 +  Some programs can be used to test this patch. 
    1.51 +  =============================================
    1.52 +
    1.53 +  1. http://www.cs.berkeley.edu/~weimer/atris (a tetris-like game) 
    1.54 +  2. http://www.libsdl.org/projects/newvox/
    1.55 +  3. http://www.libsdl.org/projects/xflame/
    1.56 +  4. http://www.libsdl.org/projects/optimum/ 
    1.57 +  5. http://www.gnugeneration.com/software/loop/ 
    1.58 +    
    1.59 +  =========
    1.60 +  Todo List 
    1.61 +  =========
    1.62 +
    1.63 +  1. Create hardware surface
    1.64 +  2. Create YUVOverlay on hardware
    1.65 +  3. Use OpenGL
    1.66 +  4. Gamma correction
    1.67 +  5. Hide/Change mouse pointer
    1.68 +
    1.69 +  =====================
    1.70 +  Supporting Institutes
    1.71 +  =====================
    1.72 +  
    1.73 +  Many thanks to go to Setabox Co., Ltd. and CML (Communication and
    1.74 +  Multimedia Laboratory, http://www.cmlab.csie.ntu.edu.tw/) in the 
    1.75 +  Department of Computer Science and Information Engineering of 
    1.76 +  National Taiwan University for supporting this porting project.
    1.77 +  
    1.78 +  ===================
    1.79 +  Contact Information
    1.80 +  ===================
    1.81 +
    1.82 +  Welcome to give me any suggestion and to report bugs.
    1.83 +  My e-mail address : clare@setabox.com or niky@cmlab.csie.ntu.edu.tw
    1.84 +  
     2.1 --- a/configure.in	Fri May 11 00:35:31 2001 +0000
     2.2 +++ b/configure.in	Fri May 11 01:13:35 2001 +0000
     2.3 @@ -403,6 +403,49 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +dnl Find the nanox include and library directories
     2.8 +CheckNANOX()
     2.9 +{
    2.10 +	AC_ARG_ENABLE(video-nanox,
    2.11 +		[  --enable-video-nanox use nanox video driver [default=no]],
    2.12 +	        , enable_video_nanox=no)
    2.13 +	AC_ARG_ENABLE(nanox-debug,  
    2.14 +		[  --enable-nanox-debug print debug messages [default=no]],
    2.15 +		, enable_nanox_debug=no)
    2.16 +	AC_ARG_ENABLE(nanox-share-memory,  
    2.17 +		[  --enable-nanox-share-memory use share memory [default=no]],
    2.18 +		, enable_nanox_share_memory=no)
    2.19 +
    2.20 +	AC_ARG_WITH(nanox_pixel_type, 
    2.21 +		[  --with-nanox-pixel-type=[rgb/0888/888/565/555/332/pal]])
    2.22 +
    2.23 +	if test x$enable_video = xyes -a x$enable_video_nanox = xyes; then
    2.24 +		if test x$enable_nanox_debug = xyes; then
    2.25 +			CFLAGS="$CFLAGS -DENABLE_NANOX_DEBUG"
    2.26 +		fi
    2.27 +
    2.28 +		if test x$enable_nanox_share_memory = xyes; then
    2.29 +			CFLAGS="$CFLAGS -DNANOX_SHARE_MEMORY"
    2.30 +		fi
    2.31 +
    2.32 +		case "$with_nanox_pixel_type" in
    2.33 +			 rgb) CFLAGS="$CFLAGS -DNANOX_PIXEL_RGB" ;;
    2.34 +			0888) CFLAGS="$CFLAGS -DNANOX_PIXEL_0888" ;;
    2.35 +			 888) CFLAGS="$CFLAGS -DNANOX_PIXEL_888"  ;;
    2.36 +			 565) CFLAGS="$CFLAGS -DNANOX_PIXEL_565"  ;;
    2.37 +			 555) CFLAGS="$CFLAGS -DNANOX_PIXEL_555"  ;;
    2.38 +			 332) CFLAGS="$CFLAGS -DNANOX_PIXEL_332"  ;;
    2.39 +			 pal) CFLAGS="$CFLAGS -DNANOX_PIXEL_PAL"  ;;
    2.40 +			   *) AC_MSG_ERROR([Invalid nanox_pixel_type]);;
    2.41 +		esac
    2.42 +
    2.43 +		CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_NANOX"
    2.44 +		SYSTEM_LIBS="$SYSTEM_LIBS -lnano-X"
    2.45 +		VIDEO_SUBDIRS="$VIDEO_SUBDIRS nanox"
    2.46 +		VIDEO_DRIVERS="$VIDEO_DRIVERS nanox/libvideo_nanox.la"
    2.47 +	fi
    2.48 +}
    2.49 +
    2.50  dnl Find the X11 include and library directories
    2.51  CheckX11()
    2.52  {
    2.53 @@ -1042,6 +1085,7 @@
    2.54          CheckESD
    2.55          CheckNAS
    2.56          CheckX11
    2.57 +        CheckNANOX
    2.58          CheckDGA
    2.59          CheckFBCON
    2.60          CheckGGI
    2.61 @@ -1921,6 +1965,7 @@
    2.62  src/video/cybergfx/Makefile
    2.63  src/video/x11/Makefile
    2.64  src/video/dga/Makefile
    2.65 +src/video/nanox/Makefile
    2.66  src/video/fbcon/Makefile
    2.67  src/video/ggi/Makefile
    2.68  src/video/maccommon/Makefile
     3.1 --- a/docs.html	Fri May 11 00:35:31 2001 +0000
     3.2 +++ b/docs.html	Fri May 11 01:13:35 2001 +0000
     3.3 @@ -16,6 +16,7 @@
     3.4  Major changes since SDL 1.0.0:
     3.5  </H2>
     3.6  <UL>
     3.7 +	<LI> 1.2.1: Added initial support for Nano-X (thanks Hsieh-Fu!)
     3.8  	<LI> 1.2.1: Fixed endian detection on IA64 architectures (thanks Bill!)
     3.9  	<LI> 1.2.1: Added --disable-dga configure option to disable DGA
    3.10  	<LI> 1.2.1: Fixed stuck keys when changing the video mode
     4.1 --- a/include/SDL_syswm.h	Fri May 11 00:35:31 2001 +0000
     4.2 +++ b/include/SDL_syswm.h	Fri May 11 01:13:35 2001 +0000
     4.3 @@ -50,7 +50,7 @@
     4.4  
     4.5  /* This is the structure for custom window manager events */
     4.6  #if (defined(unix) || defined(__unix__) || defined(_AIX)) && \
     4.7 -    (!defined(DISABLE_X11) && !defined(__CYGWIN32__))
     4.8 +    (defined(ENABLE_X11) && !defined(__CYGWIN32__))
     4.9   /* AIX is unix, of course, but the native compiler CSet doesn't define unix */
    4.10  #include <X11/Xlib.h>
    4.11  #include <X11/Xatom.h>
    4.12 @@ -95,6 +95,21 @@
    4.13  	} info;
    4.14  } SDL_SysWMinfo;
    4.15  
    4.16 +#elif defined(ENABLE_NANOX)
    4.17 +#include <microwin/nano-X.h>
    4.18 +
    4.19 +/* The generic custom event structure */
    4.20 +struct SDL_SysWMmsg {
    4.21 +	SDL_version version;
    4.22 +	int data;
    4.23 +};
    4.24 +
    4.25 +/* The windows custom window manager information structure */
    4.26 +typedef struct {
    4.27 +	SDL_version version ;
    4.28 +	GR_WINDOW_ID window ;	/* The display window */
    4.29 +} SDL_SysWMinfo;
    4.30 +
    4.31  #elif defined(WIN32)
    4.32  #include <windows.h>
    4.33  
     5.1 --- a/src/video/Makefile.am	Fri May 11 00:35:31 2001 +0000
     5.2 +++ b/src/video/Makefile.am	Fri May 11 01:13:35 2001 +0000
     5.3 @@ -5,7 +5,7 @@
     5.4  
     5.5  # Define which subdirectories need to be built
     5.6  SUBDIRS = @VIDEO_SUBDIRS@
     5.7 -DIST_SUBDIRS = dummy x11 dga fbcon svga ggi aalib \
     5.8 +DIST_SUBDIRS = dummy x11 dga nanox fbcon svga ggi aalib \
     5.9                 wincommon windib windx5 \
    5.10                 maccommon macdsp macrom bwindow photon cybergfx
    5.11  
     6.1 --- a/src/video/SDL_sysvideo.h	Fri May 11 00:35:31 2001 +0000
     6.2 +++ b/src/video/SDL_sysvideo.h	Fri May 11 01:13:35 2001 +0000
     6.3 @@ -331,6 +331,9 @@
     6.4  #ifdef ENABLE_DGA
     6.5  extern VideoBootStrap DGA_bootstrap;
     6.6  #endif
     6.7 +#ifdef ENABLE_NANOX
     6.8 +extern VideoBootStrap NX_bootstrap;
     6.9 +#endif
    6.10  #ifdef ENABLE_FBCON
    6.11  extern VideoBootStrap FBCON_bootstrap;
    6.12  #endif
     7.1 --- a/src/video/SDL_video.c	Fri May 11 00:35:31 2001 +0000
     7.2 +++ b/src/video/SDL_video.c	Fri May 11 01:13:35 2001 +0000
     7.3 @@ -51,6 +51,9 @@
     7.4  #ifdef ENABLE_DGA
     7.5  	&DGA_bootstrap,
     7.6  #endif
     7.7 +#ifdef ENABLE_NANOX
     7.8 +	&NX_bootstrap,
     7.9 +#endif
    7.10  #ifdef ENABLE_FBCON
    7.11  	&FBCON_bootstrap,
    7.12  #endif
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/nanox/Makefile.am	Fri May 11 01:13:35 2001 +0000
     8.3 @@ -0,0 +1,20 @@
     8.4 +
     8.5 +## Makefile.am for SDL using the nanox video driver
     8.6 +
     8.7 +noinst_LTLIBRARIES = libvideo_nanox.la
     8.8 +libvideo_nanox_la_SOURCES = $(NANOX_SRCS)
     8.9 +
    8.10 +# The SDL nanox video driver sources
    8.11 +NANOX_SRCS =         \
    8.12 +    SDL_nxmodes.c    \
    8.13 +    SDL_nxmodes_c.h  \
    8.14 +    SDL_nxmouse.c    \
    8.15 +    SDL_nxmouse_c.h  \
    8.16 +    SDL_nxvideo.c    \
    8.17 +    SDL_nxvideo.h    \
    8.18 +    SDL_nxwm.c       \
    8.19 +    SDL_nxwm_c.h     \
    8.20 +    SDL_nxevents.c   \
    8.21 +    SDL_nxevents_c.h \
    8.22 +    SDL_nximage.c    \
    8.23 +    SDL_nximage_c.h
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/nanox/SDL_nxevents.c	Fri May 11 01:13:35 2001 +0000
     9.3 @@ -0,0 +1,364 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     9.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
     9.8 +
     9.9 +    This library is free software; you can redistribute it and/or
    9.10 +    modify it under the terms of the GNU Library General Public
    9.11 +    License as published by the Free Software Foundation; either
    9.12 +    version 2 of the License, or (at your option) any later version.
    9.13 +
    9.14 +    This library is distributed in the hope that it will be useful,
    9.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.17 +    Library General Public License for more details.
    9.18 +
    9.19 +    You should have received a copy of the GNU Library General Public
    9.20 +    License along with this library; if not, write to the Free
    9.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.22 +
    9.23 +    Sam Lantinga
    9.24 +    slouken@devolution.com
    9.25 +    
    9.26 +    Hsieh-Fu Tsai
    9.27 +    clare@setabox.com
    9.28 +*/
    9.29 +
    9.30 +#include "SDL_keysym.h"
    9.31 +#include "SDL_events_c.h"
    9.32 +
    9.33 +#include "SDL_nxevents_c.h"
    9.34 +#include "SDL_nximage_c.h"
    9.35 +
    9.36 +// The translation tables from a nanox keysym to a SDL keysym
    9.37 +static SDLKey NX_NONASCII_keymap [MWKEY_LAST + 1] ;
    9.38 +
    9.39 +void NX_InitOSKeymap (_THIS)
    9.40 +{
    9.41 +    int i ;
    9.42 +
    9.43 +    Dprintf ("enter NX_InitOSKeymap\n") ;
    9.44 +
    9.45 +    // Map the nanox scancodes to SDL keysyms
    9.46 +    for (i = 0; i < SDL_TABLESIZE (NX_NONASCII_keymap); ++ i)
    9.47 +        NX_NONASCII_keymap [i] = SDLK_UNKNOWN ;
    9.48 +
    9.49 +    NX_NONASCII_keymap [MWKEY_LEFT        & 0xFF] = SDLK_LEFT ;
    9.50 +    NX_NONASCII_keymap [MWKEY_RIGHT       & 0xFF] = SDLK_RIGHT ;
    9.51 +    NX_NONASCII_keymap [MWKEY_UP          & 0xFF] = SDLK_UP ;
    9.52 +    NX_NONASCII_keymap [MWKEY_DOWN        & 0xFF] = SDLK_DOWN ;
    9.53 +    NX_NONASCII_keymap [MWKEY_INSERT      & 0xFF] = SDLK_INSERT ;
    9.54 +    NX_NONASCII_keymap [MWKEY_DELETE      & 0xFF] = SDLK_DELETE ;
    9.55 +    NX_NONASCII_keymap [MWKEY_HOME        & 0xFF] = SDLK_HOME ;
    9.56 +    NX_NONASCII_keymap [MWKEY_END         & 0xFF] = SDLK_END ;
    9.57 +    NX_NONASCII_keymap [MWKEY_PAGEUP      & 0xFF] = SDLK_PAGEUP ;
    9.58 +    NX_NONASCII_keymap [MWKEY_PAGEDOWN    & 0xFF] = SDLK_PAGEDOWN ;
    9.59 +
    9.60 +    NX_NONASCII_keymap [MWKEY_KP0         & 0xFF] = SDLK_KP0 ;
    9.61 +    NX_NONASCII_keymap [MWKEY_KP1         & 0xFF] = SDLK_KP1 ;
    9.62 +    NX_NONASCII_keymap [MWKEY_KP2         & 0xFF] = SDLK_KP2 ;
    9.63 +    NX_NONASCII_keymap [MWKEY_KP3         & 0xFF] = SDLK_KP3 ;
    9.64 +    NX_NONASCII_keymap [MWKEY_KP4         & 0xFF] = SDLK_KP4 ;
    9.65 +    NX_NONASCII_keymap [MWKEY_KP5         & 0xFF] = SDLK_KP5 ;
    9.66 +    NX_NONASCII_keymap [MWKEY_KP6         & 0xFF] = SDLK_KP6 ;
    9.67 +    NX_NONASCII_keymap [MWKEY_KP7         & 0xFF] = SDLK_KP7 ;
    9.68 +    NX_NONASCII_keymap [MWKEY_KP8         & 0xFF] = SDLK_KP8 ;
    9.69 +    NX_NONASCII_keymap [MWKEY_KP9         & 0xFF] = SDLK_KP9 ;
    9.70 +    NX_NONASCII_keymap [MWKEY_KP_PERIOD   & 0xFF] = SDLK_KP_PERIOD ;
    9.71 +    NX_NONASCII_keymap [MWKEY_KP_DIVIDE   & 0xFF] = SDLK_KP_DIVIDE ;
    9.72 +    NX_NONASCII_keymap [MWKEY_KP_MULTIPLY & 0xFF] = SDLK_KP_MULTIPLY ;
    9.73 +    NX_NONASCII_keymap [MWKEY_KP_MINUS    & 0xFF] = SDLK_KP_MINUS ;
    9.74 +    NX_NONASCII_keymap [MWKEY_KP_PLUS     & 0xFF] = SDLK_KP_PLUS ;
    9.75 +    NX_NONASCII_keymap [MWKEY_KP_ENTER    & 0xFF] = SDLK_KP_ENTER ;
    9.76 +    NX_NONASCII_keymap [MWKEY_KP_EQUALS   & 0xFF] = SDLK_KP_EQUALS ;
    9.77 +
    9.78 +    NX_NONASCII_keymap [MWKEY_F1          & 0xFF] = SDLK_F1 ;
    9.79 +    NX_NONASCII_keymap [MWKEY_F2          & 0xFF] = SDLK_F2 ;
    9.80 +    NX_NONASCII_keymap [MWKEY_F3          & 0xFF] = SDLK_F3 ;
    9.81 +    NX_NONASCII_keymap [MWKEY_F4          & 0xFF] = SDLK_F4 ;
    9.82 +    NX_NONASCII_keymap [MWKEY_F5          & 0xFF] = SDLK_F5 ;
    9.83 +    NX_NONASCII_keymap [MWKEY_F6          & 0xFF] = SDLK_F6 ;
    9.84 +    NX_NONASCII_keymap [MWKEY_F7          & 0xFF] = SDLK_F7 ;
    9.85 +    NX_NONASCII_keymap [MWKEY_F8          & 0xFF] = SDLK_F8 ;
    9.86 +    NX_NONASCII_keymap [MWKEY_F9          & 0xFF] = SDLK_F9 ;
    9.87 +    NX_NONASCII_keymap [MWKEY_F10         & 0xFF] = SDLK_F10 ;
    9.88 +    NX_NONASCII_keymap [MWKEY_F11         & 0xFF] = SDLK_F11 ;
    9.89 +    NX_NONASCII_keymap [MWKEY_F12         & 0xFF] = SDLK_F12 ;
    9.90 +
    9.91 +    NX_NONASCII_keymap [MWKEY_NUMLOCK     & 0xFF] = SDLK_NUMLOCK ;
    9.92 +    NX_NONASCII_keymap [MWKEY_CAPSLOCK    & 0xFF] = SDLK_CAPSLOCK ;
    9.93 +    NX_NONASCII_keymap [MWKEY_SCROLLOCK   & 0xFF] = SDLK_SCROLLOCK ;
    9.94 +    NX_NONASCII_keymap [MWKEY_LSHIFT      & 0xFF] = SDLK_LSHIFT ;
    9.95 +    NX_NONASCII_keymap [MWKEY_RSHIFT      & 0xFF] = SDLK_RSHIFT ;
    9.96 +    NX_NONASCII_keymap [MWKEY_LCTRL       & 0xFF] = SDLK_LCTRL ;
    9.97 +    NX_NONASCII_keymap [MWKEY_RCTRL       & 0xFF] = SDLK_RCTRL ;
    9.98 +    NX_NONASCII_keymap [MWKEY_LALT        & 0xFF] = SDLK_LALT ;
    9.99 +    NX_NONASCII_keymap [MWKEY_RALT        & 0xFF] = SDLK_RALT ;
   9.100 +    NX_NONASCII_keymap [MWKEY_LMETA       & 0xFF] = SDLK_LMETA ;
   9.101 +    NX_NONASCII_keymap [MWKEY_RMETA       & 0xFF] = SDLK_RMETA ;
   9.102 +    NX_NONASCII_keymap [MWKEY_ALTGR       & 0xFF] = SDLK_MODE ;
   9.103 +
   9.104 +    NX_NONASCII_keymap [MWKEY_PRINT       & 0xFF] = SDLK_PRINT ;
   9.105 +    NX_NONASCII_keymap [MWKEY_SYSREQ      & 0xFF] = SDLK_SYSREQ ;
   9.106 +    NX_NONASCII_keymap [MWKEY_PAUSE       & 0xFF] = SDLK_PAUSE ;
   9.107 +    NX_NONASCII_keymap [MWKEY_BREAK       & 0xFF] = SDLK_BREAK ;
   9.108 +    NX_NONASCII_keymap [MWKEY_MENU        & 0xFF] = SDLK_MENU ;
   9.109 +
   9.110 +    Dprintf ("leave NX_InitOSKeymap\n") ;
   9.111 +}
   9.112 +
   9.113 +SDL_keysym * NX_TranslateKey (GR_EVENT_KEYSTROKE * keystroke, SDL_keysym * keysym)
   9.114 +{
   9.115 +    GR_KEY ch = keystroke -> ch ;
   9.116 +
   9.117 +    Dprintf ("enter NX_TranslateKey\n") ;
   9.118 +
   9.119 +    keysym -> scancode = keystroke -> scancode ;
   9.120 +    keysym -> sym = SDLK_UNKNOWN ;
   9.121 +
   9.122 +    if (ch & MWKEY_NONASCII_MASK) {
   9.123 +        keysym -> sym = NX_NONASCII_keymap [ch & 0xFF] ;
   9.124 +    } else {
   9.125 +        keysym -> sym = ch & 0x7F ;
   9.126 +    }
   9.127 +
   9.128 +    keysym -> mod = KMOD_NONE ;
   9.129 +    
   9.130 +#if 1   //   Retrieve more mode information
   9.131 +    {
   9.132 +        GR_KEYMOD   mod = keystroke -> modifiers ;
   9.133 +
   9.134 +        if (mod & MWKMOD_LSHIFT)
   9.135 +            keysym -> mod |= KMOD_LSHIFT ;
   9.136 +        if (mod & MWKMOD_RSHIFT)
   9.137 +            keysym -> mod |= KMOD_RSHIFT ;
   9.138 +        if (mod & MWKMOD_LCTRL)
   9.139 +            keysym -> mod |= KMOD_LCTRL ;
   9.140 +        if (mod & MWKMOD_RCTRL)
   9.141 +            keysym -> mod |= KMOD_RCTRL ;
   9.142 +        if (mod & MWKMOD_LALT)
   9.143 +            keysym -> mod |= KMOD_LALT ;
   9.144 +        if (mod & MWKMOD_RALT)
   9.145 +            keysym -> mod |= KMOD_RALT ;
   9.146 +        if (mod & MWKMOD_LMETA)
   9.147 +            keysym -> mod |= KMOD_LMETA ;
   9.148 +        if (mod & MWKMOD_RMETA)
   9.149 +            keysym -> mod |= KMOD_RMETA ;
   9.150 +        if (mod & MWKMOD_NUM)
   9.151 +            keysym -> mod |= KMOD_NUM ;
   9.152 +        if (mod & MWKMOD_CAPS)
   9.153 +            keysym -> mod |= KMOD_CAPS ;
   9.154 +        if (mod & MWKMOD_ALTGR)
   9.155 +            keysym -> mod |= KMOD_MODE ;
   9.156 +    }
   9.157 +#endif
   9.158 +
   9.159 +    keysym -> unicode = ch ;
   9.160 +
   9.161 +    Dprintf ("leave NX_TranslateKey\n") ;
   9.162 +    return keysym ;
   9.163 +}
   9.164 +
   9.165 +static int check_boundary (_THIS, int x, int y)
   9.166 +{
   9.167 +    if (x < OffsetX || y < OffsetY || x > OffsetX + this -> screen -> w ||
   9.168 +        y > OffsetY + this -> screen -> h)
   9.169 +        return 0 ;
   9.170 +            
   9.171 +    return 1 ;
   9.172 +}
   9.173 +
   9.174 +void NX_PumpEvents (_THIS)
   9.175 +{
   9.176 +    GR_EVENT         event ;
   9.177 +    static GR_BUTTON last_button_down = 0 ;
   9.178 +
   9.179 +    GrCheckNextEvent (& event) ;
   9.180 +    while (event.type != GR_EVENT_TYPE_NONE) {
   9.181 +
   9.182 +        // dispatch event
   9.183 +        switch (event.type) {
   9.184 +            case GR_EVENT_TYPE_MOUSE_ENTER :
   9.185 +            {
   9.186 +                Dprintf ("mouse enter\n") ;
   9.187 +                SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ;
   9.188 +                break ;
   9.189 +            }
   9.190 +
   9.191 +            case GR_EVENT_TYPE_MOUSE_EXIT :
   9.192 +            {
   9.193 +                Dprintf ("mouse exit\n") ;
   9.194 +                SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ;
   9.195 +                break ;
   9.196 +            }
   9.197 +
   9.198 +            case GR_EVENT_TYPE_FOCUS_IN :
   9.199 +            {
   9.200 +                Dprintf ("focus in\n") ;
   9.201 +                SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS) ;
   9.202 +                break ;
   9.203 +            }
   9.204 +
   9.205 +            case GR_EVENT_TYPE_FOCUS_OUT :
   9.206 +            {
   9.207 +                Dprintf ("focus out\n") ;
   9.208 +                SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS) ;
   9.209 +                break ;
   9.210 +            }
   9.211 +
   9.212 +            case GR_EVENT_TYPE_MOUSE_MOTION :
   9.213 +            {               
   9.214 +                Dprintf ("mouse motion\n") ;
   9.215 +
   9.216 +                if (SDL_VideoSurface) {
   9.217 +                    if (currently_fullscreen) {
   9.218 +                        if (check_boundary (this, event.button.x, event.button.y)) {
   9.219 +                            SDL_PrivateMouseMotion (0, 0, event.button.x - OffsetX, 
   9.220 +                                event.button.y - OffsetY) ;
   9.221 +                        }
   9.222 +                    } else {
   9.223 +                        SDL_PrivateMouseMotion (0, 0, event.button.x, event.button.y) ;
   9.224 +                    }
   9.225 +                }
   9.226 +                break ;
   9.227 +            }
   9.228 +
   9.229 +            case GR_EVENT_TYPE_BUTTON_DOWN :
   9.230 +            {
   9.231 +                int button = event.button.buttons ;
   9.232 +                
   9.233 +                Dprintf ("button down\n") ;
   9.234 +
   9.235 +                switch (button) {
   9.236 +                    case MWBUTTON_L :
   9.237 +                        button = 1 ;
   9.238 +                        break ;
   9.239 +                    case MWBUTTON_M :
   9.240 +                        button = 2 ;
   9.241 +                        break ;
   9.242 +                    case MWBUTTON_R :
   9.243 +                        button = 3 ;
   9.244 +                        break ;
   9.245 +                    default :
   9.246 +                        button = 0 ;
   9.247 +                }
   9.248 +                last_button_down = button ;
   9.249 +                
   9.250 +                if (currently_fullscreen) {
   9.251 +                    if (check_boundary (this, event.button.x, event.button.y)) {
   9.252 +                        SDL_PrivateMouseButton (SDL_PRESSED, button, 
   9.253 +                            event.button.x - OffsetX, event.button.y - OffsetY) ;
   9.254 +                    }
   9.255 +                } else {
   9.256 +                    SDL_PrivateMouseButton (SDL_PRESSED, button, 
   9.257 +                        event.button.x, event.button.y) ;
   9.258 +                }
   9.259 +                break ;
   9.260 +            }
   9.261 +
   9.262 +            // do not konw which button is released
   9.263 +            case GR_EVENT_TYPE_BUTTON_UP :
   9.264 +            {   
   9.265 +                Dprintf ("button up\n") ;
   9.266 +
   9.267 +                if (currently_fullscreen) {
   9.268 +                    if (check_boundary (this, event.button.x, event.button.y)) {
   9.269 +                        SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, 
   9.270 +                            event.button.x - OffsetX, event.button.y - OffsetY) ;
   9.271 +                    }
   9.272 +                } else {
   9.273 +                    SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, 
   9.274 +                        event.button.x, event.button.y) ;
   9.275 +                }
   9.276 +                last_button_down = 0 ;
   9.277 +                break ;
   9.278 +            }
   9.279 +
   9.280 +            case GR_EVENT_TYPE_KEY_DOWN :
   9.281 +            {
   9.282 +                SDL_keysym keysym ;
   9.283 +
   9.284 +                Dprintf ("key down\n") ;
   9.285 +                SDL_PrivateKeyboard (SDL_PRESSED,
   9.286 +                    NX_TranslateKey (& event.keystroke, & keysym)) ;
   9.287 +                break ;
   9.288 +            }
   9.289 +
   9.290 +            case GR_EVENT_TYPE_KEY_UP :
   9.291 +            {
   9.292 +                SDL_keysym keysym ;
   9.293 +
   9.294 +                Dprintf ("key up\n") ;
   9.295 +                SDL_PrivateKeyboard (SDL_RELEASED,
   9.296 +                    NX_TranslateKey (& event.keystroke, & keysym)) ;
   9.297 +                break ;
   9.298 +            }
   9.299 +
   9.300 +            case GR_EVENT_TYPE_CLOSE_REQ :
   9.301 +            {
   9.302 +                Dprintf ("close require\n") ;
   9.303 +                SDL_PrivateQuit () ;
   9.304 +                break ;
   9.305 +            }
   9.306 +
   9.307 +            case GR_EVENT_TYPE_EXPOSURE :
   9.308 +            {
   9.309 +                Dprintf ("event_type_exposure\n") ;
   9.310 +                if (SDL_VideoSurface) {
   9.311 +                    NX_RefreshDisplay (this) ;//, & event.exposure) ;
   9.312 +                }
   9.313 +                break ;
   9.314 +            }
   9.315 +
   9.316 +            case GR_EVENT_TYPE_UPDATE :
   9.317 +            {
   9.318 +                switch (event.update.utype) {
   9.319 +                    case GR_UPDATE_MAP :
   9.320 +                    {
   9.321 +                        Dprintf ("GR_UPDATE_MAP\n") ;
   9.322 +                        // If we're not active, make ourselves active
   9.323 +                        if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
   9.324 +                            // Send an internal activate event
   9.325 +                            SDL_PrivateAppActive (1, SDL_APPACTIVE) ;
   9.326 +                        }
   9.327 +                        if (SDL_VideoSurface) {
   9.328 +                            NX_RefreshDisplay (this) ;
   9.329 +                        }
   9.330 +                        break ;
   9.331 +                    }
   9.332 +                    
   9.333 +                    case GR_UPDATE_UNMAP :
   9.334 +                    case GR_UPDATE_UNMAPTEMP :
   9.335 +                    {
   9.336 +                        Dprintf ("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n") ;
   9.337 +                        // If we're active, make ourselves inactive
   9.338 +                        if (SDL_GetAppState () & SDL_APPACTIVE) {
   9.339 +                            // Send an internal deactivate event
   9.340 +                            SDL_PrivateAppActive (0, SDL_APPACTIVE | SDL_APPINPUTFOCUS) ;
   9.341 +                        }
   9.342 +                        break ; 
   9.343 +                    }
   9.344 +                    
   9.345 +                    case GR_UPDATE_SIZE :
   9.346 +                    {
   9.347 +                        Dprintf ("GR_UPDATE_SIZE\n") ;
   9.348 +                        SDL_PrivateResize (event.update.width, event.update.height) ;
   9.349 +                        break ; 
   9.350 +                    }
   9.351 +                    
   9.352 +                    default :
   9.353 +                        Dprintf ("unknown GR_EVENT_TYPE_UPDATE\n") ;
   9.354 +                        break ; 
   9.355 +                }
   9.356 +                break ; 
   9.357 +            }
   9.358 +                
   9.359 +            default :
   9.360 +            {
   9.361 +                Dprintf ("pump event default\n") ;
   9.362 +            }
   9.363 +        }
   9.364 +
   9.365 +        GrCheckNextEvent (& event) ;
   9.366 +    }
   9.367 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/nanox/SDL_nxevents_c.h	Fri May 11 01:13:35 2001 +0000
    10.3 @@ -0,0 +1,31 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    10.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    10.8 +
    10.9 +    This library is free software; you can redistribute it and/or
   10.10 +    modify it under the terms of the GNU Library General Public
   10.11 +    License as published by the Free Software Foundation; either
   10.12 +    version 2 of the License, or (at your option) any later version.
   10.13 +
   10.14 +    This library is distributed in the hope that it will be useful,
   10.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.17 +    Library General Public License for more details.
   10.18 +
   10.19 +    You should have received a copy of the GNU Library General Public
   10.20 +    License along with this library; if not, write to the Free
   10.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.22 +
   10.23 +    Sam Lantinga
   10.24 +    slouken@devolution.com
   10.25 +    
   10.26 +    Hsieh-Fu Tsai
   10.27 +    clare@setabox.com
   10.28 +*/
   10.29 +
   10.30 +#include "SDL_nxvideo.h"
   10.31 +
   10.32 +// Functions to be exported
   10.33 +extern void NX_InitOSKeymap (_THIS) ;
   10.34 +extern void NX_PumpEvents (_THIS) ;
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/video/nanox/SDL_nximage.c	Fri May 11 01:13:35 2001 +0000
    11.3 @@ -0,0 +1,166 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    11.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    11.8 +
    11.9 +    This library is free software; you can redistribute it and/or
   11.10 +    modify it under the terms of the GNU Library General Public
   11.11 +    License as published by the Free Software Foundation; either
   11.12 +    version 2 of the License, or (at your option) any later version.
   11.13 +
   11.14 +    This library is distributed in the hope that it will be useful,
   11.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.17 +    Library General Public License for more details.
   11.18 +
   11.19 +    You should have received a copy of the GNU Library General Public
   11.20 +    License along with this library; if not, write to the Free
   11.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.22 +
   11.23 +    Sam Lantinga
   11.24 +    slouken@devolution.com
   11.25 +    
   11.26 +    Hsieh-Fu Tsai
   11.27 +    clare@setabox.com
   11.28 +*/
   11.29 +
   11.30 +#include <stdlib.h>
   11.31 +
   11.32 +#include "SDL_error.h"
   11.33 +
   11.34 +#include "SDL_nximage_c.h"
   11.35 +
   11.36 +void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
   11.37 +{
   11.38 +    int           i, j, xinc, yinc, destinc ;
   11.39 +    int           x, y, w, h ;
   11.40 +    unsigned char * src = NULL, * dest = NULL ;
   11.41 +            
   11.42 +    Dprintf ("enter NX_NormalUpdate\n") ;
   11.43 +
   11.44 +    xinc = this -> screen -> format -> BytesPerPixel ;
   11.45 +    yinc = this -> screen -> pitch ;
   11.46 +        
   11.47 +    for (i = 0; i < numrects; ++ i) {
   11.48 +        x = rects [i].x, y = rects [i].y ;
   11.49 +        w = rects [i].w, h = rects [i].h ;
   11.50 +        src = SDL_Image + y * yinc + x * xinc ;
   11.51 +        dest = Image_buff ;
   11.52 +        destinc = w * xinc ;
   11.53 +
   11.54 +        // apply GammaRamp table
   11.55 +#if (defined (NANOX_PIXEL_RGB) || defined (NANOX_PIXEL_0888) || \
   11.56 +     defined (NANOX_PIXEL_888))
   11.57 +        if (GammaRamp_R && GammaRamp_G && GammaRamp_B) {
   11.58 +            Uint8 * ptr ;
   11.59 +            int   k ;
   11.60 +
   11.61 +            for (j = h; j > 0; -- j, src += yinc) {
   11.62 +                ptr = src - 1 ;
   11.63 +                for (k = w; k > 0; -- k) {
   11.64 +#ifdef NANOX_PIXEL_RGB
   11.65 +                    ptr += 2 ;
   11.66 +#endif
   11.67 +#ifdef NANOX_PIXEL_0888
   11.68 +                    ptr += 2 ;
   11.69 +#endif
   11.70 +#ifdef NANOX_PIXEL_888
   11.71 +                    ++ ptr ;
   11.72 +#endif
   11.73 +                    (* ptr) = GammaRamp_B [(* ptr)] ;
   11.74 +                    ++ ptr ;
   11.75 +                    (* ptr) = GammaRamp_G [(* ptr)] ;
   11.76 +                    ++ ptr ;
   11.77 +                    (* ptr) = GammaRamp_R [(* ptr)] ;
   11.78 +                }
   11.79 +            }
   11.80 +            src = SDL_Image + y * yinc + x * xinc ;
   11.81 +        }
   11.82 +#endif // apply Gamma table
   11.83 +
   11.84 +        for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
   11.85 +            memcpy (dest, src, destinc) ;
   11.86 +        }
   11.87 +
   11.88 +        if (currently_fullscreen) {
   11.89 +            GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff, 
   11.90 +                pixel_type) ;
   11.91 +        } else {
   11.92 +            GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ;
   11.93 +        }
   11.94 +    }
   11.95 +
   11.96 +    Dprintf ("leave NX_NormalUpdate\n") ;
   11.97 +}
   11.98 +
   11.99 +int NX_SetupImage (_THIS, SDL_Surface * screen)
  11.100 +{
  11.101 +    int size = screen -> h * screen -> pitch ;
  11.102 +    
  11.103 +    Dprintf ("enter NX_SetupImage\n") ;
  11.104 +
  11.105 +    screen -> pixels = (void *) malloc (size) ;
  11.106 +    Image_buff = (unsigned char *) malloc (size) ;
  11.107 +    if (screen -> pixels == NULL || Image_buff == NULL) {
  11.108 +        free (screen -> pixels) ;
  11.109 +        free (Image_buff) ;
  11.110 +        SDL_OutOfMemory () ;
  11.111 +        return -1 ;
  11.112 +    }
  11.113 +
  11.114 +    SDL_Image = (unsigned char *) screen -> pixels ;
  11.115 +
  11.116 +    this -> UpdateRects = NX_NormalUpdate ;
  11.117 +
  11.118 +    Dprintf ("leave NX_SetupImage\n") ;
  11.119 +    return 0 ;
  11.120 +}
  11.121 +
  11.122 +void NX_DestroyImage (_THIS, SDL_Surface * screen)
  11.123 +{
  11.124 +    Dprintf ("enter NX_DestroyImage\n") ;
  11.125 +    
  11.126 +    if (SDL_Image) free (SDL_Image) ;
  11.127 +    if (Image_buff) free (Image_buff) ;
  11.128 +    if (screen) screen -> pixels = NULL ;
  11.129 +    
  11.130 +    Dprintf ("leave NX_DestroyImage\n") ;
  11.131 +}
  11.132 +
  11.133 +int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags)
  11.134 +{
  11.135 +    int            retval ;
  11.136 +    GR_SCREEN_INFO si ;
  11.137 +
  11.138 +    Dprintf ("enter NX_ResizeImage\n") ;
  11.139 +
  11.140 +    NX_DestroyImage (this, screen) ;
  11.141 +    retval = NX_SetupImage (this, screen) ;
  11.142 +
  11.143 +    GrGetScreenInfo (& si) ;
  11.144 +    OffsetX = (si.cols - screen -> w) / 2 ;
  11.145 +    OffsetY = (si.rows - screen -> h) / 2 ;
  11.146 +    
  11.147 +    Dprintf ("leave NX_ResizeImage\n") ;
  11.148 +    return retval ;
  11.149 +}
  11.150 +
  11.151 +void NX_RefreshDisplay (_THIS)
  11.152 +{
  11.153 +    Dprintf ("enter NX_RefreshDisplay\n") ;
  11.154 +
  11.155 +    // Don't refresh a display that doesn't have an image (like GL)
  11.156 +    if (! SDL_Image) {
  11.157 +        return;
  11.158 +    }
  11.159 +
  11.160 +    if (currently_fullscreen) {
  11.161 +        GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w, 
  11.162 +            this -> screen -> h, SDL_Image, pixel_type) ;
  11.163 +    } else {
  11.164 +        GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w, 
  11.165 +            this -> screen -> h, SDL_Image, pixel_type) ;
  11.166 +    }
  11.167 +
  11.168 +    Dprintf ("leave NX_RefreshDisplay\n") ;
  11.169 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/nanox/SDL_nximage_c.h	Fri May 11 01:13:35 2001 +0000
    12.3 @@ -0,0 +1,34 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    12.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    12.8 +
    12.9 +    This library is free software; you can redistribute it and/or
   12.10 +    modify it under the terms of the GNU Library General Public
   12.11 +    License as published by the Free Software Foundation; either
   12.12 +    version 2 of the License, or (at your option) any later version.
   12.13 +
   12.14 +    This library is distributed in the hope that it will be useful,
   12.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.17 +    Library General Public License for more details.
   12.18 +
   12.19 +    You should have received a copy of the GNU Library General Public
   12.20 +    License along with this library; if not, write to the Free
   12.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.22 +
   12.23 +    Sam Lantinga
   12.24 +    slouken@devolution.com
   12.25 +    
   12.26 +    Hsieh-Fu Tsai
   12.27 +    clare@setabox.com
   12.28 +*/
   12.29 +
   12.30 +#include "SDL_nxvideo.h"
   12.31 +
   12.32 +extern int NX_SetupImage (_THIS, SDL_Surface * screen) ;
   12.33 +extern void NX_DestroyImage (_THIS, SDL_Surface * screen) ;
   12.34 +extern int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags) ;
   12.35 +
   12.36 +extern void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects) ;
   12.37 +extern void NX_RefreshDisplay (_THIS) ;
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/video/nanox/SDL_nxmodes.c	Fri May 11 01:13:35 2001 +0000
    13.3 @@ -0,0 +1,84 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    13.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    13.8 +
    13.9 +    This library is free software; you can redistribute it and/or
   13.10 +    modify it under the terms of the GNU Library General Public
   13.11 +    License as published by the Free Software Foundation; either
   13.12 +    version 2 of the License, or (at your option) any later version.
   13.13 +
   13.14 +    This library is distributed in the hope that it will be useful,
   13.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.17 +    Library General Public License for more details.
   13.18 +
   13.19 +    You should have received a copy of the GNU Library General Public
   13.20 +    License along with this library; if not, write to the Free
   13.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.22 +
   13.23 +    Sam Lantinga
   13.24 +    slouken@devolution.com
   13.25 +    
   13.26 +    Hsieh-Fu Tsai
   13.27 +    clare@setabox.com
   13.28 +*/
   13.29 +
   13.30 +#include <stdlib.h>
   13.31 +
   13.32 +#include "SDL_nxmodes_c.h"
   13.33 +
   13.34 +SDL_Rect ** NX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
   13.35 +{
   13.36 +    if (flags & SDL_FULLSCREEN)
   13.37 +        return SDL_modelist ;
   13.38 +
   13.39 +    if (SDL_Visual.bpp == format -> BitsPerPixel) {
   13.40 +        return ((SDL_Rect **) -1) ;
   13.41 +    } else {
   13.42 +        return ((SDL_Rect **) 0) ;
   13.43 +    }
   13.44 +}
   13.45 +
   13.46 +void NX_FreeVideoModes (_THIS)
   13.47 +{
   13.48 +    int i ;
   13.49 +
   13.50 +    if (SDL_modelist) {
   13.51 +        for (i = 0; SDL_modelist [i]; ++ i) {
   13.52 +            free (SDL_modelist [i]) ;
   13.53 +        }
   13.54 +        free (SDL_modelist) ;
   13.55 +        SDL_modelist = NULL;
   13.56 +    }
   13.57 +}
   13.58 +
   13.59 +int NX_EnterFullScreen (_THIS)
   13.60 +{
   13.61 +    if (! currently_fullscreen) {
   13.62 +        GR_SCREEN_INFO si ;
   13.63 +
   13.64 +        GrGetScreenInfo (& si) ;
   13.65 +        GrResizeWindow (FSwindow, si.cols, si.rows) ;
   13.66 +        GrUnmapWindow (SDL_Window) ;
   13.67 +        GrMapWindow (FSwindow) ;
   13.68 +        GrRaiseWindow (FSwindow) ;
   13.69 +        GrSetFocus (FSwindow) ;
   13.70 +        currently_fullscreen = 1 ;      
   13.71 +    }
   13.72 +
   13.73 +    return 1 ;
   13.74 +}
   13.75 +
   13.76 +int NX_LeaveFullScreen (_THIS)
   13.77 +{
   13.78 +    if (currently_fullscreen) {
   13.79 +        GrUnmapWindow (FSwindow) ;
   13.80 +        GrMapWindow (SDL_Window) ;
   13.81 +        GrRaiseWindow (SDL_Window) ;
   13.82 +        GrSetFocus (SDL_Window) ;
   13.83 +        currently_fullscreen = 0 ;
   13.84 +    }
   13.85 +
   13.86 +    return 0 ;
   13.87 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/video/nanox/SDL_nxmodes_c.h	Fri May 11 01:13:35 2001 +0000
    14.3 @@ -0,0 +1,33 @@
    14.4 +/*
    14.5 +    SDL - Simple DirectMedia Layer
    14.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    14.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    14.8 +
    14.9 +    This library is free software; you can redistribute it and/or
   14.10 +    modify it under the terms of the GNU Library General Public
   14.11 +    License as published by the Free Software Foundation; either
   14.12 +    version 2 of the License, or (at your option) any later version.
   14.13 +
   14.14 +    This library is distributed in the hope that it will be useful,
   14.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14.17 +    Library General Public License for more details.
   14.18 +
   14.19 +    You should have received a copy of the GNU Library General Public
   14.20 +    License along with this library; if not, write to the Free
   14.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   14.22 +
   14.23 +    Sam Lantinga
   14.24 +    slouken@devolution.com
   14.25 +    
   14.26 +    Hsieh-Fu Tsai
   14.27 +    clare@setabox.com
   14.28 +*/
   14.29 +
   14.30 +#include "SDL_nxvideo.h"
   14.31 +#include <SDL/SDL.h>
   14.32 +
   14.33 +extern SDL_Rect ** NX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) ;
   14.34 +extern void NX_FreeVideoModes (_THIS) ;
   14.35 +extern int NX_EnterFullScreen (_THIS) ;
   14.36 +extern int NX_LeaveFullScreen (_THIS) ;
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/video/nanox/SDL_nxmouse.c	Fri May 11 01:13:35 2001 +0000
    15.3 @@ -0,0 +1,81 @@
    15.4 +/*
    15.5 +    SDL - Simple DirectMedia Layer
    15.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    15.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    15.8 +
    15.9 +    This library is free software; you can redistribute it and/or
   15.10 +    modify it under the terms of the GNU Library General Public
   15.11 +    License as published by the Free Software Foundation; either
   15.12 +    version 2 of the License, or (at your option) any later version.
   15.13 +
   15.14 +    This library is distributed in the hope that it will be useful,
   15.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.17 +    Library General Public License for more details.
   15.18 +
   15.19 +    You should have received a copy of the GNU Library General Public
   15.20 +    License along with this library; if not, write to the Free
   15.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.22 +
   15.23 +    Sam Lantinga
   15.24 +    slouken@devolution.com
   15.25 +    
   15.26 +    Hsieh-Fu Tsai
   15.27 +    clare@setabox.com
   15.28 +*/
   15.29 +
   15.30 +#include <stdlib.h>
   15.31 +
   15.32 +#include "SDL_error.h"
   15.33 +#include "SDL_events_c.h"
   15.34 +
   15.35 +#include "SDL_nxmouse_c.h"
   15.36 +
   15.37 +// The implementation dependent data for the window manager cursor
   15.38 +struct WMcursor {
   15.39 +    int unused ;
   15.40 +} ;
   15.41 +
   15.42 +WMcursor * NX_CreateWMCursor (_THIS,
   15.43 +        Uint8 * data, Uint8 * mask, int w, int h, int hot_x, int hot_y)
   15.44 +{
   15.45 +    WMcursor * cursor ;
   15.46 +
   15.47 +    Dprintf ("enter NX_CreateWMCursor\n") ;
   15.48 +
   15.49 +    cursor = (WMcursor *) malloc (sizeof (WMcursor)) ;
   15.50 +    if (cursor == NULL) {
   15.51 +        SDL_OutOfMemory () ;
   15.52 +        return NULL ;
   15.53 +    }
   15.54 +
   15.55 +    Dprintf ("leave NX_CreateWMCursor\n") ;
   15.56 +    return cursor ;
   15.57 +}
   15.58 +
   15.59 +void NX_FreeWMCursor (_THIS, WMcursor * cursor)
   15.60 +{
   15.61 +    Dprintf ("NX_FreeWMCursor\n") ;
   15.62 +    free (cursor) ;
   15.63 +    return ;
   15.64 +}
   15.65 +
   15.66 +void NX_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
   15.67 +{
   15.68 +    GR_WINDOW_INFO info ;
   15.69 +
   15.70 +    Dprintf ("enter NX_WarpWMCursor\n") ;
   15.71 +    SDL_Lock_EventThread () ;
   15.72 +    
   15.73 +    GrGetWindowInfo (SDL_Window, & info) ;
   15.74 +    GrMoveCursor (info.x + x, info.y + y) ;
   15.75 +
   15.76 +    SDL_Unlock_EventThread () ;
   15.77 +    Dprintf ("leave NX_WarpWMCursor\n") ;
   15.78 +}
   15.79 +
   15.80 +int NX_ShowWMCursor (_THIS, WMcursor * cursor)
   15.81 +{
   15.82 +    Dprintf ("NX_ShowWMCursor\n") ;
   15.83 +    return 1 ;
   15.84 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/video/nanox/SDL_nxmouse_c.h	Fri May 11 01:13:35 2001 +0000
    16.3 @@ -0,0 +1,6 @@
    16.4 +#include "SDL_nxvideo.h"
    16.5 +
    16.6 +extern WMcursor * NX_CreateWMCursor (_THIS, Uint8 * data, Uint8 * mask, int w, int h, int hot_x, int hot_y) ;
    16.7 +void NX_FreeWMCursor (_THIS, WMcursor * cursor) ;
    16.8 +extern void NX_WarpWMCursor (_THIS, Uint16 x, Uint16 y) ;
    16.9 +extern int NX_ShowWMCursor (_THIS, WMcursor * cursor) ;
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/video/nanox/SDL_nxvideo.c	Fri May 11 01:13:35 2001 +0000
    17.3 @@ -0,0 +1,557 @@
    17.4 +/*
    17.5 +    SDL - Simple DirectMedia Layer
    17.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    17.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    17.8 +
    17.9 +    This library is free software; you can redistribute it and/or
   17.10 +    modify it under the terms of the GNU Library General Public
   17.11 +    License as published by the Free Software Foundation; either
   17.12 +    version 2 of the License, or (at your option) any later version.
   17.13 +
   17.14 +    This library is distributed in the hope that it will be useful,
   17.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17.17 +    Library General Public License for more details.
   17.18 +
   17.19 +    You should have received a copy of the GNU Library General Public
   17.20 +    License along with this library; if not, write to the Free
   17.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.22 +
   17.23 +    Sam Lantinga
   17.24 +    slouken@devolution.com
   17.25 +    
   17.26 +    Hsieh-Fu Tsai
   17.27 +    clare@setabox.com
   17.28 +*/
   17.29 +
   17.30 +#include <stdlib.h>
   17.31 +
   17.32 +#include "SDL_video.h"
   17.33 +#include "SDL_pixels_c.h"
   17.34 +#include "SDL_events_c.h"
   17.35 +#include "SDL_thread.h"
   17.36 +
   17.37 +#define MWINCLUDECOLORS
   17.38 +#include "SDL_nxvideo.h"
   17.39 +#include "SDL_nxmodes_c.h"
   17.40 +#include "SDL_nxwm_c.h"
   17.41 +#include "SDL_nxmouse_c.h"
   17.42 +#include "SDL_nximage_c.h"
   17.43 +#include "SDL_nxevents_c.h"
   17.44 +
   17.45 +// Initialization/Query functions
   17.46 +static int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) ;
   17.47 +static SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags) ;
   17.48 +static int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) ;
   17.49 +static void NX_VideoQuit (_THIS) ;
   17.50 +static void NX_DestroyWindow (_THIS, SDL_Surface * screen) ;
   17.51 +static int NX_ToggleFullScreen (_THIS, int on) ;
   17.52 +static void NX_UpdateMouse (_THIS) ;
   17.53 +static int NX_SetGammaRamp (_THIS, Uint16 * ramp) ;
   17.54 +static int NX_GetGammaRamp (_THIS, Uint16 * ramp) ;
   17.55 +
   17.56 +// Microwin driver bootstrap functions
   17.57 +static int NX_Available ()
   17.58 +{
   17.59 +    Dprintf ("enter NX_Available\n") ;
   17.60 +
   17.61 +    if (GrOpen () < 0) return 0 ;
   17.62 +        GrClose () ;
   17.63 +    
   17.64 +    Dprintf ("leave NX_Available\n") ;
   17.65 +    return 1 ;
   17.66 +}
   17.67 +
   17.68 +static void NX_DeleteDevice (SDL_VideoDevice * device)
   17.69 +{
   17.70 +    Dprintf ("enter NX_DeleteDevice\n") ;
   17.71 +
   17.72 +    if (device) {
   17.73 +        if (device -> hidden) free (device -> hidden) ;
   17.74 +        if (device -> gl_data) free (device -> gl_data) ;
   17.75 +            free (device) ;
   17.76 +    }
   17.77 +
   17.78 +    Dprintf ("leave NX_DeleteDevice\n") ;
   17.79 +}
   17.80 +    
   17.81 +static SDL_VideoDevice * NX_CreateDevice (int devindex)
   17.82 +{
   17.83 +    SDL_VideoDevice * device ;
   17.84 +
   17.85 +    Dprintf ("enter NX_CreateDevice\n") ;
   17.86 +
   17.87 +    // Initialize all variables that we clean on shutdown
   17.88 +    device = (SDL_VideoDevice *) malloc (sizeof (SDL_VideoDevice)) ;
   17.89 +    if (device) {
   17.90 +        memset (device, 0, (sizeof * device)) ;
   17.91 +        device -> hidden = (struct SDL_PrivateVideoData *)
   17.92 +                malloc ((sizeof * device -> hidden)) ;
   17.93 +        device -> gl_data = NULL ;
   17.94 +    }
   17.95 +    if ((device == NULL) || (device -> hidden == NULL)) {
   17.96 +        SDL_OutOfMemory () ;
   17.97 +        NX_DeleteDevice (device) ;
   17.98 +        return 0 ;
   17.99 +    }
  17.100 +    memset (device -> hidden, 0, (sizeof * device -> hidden)) ;
  17.101 +
  17.102 +    // Set the function pointers
  17.103 +    device -> VideoInit = NX_VideoInit ;
  17.104 +    device -> ListModes = NX_ListModes ;
  17.105 +    device -> SetVideoMode = NX_SetVideoMode ;
  17.106 +    device -> ToggleFullScreen = NX_ToggleFullScreen ;
  17.107 +    device -> UpdateMouse = NX_UpdateMouse ;
  17.108 +    device -> CreateYUVOverlay = NULL ;
  17.109 +    device -> SetColors = NX_SetColors ;
  17.110 +    device -> UpdateRects = NULL ;
  17.111 +    device -> VideoQuit = NX_VideoQuit;
  17.112 +    device -> AllocHWSurface = NULL ;
  17.113 +    device -> CheckHWBlit = NULL ;
  17.114 +    device -> FillHWRect = NULL ;
  17.115 +    device -> SetHWColorKey = NULL ;
  17.116 +    device -> SetHWAlpha = NULL ;
  17.117 +    device -> LockHWSurface = NULL ;
  17.118 +    device -> UnlockHWSurface = NULL ;
  17.119 +    device -> FlipHWSurface = NULL ;
  17.120 +    device -> FreeHWSurface = NULL ;
  17.121 +    device -> SetGamma = NULL ;
  17.122 +    device -> GetGamma = NULL ;
  17.123 +    device -> SetGammaRamp = NX_SetGammaRamp ;
  17.124 +    device -> GetGammaRamp = NX_GetGammaRamp ;
  17.125 +
  17.126 +#ifdef HAVE_OPENGL
  17.127 +    device -> GL_LoadLibrary = NULL ;
  17.128 +    device -> GL_GetProcAddress = NULL ;
  17.129 +    device -> GL_GetAttribute = NULL ;
  17.130 +    device -> GL_MakeCurrent = NULL ;
  17.131 +    device -> GL_SwapBuffers = NULL ;
  17.132 +#endif
  17.133 +
  17.134 +    device -> SetIcon = NULL ;
  17.135 +    device -> SetCaption = NX_SetCaption;
  17.136 +    device -> IconifyWindow = NULL ;
  17.137 +    device -> GrabInput = NULL ;
  17.138 +    device -> GetWMInfo = NX_GetWMInfo ;
  17.139 +    device -> FreeWMCursor =  NX_FreeWMCursor ;
  17.140 +    device -> CreateWMCursor = NX_CreateWMCursor ;
  17.141 +    device -> ShowWMCursor = NX_ShowWMCursor ;
  17.142 +    device -> WarpWMCursor = NX_WarpWMCursor ;
  17.143 +    device -> CheckMouseMode = NULL ;
  17.144 +    device -> InitOSKeymap = NX_InitOSKeymap ;
  17.145 +    device -> PumpEvents = NX_PumpEvents ;
  17.146 +
  17.147 +    device -> free = NX_DeleteDevice ;
  17.148 +
  17.149 +    Dprintf ("leave NX_CreateDevice\n") ;
  17.150 +    return device ;
  17.151 +}
  17.152 +
  17.153 +VideoBootStrap NX_bootstrap = {
  17.154 +    "nanox", "nanox", NX_Available, NX_CreateDevice
  17.155 +} ;
  17.156 +
  17.157 +static void create_aux_windows (_THIS)
  17.158 +{
  17.159 +    GR_WM_PROPERTIES props ;
  17.160 +
  17.161 +    Dprintf ("enter create_aux_windows\n") ;
  17.162 +
  17.163 +    // Don't create any extra windows if we are being managed
  17.164 +    if (SDL_windowid) {
  17.165 +        FSwindow = 0 ;
  17.166 +        return ;
  17.167 +    }
  17.168 +    
  17.169 +    if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
  17.170 +        GrDestroyWindow (FSwindow) ;
  17.171 +    }
  17.172 +    
  17.173 +    FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ;
  17.174 +    props.flags = GR_WM_FLAGS_PROPS ;
  17.175 +    props.props = GR_WM_PROPS_NODECORATE ;
  17.176 +    GrSetWMProperties (FSwindow, & props) ;
  17.177 +
  17.178 +    GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE         |
  17.179 +        GR_EVENT_MASK_BUTTON_DOWN  | GR_EVENT_MASK_BUTTON_UP  |
  17.180 +        GR_EVENT_MASK_FOCUS_IN     | GR_EVENT_MASK_FOCUS_OUT  |
  17.181 +        GR_EVENT_MASK_KEY_DOWN     | GR_EVENT_MASK_KEY_UP     |
  17.182 +        GR_EVENT_MASK_MOUSE_ENTER  | GR_EVENT_MASK_MOUSE_EXIT |
  17.183 +        GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE     |
  17.184 +        GR_EVENT_MASK_CLOSE_REQ)) ;
  17.185 +
  17.186 +    Dprintf ("leave create_aux_windows\n") ;
  17.187 +}
  17.188 +
  17.189 +int NX_VideoInit (_THIS, SDL_PixelFormat * vformat)
  17.190 +{
  17.191 +    GR_SCREEN_INFO si ;
  17.192 +
  17.193 +    Dprintf ("enter NX_VideoInit\n") ;
  17.194 +    
  17.195 +    if (GrOpen () < 0) {
  17.196 +        SDL_SetError ("GrOpen() fail") ;
  17.197 +        return -1 ;
  17.198 +    }
  17.199 +
  17.200 +    // use share memory to speed up
  17.201 +#ifdef NANOX_SHARE_MEMORY
  17.202 +    GrReqShmCmds (0xFFFF);
  17.203 +#endif
  17.204 +
  17.205 +    SDL_Window = 0 ;
  17.206 +    FSwindow = 0 ;
  17.207 +
  17.208 +    GammaRamp_R = NULL ;
  17.209 +    GammaRamp_G = NULL ;
  17.210 +    GammaRamp_B = NULL ;    
  17.211 +
  17.212 +    GrGetScreenInfo (& si) ;
  17.213 +    SDL_Visual.bpp = si.bpp ;
  17.214 +
  17.215 +    // GetVideoMode
  17.216 +    SDL_modelist = (SDL_Rect **) malloc (sizeof (SDL_Rect *) * 2) ;
  17.217 +    if (SDL_modelist) {
  17.218 +        SDL_modelist [0] = (SDL_Rect *) malloc (sizeof(SDL_Rect)) ;
  17.219 +        if (SDL_modelist [0]) {
  17.220 +            SDL_modelist [0] -> x = 0 ;
  17.221 +            SDL_modelist [0] -> y = 0 ;
  17.222 +            SDL_modelist [0] -> w = si.cols ;
  17.223 +            SDL_modelist [0] -> h = si.rows ;
  17.224 +        }
  17.225 +        SDL_modelist [1] = NULL ;
  17.226 +    }
  17.227 +
  17.228 +#ifdef NANOX_PIXEL_RGB
  17.229 +    pixel_type = MWPF_RGB ;
  17.230 +    SDL_Visual.red_mask   = 0x000000FF ;
  17.231 +    SDL_Visual.green_mask = 0x0000FF00 ;
  17.232 +    SDL_Visual.blue_mask  = 0x00FF0000 ;
  17.233 +#endif
  17.234 +#ifdef NANOX_PIXEL_0888
  17.235 +    pixel_type = MWPF_TRUECOLOR0888 ;
  17.236 +    SDL_Visual.red_mask   = 0x00FF0000 ;
  17.237 +    SDL_Visual.green_mask = 0x0000FF00 ;
  17.238 +    SDL_Visual.blue_mask  = 0x000000FF ;
  17.239 +#endif
  17.240 +#ifdef NANOX_PIXEL_888
  17.241 +    pixel_type = MWPF_TRUECOLOR888 ;
  17.242 +    SDL_Visual.red_mask   = 0xFF0000 ;
  17.243 +    SDL_Visual.green_mask = 0x00FF00 ;
  17.244 +    SDL_Visual.blue_mask  = 0x0000FF ;
  17.245 +#endif
  17.246 +#ifdef NANOX_PIXEL_565
  17.247 +    pixel_type = MWPF_TRUECOLOR565 ;
  17.248 +    SDL_Visual.red_mask   = 0xF800 ;
  17.249 +    SDL_Visual.green_mask = 0x07E0 ;
  17.250 +    SDL_Visual.blue_mask  = 0x001F ;
  17.251 +#endif
  17.252 +#ifdef NANOX_PIXEL_555
  17.253 +    pixel_type = MWPF_TRUECOLOR555 ;
  17.254 +    SDL_Visual.red_mask   = 0x7C00 ;
  17.255 +    SDL_Visual.green_mask = 0x03E0 ;
  17.256 +    SDL_Visual.blue_mask  = 0x001F ;
  17.257 +#endif
  17.258 +#ifdef NANOX_PIXEL_332
  17.259 +    pixel_type = MWPF_TRUECOLOR332 ;
  17.260 +#endif
  17.261 +#ifdef NANOX_PIXEL_PAL
  17.262 +    pixel_type = MWPF_PALETTE ;
  17.263 +#endif
  17.264 +
  17.265 +    vformat -> BitsPerPixel = SDL_Visual.bpp ;
  17.266 +    if (vformat -> BitsPerPixel > 8) {
  17.267 +        vformat -> Rmask = SDL_Visual.red_mask ;
  17.268 +        vformat -> Gmask = SDL_Visual.green_mask ;
  17.269 +        vformat -> Bmask = SDL_Visual.blue_mask ;
  17.270 +    }
  17.271 +
  17.272 +    // See if we have been passed a window to use
  17.273 +    SDL_windowid = getenv ("SDL_WINDOWID") ;
  17.274 +    
  17.275 +    // Create the fullscreen (and managed windows : no implement)
  17.276 +    create_aux_windows (this) ;
  17.277 +
  17.278 +    Dprintf ("leave NX_VideoInit\n") ;
  17.279 +    return 0 ;
  17.280 +}
  17.281 +
  17.282 +void NX_VideoQuit (_THIS)
  17.283 +{
  17.284 +    Dprintf ("enter NX_VideoQuit\n") ;
  17.285 +
  17.286 +    // Start shutting down the windows
  17.287 +    NX_DestroyImage (this, this -> screen) ;
  17.288 +    NX_DestroyWindow (this, this -> screen) ;
  17.289 +    if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) {
  17.290 +        GrDestroyWindow (FSwindow) ;
  17.291 +    }
  17.292 +    NX_FreeVideoModes (this) ;
  17.293 +    free (GammaRamp_R) ;
  17.294 +    free (GammaRamp_G) ;
  17.295 +    free (GammaRamp_B) ;
  17.296 +    GrClose () ;
  17.297 +
  17.298 +    Dprintf ("leave NX_VideoQuit\n") ;
  17.299 +}
  17.300 +
  17.301 +static void NX_DestroyWindow (_THIS, SDL_Surface * screen)
  17.302 +{
  17.303 +    Dprintf ("enter NX_DestroyWindow\n") ;
  17.304 +
  17.305 +    if (! SDL_windowid) {
  17.306 +        if (screen && (screen -> flags & SDL_FULLSCREEN)) {
  17.307 +            screen -> flags &= ~ SDL_FULLSCREEN ;
  17.308 +            NX_LeaveFullScreen (this) ;
  17.309 +        }
  17.310 +
  17.311 +        // Destroy the output window
  17.312 +        if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
  17.313 +            GrDestroyWindow (SDL_Window) ;
  17.314 +        }
  17.315 +    }
  17.316 +    
  17.317 +    // Free the graphics context
  17.318 +    if (! SDL_GC) {
  17.319 +        GrDestroyGC (SDL_GC) ;
  17.320 +        SDL_GC = 0;
  17.321 +    }
  17.322 +
  17.323 +    Dprintf ("leave NX_DestroyWindow\n") ;
  17.324 +}
  17.325 +
  17.326 +static int NX_CreateWindow (_THIS, SDL_Surface * screen,
  17.327 +                int w, int h, int bpp, Uint32 flags)
  17.328 +{
  17.329 +    Dprintf ("enter NX_CreateWindow\n") ;
  17.330 +
  17.331 +    // If a window is already present, destroy it and start fresh
  17.332 +    if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) {
  17.333 +        NX_DestroyWindow (this, screen) ;
  17.334 +    }
  17.335 +
  17.336 +    // See if we have been given a window id
  17.337 +    if (SDL_windowid) {
  17.338 +        SDL_Window = strtol (SDL_windowid, NULL, 0) ;
  17.339 +    } else {
  17.340 +        SDL_Window = 0 ;
  17.341 +    }
  17.342 +    
  17.343 +    if ( ! SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, 
  17.344 +        SDL_Visual.green_mask, SDL_Visual.blue_mask, 0))
  17.345 +        return -1;
  17.346 +
  17.347 +    // Create (or use) the nanox display window
  17.348 +    if (! SDL_windowid) {
  17.349 +
  17.350 +        SDL_Window = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE) ;
  17.351 +
  17.352 +        GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE       |
  17.353 +            GR_EVENT_MASK_BUTTON_DOWN  | GR_EVENT_MASK_BUTTON_UP  |
  17.354 +            GR_EVENT_MASK_FOCUS_IN     | GR_EVENT_MASK_FOCUS_OUT  |
  17.355 +            GR_EVENT_MASK_KEY_DOWN     | GR_EVENT_MASK_KEY_UP     |
  17.356 +            GR_EVENT_MASK_MOUSE_ENTER  | GR_EVENT_MASK_MOUSE_EXIT |
  17.357 +            GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE     |
  17.358 +            GR_EVENT_MASK_CLOSE_REQ)) ;
  17.359 +    }
  17.360 +    
  17.361 +    /* Create the graphics context here, once we have a window */
  17.362 +    SDL_GC = GrNewGC () ;
  17.363 +    if (SDL_GC == 0) {
  17.364 +        SDL_SetError("Couldn't create graphics context");
  17.365 +        return(-1);
  17.366 +    }
  17.367 +
  17.368 +    // Map them both and go fullscreen, if requested
  17.369 +    if (! SDL_windowid) {
  17.370 +        GrMapWindow (SDL_Window) ;
  17.371 +        if (flags & SDL_FULLSCREEN) {
  17.372 +            screen -> flags |= SDL_FULLSCREEN ;
  17.373 +            NX_EnterFullScreen (this) ;
  17.374 +        } else {
  17.375 +            screen -> flags &= ~ SDL_FULLSCREEN ;
  17.376 +        }
  17.377 +    }
  17.378 +
  17.379 +    Dprintf ("leave NX_CreateWindow\n") ;
  17.380 +    return 0 ;
  17.381 +}
  17.382 +
  17.383 +SDL_Surface * NX_SetVideoMode (_THIS, SDL_Surface * current,
  17.384 +                int width, int height, int bpp, Uint32 flags)
  17.385 +{
  17.386 +    Dprintf ("enter NX_SetVideoMode\n") ;
  17.387 +
  17.388 +    // Lock the event thread, in multi-threading environments
  17.389 +    SDL_Lock_EventThread () ;
  17.390 +
  17.391 +    bpp = SDL_Visual.bpp ;
  17.392 +    if (NX_CreateWindow (this, current, width, height, bpp, flags) < 0) {
  17.393 +        current = NULL;
  17.394 +        goto done;
  17.395 +    }
  17.396 +
  17.397 +    if (current -> w != width || current -> h != height) {
  17.398 +        current -> w = width ;
  17.399 +        current -> h = height ;
  17.400 +        current -> pitch = SDL_CalculatePitch (current) ;
  17.401 +        NX_ResizeImage (this, current, flags) ;
  17.402 +    }
  17.403 +    current -> flags |= (flags & (SDL_RESIZABLE | SDL_NOFRAME)) ;
  17.404 +
  17.405 +  done:
  17.406 +    SDL_Unlock_EventThread () ;
  17.407 +
  17.408 +    Dprintf ("leave NX_SetVideoMode\n") ;
  17.409 +
  17.410 +    // We're done!
  17.411 +    return current ;
  17.412 +}
  17.413 +
  17.414 +// ncolors <= 256
  17.415 +int NX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
  17.416 +{
  17.417 +    int        i ;
  17.418 +    GR_PALETTE pal ;
  17.419 +
  17.420 +    Dprintf ("enter NX_SetColors\n") ;
  17.421 +
  17.422 +    if (ncolors > 256) return 0 ;
  17.423 +    
  17.424 +    pal.count = ncolors ;
  17.425 +    for (i = 0; i < ncolors; ++ i) {
  17.426 +        pal.palette [i].r = colors [i].r ;
  17.427 +        pal.palette [i].g = colors [i].g ;
  17.428 +        pal.palette [i].b = colors [i].b ;
  17.429 +    }
  17.430 +    GrSetSystemPalette (firstcolor, & pal) ;
  17.431 +
  17.432 +    Dprintf ("leave NX_SetColors\n") ;
  17.433 +    return 1 ;
  17.434 +}
  17.435 +
  17.436 +static int NX_ToggleFullScreen (_THIS, int on)
  17.437 +{
  17.438 +    SDL_Rect rect ;
  17.439 +    Uint32   event_thread ;
  17.440 +    
  17.441 +    Dprintf ("enter NX_ToggleFullScreen\n") ;
  17.442 +
  17.443 +    // Don't switch if we don't own the window
  17.444 +    if (SDL_windowid) return 0 ;
  17.445 +    
  17.446 +    // Don't lock if we are the event thread
  17.447 +    event_thread = SDL_EventThreadID () ;
  17.448 +    if (event_thread && (SDL_ThreadID () == event_thread)) {
  17.449 +        event_thread = 0 ;
  17.450 +    }
  17.451 +    if (event_thread) {
  17.452 +        SDL_Lock_EventThread() ;
  17.453 +    }
  17.454 +    
  17.455 +    if (on) {
  17.456 +        NX_EnterFullScreen (this) ;
  17.457 +    } else {
  17.458 +        this -> screen -> flags &= ~ SDL_FULLSCREEN ;
  17.459 +        NX_LeaveFullScreen (this) ;
  17.460 +    }
  17.461 +
  17.462 +    rect.x = rect.y = 0 ;
  17.463 +    rect.w = this -> screen -> w, rect.h = this -> screen -> h ;
  17.464 +    NX_NormalUpdate (this, 1, & rect) ;
  17.465 +
  17.466 +    if (event_thread) {
  17.467 +        SDL_Unlock_EventThread () ;
  17.468 +    }
  17.469 +    
  17.470 +    Dprintf ("leave NX_ToggleFullScreen\n") ;
  17.471 +    return 1 ;
  17.472 +}
  17.473 +
  17.474 +// Update the current mouse state and position
  17.475 +static void NX_UpdateMouse (_THIS)
  17.476 +{
  17.477 +    int            x, y ;
  17.478 +    GR_WINDOW_INFO info ;
  17.479 +    GR_SCREEN_INFO si ;
  17.480 +
  17.481 +
  17.482 +    Dprintf ("enter NX_UpdateMouse\n") ;
  17.483 +
  17.484 +    // Lock the event thread, in multi-threading environments
  17.485 +    SDL_Lock_EventThread () ;
  17.486 +    
  17.487 +    GrGetScreenInfo (& si) ;
  17.488 +    GrGetWindowInfo (SDL_Window, & info) ;
  17.489 +    x = si.xpos - info.x ;
  17.490 +    y = si.ypos - info.y ;
  17.491 +    if (x >= 0 && x <= info.width && y >= 0 && y <= info.height) {
  17.492 +        SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ;
  17.493 +        SDL_PrivateMouseMotion (0, 0, x, y);
  17.494 +    } else {
  17.495 +        SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ;
  17.496 +    }
  17.497 +
  17.498 +    SDL_Unlock_EventThread () ;
  17.499 +    Dprintf ("leave NX_UpdateMouse\n") ;
  17.500 +}
  17.501 +
  17.502 +static int NX_SetGammaRamp (_THIS, Uint16 * ramp)
  17.503 +{
  17.504 +    int i ;
  17.505 +    Uint16 * red, * green, * blue ;
  17.506 +    
  17.507 +    Dprintf ("enter NX_SetGammaRamp\n") ;
  17.508 +    
  17.509 +    if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ;
  17.510 +
  17.511 +    if (! GammaRamp_R) GammaRamp_R = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
  17.512 +    if (! GammaRamp_G) GammaRamp_G = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
  17.513 +    if (! GammaRamp_B) GammaRamp_B = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
  17.514 +    if ((! GammaRamp_R) || (! GammaRamp_G) || (! GammaRamp_B)) {
  17.515 +        SDL_OutOfMemory () ;
  17.516 +        return -1 ;
  17.517 +    }
  17.518 +
  17.519 +    for (i = 0; i < CI_SIZE; ++ i)
  17.520 +        GammaRamp_R [i] = GammaRamp_G [i] = GammaRamp_B [i] = i ;
  17.521 +
  17.522 +    red   = ramp ;
  17.523 +    green = ramp + CI_SIZE ;
  17.524 +    blue  = green + CI_SIZE ;
  17.525 +        
  17.526 +    for (i = 0; i < CI_SIZE; ++ i) {
  17.527 +        GammaRamp_R [i] = red   [i] ;
  17.528 +        GammaRamp_G [i] = green [i] ;
  17.529 +        GammaRamp_B [i] = blue  [i] ;
  17.530 +    }
  17.531 +
  17.532 +    Dprintf ("leave NX_SetGammaRamp\n") ;   
  17.533 +    return 0 ;
  17.534 +}
  17.535 +
  17.536 +static int NX_GetGammaRamp (_THIS, Uint16 * ramp)
  17.537 +{
  17.538 +    int i ;
  17.539 +    Uint16 * red, * green, * blue ;
  17.540 +
  17.541 +    Dprintf ("enter NX_GetGammaRamp\n") ;   
  17.542 +
  17.543 +    if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ;
  17.544 +    red   = ramp ;
  17.545 +    green = ramp  + CI_SIZE ;
  17.546 +    blue  = green + CI_SIZE ;
  17.547 +    if (GammaRamp_R && GammaRamp_G && GammaRamp_B) {
  17.548 +        for (i = 0; i < CI_SIZE; ++ i) {
  17.549 +            red   [i] = GammaRamp_R [i] ;
  17.550 +            green [i] = GammaRamp_G [i] ;
  17.551 +            blue  [i] = GammaRamp_B [i] ;
  17.552 +        }
  17.553 +    } else {
  17.554 +        for (i = 0; i < CI_SIZE; ++ i)
  17.555 +            red [i] = green [i] = blue [i] = i ;
  17.556 +    }
  17.557 +
  17.558 +    Dprintf ("leave NX_GetGammaRamp\n") ;
  17.559 +    return 0 ;
  17.560 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/video/nanox/SDL_nxvideo.h	Fri May 11 01:13:35 2001 +0000
    18.3 @@ -0,0 +1,89 @@
    18.4 +/*
    18.5 +    SDL - Simple DirectMedia Layer
    18.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    18.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    18.8 +
    18.9 +    This library is free software; you can redistribute it and/or
   18.10 +    modify it under the terms of the GNU Library General Public
   18.11 +    License as published by the Free Software Foundation; either
   18.12 +    version 2 of the License, or (at your option) any later version.
   18.13 +
   18.14 +    This library is distributed in the hope that it will be useful,
   18.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18.17 +    Library General Public License for more details.
   18.18 +
   18.19 +    You should have received a copy of the GNU Library General Public
   18.20 +    License along with this library; if not, write to the Free
   18.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.22 +
   18.23 +    Sam Lantinga
   18.24 +    slouken@devolution.com
   18.25 +    
   18.26 +    Hsieh-Fu Tsai
   18.27 +    clare@setabox.com
   18.28 +*/
   18.29 +
   18.30 +#ifndef _SDL_nxvideo_h
   18.31 +#define _SDL_nxvideo_h
   18.32 +
   18.33 +#include <microwin/nano-X.h>
   18.34 +
   18.35 +#include "SDL_sysvideo.h"
   18.36 +
   18.37 +#ifdef ENABLE_NANOX_DEBUG
   18.38 +#define Dprintf printf
   18.39 +#else
   18.40 +#define Dprintf(ignore...)
   18.41 +#endif
   18.42 +
   18.43 +// Hidden "this" pointer for the video functions
   18.44 +#define _THIS   SDL_VideoDevice * this
   18.45 +
   18.46 +// Private display data
   18.47 +typedef struct NX_SDL_VISUAL {
   18.48 +    int    bpp ;
   18.49 +    Uint32 red_mask ;
   18.50 +    Uint32 green_mask ;
   18.51 +    Uint32 blue_mask ;
   18.52 +} nx_sdl_visual_t ;
   18.53 +
   18.54 +struct SDL_PrivateVideoData {
   18.55 +    GR_WINDOW_ID    SDL_Window ;
   18.56 +    GR_WINDOW_ID    FSwindow ;
   18.57 +    // Flag: true if we have been passed a window
   18.58 +    char            * SDL_windowid ;
   18.59 +    GR_GC_ID        GC ;
   18.60 +    unsigned char   * Image ;
   18.61 +    unsigned char   * Image_buff ;
   18.62 +    nx_sdl_visual_t SDL_Visual ;
   18.63 +    // The current list of available video modes
   18.64 +    SDL_Rect        ** modelist ;
   18.65 +    int             currently_fullscreen ;
   18.66 +    // for fullscreen
   18.67 +    int             OffsetX, OffsetY ;
   18.68 +    // for GammaRamp
   18.69 +    Uint16          * GammaRamp_R, * GammaRamp_G, * GammaRamp_B ;
   18.70 +    // for GrArea, r_mask, g_mask, b_mask
   18.71 +    int             pixel_type ;
   18.72 +} ;
   18.73 +
   18.74 +#define SDL_Window           (this -> hidden -> SDL_Window)
   18.75 +#define FSwindow             (this -> hidden -> FSwindow)
   18.76 +#define SDL_windowid         (this -> hidden -> SDL_windowid)
   18.77 +#define SDL_GC               (this -> hidden -> GC)
   18.78 +#define SDL_Image            (this -> hidden -> Image)
   18.79 +#define Image_buff           (this -> hidden -> Image_buff)
   18.80 +#define SDL_Visual           (this -> hidden -> SDL_Visual)
   18.81 +#define SDL_modelist         (this -> hidden -> modelist)
   18.82 +#define currently_fullscreen (this -> hidden -> currently_fullscreen)
   18.83 +#define OffsetX              (this -> hidden -> OffsetX)
   18.84 +#define OffsetY              (this -> hidden -> OffsetY)
   18.85 +#define GammaRamp_R          (this -> hidden -> GammaRamp_R)
   18.86 +#define GammaRamp_G          (this -> hidden -> GammaRamp_G)
   18.87 +#define GammaRamp_B          (this -> hidden -> GammaRamp_B)
   18.88 +#define pixel_type           (this -> hidden -> pixel_type)
   18.89 +
   18.90 +#define CI_SIZE 256   // color index size
   18.91 +
   18.92 +#endif  // _SDL_nxvideo_h
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/video/nanox/SDL_nxwm.c	Fri May 11 01:13:35 2001 +0000
    19.3 @@ -0,0 +1,63 @@
    19.4 +/*
    19.5 +    SDL - Simple DirectMedia Layer
    19.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    19.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    19.8 +
    19.9 +    This library is free software; you can redistribute it and/or
   19.10 +    modify it under the terms of the GNU Library General Public
   19.11 +    License as published by the Free Software Foundation; either
   19.12 +    version 2 of the License, or (at your option) any later version.
   19.13 +
   19.14 +    This library is distributed in the hope that it will be useful,
   19.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19.17 +    Library General Public License for more details.
   19.18 +
   19.19 +    You should have received a copy of the GNU Library General Public
   19.20 +    License along with this library; if not, write to the Free
   19.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.22 +
   19.23 +    Sam Lantinga
   19.24 +    slouken@devolution.com
   19.25 +    
   19.26 +    Hsieh-Fu Tsai
   19.27 +    clare@setabox.com
   19.28 +*/
   19.29 +
   19.30 +#include <stdlib.h>
   19.31 +
   19.32 +#include "SDL_syswm.h"
   19.33 +#include "SDL_error.h"
   19.34 +#include "SDL_events_c.h"
   19.35 +
   19.36 +#include "SDL_nxwm_c.h"
   19.37 +
   19.38 +void NX_SetCaption (_THIS, const char * title, const char * icon)
   19.39 +{
   19.40 +    Dprintf ("enter NX_SetCaption\n") ;
   19.41 +
   19.42 +    // Lock the event thread, in multi-threading environments
   19.43 +    SDL_Lock_EventThread () ;
   19.44 +    
   19.45 +    if (SDL_Window) 
   19.46 +        GrSetWindowTitle (SDL_Window, title) ;
   19.47 +    
   19.48 +    SDL_Unlock_EventThread () ;
   19.49 +    Dprintf ("leave NX_SetCaption\n") ;
   19.50 +}
   19.51 +
   19.52 +int NX_GetWMInfo (_THIS, SDL_SysWMinfo * info)
   19.53 +{
   19.54 +    Dprintf ("enter NX_GetWMInfo\n") ;
   19.55 +
   19.56 +    if (info -> version.major <= SDL_MAJOR_VERSION) {
   19.57 +        info -> window = SDL_Window ;
   19.58 +        return 1 ;
   19.59 +    } else {
   19.60 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
   19.61 +            SDL_MAJOR_VERSION, SDL_MINOR_VERSION) ;
   19.62 +        return -1 ;
   19.63 +    }
   19.64 +
   19.65 +    Dprintf ("leave NX_GetWMInfo\n") ;
   19.66 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/nanox/SDL_nxwm_c.h	Fri May 11 01:13:35 2001 +0000
    20.3 @@ -0,0 +1,31 @@
    20.4 +/*
    20.5 +    SDL - Simple DirectMedia Layer
    20.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    20.7 +    Copyright (C) 2001  Hsieh-Fu Tsai
    20.8 +
    20.9 +    This library is free software; you can redistribute it and/or
   20.10 +    modify it under the terms of the GNU Library General Public
   20.11 +    License as published by the Free Software Foundation; either
   20.12 +    version 2 of the License, or (at your option) any later version.
   20.13 +
   20.14 +    This library is distributed in the hope that it will be useful,
   20.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.17 +    Library General Public License for more details.
   20.18 +
   20.19 +    You should have received a copy of the GNU Library General Public
   20.20 +    License along with this library; if not, write to the Free
   20.21 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   20.22 +
   20.23 +    Sam Lantinga
   20.24 +    slouken@devolution.com
   20.25 +    
   20.26 +    Hsieh-Fu Tsai
   20.27 +    clare@setabox.com
   20.28 +*/
   20.29 +
   20.30 +#include "SDL_nxvideo.h"
   20.31 +
   20.32 +// Functions to be exported
   20.33 +extern void NX_SetCaption (_THIS, const char * title, const char * icon) ;
   20.34 +extern int NX_GetWMInfo (_THIS, SDL_SysWMinfo * info) ;