home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / ddx-mips.zip / MIPS3230.C < prev    next >
C/C++ Source or Header  |  1992-04-07  |  10KB  |  459 lines

  1. /*
  2.  * $XConsortium: mips3230.c,v 1.2 91/07/12 20:48:43 keith Exp $
  3.  *
  4.  * Copyright 1991 MIPS Computer Systems, Inc.
  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 MIPS not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  MIPS 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.  * MIPS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL MIPS
  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. #ident    "$Header: mips3230.c,v 1.12 92/04/06 21:01:56 dd Exp $"
  24.  
  25. #include <sys/types.h>
  26. #include <sysv/sys/grafreg.h>
  27. #include <sysv/sys/termio.h>
  28. #include <sysv/sys/kbd_ioctl.h>
  29.  
  30. #include <X.h>
  31. #include <Xproto.h>
  32. #include <misc.h>
  33. #include <cursorstr.h>
  34. #include <input.h>
  35. #include <scrnintstr.h>
  36. #include <servermd.h>
  37.  
  38. #include "mips.h"
  39. #include "mipsFb.h"
  40. #include "mips3230.h"
  41. #include "mipsKbd.h"
  42. #include "mipsIo.h"
  43.  
  44. #ifdef MIPSEL
  45.  
  46. /* XXX need to #ifdef MIPSPACKED stuff */
  47. mipsFlush3230()
  48. {
  49. }
  50.  
  51. #else /* MIPSEL */
  52.  
  53. extern char *mipsMapit();
  54.  
  55. static void Blank3230c();
  56. static void WriteCMap3230c();
  57. static void Close3230c();
  58.  
  59. static Bool RealizeCursor3230c();
  60. static void SetCursor3230c();
  61. static void MoveCursor3230c();
  62. static void RecolorCursor3230c();
  63.  
  64. static void Blank3230m();
  65.  
  66. /*
  67.  * Color frame buffer support
  68.  */
  69.  
  70. Bool
  71. mipsMap3230c(pm)
  72.     MipsScreenPtr pm;
  73. {
  74.     if (!pm->fbreg && (
  75.         !(pm->fbcache = (unsigned char *) mipsMapit((char *) 0,
  76.             GBFCKEY, R3030_GRAPHICS_FRAME_SIZE)) ||
  77.         !(pm->fbnocache = (unsigned char *) mipsMapit((char *) 0,
  78.             GBUFKEY, R3030_GRAPHICS_FRAME_SIZE)) ||
  79.         !(pm->fbspec = (unsigned char *) mipsMapit((char *) 0,
  80.             GBFVKEY, R3030_GRAPHICS_VECTOR_FRAME_SIZE)) ||
  81.         !(pm->fbreg = (unsigned char *) mipsMapit((char *) 0,
  82.             GREGKEY, R3030_GRAPHICS_REG_SIZE))))
  83.         return FALSE;
  84.  
  85.     pm->fbnorm = pm->option & MIPS_SCR_NOCACHE ?
  86.         pm->fbnocache : pm->fbcache;
  87.  
  88.     Close3230c(pm);
  89.     mipsInitColor(pm);
  90.  
  91.     /*
  92.      * Disable monochrome video to avoid performance degradation
  93.      * when running color-only on two headed system.
  94.      *
  95.      * (Depends on monochrome video being enabled later for real
  96.      * two headed operation, and Blank3230m() not needing the pm
  97.      * struct contents.)
  98.      */
  99.     openKeybd();
  100.     Blank3230m((MipsScreenPtr) 0, SCREEN_SAVER_ON);
  101.  
  102.     pm->fb_width = RS3230C_BPSL;
  103.  
  104.     if (!(pm->option & MIPS_SCR_NOHW)) {
  105.         pm->cap = MIPS_SCR_CURSOR | MIPS_SCR_MASK;
  106.  
  107.         /* fill mode and packed mode don't work on type 0 color
  108.          * boards */
  109.         if (((struct rs3230c_reg *) pm->fbreg)->kernel &
  110.             RS3230C_KERNEL_IDMASK)
  111.             pm->cap |= MIPS_SCR_PACKED | MIPS_SCR_FILL;
  112.     }
  113.  
  114.     pm->Blank = Blank3230c;
  115.     pm->WriteCMap = WriteCMap3230c;
  116.     pm->Close = Close3230c;
  117.  
  118.     pm->RealizeCursor = RealizeCursor3230c;
  119.     pm->SetCursor = SetCursor3230c;
  120.     pm->MoveCursor = MoveCursor3230c;
  121.     pm->RecolorCursor = RecolorCursor3230c;
  122.  
  123.     {
  124.         struct bt459 *ramdac =
  125.             &((struct rs3230c_reg *) pm->fbreg)->ramdac;
  126.         int v;
  127.  
  128.         /*
  129.          * Set read mask for number of planes populated.
  130.          * XXX The PROM and/or kernel should take care of this.
  131.          * XXX All 3230s have 8 bit frame buffers anyway.
  132.          */
  133.         BT459_SETADDR(ramdac, BT459_READMASK);
  134.         ramdac->ctrl = (1 << pm->depth) - 1;
  135.  
  136.         /*
  137.          * Set HW cursor to "X mode"
  138.          */
  139.         BT459_SETADDR(ramdac, BT459_CR2);
  140.         v = ramdac->ctrl;
  141.         ramdac->adlo = BT459_CR2;
  142.         ramdac->ctrl = v | BT459_CR2_XCURS;
  143.     }
  144.  
  145.     return TRUE;
  146. }
  147.  
  148. static void
  149. Blank3230c(pm, on)
  150.     MipsScreenPtr pm;
  151.     Bool on;
  152. {
  153.     struct rs3230c_reg *reg = (struct rs3230c_reg *) pm->fbreg;
  154.  
  155.     if (on != SCREEN_SAVER_ON)
  156.         reg->xserver |= RS3230C_XSERVER_UNBLANK;
  157.     else
  158.         reg->xserver &= ~RS3230C_XSERVER_UNBLANK;
  159. }
  160.  
  161. /*
  162.  * KTCWRTCOLOR doesn't work on a 3230.  It doesn't even give an error,
  163.  * just prints "WARNING: No IRQ5 Interrupt Available" on the console.
  164.  */
  165. static void
  166. WriteCMap3230c(pm, index, count, rgb)
  167.     MipsScreenPtr pm;
  168.     int index;
  169.     int count;
  170.     unsigned char *rgb;
  171. {
  172.     struct bt459 *ramdac =
  173.         &((struct rs3230c_reg *) pm->fbreg)->ramdac;
  174.     volatile DACBITS *out = &ramdac->cmap;
  175.  
  176.     BT459_SETADDR(ramdac, BT459_CMAPRAM + index);
  177.  
  178.     while (--count >= 0) {
  179.         *out = rgb[0];
  180.         *out = rgb[1];
  181.         *out = rgb[2];
  182.         rgb +=3;
  183.     }
  184. }
  185.  
  186. static void
  187. Close3230c(pm)
  188.     MipsScreenPtr pm;
  189. {
  190.     struct rs3230c_reg *reg = (struct rs3230c_reg *) pm->fbreg;
  191.  
  192.     /* clear mode bits in X server register */
  193.     reg->xserver &= RS3230C_XSERVER_UNBLANK;
  194.  
  195.     /* disable plane mask */
  196.     reg->mask = ~0;
  197.  
  198.     /* disable HW cursor */
  199.     SetCursor3230c(pm, (CursorPtr) 0, (pointer) 0, 0, 0);
  200. }
  201.  
  202. /*
  203.  * Convert cursor source and mask planes into fixed size Bt459 format
  204.  * buffer, so we can reload the cursor RAM more quickly.
  205.  *
  206.  * The Bt459 interleaves mask and source bits in each byte, with the leftmost
  207.  * pixel as the MSB:  <M0 S0 M1 S1 M2 S2 M3 S3>
  208.  */
  209. static Bool
  210. RealizeCursor3230c(pm, pCurs, pPriv)
  211.     MipsScreenPtr pm;
  212.     CursorPtr pCurs;
  213.     pointer *pPriv;
  214. {
  215.     CursorBitsPtr bits = pCurs->bits;
  216.     int w, h;
  217.     int x, y;
  218.     int bytes;
  219.     int soffset;
  220.     short *ram, rmask;
  221.     unsigned char *source, *mask;
  222.     int ramt, st, mt;
  223.     int bit;
  224.  
  225.     ram = (short *) xalloc(BT459_CURSBYTES);
  226.     *pPriv = (pointer) ram;
  227.     if (!ram)
  228.         return FALSE;
  229.  
  230.     h = bits->height;
  231.     if (h > BT459_CURSMAX)
  232.         h = BT459_CURSMAX;
  233.  
  234.     w = bits->width;
  235.  
  236.     /* line to line offset in source and mask bitmaps */
  237.     soffset = ((w + BITMAP_SCANLINE_PAD - 1) &
  238.         ~(BITMAP_SCANLINE_PAD - 1)) >> 3;
  239.  
  240.     if (w > BT459_CURSMAX)
  241.         w = BT459_CURSMAX;
  242.  
  243.     /* right edge mask for cursor RAM */
  244.     rmask = 0xffff0000 >> ((w & 7) << 1);
  245.  
  246.     /* bytes per line actually used in source and mask bitmaps */
  247.     bytes = (w + 7) >> 3;
  248.  
  249.     source = bits->source;
  250.     mask = bits->mask;
  251.  
  252.     for (y = 0; y < h; y++) {
  253.         for (x = 0; x < bytes; x++) {
  254.             /*
  255.              * Repack 1 mask byte and 1 source byte into
  256.              * 2 Bt459 cursor RAM bytes.
  257.              */
  258.             mt = mask[x] << 8;
  259.             st = source[x] << 7;
  260.             ramt = 0;
  261.             bit = 0x8000;
  262.             while (bit) {
  263.                 ramt |= (mt & bit);
  264.                 bit >>= 1;
  265.                 mt >>= 1;
  266.                 ramt |= (st & bit);
  267.                 bit >>= 1;
  268.                 st >>= 1;
  269.             }
  270.             *ram++ = ramt;
  271.         }
  272.  
  273.         /*
  274.          * Mask off garbage bits of partial word on right edge of
  275.          * cursor (if any).
  276.          */
  277.         if (rmask)
  278.             ram[-1] &= rmask;
  279.  
  280.         /* zero out blank space to right of cursor */
  281.         for (; x < BT459_CURSMAX / 8; x++)
  282.             *ram++ = 0;
  283.  
  284.         source += soffset;
  285.         mask += soffset;
  286.     }
  287.     /* zero out blank space below cursor */
  288.     for (; y < BT459_CURSMAX; y++) {
  289.         for (x = 0; x < BT459_CURSMAX / 8; x++)
  290.             ram[x] = 0;
  291.         ram += BT459_CURSMAX / 8;
  292.     }
  293.  
  294.     return TRUE;
  295. }
  296.  
  297. static void
  298. SetCursor3230c(pm, pCurs, priv, x, y)
  299.     MipsScreenPtr pm;
  300.     CursorPtr pCurs;
  301.     pointer priv;
  302.     int x, y;
  303. {
  304.     struct bt459 *ramdac =
  305.         &((struct rs3230c_reg *) pm->fbreg)->ramdac;
  306.     unsigned char *ram, c;
  307.     int i;
  308.  
  309.     /* turn cursor off */
  310.     BT459_SETADDR(ramdac, BT459_CURSCMD);
  311.     ramdac->ctrl = 0;
  312.  
  313.     if (!pCurs)
  314.         return;
  315.  
  316.     /* adjust hot spot values using magic constants from databook */
  317.     pm->xhot = BT459_CURSFIXX(pCurs->bits->xhot);
  318.     pm->yhot = BT459_CURSFIXY(pCurs->bits->yhot);
  319.  
  320.     /* position cursor */
  321.     MoveCursor3230c(pm, x, y);
  322.  
  323.     /* load colormap */
  324.     RecolorCursor3230c(pm, pCurs);
  325.  
  326.     ram = (unsigned char *) priv;
  327.  
  328.     /*
  329.      * Load cursor RAM from preformatted buffer
  330.      */
  331.     BT459_SETADDR(ramdac, BT459_CURSRAM);
  332.     for (i = 0; i < BT459_CURSBYTES; i++)
  333.         ramdac->ctrl = ram[i];
  334.  
  335.     /*
  336.      * Verify cursor RAM contents and correct any errors caused by
  337.      * internal bus contention in Bt459 Rev A parts...
  338.      */
  339.     BT459_SETADDR(ramdac, BT459_CURSRAM);
  340.     for (i = 0; i < BT459_CURSBYTES; i++)
  341.         while ((c = (unsigned char) ramdac->ctrl) != ram[i]) {
  342.             BT459_SETADDR(ramdac, BT459_CURSRAM + i);
  343.             ramdac->ctrl = (DACBITS) ram[i];
  344.             BT459_SETADDR(ramdac, BT459_CURSRAM + i);
  345.         }
  346.  
  347.     /* turn cursor on */
  348.     BT459_SETADDR(ramdac, BT459_CURSCMD);
  349.     ramdac->ctrl = BT459_CURSCMD_CURSEN;
  350. }
  351.  
  352. static void
  353. MoveCursor3230c(pm, x, y)
  354.     MipsScreenPtr pm;
  355.     int x, y;
  356. {
  357.     struct bt459 *ramdac =
  358.         &((struct rs3230c_reg *) pm->fbreg)->ramdac;
  359.  
  360.     x += pm->xhot;
  361.     y += pm->yhot;
  362.  
  363.     BT459_SETADDR(ramdac, BT459_CURSXLO);
  364.     ramdac->ctrl = x;
  365.     ramdac->ctrl = x >> 8;
  366.     ramdac->ctrl = y;
  367.     ramdac->ctrl = y >> 8;
  368. }
  369.  
  370. static void
  371. RecolorCursor3230c(pm, pCurs)
  372.     MipsScreenPtr pm;
  373.     CursorPtr pCurs;
  374. {
  375.     struct bt459 *ramdac =
  376.         &((struct rs3230c_reg *) pm->fbreg)->ramdac;
  377.  
  378.     BT459_SETADDR(ramdac, BT459_CURSCOL2);
  379.     ramdac->ctrl = pCurs->backRed >> 8;
  380.     ramdac->ctrl = pCurs->backGreen >> 8;
  381.     ramdac->ctrl = pCurs->backBlue >> 8;
  382.     ramdac->ctrl = pCurs->foreRed >> 8;
  383.     ramdac->ctrl = pCurs->foreGreen >> 8;
  384.     ramdac->ctrl = pCurs->foreBlue >> 8;
  385. }
  386.  
  387.  
  388. /*
  389.  * Monochrome frame buffer support
  390.  */
  391.  
  392. Bool
  393. mipsMap3230m(pm)
  394.     MipsScreenPtr pm;
  395. {
  396.     if (!pm->fbnorm &&
  397.         !(pm->fbnorm = pm->option & MIPS_SCR_NOCACHE ?
  398.             (pm->fbnocache =
  399.                 (unsigned char *) mipsMapit((char *) 0,
  400.                 GBMNUNC, MONO_FRAME_SIZE)) :
  401.             (pm->fbcache =
  402.                 (unsigned char *) mipsMapit((char *) 0,
  403.                 GBMONCH, MONO_FRAME_SIZE))))
  404.         return FALSE;
  405.  
  406.     pm->bitsPerPixel = 1;
  407.     pm->depth = 1;
  408.     pm->dpi = DPI_MONO17;
  409.     pm->scr_width = RS3230M_VISW;
  410.     pm->scr_height = RS3230M_VISH;
  411.     pm->fb_width = RS3230M_BPSL * 8;
  412.     pm->Blank = Blank3230m;
  413.  
  414.     /* need to open keyboard for blanking control */
  415.     openKeybd();
  416.  
  417.     return TRUE;
  418. }
  419.  
  420. static void
  421. Blank3230m(pm, on)
  422.     MipsScreenPtr pm;
  423.     Bool on;
  424. {
  425.     int value;
  426.  
  427.     value = on == SCREEN_SAVER_ON ? 1 : 0;
  428.  
  429.     if (keybdPriv.cap & DEV_BLANK)
  430.         if (sysvIoctl(keybdPriv.fd, KTMBLANK, &value) < 0) {
  431.             keybdPriv.cap &= ~DEV_BLANK;
  432.             Error("KTMBLANK ioctl failed");
  433.         }
  434. }
  435.  
  436.  
  437. #define    RS3230_LINESIZE        32
  438. #define    RS3230_CACHESIZE    RS3230C_VISW
  439. #define    RS3230_ALIGN        (64 * 1024)
  440.  
  441. /* flush frame buffer data from cache */
  442. /* XXX method for computing flush address is hokey */
  443. mipsFlush3230()
  444. {
  445.     static volatile char *flush;
  446.     extern char *sbrk();
  447.     volatile char *p;
  448.     int i;
  449.  
  450.     if ((p = flush) == 0)
  451.         flush = p = (volatile char *)
  452.             (((int) sbrk(0) & ~(RS3230_ALIGN - 1)) - RS3230_ALIGN);
  453.  
  454.     for (i = 0; i < RS3230_CACHESIZE; i += RS3230_LINESIZE)
  455.         p[i];
  456. }
  457.  
  458. #endif /* not MIPSEL */
  459.