diff -Nur SDL-1.2.5_agawa.org/src/video/qtopia/SDL_QWin.cc SDL-1.2.5_pi/src/video/qtopia/SDL_QWin.cc
--- SDL-1.2.5_agawa.org/src/video/qtopia/SDL_QWin.cc	2004-06-14 19:11:07.000000000 +0900
+++ SDL-1.2.5_pi/src/video/qtopia/SDL_QWin.cc	2004-06-14 19:14:28.000000000 +0900
@@ -25,12 +25,17 @@
 static char rcsid =
  "@(#) $Id: SDL_QWin.cc,v 1.3 2002/09/01 00:37:24 slouken Exp $";
 #endif
-
+#include <stdio.h>
 #include "SDL_QWin.h"
 #include <qapplication.h>
 #include <qpe/qpeapplication.h>
 #include <qdirectpainter_qws.h>
 
+extern int fb_hwrot;
+extern int fb_direct;
+extern bool is_VGA_machine;
+static int mouse_button_mode=1;
+
 screenRotationT screenRotation = SDL_QT_NO_ROTATION;
 
 SDL_QWin::SDL_QWin(const QSize& size)
@@ -100,52 +105,63 @@
   }
 #else
   QPoint realPos;
-  switch (qteRotation_) {
-  case 0:
-    realPos = pos;
-    break;
-  case 1:
-    realPos.setX(pos.y());
-    realPos.setY(fbSize_.height() - 1 - pos.x());
-    break;
-  case 2:
-    realPos.setX(fbSize_.width() - 1 - pos.x());
-    realPos.setY(fbSize_.height() - 1 - pos.y());
-    break;
-  case 3:
-    realPos.setX(fbSize_.width() - 1 - pos.y());
-    realPos.setY(pos.x());
-    break;
-  };
-
-//   fprintf(stderr, "setMousePos: realPos(%d, %d)\n", realPos.x(), realPos.y());
 
-  int borderWidth = (fbSize_.width() - my_image->width()) >> 1;
-  int borderHeight = (fbSize_.height() - my_image->height()) >> 1;
-  if ( rotation_ & 1 ){
-    borderWidth = (fbSize_.height() - my_image->width()) >> 1;
-    borderHeight = (fbSize_.width() - my_image->height()) >> 1;
-  }
-  realPos.setX(realPos.x() - borderWidth);
-  realPos.setY(realPos.y() - borderHeight);
-
-  switch (rotation_) {
-  case 0:
-    my_mouse_pos = realPos;
-    break;
-  case 1:
-    my_mouse_pos.setX(realPos.y());
-    my_mouse_pos.setY(my_image->height() - 1 - realPos.x());
-    break;
-  case 2:
-    my_mouse_pos.setX(my_image->width() - 1 - realPos.x());
-    my_mouse_pos.setY(my_image->height() - 1 - realPos.y());
-    break;
-  case 3:
-    my_mouse_pos.setX(realPos.y());//my_image->width() - 1 - realPos.y());
-    my_mouse_pos.setY(my_image->height() - realPos.x());
-    break;
+  if (is_VGA_machine) {
+	realPos = pos;
+	my_mouse_pos = realPos;
+  }else {
+	  switch (qteRotation_) {
+	  case 0:
+	    realPos = pos;
+	    break;
+	  case 1:
+	    realPos.setX(pos.y());
+	    realPos.setY(fbSize_.height() - 1 - pos.x());
+	    break;
+	  case 2:
+	    realPos.setX(fbSize_.width() - 1 - pos.x());
+	    realPos.setY(fbSize_.height() - 1 - pos.y());
+	    break;
+	  case 3:
+	    realPos.setX(fbSize_.width() - 1 - pos.y());
+	    realPos.setY(pos.x());
+	    break;
+	  };
+	
+	//   fprintf(stderr, "setMousePos: realPos(%d, %d)\n", realPos.x(), realPos.y());
+
+	  int borderWidth = (fbSize_.width() - my_image->width()) >> 1;
+	  int borderHeight = (fbSize_.height() - my_image->height()) >> 1;
+	  if ( rotation_ & 1 ){
+	    borderWidth = (fbSize_.height() - my_image->width()) >> 1;
+	    borderHeight = (fbSize_.width() - my_image->height()) >> 1;
+	  }
+	  realPos.setX(realPos.x() - borderWidth);
+	  realPos.setY(realPos.y() - borderHeight);
+
+	   fprintf(stderr, "setMousePos: realPos2(%d, %d)\n", realPos.x(), realPos.y());
+
+	  switch (rotation_) {
+	  case 0:
+	    my_mouse_pos = realPos;
+	    break;
+	  case 1:
+	    my_mouse_pos.setX(realPos.y());
+	    my_mouse_pos.setY(my_image->height() - 1 - realPos.x());
+	    break;
+	  case 2:
+	    my_mouse_pos.setX(my_image->width() - 1 - realPos.x());
+	    my_mouse_pos.setY(my_image->height() - 1 - realPos.y());
+	    break;
+	  case 3:
+	    my_mouse_pos.setX(realPos.y());//my_image->width() - 1 - realPos.y());
+	    my_mouse_pos.setY(my_image->height() - realPos.x());
+	    break;
+	  }
   }
+
+//   fprintf(stderr, "setMousePos: mymousePos(%d, %d)\n", (short)my_mouse_pos.x(), (short)my_mouse_pos.y());
+
 #endif
 }
 
@@ -168,18 +184,14 @@
 void SDL_QWin::mousePressEvent(QMouseEvent *e) {
   mouseMoveEvent(e);
   Qt::ButtonState button = e->button();
-  SDL_PrivateMouseButton(SDL_PRESSED,
-			 (button & Qt::LeftButton) ? 1 :
-			 ((button & Qt::RightButton) ? 2 : 3),
+  SDL_PrivateMouseButton(SDL_PRESSED,mouse_button_mode,
 			 my_mouse_pos.x(), my_mouse_pos.y());
 }
 
 void SDL_QWin::mouseReleaseEvent(QMouseEvent *e) {
   setMousePos(e->pos());
   Qt::ButtonState button = e->button();
-  SDL_PrivateMouseButton(SDL_RELEASED,
-			 (button & Qt::LeftButton) ? 1 :
-			 ((button & Qt::RightButton) ? 2 : 3),
+  SDL_PrivateMouseButton(SDL_RELEASED,mouse_button_mode,
 			 my_mouse_pos.x(), my_mouse_pos.y());
   my_mouse_pos = QPoint(-1, -1);
 }
@@ -528,9 +540,18 @@
     case Qt::Key_F7: scancode = SDLK_F7; break;
     case Qt::Key_F8: scancode = SDLK_F8; break;
     case Qt::Key_F9: scancode = SDLK_F9; break;
-    case Qt::Key_F10: scancode = SDLK_F10; break;
-    case Qt::Key_F11: scancode = SDLK_F11; break;
-    case Qt::Key_F12: scancode = SDLK_F12; break;
+    case Qt::Key_F10: 
+      scancode = SDLK_F10;
+      mouse_button_mode=1;
+      break;
+    case Qt::Key_F11:
+      scancode = SDLK_F11;
+      mouse_button_mode=3;
+      break;
+    case Qt::Key_F12:
+      scancode = SDLK_F12;
+      mouse_button_mode=2;
+      break;
     case Qt::Key_F13: scancode = SDLK_F13; break;
     case Qt::Key_F14: scancode = SDLK_F14; break;
     case Qt::Key_F15: scancode = SDLK_F15; break;
@@ -539,6 +560,12 @@
     case Qt::Key_Menu: scancode = SDLK_MENU; break;
     case Qt::Key_Help: scancode = SDLK_HELP; break;
 
+    case 0x5001:                                //zaurus zen key Qt::Key_F21
+    case 0x5002: scancode = SDLK_LSUPER; break; //zaurus zen key Qt::Key_F25
+    case 0x5003:                                //zaurus kana key Qt::Key_F26
+    case 0x5004: scancode = SDLK_RSUPER; break; //zaurus kana key Qt::Key_F31
+    case Qt::Key_F22: scancode = SDLK_MENU; break;   //zaurus Fn key
+
     case Qt::Key_F33:
       // FIXME: This is a hack to enable the OK key on
       // Zaurii devices. SDLK_RETURN is a suitable key to use
diff -Nur SDL-1.2.5_agawa.org/src/video/qtopia/SDL_sysvideo.cc SDL-1.2.5_pi/src/video/qtopia/SDL_sysvideo.cc
--- SDL-1.2.5_agawa.org/src/video/qtopia/SDL_sysvideo.cc	2004-06-14 19:11:07.000000000 +0900
+++ SDL-1.2.5_pi/src/video/qtopia/SDL_sysvideo.cc	2004-06-14 23:24:49.000000000 +0900
@@ -31,20 +31,31 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
 
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <linux/fb.h>
+#include <sys/mman.h>
+#include <asm/page.h>	
 
 #include <qapplication.h>
 #include <qpe/qpeapplication.h>
 #include <qpe/qcopenvelope_qws.h>
+#include <qgfx_qws.h>
+#include <qwindowsystem_qws.h>
+#include <qwidget.h>
+#include <qwidgetlist.h>
+#include <qdirectpainter_qws.h>
 
 #include "SDL.h"
 #include "SDL_timer.h"
 
 #include "SDL_QWin.h"
+#include "SDL_sysvideo.h"
 
 extern "C" {
 
@@ -136,6 +147,20 @@
   static int QT_IconifyWindow(_THIS);
   static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode);
 
+  static int console_fd;
+  struct fb_var_screeninfo saved_vinfo;
+  int fb_hwrot;
+  int fb_direct;
+  static int isKHloaded;
+  bool is_VGA_machine;
+ 
+#define W100FB_CONFIG          0x57415200 /* WAL\00 */
+#define W100INIT_ITEM          0
+#define W100INIT_ALL           1
+#define W100INIT_ITEM_WITH_VAL 2
+#define W100FB_CONFIG_EX       0x57415202 /* WAL\02 */
+
+
   /* FB driver bootstrap functions */
 
   static int QT_Available(void)
@@ -280,13 +305,34 @@
 
   int QT_VideoInit(_THIS, SDL_PixelFormat *vformat)
   {
-    /* Initialize the QPE Application  */
+    const char *SDL_fbdev;
+    struct fb_var_screeninfo vinfo;
+
+     /* Initialize the QPE Application  */
      /* Determine the screen depth */
     vformat->BitsPerPixel = QPixmap::defaultDepth();
 
     // For now we hardcode the current depth because anything else
     // might as well be emulated by SDL rather than by Qtopia.
 
+    //frame buffer device open.
+    SDL_fbdev = getenv("SDL_FBDEV");
+    if ( SDL_fbdev == NULL ) {
+    	SDL_fbdev = "/dev/fb0";
+    }
+    console_fd = open(SDL_fbdev, O_RDWR, 0);
+    if ( console_fd < 0 ) {
+    	SDL_SetError("Unable to open %s", SDL_fbdev);
+    	return(-1);
+    }
+
+    if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
+    	SDL_SetError("Couldn't get console pixel format");
+    	QT_VideoQuit(_this);
+    	return(-1);
+    }
+    saved_vinfo = vinfo;
+
     QSize desktop_size = qApp->desktop()->size();
     QT_AddMode(_this, ((vformat->BitsPerPixel+7)/8)-1,
 	       desktop_size.width(), desktop_size.height());
@@ -304,12 +350,20 @@
     if (!st_logfp)
       st_logfp = stderr;
 #endif
+
 
+    QT_GrabInput(_this, SDL_GRAB_ON);
+/*
     {
       QCopEnvelope e("QPE/KeyHelper", "repeater(int)");
       e << 2;
     }
-
+*/
+    isKHloaded=(fopen("/home/zaurus/Settings/keyhelper_SDL.xml","r") != NULL) ? 1 : 0;
+    if (isKHloaded) {
+	system("qcop QPE/KeyHelper \"reload(QString)\" keyhelper_SDL.xml"); //QcopEnvelope can't use. 
+	LOG("keyhelper_SDL.xml loaded\n");
+    }
     return(0);
   }
 
@@ -332,6 +386,7 @@
 
   /* Various screen update functions available */
   static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
+  static void QT_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
 
 
   static int QT_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen)
@@ -353,11 +408,13 @@
     fp = fopen("/proc/deviceinfo/product", "rb");
     if (fp) {
       if (fread(buf, 1, sizeof(buf), fp) > 0) {
-        LOG("QT_GetMachine: /proc/deviceinfo/product is '%s'\n", buf);
+//        LOG("QT_GetMachine: /proc/deviceinfo/product is %s\n", buf);
         if (strncmp(buf, "SL-A300", 7) == 0)
           machine = MACHINE_SHARP_SLA300;
         else if (strncmp(buf, "SL-5500", 7) == 0)
           machine = MACHINE_SHARP_SL5500;
+        else if (strncmp(buf, "SL-6000", 7) == 0) // 詳しいことわからんけどとりあえず
+          machine = MACHINE_SHARP_SL6000;
         else if (strncmp(buf, "SL-B500", 7) == 0)
           machine = MACHINE_SHARP_SLB500;
         else if (strncmp(buf, "SL-C700", 7) == 0)
@@ -433,6 +490,20 @@
     QSize qteSize = qApp->desktop()->size();
     QSize fbSize;
     QSize userSize;
+    int fb_xres;
+    int fb_yres;
+    struct fb_var_screeninfo vinfo;
+    struct fb_fix_screeninfo finfo;
+    int tmp_ioctl_data;
+    char fb_size_fix = ' ';
+    bool isW100patch_kernel = false;
+    int numFb_Size;
+
+    int mapped_memlen;
+    int mapped_offset;
+    void *mapped_mem;
+    int fb_offset;
+
 
     machine_t machine = QT_GetMachine(_this);
     machine_spec_t machineSpec = st_machine_spec[machine];
@@ -440,9 +511,174 @@
     int qteKeyRotation, sdlKeyRotation;
     bool isQteQvga;
 
+    if (machine == MACHINE_SHARP_SLC700 ||
+        machine == MACHINE_SHARP_SLC750 ||
+        machine == MACHINE_SHARP_SLC760 ||
+        machine == MACHINE_SHARP_SLC860 ||      // 詳しいことわからんけどとりあえず
+        machine == MACHINE_SHARP_SL6000 ) {     // 詳しいことわからんけどとりあえず
+	is_VGA_machine = true;
+    }else {
+	is_VGA_machine = false;
+    }
+
     // qte での回転角度を取得
     QT_GetQteServerSpec(_this, &qteRotation, &isQteQvga);
 
+    // SL-C700 のスタイル
+    bool isInputStyle = false;
+    if (is_VGA_machine) {
+      int status = system("/home/QtPalmtop/bin/chkhinge");
+      if (WEXITSTATUS(status) != 2)
+        isInputStyle = true;
+      LOG("QT_SetVideoMode: SL-C700 Style is %s\n",
+          isInputStyle ? "Input style" : "View style");
+    }
+
+    
+    // specity screen setting
+    if (is_VGA_machine) {
+
+	// w100 rotation pached kernel check
+      isW100patch_kernel = (fopen("/proc/driver/w100/rotation","r") != NULL) ? true : false;
+      LOG("Your Kernel is %s\n",isW100patch_kernel ? "Special Kernel" : "Normal Kernel");
+
+      const char *envFb_Size = getenv("SDL_FB_SIZE");
+      if (envFb_Size !=NULL) {
+	numFb_Size=sscanf(envFb_Size,"%dx%d%c",&fb_xres,&fb_yres,&fb_size_fix);
+      } else {
+	numFb_Size=0;
+      }
+
+      if (numFb_Size >=2) {
+
+	// specity screen mode
+	if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
+		SDL_SetError("Couldn't get console pixel format");
+		QT_VideoQuit(_this);
+		return(NULL);
+	}
+
+	vinfo.xres = fb_xres;
+	vinfo.xres_virtual = fb_xres;
+	vinfo.yres = fb_yres;
+	vinfo.yres_virtual = fb_yres;
+
+	if (fb_size_fix == '@') {
+		width = fb_xres;
+		height = fb_yres;
+	}
+
+	if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) {
+		SDL_SetError("Couldn't set console screen info");
+		return(NULL);
+	}
+
+
+	if (isW100patch_kernel) {
+		qteSize.setWidth(vinfo.xres);
+		qteSize.setHeight(vinfo.yres);
+		qteRotation=0;
+	}else if(vinfo.xres == 320){
+		qteSize.setWidth(vinfo.xres);
+		qteSize.setHeight(vinfo.yres);
+		qteRotation=2;
+	}else {
+		qteSize.setWidth(vinfo.yres);
+		qteSize.setHeight(vinfo.xres);
+		qteRotation=3;
+	}			
+
+	if (isW100patch_kernel && (vinfo.xres == 320) && (vinfo.yres == 240)) {
+		tmp_ioctl_data=121;
+		ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data);
+		fb_hwrot=1;	
+	}
+
+	LOG("FBVideoMode: %dx%d%c\n", vinfo.xres, vinfo.yres,fb_size_fix );
+
+      }else {
+
+	// auto screen mode	
+	if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
+		SDL_SetError("Couldn't get console pixel format");
+		QT_VideoQuit(_this);
+		return(NULL);
+	}
+
+	if (isW100patch_kernel && (isInputStyle == false) && (vinfo.xres == 240) && (vinfo.yres == 320)) {
+		vinfo.xres = 240;
+		vinfo.xres_virtual = 240;
+		vinfo.yres = 320;
+		vinfo.yres_virtual = 320;
+		qteRotation=0;
+	}else if ((width <= 320) && (height <= 240)) {
+		vinfo.xres = 320;
+		vinfo.xres_virtual = 320;
+		vinfo.yres = 240;
+		vinfo.yres_virtual = 240;
+	}else if (isW100patch_kernel && (isInputStyle == true)){
+		vinfo.xres = 640;
+		vinfo.xres_virtual = 640;
+		vinfo.yres = 480;
+		vinfo.yres_virtual = 480;
+		qteRotation=0;
+	}else {
+		vinfo.xres = 480;
+		vinfo.xres_virtual = 480;
+		vinfo.yres = 640;
+		vinfo.yres_virtual = 640;
+	}
+
+		if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) {
+		SDL_SetError("Couldn't set console screen info");
+		return(NULL);
+	}
+
+	if (isW100patch_kernel) {
+		qteSize.setWidth(vinfo.xres);
+		qteSize.setHeight(vinfo.yres);
+		qteRotation=0;
+		fb_direct=1;
+	}else if(vinfo.xres == 320){
+		qteSize.setWidth(vinfo.xres);
+		qteSize.setHeight(vinfo.yres);
+		qteRotation=2;
+	}else {
+		qteSize.setWidth(vinfo.yres);
+		qteSize.setHeight(vinfo.xres);
+		qteRotation=3;
+	}			
+
+	if (isW100patch_kernel && (vinfo.xres == 320) && (vinfo.yres == 240)) {
+		tmp_ioctl_data=121;
+		ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data);	
+		fb_hwrot=1;
+		qteRotation=0;
+	}
+
+	LOG("FBVideoMode: %dx%d%c\n", vinfo.xres, vinfo.yres,fb_size_fix );
+      }
+    }
+
+    // direct paint setting
+    const char *envFb_Direct = getenv("SDL_FB_DIRECT");
+    if (envFb_Direct !=NULL)
+	fb_direct = envFb_Direct ? atoi(envFb_Direct) : -1;
+
+    if (fb_direct == 1){
+	if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
+		SDL_SetError("Couldn't get console hardware info");
+		QT_VideoQuit(_this);
+		return(NULL);
+    	}
+        if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
+		SDL_SetError("Couldn't get console pixel format");
+		QT_VideoQuit(_this);
+                return(NULL);
+        }
+	LOG("Direct paint mode\n");
+    }
+
     // hack for SL-5500
     if (machine == MACHINE_SHARP_SL5500)
       qteRotation = 3;
@@ -450,11 +686,7 @@
     // SL-B500 用ハック(とりあえず、ね)
     if (machine == MACHINE_SHARP_SLB500)
       qteRotation = 3;
-#if 0
-    // SL-C750/760 用ハック(Thanks to 浜地さん)
-    if (machine == MACHINE_SHARP_SLC750 || machine == MACHINE_SHARP_SLC760)
-      qteRotation = (qteRotation + 2) & 3;
-#endif
+
     // 生フレームバッファのサイズを得る
     if (qteRotation & 1) {
       fbSize.setWidth(qteSize.height());
@@ -473,20 +705,6 @@
       userSize = fbSize;
     }
 
-    // SL-C700 のスタイル
-    bool isInputStyle = false;
-    if (machine == MACHINE_SHARP_SLC700 ||
-        machine == MACHINE_SHARP_SLC750 ||
-        machine == MACHINE_SHARP_SLC760 ||
-        machine == MACHINE_SHARP_SLC860 ||
-        machine == MACHINE_SHARP_SL6000) {
-      int status = system("/home/QtPalmtop/bin/chkhinge");
-      if (WEXITSTATUS(status) != 2)
-        isInputStyle = true;
-      LOG("QT_SetVideoMode: SL-C700 Style is %s\n",
-          isInputStyle ? "Input style" : "View style");
-    }
-
     // まず、要求されたウィンドウサイズがユーザの望む回転角度のスクリーンに
     // 収まるのかをチェック。
     if (width <= userSize.width() && height <= userSize.height()) {
@@ -496,12 +714,7 @@
       else {
         // で、その指定が無いのであれば qte の回転角度に合わせるだけ
         // なんだけど、SL-C700 ではちょい複雑。
-        if ((machine == MACHINE_SHARP_SLC700 ||
-             machine == MACHINE_SHARP_SLC750 ||
-             machine == MACHINE_SHARP_SLC760 ||
-             machine == MACHINE_SHARP_SLC860 ||
-             machine == MACHINE_SHARP_SL6000) &&
-            fbSize.width() == 320 && fbSize.height() == 240) {
+	if (is_VGA_machine && (fbSize.width() == 320) && (fbSize.height() == 240)) {
           if (isInputStyle)
             sdlRotation = 2;
           else
@@ -512,13 +725,7 @@
       }
     } else if (width <= fbSize.width() && height <= fbSize.height()) {
       sdlRotation = 0;
-      if ((machine == MACHINE_SHARP_SLC700 ||
-           machine == MACHINE_SHARP_SLC750 ||
-           machine == MACHINE_SHARP_SLC760 ||
-           machine == MACHINE_SHARP_SLC860 ||
-           machine == MACHINE_SHARP_SL6000) &&
-          fbSize.width() == 320 && fbSize.height() == 240
-          && isInputStyle)
+      if (is_VGA_machine && (fbSize.width() == 320) && (fbSize.height() == 240) && isInputStyle)
         sdlRotation = 2;
     } else if (width <= fbSize.height() && height <= fbSize.width()) {
       sdlRotation = 1;
@@ -527,13 +734,13 @@
       return NULL;
     }
 
+    if (fb_hwrot == 1) 
+	sdlRotation = 0;
+
     if (getenv(SDL_QT_INVERT_ROTATION_ENV_NAME) != NULL) {
       sdlRotation = (sdlRotation + 2) & 3;
     }
-#if 0
-    if (machine == MACHINE_SHARP_SLC750 || machine == MACHINE_SHARP_SLC760)
-      sdlRotation = (sdlRotation + 2) & 3;
-#endif
+
     LOG("QT_SetVideoMode: argSize=%dx%d\n", width, height);
     LOG("QT_SetVideoMode: qteSize=%dx%d\n",
         qteSize.width(), qteSize.height());
@@ -556,15 +763,14 @@
     qteKeyRotation = qteRotation;
 //     fprintf(stderr, "%d\n", (machine == MACHINE_SHARP_SLC700));
 //     fprintf(stderr, "%d\n", isQteQvga);
-    if (isQteQvga && (machine == MACHINE_SHARP_SLC700 ||
-                      machine == MACHINE_SHARP_SLC750 ||
-                      machine == MACHINE_SHARP_SLC760 ||
-                      machine == MACHINE_SHARP_SLC860 ||
-                      machine == MACHINE_SHARP_SL6000))
+    if (isQteQvga && is_VGA_machine)
       qteKeyRotation = 3;
     else if (machine == MACHINE_SHARP_SLB500)
       qteKeyRotation = 3;
 
+    if (isQteQvga && fb_hwrot == 1) 
+      qteKeyRotation = 1;
+
     sdlKeyRotation = sdlRotation;
 
     SDL_Win->setKeyRotation(sdlKeyRotation, qteKeyRotation);
@@ -572,25 +778,51 @@
     LOG("QT_SetVideoMode: qteKeyRotation=%d\n", qteKeyRotation);
     LOG("QT_SetVideoMode: sdlKeyRotation=%d\n", sdlKeyRotation);
 
-//     if (isSlc700 && isQvga)
-//       SDL_Win->setSLC700InputFix(true);
-
     if ( flags & SDL_OPENGL ) {
       SDL_SetError("OpenGL not supported");
       return(NULL);
     }
     /* Create the QImage framebuffer */
-    qimage = new QImage(current->w, current->h, bpp);
-    if (qimage->isNull()) {
-      SDL_SetError("Couldn't create screen bitmap");
-      delete qimage;
-      return(NULL);
+
+    // frame buffer memory mapping    
+    if (fb_direct == 1) {
+	current->pitch = finfo.line_length;
+        current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
+        mapped_offset = (((long)finfo.smem_start) -
+	                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
+	mapped_memlen = finfo.smem_len+mapped_offset;
+        if(console_fd >0 ) {
+		mapped_mem = mmap(NULL, mapped_memlen,PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
+		fb_offset=(vinfo.xres-width)+(vinfo.yres-height)*vinfo.xres;
+		current->pixels = (void *)((int )mapped_mem+fb_offset);
+                _this->UpdateRects = QT_DirectUpdate;
+    	} else {
+		qimage = new QImage(current->w, current->h, bpp);
+		if (qimage->isNull()) {
+			SDL_SetError("Couldn't create screen bitmap");
+			delete qimage;
+			return(NULL);
+		}
+    		current->pixels = (void *)qimage->bits();
+                _this->UpdateRects = QT_NormalUpdate;
+		SDL_Win->setImage(qimage);
+//		SDL_Win->setFullscreen(true);  //comment to non update taskbar
+    	}
+    } else {
+	qimage = new QImage(current->w, current->h, bpp);
+	if (qimage->isNull()) {
+		SDL_SetError("Couldn't create screen bitmap");
+		delete qimage;
+		return(NULL);
+	}
+	current->pitch = qimage->bytesPerLine();
+	current->pixels = (void *)qimage->bits();
+        _this->UpdateRects = QT_NormalUpdate;
+	SDL_Win->setImage(qimage);
+//	SDL_Win->setFullscreen(true);  //comment out to non update taskbar
+
     }
-    current->pitch = qimage->bytesPerLine();
-    current->pixels = (void *)qimage->bits();
-    SDL_Win->setImage(qimage);
-    _this->UpdateRects = QT_NormalUpdate;
-    SDL_Win->setFullscreen(true);
+
 
     //     fprintf(stderr,"QT_SetVideoMode() qImage:%dx%d %d\n",
     // 			qimage->width(), qimage->height(), qimage->bytesPerLine());
@@ -645,6 +877,12 @@
       SDL_Win->unlockScreen();
     }
   }
+
+  static void QT_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
+  {
+
+  }
+
   /* Is the system palette settable? */
   int QT_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   {
@@ -660,15 +898,36 @@
     //    -- David Hedbor
     //    delete SDL_Win; 
     //    SDL_Win = 0;
+
+    if ( console_fd > 0 ) {
+    	/* Restore the original video mode and palette */
+	if (fb_hwrot == 1) {
+		int tmp_ioctl_data=120;
+		ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data);	
+	}
+
+    	ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo);
+
+    	/* We're all done with the framebuffer */
+    	close(console_fd);
+    	console_fd = -1;
+    }
+
     _this->screen->pixels = NULL;
     QT_GrabInput(_this, SDL_GRAB_OFF);
-
+/*
     {
       QCopEnvelope e("QPE/KeyHelper", "repeater(int)");
       e << 1;
     }
+*/
+    if (isKHloaded)
+	system("qcop QPE/KeyHelper \"reload()\""); //QcopEnvelope can't use. 
+
   }
 
+
+
   static int QT_IconifyWindow(_THIS) {
     SDL_Win->hide();
     
