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

  1. /*
  2.  * $XConsortium: omronDtBm.c,v 1.1 91/06/29 13:48:53 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. #ifndef luna88k
  25. #include "omron.h" 
  26.  
  27. #include "omronFb.h" 
  28.  
  29. /*
  30. **    color palette 
  31. */
  32. struct pal{
  33.     unsigned char red;
  34.     unsigned char green;
  35.     unsigned char blue;
  36. };
  37.  
  38. static struct pal paldata[256] = {
  39.     {~0,~0,~0}, {0,0,0},
  40.     {~0,~0,~0}, {0,0,0},
  41.     {~0,~0,~0}, {0,0,0},
  42.     {~0,~0,~0}, {0,0,0},
  43.     {~0,~0,~0}, {0,0,0},
  44.     {~0,~0,~0}, {0,0,0},
  45.     {~0,~0,~0}, {0,0,0},
  46.     {~0,~0,~0}, {0,0,0}
  47. };
  48.  
  49. static struct pal palinit[256] = {
  50.     {~0,~0,~0}, {0,0,0},
  51.     {~0,~0,~0}, {0,0,0},
  52.     {~0,~0,~0}, {0,0,0},
  53.     {~0,~0,~0}, {0,0,0},
  54.     {~0,~0,~0}, {0,0,0},
  55.     {~0,~0,~0}, {0,0,0},
  56.     {~0,~0,~0}, {0,0,0},
  57.     {~0,~0,~0}, {0,0,0}
  58. };
  59.  
  60. static struct pal palsave[256];
  61.  
  62. static int      pagesize;
  63.  
  64. static Bool omronDtBmPalCreate();
  65. static void omronDtBmPalInit();
  66. static void omronDtBmGetPal();
  67. static void omronDtBmSetPal();
  68.  
  69. Bool
  70. omronDtBmCreate(omron_fb_info)
  71. OmronFbInfoPtr omron_fb_info;
  72. {
  73.     DtBmMapPtr dt_bm_reg = (DtBmMapPtr)0xb1000000;    /* frame buffer i/o port */
  74.  
  75.     /* Set transparent Mapping. */
  76. #ifdef uniosu
  77.     if(sys9100(S91TPTRE, 0x80, 0x3f, 0) < 0) {
  78.         return FALSE;
  79.     }
  80. #else
  81.     if(sysomron(S91TPTRE, 0x80, 0x3f, 0) < 0) {
  82.         return FALSE;
  83.     }
  84. #endif
  85.  
  86.     omron_fb_info->plane = (char *)0xb10c0008;    
  87.  
  88.  
  89.     omron_fb_info->fbmap = (char *)dt_bm_reg;
  90.     omron_fb_info->refresh_reg = &(dt_bm_reg->refresh.reg);
  91.  
  92.     if (!omronDtBmPalCreate(omron_fb_info)) {
  93.         return FALSE;
  94.     }
  95.  
  96.     if (omron_fb_info->fb_type == DT_PLASMA)
  97.         *(omron_fb_info->refresh_reg) = 0x100000;
  98.     else if (omron_fb_info->fb_type == DT_BM8)
  99.         *(omron_fb_info->refresh_reg) = 0xff07f7e6;
  100.     else
  101.         *(omron_fb_info->refresh_reg) = 0xff07f7e5;
  102.  
  103.     return TRUE;
  104. }
  105.  
  106.  
  107. static Bool
  108. omronDtBmSaveScreen(pScreen, on)
  109. ScreenPtr     pScreen;
  110. Bool          on;
  111. {
  112. static int omronScreenIsSaved = FALSE;
  113.     struct pal savepal[256];     
  114.     OmronFbInfoPtr pFbInfo =
  115.         (OmronFbInfoPtr)pScreen->devPrivates[omronScreenIndex].ptr;
  116.  
  117.     if (on != SCREEN_SAVER_ON) {
  118.         omronSetLastEventTime();
  119.         if(omronScreenIsSaved == TRUE) {
  120.             omronDtBmSetPal(pFbInfo, palsave);
  121.             omronScreenIsSaved = FALSE;
  122.         }
  123.         return TRUE;
  124.     }
  125.  
  126.     bzero(savepal, sizeof(savepal));
  127.     omronDtBmSetPal(pFbInfo, savepal);
  128.     omronScreenIsSaved = TRUE;
  129.     return TRUE;
  130. }
  131.  
  132. Bool
  133. omronDtBmInit(index, pScreen, argc, argv)
  134.     int           index;
  135.     ScreenPtr     pScreen;
  136.     int           argc;
  137.     char          **argv;
  138. {
  139.     OmronFbInfoPtr pFbInfo;
  140.     extern miPointerScreenFuncRec  omronPointerScreenFuncs;
  141.     
  142.     pFbInfo = (OmronFbInfoPtr) pScreen->devPrivates[omronScreenIndex].ptr;
  143.  
  144.     omronDtBmPalInit(pFbInfo);
  145.  
  146.     if (!monitorResolution) {
  147.         if (pFbInfo->fb_type == DT_PLASMA)
  148.             monitorResolution = PLASMA_TV_RESOLUTION;
  149.         else
  150.             monitorResolution = MONO_TV_RESOLUTION; 
  151.     }
  152.  
  153.     if(!mfbScreenInit(pScreen,(pointer)pFbInfo->plane,
  154.             pFbInfo->scr_width,pFbInfo->scr_height,
  155.             monitorResolution,monitorResolution,pFbInfo->fb_width)){
  156.         ErrorF("mfbScreenInit error.\n");
  157.         return FALSE;
  158.     }
  159.  
  160.        pScreen->whitePixel = 0;
  161.        pScreen->blackPixel = 1;
  162.  
  163.     miDCInitialize (pScreen, &omronPointerScreenFuncs);
  164.  
  165.     mfbCreateDefColormap(pScreen);
  166.  
  167.     pScreen->SaveScreen = omronDtBmSaveScreen;
  168.  
  169.     omronDtBmSaveScreen(pScreen, SCREEN_SAVER_FORCER);
  170.     
  171.     return TRUE;
  172.  
  173. }
  174.  
  175. static void
  176. omronDtBmPalClose(omron_fb_info)
  177. OmronFbInfoPtr omron_fb_info;
  178. {
  179.     union palette_bm8 *dt_bm8_pal;
  180.  
  181.     omronDtBmSetPal(omron_fb_info, paldata);
  182.  
  183.     if(omron_fb_info->fb_type == DT_BM8) {
  184.         dt_bm8_pal = (union palette_bm8 *)(omron_fb_info->palmap);
  185.         dt_bm8_pal->reg.addr = 0x4L;
  186.         dt_bm8_pal->reg.command = 0x1L;
  187.     } else if(omron_fb_info->fb_type == DT_PLASMA) {
  188.         *(omron_fb_info->refresh_reg) = 0;
  189.     }
  190.  
  191.     if (munmap(omron_fb_info->palmap, omron_fb_info->palmapsize) < 0) {
  192.         Error("Can't munmap palette.");
  193.     }
  194.  
  195.     free(omron_fb_info->palmap);
  196.     (void)close(omron_fb_info->palfd);
  197. }
  198.  
  199.  
  200. static Bool
  201. omronDtBmPalCreate(omron_fb_info)
  202. OmronFbInfoPtr omron_fb_info;
  203. {
  204.     union palette_bm8 *dt_bm8_pal;
  205.  
  206.     if ((omron_fb_info->palfd = open("/dev/palette",2)) < 0) {
  207.         Error("Can't open /dev/palette");
  208.         return FALSE;
  209.     }
  210.  
  211. #ifndef uniosu
  212.     pagesize = getpagesize();
  213. #endif
  214.  
  215.     if(omron_fb_info->fb_type == DT_BM8) {    /* BM8 */
  216. #ifndef uniosu
  217.         omron_fb_info->palmapsize =
  218.             (sizeof(union palette_bm8) + (pagesize - 1)) & ~(pagesize - 1);
  219. #else
  220.         omron_fb_info->palmapsize = sizeof(union palette_bm8);
  221. #endif
  222.     } else {    /* BM */
  223. #ifndef uniosu
  224.         omron_fb_info->palmapsize =
  225.             (sizeof(union palette) + (pagesize - 1)) & ~(pagesize - 1);
  226. #else
  227.         omron_fb_info->palmapsize = sizeof(union palette);
  228. #endif
  229.     }
  230.  
  231.     omron_fb_info->palmap = valloc(omron_fb_info->palmapsize);
  232.  
  233.     if(omron_fb_info->palmap  == (char *) NULL) {
  234.         Error("Can't allocate palette.");
  235.         return FALSE;    
  236.     }
  237.  
  238.     if (mmap(omron_fb_info->palmap, omron_fb_info->palmapsize,
  239.              (PROT_WRITE | PROT_READ),MAP_SHARED, omron_fb_info->palfd, 0) < 0) { 
  240.         Error("Can't mmap palette.");
  241.         free(omron_fb_info->palmap);
  242.         return FALSE;
  243.     }    
  244.  
  245.     if(ioctl(omron_fb_info->palfd, PLTIOCUND, 0) < 0) {
  246.         Error("ioctl PLTIOCUND error.");
  247.         return FALSE;
  248.     }
  249.  
  250.     if(omron_fb_info->fb_type == DT_BM8) {    /* BM8 */
  251.         dt_bm8_pal = (union palette_bm8 *)(omron_fb_info->palmap);
  252.         dt_bm8_pal->reg.addr    = 0x04;
  253.         dt_bm8_pal->reg.command = (1 << omron_fb_info->fb_depth) - 1;
  254.         dt_bm8_pal->reg.addr    = 0x06;
  255.         dt_bm8_pal->reg.command = 0x40;
  256.     }
  257.  
  258.     omronDtBmGetPal(omron_fb_info, paldata);
  259.  
  260.     return TRUE; 
  261. }
  262.  
  263.  
  264. static void
  265. omronDtBmPalInit(omron_fb_info)
  266. OmronFbInfoPtr omron_fb_info;
  267. {
  268.     bcopy(palinit, palsave, sizeof(palinit));
  269.     omronDtBmSetPal(omron_fb_info, palsave);
  270. }
  271.  
  272.  
  273. static void
  274. omronDtBmSetPal(omron_fb_info, pal)
  275. OmronFbInfoPtr omron_fb_info;
  276. struct pal *pal;
  277. {
  278.     union palette       *dt_bm_pal;
  279.     union palette_bm8  *dt_bm8_pal;
  280.     register int       i, j;
  281.     unsigned char      *palp;
  282.  
  283.     if(omron_fb_info->fb_type == DT_BM8) {    /* BM8 */
  284.         dt_bm8_pal = (union palette_bm8 *)(omron_fb_info->palmap);
  285.         for (i = 0; i < 256; i++) {
  286.             palp = &pal++->red;
  287.             dt_bm8_pal->reg.addr = i;
  288.             for (j = 0; j < 3; j++) {
  289.                 dt_bm8_pal->reg.coldata = *palp++;
  290.             }
  291.         }
  292.     } else {
  293.         dt_bm_pal = (union palette *)(omron_fb_info->palmap);
  294.         /* restore palette data */
  295.         for (i = 0; i < 16; i++) {
  296.             palp = &pal++->red;
  297.             dt_bm_pal->reg.addr = i << 4;
  298.             for (j = 0; j < 3; j++)
  299.                 dt_bm_pal->reg.coldata = *palp++;
  300.         }
  301.     }
  302. }
  303.  
  304.  
  305. static void
  306. omronDtBmGetPal(omron_fb_info, pal)
  307. OmronFbInfoPtr omron_fb_info;
  308. struct pal *pal;
  309. {
  310.     union palette       *dt_bm_pal;
  311.     union palette_bm8  *dt_bm8_pal;
  312.     register    int    i,j;
  313.     unsigned char    *palp;
  314.  
  315.     if(omron_fb_info->fb_type == DT_BM8) {    /* BM8 */
  316.         dt_bm8_pal = (union palette_bm8 *)(omron_fb_info->palmap);
  317.  
  318.         /* save the CPU ROM palette setting */
  319.         for (i = 0; i < 256; i++) {
  320.             palp = &pal++->red;
  321.             dt_bm8_pal->reg.addr = i;
  322.             for (j = 0; j < 3; j++) {
  323.                 *palp++ = dt_bm8_pal->reg.coldata;
  324.             }
  325.         }
  326.     } else {
  327.         dt_bm_pal = (union palette *)(omron_fb_info->palmap);
  328.  
  329.         /* save the CPU ROM palette setting */
  330.         for (i = 0; i < 16; i++) {
  331.             palp = &pal++->red;
  332.             dt_bm_pal->reg.addr = i << 4;
  333.             for (j = 0; j < 3; j++) {
  334.                 *palp++ = dt_bm_pal->reg.coldata;
  335.             }
  336.         }
  337.     }
  338. }
  339.  
  340.  
  341. static void
  342. omronDtBmFbClear(omron_fb_info)
  343. OmronFbInfoPtr omron_fb_info;
  344. {
  345.     register int *f;
  346.     register int nw,height;
  347.     int nwidth,nlwidth,nlwExtra;
  348.  
  349.     f = (int *)omron_fb_info->plane;
  350.     nlwidth  = (omron_fb_info->fb_width)>>5;
  351.     nwidth   = (omron_fb_info->scr_width)>>5;
  352.     nlwExtra = nlwidth - nwidth;
  353.     height =omron_fb_info->scr_height;
  354.  
  355.     while(height--) {
  356.         nw = nwidth;
  357.         while(nw--)
  358.             *f++ = 0;
  359.         f += nlwExtra;
  360.     }
  361. }
  362.  
  363. void
  364. omronDtBmGiveUp(omron_fb_info)
  365. OmronFbInfoPtr omron_fb_info;
  366. {
  367.     omronDtBmFbClear(omron_fb_info);
  368.     omronDtBmPalClose(omron_fb_info);
  369. }
  370. /*
  371. #endif
  372. */
  373. #endif /* !luna88k */
  374.