home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / plotting / gnuplot3.lzh / gnuplot / term / amiga.trm < prev    next >
Encoding:
Text File  |  1991-10-08  |  10.7 KB  |  343 lines

  1. /* GNUPLOT - amiga.trm */
  2. /*
  3.  * Copyright (C) 1991
  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 Custom Screen
  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.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  42.  * 
  43.  */
  44.  
  45. #ifdef AMIGA_AC_5
  46. #include <intuition/intuitionbase.h>
  47. #include <intuition/screens.h>
  48. #include <graphics/text.h>
  49. #include <graphics/gfxbase.h>
  50.  
  51. #define OSCAN_TEXT     (1)                   /*                            */
  52. #define SA_Dummy       (TAG_USER + 32)       /* This stuff is temporary    */
  53. #define SA_Overscan    (SA_Dummy + 0x0014)   /* until Aztec C implements   */
  54. #define STDSCREENWIDTH -1                    /* KS/WB 2.0 support.         */
  55. #define TAG_DONE       (0L)                  /*                            */
  56. #define TAG_USER       (1L<<31)              /*                            */
  57.                                              /*                            */
  58. typedef ULONG Tag;                           /*                            */
  59.                                              /*                            */
  60. struct TagItem                               /*                            */
  61.    {                                         /*                            */
  62.    Tag   ti_Tag;                             /*                            */
  63.    ULONG ti_Data;                            /*                            */
  64.    };                                        /*                            */
  65.  
  66. #else
  67. /* You will have to use the Kickstart 2.0 header files for this to compile */
  68. #include <exec/types.h>
  69. #include <intuition/intuitionbase.h>
  70. #include <graphics/gfxbase.h>
  71. #include <proto/intuition.h>
  72. #include <proto/graphics.h>
  73. #include <proto/exec.h>
  74. #include <proto/diskfont.h>
  75. #endif
  76.  
  77. extern char *getenv(),*strchr();
  78.  
  79. #define AMIGA_XMAX 640
  80. #define AMIGA_YMAX 512
  81.  
  82. #define AMIGA_VCHAR (12)
  83. #define AMIGA_HCHAR (8)
  84. #define AMIGA_VTIC (AMIGA_YMAX/80)
  85. #define AMIGA_HTIC (AMIGA_XMAX/80)
  86. /* The origin is in the upper left hand corner, so we have to translate */
  87. /* and flip the coordinates: */
  88. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  89.  
  90.  
  91. struct IntuitionBase *IntuitionBase;
  92. struct GfxBase *GfxBase;
  93. struct Library *DiskfontBase;
  94. static struct TextAttr AMIGA_Font = {
  95.   "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
  96. };
  97. static struct TextFont *AMIGA_TextFont;
  98. static struct NewScreen AMIGA_NewScreen = {
  99.   0,0,AMIGA_XMAX,AMIGA_YMAX,4,15,0,HIRES|LACE,
  100.   CUSTOMSCREEN|SCREENBEHIND|SCREENQUIET,NULL,NULL,NULL,NULL
  101. };
  102. static struct Screen *AMIGA_Screen;
  103. static UWORD AMIGA_Colors [] = {
  104.   0x000,0xfff,0xbbb,0x0f0,0xf00,0x00f,0x3ca,0xf0f,
  105.   0x94d,0x0ff,0x82f,0xff0,0x0af,0xc5e,0xfa2,0xf44
  106. };
  107. static int AMIGA_slinetype;
  108. static enum JUSTIFY AMIGA_justify = LEFT;
  109. static unsigned int AMIGA_ymax,AMIGA_xmax; 
  110. static WORD AMIGA_cwd,AMIGA_cht,AMIGA_bsl,AMIGA_vadj;
  111. static struct TagItem AMIGA_ScrTagList[] = {
  112.   {SA_Overscan,OSCAN_TEXT},{TAG_DONE,0}
  113. };
  114.  
  115.  
  116. AMIGA_reset()
  117. {
  118.   if (AMIGA_TextFont != NULL) CloseFont(AMIGA_TextFont);
  119.   if (DiskfontBase != NULL) CloseLibrary(DiskfontBase);
  120.   if (AMIGA_Screen != NULL) CloseScreen(AMIGA_Screen);
  121.   if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  122.   if (GfxBase != NULL) CloseLibrary(GfxBase);
  123.   AMIGA_TextFont = NULL;
  124.   DiskfontBase = NULL;
  125.   AMIGA_Screen = NULL;
  126.   IntuitionBase = NULL;
  127.   GfxBase = NULL;
  128. }
  129.  
  130.  
  131. AMIGA_init()
  132. {
  133.   static char fontname[80],*gnufont,*search;
  134.   static int fsize;
  135.   static char *test_str =
  136.     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  137.   static WORD test_len,test_pxl;
  138.  
  139.  
  140. #ifdef AMIGA_LC_5_1
  141.   /* Install exit trap in case of abnormal termination (see below). */
  142.   int AMIGA_exit();
  143.   if (!onexit(&AMIGA_exit)) {
  144.     fprintf(stderr,"Couldn't set exit trap\n");
  145.     exit(20);
  146.   }
  147. #endif
  148.   GfxBase = OpenLibrary("graphics.library",0);
  149.   if (GfxBase == NULL) {
  150.     fprintf(stderr,"No Graphics-Library\n");
  151.     AMIGA_reset();
  152.     exit(20);
  153.   }
  154.   IntuitionBase = OpenLibrary("intuition.library",0);
  155.   if (IntuitionBase == NULL) {
  156.     fprintf(stderr,"No Intuition-Library\n");
  157.     AMIGA_reset();
  158.     exit(20);
  159.   }
  160.   if (IntuitionBase->LibNode.lib_Version <= 34) {
  161.     /* We compute the vertical resolution for those poor NTSC-souls   :-)   */
  162.     if (GfxBase->DisplayFlags && PAL) AMIGA_ymax = 512;
  163.     else AMIGA_ymax = 400;
  164.     AMIGA_xmax = 640;
  165.     AMIGA_NewScreen.Width = AMIGA_xmax;
  166.     AMIGA_NewScreen.Height = AMIGA_ymax;
  167.     AMIGA_Screen = OpenScreen(&AMIGA_NewScreen);
  168.     if (AMIGA_Screen == NULL) {
  169.       fprintf(stderr,"No Screen\n");
  170.       AMIGA_reset();
  171.       exit(20);
  172.     }
  173.   } else {
  174.     /* Kickstart 2.0 support */
  175.     AMIGA_NewScreen.Width = STDSCREENWIDTH;
  176.     AMIGA_NewScreen.Height = STDSCREENHEIGHT;
  177.     /* I had to set TopEdge equal to 1 with my (probably outdated) software */
  178.     /* version of Kickstart 2.0 in order for the last line to be displayed */
  179.     /* correctly. Remove the next two lines and check if it still works */
  180.     /* with newer ROM-versions of Kickstart 2.0 */
  181. #ifdef AMIGA_LC_5_1
  182.     AMIGA_NewScreen.TopEdge = 1;
  183.     AMIGA_NewScreen.LeftEdge = 0;
  184. #endif
  185.     AMIGA_Screen = OpenScreenTagList(&AMIGA_NewScreen,AMIGA_ScrTagList);
  186.     if (AMIGA_Screen == NULL) {
  187.       fprintf(stderr,"No Screen\n");
  188.       AMIGA_reset();
  189.       exit(20);
  190.     }
  191.     AMIGA_xmax = AMIGA_Screen->Width;
  192.     AMIGA_ymax = AMIGA_Screen->Height;
  193.   }
  194.   term_tbl[term].xmax = AMIGA_xmax;
  195.   term_tbl[term].ymax = AMIGA_ymax;
  196.   gnufont = getenv("GNUFONT");
  197.   if (gnufont != NULL ) {
  198.     search = strchr(gnufont,'/');
  199.     if (search != NULL) {
  200.       *search++ = '\0';
  201.       strncpy(fontname,gnufont,74);
  202.       strcat(fontname,".font");
  203.       sscanf(search,"%d",&fsize);
  204.       /* Avoid opening "diskfont.library" if a built-in font is desired */
  205.       if ((strcmp("topaz.font",fontname) == 0) &&
  206.         ((fsize == TOPAZ_EIGHTY) || (fsize == TOPAZ_SIXTY))) {
  207.         AMIGA_Font.ta_Name = fontname;
  208.         AMIGA_Font.ta_YSize = fsize;
  209.         AMIGA_Font.ta_Style = FS_NORMAL;
  210.         AMIGA_Font.ta_Flags = FPF_ROMFONT;
  211.         AMIGA_TextFont = OpenFont(&AMIGA_Font);
  212.         if (AMIGA_TextFont != NULL) 
  213.           SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  214.       } else {
  215.         DiskfontBase = OpenLibrary("diskfont.library",0);
  216.         if (DiskfontBase != NULL) {
  217.           AMIGA_Font.ta_Name = fontname;
  218.           AMIGA_Font.ta_YSize = fsize;
  219.           AMIGA_Font.ta_Style = FS_NORMAL;
  220.           AMIGA_Font.ta_Flags = FPF_ROMFONT|FPF_DISKFONT;
  221.           AMIGA_TextFont = OpenDiskFont(&AMIGA_Font);
  222.           if (AMIGA_TextFont != NULL)
  223.             SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  224.         }
  225.       }
  226.     }
  227.   }
  228.   /* Width of characters: This works better for proportional fonts than */
  229.   /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
  230.   test_len = strlen(test_str);
  231.   test_pxl = TextLength(&AMIGA_Screen->RastPort,test_str,test_len);
  232.   AMIGA_cwd = test_pxl / test_len;
  233.   AMIGA_cht = AMIGA_Screen->RastPort.TxHeight; /* Height of characters */
  234.   AMIGA_bsl = AMIGA_Screen->RastPort.TxBaseline; /* Reference line */
  235.   /* Amount by which characters have to be shifted upwards to be */
  236.   /* vertically justified: */
  237.   AMIGA_vadj = AMIGA_bsl / 2;
  238.   term_tbl[term].v_char = AMIGA_cht + 4; /* So lines won't be too close */
  239.   term_tbl[term].h_char = AMIGA_cwd;
  240.   LoadRGB4(&AMIGA_Screen->ViewPort,AMIGA_Colors,16);
  241.   RemakeDisplay();
  242.   AMIGA_slinetype = 1;
  243.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  244.   SetDrMd(&AMIGA_Screen->RastPort,JAM1);
  245. }
  246.  
  247.  
  248. AMIGA_text()
  249. {
  250.   char c;
  251.  
  252.   c = getc(stdin); /* This is extremely ugly... Yuk !!!!   >:-(   */
  253.   ungetc(c,stdin); /* Maybe someone else will find a better solution */
  254.   ScreenToBack(AMIGA_Screen);
  255. }
  256.  
  257.  
  258. AMIGA_graphics()
  259. {
  260.   SetRast(&AMIGA_Screen->RastPort,0);
  261.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  262.   ScreenToFront(AMIGA_Screen);
  263. }
  264.  
  265.  
  266. AMIGA_move(x,y)
  267. unsigned int x,y;
  268. {
  269.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  270.   Move(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  271. }
  272.  
  273.  
  274. AMIGA_vector(x,y)
  275. unsigned int x,y;
  276. {
  277.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  278.   Draw(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  279. }
  280.  
  281.  
  282. AMIGA_linetype(linetype)
  283. int linetype;
  284. {
  285.   if (linetype >= 13) linetype %= 13;
  286.   AMIGA_slinetype = linetype+3;
  287.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  288. }
  289.  
  290.  
  291. AMIGA_put_text(x,y,str)
  292. unsigned int x,y;
  293. char *str;
  294. {
  295.   LONG len,tx_len;
  296.   WORD xmin,xmax,ymin,ymax;
  297.  
  298.   len = strlen(str);
  299.   tx_len = TextLength(&AMIGA_Screen->RastPort,str,len);
  300.   switch (AMIGA_justify) {
  301.     case LEFT:
  302.       xmin = x;
  303.       xmax = x + tx_len;
  304.       break;
  305.     case CENTRE:
  306.       xmin = x - tx_len / 2;
  307.       xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  308.       break;
  309.     case RIGHT:
  310.       xmin = x - tx_len;
  311.       xmax = x;
  312.       break;
  313.   }
  314.   ymin = AMIGA_VTF(y) - AMIGA_vadj;
  315.   ymax = ymin + AMIGA_cht;
  316.   /* Check if character-string lies completely within the screen: */
  317.   if ((xmax >= AMIGA_xmax) || (ymin < 0) || (ymax >= AMIGA_ymax)) return;
  318.   Move(&AMIGA_Screen->RastPort,xmin,ymin+AMIGA_bsl);
  319.   Text(&AMIGA_Screen->RastPort,str,len);
  320. }
  321.  
  322.  
  323. int AMIGA_justify_text(mode)
  324. enum JUSTIFY mode;
  325. {
  326.   AMIGA_justify = mode;
  327.   return TRUE;
  328. }
  329.  
  330.  
  331. /* This function is mainly included if the program terminates abnormally */
  332. /* and the screen and libraries are still open. It closes down all opened */
  333. /* libraries and screens. This happens e.g. when loading "bivariat.demo" */
  334. /* and the stack is smaller than 70000 bytes. */
  335. #ifdef AMIGA_LC_5_1
  336. int AMIGA_exit(rc)
  337. int rc;
  338. {
  339.   AMIGA_reset();
  340.   return rc;
  341. }
  342. #endif
  343.