[BACK]Return to amiga.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/amiga.trm, Revision 1.1.1.1

1.1       maekawa     1: /*
                      2:  * $Id: amiga.trm,v 1.18 1998/04/14 00:17:29 drd Exp $
                      3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - amiga.trm */
                      7:
                      8: /*[
                      9:  * Copyright 1991, 1992, 1993, 1998
                     10:  *
                     11:  * Permission to use, copy, and distribute this software and its
                     12:  * documentation for any purpose with or without fee is hereby granted,
                     13:  * provided that the above copyright notice appear in all copies and
                     14:  * that both that copyright notice and this permission notice appear
                     15:  * in supporting documentation.
                     16:  *
                     17:  * Permission to modify the software is granted, but not the right to
                     18:  * distribute the complete modified source code.  Modifications are to
                     19:  * be distributed as patches to the released version.  Permission to
                     20:  * distribute binaries produced by compiling modified sources is granted,
                     21:  * provided you
                     22:  *   1. distribute the corresponding source modifications from the
                     23:  *    released version in the form of a patch file along with the binaries,
                     24:  *   2. add special version identification to distinguish your version
                     25:  *    in addition to the base release version number,
                     26:  *   3. provide your name and address as the primary contact for the
                     27:  *    support of your modified version, and
                     28:  *   4. retain our contact information in regard to use of the base
                     29:  *    software.
                     30:  * Permission to distribute the released version of the source code along
                     31:  * with corresponding source modifications in the form of a patch file is
                     32:  * granted with same provisions 2 through 4 for binary distributions.
                     33:  *
                     34:  * This software is provided "as is" without express or implied warranty
                     35:  * to the extent permitted by applicable law.
                     36: ]*/
                     37:
                     38: /*
                     39:  * This file is included by ../term.c.
                     40:  *
                     41:  * This terminal driver supports:
                     42:  *   Amiga Custom Screen
                     43:  *
                     44:  * AUTHORS
                     45:  *   Carsten Steger
                     46:  *
                     47:  *   Pat R. Empleo      Slightly modified for Aztec C v5.2a (beta); sort of
                     48:  *   08/27/91           supports overscan; for large WB 2.0 virtual screens,
                     49:  *                      we limit the plot size so we don't have to scroll
                     50:  *                      around (not fun).
                     51:  *
                     52:  *   Carsten Steger     Modified to support Kickstart 2.0.
                     53:  *   09/11/91           Opens a text overscan screen when used with WB 2.0.
                     54:  *                      Discerns between NTSC and PAL Amigas when used with
                     55:  *                      WB 1.3 and lower.
                     56:  *
                     57:  *   Pat R. Empleo      Defined some 2.0 stuff in order to get Aztec C to
                     58:  *   09/20/91           work with Carsten's new code (see above).  When
                     59:  *                      KS/WB 2.0 support gets implemented in Aztec C, this
                     60:  *                      kludge will get deleted!
                     61:  *                      (Aztec C release 5.2 beta)
                     62:  *
                     63:  *   Carsten Steger     Converted to new terminal layout.
                     64:  *   10/01/95
                     65:  *
                     66:  *   Lars Hecking      Add code from George Coulouris <glc5@cornell.edu> to
                     67:  *   06/20/97          implement window option, requires AmigaOS 3.0+.
                     68:  *                     General cleanup, better readability.
                     69:  *
                     70:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
                     71:  *
                     72:  */
                     73:
                     74: #include "driver.h"
                     75:
                     76: #ifdef TERM_REGISTER
                     77: register_term(amiga)
                     78: #endif
                     79:
                     80: #ifdef TERM_PROTO
                     81:
                     82: #define AMIGA_XMAX 640
                     83: #define AMIGA_YMAX 512
                     84:
                     85: #define AMIGA_VCHAR 12
                     86: #define AMIGA_HCHAR 8
                     87: #define AMIGA_VTIC  5
                     88: #define AMIGA_HTIC  5
                     89:
                     90: TERM_PUBLIC void AMIGA_reset __PROTO((void));
                     91: TERM_PUBLIC void AMIGA_init __PROTO((void));
                     92: TERM_PUBLIC void AMIGA_options __PROTO((void));
                     93: TERM_PUBLIC void AMIGA_text __PROTO((void));
                     94: TERM_PUBLIC void AMIGA_graphics __PROTO((void));
                     95: TERM_PUBLIC void AMIGA_move __PROTO((unsigned int x, unsigned int y));
                     96: TERM_PUBLIC void AMIGA_vector __PROTO((unsigned int x, unsigned int y));
                     97: TERM_PUBLIC void AMIGA_linetype __PROTO((int linetype));
                     98: TERM_PUBLIC void AMIGA_put_text __PROTO((unsigned int x, unsigned int y, char *str));
                     99: TERM_PUBLIC int AMIGA_justify_text __PROTO((enum JUSTIFY mode));
                    100: TERM_PUBLIC int AMIGA_set_font __PROTO((char *font));
                    101: TERM_PUBLIC void AMIGA_suspend __PROTO((void));
                    102: TERM_PUBLIC void AMIGA_resume __PROTO((void));
                    103:
                    104: #define GOT_AMIGA_PROTO
                    105:
                    106: #endif /* TERM_PROTO */
                    107:
                    108:
                    109: #ifndef TERM_PROTO_ONLY
                    110:
                    111: #ifdef TERM_BODY
                    112:
                    113: #ifdef AMIGA_AC_5
                    114: #include <intuition/intuitionbase.h>
                    115: #include <intuition/screens.h>
                    116: #include <graphics/text.h>
                    117: #include <graphics/gfxbase.h>
                    118: #else
                    119: /* You will have to use the Kickstart 2.0 header files for this to compile */
                    120: #include <exec/types.h>
                    121: #include <dos/dos.h>
                    122: #include <intuition/intuitionbase.h>
                    123: #include <graphics/gfxbase.h>
                    124: #include <proto/intuition.h>
                    125: #include <proto/graphics.h>
                    126: #include <proto/exec.h>
                    127: #include <proto/diskfont.h>
                    128: #endif /* !AMIGA_AC_5 */
                    129:
                    130: #ifndef NO_ATEXIT
                    131: void AMIGA_exit(void);
                    132: # define ATEXIT(x) (atexit(x) != 0)
                    133: # ifdef AMIGA_SC_6_1
                    134: /* #  define ATEXIT(x) (onexit(x) == 0) */
                    135: #  define RAWCON(x) rawcon(x)
                    136: # else
                    137: #  define RAWCON(x)            /* nought */
                    138: # endif                                /* SAS */
                    139: #else
                    140: # define ATEXIT(x) 0
                    141: #endif /* NO_ATEXIT */
                    142:
                    143: #ifndef RETURN_FAIL
                    144: # define RETURN_FAIL 20
                    145: #endif
                    146:
                    147: #define LIB_VERSION(LibBase)    ((LibBase)->LibNode.lib_Version)
                    148:
                    149: #define AMIGA_ERROR(string,rc)  {fprintf (stderr,"%s\n",string);\
                    150:                                 AMIGA_reset (); exit (rc);}
                    151:
                    152: /* from plot.c */
                    153: extern TBOOLEAN interactive;
                    154:
                    155: /* The origin is in the upper left hand corner, so we have to translate */
                    156: /* and flip the coordinates: */
                    157: #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
                    158:
                    159:
                    160: /* Libraries */
                    161: struct IntuitionBase *IntuitionBase;
                    162: struct GfxBase *GfxBase;
                    163: struct Library *DiskfontBase;
                    164:
                    165:
                    166: /* Name of font, size in pts */
                    167: static char AMIGA_FontName[MAX_ID_LEN+1] = "";
                    168: static int AMIGA_FontSize;
                    169:
                    170:
                    171: /* Font stuff */
                    172: static struct TextAttr AMIGA_Font =
                    173: {
                    174:     "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT
                    175: };
                    176: static struct TextFont *AMIGA_TextFont;
                    177:
                    178:
                    179: /* Screen stuff */
                    180: static struct NewScreen AMIGA_NewScreen =
                    181: {
                    182:     0, 0, AMIGA_XMAX, AMIGA_YMAX, 4, 15, 0, HIRES | LACE,
                    183:     CUSTOMSCREEN | SCREENBEHIND | SCREENQUIET, NULL, NULL, NULL, NULL
                    184: };
                    185: static struct Screen *AMIGA_Screen;
                    186: static struct TagItem AMIGA_ScrTagList[] =
                    187: {
                    188:     { SA_Overscan, OSCAN_TEXT },
                    189:     { TAG_DONE, 0 }
                    190: };
                    191:
                    192:
                    193: /* Window stuff */
                    194: /* FALSE: plot to screen; TRUE: plot to window */
                    195: static TBOOLEAN AMIGA_window_mode = FALSE;
                    196:
                    197: #define AMIGA_WIN_XMAX 512
                    198: #define AMIGA_WIN_YMAX 320
                    199:
                    200: static struct Window *AMIGA_Window;
                    201: static struct TagItem AMIGA_WinTagList[] =
                    202: {
                    203:     { WA_InnerWidth, AMIGA_WIN_XMAX },
                    204:     { WA_InnerHeight, AMIGA_WIN_YMAX },
                    205:     { WA_Title, (ULONG) "gnuplot" },
                    206:     { WA_DragBar, TRUE },
                    207:     { WA_DepthGadget, TRUE },
                    208:     { WA_WBenchWindow, TRUE },
                    209:     { WA_SmartRefresh, TRUE },
                    210:     { WA_GimmeZeroZero, TRUE },
                    211:     { WA_AutoAdjust, TRUE },
                    212:     { TAG_DONE, 0 }
                    213: };
                    214:
                    215: /*
                    216:  * This  is the palette.  Values are stored as 0xrrggbb, where rr, gg, and, bb
                    217:  * are big-endian 8-bit intensities for red, green, and blue, respectively.
                    218:  */
                    219: static unsigned int palette[] =
                    220: {
                    221:     0xffffff,                  /* white */
                    222:     0x000000,                  /* black */
                    223:     0xff0000,                  /* red */
                    224:     0x00ff00,                  /* green */
                    225:     0x0000ff,                  /* blue */
                    226:     0x00ffff,                  /* cyan */
                    227:     0xff00ff,                  /* magenta */
                    228:     0xffff00,                  /* yellow */
                    229:     0x7f007f,                  /* purple */
                    230:     0xff7f00,                  /* orange */
                    231: };
                    232:
                    233: #define PALETTE_SIZE (sizeof (palette) / sizeof (unsigned int))
                    234:
                    235: /* This is the color look-up table, indexed in the same order as
                    236:  * the above palette. The values stored in this table are pen numbers;
                    237:  * e.g clut[2] is the pen which represents the color "red".
                    238:  */
                    239: static unsigned int clut[PALETTE_SIZE];
                    240:
                    241:
                    242: /* Colors */
                    243: static UWORD AMIGA_Colors[] =
                    244: {
                    245:     0x000, 0xfff, 0xbbb, 0x0f0, 0xf00, 0x00f, 0x3ca, 0xf0f,
                    246:     0x94d, 0x0ff, 0x82f, 0xff0, 0x0af, 0xc5e, 0xfa2, 0xf44
                    247: };
                    248:
                    249:
                    250: /* Misc */
                    251: static int AMIGA_slinetype;
                    252: static enum JUSTIFY AMIGA_justify = LEFT;
                    253: static unsigned int AMIGA_ymax, AMIGA_xmax;
                    254: static WORD AMIGA_cwd, AMIGA_cht, AMIGA_bsl, AMIGA_vadj;
                    255: /* Common RastPort */
                    256: static struct RastPort *AMIGA_RastPort;
                    257:
                    258: /*
                    259:  * Close open font, screen and libraries.
                    260:  */
                    261: TERM_PUBLIC void AMIGA_reset()
                    262: {
                    263:     if (AMIGA_window_mode == TRUE) {
                    264:        int i = 0;
                    265:
                    266:        /* Free the pens */
                    267:        while (i < PALETTE_SIZE) {
                    268:            if (clut[i] != -1)
                    269:                ReleasePen(AMIGA_Window->WScreen->ViewPort.ColorMap, clut[i]);
                    270:
                    271:            i++;
                    272:        }
                    273:
                    274:        /* Close the window */
                    275:        if (AMIGA_Window != NULL)
                    276:            CloseWindow(AMIGA_Window);
                    277:
                    278:        AMIGA_Window = NULL;
                    279:        AMIGA_window_mode = FALSE;
                    280:     }
                    281:     if (AMIGA_TextFont != NULL)
                    282:        CloseFont(AMIGA_TextFont);
                    283:
                    284:     if (DiskfontBase != NULL)
                    285:        CloseLibrary(DiskfontBase);
                    286:
                    287:     if (AMIGA_Screen != NULL)
                    288:        CloseScreen(AMIGA_Screen);
                    289:
                    290:     if (IntuitionBase != NULL)
                    291:        CloseLibrary((struct Library *) IntuitionBase);
                    292:
                    293:     if (GfxBase != NULL)
                    294:        CloseLibrary((struct Library *) GfxBase);
                    295:
                    296:     AMIGA_TextFont = NULL;
                    297:     DiskfontBase = NULL;
                    298:     AMIGA_Screen = NULL;
                    299:     IntuitionBase = NULL;
                    300:     GfxBase = NULL;
                    301:
                    302:     AMIGA_RastPort = NULL;
                    303: }
                    304:
                    305:
                    306: /*
                    307:  * Init terminal.
                    308:  */
                    309: TERM_PUBLIC void AMIGA_init()
                    310: {
                    311:     char name[MAX_ID_LEN + 1];
                    312:
                    313:     /* Install exit trap in case of abnormal termination (see below). */
                    314:     if (ATEXIT(AMIGA_exit))
                    315:        AMIGA_ERROR("Couldn't set exit trap", RETURN_FAIL);
                    316:
                    317:     /* Open needed libraries */
                    318:     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0);
                    319:     if (GfxBase == NULL)
                    320:        AMIGA_ERROR("No Graphics-Library", RETURN_FAIL);
                    321:
                    322:     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
                    323:     if (IntuitionBase == NULL)
                    324:        AMIGA_ERROR("No Intuition-Library", RETURN_FAIL);
                    325:
                    326:     if (AMIGA_window_mode == TRUE) {
                    327:        int i = 0;
                    328:
                    329:        /* Initialize the clut */
                    330:        while (i < PALETTE_SIZE)
                    331:            clut[i++] = -1;
                    332:     }
                    333:     if (LIB_VERSION(IntuitionBase) <= 34) {
                    334:        /* We compute the vertical resolution for those poor NTSC-souls   :-)   */
                    335:        if (GfxBase->DisplayFlags & PAL)
                    336:            AMIGA_ymax = 512;
                    337:        else
                    338:            AMIGA_ymax = 400;
                    339:
                    340:        AMIGA_xmax = 640;
                    341:        AMIGA_NewScreen.Width = AMIGA_xmax;
                    342:        AMIGA_NewScreen.Height = AMIGA_ymax;
                    343:
                    344:        AMIGA_Screen = OpenScreen(&AMIGA_NewScreen);
                    345:
                    346:        if (AMIGA_Screen == NULL)
                    347:            AMIGA_ERROR("No Screen", RETURN_FAIL);
                    348:
                    349:        AMIGA_RastPort = &AMIGA_Screen->RastPort;
                    350:
                    351:     } else {                   /* Intuition version > 34 */
                    352:        /* Kickstart 2.0 support */
                    353:        AMIGA_NewScreen.Width = STDSCREENWIDTH;
                    354:        AMIGA_NewScreen.Height = STDSCREENHEIGHT;
                    355:
                    356:        if (AMIGA_window_mode != TRUE) {
                    357:
                    358:            AMIGA_Screen = OpenScreenTagList(&AMIGA_NewScreen, AMIGA_ScrTagList);
                    359:
                    360:            if (AMIGA_Screen == NULL)
                    361:                AMIGA_ERROR("No Screen", RETURN_FAIL);
                    362:
                    363:            AMIGA_RastPort = &AMIGA_Screen->RastPort;
                    364:
                    365:            AMIGA_xmax = AMIGA_Screen->Width;
                    366:            AMIGA_ymax = AMIGA_Screen->Height;
                    367:        } else if (LIB_VERSION(GfxBase) >= 39) { /* AMIGA_window_mode == TRUE */
                    368:            /* Open the plot window */
                    369:
                    370:            AMIGA_Window = (struct Window *)OpenWindowTagList(NULL, AMIGA_WinTagList);
                    371:
                    372:            /* Don't do this: fall back to screen */
                    373:            if (AMIGA_Window == NULL)
                    374:                AMIGA_ERROR("Could not open plot window", RETURN_FAIL);
                    375:
                    376:            AMIGA_RastPort = AMIGA_Window->RPort;
                    377:
                    378:            AMIGA_xmax = AMIGA_WIN_XMAX;
                    379:            AMIGA_ymax = AMIGA_WIN_YMAX;
                    380:
                    381:        }                       /* Gfx version >= 39 */
                    382:     }                          /* Intuition version <= 34 */
                    383:
                    384:     term->xmax = AMIGA_xmax;
                    385:     term->ymax = AMIGA_ymax;
                    386:
                    387:     if (AMIGA_window_mode != TRUE) {
                    388:        sprintf(name, "%s,%d", AMIGA_FontName, AMIGA_FontSize);
                    389:        AMIGA_set_font(name);
                    390:
                    391:        LoadRGB4(&AMIGA_Screen->ViewPort, AMIGA_Colors, 16);
                    392:        RemakeDisplay();
                    393:        AMIGA_slinetype = 1;
                    394:        SetAPen(&AMIGA_Screen->RastPort, AMIGA_slinetype);
                    395:     } else {
                    396:        int i, r, g, b;
                    397:
                    398:        AMIGA_bsl = AMIGA_Window->RPort->TxBaseline;    /* Reference line */
                    399:        AMIGA_cht = AMIGA_Window->RPort->TxHeight;      /* Height of characters */
                    400:
                    401:        /* Allocate pens */
                    402:        for (i = 0; i < PALETTE_SIZE; i++) {
                    403:            r = (palette[i] << 8) & 0xFF000000;
                    404:            g = (palette[i] << 16) & 0xFF000000;
                    405:            b = (palette[i] << 24) & 0xFF000000;
                    406:            clut[i] = ObtainBestPenA(AMIGA_Window->WScreen->ViewPort.ColorMap, r, g, b, NULL);
                    407:        }
                    408:
                    409:     }
                    410:
                    411:     SetDrMd(AMIGA_RastPort, JAM1);
                    412:
                    413: }
                    414:
                    415:
                    416: /*
                    417:  * Scan terminal options
                    418:  */
                    419: TERM_PUBLIC void AMIGA_options()
                    420: {
                    421:
                    422:     /* Screen/Window mode */
                    423:     if (!END_OF_COMMAND) {
                    424:        if (almost_equals(c_token, "scr$een")) {
                    425:            AMIGA_window_mode = FALSE;
                    426:            c_token++;
                    427:        } else if (almost_equals(c_token, "win$dow")) {
                    428:            AMIGA_window_mode = TRUE;
                    429:            c_token++;
                    430:        }
                    431:     }
                    432:     /* Font name */
                    433:     if (!END_OF_COMMAND && isstring(c_token)) {
                    434:        quote_str(AMIGA_FontName, c_token, MAX_ID_LEN);
                    435:        c_token++;
                    436:     }
                    437:     /* Font size */
                    438:     if (!END_OF_COMMAND) {
                    439:        /* We have font size specified */
                    440:        struct value a;
                    441:        AMIGA_FontSize = (int) real(const_express(&a));
                    442:     }
                    443:     if (strcmp(AMIGA_FontName, "") == 0 && AMIGA_FontSize != 0)
                    444:        strcpy(AMIGA_FontName, "topaz");
                    445:
                    446:     if (strcmp(AMIGA_FontName, "") != 0 && AMIGA_FontSize == 0)
                    447:        AMIGA_FontSize = 8;
                    448:
                    449:     if (strcmp(AMIGA_FontName, "") != 0 && AMIGA_FontSize != 0) {
                    450:        sprintf(default_font, "%s,%d", AMIGA_FontName, AMIGA_FontSize);
                    451:        sprintf(term_options, "%s \"%s\" %d", \
                    452:                (AMIGA_window_mode != TRUE ? "screen" : "window"), \
                    453:                AMIGA_FontName, AMIGA_FontSize);
                    454:     } else
                    455:        sprintf(term_options, "%s", (AMIGA_window_mode != TRUE ? "screen" : "window"));
                    456: }
                    457:
                    458:
                    459: /*
                    460:  *
                    461:  */
                    462: TERM_PUBLIC void AMIGA_text()
                    463: {
                    464:     if (AMIGA_window_mode != TRUE) {
                    465:        if (interactive == TRUE) {
                    466:            FILE *fp;
                    467:
                    468:            if ((fp = fopen("*", "r")) != NULL) {
                    469:                int c = getc(fp);
                    470:
                    471:                ungetc(c, stdin);
                    472:                fclose(fp);
                    473:            }
                    474:            ScreenToBack(AMIGA_Screen);
                    475:        }
                    476:     }
                    477: }
                    478:
                    479:
                    480: /*
                    481:  *
                    482:  */
                    483: TERM_PUBLIC void AMIGA_graphics()
                    484: {
                    485:
                    486:     SetRast(AMIGA_RastPort, 0);
                    487:
                    488:     if (AMIGA_window_mode == TRUE) {
                    489:        /* clear the window */
                    490:        SetAPen(AMIGA_Window->RPort, clut[0]);
                    491:        RectFill(AMIGA_Window->RPort, 0, 0, 640, 400);
                    492:        AMIGA_slinetype = clut[1];
                    493:     }
                    494:     SetAPen(AMIGA_RastPort, AMIGA_slinetype);
                    495:     AMIGA_resume();
                    496: }
                    497:
                    498:
                    499: /*
                    500:  *
                    501:  */
                    502: TERM_PUBLIC void AMIGA_move(x, y)
                    503: unsigned int x, y;
                    504: {
                    505:     if ((x >= AMIGA_xmax) || (y >= AMIGA_ymax))
                    506:        return;
                    507:
                    508:     Move(AMIGA_RastPort, x, AMIGA_VTF(y));
                    509: }
                    510:
                    511:
                    512: /*
                    513:  *
                    514:  */
                    515: TERM_PUBLIC void AMIGA_vector(x, y)
                    516: unsigned int x, y;
                    517: {
                    518:     if ((x >= AMIGA_xmax) || (y >= AMIGA_ymax))
                    519:        return;
                    520:
                    521:     Draw(AMIGA_RastPort, x, AMIGA_VTF(y));
                    522: }
                    523:
                    524:
                    525: /*
                    526:  *
                    527:  */
                    528: TERM_PUBLIC void AMIGA_linetype(linetype)
                    529: int linetype;
                    530: {
                    531:     if (AMIGA_window_mode != TRUE) {
                    532:        if (linetype >= 13)
                    533:            linetype %= 13;
                    534:
                    535:        if (linetype < -2)
                    536:            linetype = -2;
                    537:
                    538:        AMIGA_slinetype = linetype + 3;
                    539:     } else {
                    540:        if (linetype >= 0)
                    541:            linetype = (linetype % 9) + 1;
                    542:
                    543:        if (linetype < 0)
                    544:            linetype = 1;
                    545:
                    546:        AMIGA_slinetype = clut[linetype];
                    547:     }
                    548:     SetAPen(AMIGA_RastPort, AMIGA_slinetype);
                    549: }
                    550:
                    551:
                    552: /*
                    553:  *
                    554:  */
                    555: TERM_PUBLIC void AMIGA_put_text(x, y, str)
                    556: unsigned int x, y;
                    557: char *str;
                    558: {
                    559:     LONG len, tx_len;
                    560:     WORD x_min, x_max, y_min, y_max;
                    561:
                    562:     len = strlen(str);
                    563:
                    564:     tx_len = TextLength(AMIGA_RastPort, str, len);
                    565:
                    566:     switch (AMIGA_justify) {
                    567:     case LEFT:
                    568:        x_min = x;
                    569:        x_max = x + tx_len;
                    570:        break;
                    571:     case CENTRE:
                    572:        x_min = x - tx_len / 2;
                    573:        x_max = x + tx_len - tx_len / 2;        /* avoid roundoff errors ! */
                    574:        break;
                    575:     default:                   /* does this make sense ?? */
                    576:     case RIGHT:
                    577:        x_min = x - tx_len;
                    578:        x_max = x;
                    579:        break;
                    580:     }
                    581:
                    582:     y_min = AMIGA_VTF(y) - AMIGA_vadj;
                    583:     y_max = y_min + AMIGA_cht;
                    584:
                    585:     /* Check if character-string lies completely within the screen: */
                    586:     /* What about clipping? */
                    587:     if ((x_max >= AMIGA_xmax) || (y_min < 0) || (y_max >= AMIGA_ymax))
                    588:        return;
                    589:
                    590:     Move(AMIGA_RastPort, x_min, y_min + AMIGA_bsl);
                    591:     Text(AMIGA_RastPort, str, len);
                    592: }
                    593:
                    594:
                    595: /*
                    596:  *
                    597:  */
                    598: TERM_PUBLIC int AMIGA_justify_text(mode)
                    599: enum JUSTIFY mode;
                    600: {
                    601:     AMIGA_justify = mode;
                    602:     return TRUE;
                    603: }
                    604:
                    605:
                    606: /*
                    607:  *
                    608:  */
                    609: TERM_PUBLIC int AMIGA_set_font(font)
                    610: char *font;
                    611: {
                    612:     static char test_str[] =
                    613:     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
                    614:     static WORD test_len, test_pxl;
                    615:     char name[MAX_ID_LEN+1];
                    616:     int size, sep;
                    617:
                    618:     /* Disable for window mode */
                    619:     if (AMIGA_window_mode != TRUE) {
                    620:        sep = strcspn(font, ",");
                    621:        strncpy(name, font, sep);
                    622:        name[sep] = NUL;
                    623:        size = AMIGA_FontSize;
                    624:        sscanf(&(font[sep + 1]), "%d", &size);
                    625:
                    626:        if (strcmp(name, "") != 0) {
                    627:            strncat(name, ".font", MAX_ID_LEN+1);
                    628:
                    629:            /* Avoid opening "diskfont.library" if a built-in font is desired */
                    630:            if ((strcmp("topaz.font", name) == 0) &&
                    631:                ((size == TOPAZ_EIGHTY) || (size == TOPAZ_SIXTY))) {
                    632:                AMIGA_Font.ta_Name = name;
                    633:                AMIGA_Font.ta_YSize = size;
                    634:                AMIGA_Font.ta_Style = FS_NORMAL;
                    635:                AMIGA_Font.ta_Flags = FPF_ROMFONT;
                    636:                AMIGA_TextFont = OpenFont(&AMIGA_Font);
                    637:
                    638:                if (AMIGA_TextFont != NULL)
                    639:                    SetFont(&AMIGA_Screen->RastPort, AMIGA_TextFont);
                    640:
                    641:            } else {
                    642:                DiskfontBase = OpenLibrary("diskfont.library", 0);
                    643:
                    644:                if (DiskfontBase != NULL) {
                    645:                    AMIGA_Font.ta_Name = name;
                    646:                    AMIGA_Font.ta_YSize = size;
                    647:                    AMIGA_Font.ta_Style = FS_NORMAL;
                    648:                    AMIGA_Font.ta_Flags = FPF_ROMFONT | FPF_DISKFONT;
                    649:                    AMIGA_TextFont = OpenDiskFont(&AMIGA_Font);
                    650:
                    651:                    if (AMIGA_TextFont != NULL)
                    652:                        SetFont(&AMIGA_Screen->RastPort, AMIGA_TextFont);
                    653:                }
                    654:            }
                    655:        }
                    656:        /* Width of characters: This works better for proportional fonts than */
                    657:        /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
                    658:        test_len = strlen(test_str);
                    659:        test_pxl = TextLength(&AMIGA_Screen->RastPort, test_str, test_len);
                    660:
                    661:        AMIGA_cwd = test_pxl / test_len;
                    662:        AMIGA_cht = AMIGA_Screen->RastPort.TxHeight;    /* Height of characters */
                    663:        AMIGA_bsl = AMIGA_Screen->RastPort.TxBaseline;  /* Reference line */
                    664:
                    665:        /* Amount by which characters have to be shifted upwards to be */
                    666:        /* vertically justified: */
                    667:        AMIGA_vadj = AMIGA_bsl / 2;
                    668:        term->v_char = AMIGA_cht + 4;   /* So lines won't be too close */
                    669:        term->h_char = AMIGA_cwd;
                    670:
                    671:     }                          /* !window_mode */
                    672:     return TRUE;
                    673: }
                    674:
                    675:
                    676: /*
                    677:  *
                    678:  */
                    679: TERM_PUBLIC void AMIGA_suspend()
                    680: {
                    681:     if (AMIGA_window_mode != TRUE) {
                    682:        if (interactive == TRUE) {
                    683:            FILE *fp;
                    684:
                    685:            if ((fp = fopen("*", "r")) != NULL) {
                    686:                int c = getc(fp);
                    687:
                    688:                ungetc(c, stdin);
                    689:                fclose(fp);
                    690:            }
                    691:            ScreenToBack(AMIGA_Screen);
                    692:        }
                    693:     }
                    694: }
                    695:
                    696:
                    697: /*
                    698:  *
                    699:  */
                    700: TERM_PUBLIC void AMIGA_resume()
                    701: {
                    702:     if (AMIGA_window_mode != TRUE)
                    703:        ScreenToFront(AMIGA_Screen);
                    704:     else
                    705:        WindowToFront(AMIGA_Window);
                    706: }
                    707:
                    708:
                    709: #ifndef NO_ATEXIT
                    710: /* This function is mainly included if the program terminates abnormally
                    711:  * and the screen and libraries are still open. It closes down all opened
                    712:  * libraries and screens. This happens e.g. when loading "bivariat.demo"
                    713:  * and the stack is smaller than 120000 bytes.
                    714:  */
                    715: void AMIGA_exit(void)
                    716: {
                    717:     AMIGA_reset();
                    718:     RAWCON(0);
                    719: }
                    720:
                    721: #endif /* NO_ATEXIT */
                    722:
                    723:
                    724: #endif /* TERM_BODY */
                    725:
                    726: #ifdef TERM_TABLE
                    727:
                    728: TERM_TABLE_START(amiga_driver)
                    729:     "amiga", "Amiga Custom Screen/Window [screen window]",
                    730:     AMIGA_XMAX, AMIGA_YMAX, AMIGA_VCHAR, AMIGA_HCHAR,
                    731:     AMIGA_VTIC, AMIGA_HTIC, AMIGA_options, AMIGA_init, AMIGA_reset,
                    732:     AMIGA_text, null_scale, AMIGA_graphics, AMIGA_move, AMIGA_vector,
                    733:     AMIGA_linetype, AMIGA_put_text, null_text_angle,
                    734:     AMIGA_justify_text, do_point, do_arrow, AMIGA_set_font,
                    735:     0,                         /* pointsize */
                    736:     TERM_CAN_MULTIPLOT, AMIGA_suspend, AMIGA_resume
                    737: TERM_TABLE_END(amiga_driver)
                    738:
                    739: #undef LAST_TERM
                    740: #define LAST_TERM amiga_driver
                    741:
                    742: #endif /* TERM_TABLE */
                    743: #endif /* TERM_PROTO_ONLY */
                    744:
                    745:
                    746: #ifdef TERM_HELP
                    747: START_HELP(amiga)
                    748: "1 amiga",
                    749: "?commands set terminal amiga",
                    750: "?set terminal amiga",
                    751: "?set term amiga",
                    752: "?terminal amiga",
                    753: "?term amiga",
                    754: "?amiga",
                    755: " The `amiga` terminal, for Commodore Amiga computers, allows the user to",
                    756: " plot either to a screen (default), or, if Kickstart 3.0 or higher is",
                    757: " installed, to a window on the current public screen. The font and its size",
                    758: " can also be selected.",
                    759: "",
                    760: " Syntax:",
                    761: "       set terminal amiga {screen | window} {\"<fontname>\"} {<fontsize>}",
                    762: "",
                    763: " The default font is 8-point \"topaz\".",
                    764: "",
                    765: " The screen option uses a virtual screen, so it is possible that the graph",
                    766: " will be larger than the screen."
                    767: END_HELP(amiga)
                    768: #endif /* TERM_HELP */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>