home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / term / amiga.trm < prev    next >
Encoding:
Text File  |  1993-03-02  |  9.6 KB  |  331 lines

  1. /*
  2.  * $Id: amiga.trm 3.38.2.32 1992/12/04 18:32:51 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - amiga.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   Amiga Custom Screen
  26.  *
  27.  * AUTHORS
  28.  *   Carsten Steger
  29.  * 
  30.  *   Pat R. Empleo      Slightly modified for Aztec C v5.2a (beta); sort of
  31.  *   08/27/91           supports overscan; for large WB 2.0 virtual screens,
  32.  *                      we limit the plot size so we don't have to scroll
  33.  *                      around (not fun).
  34.  *
  35.  *   Carsten Steger     Modified to support Kickstart 2.0.
  36.  *   09/11/91           Opens a text overscan screen when used with WB 2.0.
  37.  *                      Discerns between NTSC and PAL Amigas when used with
  38.  *                      WB 1.3 and lower.
  39.  *
  40.  *   Pat R. Empleo      Defined some 2.0 stuff in order to get Aztec C to
  41.  *   09/20/91           work with Carsten's new code (see above).  When
  42.  *                      KS/WB 2.0 support gets implemented in Aztec C, this
  43.  *                      kludge will get deleted! 
  44.  *                      (Aztec C release 5.2 beta)
  45.  *
  46.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  47.  * 
  48.  */
  49.  
  50. #ifdef AMIGA_AC_5
  51. #include <intuition/intuitionbase.h>
  52. #include <intuition/screens.h>
  53. #include <graphics/text.h>
  54. #include <graphics/gfxbase.h>
  55. #else
  56. /* You will have to use the Kickstart 2.0 header files for this to compile */
  57. #include <exec/types.h>
  58. #include <intuition/intuitionbase.h>
  59. #include <graphics/gfxbase.h>
  60. #include <proto/intuition.h>
  61. #include <proto/graphics.h>
  62. #include <proto/exec.h>
  63. #include <proto/diskfont.h>
  64. #endif
  65.  
  66. extern char *getenv(),*strchr();
  67.  
  68. #define AMIGA_XMAX 640
  69. #define AMIGA_YMAX 512
  70.  
  71. #define AMIGA_VCHAR (12)
  72. #define AMIGA_HCHAR (8)
  73. #define AMIGA_VTIC (AMIGA_YMAX/80)
  74. #define AMIGA_HTIC (AMIGA_XMAX/80)
  75. /* The origin is in the upper left hand corner, so we have to translate */
  76. /* and flip the coordinates: */
  77. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  78.  
  79.  
  80. struct IntuitionBase *IntuitionBase;
  81. struct GfxBase *GfxBase;
  82. struct Library *DiskfontBase;
  83. static struct TextAttr AMIGA_Font = {
  84.   "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
  85. };
  86. static struct TextFont *AMIGA_TextFont;
  87. static struct NewScreen AMIGA_NewScreen = {
  88.   0,0,AMIGA_XMAX,AMIGA_YMAX,4,15,0,HIRES|LACE,
  89.   CUSTOMSCREEN|SCREENBEHIND|SCREENQUIET,NULL,NULL,NULL,NULL
  90. };
  91. static struct Screen *AMIGA_Screen;
  92. static UWORD AMIGA_Colors [] = {
  93.   0x000,0xfff,0xbbb,0x0f0,0xf00,0x00f,0x3ca,0xf0f,
  94.   0x94d,0x0ff,0x82f,0xff0,0x0af,0xc5e,0xfa2,0xf44
  95. };
  96. static int AMIGA_slinetype;
  97. static enum JUSTIFY AMIGA_justify = LEFT;
  98. static unsigned int AMIGA_ymax,AMIGA_xmax; 
  99. static WORD AMIGA_cwd,AMIGA_cht,AMIGA_bsl,AMIGA_vadj;
  100. static struct TagItem AMIGA_ScrTagList[] = {
  101.   {SA_Overscan,OSCAN_TEXT},{TAG_DONE,0}
  102. };
  103.  
  104.  
  105. AMIGA_reset()
  106. {
  107.   if (AMIGA_TextFont != NULL) CloseFont(AMIGA_TextFont);
  108.   if (DiskfontBase != NULL) CloseLibrary(DiskfontBase);
  109.   if (AMIGA_Screen != NULL) CloseScreen(AMIGA_Screen);
  110.   if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  111.   if (GfxBase != NULL) CloseLibrary(GfxBase);
  112.   AMIGA_TextFont = NULL;
  113.   DiskfontBase = NULL;
  114.   AMIGA_Screen = NULL;
  115.   IntuitionBase = NULL;
  116.   GfxBase = NULL;
  117. }
  118.  
  119.  
  120. AMIGA_init()
  121. {
  122.   static char fontname[80],*gnufont,*search;
  123.   static int fsize;
  124.   static char *test_str =
  125.     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  126.   static WORD test_len,test_pxl;
  127.  
  128.  
  129. #ifdef AMIGA_SC_6_1
  130.   /* Install exit trap in case of abnormal termination (see below). */
  131.   int AMIGA_exit();
  132.   if (!onexit(&AMIGA_exit)) {
  133.     fprintf(stderr,"Couldn't set exit trap\n");
  134.     exit(20);
  135.   }
  136. #endif
  137.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0);
  138.   if (GfxBase == NULL) {
  139.     fprintf(stderr,"No Graphics-Library\n");
  140.     AMIGA_reset();
  141.     exit(20);
  142.   }
  143.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0);
  144.   if (IntuitionBase == NULL) {
  145.     fprintf(stderr,"No Intuition-Library\n");
  146.     AMIGA_reset();
  147.     exit(20);
  148.   }
  149.   if (IntuitionBase->LibNode.lib_Version <= 34) {
  150.     /* We compute the vertical resolution for those poor NTSC-souls   :-)   */
  151.     if (GfxBase->DisplayFlags & PAL) AMIGA_ymax = 512;
  152.     else AMIGA_ymax = 400;
  153.     AMIGA_xmax = 640;
  154.     AMIGA_NewScreen.Width = AMIGA_xmax;
  155.     AMIGA_NewScreen.Height = AMIGA_ymax;
  156.     AMIGA_Screen = OpenScreen(&AMIGA_NewScreen);
  157.     if (AMIGA_Screen == NULL) {
  158.       fprintf(stderr,"No Screen\n");
  159.       AMIGA_reset();
  160.       exit(20);
  161.     }
  162.   } else {
  163.     /* Kickstart 2.0 support */
  164.     AMIGA_NewScreen.Width = STDSCREENWIDTH;
  165.     AMIGA_NewScreen.Height = STDSCREENHEIGHT;
  166.     AMIGA_Screen = OpenScreenTagList(&AMIGA_NewScreen,AMIGA_ScrTagList);
  167.     if (AMIGA_Screen == NULL) {
  168.       fprintf(stderr,"No Screen\n");
  169.       AMIGA_reset();
  170.       exit(20);
  171.     }
  172.     AMIGA_xmax = AMIGA_Screen->Width;
  173.     AMIGA_ymax = AMIGA_Screen->Height;
  174.   }
  175.   term_tbl[term].xmax = AMIGA_xmax;
  176.   term_tbl[term].ymax = AMIGA_ymax;
  177.   gnufont = getenv("GNUFONT");
  178.   if (gnufont != NULL ) {
  179.     search = strchr(gnufont,'/');
  180.     if (search != NULL) {
  181.       *search++ = '\0';
  182.       strncpy(fontname,gnufont,74);
  183.       strcat(fontname,".font");
  184.       sscanf(search,"%d",&fsize);
  185.       /* Avoid opening "diskfont.library" if a built-in font is desired */
  186.       if ((strcmp("topaz.font",fontname) == 0) &&
  187.         ((fsize == TOPAZ_EIGHTY) || (fsize == TOPAZ_SIXTY))) {
  188.         AMIGA_Font.ta_Name = fontname;
  189.         AMIGA_Font.ta_YSize = fsize;
  190.         AMIGA_Font.ta_Style = FS_NORMAL;
  191.         AMIGA_Font.ta_Flags = FPF_ROMFONT;
  192.         AMIGA_TextFont = OpenFont(&AMIGA_Font);
  193.         if (AMIGA_TextFont != NULL) 
  194.           SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  195.       } else {
  196.         DiskfontBase = OpenLibrary("diskfont.library",0);
  197.         if (DiskfontBase != NULL) {
  198.           AMIGA_Font.ta_Name = fontname;
  199.           AMIGA_Font.ta_YSize = fsize;
  200.           AMIGA_Font.ta_Style = FS_NORMAL;
  201.           AMIGA_Font.ta_Flags = FPF_ROMFONT|FPF_DISKFONT;
  202.           AMIGA_TextFont = OpenDiskFont(&AMIGA_Font);
  203.           if (AMIGA_TextFont != NULL)
  204.             SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  205.         }
  206.       }
  207.     }
  208.   }
  209.   /* Width of characters: This works better for proportional fonts than */
  210.   /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
  211.   test_len = strlen(test_str);
  212.   test_pxl = TextLength(&AMIGA_Screen->RastPort,test_str,test_len);
  213.   AMIGA_cwd = test_pxl / test_len;
  214.   AMIGA_cht = AMIGA_Screen->RastPort.TxHeight; /* Height of characters */
  215.   AMIGA_bsl = AMIGA_Screen->RastPort.TxBaseline; /* Reference line */
  216.   /* Amount by which characters have to be shifted upwards to be */
  217.   /* vertically justified: */
  218.   AMIGA_vadj = AMIGA_bsl / 2;
  219.   term_tbl[term].v_char = AMIGA_cht + 4; /* So lines won't be too close */
  220.   term_tbl[term].h_char = AMIGA_cwd;
  221.   LoadRGB4(&AMIGA_Screen->ViewPort,AMIGA_Colors,16);
  222.   RemakeDisplay();
  223.   AMIGA_slinetype = 1;
  224.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  225.   SetDrMd(&AMIGA_Screen->RastPort,JAM1);
  226. }
  227.  
  228.  
  229. AMIGA_text()
  230. {
  231.   char c;
  232.   FILE *console;
  233.  
  234.   console = fopen("*","r");
  235.   if (console != NULL) {
  236.     /* Wait for return from the console window */
  237.     c = getc(console); /* This is extremely ugly... Yuk !!!!   >:-(   */
  238.     ungetc(c,stdin); /* Maybe someone else will find a better solution */
  239.     fclose(console);
  240.   }
  241.   ScreenToBack(AMIGA_Screen);
  242. }
  243.  
  244.  
  245. AMIGA_graphics()
  246. {
  247.   SetRast(&AMIGA_Screen->RastPort,0);
  248.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  249.   ScreenToFront(AMIGA_Screen);
  250. }
  251.  
  252.  
  253. AMIGA_move(x,y)
  254. unsigned int x,y;
  255. {
  256.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  257.   Move(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  258. }
  259.  
  260.  
  261. AMIGA_vector(x,y)
  262. unsigned int x,y;
  263. {
  264.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  265.   Draw(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  266. }
  267.  
  268.  
  269. AMIGA_linetype(linetype)
  270. int linetype;
  271. {
  272.   if (linetype >= 13) linetype %= 13;
  273.   if (linetype < -2) linetype = -2;
  274.   AMIGA_slinetype = linetype+3;
  275.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  276. }
  277.  
  278.  
  279. AMIGA_put_text(x,y,str)
  280. unsigned int x,y;
  281. char *str;
  282. {
  283.   LONG len,tx_len;
  284.   WORD xmin,xmax,ymin,ymax;
  285.  
  286.   len = strlen(str);
  287.   tx_len = TextLength(&AMIGA_Screen->RastPort,str,len);
  288.   switch (AMIGA_justify) {
  289.     case LEFT:
  290.       xmin = x;
  291.       xmax = x + tx_len;
  292.       break;
  293.     case CENTRE:
  294.       xmin = x - tx_len / 2;
  295.       xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  296.       break;
  297.     case RIGHT:
  298.       xmin = x - tx_len;
  299.       xmax = x;
  300.       break;
  301.   }
  302.   ymin = AMIGA_VTF(y) - AMIGA_vadj;
  303.   ymax = ymin + AMIGA_cht;
  304.   /* Check if character-string lies completely within the screen: */
  305.   if ((xmax >= AMIGA_xmax) || (ymin < 0) || (ymax >= AMIGA_ymax)) return;
  306.   Move(&AMIGA_Screen->RastPort,xmin,ymin+AMIGA_bsl);
  307.   Text(&AMIGA_Screen->RastPort,str,len);
  308. }
  309.  
  310.  
  311. int AMIGA_justify_text(mode)
  312. enum JUSTIFY mode;
  313. {
  314.   AMIGA_justify = mode;
  315.   return TRUE;
  316. }
  317.  
  318.  
  319. /* This function is mainly included if the program terminates abnormally */
  320. /* and the screen and libraries are still open. It closes down all opened */
  321. /* libraries and screens. This happens e.g. when loading "bivariat.demo" */
  322. /* and the stack is smaller than 120000 bytes. */
  323. #ifdef AMIGA_SC_6_1
  324. int AMIGA_exit(rc)
  325. int rc;
  326. {
  327.   AMIGA_reset();
  328.   return rc;
  329. }
  330. #endif
  331.