home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / gfx / superview-lib-9.12.lha / SuperView-Lib / Programmers / Example_SVDrivers / ECS / SD_BufferSubs.c < prev    next >
C/C++ Source or Header  |  1994-12-28  |  10KB  |  328 lines

  1.  
  2.  /* SD_BufferSubs.c
  3.     - Functions for handling external drivers -
  4.     (c) 1990-94 by Andreas R. Kleinert
  5.     Last changes : 28.09.1994
  6.  */
  7.  
  8. #include "svdriver.h"
  9.  
  10. ULONG __saveds __asm SVD_SetGfxBuffer(      register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 struct SV_GfxBuffer *buffer, register __a3 ULONG future);
  11. ULONG __saveds __asm SVD_DisplayGfxBuffer(  register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 ULONG future);
  12.  
  13. long __saveds __stdargs SVLI_SVDScreen(struct SVDriverHandle *SVDriverHandle, ULONG ai_mode_id);
  14. long __saveds __stdargs SVLI_SVDSetCMAP(struct SVDriverHandle *SVDriverHandle, struct Screen *screen, long colornum);
  15.  
  16.  
  17. /* *************************************************** */
  18. /* *                             * */
  19. /* * SVD_SetGfxBuffer :                              * */
  20. /* *                             * */
  21. /* *************************************************** */
  22.  
  23. ULONG __saveds __asm SVD_SetGfxBuffer(  register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 struct SV_GfxBuffer *buffer, register __a3 ULONG future)
  24. {
  25.  struct SVDriverHandle *SVDriverHandle = SVDriverHandle_a1;
  26.  ULONG retval = SVERR_NO_ERROR;
  27.  
  28.  if(!SVDriverHandle) return(SVERR_NO_HANDLE);
  29.  
  30.  if(!buffer) return(SVERR_ILLEGAL_ACCESS);
  31.  
  32.  SVDriverHandle->ah_SV_GfxBuffer = buffer;
  33.  
  34.  return(retval);
  35. }
  36.  
  37. /* *************************************************** */
  38. /* *                             * */
  39. /* * SVD_DisplayGfxBuffer :                          * */
  40. /* *                             * */
  41. /* *************************************************** */
  42.  
  43. ULONG __saveds __asm SVD_DisplayGfxBuffer(  register __a1 struct SVDriverHandle *SVDriverHandle_a1, register __a2 ULONG future)
  44. {
  45.  struct SVDriverHandle *SVDriverHandle = SVDriverHandle_a1;
  46.  ULONG retval = SVERR_NO_ERROR;
  47.  ULONG width, height, depth, colnum, linebytes, bmpwidth, mode_id, j;
  48.  UBYTE *buffer, *bufferptr, *planeptr;
  49.  
  50.  struct RastPort *rp;
  51.  struct BitMap     *bm;
  52.  struct ViewPort *vp;
  53.  
  54.  if(!SVDriverHandle->ah_SV_GfxBuffer) return(SVERR_ILLEGAL_ACCESS);
  55.  
  56.  bufferptr = buffer = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Buffer;
  57.  if(!buffer) return(SVERR_ILLEGAL_ACCESS);
  58.  
  59.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType > SVGFX_BUFFERTYPE_ONEPLANE) return(SVERR_ACTION_NOT_SUPPORTED);
  60.  
  61.  /* Open Screen */
  62.  
  63.  mode_id = SVDriverHandle->ah_SV_GfxBuffer->svgfx_ViewMode32;
  64.  
  65.  if(!SVLI_SVDScreen(SVDriverHandle, mode_id)) return(SVERR_NO_SCREEN);
  66.  
  67.  rp = (struct RastPort *) &(SVDriverHandle->ah_Screen->RastPort);
  68.  bm = (struct BitMap   *) SVDriverHandle->ah_Screen->RastPort.BitMap;
  69.  vp = (struct ViewPort *) &(SVDriverHandle->ah_Screen->ViewPort);
  70.  
  71.  width     = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Width;
  72.  height    = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Height;
  73.  depth     = SVDriverHandle->ah_SV_GfxBuffer->svgfx_ColorDepth;
  74.  colnum    = 1 << depth;
  75.  
  76.  bmpwidth = ((width + 31) >> 5) << 5;
  77.  
  78.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType == SVGFX_BUFFERTYPE_BITPLANE)
  79.        linebytes = (long) SVDriverHandle->ah_SV_GfxBuffer->svgfx_BytesPerLine;
  80.   else linebytes = (long) bm->BytesPerRow;
  81.  
  82.  
  83.  /* Read Palette */
  84.  
  85.  SVLI_SVDSetCMAP(SVDriverHandle, SVDriverHandle->ah_Screen, colnum);
  86.  
  87.  
  88.  /* Decoding */
  89.  
  90.  planeptr  = (UBYTE *) N;
  91.  
  92.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType == SVGFX_BUFFERTYPE_BITPLANE)
  93.   {
  94.    if(linebytes == bm->BytesPerRow)
  95.     {
  96.      ULONG prod_1 = height * linebytes;
  97.  
  98.      for(j=0;j<depth;j++) CopyMem(bufferptr + j*prod_1, bm->Planes[j], prod_1);
  99.     }else
  100.     {
  101.               ULONG copybytes, pskipbytes, buf_ptradd1;
  102.      register ULONG i, j;
  103.      register UBYTE *bptr, *pptr;
  104.  
  105.      pskipbytes = bm->BytesPerRow;
  106.  
  107.      if(pskipbytes < linebytes) copybytes = pskipbytes;
  108.       else                      copybytes = linebytes;
  109.  
  110.      buf_ptradd1 = height*linebytes;
  111.  
  112.      for(j=0;j<depth;j++)
  113.       {
  114.        bptr = (UBYTE *) bufferptr + (buf_ptradd1 * j);
  115.        pptr = (UBYTE *) bm->Planes[j];
  116.  
  117.        for(i=0; i<height; i++)
  118.         {
  119.          CopyMem(bptr, pptr, copybytes);
  120.  
  121.          bptr += linebytes;
  122.          pptr += pskipbytes;
  123.         }
  124.       }
  125.     }
  126.   }
  127.  
  128.  if(SVDriverHandle->ah_SV_GfxBuffer->svgfx_BufferType == SVGFX_BUFFERTYPE_ONEPLANE)
  129.   {
  130.    if(depth <= 8)
  131.     {
  132.      /* Maybe, there are Graphic Cards, which allow 8 Bits colordepth
  133.         via an intuition-compatible AGA-emulation, but nevertheless
  134.         we cannot use V39-functions as in AGA.svdriver !!!
  135.      */
  136.  
  137.      struct RastPort *tmp_rp;
  138.      UBYTE           *bptr;
  139.      UBYTE           *linebuffer;
  140.      UWORD            i, j;
  141.  
  142.      linebuffer = (APTR) AllocVec(width, MEMF_CLEAR|MEMF_PUBLIC);
  143.      if(linebuffer)
  144.       {
  145.        tmp_rp = (APTR) AllocVec(sizeof(struct RastPort), MEMF_CLEAR|MEMF_PUBLIC);
  146.        if(tmp_rp)
  147.         {
  148.          InitRastPort(tmp_rp);
  149.  
  150.          tmp_rp->BitMap = AllocVec(sizeof(struct BitMap), MEMF_CLEAR|MEMF_PUBLIC);
  151.          if(tmp_rp->BitMap)
  152.           {
  153.            InitBitMap(tmp_rp->BitMap, depth, bmpwidth, 1);
  154.  
  155.            for(i=0; i<depth; i++)
  156.             {
  157.              tmp_rp->BitMap->Planes[i] = (APTR) AllocRaster(bmpwidth, 1);
  158.              if(!tmp_rp->BitMap->Planes[i])
  159.               {
  160.                retval = SVERR_NO_MEMORY;
  161.  
  162.                break;
  163.               }
  164.             }
  165.  
  166.            if(!retval)
  167.             {
  168.              ULONG wm8 = (width>>3)<<3;
  169.  
  170.              bptr = bufferptr;
  171.  
  172.              for(j=0; j<height; j++, bptr+=width)
  173.               {
  174.                CopyMem(bptr, linebuffer, width);
  175.  
  176.                WritePixelLine8(rp, 0, j, wm8, linebuffer, tmp_rp);
  177.               }
  178.             }
  179.  
  180.            for(i=0; i<8; i++) if(tmp_rp->BitMap->Planes[i]) FreeRaster(tmp_rp->BitMap->Planes[i], bmpwidth, 1);
  181.  
  182.            FreeVec(tmp_rp->BitMap);
  183.           }else retval = SVERR_NO_MEMORY;
  184.  
  185.          FreeVec(tmp_rp);
  186.         }else retval = SVERR_NO_MEMORY;
  187.  
  188.        FreeVec(linebuffer);
  189.  
  190.       }else retval = SVERR_NO_MEMORY;
  191.  
  192.     }else
  193.     {
  194.      /* Insert code for handling color depths > 8
  195.         (future AGA or AAA features ?)
  196.      */
  197.  
  198.      retval = SVERR_UNKNOWN_PARAMETERS;
  199.     }
  200.   }
  201.  
  202.  ScreenToFront(SVDriverHandle->ah_Screen);
  203.  
  204.  return(retval);
  205. }
  206.  
  207. /* *************************************************** */
  208. /* *                             * */
  209. /* * SVLI_SVDScreen : SVD Screen Opening Function    * */
  210. /* *                             * */
  211. /* *************************************************** */
  212.  
  213. struct TextAttr __aligned chip topazfont = { (STRPTR) "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  214.  
  215. long __saveds __stdargs SVLI_SVDScreen(struct SVDriverHandle *SVDriverHandle, ULONG ai_mode_id)
  216. {
  217.  long ai_width, ai_height, ai_depth;
  218.  struct Rectangle __aligned rect;
  219.  
  220.  if(!SVDriverHandle->ah_SV_GfxBuffer) return(FALSE);
  221.  
  222.  
  223.  /* Get and set Standard Screen Dimensions */
  224.  
  225.  ai_width  = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Width;
  226.  ai_height = SVDriverHandle->ah_SV_GfxBuffer->svgfx_Height;
  227.  ai_depth  = SVDriverHandle->ah_SV_GfxBuffer->svgfx_ColorDepth;
  228.  
  229.  
  230.  /* Get and/or set Screen, Window and IDCMP Flags */
  231.  
  232.  if(!SVDriverHandle->ah_ScreenType)  SVDriverHandle->ah_ScreenType  = CUSTOMSCREEN;
  233.  if(!SVDriverHandle->ah_WindowIDCMP) SVDriverHandle->ah_WindowIDCMP = IDCMP_MOUSEBUTTONS | IDCMP_VANILLAKEY;
  234.  if(!SVDriverHandle->ah_WindowFlags) SVDriverHandle->ah_WindowFlags = WFLG_BACKDROP | WFLG_BORDERLESS | WFLG_NOCAREREFRESH | WFLG_SIMPLE_REFRESH;
  235.  
  236.  if(!QueryOverscan(ai_mode_id, &rect, OSCAN_TEXT))
  237.   {
  238.    rect.MinX = 0;
  239.    rect.MaxX = ai_width;
  240.    rect.MinY = 0;
  241.    rect.MaxY = ai_height;
  242.   }
  243.  
  244.  /* Open Screen like needed for SVD Displaying */
  245.  
  246.  SVDriverHandle->ah_Screen = OpenScreenTags( NULL, SA_Left,        0,
  247.                                         SA_Top,       0,
  248.                                        SA_Width,       ai_width,
  249.                                    SA_Height,       ai_height,
  250.                                    SA_Depth,       ai_depth,
  251.                                    SA_Font,      &topazfont,
  252.                                    SA_Type,       SVDriverHandle->ah_ScreenType,
  253.                                    SA_DisplayID,   ai_mode_id,
  254.                                    SA_Title,       "Please wait ...",
  255.                                    SA_AutoScroll,  TRUE,
  256.                                    SA_DClip,       &rect,
  257.                                    SA_Behind,      TRUE,
  258.                                    TAG_END );
  259.  
  260.  if(!SVDriverHandle->ah_Screen) return(FALSE);
  261.  
  262.  
  263.  /* Open Window like needed for SVD Displaying */
  264.  
  265.  SV