]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/libsdl/libsdl-qpe-1.2.7/agawa-piro-mickey.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / libsdl / libsdl-qpe-1.2.7 / agawa-piro-mickey.patch
1
2 #
3 # Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
4 #
5
6 Index: SDL-1.2.7/src/video/qtopia/SDL_QWin.cc
7 ===================================================================
8 --- SDL-1.2.7.orig/src/video/qtopia/SDL_QWin.cc 2005-03-02 22:24:43.457491622 +0100
9 +++ SDL-1.2.7/src/video/qtopia/SDL_QWin.cc      2005-03-02 22:24:46.867009932 +0100
10 @@ -1,3 +1,4 @@
11 +
12  /*
13      SDL - Simple DirectMedia Layer
14      Copyright (C) 1997-2004 Sam Lantinga
15 @@ -27,15 +28,24 @@
16  
17  #include "SDL_QWin.h"
18  #include <qapplication.h>
19 +#include <qpe/qpeapplication.h>
20  #include <qdirectpainter_qws.h>
21  
22 +extern int fb_hwrot;
23 +extern int fb_direct;
24 +extern bool is_VGA_machine;
25 +static int mouse_button_mode=1;
26 +
27  screenRotationT screenRotation = SDL_QT_NO_ROTATION;
28  
29  SDL_QWin::SDL_QWin(const QSize& size)
30    : QWidget(0, "SDL_main"), my_painter(0), my_image(0),
31      my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0),
32 -    my_has_fullscreen(false), my_locked(0)
33 +    my_has_fullscreen(false), my_locked(0),
34 +    rotation_(0), qteRotation_(0), keyRotation_(0), qteKeyRotation_(0),
35 +    isSLA300InputFix_(0)
36  {
37 +  for (int i = 0; i < 5; i++) curAxis_[i] = 0;
38    setBackgroundMode(NoBackground);
39  }
40  
41 @@ -84,6 +94,7 @@
42  }
43  
44  void SDL_QWin::setMousePos(const QPoint &pos) {
45 +#if 0
46    if(my_image->width() == height()) {
47      if (screenRotation == SDL_QT_ROTATION_90)
48        my_mouse_pos = QPoint(height()-pos.y(), pos.x());
49 @@ -92,6 +103,66 @@
50    } else {
51      my_mouse_pos = pos;
52    }
53 +#else
54 +  QPoint realPos;
55 +
56 +  if (is_VGA_machine) {
57 +       realPos = pos;
58 +       my_mouse_pos = realPos;
59 +  }else {
60 +         switch (qteRotation_) {
61 +         case 0:
62 +           realPos = pos;
63 +           break;
64 +         case 1:
65 +           realPos.setX(pos.y());
66 +           realPos.setY(fbSize_.height() - 1 - pos.x());
67 +           break;
68 +         case 2:
69 +           realPos.setX(fbSize_.width() - 1 - pos.x());
70 +           realPos.setY(fbSize_.height() - 1 - pos.y());
71 +           break;
72 +         case 3:
73 +           realPos.setX(fbSize_.width() - 1 - pos.y());
74 +           realPos.setY(pos.x());
75 +           break;
76 +         };
77 +       
78 +       //   fprintf(stderr, "setMousePos: realPos(%d, %d)\n", realPos.x(), realPos.y());
79 +
80 +         int borderWidth = (fbSize_.width() - my_image->width()) >> 1;
81 +         int borderHeight = (fbSize_.height() - my_image->height()) >> 1;
82 +         if ( rotation_ & 1 ){
83 +           borderWidth = (fbSize_.height() - my_image->width()) >> 1;
84 +           borderHeight = (fbSize_.width() - my_image->height()) >> 1;
85 +         }
86 +         realPos.setX(realPos.x() - borderWidth);
87 +         realPos.setY(realPos.y() - borderHeight);
88 +
89 +          fprintf(stderr, "setMousePos: realPos2(%d, %d)\n", realPos.x(), realPos.y());
90 +
91 +         switch (rotation_) {
92 +         case 0:
93 +           my_mouse_pos = realPos;
94 +           break;
95 +         case 1:
96 +           my_mouse_pos.setX(realPos.y());
97 +           my_mouse_pos.setY(my_image->height() - 1 - realPos.x());
98 +           break;
99 +         case 2:
100 +           my_mouse_pos.setX(my_image->width() - 1 - realPos.x());
101 +           my_mouse_pos.setY(my_image->height() - 1 - realPos.y());
102 +           break;
103 +         case 3:
104 +           my_mouse_pos.setX(realPos.y());//my_image->width() - 1 - realPos.y());
105 +           my_mouse_pos.setY(my_image->height() - realPos.x());
106 +           break;
107 +         }
108 +  }
109 +
110 +//   fprintf(stderr, "setMousePos: mymousePos(%d, %d)\n", (short)my_mouse_pos.x(), (short)my_mouse_pos.y());
111 +
112 +#endif
113  }
114  
115  void SDL_QWin::mouseMoveEvent(QMouseEvent *e) {
116 @@ -113,269 +184,318 @@
117  void SDL_QWin::mousePressEvent(QMouseEvent *e) {
118    mouseMoveEvent(e);
119    Qt::ButtonState button = e->button();
120 -  SDL_PrivateMouseButton(SDL_PRESSED,
121 -                        (button & Qt::LeftButton) ? 1 :
122 -                        ((button & Qt::RightButton) ? 2 : 3),
123 +  SDL_PrivateMouseButton(SDL_PRESSED,mouse_button_mode,
124                          my_mouse_pos.x(), my_mouse_pos.y());
125  }
126  
127  void SDL_QWin::mouseReleaseEvent(QMouseEvent *e) {
128    setMousePos(e->pos());
129    Qt::ButtonState button = e->button();
130 -  SDL_PrivateMouseButton(SDL_RELEASED,
131 -                        (button & Qt::LeftButton) ? 1 :
132 -                        ((button & Qt::RightButton) ? 2 : 3),
133 +  SDL_PrivateMouseButton(SDL_RELEASED,mouse_button_mode,
134                          my_mouse_pos.x(), my_mouse_pos.y());
135    my_mouse_pos = QPoint(-1, -1);
136  }
137  
138 -static inline void
139 -gs_fastRotateBlit_3 ( unsigned short *fb,
140 -                     unsigned short *bits,
141 -                     const QRect& rect )
142 +#ifndef __i386__
143 +
144 +static void
145 +blitRotate3(Uint16 *dstBits, const QSize& dstSize,
146 +            const Uint16 *srcBits, const QSize& srcSize,
147 +            const QRect& srcBlitRect);
148 +
149 +static void
150 +blitRotate0(Uint16 *dstBits, const QSize& dstSize,
151 +            const Uint16 *srcBits, const QSize& srcSize,
152 +            const QRect& srcBlitRect)
153  {
154 -  // FIXME: this only works correctly for 240x320 displays
155 -  int startx, starty;
156 -  int width, height;
157 -  
158 -  startx = rect.left() >> 1;
159 -  starty = rect.top() >> 1;
160 -  width  = ((rect.right() - rect.left()) >> 1) + 2;
161 -  height = ((rect.bottom() - rect.top()) >> 1) + 2;
162 -
163 -  if((startx+width) > 120) {
164 -    width = 120 - startx; // avoid horizontal overflow
165 -  }
166 -  if((starty+height) > 160) { 
167 -    height = 160 - starty; // avoid vertical overflow
168 -  }
169 -
170 -  ulong *sp1, *sp2, *dp1, *dp2;
171 -  ulong stop, sbot, dtop, dbot;    
172 -  
173 -  sp1 = (ulong*)bits + startx + starty*240;
174 -  sp2 = sp1 + 120;
175 -  dp1 = (ulong *)fb + (159 - starty) + startx*320;
176 -  dp2 = dp1 + 160;
177 -  int rowadd = (-320*width) - 1;
178 -  int rowadd2 = 240 - width;
179 -  // transfer in cells of 2x2 pixels in words
180 -  for (int y=0; y<height; y++) {
181 -    for (int x=0; x<width; x++) {
182 -      // read source pixels
183 -      stop = *sp1;
184 -      sbot = *sp2;
185 -      // rotate pixels
186 -      dtop = (sbot & 0xffff) + ((stop & 0xffff)<<16);
187 -      dbot = ((sbot & 0xffff0000)>>16) + (stop & 0xffff0000);
188 -      // write to framebuffer
189 -      *dp1 = dtop;
190 -      *dp2 = dbot;
191 -      // update source ptrs
192 -      sp1++; sp2++;
193 -      // update dest ptrs - 2 pix at a time
194 -      dp1 += 320;
195 -      dp2 += 320;
196 -    }
197 -    // adjust src ptrs - skip a row as we work in pairs
198 -    sp1 += rowadd2;
199 -    sp2 += rowadd2;
200 -    // adjust dest ptrs for rotation
201 -    dp1 += rowadd;
202 -    dp2 += rowadd;
203 +  srcBits += srcBlitRect.left() + srcBlitRect.top() * srcSize.width();
204 +  dstBits += ((dstSize.width() - srcSize.width()) >> 1)
205 +    + (((dstSize.height() - srcSize.height()) >> 1) * dstSize.width());
206 +  dstBits += srcBlitRect.left() + srcBlitRect.top() * dstSize.width();
207 +  int w = srcBlitRect.width() << 1;
208 +  int h = srcBlitRect.height();
209 +
210 +  while (h--) {
211 +    memcpy(dstBits, srcBits, w);
212 +    dstBits += dstSize.width();
213 +    srcBits += srcSize.width();
214    }
215  }
216  
217 -static inline void
218 -gs_fastRotateBlit_1 ( unsigned short *fb,
219 -                     unsigned short *bits,
220 -                     const QRect& rect ) {
221 -  // FIXME: this only works correctly for 240x320 displays
222 -  int startx, starty;
223 -  int width, height;
224 -
225 -  startx = rect.left() >> 1;
226 -  starty = rect.top() >> 1;
227 -  width  = ((rect.right() - rect.left()) >> 1) + 2;
228 -  height = ((rect.bottom() - rect.top()) >> 1) + 2;
229 -
230 -  if((startx+width) > 120) {
231 -    width = 120 - startx; // avoid horizontal overflow
232 -  }
233 -  if((starty+height) > 160) { 
234 -    height = 160 - starty; // avoid vertical overflow
235 -  }
236 -
237 -  ulong *sp1, *sp2, *dp1, *dp2;
238 -  ulong stop, sbot, dtop, dbot;    
239 -  fb += 320*239; // Move "fb" to top left corner
240 -  sp1 = (ulong*)bits + startx + starty*240;
241 -  sp2 = sp1 + 120;
242 -  dp1 = (ulong*)fb - startx * 320 - starty;
243 -  dp2 = dp1 - 160;
244 -  int rowadd = (320*width) + 1;
245 -  int rowadd2 = 240 - width;
246 -  // transfer in cells of 2x2 pixels in words
247 -  for (int y=0; y<height; y++) {
248 -    for (int x=0; x<width; x++) {
249 -      // read
250 -      stop = *sp1;
251 -      sbot = *sp2;
252 -      // rotate
253 -      dtop = (stop & 0xffff) + ((sbot & 0xffff)<<16);
254 -      dbot = ((stop & 0xffff0000)>>16) + (sbot & 0xffff0000);
255 -      // write
256 -      *dp1 = dtop;
257 -      *dp2 = dbot;
258 -      // update source ptrs
259 -      sp1++; sp2++;
260 -      // update dest ptrs - 2 pix at a time
261 -      dp1 -= 320;
262 -      dp2 -= 320;
263 -    }
264 -    // adjust src ptrs - skip a row as we work in pairs
265 -    sp1 += rowadd2;
266 -    sp2 += rowadd2;
267 -    // adjust dest ptrs for rotation
268 -    dp1 += rowadd;
269 -    dp2 += rowadd;
270 -  }
271 +static void
272 +blitRotate1(Uint16 *dstBits, const QSize& dstSize,
273 +            const Uint16 *srcBits, const QSize& srcSize,
274 +            const QRect& srcBlitRect)
275 +{
276 +//   fprintf(stdout, "SDL_QT_ROTATION (1) is not implemented.\n");
277 +  blitRotate3(dstBits, dstSize, srcBits, srcSize, srcBlitRect);
278  }
279  
280 -// desktop, SL-A300 etc
281 -bool SDL_QWin::repaintRotation0(const QRect& rect) {
282 -  if(my_image->width() == width()) {
283 -    uchar *fb = (uchar*)my_painter->frameBuffer();
284 -    uchar *buf = (uchar*)my_image->bits();
285 -    if(rect == my_image->rect()) {
286 -      memcpy(fb, buf, width()*height()*2);
287 -    } else {
288 -      int h = rect.height();
289 -      int wd = rect.width()<<1;
290 -      int fblineadd = my_painter->lineStep();
291 -      int buflineadd = my_image->bytesPerLine();
292 -      fb  += (rect.left()<<1) + rect.top() * my_painter->lineStep();
293 -      buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
294 -      while(h--) {
295 -       memcpy(fb, buf, wd);
296 -       fb += fblineadd;
297 -       buf += buflineadd;
298 -      }
299 +static void
300 +blitRotate2(Uint16 *dstBits, const QSize& dstSize,
301 +            const Uint16 *srcBits, const QSize& srcSize,
302 +            QRect srcBlitRect)
303 +{
304 +//   if (srcBlitRect.left() & 1)
305 +//     srcBlitRect.setLeft(srcBlitRect.left() - 1);
306 +//   if (srcBlitRect.right() & 1)
307 +//     srcBlitRect.setRight(srcBlitRect.right() - 1);
308 +
309 +  int dstBorderLeftRight = (dstSize.width() - srcSize.width()) >>1;
310 +  int dstBorderTopBottom = (dstSize.height() - srcSize.height()) >>1;
311 +  int dstStartOffsetX = dstSize.width() - dstBorderLeftRight - 2;
312 +  int dstStartOffsetY = dstSize.height() - dstBorderTopBottom - 1;
313 +  int left = srcBlitRect.left() & ~(int)1; // to be 32bit aligned
314 +  srcBits += left + srcBlitRect.top() * srcSize.width();
315 +  dstBits += dstStartOffsetY * dstSize.width() + dstStartOffsetX;
316 +  dstBits -= left;
317 +  dstBits -= srcBlitRect.top() * dstSize.width();
318 +
319 +  Uint32 *pSrc = (Uint32 *)srcBits;
320 +  Uint32 *pDst = (Uint32 *)dstBits;
321 +
322 +  int width = srcBlitRect.width(), width2 = srcBlitRect.width(), w;
323 +  if ( srcBlitRect.left() & 1 ){
324 +    width--; width2++;
325 +  }
326 +  if ( (srcBlitRect.left()+srcBlitRect.width()) & 1 ){
327 +    width--; width2++;
328 +  }
329 +  width >>= 1;
330 +  int height = srcBlitRect.height();
331 +  int srcYAdd = srcSize.width() - width2;
332 +  int dstYSub = dstSize.width() - width2;
333 +
334 +  while (height--) {
335 +    w = width;
336 +    if (srcBlitRect.left() & 1){
337 +      *((Uint16 *)pDst) = *(((Uint16 *)pSrc) + 1);
338 +      pDst--; pSrc++;
339      }
340 -  } else {
341 -    return false; // FIXME: Landscape
342 +    while (w--) {
343 +      *pDst-- = (*pSrc << 16) | (*pSrc >> 16);
344 +      ++pSrc;
345 +    }
346 +    if ((srcBlitRect.left()+srcBlitRect.width()) & 1){
347 +      *(((Uint16 *)pDst) + 1) = *((Uint16 *)pSrc);
348 +      pDst--; pSrc++;
349 +    }
350 +    pSrc += srcYAdd;
351 +    pDst -= dstYSub;
352    }
353 -#ifdef __i386__
354 -  my_painter->fillRect( rect, QBrush( Qt::NoBrush ) );
355 -#endif
356 -  return true;
357  }
358  
359 -  
360 -// Sharp Zaurus SL-5500 etc 
361 -bool SDL_QWin::repaintRotation3(const QRect& rect) {
362 -  if(my_image->width() == width()) {
363 -    ushort *fb = (ushort*)my_painter->frameBuffer();
364 -    ushort *buf = (ushort*)my_image->bits();
365 -    gs_fastRotateBlit_3(fb, buf, rect);
366 +#define BLIT_ROTATE_3_MOV32
367 +
368 +static void
369 +blitRotate3(Uint16 *dstBits, const QSize& dstSize,
370 +            const Uint16 *srcBits, const QSize& srcSize,
371 +            const QRect& srcBlitRect)
372 +{
373 +  if (srcBlitRect.width() != dstSize.height() ||
374 +      srcBlitRect.height() != dstSize.width()) {
375 +    // partial update
376 +    const Uint16 *pSrc = srcBits +
377 +      (srcBlitRect.left() + srcBlitRect.top() * srcSize.width());
378 +
379 +    int dstBorderLeftRight = (dstSize.width() - srcSize.height()) >>1;
380 +    int dstBorderTopBottom = (dstSize.height() - srcSize.width()) >>1;
381 +    int dstStartOffsetX = dstSize.width() - dstBorderLeftRight - 1;
382 +    int dstStartOffsetY = dstBorderTopBottom;
383 +    Uint16 *pDst = dstBits +
384 +      (dstStartOffsetY * dstSize.width() + dstStartOffsetX);
385 +    pDst += srcBlitRect.left() * dstSize.width();
386 +    pDst -= srcBlitRect.top();
387 +
388 +    int width = srcBlitRect.width(), height = srcBlitRect.height(), w;
389 +    int srcYAdd = srcSize.width() - srcBlitRect.width();
390 +    int dstXAdd = dstSize.width();
391 +    int dstYSub = (dstSize.width() * srcBlitRect.width()) + 1;
392 +
393 +#if 0
394 +    fprintf(stderr, "---- Blit begin\n");
395 +    fprintf(stderr, "srcSize.width: %d srcSize.height:%d\n",
396 +            srcSize.width(), srcSize.height());
397 +    fprintf(stderr, "srcBlitRect.left:%d srcBlitRect.right:%d srcBlitRect.top:%d srcBlitRect.bottom:%d srcBlitRect.width:%d srcBlitRect.height:%d\n",
398 +            srcBlitRect.left(), srcBlitRect.right(), srcBlitRect.top(), srcBlitRect.bottom(), srcBlitRect.width(), srcBlitRect.height());
399 +
400 +    fprintf(stderr, "dstSize.width: %d dstSize.height:%d\n",
401 +            dstSize.width(), dstSize.height());
402 +    fprintf(stderr, "dstBorderLeftRight:%d dstBorderTopBottom:%d dstStartOffsetX:%d dstStartOffsetY:%d\n",
403 +            dstBorderLeftRight, dstBorderTopBottom, dstStartOffsetX, dstStartOffsetY);
404 +    fprintf(stderr, "srcYAdd:%d dstXAdd:%d dstYSub:%d\n", srcYAdd, dstXAdd, dstYSub);
405 +#endif
406 +
407 +    while (height--) {
408 +      w = width;
409 +      while (w--) {
410 +        *pDst = *pSrc ++;
411 +        pDst += dstXAdd;
412 +      }
413 +      pSrc += srcYAdd;
414 +      pDst -= dstYSub;
415 +    }
416 +    //                 fprintf(stderr, "---- Blit end\n");
417    } else {
418 -    // landscape mode
419 -    if (screenRotation == SDL_QT_ROTATION_90) {
420 -      uchar *fb = (uchar*)my_painter->frameBuffer();
421 -      uchar *buf = (uchar*)my_image->bits();
422 -      if(rect == my_image->rect()) {
423 -       memcpy(fb, buf, width()*height()*2);
424 -      } else {
425 -       int h = rect.height();
426 -       int wd = rect.width()<<1;
427 -       int fblineadd = my_painter->lineStep();
428 -       int buflineadd = my_image->bytesPerLine();
429 -       fb  += (rect.left()<<1) + rect.top() * my_painter->lineStep();
430 -       buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
431 -       while(h--) {
432 -         memcpy(fb, buf, wd);
433 -         fb += fblineadd;
434 -         buf += buflineadd;
435 -       }
436 +    // full update
437 +#if !defined(BLIT_ROTATE_3_MOV32)
438 +    const Uint16 *src = srcBits;
439 +    Uint16 *dst = dstBits + (dstSize.width() - 1);
440 +    int w = srcBlitRect.width();
441 +    int h = srcBlitRect.height();
442 +    int i, dstSub = dstSize.width() * w + 1;
443 +    int dstAdd = dstSize.width();
444 +
445 +    while (h--) {
446 +      i = w;
447 +      while (i--) {
448 +        *dst = *src ++;
449 +        dst += dstAdd;
450        }
451 -    } else if (screenRotation == SDL_QT_ROTATION_270) {
452 -      int h = rect.height();
453 -      int wd = rect.width();
454 -      int fblineadd = my_painter->lineStep() - (rect.width() << 1);
455 -      int buflineadd = my_image->bytesPerLine() - (rect.width() << 1);
456 -      int w;
457 -
458 -      uchar *fb = (uchar*)my_painter->frameBuffer();
459 -      uchar *buf = (uchar*)my_image->bits();
460 -        
461 -      fb += ((my_painter->width() - (rect.top() + rect.height())) * 
462 -            my_painter->lineStep()) + ((my_painter->height() - ((rect.left() + 
463 -                                                                 rect.width()))) << 1);
464 -
465 -      buf += my_image->bytesPerLine() * (rect.top() + rect.height()) -
466 -       (((my_image->width() - (rect.left() + rect.width())) << 1) + 2);
467 -
468 -      while(h--) {
469 -       w = wd;
470 -       while(w--) *((unsigned short*)fb)++ = *((unsigned short*)buf)--;
471 -       fb += fblineadd;
472 -       buf -= buflineadd;
473 +      dst -= dstSub;
474 +    }
475 +#else  // BLIT_ROTATE_3_MOV32
476 +    Uint32 *src1 = (Uint32 *)(srcBits);
477 +    Uint32 *src2 = (Uint32 *)(srcBits + srcSize.width());
478 +    Uint32 *dst1 = (Uint32 *)(dstBits + (dstSize.width() - 2));
479 +    Uint32 *dst2 = (Uint32 *)(dstBits + (dstSize.width() + dstSize.width() - 2));
480 +    int w = srcBlitRect.width() >> 3;
481 +    int h = srcBlitRect.height() >> 1;
482 +    int i, dstSub = ((dstSize.width() * srcBlitRect.width()) >> 1) + 1;
483 +    int dstAdd = dstSize.width();
484 +
485 +    Uint32 a, b;
486 +    while (h--) {
487 +      i = w;
488 +      while (i--) {
489 +        a = *src1 ++;
490 +        b = *src2 ++;
491 +        *dst1 = (a << 16) | (b & 0xFFFF);
492 +        *dst2 = (a & 0xFFFF0000) | (b >> 16);
493 +        dst1 += dstAdd;
494 +        dst2 += dstAdd;
495 +
496 +        a = *src1 ++;
497 +        b = *src2 ++;
498 +        *dst1 = (a << 16) | (b & 0xFFFF);
499 +        *dst2 = (a & 0xFFFF0000) | (b >> 16);
500 +        dst1 += dstAdd;
501 +        dst2 += dstAdd;
502 +
503 +        a = *src1 ++;
504 +        b = *src2 ++;
505 +        *dst1 = (a << 16) | (b & 0xFFFF);
506 +        *dst2 = (a & 0xFFFF0000) | (b >> 16);
507 +        dst1 += dstAdd;
508 +        dst2 += dstAdd;
509 +
510 +        a = *src1 ++;
511 +        b = *src2 ++;
512 +        *dst1 = (a << 16) | (b & 0xFFFF);
513 +        *dst2 = (a & 0xFFFF0000) | (b >> 16);
514 +        dst1 += dstAdd;
515 +        dst2 += dstAdd;
516        }
517 +      src1 += srcSize.width() >> 1;
518 +      src2 += srcSize.width() >> 1;
519 +      dst1 -= dstSub;
520 +      dst2 -= dstSub;
521      }
522 +#endif // BLIT_ROTATE_3_MOV32
523    }
524 -  return true;
525  }
526  
527 -// ipaq 3800...
528 -bool SDL_QWin::repaintRotation1(const QRect& rect) {
529 -  if(my_image->width() == width()) {
530 -    ushort *fb = (ushort*)my_painter->frameBuffer();
531 -    ushort *buf = (ushort*)my_image->bits();
532 -    gs_fastRotateBlit_1(fb, buf, rect);
533 -  } else {
534 -    return false; // FIXME: landscape mode
535 -  }
536 -  return true;
537 -}
538 +#endif // __i386__
539  
540  void SDL_QWin::repaintRect(const QRect& rect) {
541    if(!my_painter || !rect.width() || !rect.height()) {
542      return;
543    }
544 -  
545 -  if(QPixmap::defaultDepth() == 16) {
546 -    switch(my_painter->transformOrientation()) {
547 -    case 3:
548 -      if(repaintRotation3(rect)) { return;  }
549 +#ifndef __i386__
550 +  if (QPixmap::defaultDepth() == 16 && my_painter->numRects() >= 0) {
551 +    Uint16 *fb = (Uint16*)my_painter->frameBuffer();
552 +    Uint16 *buf = (Uint16*)my_image->bits();
553 +    switch (rotation_) {
554 +    case 0:
555 +      blitRotate0(fb, fbSize_,
556 +                  buf, QSize(my_image->width(), my_image->height()),
557 +                  rect);
558        break;
559      case 1:
560 -      if(repaintRotation1(rect)) { return;  }
561 +      blitRotate1(fb, fbSize_,
562 +                  buf, QSize(my_image->width(), my_image->height()),
563 +                  rect);
564        break;
565 -    case 0:
566 -      if(repaintRotation0(rect)) { return;  }
567 +    case 2:
568 +      blitRotate2(fb, fbSize_,
569 +                  buf, QSize(my_image->width(), my_image->height()),
570 +                  rect);
571 +      break;
572 +    case 3:
573 +      blitRotate3(fb, fbSize_,
574 +                  buf, QSize(my_image->width(), my_image->height()),
575 +                  rect);
576        break;
577      }
578 -  } 
579 -  my_painter->drawImage(rect.topLeft(), *my_image, rect);
580 +  } else {
581 +#endif // __i386__
582 +    QDirectPainter pp(this);
583 +    pp.drawImage(rect.topLeft(), *my_image, rect);
584 +//     pp.end();
585 +#ifndef __i386__
586 +  }
587 +#endif // __i386__
588  }
589  
590  // This paints the current buffer to the screen, when desired. 
591  void SDL_QWin::paintEvent(QPaintEvent *ev) {  
592 -  if(my_image) {
593 +  if(my_image && isVisible() && isActiveWindow()) {
594 +    // TODO: better handling
595      lockScreen(true);
596      repaintRect(ev->rect());
597      unlockScreen();
598    }
599  }  
600  
601 +int SDL_QWin::ApplyKeyRotation(int key)
602 +{
603 +  int c;
604 +  int sdlScancode[] = { SDLK_LEFT, SDLK_DOWN, SDLK_RIGHT, SDLK_UP };
605 +
606 +  switch (key) {
607 +  case Qt::Key_Left:
608 +    c = 0;
609 +    break;
610 +  case Qt::Key_Down:
611 +    c = 1;
612 +    break;
613 +  case Qt::Key_Right:
614 +    c = 2;
615 +    break;
616 +  case Qt::Key_Up:
617 +    c = 3;
618 +    break;
619 +  default:
620 +    return 0;
621 +  }
622 +
623 +//   c = (c + qteKeyRotation_) & 3;
624 +//   return sdlScancode[(c - keyRotation_) & 3];
625 +  return sdlScancode[(c + qteKeyRotation_ - keyRotation_) & 3];
626 +}
627 +
628  /* Function to translate a keyboard transition and queue the key event
629   * This should probably be a table although this method isn't exactly
630   * slow.
631   */
632  void SDL_QWin::QueueKey(QKeyEvent *e, int pressed)
633 -{  
634 +{
635 +  if (e->isAutoRepeat())
636 +    return;
637 +
638    SDL_keysym keysym;
639    int scancode = e->key();
640 +
641    /* Set the keysym information */
642    if(scancode >= 'A' && scancode <= 'Z') {
643      // Qt sends uppercase, SDL wants lowercase
644 @@ -396,26 +516,12 @@
645      case Qt::Key_Home: scancode = SDLK_HOME; break;
646      case Qt::Key_End: scancode = SDLK_END; break;
647      // We want the control keys to rotate with the screen
648 -    case Qt::Key_Left: 
649 -        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP;
650 -        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_DOWN;
651 -        else scancode = SDLK_LEFT;
652 -        break;
653 -    case Qt::Key_Up: 
654 -        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_RIGHT;
655 -        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_LEFT;
656 -        else scancode = SDLK_UP;
657 -        break;
658 -    case Qt::Key_Right: 
659 -        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_DOWN;
660 -        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_UP;
661 -        else scancode = SDLK_RIGHT;
662 -        break;
663 +    case Qt::Key_Left:
664 +    case Qt::Key_Up:
665 +    case Qt::Key_Right:
666      case Qt::Key_Down:
667 -        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_LEFT;
668 -        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_RIGHT;
669 -        else scancode = SDLK_DOWN;
670 -        break;
671 +      scancode = ApplyKeyRotation(scancode);
672 +      break;
673      case Qt::Key_Prior: scancode = SDLK_PAGEUP; break;
674      case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break;
675      case Qt::Key_Shift: scancode = SDLK_LSHIFT; break;
676 @@ -434,9 +540,18 @@
677      case Qt::Key_F7: scancode = SDLK_F7; break;
678      case Qt::Key_F8: scancode = SDLK_F8; break;
679      case Qt::Key_F9: scancode = SDLK_F9; break;
680 -    case Qt::Key_F10: scancode = SDLK_F10; break;
681 -    case Qt::Key_F11: scancode = SDLK_F11; break;
682 -    case Qt::Key_F12: scancode = SDLK_F12; break;
683 +    case Qt::Key_F10: 
684 +      scancode = SDLK_F10;
685 +      mouse_button_mode=1;
686 +      break;
687 +    case Qt::Key_F11:
688 +      scancode = SDLK_F11;
689 +      mouse_button_mode=3;
690 +      break;
691 +    case Qt::Key_F12:
692 +      scancode = SDLK_F12;
693 +      mouse_button_mode=2;
694 +      break;
695      case Qt::Key_F13: scancode = SDLK_F13; break;
696      case Qt::Key_F14: scancode = SDLK_F14; break;
697      case Qt::Key_F15: scancode = SDLK_F15; break;
698 @@ -452,13 +567,14 @@
699        //     david@hedbor.org
700        scancode = SDLK_RETURN;
701        break;
702 +
703      default:
704        scancode = SDLK_UNKNOWN;
705        break;
706      }
707 -    keysym.sym = static_cast<SDLKey>(scancode);    
708 +    keysym.sym = static_cast<SDLKey>(scancode);
709    } else {
710 -    keysym.sym = static_cast<SDLKey>(scancode);    
711 +    keysym.sym = static_cast<SDLKey>(scancode);
712    }
713    keysym.scancode = scancode;
714    keysym.mod = KMOD_NONE;
715 @@ -478,11 +594,82 @@
716    //           pressed = 1;
717    //   }
718  
719 +  if (isSLA300InputFix_ &&
720 +      (keysym.sym == SDLK_SPACE || (keysym.sym >= 273 && keysym.sym <= 276))) {
721 +      if (keysym.sym >= 273) curAxis_[keysym.sym-273] = pressed;
722 +      else curAxis_[4] = pressed;
723 +  }
724 +
725    /* Queue the key event */
726    if ( pressed ) {
727 -    SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
728 +      /* fprintf(stderr, "press %d\n", keysym.sym); */
729 +      SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
730 +      if (isSLA300InputFix_ &&
731 +          (keysym.sym >= 273 && keysym.sym <= 276)) {
732 +          if (keysym.sym == SDLK_UP) {
733 +              if (curAxis_[1]) {
734 +                  keysym.sym = SDLK_DOWN;
735 +                  keysym.scancode = Qt::Key_Down;
736 +                  curAxis_[1] = 0;
737 +                  /* fprintf(stderr, "force release %d\n", keysym.sym); */
738 +                  SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
739 +              }
740 +          }
741 +          else if (keysym.sym == SDLK_DOWN) {
742 +              if (curAxis_[0]) {
743 +                  keysym.sym = SDLK_UP;
744 +                  keysym.scancode = Qt::Key_Up;
745 +                  curAxis_[0] = 0;
746 +                  /* fprintf(stderr, "force release %d\n", keysym.sym); */
747 +                  SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
748 +              }
749 +          }
750 +          else if (keysym.sym == SDLK_RIGHT) {
751 +              if (curAxis_[3]) {
752 +                  keysym.sym = SDLK_LEFT;
753 +                  keysym.scancode = Qt::Key_Left;
754 +                  curAxis_[3] = 0;
755 +                  /* fprintf(stderr, "force release %d\n", keysym.sym); */
756 +                  SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
757 +              }
758 +          }
759 +          else if (keysym.sym == SDLK_LEFT) {
760 +              if (curAxis_[2]) {
761 +                  keysym.sym = SDLK_RIGHT;
762 +                  keysym.scancode = Qt::Key_Right;
763 +                  curAxis_[2] = 0;
764 +                  /* fprintf(stderr, "force release %d\n", keysym.sym); */
765 +                  SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
766 +              }
767 +          }
768 +      }
769    } else {
770 -    SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
771 +      /* fprintf(stderr, "release %d\n", keysym.sym); */
772 +      SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
773 +
774 +      if (isSLA300InputFix_ &&
775 +          (keysym.sym == SDLK_SPACE ||
776 +           (keysym.sym >= 273 && keysym.sym <= 276))) {
777 +          for (int i = 0; i < 4; i++) {
778 +              if (curAxis_[i]) {
779 +                  int sym = i+273;
780 +                  keysym.sym = static_cast<SDLKey>(sym);
781 +                  if (sym == SDLK_UP) keysym.scancode = Qt::Key_Up;
782 +                  else if (sym == SDLK_RIGHT) keysym.scancode = Qt::Key_Right;
783 +                  else if (sym == SDLK_DOWN) keysym.scancode = Qt::Key_Down;
784 +                  else if (sym == SDLK_LEFT) keysym.scancode = Qt::Key_Left;
785 +                  curAxis_[i] = 0;
786 +                  /* fprintf(stderr, "force release %d\n", keysym.sym); */
787 +                  SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
788 +              }
789 +          }
790 +          if (curAxis_[4]) {
791 +              keysym.scancode = keysym.sym = SDLK_SPACE;
792 +              curAxis_[4] = 0;
793 +              /* fprintf(stderr, "force release %d\n", keysym.sym); */
794 +              SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
795 +          }
796 +      }
797    }
798  }
799  
800 @@ -524,7 +711,7 @@
801      my_locked--; // decrease lock refcount;
802    }
803    if(!my_locked && my_painter) {
804 -    my_painter->end();
805 +//     my_painter->end();
806      delete my_painter;
807      my_painter = 0;
808    }
809 Index: SDL-1.2.7/src/video/qtopia/SDL_QWin.h
810 ===================================================================
811 --- SDL-1.2.7.orig/src/video/qtopia/SDL_QWin.h  2005-03-02 22:24:43.457491622 +0100
812 +++ SDL-1.2.7/src/video/qtopia/SDL_QWin.h       2005-03-02 22:24:46.868009791 +0100
813 @@ -1,3 +1,4 @@
814 +
815  /*
816      SDL - Simple DirectMedia Layer
817      Copyright (C) 1997-2004 Sam Lantinga
818 @@ -52,6 +53,7 @@
819  class SDL_QWin : public QWidget
820  {
821    void QueueKey(QKeyEvent *e, int pressed);
822 +  int SDL_QWin::ApplyKeyRotation(int key);
823   public:
824    SDL_QWin(const QSize& size);
825    virtual ~SDL_QWin();
826 @@ -71,7 +73,7 @@
827      y = my_offset.y();
828    }
829    QImage *image(void) { return my_image; }
830 -  
831 +
832    void setWFlags(WFlags flags) {
833      QWidget::setWFlags(flags);
834      my_flags = flags;
835 @@ -83,6 +85,15 @@
836    bool lockScreen(bool force=false);
837    void unlockScreen();
838    void repaintRect(const QRect& rect);
839 +  void setScreenRotation(int sdlr, int qter) {
840 +         rotation_ = sdlr; qteRotation_ = qter;
841 +  }
842 +  void setKeyRotation(int sdlr, int qter) {
843 +    keyRotation_ = sdlr; qteKeyRotation_ = qter;
844 +  }
845 +  void setFBSize(QSize& s) { fbSize_ = s; }
846 +//   void setSLC700InputFix(bool isEnable) { isSLC700InputFix_ = isEnable; }
847 +  void setSLA300InputFix(bool isEnable) { isSLA300InputFix_ = isEnable; }
848   protected:
849    /* Handle resizing of the window */
850    virtual void resizeEvent(QResizeEvent *e);
851 @@ -95,10 +106,8 @@
852    void paintEvent(QPaintEvent *ev);
853    void keyPressEvent(QKeyEvent *e)   { QueueKey(e, 1); }
854    void keyReleaseEvent(QKeyEvent *e) { QueueKey(e, 0); }
855 +
856   private:
857 -  bool repaintRotation0(const QRect& rect);
858 -  bool repaintRotation1(const QRect& rect);
859 -  bool repaintRotation3(const QRect& rect);
860    void enableFullscreen();
861    QDirectPainter *my_painter;
862    QImage *my_image;
863 @@ -108,6 +117,12 @@
864    WFlags my_flags;
865    WFlags my_has_fullscreen;
866    unsigned int my_locked;
867 +  int rotation_, qteRotation_;
868 +  int keyRotation_, qteKeyRotation_;
869 +  QSize fbSize_;
870 +//   bool isSLC700InputFix_;
871 +  bool isSLA300InputFix_;
872 +  int curAxis_[5];   // 0: up, 1: down, 2: right, 3: left, 4: center
873  };
874  
875  #endif /* _SDL_QWin_h */
876 Index: SDL-1.2.7/src/video/qtopia/SDL_sysmouse.cc
877 ===================================================================
878 --- SDL-1.2.7.orig/src/video/qtopia/SDL_sysmouse.cc     2005-03-02 22:24:43.457491622 +0100
879 +++ SDL-1.2.7/src/video/qtopia/SDL_sysmouse.cc  2005-03-02 22:24:46.868009791 +0100
880 @@ -60,6 +60,7 @@
881  void QT_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
882  {
883    SDL_Win->setMousePos(QPoint(x, y));
884 +  SDL_PrivateMouseMotion( 0, 0, x, y );
885  }
886  
887  }; /* Extern C */
888 Index: SDL-1.2.7/src/video/qtopia/SDL_sysvideo.cc
889 ===================================================================
890 --- SDL-1.2.7.orig/src/video/qtopia/SDL_sysvideo.cc     2005-03-02 22:24:43.458491481 +0100
891 +++ SDL-1.2.7/src/video/qtopia/SDL_sysvideo.cc  2005-03-02 22:24:46.873009084 +0100
892 @@ -1,3 +1,4 @@
893 +
894  /*
895    SDL - Simple DirectMedia Layer
896      Copyright (C) 1997-2004 Sam Lantinga
897 @@ -29,17 +30,32 @@
898  
899  #include <stdlib.h>
900  #include <string.h>
901 +#include <stdarg.h>
902 +#include <fcntl.h>
903 +#include <sys/ioctl.h>
904  
905  #include <stdio.h>
906  #include <unistd.h>
907 +#include <sys/types.h>
908 +#include <sys/wait.h>
909 +#include <linux/fb.h>
910 +#include <sys/mman.h>
911 +#include <asm/page.h>  
912  
913  #include <qapplication.h>
914  #include <qpe/qpeapplication.h>
915 +#include <qpe/qcopenvelope_qws.h>
916 +#include <qgfx_qws.h>
917 +#include <qwindowsystem_qws.h>
918 +#include <qwidget.h>
919 +#include <qwidgetlist.h>
920 +#include <qdirectpainter_qws.h>
921  
922  #include "SDL.h"
923  #include "SDL_timer.h"
924  
925  #include "SDL_QWin.h"
926 +#include "SDL_sysvideo.h"
927  
928  extern "C" {
929  
930 @@ -51,14 +67,67 @@
931  #include "SDL_lowvideo.h"
932  
933    //#define QTOPIA_DEBUG
934 +#define QTOPIA_LOG
935  #define QT_HIDDEN_SIZE 32      /* starting hidden window size */
936  
937 +#ifdef QTOPIA_LOG
938 +  static FILE *st_logfp = NULL;
939 +#endif
940 +  static inline void LOG(char *fmt, ...)
941 +  {
942 +#ifdef QTOPIA_LOG
943 +    va_list ap;
944 +
945 +    va_start(ap, fmt);
946 +    vfprintf(st_logfp, fmt, ap);
947 +    if (st_logfp != stderr) {
948 +      fflush(st_logfp);
949 +      vfprintf(stderr, fmt, ap);
950 +    }
951 +    va_end(ap);
952 +#endif
953 +  }
954 +
955 +  typedef struct machine_spec {
956 +    const char *manif;
957 +    const char *name;
958 +    int qpe_server_rotation;
959 +    int init_screen_rot;
960 +    int init_key_rot;
961 +  } machine_spec_t;
962 +
963 +  typedef enum {
964 +    MACHINE_SHARP_SL5000D,
965 +    MACHINE_SHARP_SL5500,
966 +    MACHINE_SHARP_SLA300,
967 +    MACHINE_SHARP_SLB500,
968 +    MACHINE_SHARP_SLC700,
969 +    MACHINE_SHARP_SLC750,
970 +    MACHINE_SHARP_SLC760,
971 +    MACHINE_SHARP_SLC860,
972 +    MACHINE_SHARP_SL6000,
973 +    MACHINE_MAX
974 +  } machine_t;
975 +
976 +  static const machine_spec_t st_machine_spec[] = {
977 +    { "Sharp", "SL-5000D", 0 },
978 +    { "Sharp", "SL-5500", 0 },
979 +    { "Sharp", "SL-A300", 0 },
980 +    { "Sharp", "SL-B500", 0 },
981 +    { "Sharp", "SL-C700", 0 },
982 +    { "Sharp", "SL-C750", 0 },
983 +    { "Sharp", "SL-C760", 0 },
984 +    { "Sharp", "SL-C860", 0 },
985 +    { "Sharp", "SL-6000", 0 },
986 +  };
987 +
988    /* Name of the environment variable used to invert the screen rotation or not:
989       Possible values:
990 -     !=0 : Screen is 270° rotated
991 -     0: Screen is 90° rotated*/
992 -#define SDL_QT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION"
993 -  
994 +   !=0 : Screen is 270- rotated
995 +   0: Screen is 90- rotated*/
996 +#define SDL_QT_ROTATION_ENV_NAME "SDL_QT_ROTATION"
997 +#define SDL_QT_INVERT_ROTATION_ENV_NAME "SDL_QT_INVERT_ROTATION"
998 +
999    /* Initialization/Query functions */
1000    static int QT_VideoInit(_THIS, SDL_PixelFormat *vformat);
1001    static SDL_Rect **QT_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
1002 @@ -78,6 +147,20 @@
1003    static int QT_IconifyWindow(_THIS);
1004    static SDL_GrabMode QT_GrabInput(_THIS, SDL_GrabMode mode);
1005  
1006 +  static int console_fd;
1007 +  struct fb_var_screeninfo saved_vinfo;
1008 +  int fb_hwrot;
1009 +  int fb_direct;
1010 +  static int isKHloaded;
1011 +  bool is_VGA_machine;
1012
1013 +#define W100FB_CONFIG          0x57415200 /* WAL\00 */
1014 +#define W100INIT_ITEM          0
1015 +#define W100INIT_ALL           1
1016 +#define W100INIT_ITEM_WITH_VAL 2
1017 +#define W100FB_CONFIG_EX       0x57415202 /* WAL\02 */
1018 +
1019 +
1020    /* FB driver bootstrap functions */
1021  
1022    static int QT_Available(void)
1023 @@ -222,13 +305,34 @@
1024  
1025    int QT_VideoInit(_THIS, SDL_PixelFormat *vformat)
1026    {
1027 -    /* Initialize the QPE Application  */
1028 +    const char *SDL_fbdev;
1029 +    struct fb_var_screeninfo vinfo;
1030 +
1031 +     /* Initialize the QPE Application  */
1032       /* Determine the screen depth */
1033      vformat->BitsPerPixel = QPixmap::defaultDepth();
1034  
1035      // For now we hardcode the current depth because anything else
1036      // might as well be emulated by SDL rather than by Qtopia.
1037 -    
1038 +
1039 +    //frame buffer device open.
1040 +    SDL_fbdev = getenv("SDL_FBDEV");
1041 +    if ( SDL_fbdev == NULL ) {
1042 +       SDL_fbdev = "/dev/fb0";
1043 +    }
1044 +    console_fd = open(SDL_fbdev, O_RDWR, 0);
1045 +    if ( console_fd < 0 ) {
1046 +       SDL_SetError("Unable to open %s", SDL_fbdev);
1047 +       return(-1);
1048 +    }
1049 +
1050 +    if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
1051 +       SDL_SetError("Couldn't get console pixel format");
1052 +       QT_VideoQuit(_this);
1053 +       return(-1);
1054 +    }
1055 +    saved_vinfo = vinfo;
1056 +
1057      QSize desktop_size = qApp->desktop()->size();
1058      QT_AddMode(_this, ((vformat->BitsPerPixel+7)/8)-1,
1059                desktop_size.width(), desktop_size.height());
1060 @@ -241,7 +345,24 @@
1061      /* Fill in some window manager capabilities */
1062      _this->info.wm_available = 0;
1063  
1064 -    /* We're done! */
1065 +#ifdef QTOPIA_LOG
1066 +    st_logfp = fopen("/tmp/sdl-qt-debug", "w");
1067 +    if (!st_logfp)
1068 +      st_logfp = stderr;
1069 +#endif
1070 +
1071 +    QT_GrabInput(_this, SDL_GRAB_ON);
1072 +/*
1073 +    {
1074 +      QCopEnvelope e("QPE/KeyHelper", "repeater(int)");
1075 +      e << 2;
1076 +    }
1077 +*/
1078 +    isKHloaded=(fopen("/home/zaurus/Settings/keyhelper_SDL.xml","r") != NULL) ? 1 : 0;
1079 +    if (isKHloaded) {
1080 +       system("qcop QPE/KeyHelper \"reload(QString)\" keyhelper_SDL.xml"); //QcopEnvelope can't use.
1081 +       LOG("keyhelper_SDL.xml loaded\n");
1082 +    }
1083      return(0);
1084    }
1085  
1086 @@ -264,6 +385,7 @@
1087  
1088    /* Various screen update functions available */
1089    static void QT_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
1090 +  static void QT_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
1091  
1092  
1093    static int QT_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen)
1094 @@ -276,47 +398,428 @@
1095      return -1;
1096    }
1097  
1098 +  static machine_t QT_GetMachine(_THIS)
1099 +  {
1100 +    FILE *fp;
1101 +    machine_t machine = MACHINE_SHARP_SL5000D;
1102 +    char buf[1024];
1103 +
1104 +
1105 +    fp = fopen("/proc/cpuinfo", "rb");
1106 +    if (fp) {
1107 +      if (fread(buf, 1, sizeof(buf), fp) > 0) {
1108 +        LOG("QT_GetMachine: /proc/cpuinfo is %s\n", buf);
1109 +        if (strstr(buf, "SHARP Tosa") != NULL)  
1110 +          machine = MACHINE_SHARP_SL6000;
1111 +        else if (strstr(buf, "Collie") != NULL)
1112 +          machine = MACHINE_SHARP_SL5500;
1113 +        else if (strstr(buf, "SHARP Poodle") != NULL)
1114 +          machine = MACHINE_SHARP_SLB500;
1115 +        else if (strstr(buf, "SHARP Corgi") !=NULL)
1116 +          machine = MACHINE_SHARP_SLC700;
1117 +        else if (strstr(buf, "SHARP Shepherd") !=NULL)
1118 +          machine = MACHINE_SHARP_SLC750;
1119 +        else if (strstr(buf, "SHARP Husky") !=NULL)
1120 +          machine = MACHINE_SHARP_SLC760;
1121 +        else if (strstr(buf, "SHARP Boxer") != NULL)
1122 +          machine = MACHINE_SHARP_SLC860;
1123 +      }
1124 +      fclose(fp);
1125 +    } else {
1126 +      LOG("QT_GetMachine: Couldn't read /proc/deviceinfo/product.\n");
1127 +      LOG(" Now set machine variable to default (SL-5000D)\n");
1128 +    }
1129 +
1130 +    LOG(" detected machine is '%s %s'\n",
1131 +        st_machine_spec[machine].manif, st_machine_spec[machine].name);
1132 +    return machine;
1133 +  }
1134 +
1135 +  static void QT_GetQteServerSpec(_THIS, int *rotation, bool *isQvga)
1136 +  {
1137 +    const char *user;
1138 +    char buf[FILENAME_MAX];
1139 +    FILE *fp;
1140 +    int rot = 0, is_qvga = 0;
1141 +
1142 +    user = getenv("USER");
1143 +    snprintf(buf, sizeof(buf), "/tmp/qtembedded-%s/QtEmbedded-0.spec",
1144 +             user ? user : "root");
1145 +    LOG("QT_GetRotation: Read spec from '%s'\n", buf);
1146 +
1147 +    fp = fopen(buf, "rb");
1148 +    if (fp) {
1149 +      int size;
1150 +      if ((size = fread(buf, 1, sizeof(buf) - 1, fp)) > 0) {
1151 +        buf[size] = '\0';
1152 +        LOG(" spec is '%s'\n", buf);
1153 +        // get rotation value
1154 +        if (strstr(buf, "Rot")) {
1155 +          rot = atoi(strstr(buf, "Rot") + 3);
1156 +          rot /= 90;
1157 +          if (rot < 0 || rot > 3) {
1158 +            rot = 0;
1159 +          }
1160 +        } else
1161 +          rot = 0;
1162 +
1163 +        // get qvga mode in SL-C700
1164 +        if (strstr(buf, "Qvga"))
1165 +          is_qvga = 1;
1166 +      }
1167 +      fclose(fp);
1168 +    }
1169 +
1170 +    LOG(" Rot=%d, Qvga=%d\n", rot, is_qvga);
1171 +
1172 +    if (rotation)
1173 +      *rotation = rot;
1174 +    if (isQvga)
1175 +      *isQvga = is_qvga;
1176 +  }
1177 +
1178    /* FIXME: check return values and cleanup here */
1179    SDL_Surface *QT_SetVideoMode(_THIS, SDL_Surface *current,
1180                                int width, int height, int bpp, Uint32 flags)
1181    {
1182 -
1183      QImage *qimage;
1184 -    QSize desktop_size = qApp->desktop()->size();
1185 +    QSize qteSize = qApp->desktop()->size();
1186 +    QSize fbSize;
1187 +    QSize userSize;
1188 +    int fb_xres;
1189 +    int fb_yres;
1190 +    struct fb_var_screeninfo vinfo;
1191 +    struct fb_fix_screeninfo finfo;
1192 +    int tmp_ioctl_data;
1193 +    char fb_size_fix = ' ';
1194 +    bool isW100patch_kernel = false;
1195 +    int numFb_Size;
1196 +
1197 +    int mapped_memlen;
1198 +    int mapped_offset;
1199 +    void *mapped_mem;
1200 +    int fb_offset;
1201 +
1202 +
1203 +    machine_t machine = QT_GetMachine(_this);
1204 +    machine_spec_t machineSpec = st_machine_spec[machine];
1205 +    int qteRotation, userRotation, sdlRotation;
1206 +    int qteKeyRotation, sdlKeyRotation;
1207 +    bool isQteQvga;
1208 +
1209 +    if (machine == MACHINE_SHARP_SLC700 ||
1210 +        machine == MACHINE_SHARP_SLC750 ||
1211 +        machine == MACHINE_SHARP_SLC760 ||
1212 +        machine == MACHINE_SHARP_SLC860 ||      // ¾Ü¤·¤¤¤³¤È¤ï¤«¤é¤ó¤±¤É¤È¤ê¤¢¤¨¤º
1213 +        machine == MACHINE_SHARP_SL6000 ) {     // ¾Ü¤·¤¤¤³¤È¤ï¤«¤é¤ó¤±¤É¤È¤ê¤¢¤¨¤º
1214 +       is_VGA_machine = true;
1215 +    }else {
1216 +       is_VGA_machine = false;
1217 +    }
1218 +
1219 +    // qte ¤Ç¤Î²óž³ÑÅÙ¤ò¼èÆÀ
1220 +    QT_GetQteServerSpec(_this, &qteRotation, &isQteQvga);
1221 +
1222 +    // SL-C700 ¤Î¥¹¥¿¥¤¥ë
1223 +    bool isInputStyle = false;
1224 +    if (is_VGA_machine) {
1225 +      int status = system("/home/QtPalmtop/bin/chkhinge");
1226 +      if (WEXITSTATUS(status) != 2)
1227 +        isInputStyle = true;
1228 +      LOG("QT_SetVideoMode: SL-C700 Style is %s\n",
1229 +          isInputStyle ? "Input style" : "View style");
1230 +    }
1231  
1232      
1233 -    current->flags = 0; //SDL_FULLSCREEN; // We always run fullscreen.
1234 +    // specity screen setting
1235 +    if (is_VGA_machine) {
1236 +
1237 +       // w100 rotation pached kernel check
1238 +      isW100patch_kernel = (fopen("/proc/driver/w100/rotation","r") != NULL) ? true : false;
1239 +      LOG("Your Kernel is %s\n",isW100patch_kernel ? "Special Kernel" : "Normal Kernel");
1240 +
1241 +      const char *envFb_Size = getenv("SDL_FB_SIZE");
1242 +      if (envFb_Size !=NULL) {
1243 +       numFb_Size=sscanf(envFb_Size,"%dx%d%c",&fb_xres,&fb_yres,&fb_size_fix);
1244 +      } else {
1245 +       numFb_Size=0;
1246 +      }
1247  
1248 -    if(width <= desktop_size.width()
1249 -             && height <= desktop_size.height()) {
1250 -      current->w = desktop_size.width();
1251 -      current->h = desktop_size.height();
1252 -    } else if(width <= desktop_size.height() && height <= desktop_size.width()) {
1253 -      // Landscape mode
1254 -      char * envString = getenv(SDL_QT_ROTATION_ENV_NAME);
1255 -      int envValue = envString ? atoi(envString) : 0;
1256 -      screenRotation = envValue ? SDL_QT_ROTATION_270 : SDL_QT_ROTATION_90;
1257 -      current->h = desktop_size.width();
1258 -      current->w = desktop_size.height();
1259 +      if (numFb_Size >=2) {
1260 +
1261 +       // specity screen mode
1262 +       if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
1263 +               SDL_SetError("Couldn't get console pixel format");
1264 +               QT_VideoQuit(_this);
1265 +               return(NULL);
1266 +       }
1267 +
1268 +       vinfo.xres = fb_xres;
1269 +       vinfo.xres_virtual = fb_xres;
1270 +       vinfo.yres = fb_yres;
1271 +       vinfo.yres_virtual = fb_yres;
1272 +
1273 +       if (fb_size_fix == '@') {
1274 +               width = fb_xres;
1275 +               height = fb_yres;
1276 +       }
1277 +
1278 +       if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) {
1279 +               SDL_SetError("Couldn't set console screen info");
1280 +               return(NULL);
1281 +       }
1282 +
1283 +
1284 +       if (isW100patch_kernel) {
1285 +               qteSize.setWidth(vinfo.xres);
1286 +               qteSize.setHeight(vinfo.yres);
1287 +               qteRotation=0;
1288 +       }else if(vinfo.xres == 320){
1289 +               qteSize.setWidth(vinfo.xres);
1290 +               qteSize.setHeight(vinfo.yres);
1291 +               qteRotation=2;
1292 +       }else {
1293 +               qteSize.setWidth(vinfo.yres);
1294 +               qteSize.setHeight(vinfo.xres);
1295 +               qteRotation=3;
1296 +       }                       
1297 +
1298 +       if (isW100patch_kernel && (vinfo.xres == 320) && (vinfo.yres == 240)) {
1299 +               tmp_ioctl_data=121;
1300 +               ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data);
1301 +               fb_hwrot=1;     
1302 +       }
1303 +
1304 +       LOG("FBVideoMode: %dx%d%c\n", vinfo.xres, vinfo.yres,fb_size_fix );
1305 +
1306 +      }else {
1307 +
1308 +       // auto screen mode     
1309 +       if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
1310 +               SDL_SetError("Couldn't get console pixel format");
1311 +               QT_VideoQuit(_this);
1312 +               return(NULL);
1313 +       }
1314 +
1315 +       if (isW100patch_kernel && (isInputStyle == false) && (vinfo.xres == 240) && (vinfo.yres == 320)) {
1316 +               vinfo.xres = 240;
1317 +               vinfo.xres_virtual = 240;
1318 +               vinfo.yres = 320;
1319 +               vinfo.yres_virtual = 320;
1320 +               qteRotation=0;
1321 +       }else if ((width <= 320) && (height <= 240)) {
1322 +               vinfo.xres = 320;
1323 +               vinfo.xres_virtual = 320;
1324 +               vinfo.yres = 240;
1325 +               vinfo.yres_virtual = 240;
1326 +       }else if (isW100patch_kernel && (isInputStyle == true)){
1327 +               vinfo.xres = 640;
1328 +               vinfo.xres_virtual = 640;
1329 +               vinfo.yres = 480;
1330 +               vinfo.yres_virtual = 480;
1331 +               qteRotation=0;
1332 +       }else {
1333 +               vinfo.xres = 480;
1334 +               vinfo.xres_virtual = 480;
1335 +               vinfo.yres = 640;
1336 +               vinfo.yres_virtual = 640;
1337 +       }
1338 +
1339 +               if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) {
1340 +               SDL_SetError("Couldn't set console screen info");
1341 +               return(NULL);
1342 +       }
1343 +
1344 +       if (isW100patch_kernel) {
1345 +               qteSize.setWidth(vinfo.xres);
1346 +               qteSize.setHeight(vinfo.yres);
1347 +               qteRotation=0;
1348 +               fb_direct=1;
1349 +       }else if(vinfo.xres == 320){
1350 +               qteSize.setWidth(vinfo.xres);
1351 +               qteSize.setHeight(vinfo.yres);
1352 +               qteRotation=2;
1353 +       }else {
1354 +               qteSize.setWidth(vinfo.yres);
1355 +               qteSize.setHeight(vinfo.xres);
1356 +               qteRotation=3;
1357 +       }                       
1358 +
1359 +       if (isW100patch_kernel && (vinfo.xres == 320) && (vinfo.yres == 240)) {
1360 +               tmp_ioctl_data=121;
1361 +               ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data);   
1362 +               fb_hwrot=1;
1363 +               qteRotation=0;
1364 +       }
1365 +
1366 +       LOG("FBVideoMode: %dx%d%c\n", vinfo.xres, vinfo.yres,fb_size_fix );
1367 +      }
1368 +    }
1369 +
1370 +    // direct paint setting
1371 +    const char *envFb_Direct = getenv("SDL_FB_DIRECT");
1372 +    if (envFb_Direct !=NULL)
1373 +       fb_direct = envFb_Direct ? atoi(envFb_Direct) : -1;
1374 +
1375 +    if (fb_direct == 1){
1376 +       if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
1377 +               SDL_SetError("Couldn't get console hardware info");
1378 +               QT_VideoQuit(_this);
1379 +               return(NULL);
1380 +       }
1381 +        if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
1382 +               SDL_SetError("Couldn't get console pixel format");
1383 +               QT_VideoQuit(_this);
1384 +                return(NULL);
1385 +        }
1386 +       LOG("Direct paint mode\n");
1387 +    }
1388 +
1389 +    // hack for SL-5500
1390 +    if (machine == MACHINE_SHARP_SL5500)
1391 +      qteRotation = 3;
1392 +
1393 +    // SL-B500 Íѥϥå¯(¤È¤ê¤¢¤¨¤º¡¢¤Í)
1394 +    if (machine == MACHINE_SHARP_SLB500)
1395 +      qteRotation = 3;
1396 +
1397 +    // À¸¥Õ¥ì¡¼¥à¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤òÆÀ¤ë
1398 +    if (qteRotation & 1) {
1399 +      fbSize.setWidth(qteSize.height());
1400 +      fbSize.setHeight(qteSize.width());
1401 +    } else {
1402 +      fbSize = qteSize;
1403 +    }
1404 +
1405 +    //
1406 +    const char *envRotStr = getenv(SDL_QT_ROTATION_ENV_NAME);
1407 +    userRotation = envRotStr ? atoi(envRotStr) : -1;
1408 +    if ((userRotation >= 0 ? userRotation : qteRotation) & 1) {
1409 +      userSize.setWidth(fbSize.height());
1410 +      userSize.setHeight(fbSize.width());
1411 +    } else {
1412 +      userSize = fbSize;
1413 +    }
1414 +
1415 +    if (width <= userSize.width() && height <= userSize.height()) {
1416 +      // ´Ä¶­ÊÑ¿ô¤Ç²óž³ÑÅÙ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ì¤Ð¡¢¤½¤ì¤òºÇÍ¥À褹¤ë
1417 +      if (userRotation >= 0)
1418 +        sdlRotation = userRotation;
1419 +      else {
1420 +        // ¤Ç¡¢¤½¤Î»ØÄ̵꤬¤¤¤Î¤Ç¤¢¤ì¤Ð qte ¤Î²óž³ÑÅ٤˹ç¤ï¤»¤ë¤À¤±
1421 +        // ¤Ê¤ó¤À¤±¤É¡¢SL-C700 ¤Ç¤Ï¤Á¤ç¤¤Ê£»¨¡£
1422 +        if (is_VGA_machine && (fbSize.width() == 320) && (fbSize.height() == 240)) {
1423 +          if (isInputStyle)
1424 +            sdlRotation = 2;
1425 +          else
1426 +            sdlRotation = qteRotation;
1427 +        } else {
1428 +          sdlRotation = qteRotation;
1429 +        }
1430 +      }
1431 +    } else if (width <= fbSize.width() && height <= fbSize.height()) {
1432 +      sdlRotation = 0;
1433 +      if (is_VGA_machine && (fbSize.width() == 320) && (fbSize.height() == 240) && isInputStyle)
1434 +        sdlRotation = 2;
1435 +    } else if (width <= fbSize.height() && height <= fbSize.width()) {
1436 +      sdlRotation = 1;
1437      } else {
1438        SDL_SetError("Unsupported resolution, %dx%d\n", width, height);
1439 +      return NULL;
1440      }
1441 +
1442 +    if (fb_hwrot == 1) 
1443 +       sdlRotation = 0;
1444 +
1445 +    if (getenv(SDL_QT_INVERT_ROTATION_ENV_NAME) != NULL) {
1446 +      sdlRotation = (sdlRotation + 2) & 3;
1447 +    }
1448 +
1449 +    LOG("QT_SetVideoMode: argSize=%dx%d\n", width, height);
1450 +    LOG("QT_SetVideoMode: qteSize=%dx%d\n",
1451 +        qteSize.width(), qteSize.height());
1452 +    LOG("QT_SetVideoMode: fbSize=%dx%d\n",
1453 +        fbSize.width(), fbSize.height());
1454 +    LOG("QT_SetVideoMode: qteRotation=%d\n", qteRotation);
1455 +    LOG("QT_SetVideoMode: userRotation=%d\n", userRotation);
1456 +    LOG("QT_SetVideoMode: sdlRotation=%d\n", sdlRotation);
1457 +
1458 +    current->flags = 0;//SDL_FULLSCREEN; // We always run fullscreen.
1459 +    current->w = width;
1460 +    current->h = height;
1461 +    SDL_Win->setScreenRotation(sdlRotation, qteRotation);
1462 +    SDL_Win->setFBSize(fbSize);
1463 +
1464 +    if (machine == MACHINE_SHARP_SLA300)
1465 +      SDL_Win->setSLA300InputFix(true);
1466 +
1467 +    // keyboard rotation
1468 +    qteKeyRotation = qteRotation;
1469 +//     fprintf(stderr, "%d\n", (machine == MACHINE_SHARP_SLC700));
1470 +//     fprintf(stderr, "%d\n", isQteQvga);
1471 +    if (isQteQvga && is_VGA_machine)
1472 +      qteKeyRotation = 3;
1473 +    else if (machine == MACHINE_SHARP_SLB500)
1474 +      qteKeyRotation = 3;
1475 +
1476 +    if (isQteQvga && fb_hwrot == 1) 
1477 +       qteKeyRotation = 1;
1478 +
1479 +    sdlKeyRotation = sdlRotation;
1480 +
1481 +    SDL_Win->setKeyRotation(sdlKeyRotation, qteKeyRotation);
1482 +
1483 +    LOG("QT_SetVideoMode: qteKeyRotation=%d\n", qteKeyRotation);
1484 +    LOG("QT_SetVideoMode: sdlKeyRotation=%d\n", sdlKeyRotation);
1485 +
1486      if ( flags & SDL_OPENGL ) {
1487        SDL_SetError("OpenGL not supported");
1488        return(NULL);
1489 -    } 
1490 +    }
1491      /* Create the QImage framebuffer */
1492 -    qimage = new QImage(current->w, current->h, bpp);
1493 -    if (qimage->isNull()) {
1494 -      SDL_SetError("Couldn't create screen bitmap");
1495 -      delete qimage;
1496 -      return(NULL);
1497 +
1498 +    // frame buffer memory mapping    
1499 +    if (fb_direct == 1) {
1500 +       current->pitch = finfo.line_length;
1501 +        current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
1502 +        mapped_offset = (((long)finfo.smem_start) -
1503 +                       (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
1504 +       mapped_memlen = finfo.smem_len+mapped_offset;
1505 +        if(console_fd >0 ) {
1506 +               mapped_mem = mmap(NULL, mapped_memlen,PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
1507 +               fb_offset=(vinfo.xres-width)+(vinfo.yres-height)*vinfo.xres;
1508 +               current->pixels = (void *)((int )mapped_mem+fb_offset);
1509 +                _this->UpdateRects = QT_DirectUpdate;
1510 +       } else {
1511 +               qimage = new QImage(current->w, current->h, bpp);
1512 +               if (qimage->isNull()) {
1513 +                       SDL_SetError("Couldn't create screen bitmap");
1514 +                       delete qimage;
1515 +                       return(NULL);
1516 +               }
1517 +               current->pixels = (void *)qimage->bits();
1518 +                _this->UpdateRects = QT_NormalUpdate;
1519 +               SDL_Win->setImage(qimage);
1520 +//             SDL_Win->setFullscreen(true);  //comment to non update taskbar
1521 +       }
1522 +    } else {
1523 +       qimage = new QImage(current->w, current->h, bpp);
1524 +       if (qimage->isNull()) {
1525 +               SDL_SetError("Couldn't create screen bitmap");
1526 +               delete qimage;
1527 +               return(NULL);
1528 +       }
1529 +       current->pitch = qimage->bytesPerLine();
1530 +       current->pixels = (void *)qimage->bits();
1531 +        _this->UpdateRects = QT_NormalUpdate;
1532 +       SDL_Win->setImage(qimage);
1533 +//     SDL_Win->setFullscreen(true);  //comment to non update taskbar
1534 +
1535      }
1536 -    current->pitch = qimage->bytesPerLine();
1537 -    current->pixels = (void *)qimage->bits();
1538 -    SDL_Win->setImage(qimage);
1539 -    _this->UpdateRects = QT_NormalUpdate;
1540 -    SDL_Win->setFullscreen(true);
1541 +
1542 +
1543 +    //     fprintf(stderr,"QT_SetVideoMode() qImage:%dx%d %d\n",
1544 +    //                         qimage->width(), qimage->height(), qimage->bytesPerLine());
1545      /* We're done */
1546      return(current);
1547    }
1548 @@ -361,13 +864,19 @@
1549    {
1550      if(SDL_Win->lockScreen()) {
1551        for(int i=0; i<numrects; ++i ) {
1552 -       QRect rect(rects[i].x, rects[i].y,
1553 -                  rects[i].w, rects[i].h);
1554 -       SDL_Win->repaintRect(rect);
1555 +           QRect rect(rects[i].x, rects[i].y,
1556 +                  rects[i].w, rects[i].h);
1557 +       SDL_Win->repaintRect(rect);
1558        }
1559        SDL_Win->unlockScreen();
1560      }
1561    }
1562 +
1563 +  static void QT_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
1564 +  {
1565 +
1566 +  }
1567 +
1568    /* Is the system palette settable? */
1569    int QT_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
1570    {
1571 @@ -383,10 +892,36 @@
1572      //    -- David Hedbor
1573      //    delete SDL_Win; 
1574      //    SDL_Win = 0;
1575 +
1576 +    if ( console_fd > 0 ) {
1577 +       /* Restore the original video mode and palette */
1578 +       if (fb_hwrot == 1) {
1579 +               int tmp_ioctl_data=120;
1580 +               ioctl(console_fd, W100FB_CONFIG_EX, &tmp_ioctl_data);   
1581 +       }
1582 +
1583 +       ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo);
1584 +
1585 +       /* We're all done with the framebuffer */
1586 +       close(console_fd);
1587 +       console_fd = -1;
1588 +    }
1589 +
1590      _this->screen->pixels = NULL;
1591      QT_GrabInput(_this, SDL_GRAB_OFF);
1592 +/*
1593 +    {
1594 +      QCopEnvelope e("QPE/KeyHelper", "repeater(int)");
1595 +      e << 1;
1596 +    }
1597 +*/
1598 +    if (isKHloaded)
1599 +       system("qcop QPE/KeyHelper \"reload()\""); //QcopEnvelope can't use. 
1600 +
1601    }
1602  
1603 +
1604 +
1605    static int QT_IconifyWindow(_THIS) {
1606      SDL_Win->hide();
1607      
1608 Index: SDL-1.2.7/src/video/fbcon/SDL_fbvideo.c
1609 ===================================================================
1610 --- SDL-1.2.7.orig/src/video/fbcon/SDL_fbvideo.c        2005-03-02 22:24:43.458491481 +0100
1611 +++ SDL-1.2.7/src/video/fbcon/SDL_fbvideo.c     2005-03-02 22:24:46.875008802 +0100
1612 @@ -51,7 +51,7 @@
1613  #include "SDL_fbmatrox.h"
1614  #include "SDL_fbriva.h"
1615  
1616 -
1617 +/* #define FBCON_DEBUG 1 */
1618  #if defined(i386) && defined(FB_TYPE_VGA_PLANES)
1619  #define VGA16_FBCON_SUPPORT
1620  #ifndef FB_AUX_VGA_PLANES_VGA4
1621 @@ -76,9 +76,11 @@
1622         {  0, 0,  720,  576 },          /* PAL */
1623         {  0, 0,  720,  480 },          /* NTSC */
1624         {  0, 0,  640,  480 },          /* 16 bpp: 0x111, or 273 */
1625 +       {  0, 0,  480,  640 },
1626         {  0, 0,  640,  400 },          /*  8 bpp: 0x100, or 256 */
1627         {  0, 0,  512,  384 },
1628         {  0, 0,  320,  240 },
1629 +       {  0, 0,  240,  320 },
1630         {  0, 0,  320,  200 }
1631  };
1632  static const struct {
1633 @@ -112,9 +114,11 @@
1634         */
1635         {  320,  200, 79440,  16, 16, 20,  4,  48, 1, 0, 2 },   /* 70 Hz */
1636         {  320,  240, 63492,  16, 16, 16,  4,  48, 2, 0, 2 },   /* 72 Hz */
1637 +        {  240,  320, 63492,  16, 16, 16,  4,  48, 3, 0, 2 },   /* 72 Hz */
1638         {  512,  384, 49603,  48, 16, 16,  1,  64, 3, 0, 0 },   /* 78 Hz */
1639         {  640,  400, 31746,  96, 32, 41,  1,  64, 3, 2, 0 },   /* 85 Hz */
1640         {  640,  480, 31746, 120, 16, 16,  1,  64, 3, 0, 0 },   /* 75 Hz */
1641 +        {  480,  640, 31746, 120, 16, 16,  1,  64, 4, 0, 0 },   /* 75 Hz */
1642         {  768,  576, 26101, 144, 16, 28,  6, 112, 4, 0, 0 },   /* 60 Hz */
1643         {  800,  600, 20000,  64, 56, 23, 37, 120, 6, 3, 0 },   /* 72 Hz */
1644         {  960,  720, 17686, 144, 24, 28,  8, 112, 4, 0, 0 },   /* 60 Hz */
1645 @@ -152,6 +156,10 @@
1646                                    struct fb_var_screeninfo *vinfo);
1647  static void FB_RestorePalette(_THIS);
1648  
1649 +static char *console_fd_buf;
1650 +static char *mapped_mem_fb;
1651 +static int rotation_flag;
1652 +
1653  /* FB driver bootstrap functions */
1654  
1655  static int FB_Available(void)
1656 @@ -241,18 +249,30 @@
1657  
1658         mode_okay = 0;
1659         vinfo->bits_per_pixel = (index+1)*8;
1660 -       vinfo->xres = *w;
1661 -       vinfo->xres_virtual = *w;
1662 -       vinfo->yres = *h;
1663 -       vinfo->yres_virtual = *h;
1664 +       if ((rotation_flag == 0) || (rotation_flag == 2)) {
1665 +               vinfo->xres = *w;
1666 +               vinfo->xres_virtual = *w;
1667 +               vinfo->yres = *h;
1668 +               vinfo->yres_virtual = *h;
1669 +       } else {
1670 +               vinfo->xres = *h;
1671 +               vinfo->xres_virtual = *h;
1672 +               vinfo->yres = *w;
1673 +               vinfo->yres_virtual = *w;
1674 +       }
1675         vinfo->activate = FB_ACTIVATE_TEST;
1676         if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, vinfo) == 0 ) {
1677  #ifdef FBCON_DEBUG
1678                 fprintf(stderr, "Checked mode %dx%d at %d bpp, got mode %dx%d at %d bpp\n", *w, *h, (index+1)*8, vinfo->xres, vinfo->yres, vinfo->bits_per_pixel);
1679  #endif
1680                 if ( (((vinfo->bits_per_pixel+7)/8)-1) == index ) {
1681 -                       *w = vinfo->xres;
1682 -                       *h = vinfo->yres;
1683 +                       if ((rotation_flag == 0) || (rotation_flag == 2)) {
1684 +                               *w = vinfo->xres;
1685 +                               *h = vinfo->yres;
1686 +                       } else {
1687 +                               *h = vinfo->xres;
1688 +                               *w = vinfo->yres;
1689 +                       }
1690                         mode_okay = 1;
1691                 }
1692         }
1693 @@ -332,6 +352,7 @@
1694         unsigned int current_w;
1695         unsigned int current_h;
1696         const char *SDL_fbdev;
1697 +       const char *SDL_rot_flag;
1698  
1699         /* Initialize the library */
1700         SDL_fbdev = getenv("SDL_FBDEV");
1701 @@ -344,6 +365,14 @@
1702                 return(-1);
1703         }
1704  
1705 +       SDL_rot_flag = getenv("SDL_FBROT");
1706 +       if ( SDL_rot_flag == NULL ) {
1707 +               rotation_flag = 0;
1708 +       } else {
1709 +               rotation_flag = atoi(SDL_rot_flag);
1710 +       }
1711 +
1712 +
1713  #ifndef DISABLE_THREADS
1714         /* Create the hardware surface lock mutex */
1715         hw_lock = SDL_CreateMutex();
1716 @@ -407,13 +436,33 @@
1717         mapped_offset = (((long)finfo.smem_start) -
1718                         (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
1719         mapped_memlen = finfo.smem_len+mapped_offset;
1720 -       mapped_mem = mmap(NULL, mapped_memlen,
1721 -                         PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
1722 -       if ( mapped_mem == (char *)-1 ) {
1723 -               SDL_SetError("Unable to memory map the video hardware");
1724 -               mapped_mem = NULL;
1725 -               FB_VideoQuit(this);
1726 -               return(-1);
1727 +       if (rotation_flag == 0) { 
1728 +               mapped_mem = mmap(NULL, mapped_memlen,
1729 +                                 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
1730 +               if ( mapped_mem == (char *)-1 ) {
1731 +                       SDL_SetError("Unable to memory map the video hardware");
1732 +                       mapped_mem = NULL;
1733 +                       FB_VideoQuit(this);
1734 +                       return(-1);
1735 +               }
1736 +       } else {
1737
1738 +               console_fd_buf = (char *)malloc(640*480*2);
1739 +
1740 +               if (console_fd_buf == NULL){
1741 +                       SDL_SetError("Unable to memory for buffer");
1742 +                       return(-1);
1743 +               }
1744 +       
1745 +               mapped_mem_fb = mmap(NULL, mapped_memlen,
1746 +                                 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
1747 +               if ( mapped_mem_fb == (char *)-1 ) {
1748 +                       SDL_SetError("Unable to memory map the video hardware");
1749 +                       mapped_mem_fb = NULL;
1750 +                       FB_VideoQuit(this);
1751 +                       return(-1);
1752 +               }
1753 +               mapped_mem = console_fd_buf;
1754         }
1755  
1756         /* Determine the current screen depth */
1757 @@ -555,6 +604,7 @@
1758  
1759  /* Various screen update functions available */
1760  static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
1761 +static void FB_RotationUpdate(_THIS, int numrects, SDL_Rect *rects);
1762  #ifdef VGA16_FBCON_SUPPORT
1763  static void FB_VGA16Update(_THIS, int numrects, SDL_Rect *rects);
1764  #endif
1765 @@ -725,7 +775,7 @@
1766         Uint32 Bmask;
1767         char *surfaces_mem;
1768         int surfaces_len;
1769 -
1770 +       
1771         /* Set the terminal into graphics mode */
1772         if ( FB_EnterGraphicsMode(this) < 0 ) {
1773                 return(NULL);
1774 @@ -734,6 +784,8 @@
1775         /* Restore the original palette */
1776         FB_RestorePalette(this);
1777  
1778 +       flags &= ~SDL_DOUBLEBUF;
1779 +
1780         /* Set the video mode and get the final screen format */
1781         if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) {
1782                 SDL_SetError("Couldn't get console screen info");
1783 @@ -748,13 +800,24 @@
1784                 vinfo.activate = FB_ACTIVATE_NOW;
1785                 vinfo.accel_flags = 0;
1786                 vinfo.bits_per_pixel = bpp;
1787 -               vinfo.xres = width;
1788 -               vinfo.xres_virtual = width;
1789 -               vinfo.yres = height;
1790 -               if ( flags & SDL_DOUBLEBUF ) {
1791 -                       vinfo.yres_virtual = height*2;
1792 +               if ((rotation_flag == 0) || (rotation_flag == 2)) {
1793 +                       vinfo.xres = width;
1794 +                       vinfo.xres_virtual = width;
1795 +                       vinfo.yres = height;
1796 +                       if ( flags & SDL_DOUBLEBUF ) {
1797 +                               vinfo.yres_virtual = height*2;
1798 +                       } else {
1799 +                               vinfo.yres_virtual = height;
1800 +                       }
1801                 } else {
1802 -                       vinfo.yres_virtual = height;
1803 +                       vinfo.xres = height;
1804 +                       vinfo.xres_virtual = height;
1805 +                       vinfo.yres = width;
1806 +                       if ( flags & SDL_DOUBLEBUF ) {
1807 +                               vinfo.yres_virtual = width*2;
1808 +                       } else {
1809 +                               vinfo.yres_virtual = width;
1810 +                       }
1811                 }
1812                 vinfo.xoffset = 0;
1813                 vinfo.yoffset = 0;
1814 @@ -776,6 +839,15 @@
1815                                 return(NULL);
1816                         }
1817                 }
1818 +               vinfo.xres = width;
1819 +               vinfo.xres_virtual = width;
1820 +               vinfo.yres = height;
1821 +               if ( flags & SDL_DOUBLEBUF ) {
1822 +                       vinfo.yres_virtual = height*2;
1823 +               } else {
1824 +                       vinfo.yres_virtual = height;
1825 +               }
1826 +
1827         } else {
1828                 int maxheight;
1829  
1830 @@ -821,7 +893,9 @@
1831                 SDL_SetError("Couldn't get console hardware info");
1832                 return(NULL);
1833         }
1834 -
1835 +#ifdef FBCON_DEBUG
1836 +       print_finfo(&finfo);
1837 +#endif
1838         /* Save hardware palette, if needed */
1839         FB_SavePalette(this, &finfo, &vinfo);
1840  
1841 @@ -829,7 +903,11 @@
1842         current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
1843         current->w = vinfo.xres;
1844         current->h = vinfo.yres;
1845 -       current->pitch = finfo.line_length;
1846 +       if ((rotation_flag == 0) || (rotation_flag == 2) ) {
1847 +               current->pitch = finfo.line_length;
1848 +       } else { 
1849 +       current->pitch = vinfo.xres*2;
1850 +       }
1851         current->pixels = mapped_mem+mapped_offset;
1852  
1853         /* Set up the information for hardware surfaces */
1854 @@ -863,7 +941,7 @@
1855         }
1856  
1857         /* Set the update rectangle function */
1858 -       this->UpdateRects = FB_DirectUpdate;
1859 +       this->UpdateRects = FB_RotationUpdate;
1860  
1861         /* We're done */
1862         return(current);
1863 @@ -1123,6 +1201,89 @@
1864         return;
1865  }
1866  
1867 +static void FB_RotationUpdate(_THIS, int numrects, SDL_Rect *rects)
1868 +{
1869 +       unsigned short *pDst;
1870 +       unsigned short *pSrc;
1871 +       unsigned int width;
1872 +       unsigned int height;
1873 +       unsigned int srcYAdd;
1874 +       unsigned int dstXAdd;
1875 +       unsigned int dstYSub;
1876 +       unsigned int i;
1877 +       unsigned int dstH;
1878 +       unsigned int dstW;
1879 +       
1880 +#ifdef FBCON_DEBUG
1881 +               fprintf(stderr,"rotation_flag = %d \n",rotation_flag);
1882 +#endif
1883 +       switch (rotation_flag) {
1884 +       case 0:
1885 +               break;
1886 +       case 1:
1887 +               memcpy(mapped_mem_fb,mapped_mem,640*480*2);
1888 +               break;
1889 +       case 2:
1890 +               memcpy(mapped_mem_fb,mapped_mem,640*480*2);
1891 +               break;
1892 +       case 3:
1893 +               dstW=cache_vinfo.xres;
1894 +               dstH=cache_vinfo.yres;
1895 +#ifdef FBCON_DEBUG
1896 +               fprintf(stderr,"dstH = %d : dstW = %d : rects->x = %d : rects->y = %d\n",dstH,dstW);
1897 +               fprintf(stderr,"rects->x = %d : rects->y = %d : rects->w = %d : rects->h = %d\n",rects->x,rects->y,rects->w,rects->h);
1898 +#endif
1899 +               while (numrects) {
1900 +                       if (rects->w != dstW || rects->h != dstH) {
1901 +                               pSrc = mapped_mem + (rects->x + rects->y * dstW)*2;
1902 +                               pDst = mapped_mem_fb + (dstH-1+rects->x * dstH - rects->y)*2;
1903 +
1904 +                               width = rects->w;
1905 +                               height = rects->h;
1906 +
1907 +                               srcYAdd = dstW - rects->w;
1908 +                               dstXAdd = dstH;
1909 +                               dstYSub = (dstH * rects->w) + 1;
1910 +
1911 +                               while (height--) {
1912 +                                       i = width;
1913 +                                       while (i--) {
1914 +                                               *pDst = *pSrc ++;
1915 +                                               pDst += dstXAdd;
1916 +                                       }
1917 +                                       pSrc += srcYAdd;
1918 +                                       pDst -= dstYSub;
1919 +                               }
1920 +
1921 +                       } else {
1922 +                               pDst=mapped_mem_fb+dstH*2-2;
1923 +                               pSrc=mapped_mem;
1924 +                               height=dstH;
1925 +                               width=dstW;
1926 +                               dstXAdd=height;
1927 +                               dstYSub=dstW*dstH+1;
1928 +
1929 +                               while (height--) {
1930 +                                       i = width;
1931 +                                       while (i--) {
1932 +                                               *pDst = *pSrc ++;
1933 +                                               pDst += dstXAdd;
1934 +                                       }
1935 +                                       pDst -= dstYSub;
1936 +                               }
1937 +                       }
1938 +                       numrects--;
1939 +                       rects++;
1940 +               }
1941 +               break;
1942 +       default:
1943 +               break;
1944 +       }
1945 +
1946 +
1947 +
1948 +}
1949 +
1950  #ifdef VGA16_FBCON_SUPPORT
1951  /* Code adapted with thanks from the XFree86 VGA16 driver! :) */
1952  #define writeGr(index, value) \
1953 Index: SDL-1.2.7/src/video/fbcon/SDL_fbevents.c
1954 ===================================================================
1955 --- SDL-1.2.7.orig/src/video/fbcon/SDL_fbevents.c       2005-03-02 22:24:43.458491481 +0100
1956 +++ SDL-1.2.7/src/video/fbcon/SDL_fbevents.c    2005-03-02 22:24:46.876008660 +0100
1957 @@ -60,7 +60,13 @@
1958  #ifndef GPM_NODE_FIFO
1959  #define GPM_NODE_FIFO  "/dev/gpmdata"
1960  #endif
1961 +#define POINTERCAL "/etc/pointercal"
1962  
1963 +static struct SDL_cal {
1964 +       long ok;
1965 +       long a, b, c, d, e, f, s;
1966 +       long rotate;
1967 +} cal = { 0 };
1968  
1969  /* The translation tables from a console scancode to a SDL keysym */
1970  #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT)
1971 @@ -317,6 +323,7 @@
1972         MOUSE_MS,
1973         MOUSE_BM,
1974         MOUSE_ELO,
1975 +       TS_SLC7X0,
1976         NUM_MOUSE_DRVS
1977  } mouse_drv = MOUSE_NONE;
1978  
1979 @@ -500,6 +507,9 @@
1980         mousedev = getenv("SDL_MOUSEDEV");
1981         mouse_fd = -1;
1982  
1983 +       const char *sdl_rot_flag;
1984 +       sdl_rot_flag = getenv("SDL_FBROT");
1985 +
1986         /* ELO TOUCHSCREEN SUPPORT */
1987  
1988         if( (mousedrv != NULL) && (strcmp(mousedrv, "ELO") == 0) ) {
1989 @@ -601,9 +611,39 @@
1990                         mouse_drv = MOUSE_MS;
1991                 }
1992         }
1993 +       /* Default to a SLC7X0 touch screen */
1994 +       if ( mouse_fd < 0 ) {
1995 +               mousedev = "/dev/ts";
1996 +               mouse_fd = open(mousedev, O_RDONLY, 0);
1997 +               if ( mouse_fd >= 0 ) {
1998 +                       FILE *pcal;
1999 +                       cal.ok = 0;
2000 +                       pcal = fopen(POINTERCAL, "r");
2001 +                       if(pcal == NULL){
2002 +                               fprintf(stderr, "Warning: cannot open " POINTERCAL ".\n");
2003 +                       }else{
2004 +                               int n;
2005 +                               n = fscanf(pcal, "%d %d %d %d %d %d %d",
2006 +                                          &cal.a, &cal.b, &cal.c, &cal.d, &cal.e, &cal.f, &cal.s);
2007 +                               if(n != 7){
2008 +                                   fprintf(stderr, "Warning: " POINTERCAL " is unknown format.\n");
2009 +                               }else{
2010 +                                   cal.ok = 1;
2011 +                               }
2012 +                               fclose(pcal);
2013 +                       }
2014 +                       if ( sdl_rot_flag == NULL ) {
2015 +                               cal.rotate = 0;
2016 +                       } else {
2017 +                               cal.rotate = atoi(sdl_rot_flag);
2018 +                       }
2019 +                       mouse_drv = TS_SLC7X0;
2020 +               }
2021 +       }
2022         if ( mouse_fd < 0 ) {
2023                 mouse_drv = MOUSE_NONE;
2024         }
2025 +
2026         return(mouse_fd);
2027  }
2028  
2029 @@ -678,6 +718,10 @@
2030                         packetsize = ELO_PACKET_SIZE;
2031                         relative = 0;
2032                         break;
2033 +               case TS_SLC7X0:
2034 +                       packetsize = 8;
2035 +                       relative = 0;
2036 +                       break;
2037                 case NUM_MOUSE_DRVS:
2038                         /* Uh oh.. */
2039                         packetsize = 0;
2040 @@ -810,6 +854,25 @@
2041                         */
2042  
2043                         case MOUSE_ELO:
2044 +                       case TS_SLC7X0:
2045 +                               /* Get current mouse state */
2046 +                               button = ((mousebuf[i+1] << 8)+mousebuf[i])/500;
2047 +                               dx = (mousebuf[i+3] << 8)+mousebuf[i+2];
2048 +                               dy = (mousebuf[i+5] << 8)+mousebuf[i+4];
2049 +                               if(cal.ok){
2050 +                                       long X, Y;
2051 +                                       X = (cal.a * dx + cal.b * dy + cal.c) / cal.s;
2052 +                                       Y = (cal.d * dx + cal.e * dy + cal.f) / cal.s;
2053 +                                       dx = X;
2054 +                                       dy = Y;
2055 +                               }
2056 +                               if(cal.rotate == 3){
2057 +                                       int tmp;
2058 +                                       tmp=dx;
2059 +                                       dx = dy;
2060 +                                       dy = 480-tmp;
2061 +                               }
2062 +                               break;
2063                         case NUM_MOUSE_DRVS:
2064                                 /* Uh oh.. */
2065                                 dx = 0;