home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / omron / omronInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-29  |  7.7 KB  |  327 lines

  1. /*
  2.  * $XConsortium: omronInit.c,v 1.1 91/06/29 13:48:57 xguest Exp $
  3.  *
  4.  * Copyright 1991 by OMRON Corporation
  5.  * 
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of OMRON not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  OMRON makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OMRON
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23.  
  24. #include "omron.h"
  25. #include "omronFb.h"
  26. #include "omronKbd.h"
  27. #include "omronMouse.h"
  28.  
  29. OmronFbInfo    omron_fb_info;    
  30.  
  31. int omronScreenIndex;
  32. static unsigned long omronGeneration;
  33.  
  34. static Bool omronScreenInit();
  35. static Bool omronGetFbInfo();
  36. static void omronSetConsoleMode();
  37. static void omronResetConsoleMode();
  38.  
  39. #ifndef luna88k
  40. # ifdef uniosu
  41. #  ifndef luna2
  42. static OmronFbProc omron_fb_proc_2 = {
  43.     omronFsBmCreate,  omronFsBmInit,  omronFsBmGiveUp
  44. };
  45. #  endif
  46. # endif /* uniosu */
  47. static OmronFbProc omron_fb_proc_1 = {
  48.     omronDtBmCreate,  omronDtBmInit,  omronDtBmGiveUp
  49. };
  50. #else /* luna88k */
  51. static OmronFbProc omron_fb_proc_1 = {
  52.     omron88kBmCreate, omron88kBmInit, omron88kBmGiveUp
  53. };
  54. #endif /* luna88k */
  55.  
  56.  
  57. int
  58. InitOutput(pScreenInfo, argc, argv)
  59. ScreenInfo       *pScreenInfo;
  60. int           argc;
  61. char          **argv;
  62. {
  63. static PixmapFormatRec  MonoFormats = {
  64.         1, 1, BITMAP_SCANLINE_PAD,  /* 1-bit deep */
  65.     };
  66. static Bool omronFbInfo     = FALSE;
  67. static Bool omronDevsCreate = FALSE;
  68.     
  69.     if (!omronFbInfo) {
  70.         if (omronGetFbInfo(&omron_fb_info) != TRUE) 
  71.             FatalError("Can't get framebuffer information.\n");
  72.         omronFbInfo = TRUE;
  73.     }
  74.  
  75.     pScreenInfo->imageByteOrder     = IMAGE_BYTE_ORDER;
  76.     pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  77.     pScreenInfo->bitmapScanlinePad  = BITMAP_SCANLINE_PAD;
  78.     pScreenInfo->bitmapBitOrder     = BITMAP_BIT_ORDER;
  79.  
  80.     pScreenInfo->numPixmapFormats = 1;
  81.     pScreenInfo->formats[0]       = MonoFormats;
  82.     
  83.     if (!omronDevsCreate) {
  84.         omronSetConsoleMode();
  85.  
  86.         if (!(* omron_fb_info.func->CreateProc)(&omron_fb_info)) {
  87.             FatalError("Can't create framebuffer.\n");
  88.         }
  89.         omronDevsCreate = TRUE;
  90.     }
  91.  
  92.     if(AddScreen(omronScreenInit, argc, argv) < 0) {
  93.         FatalError("Can't add screen\n");
  94.     }
  95. }
  96.  
  97.  
  98. static Bool
  99. omronScreenInit(screenIndex, pScreen, argc, argv)
  100. int        screenIndex;
  101. ScreenPtr    pScreen;
  102. int        argc;
  103. char         **argv;
  104. {
  105.     if (omronGeneration != serverGeneration) {
  106.         if((omronScreenIndex = AllocateScreenPrivateIndex()) <0) {
  107.             ErrorF("AllocateScreenPrivateIndex error.\n");
  108.             return FALSE;
  109.         }
  110.         omronGeneration = serverGeneration;
  111.     }
  112.     pScreen->devPrivates[omronScreenIndex].ptr = (pointer)&omron_fb_info;
  113.  
  114.     return((* omron_fb_info.func->InitProc)(screenIndex, pScreen, argc, argv));
  115. }
  116.  
  117.  
  118. int
  119. InitInput(argc, argv)
  120.     int    argc;
  121.     char   **argv;
  122. {
  123.     DevicePtr p, k;
  124.  
  125. #ifndef UNUSE_DRV_TIME
  126.     omronInitEventPrvRec();
  127. #endif
  128.     
  129.     p = AddInputDevice(omronMouseProc, TRUE);
  130.     k = AddInputDevice(omronKbdProc, TRUE);
  131.  
  132.     RegisterPointerDevice(p);
  133.     RegisterKeyboardDevice(k);
  134.  
  135.     miRegisterPointerDevice(screenInfo.screens[0], p);
  136.  
  137.     if (mieqInit (k, p) != TRUE) {
  138.         FatalError("Enqueue init error.\n");
  139.     }
  140.  
  141.     omronSetIoHandler(omronEnqueueEvents);
  142.  
  143. #ifndef UNUSE_SIGIO_SIGNAL
  144.     signal(SIGIO, omronSigIOHandler);
  145. #else
  146.     if(RegisterBlockAndWakeupHandlers(NoopDDA, omronWakeupProc, (pointer)0) != TRUE) {
  147.         FatalError("Can't register WakeupHandler\n");
  148.      }
  149. #endif
  150. }
  151.  
  152.  
  153. static Bool
  154. omronGetFbInfo(omron_fb_info)
  155. OmronFbInfoPtr omron_fb_info;
  156. {
  157.     int machine_type;
  158.  
  159.     if ( fb_type )
  160.     {
  161.         if (strcmp(fb_type, "DT_BM") == 0) {
  162.             omron_fb_info->fb_type = DT_BM;
  163.             omron_fb_info->func  = &omron_fb_proc_1;
  164.         } else if (strcmp(fb_type, "DT_BM8") == 0) {
  165.             omron_fb_info->fb_type = DT_BM8;
  166.             omron_fb_info->func  = &omron_fb_proc_1;
  167.         } else if (strcmp(fb_type, "DT_PLASMA") == 0) {
  168.             omron_fb_info->fb_type = DT_PLASMA;
  169.             omron_fb_info->func  = &omron_fb_proc_1;
  170.         } else if (strcmp(fb_type, "FS_BM") == 0) {    
  171.             omron_fb_info->fb_type = FS_BM;
  172. #if (defined(uniosu) && (! defined(luna2)))
  173.             omron_fb_info->func  = &omron_fb_proc_2;
  174. #endif
  175.         } else if (strcmp(fb_type, "DS_BM") == 0) {
  176.             omron_fb_info->fb_type = DS_BM; 
  177.         } else {
  178.             ErrorF("Unknown framebuffer type.\n");
  179.             return (FALSE);
  180.         }
  181.  
  182.         if (omron_fb_info->fb_type != DT_PLASMA) {
  183.             omron_fb_info->scr_width = SCREEN_WIDTH;  
  184.             omron_fb_info->scr_height = SCREEN_HEIGHT;  
  185.         } else {
  186.             omron_fb_info->scr_width = PLASMA_SCREEN_WIDTH;  
  187.             omron_fb_info->scr_height = PLASMA_SCREEN_HEIGHT;  
  188.         }
  189.  
  190.         omron_fb_info->fb_width = FB_WIDTH;  
  191.         omron_fb_info->fb_height = FB_HEIGHT;  
  192.         omron_fb_info->fb_depth = 1;
  193.         return (TRUE);
  194.     }
  195.  
  196. #ifdef    uniosu
  197.     if (sys9100(S91MACHTYPE,&machine_type) < 0) {
  198.         Error("sys9100 error.");
  199.         return (FALSE);
  200.     }
  201. #else
  202.     if (sysomron(S91MACHTYPE,&machine_type) < 0) {
  203.         Error("sysomron error.");
  204.         return (FALSE);
  205.     }
  206. #endif
  207.  
  208.     switch(machine_type & (MACH_MACH | MACH_GRAPHIC_BOARD)) {
  209.     case MACH_DT | MACH_BM : /* we call LUNA */ 
  210.         omron_fb_info->fb_type = DT_BM;
  211.         omron_fb_info->func  = &omron_fb_proc_1;
  212.         break;
  213.  
  214.     case MACH_DT | MACH_PLASMA  : /* LUNA support plasma display */  
  215.         omron_fb_info->fb_type = DT_PLASMA;
  216.         omron_fb_info->func  = &omron_fb_proc_1;
  217.         break;
  218.  
  219.     case MACH_DS | MACH_BM : /* we call Mr. */
  220.         omron_fb_info->fb_type = DS_BM;
  221.         break;
  222.  
  223.     case MACH_FS | MACH_BM : /* we call M90 */
  224.         omron_fb_info->fb_type = FS_BM;
  225. #if (defined(uniosu) && (! defined(luna2)))
  226.         omron_fb_info->func  = &omron_fb_proc_2;
  227. #endif
  228.         break;
  229.     default : 
  230.         ErrorF("Can't support machine type. (0x%x)\n",machine_type);
  231.         return (FALSE);
  232.     }
  233.  
  234.     switch(machine_type & MACH_PLANE){
  235.     case MACH_1_PLANE :
  236.         omron_fb_info->fb_depth = 1;
  237.         break;
  238.  
  239.     case MACH_4_PLANE :
  240.         omron_fb_info->fb_depth = 4;
  241.         break;
  242.  
  243.     case MACH_8_PLANE :
  244.         omron_fb_info->fb_depth = 8;
  245.         if(omron_fb_info->fb_type == DT_BM) {
  246.             omron_fb_info->fb_type = DT_BM8;
  247.         }
  248.         break;
  249.  
  250.     default :
  251.         ErrorF("Can't support plane number. (0x%x)\n", machine_type); 
  252.         return (FALSE);
  253.     }
  254.  
  255.     if (omron_fb_info->fb_type != DT_PLASMA) {
  256.         omron_fb_info->scr_width  = SCREEN_WIDTH;  
  257.         omron_fb_info->scr_height = SCREEN_HEIGHT;  
  258.     } else {
  259.         omron_fb_info->scr_width  = PLASMA_SCREEN_WIDTH;  
  260.         omron_fb_info->scr_height = PLASMA_SCREEN_HEIGHT;  
  261.     }
  262.  
  263.     if( scrw )
  264.         omron_fb_info->scr_width  = scrw;
  265.     if( scrh )
  266.         omron_fb_info->scr_height = scrh;
  267.  
  268.     omron_fb_info->fb_width = FB_WIDTH;  
  269.     omron_fb_info->fb_height = FB_HEIGHT;  
  270.  
  271.     return(TRUE);
  272. }
  273.  
  274.  
  275. static int  NonConsole;
  276.  
  277. static void
  278. omronSetConsoleMode()
  279. {
  280.     extern    char *ttyname();
  281.     char *p = ttyname(2);
  282.     register int i; 
  283.  
  284.     if (p && strcmp(p,"/dev/console")!=0) {
  285.         NonConsole = TRUE;
  286.         return;
  287.     } 
  288.  
  289.     i = fcntl(2, F_GETFL, 0); 
  290.     if(i >=0)
  291.         i = fcntl(2, F_SETFL, i | FNDELAY);
  292.     if (i < 0) {
  293.         FatalError("InitOutput:on console can't put stderr in non-block mode.\n");
  294.     }
  295. }
  296.  
  297. static void
  298. omronResetConsoleMode()
  299. {
  300.     register int i;
  301.  
  302.     if ( NonConsole ) {
  303.         return;
  304.     }
  305.     i = fcntl(2, F_GETFL, 0);
  306.     if (i >= 0)
  307.         (void)fcntl(2, F_SETFL, i & ~FNDELAY);
  308. }
  309.  
  310.  
  311. void
  312. AbortDDX()
  313. {
  314.     omronResetConsoleMode();
  315. }
  316.  
  317.  
  318. void
  319. ddxGiveUp()
  320. {
  321.     omronKbdGiveUp();
  322.     omronMouseGiveUp();
  323.     if (omron_fb_info.func->GiveUpProc != NULL)
  324.         (*omron_fb_info.func->GiveUpProc)(&omron_fb_info);
  325.     omronResetConsoleMode();
  326. }
  327.