home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / gnuplot.lha / gnuplot / src / term / amiga.trm < prev    next >
Encoding:
Text File  |  1995-12-13  |  6.4 KB  |  272 lines

  1. /* GNUPLOT - amiga.trm */
  2. /*
  3.  * Copyright (C) 1991, 1992, 1995
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *   Amiga Workbench window
  21.  *
  22.  * AUTHORS
  23.  *   Carsten Steger
  24.  * 
  25.  *   Pat R. Empleo      Slightly modified for Aztec C v5.2a (beta); sort of
  26.  *   08/27/91           supports overscan; for large WB 2.0 virtual screens,
  27.  *                      we limit the plot size so we don't have to scroll
  28.  *                      around (not fun).
  29.  *
  30.  *   Carsten Steger     Modified to support Kickstart 2.0.
  31.  *   09/11/91           Opens a text overscan screen when used with WB 2.0.
  32.  *                      Discerns between NTSC and PAL Amigas when used with
  33.  *                      WB 1.3 and lower.
  34.  *
  35.  *   Pat R. Empleo      Defined some 2.0 stuff in order to get Aztec C to
  36.  *   09/20/91           work with Carsten's new code (see above).  When
  37.  *                      KS/WB 2.0 support gets implemented in Aztec C, this
  38.  *                      kludge will get deleted!
  39.  *                      (Aztec C release 5.2 beta)
  40.  *
  41.  *   George Coulouris   Significant rewrite. Now opens a 512x320 window on
  42.  *   glc5@cornell.edu   the Workbench screen, allocates pens with
  43.  *   12/12/95           ObtainBestPen(). Requires AmigaDOS 3.0.
  44.  *                      Source is commented a little better than before.
  45.  *
  46.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  47.  * 
  48.  */
  49. #include <stdio.h>
  50.  
  51. #include <exec/types.h>
  52. #include <intuition/intuitionbase.h>
  53. #include <graphics/gfxbase.h>
  54. #include <proto/intuition.h>
  55. #include <proto/graphics.h>
  56. #include <proto/exec.h>
  57.  
  58. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  59. #define AMIGA_XMAX 512
  60. #define AMIGA_YMAX 320
  61. #define AMIGA_VCHAR (12)
  62. #define AMIGA_HCHAR (8)
  63. #define AMIGA_VTIC (AMIGA_YMAX/80)
  64. #define AMIGA_HTIC (AMIGA_XMAX/80)
  65.  
  66. struct IntuitionBase *IntuitionBase;
  67. struct GfxBase *GfxBase;
  68. struct Window *plotwin;
  69.  
  70. static enum JUSTIFY AMIGA_justify = LEFT;
  71. static WORD AMIGA_bsl, AMIGA_cht, AMIGA_vadj;
  72. static unsigned int AMIGA_xmax, AMIGA_ymax;
  73.  
  74. /*
  75.  * This  is the palette.  Values are stored as 0xrrggbb, where rr, gg, and, bb
  76.  * are big-endian 8-bit intensities for red, green, and blue, respectively.
  77.  */
  78.  
  79. static unsigned int palette[10] =
  80.     {
  81.     0xffffff,    /* white */
  82.     0x000000,    /* black */
  83.     0xff0000,    /* red */
  84.     0x00ff00,    /* green */
  85.     0x0000ff,    /* blue */
  86.     0x00ffff,    /* cyan */
  87.     0xff00ff,    /* magenta */
  88.     0xffff00,    /* yellow */
  89.     0x7f007f,    /* purple */
  90.     0xff7f00,    /* orange */
  91.     };
  92.  
  93. /* This is the color look-up table, indexed in the same order as
  94. the above palette. The values stored in this table are pen numbers;
  95. e.g clut[2] is the pen which represents the color "red". */
  96.  
  97. static unsigned int clut[10];
  98.  
  99. AMIGA_reset()
  100. {
  101. int i;
  102.  
  103. /* Free the pens */
  104. for(i=0;i<11;i++)
  105.     if ( clut[i] != -1 )
  106.         ReleasePen(plotwin->WScreen->ViewPort.ColorMap, clut[i]);
  107.  
  108. /* Close the window */
  109.   if (plotwin != NULL) CloseWindow(plotwin);
  110.  
  111. /* Close libraries */
  112.   if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  113.   if (GfxBase != NULL) CloseLibrary(GfxBase);
  114. }
  115.  
  116. AMIGA_init()
  117. {
  118. int i, r,g,b;
  119.  
  120. /* Initialize the clut */
  121. for(i=0;i<11;i++)
  122.     clut[i] = -1;
  123.  
  124. /* Open libraries */
  125.  
  126. GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",39);
  127.  
  128. if (GfxBase == NULL)
  129.     {
  130.     fprintf(stderr,"*** Could not load graphics.library 39\n\n");
  131.     AMIGA_reset();
  132.     exit(20);
  133.     }
  134.  
  135. IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",36);
  136.  
  137. if (IntuitionBase == NULL)
  138.     {
  139.     fprintf(stderr,"*** Could not load intuition.library 36\n\n");
  140.     AMIGA_reset();
  141.     exit(20);
  142.     }
  143.  
  144. /* Open the plot window */
  145.  
  146. plotwin = (struct Window *) OpenWindowTags(NULL,
  147.     WA_InnerWidth, 512,
  148.     WA_InnerHeight, 320,
  149.     WA_Title, "gnuplot",
  150.     WA_DragBar, TRUE,
  151.     WA_DepthGadget, TRUE,
  152.     WA_WBenchWindow, TRUE,
  153.     WA_SmartRefresh, TRUE,
  154.     WA_GimmeZeroZero, TRUE,
  155.     WA_AutoAdjust, TRUE,
  156.     TAG_DONE);
  157.  
  158. if (plotwin == NULL)
  159.     {
  160.     fprintf(stderr,"*** Could not open window\n\n");
  161.     AMIGA_reset();
  162.     exit(20);
  163.     }
  164.  
  165. AMIGA_xmax = 512;
  166. AMIGA_ymax = 320;
  167.  
  168. term_tbl[term].xmax = AMIGA_xmax;
  169. term_tbl[term].ymax = AMIGA_ymax;
  170.  
  171. AMIGA_bsl = plotwin->RPort->TxBaseline; /* Reference line */
  172. AMIGA_cht = plotwin->RPort->TxHeight; /* Height of characters */
  173. AMIGA_vadj = AMIGA_bsl / 2;
  174.  
  175.  
  176. /* Allocate pens */
  177.  
  178. for(i=0;i<11;i++)
  179.     {
  180.     r = (palette[i] << 8 ) & 0xFF000000;
  181.     g = (palette[i] << 16) & 0xFF000000;
  182.     b = (palette[i] << 24) & 0xFF000000;
  183.     clut[i] = ObtainBestPenA(plotwin->WScreen->ViewPort.ColorMap,r,g,b,NULL);
  184.     }
  185.  
  186.   SetDrMd(plotwin->RPort,JAM1);
  187. }
  188.  
  189.  
  190. /* Shove the plot window to the back */
  191.  
  192. AMIGA_text()
  193. {
  194.   char c;
  195.  
  196.   c = getc(stdin);
  197.   ungetc(c,stdin);
  198.   WindowToBack(plotwin);
  199. }
  200.  
  201. /* Bring the plot window to the front */
  202.  
  203. AMIGA_graphics()
  204. {
  205.   SetRast(plotwin->RPort,0);
  206.  
  207. /* clear the window */
  208.  
  209. SetAPen(plotwin->RPort,clut[0]);
  210. RectFill(plotwin->RPort,0,0,640,400);
  211.  
  212.   SetAPen(plotwin->RPort,clut[1]);
  213.   WindowToFront(plotwin);
  214. }
  215.  
  216. AMIGA_move(x,y)
  217. unsigned int x,y;
  218. {
  219.   Move(plotwin->RPort,x,AMIGA_VTF(y));
  220. }
  221.  
  222. AMIGA_vector(x,y)
  223. unsigned int x,y;
  224. {
  225.   Draw(plotwin->RPort,x,AMIGA_VTF(y));
  226. }
  227.  
  228. AMIGA_linetype(int linetype)
  229. {
  230.   if (linetype >= 0) linetype = (linetype % 9) + 1;
  231.   if (linetype < 0) linetype = 1;
  232.   SetAPen(plotwin->RPort,clut[linetype] );
  233. }
  234.  
  235. AMIGA_put_text(x,y,str)
  236. unsigned int x,y;
  237. char *str;
  238. {
  239.   LONG len,tx_len;
  240.   WORD xmin,xmax,ymin,ymax;
  241.  
  242.   len = strlen(str);
  243.   tx_len = TextLength(plotwin->RPort,str,len);
  244.   switch (AMIGA_justify) {
  245.     case LEFT:
  246.       xmin = x;
  247.       xmax = x + tx_len;
  248.       break;
  249.     case CENTRE:
  250.       xmin = x - tx_len / 2;
  251.       xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  252.       break;
  253.     case RIGHT:
  254.       xmin = x - tx_len;
  255.       xmax = x;
  256.       break;
  257.   }
  258.   ymin = AMIGA_VTF(y) - AMIGA_vadj;
  259.   ymax = ymin + AMIGA_cht;
  260.   /* Check if character-string lies completely within the screen: */
  261.   if ((xmax >= AMIGA_xmax) || (ymin < 0) || (ymax >= AMIGA_ymax)) return;
  262.   Move(plotwin->RPort,xmin,ymin+AMIGA_bsl);
  263.   Text(plotwin->RPort,str,len);
  264. }
  265.  
  266. int AMIGA_justify_text(mode)
  267. enum JUSTIFY mode;
  268. {
  269.   AMIGA_justify = mode;
  270.   return TRUE;
  271. }
  272.