home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 355.lha / post_v1.0 / pmsg.c < prev    next >
C/C++ Source or Header  |  1990-03-06  |  5KB  |  162 lines

  1. /* Test program to demonstrate the message interface to Post V1.0.
  2.  * (C) Adrian Aylward 1989, 1990
  3.  *
  4.  * You may freely copy, use, and modify this file.  It was tested using
  5.  * Lattice C V5.04
  6.  *
  7.  * To run this program, you need to be in a directory containing the files
  8.  * "post", "init.ps", "prog1.ps", "prog2.ps".  Then type
  9.  *
  10.  *     run pmsg
  11.  *
  12.  * to the cli.  Wait until the disc has finished.  Then type
  13.  *
  14.  *     post screen size x640y400 messageport post.test
  15.  *
  16.  * To recompile this program type
  17.  *
  18.  *     lc -L pmsg.c
  19.  */
  20.  
  21. # include <dos.h>
  22. # include <exec/exec.h>
  23. # include <exec/tasks.h>
  24. # include <intuition/intuition.h>
  25. # include <proto/dos.h>
  26. # include <proto/exec.h>
  27. # include <proto/graphics.h>
  28. # include <proto/intuition.h>
  29. # include "stdio.h"
  30. # include "stdlib.h"
  31.  
  32. # include "postmsg.h"
  33.  
  34. struct MessagePort *testport;
  35.  
  36. struct NewScreen newscreen =
  37. {   0, 0, 640, 400, 3, 0, 15, LACE|HIRES, CUSTOMSCREEN,
  38.     NULL, NULL, NULL, NULL
  39. };
  40. struct Screen *screen;
  41. static short ccolors[8] =
  42. {   0xfff, 0x0ff, 0xf0f, 0x00f, /* White   cyan    magenta blue */
  43.     0xff0, 0x0f0, 0xf00, 0x000  /* Yellow  green   red     black */
  44. };
  45.  
  46.  
  47. int returncode;
  48. int count;
  49.  
  50. main(int argc, char **argv)
  51. {   struct PSMessage *msg;
  52.     int action;
  53.  
  54.     /* Open the libraries */
  55.  
  56.     GfxBase =
  57.         (struct GfxBase *)       OpenLibrary("graphics.library", 0);
  58.     IntuitionBase =
  59.         (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
  60.     if (GfxBase == NULL || IntuitionBase == NULL)
  61.     {   fprintf(stderr, "Can't open libraries\n");
  62.         goto errorexit;
  63.     }
  64.  
  65.     /* Open a screen and set up the colours */
  66.  
  67.     screen = OpenScreen(&newscreen);
  68.     if (screen == NULL)
  69.     {   fprintf(stderr, "Can't open screen\n");
  70.         goto errorexit;
  71.     }
  72.     LoadRGB4(&screen->ViewPort, ccolors, 8);
  73.  
  74.     /* Create the message port */
  75.  
  76.     testport = CreatePort("post.test", 0);
  77.     if (testport == NULL)
  78.     {   fprintf(stderr, "Can't create port\n");
  79.         goto errorexit;
  80.     }
  81.  
  82.     /* Loop processing messages, until we get a CLOSE */
  83.  
  84.     for (;;)
  85.     {   for (;;)
  86.         {   msg = (struct PSMessage *) GetMsg(testport);
  87.             if (msg) break;
  88.             WaitPort(testport);
  89.         }
  90.  
  91.         action = msg->action;
  92.         switch(action)
  93.         {   case PSACTOPEN:    /* Open */
  94.                 break;
  95.  
  96.             case PSACTCLOSE:   /* Close */
  97.                 break;
  98.  
  99.             case PSACTFLUSH:   /* Flush out the bitmap */
  100.                 BltBitMapRastPort(msg->bitmap,            /* Bitmap */
  101.                                   0, msg->y1,             /* source pos */
  102.                                   &screen->RastPort,      /* RastPort */
  103.                                   0, msg->y1,             /* Target pos */
  104.                                   640, msg->y2 - msg->y1, /* Size */
  105.                                   0xC0);                  /* Copy */
  106.                 break;
  107.  
  108.             case PSACTPAUSE:   /* Pause at the end of a page */
  109.                 Delay(250);
  110.                 break;
  111.  
  112.             case PSACTCOMMAND: /* Get a command */
  113.                 count++;       /* Send the commands in sequence */
  114.                 if      (count == 1)
  115.                 {   msg->command = PSCOMFILEL;
  116.                     msg->string = "init.ps";
  117.                 }
  118.                 else if (count == 2)
  119.                 {   msg->command = PSCOMSTRING;
  120.                     msg->string = "(prog1.ps) run";
  121.                     msg->length = -1;
  122.                 }
  123.                 else if (count == 3)
  124.                     msg->command = PSCOMRESTART;
  125.                 else if (count == 4)
  126.                 {   msg->command = PSCOMFILEL;
  127.                     msg->string = "init.ps";
  128.                 }
  129.                 else if (count == 5)
  130.                 {   msg->command = PSCOMFILER;
  131.                     msg->string = "prog2.ps";
  132.                 }
  133.                 else
  134.                     msg->command = PSCOMQUIT;
  135.                 break;
  136.  
  137.             case PSACTEXIT:    /* Exit */
  138.                 msg->command = PSCOMQUIT;
  139.                 break;
  140.         }
  141.  
  142.         /* Comment this out to omit trace output */
  143.  
  144.         fprintf(stdout, "msg act %d com %d res %d err %d\n",
  145.                 msg->action, msg->command, msg->result, msg->errnum);
  146.  
  147.         ReplyMsg((struct Message *) msg);
  148.         if (action == PSACTCLOSE) goto tidyup;
  149.     }
  150.  
  151. errorexit:
  152.     returncode = 20;
  153.  
  154. tidyup:
  155.     if (testport) DeletePort(testport);
  156.     if (screen) CloseScreen(screen);
  157.     if (GfxBase) CloseLibrary((struct Library *) GfxBase);
  158.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  159.  
  160.     exit(returncode);
  161. }
  162.