e45a804bb7b6f8be10d49082b7ceb7ad24fb6cc8
[drnoksnes] / platform / sdlv.cpp
1 #include <stdio.h>
2
3 #include <X11/Xlib.h>
4 #include <X11/Xutil.h>
5 #include <SDL.h>
6 #include <SDL_syswm.h>
7
8 #if CONF_XSP
9 #       include <X11/extensions/Xsp.h>
10 #endif
11
12 #include "snes9x.h"
13 #include "platform.h"
14 #include "display.h"
15 #include "gfx.h"
16 #include "ppu.h"
17
18 #define DIE(format, ...) do { \
19                 fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
20                 fprintf(stderr, format "\n", ## __VA_ARGS__); \
21                 abort(); \
22         } while (0);
23
24 struct gui GUI;
25
26 static SDL_Surface* screen;
27
28 static SDL_Rect windowSize, screenSize;
29 static bool gotWindowSize, gotScreenSize;
30
31 class Scaler;
32 /** The current scaler object */
33 static Scaler* scaler;
34
35 static void centerRectangle(SDL_Rect& result, int areaW, int areaH, int w, int h)
36 {
37         result.x = areaW / 2 - w / 2;
38         result.w = w;
39         result.y = areaH / 2 - h / 2;
40         result.h = h;
41 }
42
43 class Scaler
44 {
45 public:
46         Scaler() { };
47         virtual ~Scaler() { };
48
49         virtual const char * getName() const = 0;
50
51         virtual uint8* getDrawBuffer() const = 0;
52         virtual unsigned int getDrawBufferPitch() const = 0;
53         virtual void getRenderedGUIArea(unsigned short & x, unsigned short & y,
54                                                                         unsigned short & w, unsigned short & h)
55                                                                         const = 0;
56         virtual int getRatio() const = 0;
57         virtual void prepare() = 0;
58         virtual void finish() = 0;
59         virtual void pause() = 0;
60         virtual void resume() = 0;
61 };
62
63 class ScalerFactory
64 {
65 public:
66         ScalerFactory() { };
67         virtual ~ScalerFactory() { };
68         virtual const char * getName() const = 0;
69         virtual bool canEnable(int bpp, int w, int h) const = 0;
70         virtual Scaler* instantiate(SDL_Surface* screen, int w, int h) const = 0;
71 };
72
73 class DummyScaler : public Scaler
74 {
75         SDL_Surface * m_screen;
76         SDL_Rect m_area;
77
78         DummyScaler(SDL_Surface* screen, int w, int h)
79         : m_screen(screen)
80         {
81                 centerRectangle(m_area, GUI.Width, GUI.Height, w, h);
82         }
83 public:
84
85         ~DummyScaler()
86         {
87         };
88
89         class Factory : public ScalerFactory
90         {
91                 const char * getName() const
92                 {
93                         return "none";
94                 }
95
96                 bool canEnable(int bpp, int w, int h) const
97                 {
98                         return true;
99                 }
100
101                 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
102                 {
103                         return new DummyScaler(screen, w, h);
104                 }
105         };
106
107         static const Factory factory;
108
109         const char * getName() const
110         {
111                 return "no scaling";
112         }
113
114         uint8* getDrawBuffer() const
115         {
116                 const int Bpp = screen->format->BitsPerPixel / 8;
117                 const int pitch = screen->pitch;
118                 return ((uint8*) screen->pixels)
119                         + (m_area.x * Bpp)
120                         + (m_area.y * pitch);
121         };
122
123         unsigned int getDrawBufferPitch() const
124         {
125                 return screen->pitch;
126         };
127
128         void getRenderedGUIArea(unsigned short & x, unsigned short & y,
129                                                         unsigned short & w, unsigned short & h) const
130         {
131                 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
132         };
133
134         int getRatio() const
135         {
136                 return 1;
137         };
138
139         void prepare() { };
140
141         void finish()
142         {
143                 SDL_UpdateRects(m_screen, 1, &m_area);
144         };
145
146         void pause() { };
147         void resume() { };
148 };
149 const DummyScaler::Factory DummyScaler::factory;
150
151 #ifdef __arm__
152 class ARMScaler : public Scaler
153 {
154         SDL_Surface * m_screen;
155         SDL_Rect m_area;
156         uint8 * m_surface;
157         const int m_w, m_h, m_Bpp;
158
159         ARMScaler(SDL_Surface* screen, int w, int h)
160         : m_screen(screen), m_w(w), m_h(h),
161          m_Bpp(m_screen->format->BitsPerPixel / 8)
162         {
163                 centerRectangle(m_area, GUI.Width, GUI.Height, w * 2, h * 2);
164                 m_surface = reinterpret_cast<uint8*>(malloc(w * h * m_Bpp));
165         }
166 public:
167         ~ARMScaler()
168         {
169                 free(m_surface);
170         };
171
172         class Factory : public ScalerFactory
173         {
174                 const char * getName() const
175                 {
176                         return "2x";
177                 }
178
179                 bool canEnable(int bpp, int w, int h) const
180                 {
181                         return bpp == 16 && w * 2 < GUI.Width && h * 2 < GUI.Height &&
182                                 w % 16 == 0 /* asm assumes w div by 16 */;
183                 }
184
185                 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
186                 {
187                         return new ARMScaler(screen, w, h);
188                 }
189         };
190
191         static const Factory factory;
192
193         const char * getName() const
194         {
195                 return "software ARM 2x scaling";
196         }
197
198         uint8* getDrawBuffer() const
199         {
200                 return m_surface;
201         };
202
203         unsigned int getDrawBufferPitch() const
204         {
205                 return m_w * m_Bpp;
206         };
207
208         void getRenderedGUIArea(unsigned short & x, unsigned short & y,
209                                                         unsigned short & w, unsigned short & h) const
210         {
211                 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
212         };
213
214         int getRatio() const
215         {
216                 return 2;
217         };
218
219         void prepare() { };
220
221         void finish()
222         {
223                 uint16 * src = reinterpret_cast<uint16*>(m_surface);
224                 uint16 * dst = reinterpret_cast<uint16*>(
225                         ((uint8*) m_screen->pixels)
226                         + (m_area.x * m_Bpp)
227                         + (m_area.y * m_screen->pitch));
228                 const int src_pitch = m_w;
229                 const int dst_pitch = m_screen->pitch / m_Bpp;
230                 int y;
231
232                 for (y = 0; y < m_h*2; y++) {
233                         asm volatile
234                         (
235                                 "mov r0, %0; mov r1, %1; mov r2, %2;"
236                                 "stmdb r13!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,r14};"
237                                 "1:     ldmia r1!,{r3,r4,r5,r6,r7,r8,r9,r10};"
238                                 "mov r14,r5,lsr #16;"
239                                 "mov r12,r5,lsl #16;"
240                                 "orr r14,r14,r14,lsl #16;"
241                                 "orr r12,r12,r12,lsr #16;"
242                                 "mov r11,r4,lsr #16;"
243                                 "mov r5,r4,lsl #16;"
244                                 "orr r11,r11,r11,lsl #16;"
245                                 "orr r5,r5,r5,lsr #16;"
246                                 "mov r4,r3,lsr #16;"
247                                 "mov r3,r3,lsl #16;"
248                                 "orr r4,r4,r4,lsl #16;"
249                                 "orr r3,r3,r3,lsr #16;"
250                                 "stmia r0!,{r3,r4,r5,r11,r12,r14};"
251                                 "mov r3,r6,lsl #16;"
252                                 "mov r4,r6,lsr #16;"
253                                 "orr r3,r3,r3,lsr #16;"
254                                 "orr r4,r4,r4,lsl #16;"
255                                 "mov r5,r7,lsl #16;"
256                                 "mov r6,r7,lsr #16;"
257                                 "orr r5,r5,r5,lsr #16;"
258                                 "orr r6,r6,r6,lsl #16;"
259                                 "mov r7,r8,lsl #16;"
260                                 "mov r8,r8,lsr #16;"
261                                 "orr r7,r7,r7,lsr #16;"
262                                 "orr r8,r8,r8,lsl #16;"
263                                 "mov r12,r10,lsr #16;"
264                                 "mov r11,r10,lsl #16;"
265                                 "orr r12,r12,r12,lsl #16;"
266                                 "orr r11,r11,r11,lsr #16;"
267                                 "mov r10,r9,lsr #16;"
268                                 "mov r9,r9,lsl #16;"
269                                 "orr r10,r10,r10,lsl #16;"
270                                 "orr r9,r9,r9,lsr #16;"
271                                 "stmia r0!,{r3,r4,r5,r6,r7,r8,r9,r10,r11,r12};"
272                                 "subs r2,r2,#16;"
273                                 "bhi 1b;"
274                                 "ldmia r13!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,r14};"
275                         :
276                         : "r" (dst), "r" (src), "r" (m_w)
277                         : "r0", "r1", "r2", "r3"
278                         );
279                         dst += dst_pitch;
280                         if (y&1) src += src_pitch;
281                 }
282
283                 SDL_UpdateRects(m_screen, 1, &m_area);
284         };
285
286         void pause() { };
287         void resume() { };
288 };
289 const ARMScaler::Factory ARMScaler::factory;
290 #endif
291
292 class SWScaler : public Scaler
293 {
294         SDL_Surface * m_screen;
295         SDL_Rect m_area;
296         uint8 * m_surface;
297         const int m_w, m_h, m_Bpp;
298
299         SWScaler(SDL_Surface* screen, int w, int h)
300         : m_screen(screen), m_w(w), m_h(h),
301          m_Bpp(m_screen->format->BitsPerPixel / 8)
302         {
303                 centerRectangle(m_area, GUI.Width, GUI.Height, w * 2, h * 2);
304                 m_surface = reinterpret_cast<uint8*>(malloc(w * h * m_Bpp));
305         }
306 public:
307         ~SWScaler()
308         {
309                 free(m_surface);
310         };
311
312         class Factory : public ScalerFactory
313         {
314                 const char * getName() const
315                 {
316                         return "soft2x";
317                 }
318
319                 bool canEnable(int bpp, int w, int h) const
320                 {
321                         return w * 2 < GUI.Width && h * 2 < GUI.Height;
322                 }
323
324                 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
325                 {
326                         return new SWScaler(screen, w, h);
327                 }
328         };
329
330         static const Factory factory;
331
332         const char * getName() const
333         {
334                 return "software 2x scaling";
335         }
336
337         uint8* getDrawBuffer() const
338         {
339                 return m_surface;
340         };
341
342         unsigned int getDrawBufferPitch() const
343         {
344                 return m_w * m_Bpp;
345         };
346
347         void getRenderedGUIArea(unsigned short & x, unsigned short & y,
348                                                         unsigned short & w, unsigned short & h) const
349         {
350                 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
351         };
352
353         int getRatio() const
354         {
355                 return 2;
356         };
357
358         void prepare() { };
359
360         void finish()
361         {
362                 uint16 * src = reinterpret_cast<uint16*>(m_surface);
363                 uint16 * dst = reinterpret_cast<uint16*>(
364                         ((uint8*) m_screen->pixels)
365                         + (m_area.x * m_Bpp)
366                         + (m_area.y * m_screen->pitch));
367                 const int src_pitch = m_w;
368                 const int dst_pitch = m_screen->pitch / m_Bpp;
369                 int x, y;
370
371                 for (y = 0; y < m_h*2; y++) {
372                         for (x = 0; x < m_w*2; x+=2) {
373                                 dst[x] = src[x/2];
374                                 dst[x + 1] = src[x/2];
375                         }
376                         dst += dst_pitch;
377                         if (y&1) src += src_pitch;
378                 }
379
380                 SDL_UpdateRects(m_screen, 1, &m_area);
381         };
382
383         void pause() { };
384         void resume() { };
385 };
386 const SWScaler::Factory SWScaler::factory;
387
388 #if CONF_XSP
389 class XSPScaler : public Scaler
390 {
391         SDL_Surface* m_screen;
392         SDL_Rect m_area;
393         SDL_Rect m_real_area;
394         bool m_should_enable, m_enabled; // Try to avoid flicker.
395
396         static void setDoubling(bool enable)
397         {
398                 SDL_SysWMinfo wminfo;
399                 SDL_VERSION(&wminfo.version);
400                 if ( SDL_GetWMInfo(&wminfo) ) {
401                         Display *dpy = wminfo.info.x11.display;
402                         XSPSetPixelDoubling(dpy, 0, enable ? 1 : 0);
403                         XFlush(dpy);
404                 }
405         }
406
407         XSPScaler(SDL_Surface* screen, int w, int h)
408         : m_screen(screen), m_should_enable(true), m_enabled(false)
409         {
410                 centerRectangle(m_area, GUI.Width, GUI.Height,
411                         w * 2, h * 2);
412
413                 m_real_area.x = m_area.x;
414                 m_real_area.y = m_area.y;
415                 m_real_area.w = m_area.w / 2;
416                 m_real_area.h = m_area.h / 2;
417         };
418 public:
419         ~XSPScaler()
420         {
421                 if (m_enabled) setDoubling(false);
422         };
423
424         class Factory : public ScalerFactory
425         {
426                 const char * getName() const
427                 {
428                         return "xsp";
429                 }
430
431                 bool canEnable(int bpp, int w, int h) const
432                 {
433                         return w * 2 < GUI.Width && h * 2 < GUI.Height;
434                 };
435
436                 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
437                 {
438                         return new XSPScaler(screen, w, h);
439                 }
440         };
441
442         static const Factory factory;
443
444         const char * getName() const
445         {
446                 return "XSP pixel doubling";
447         }
448
449         uint8* getDrawBuffer() const
450         {
451                 const int Bpp = screen->format->BitsPerPixel / 8;
452                 const int pitch = screen->pitch;
453                 return ((uint8*) screen->pixels)
454                         + (m_area.x * Bpp)
455                         + (m_area.y * pitch);
456         };
457
458         unsigned int getDrawBufferPitch() const
459         {
460                 return screen->pitch;
461         };
462
463         void getRenderedGUIArea(unsigned short & x, unsigned short & y,
464                                                         unsigned short & w, unsigned short & h) const
465         {
466                 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
467         };
468
469         int getRatio() const
470         {
471                 return 2;
472         };
473
474         void prepare() 
475         {
476                 if (m_should_enable && !m_enabled) {
477                         setDoubling(true);
478                         m_enabled = true;
479                 }
480         };
481
482         void finish()
483         {
484                 SDL_UpdateRects(m_screen, 1, &m_real_area);
485         };
486
487         void pause()
488         {
489                 m_should_enable = false;
490                 if (m_enabled) {
491                         setDoubling(false);
492                         m_enabled = false;
493                 }
494         };
495
496         void resume()
497         {
498                 m_should_enable = true; // Will enable later
499         };
500 };
501 const XSPScaler::Factory XSPScaler::factory;
502 #endif
503
504 static const ScalerFactory* scalers[] = {
505 #if CONF_XSP
506         &XSPScaler::factory,
507 #endif
508 #ifdef __arm__
509         &ARMScaler::factory,
510 #endif
511         &SWScaler::factory,
512         &DummyScaler::factory
513 };
514
515 static const ScalerFactory* searchForScaler(int bpp, int w, int h)
516 {
517         const int n = sizeof(scalers) / sizeof(ScalerFactory*);
518         int i;
519
520         if (Config.scaler && strcasecmp(Config.scaler, "help") == 0 ) {
521                 // List scalers
522                 printf("Scalers list:\n");
523                 for (i = 0; i < n; i++) {
524                         printf(" %s\n", scalers[i]->getName());
525                 }
526                 DIE("End of scalers list");
527         } else if (Config.scaler && strcasecmp(Config.scaler, "auto") != 0 ) {
528                 // We prefer a specific scaler
529                 for (i = 0; i < n; i++) {
530                         if (strcasecmp(scalers[i]->getName(), Config.scaler) == 0) {
531                                 if (scalers[i]->canEnable(bpp, w, h)) {
532                                         // Found the scaler selected by the user, and we can use it.
533                                         return scalers[i];
534                                 } else {
535                                         fprintf(stderr,
536                                                 "Selected scaler '%s' cannot be enabled in this mode\n",
537                                                 Config.scaler);
538                                         break; // Fallback to another scaler.
539                                 }
540                         }
541                 }
542                 if (i == n) {
543                         fprintf(stderr, "Selected scaler '%s' does not exist\n",
544                                 Config.scaler);
545                 }
546         }
547
548         // Just try them all now, in a buildtime set priority.
549         for (i = 0; i < n; i++) {
550                 if (scalers[i]->canEnable(bpp, w, h)) {
551                         return scalers[i];
552                 }
553         }
554
555         DIE("Can't use any scaler; this shouldn't happen.");
556 }
557
558 static void calculateScreenSize()
559 {
560         SDL_SysWMinfo wminfo;
561         SDL_VERSION(&wminfo.version);
562
563         if ( SDL_GetWMInfo(&wminfo) ) {
564                 Display *dpy = wminfo.info.x11.display;
565                 Window w;
566                 SDL_Rect* size;
567                 XWindowAttributes xwa;
568
569                 if (Config.fullscreen) {
570                         w =  wminfo.info.x11.fswindow;
571                         size = &screenSize;
572                         gotScreenSize = true;
573                 } else {
574                         w =  wminfo.info.x11.wmwindow;
575                         size = &windowSize;
576                         gotWindowSize = true;
577                 }
578
579                 XGetWindowAttributes(dpy, w, &xwa);
580                 size->x = xwa.x;
581                 size->y = xwa.y;
582                 size->w = xwa.width;
583                 size->h = xwa.height;
584         }
585 }
586
587 void S9xSetTitle(const char *title)
588 {
589         SDL_SysWMinfo info;
590         SDL_VERSION(&info.version);
591         if ( SDL_GetWMInfo(&info) ) {
592                 Display *dpy = info.info.x11.display;
593                 Window win;
594                 if (dpy) {
595                         win = info.info.x11.fswindow;
596                         if (win) XStoreName(dpy, win, title);
597                         win = info.info.x11.wmwindow;
598                         if (win) XStoreName(dpy, win, title);
599                 }
600         }
601 }
602
603 static void freeVideoSurface()
604 {
605         screen = 0; // There's no need to free the screen surface.
606         GFX.Screen = 0;
607
608         free(GFX.SubScreen); GFX.SubScreen = 0;
609         free(GFX.ZBuffer); GFX.ZBuffer = 0;
610         free(GFX.SubZBuffer); GFX.SubZBuffer = 0;
611
612         delete scaler; scaler = 0;
613 }
614
615 static void setupVideoSurface()
616 {
617         // Real surface area.
618         const unsigned gameWidth = IMAGE_WIDTH;
619         const unsigned gameHeight = IMAGE_HEIGHT;
620
621 #ifdef MAEMO
622         if ((Config.fullscreen && !gotScreenSize) ||
623                 (!Config.fullscreen && !gotWindowSize)) {
624                 // Do a first try, in order to get window/screen size
625                 screen = SDL_SetVideoMode(gameWidth, gameHeight, 16,
626                         SDL_SWSURFACE | SDL_RESIZABLE |
627                         (Config.fullscreen ? SDL_FULLSCREEN : 0));
628                 if (!screen) DIE("SDL_SetVideoMode: %s", SDL_GetError());
629                 calculateScreenSize();
630         }
631         if (Config.fullscreen) {
632                 GUI.Width = screenSize.w;
633                 GUI.Height = screenSize.h;
634         } else {
635                 GUI.Width = windowSize.w;
636                 GUI.Height = windowSize.h;
637         }
638 #else
639         GUI.Width = gameWidth;
640         GUI.Height = gameHeight;
641 #endif
642
643         // Safeguard
644         if (gameHeight > GUI.Height || gameWidth > GUI.Width)
645                 DIE("Video is larger than window size!");
646
647         const ScalerFactory* sFactory =
648                 searchForScaler(Settings.SixteenBit ? 16 : 8, gameWidth, gameHeight);
649
650         screen = SDL_SetVideoMode(GUI.Width, GUI.Height,
651                                                                 Settings.SixteenBit ? 16 : 8,
652                                                                 SDL_SWSURFACE |
653                                                                 (Config.fullscreen ? SDL_FULLSCREEN : 0));
654         if (!screen)
655                 DIE("SDL_SetVideoMode: %s", SDL_GetError());
656         
657         SDL_ShowCursor(SDL_DISABLE);
658
659         scaler = sFactory->instantiate(screen, gameWidth, gameHeight);
660
661         // We get pitch surface values from SDL
662         GFX.RealPitch = GFX.Pitch = scaler->getDrawBufferPitch();
663         GFX.ZPitch = GFX.Pitch / 2; // gfx & tile.cpp depend on this, unfortunately.
664         GFX.PixSize = screen->format->BitsPerPixel / 8;
665         
666         GFX.Screen = scaler->getDrawBuffer();
667         GFX.SubScreen = (uint8 *) malloc(GFX.Pitch * IMAGE_HEIGHT);
668         GFX.ZBuffer =  (uint8 *) malloc(GFX.ZPitch * IMAGE_HEIGHT);
669         GFX.SubZBuffer = (uint8 *) malloc(GFX.ZPitch * IMAGE_HEIGHT);
670
671         GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
672         GFX.PPL = GFX.Pitch >> 1;
673         GFX.PPLx2 = GFX.Pitch;
674
675         scaler->getRenderedGUIArea(GUI.RenderX, GUI.RenderY, GUI.RenderW, GUI.RenderH);
676         GUI.Scale = scaler->getRatio();
677
678         printf("Video: %dx%d (%dx%d output), %hu bits per pixel, %s, %s\n",
679                 gameWidth, gameHeight,
680                 screen->w, screen->h, screen->format->BitsPerPixel,
681                 Config.fullscreen ? "fullscreen" : "windowed",
682                 scaler->getName());
683 }
684
685 static void drawOnscreenControls()
686 {
687         if (Config.touchscreenInput) {
688                 S9xInputScreenChanged();
689                 if (Config.touchscreenShow) {
690                         scaler->pause();
691                         SDL_FillRect(screen, NULL, 0);
692                         S9xInputScreenDraw(Settings.SixteenBit ? 2 : 1,
693                                                                 screen->pixels, screen->pitch);
694                         SDL_Flip(screen);
695                         scaler->resume();
696                 }
697         }
698 }
699
700 void S9xInitDisplay(int argc, const char ** argv)
701 {       
702         if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) 
703                 DIE("SDL_InitSubSystem(VIDEO): %s", SDL_GetError());
704
705         setupVideoSurface();
706         drawOnscreenControls();
707 }
708
709 void S9xDeinitDisplay()
710 {
711         freeVideoSurface();     
712         SDL_QuitSubSystem(SDL_INIT_VIDEO);
713 }
714
715 void S9xVideoToggleFullscreen()
716 {
717         Config.fullscreen = !Config.fullscreen;
718         freeVideoSurface();
719         setupVideoSurface();
720         drawOnscreenControls();
721 }
722
723 void S9xVideoOutputFocus(bool hasFocus)
724 {
725 #if 0 // TODO
726         if (Config.xsp) {
727                 setDoubling(hasFocus);
728         } 
729 #endif
730 }
731
732 // This is here for completeness, but palette mode is useless on N8x0
733 void S9xSetPalette ()
734 {
735         if (Settings.SixteenBit) return;
736         
737         SDL_Color colors[256];
738         int brightness = IPPU.MaxBrightness *138;
739         for (int i = 0; i < 256; i++)
740         {
741                 colors[i].r = ((PPU.CGDATA[i] >> 0) & 0x1F) * brightness;
742                 colors[i].g = ((PPU.CGDATA[i] >> 5) & 0x1F) * brightness;
743                 colors[i].b = ((PPU.CGDATA[i] >> 10) & 0x1F) * brightness;
744         }
745         
746         SDL_SetColors(screen, colors, 0, 256);
747 }
748
749 bool8_32 S9xInitUpdate ()
750 {
751         scaler->prepare();
752
753         return TRUE;
754 }
755
756 bool8_32 S9xDeinitUpdate (int width, int height, bool8_32 sixteenBit)
757 {
758         scaler->finish();
759
760         return TRUE;
761 }
762