home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / avogl.tar.gz / avogl.tar / vogl / drivers / Amiga.c.bac < prev    next >
Text File  |  1992-09-24  |  20KB  |  832 lines

  1.     /*
  2.  * Driver for the Amiga computer
  3.  *
  4.  * Compiled with gcc 2.2.2 (GNU)  or dcc (DICE)  under Amiga OS 2.04
  5.  *
  6.  *  Oliver Schersand  elm: scher@orion.informatik.uni-freiburg.de
  7.  *
  8.  */
  9.  
  10. #include "vogl.h"
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. #include <intuition/intuition.h>
  15. #include <intuition/Screens.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/rastport.h>
  18. #include <graphics/gfxmacros.h>
  19. #include <graphics/text.h>
  20. #include <graphics/displayinfo.h>
  21. #include <libraries/diskfont.h>
  22. #include <utility/tagitem.h>
  23. #include <exec/memory.h>
  24. #include <dos/dos.h>
  25.  
  26. #ifdef AMIGAGCC
  27. #include <inline/intuition.h>
  28. #include <inline/graphics.h>
  29. #include <inline/exec.h>
  30. #include <inline/diskfont.h>
  31. #endif
  32.  
  33. #define LARGE_AMIGA_FONT "Courier.font,15"
  34. #define SMALL_AMIGA_FONT "topaz.font,8"
  35.  
  36. static struct Window   *win;
  37. static struct RastPort *rp;
  38. static struct RastPort *BackRast;
  39. static struct BitMap   *BackMap,*toggle[2];
  40. static int colour;
  41. static short  Buffer[128*5];
  42. static struct AreaInfo AInfo;
  43. static struct TmpRas TRas;
  44. static int x,y,w,h,tog,depth,type,mode,monitor;
  45. static char pubscreen[40];
  46. static int LDown,MDown,RDown;
  47. static char input[256];
  48. static int  pos = 0, inget = 0,ownscr;
  49. int pens[] = {~0};
  50. static long col[32];
  51. static struct Screen *scr;
  52.  
  53. #define am2error(string) { fprintf(stderr,"Am2:%s\n",string); Am2_exit(); return 0;}
  54. #define am1error(string) { fprintf(stderr,"Am1:%s\n",string); Am1_exit(); return 0;}
  55.  
  56.  
  57. void Clear()
  58.  
  59. {
  60.    win =0;
  61.    rp = 0;
  62.    BackRast = 0;
  63.    BackMap = 0;
  64.    toggle[0] = 0;
  65.    toggle[1] = 0;
  66. }
  67.  
  68.  
  69. void ReadConfig(char *name)
  70.  
  71. {
  72.    FILE *config;
  73.    char key[40],*env;
  74.  
  75.  
  76.     monitor = 0;
  77.     mode    = HIRESLACE_KEY;
  78.     depth   = 2;
  79.     type = OSCAN_STANDARD;
  80.  
  81.  
  82.     GetDefaultPubScreen(pubscreen);
  83.  
  84.     config = NULL;
  85.     env = getenv(name);
  86.     if (env != NULL)
  87.            config = fopen(env,"r");
  88.  
  89.     if (config == NULL) {
  90.        sprintf(key,"s:%s.config",name);
  91.        config = fopen(key,"r");
  92.        if (config == NULL) return;
  93.     }
  94.  
  95.     do {
  96.         key[0] = (char)0;
  97.         fscanf(config,"%s",key);
  98.  
  99.         if (strcmp(key,"Screen") == 0) {
  100.             fscanf(config,"%s",pubscreen);
  101.         } else if (strcmp(key,"Size") == 0) {
  102.             fscanf(config,"%s",key);
  103.             if (strcmp(key,"Overscan") == 0) {
  104.                 type = OSCAN_STANDARD;
  105.             } else if (strcmp(key,"Standart") == 0) {
  106.                 type = 0;
  107.             }
  108.         } else if (strcmp(key,"Top") == 0) {
  109.             fscanf(config,"%i",&y);
  110.         } else if (strcmp(key,"Left") == 0) {
  111.             fscanf(config,"%i",&x);
  112.         } else if (strcmp(key,"Width") == 0) {
  113.             fscanf(config,"%i",&w);
  114.         } else if (strcmp(key,"Height") == 0) {
  115.             fscanf(config,"%i",&h);
  116.         } else if (strcmp(key,"Depth") == 0) {
  117.             fscanf(config,"%i",&depth);
  118.         } else if (strcmp(key,"Monitor") == 0) {
  119.             fscanf(config,"%x",&monitor);
  120.         } else if (strcmp(key,"Mode") == 0) {
  121.             fscanf(config,"%x",&mode);
  122.         } else if (strcmp(key,"End") == 0) {
  123.         } else {
  124.             fprintf(stderr,"Unknown keyword > %s <\n",key);
  125.             return;
  126.         }
  127.     } while (strcmp(key,"End") != 0);
  128.     close(config);
  129. }
  130.  
  131. int Am2_init()
  132.  
  133. /* DOUBLE BUFFERING SCREEN BASED ON AN EXAMPLE OF RKM-LIBRARY */
  134.  
  135. {
  136.     int i;
  137.     vdevice.initialised = TRUE;
  138.  
  139.     Clear();
  140.     ReadConfig("AM2");
  141.  
  142.     BackRast = AllocMem(sizeof(struct RastPort),MEMF_CHIP|MEMF_CLEAR);
  143.     if (BackRast == 0) am2error("no chimpmem");
  144.     BackMap  = AllocMem(sizeof(struct BitMap),MEMF_CHIP|MEMF_CLEAR);
  145.     if (BackRast == 0) am2error("no chipmem");
  146.     if (type != 0) {
  147.         scr = OpenScreenTags(NULL,SA_Depth,depth,
  148.                                   SA_Title,NULL,
  149.                                   SA_Height,STDSCREENHEIGHT,
  150.                                   SA_Width,STDSCREENWIDTH,
  151.                                   SA_DisplayID,mode | monitor,
  152.                                   SA_Type,SCREENQUIET | CUSTOMSCREEN,
  153.                                   SA_Overscan,type,
  154.                                   TAG_DONE);
  155.     } else {
  156.         scr = OpenScreenTags(NULL,SA_Depth,depth,
  157.                                   SA_Title,NULL,
  158.                                   SA_DisplayID,mode | monitor,
  159.                                   SA_Height,STDSCREENHEIGHT,
  160.                                   SA_Width,STDSCREENWIDTH,
  161.                                   SA_Type,SCREENQUIET | CUSTOMSCREEN,
  162.                                   TAG_DONE);
  163.    }
  164.    if (scr == NULL) am2error("no screen");
  165.  
  166.     x = 0;
  167.     y = 0;
  168.     h = scr->Height;
  169.     w = scr->Width;
  170.  
  171.     win = OpenWindowTags(NULL,WA_Left,x,
  172.                               WA_Top,y,
  173.                               WA_Width,w,
  174.                               WA_Height,h,
  175.                               WA_IDCMP, IDCMP_VANILLAKEY|
  176.                                         IDCMP_MOUSEBUTTONS,
  177.                               WA_CustomScreen,(int)scr,
  178.                               WA_ReportMouse,TRUE,
  179.                               WA_NoCareRefresh,TRUE,
  180.                               WA_Borderless,TRUE,
  181.                               WA_Backdrop,TRUE,
  182.                               WA_Activate,TRUE,
  183.                               WA_RMBTrap,TRUE,
  184.                               TAG_DONE);
  185.  
  186.     /* I need the window to get the input */
  187.  
  188.  
  189.     if (win == NULL) am2error("no backdropwindow");
  190.  
  191.     vdevice.depth =  depth;
  192.     vdevice.sizeX =  w - 1;
  193.     vdevice.sizeY =  h - 1;
  194.     vdevice.sizeSx = w - 1;
  195.     vdevice.sizeSy = h - 1;
  196.  
  197.     InitArea(&AInfo,Buffer,128);
  198.     rp = &(scr->RastPort);
  199.     rp->AreaInfo = &AInfo;
  200.     rp->TmpRas = (struct TmpRas *) InitTmpRas(&TRas,AllocRaster(w,h),RASSIZE(w,h));
  201.     if (rp->TmpRas == NULL) am2error("no tempras");
  202.     if (rp->TmpRas->RasPtr == NULL) am2error("no tempbitmap");
  203.     InitRastPort(BackRast);
  204.     InitBitMap(BackMap,depth,w,h);
  205.     BackRast->BitMap = BackMap;
  206.     for (i=0;i<depth;i++) {
  207.         BackMap->Planes[i] = AllocRaster(w,h);
  208.         if (BackMap->Planes[i] == NULL) am2error("no bitmap");
  209.     }
  210.     BackRast->TmpRas = rp->TmpRas;
  211.     BackRast->AreaInfo = &AInfo;
  212.  
  213.     SetAPen(rp,1);
  214.     SetBPen(rp,0);
  215.  
  216.     SetAPen(BackRast,1);
  217.     SetBPen(BackRast,0);
  218.  
  219.     SetDrMd(BackRast,JAM1);
  220.     SetDrMd(rp,JAM1);
  221.  
  222.     toggle[0] = rp->BitMap;
  223.     toggle[1] = BackRast->BitMap;
  224.     SetRGB4(&scr->ViewPort,0,0,0,0);
  225.     SetRGB4(&scr->ViewPort,1,15,0,0);
  226.     SetRGB4(&scr->ViewPort,2,0,15,0);
  227.     SetRGB4(&scr->ViewPort,3,15,15,0);
  228.     SetRGB4(&scr->ViewPort,4,0,0,15);
  229.     SetRGB4(&scr->ViewPort,5,15,0,15);
  230.     SetRGB4(&scr->ViewPort,6,0,15,15);
  231.     SetRGB4(&scr->ViewPort,7,15,15,15);
  232.  
  233.     tog = 1;
  234.  
  235.     return (1);
  236.  
  237. }
  238.  
  239.  
  240. int Am1_init()
  241.  
  242. {
  243.  int prefx,prefy,prefxs,prefys,i;
  244.  
  245.   vdevice.initialised = TRUE;
  246.  
  247.  Clear();
  248.  BackRast = AllocMem(sizeof(struct RastPort),MEMF_CHIP|MEMF_CLEAR);
  249.  BackMap  = AllocMem(sizeof(struct BitMap), MEMF_CHIP|MEMF_CLEAR);
  250.  
  251.  getprefposandsize(&prefx, &prefy, &prefxs, &prefys);
  252.  
  253.  
  254.  x = 0; y = 0; w = 0; h = 0;
  255.  
  256.  if (prefx > -1) {
  257.           x = prefx;
  258.           y = prefy;
  259.   }
  260.  
  261.   if (prefxs > -1) {
  262.           w = prefxs;
  263.           h = prefys;
  264.   }
  265.  
  266.   ReadConfig("AM1");
  267.  
  268.   ownscr = 0;
  269.   scr = LockPubScreen(pubscreen);
  270.  
  271.   if (scr == NULL) {
  272.         if (type != 0) {
  273.             scr = OpenScreenTags(NULL,SA_Depth,depth,
  274.                                   SA_Title,  (int )pubscreen,
  275.                                   SA_PubName,(int )pubscreen,
  276.                                   SA_DisplayID,mode | monitor,
  277.                                   SA_Type,PUBLICSCREEN,
  278.                                   SA_Overscan,type,
  279.                                   SA_Pens,(int)pens,
  280.                                   SA_Height,STDSCREENHEIGHT,
  281.                                   SA_Width,STDSCREENWIDTH,
  282.                                    TAG_DONE);
  283.         } else {
  284.             scr = OpenScreenTags(NULL,SA_Depth,depth,
  285.                                   SA_Title,  (int )pubscreen,
  286.                                   SA_PubName,(int )pubscreen,
  287.                                   SA_DisplayID,mode | monitor,
  288.                                   SA_Height,STDSCREENHEIGHT,
  289.                                   SA_Width,STDSCREENWIDTH,
  290.                                   SA_Type,PUBLICSCREEN,
  291.                                   SA_Pens,(int)pens,
  292.                                   TAG_DONE);
  293.         }
  294.  
  295.         ownscr = 1;
  296.         PubScreenStatus(scr,0);
  297.   }  else {
  298.         UnlockPubScreen(pubscreen,scr);
  299.   }
  300.  
  301.   if (scr == 0) am1error("Cannot open public screen");
  302.  
  303.   if (w + x > scr->Width) {
  304.     if (w > scr->Width) {
  305.           x = 0; w = scr->Width;
  306.     } else {
  307.           x = scr->Width - w;
  308.     }
  309.   }
  310.  
  311.  
  312.   if (h + y > scr->Height) {
  313.     if (w > scr->Height) {
  314.           y = 0; h = scr->Height;
  315.     } else {
  316.           y = scr->Height - h;
  317.     }
  318.   }
  319.  
  320.   if (w == 0) w = scr->Width;
  321.   if (h == 0) h = scr->Height;
  322.  
  323.   win = OpenWindowTags (NULL,
  324.                          WA_Title,vdevice.wint
  325.                          WA_Left,x,
  326.                          WA_Top,y,
  327.                          WA_Width,w,
  328.                          WA_Height,h,
  329.                          WA_CustomScreen,(int)scr,
  330.                          WA_Flags,WFLG_DRAGBAR|
  331.                                   WFLG_DEPTHGADGET|
  332.                                   WFLG_SMART_REFRESH|
  333.                                   WFLG_REPORTMOUSE|
  334.                                   WFLG_ACTIVATE|
  335.                                   WFLG_RMBTRAP|
  336.                                   WFLG_NOCAREREFRESH,
  337.                          WA_IDCMP, IDCMP_VANILLAKEY|
  338.                                    IDCMP_MOUSEBUTTONS,
  339.                          WA_WindowName,(int)"Am1-Vogle-Output",
  340.                          TAG_END);
  341.  
  342.     if (win == 0) am1error("Unable to open a Window");
  343.  
  344.     vdevice.depth =  scr->BitMap.Depth;
  345.     depth = scr->BitMap.Depth;
  346.     vdevice.sizeX =  w - win->BorderLeft - win->BorderRight  - 1;
  347.     vdevice.sizeY =  h - win->BorderTop  - win->BorderBottom - 1;
  348.     vdevice.sizeSx = w - win->BorderLeft - win->BorderRight  - 1;
  349.     vdevice.sizeSy = h - win->BorderTop  - win->BorderBottom - 1;
  350.  
  351.     InitArea(&AInfo,Buffer,128);
  352.     rp = win->RPort;
  353.     rp->AreaInfo = &AInfo;
  354.     rp->TmpRas = (struct TmpRas *) InitTmpRas(&TRas,AllocRaster(w,h),RASSIZE(w,h));
  355.     InitRastPort(BackRast);
  356.     InitBitMap(BackMap,depth,w,h);
  357.     BackRast->BitMap = BackMap;
  358.  
  359.     for (i=0;i<depth;i++) {
  360.         BackMap->Planes[i] = AllocRaster(w,h);
  361.         if (BackMap->Planes[i] == NULL) am1error("No Bitmap");
  362.     }
  363.  
  364.     BackRast->TmpRas = rp->TmpRas;
  365.     BackRast->AreaInfo = &AInfo;
  366.     SetBPen(rp,0);
  367.     SetBPen(BackRast,0);
  368.     SetDrMd(BackRast,JAM1);
  369.     SetDrMd(rp,JAM1);
  370.  
  371.     for (i = 0;i < 32; i++)               /* Save the old colormap */
  372.         col[i] = GetRGB4(scr->ViewPort.ColorMap,i);
  373.  
  374.  
  375.     SetRGB4(&scr->ViewPort,4,0,0,0);
  376.     SetRGB4(&scr->ViewPort,5,15,0,0);
  377.     SetRGB4(&scr->ViewPort,6,0,15,0);
  378.     SetRGB4(&scr->ViewPort,7,15,15,0);
  379.     SetRGB4(&scr->ViewPort,8,0,0,15);
  380.     SetRGB4(&scr->ViewPort,9,15,0,15);
  381.     SetRGB4(&scr->ViewPort,10,0,15,15);
  382.     SetRGB4(&scr->ViewPort,11,15,15,15);
  383.     return(1);
  384.  }
  385.  
  386. int Am1_exit()
  387.  
  388. {
  389.  int i;
  390.  struct EasyStruct er =
  391.     { sizeof(struct EasyStruct),
  392.       0,
  393.       "Vogle Request",
  394.       "Close windows on public screen %s .",
  395.       "Ok",
  396.     };
  397.  if (BackRast->Font != NULL) CloseFont(BackRast->Font);
  398.  if (rp->Font != NULL) CloseFont(rp->Font);
  399.  if (TRas.RasPtr != NULL) FreeRaster(TRas.RasPtr,w,h);
  400.  if (BackMap != 0) {
  401.      for (i = 0;i < BackMap->Depth;i++)
  402.          if (BackMap->Planes[i] != 0) FreeRaster(BackMap->Planes[i],w,h);
  403.      FreeMem(BackMap,sizeof(struct BitMap));
  404.  }
  405.  if (BackRast != NULL) FreeMem(BackRast,sizeof(struct RastPort));
  406.  if (win != NULL) CloseWindow(win);
  407.   for (i = 0; i <32; i++)
  408.        SetRGB4(&scr->ViewPort,i,(col[i]>>8) & 15,
  409.                                (col[i]>>4) & 15,
  410.                                 col[i] & 15);
  411.   if (ownscr == 1) {
  412.       while (TRUE != CloseScreen(scr))
  413.          EasyRequestArgs(NULL,&er,NULL,pubscreen);
  414.   }
  415.  return (1);
  416. }
  417.  
  418.  
  419. int Am2_exit()
  420.  
  421. {
  422.  int i;
  423.  
  424.  if (toggle[0] != 0) {
  425.      BackRast->BitMap              = toggle[1];
  426.      scr->RastPort.BitMap          = toggle[0];
  427.      scr->ViewPort.RasInfo->BitMap = toggle[0];
  428.      MakeScreen(scr);
  429.      RethinkDisplay();
  430.   }
  431.  
  432.  if (BackRast->Font != NULL) CloseFont(BackRast->Font);
  433.  if (rp->Font != NULL) CloseFont(rp->Font);
  434.  if (TRas.RasPtr != NULL) FreeRaster(TRas.RasPtr,w,h);
  435.  if (BackMap != 0) {
  436.      for (i = 0;i < BackMap->Depth;i++)
  437.          if (BackMap->Planes[i] != 0) FreeRaster(BackMap->Planes[i],w,h);
  438.      FreeMem(BackMap,sizeof(struct BitMap));
  439.  }
  440.  if (BackRast != NULL) FreeMem(BackRast,sizeof(struct RastPort));
  441.  if (win != NULL) CloseWindow(win);
  442.  if (scr != NULL) CloseScreen(scr);
  443.  
  444.  return (1);
  445. }
  446.  
  447.  
  448. int Am1_char(char c)
  449.  
  450. {
  451.   Move(rp,vdevice.cpVx + win->BorderLeft,
  452.           (int)(vdevice.sizeSy - vdevice.cpVy) + win->BorderTop);
  453.   Text(rp, &c, 1);
  454.   return 1;
  455. }
  456.  
  457. int Am2_char(char c)
  458.  
  459. {
  460.   Move(rp,vdevice.cpVx ,
  461.           (int)(vdevice.sizeSy - vdevice.cpVy));
  462.   Text(rp, &c, 1);
  463.   return 1;
  464. }
  465.  
  466. int Am1_clear()
  467. {
  468.         SetAPen(rp, colour);
  469.         RectFill(rp, win->BorderLeft,
  470.                      win->BorderTop,
  471.                      vdevice.sizeSx + win->BorderLeft ,
  472.                      vdevice.sizeSy + win->BorderTop
  473.         );
  474.         return 1;
  475. }
  476.  
  477.  
  478. int Am2_clear()
  479. {
  480.  
  481.         SetAPen(rp, colour);
  482.         RectFill(rp, 0,
  483.                      0,
  484.                      vdevice.sizeSx,
  485.                      vdevice.sizeSy
  486.         );
  487.         return 1;
  488. }
  489.  
  490. int Am1_color(int color)
  491.  
  492. {
  493.    colour = (color + 4);
  494.    SetAPen(win->RPort, colour);
  495.    SetAPen(BackRast,   colour);
  496.    return 1;
  497. }
  498.  
  499.  
  500. int Am2_color(int color)
  501.  
  502. {
  503.    colour = color;
  504.    SetAPen(&scr->RastPort, colour);
  505.    SetAPen(BackRast, colour);
  506.    return 1;
  507. }
  508.  
  509. Am2_draw(int px, int py)
  510.  
  511. {
  512.         Move(rp, vdevice.cpVx ,
  513.                   vdevice.sizeSy - vdevice.cpVy);
  514.         Draw(rp, px  ,
  515.                  vdevice.sizeSy - py);
  516.         return 1;
  517. }
  518.  
  519.  
  520. Am1_draw(int px, int py)
  521.  
  522. {
  523.         Move(rp, vdevice.cpVx + win->BorderLeft,
  524.                   vdevice.sizeSy - vdevice.cpVy + win->BorderTop);
  525.         Draw(rp, px  + win->BorderLeft,
  526.                  vdevice.sizeSy - py + win->BorderTop);
  527.         return 1;
  528. }
  529.  
  530. Am2_fill(int n, int *fx,int *fy)
  531.  
  532. {
  533.   int i;
  534.  
  535.   if (n > 128)
  536.      verror("vogle: more than 128 points in a polygon");
  537.  
  538.   AreaMove(rp,fx[0],vdevice.sizeSy - fy[0]);
  539.  
  540.   for (i = 1; i < n; i++)
  541.     AreaDraw(rp,fx[i],vdevice.sizeSy - fy[i]);
  542.  
  543.   AreaEnd(rp);
  544. }
  545.  
  546. Am1_fill(int n, int *x,int *y)
  547.  
  548. {
  549.   int i;
  550.  
  551.   if (n > 128)
  552.      verror("vogle: more than 128 points in a polygon");
  553.  
  554.   AreaMove(rp,x[0] + win->BorderLeft,vdevice.sizeSy - y[0] + win->BorderTop);
  555.  
  556.   for (i = 1; i < n; i++)
  557.     AreaDraw(rp,x[i] + win->BorderLeft,vdevice.sizeSy - y[i] + win->BorderTop);
  558.  
  559.   AreaEnd(rp);
  560. }
  561.  
  562.  
  563. int Am1_font(char *font)
  564.  
  565. {
  566.     char name[40],attr[4][20];
  567.     int res = 8,i;
  568.     UWORD style = 0;
  569.     struct TextAttr ta;
  570.     struct TextFont *tf;
  571.  
  572.     *name  = (char)0;
  573.     *attr[0] = (char)0;
  574.     *attr[1] = (char)0;
  575.     *attr[2] = (char)0;
  576.     *attr[3] = (char)0;
  577.  
  578.     sscanf(font ,"%[^,],%i,%[^,],%[^,],%[^,],%[^,]",
  579.                   name,&res,attr[0],attr[1],attr[2],attr[3]);
  580.  
  581.     if (strcmp(name,"large") == 0) {
  582.         sscanf(font ,"%[^,],%[^,],%[^,],%[^,],%[^,]",
  583.                   name,attr[0],attr[1],attr[2],attr[3]);
  584.         sscanf(LARGE_AMIGA_FONT,"%[^,],%i",name,&res);
  585.     }
  586.  
  587.     if (strcmp(name,"small") == 0) {
  588.         sscanf(font ,"%[^,],%[^,],%[^,],%[^,],%[^,]",
  589.                 name,attr[0],attr[1],attr[2],attr[3]);
  590.         sscanf(SMALL_AMIGA_FONT,"%[^,],%i",name,&res);
  591.     }
  592.  
  593.     for (i=0;i < 4; i++) {
  594.         if (strcmp(attr[i],"bold") == 0)       style   |= FSF_BOLD;
  595.         if (strcmp(attr[i],"italic") == 0)     style   |= FSF_ITALIC;
  596.         if (strcmp(attr[i],"underlined") == 0) style   |= FSF_UNDERLINED;
  597.     }
  598.  
  599.     ta.ta_Name = name;
  600.     ta.ta_YSize = res;
  601.     ta.ta_Style = 0;
  602.     ta.ta_Flags = 0;
  603.  
  604.  
  605.     tf = OpenDiskFont(&ta);
  606.     if (tf == 0) return 0;
  607.  
  608.     if (BackRast->Font != NULL) CloseFont(BackRast->Font);
  609.     if (rp->Font != NULL) CloseFont(rp->Font);
  610.  
  611.     SetFont(rp,tf); SetSoftStyle(rp,style,255);
  612.     SetFont(BackRast,tf); SetSoftStyle(BackRast,style,255);
  613.     vdevice.hheight = tf->tf_YSize;
  614.     vdevice.hwidth = tf->tf_XSize;
  615.     return (1);
  616. }
  617.  
  618. TestInput()
  619.  
  620. {
  621.    if (win->UserPort->mp_MsgList.lh_Head->ln_Succ == NULL)
  622.       return;
  623.    else {
  624.       struct IntuiMessage *msg;
  625.       for (;;) {
  626.           msg = (struct IntuiMessage *)GetMsg(win->UserPort); if (msg == NULL) return ;
  627.           if (msg->Class == IDCMP_VANILLAKEY) {
  628.                input[pos] = msg->Code; pos ++;
  629.                if (pos == inget) pos--;
  630.                if (pos > 256) pos = 0;
  631.                ReplyMsg((struct Message *)msg);
  632.                return;
  633.           } else if (msg->Class == IDCMP_MOUSEBUTTONS) {
  634.                switch (msg->Code) {
  635.                    case SELECTDOWN: LDown = 1; break;
  636.                    case SELECTUP  : LDown = 0; break;
  637.                    case MENUUP    : RDown = 4; break;
  638.                    case MENUDOWN  : RDown = 0; break;
  639.                }
  640.           }
  641.           ReplyMsg((struct Message  *)msg);
  642.       }
  643.    }
  644. }
  645.  
  646.  
  647. Am1_checkkey()
  648.  
  649. { char c = 0;
  650.   TestInput();
  651.   if (pos != inget) { c = input[inget]; inget++;}
  652.   if (inget > 256) inget = 0;
  653.   return c;
  654. }
  655.  
  656.  
  657. Am1_getkey()
  658.  
  659. {
  660.     char c;
  661.     for (;;) {
  662.        c = Am1_checkkey();
  663.        if (c != 0) return c;
  664.        WaitPort(win->UserPort);
  665.     }
  666.  
  667. }
  668.  
  669. Am1_locator(int *mx,int *my)
  670.  
  671. {
  672.   TestInput();
  673.   *mx = win->MouseX - win->BorderLeft;
  674.   *my = vdevice.sizeSy - (win->MouseY - win->BorderTop );
  675.   return LDown + RDown;
  676. }
  677.  
  678.  
  679. Am2_locator(int *mx,int *my)
  680.  
  681. {
  682.   TestInput();
  683.   *mx = win->MouseX ;
  684.   *my = vdevice.sizeSy - (win->MouseY);
  685.   return LDown + RDown;
  686. }
  687.  
  688. int Am2_mapcolor(int i,int r,int g,int b)
  689.  
  690. {
  691.   if (i > 31) return 0;
  692.   SetRGB4(&scr->ViewPort,i,r / 16,g / 16, b / 16);
  693.   return 1;
  694.  }
  695.  
  696.  
  697. int Am1_mapcolor(int i,int r,int g,int b)
  698.  
  699. {
  700.   i += 4;
  701.   if (i > 31) return 0;
  702.   SetRGB4(&scr->ViewPort,i,r / 16,g / 16, b / 16);
  703.   return 1;
  704.  }
  705.  
  706.  
  707. int Am1_string(char *str)
  708.  
  709. {
  710.    Move(rp,vdevice.cpVx + win->BorderLeft,
  711.            (int)(vdevice.sizeSy - vdevice.cpVy) + win->BorderTop);
  712.    Text(rp, str, strlen(str));
  713.    return 1;
  714. }
  715.  
  716.  
  717. int Am2_string(char *str)
  718.  
  719. {
  720.    Move(rp,vdevice.cpVx ,
  721.            (int)(vdevice.sizeSy - vdevice.cpVy));
  722.    Text(rp, str, strlen(str));
  723.    return 1;
  724. }
  725.  
  726. int Am1_backbuf()
  727.  
  728. {
  729.   rp = BackRast;
  730.   return 1;
  731. }
  732.  
  733. int Am1_frontbuf()
  734.  
  735. {
  736.   rp = win->RPort;
  737.   return 1;
  738.  
  739. }
  740.  
  741. int Am1_swapbuf()
  742.  
  743. {
  744.  WaitTOF();
  745.  ClipBlit(BackRast,win->BorderLeft,win->BorderTop,
  746.            win->RPort,win->BorderLeft,win->BorderTop,
  747.            vdevice.sizeX,vdevice.sizeY,0XC0);
  748.   return 1;
  749. }
  750.  
  751.  
  752. int Am2_backbuf()
  753.  
  754. {
  755.     rp = BackRast;
  756.     return 1;
  757. }
  758.  
  759. int Am2_frontbuf()
  760.  
  761. {
  762.     rp = &scr->RastPort;
  763.     return 1;
  764. }
  765.  
  766. Am2_swapbuf()
  767.  
  768. {
  769.     scr->RastPort.BitMap          = toggle[tog];
  770.     scr->ViewPort.RasInfo->BitMap = toggle[tog];
  771.     MakeScreen(scr);
  772.     RethinkDisplay();
  773.     if (tog == 1) tog = 0; else tog = 1; /* Oh Gott ich komme von Pascal */
  774.     BackRast->BitMap = toggle[tog];
  775.  
  776. }
  777.  
  778. static DevEntry Am1dev = {
  779.         "Am1",
  780.         "large",
  781.         "small",
  782.         Am1_backbuf,
  783.         Am1_char,
  784.         Am1_checkkey,
  785.         Am1_clear,
  786.         Am1_color,
  787.         Am1_draw,
  788.         Am1_exit,
  789.         Am1_fill,
  790.         Am1_font,
  791.         Am1_frontbuf,
  792.         Am1_getkey,
  793.         Am1_init,
  794.         Am1_locator,
  795.         Am1_mapcolor,
  796.         Am1_string,
  797.         Am1_swapbuf
  798.       };
  799.  
  800.  
  801. static DevEntry Am2dev = {
  802.         "Am2",
  803.         "large",
  804.         "small",
  805.         Am2_backbuf,
  806.         Am2_char,
  807.         Am1_checkkey,
  808.         Am2_clear,
  809.         Am2_color,
  810.         Am2_draw,
  811.         Am2_exit,
  812.         Am2_fill,
  813.         Am1_font,
  814.         Am2_frontbuf,
  815.         Am1_getkey,
  816.         Am2_init,
  817.         Am2_locator,
  818.         Am2_mapcolor,
  819.         Am2_string,
  820.         Am2_swapbuf
  821.       };
  822.  
  823.  
  824. _Am1_devcpy()
  825. {
  826.         vdevice.dev = Am1dev;
  827. }
  828. _Am2_devcpy()
  829. {
  830.         vdevice.dev = Am2dev;
  831. }
  832.