home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 152.lha / Console / window.c < prev    next >
C/C++ Source or Header  |  1988-04-26  |  4KB  |  159 lines

  1. #include "exec/types.h"
  2. #include "exec/libraries.h"
  3. #include "exec/memory.h"
  4. #include "graphics/gfx.h"
  5. #include "intuition/intuition.h"
  6. #include "libraries/dos.h"
  7. #include "libraries/dosextens.h"
  8.  
  9. #define BLUE 0 
  10. #define WHITE 1 
  11. #define BLACK 2 
  12. #define RED 3 
  13.  
  14. #define ACTION_SCREEN_MODE 994
  15.  
  16. struct GfxBase *GfxBase; 
  17. LONG *IntuitionBase;
  18. LONG *DosBase;
  19.  
  20. extern struct Library *OpenLibrary();
  21. extern struct Screen *OpenScreen();
  22. extern struct Window *OpenWindow();
  23.  
  24. extern struct MsgPort  *NewConsole();
  25.  
  26. struct Window   *window=NULL;
  27. struct Screen   *screen=NULL;
  28. struct MsgPort  *task=NULL;
  29. struct Process  *process=NULL;
  30.  
  31. LONG handle=NULL;
  32.  
  33. char buffer[80];
  34.  
  35. struct MsgPort iorp = {
  36.     {0, 0, NT_MSGPORT, 0, 0}, 0,
  37.     -1,                         /* initialize signal to -1 */
  38.     0,
  39.                                 /* start with empty list */
  40.     {&iorp.mp_MsgList.lh_Tail, 0, &iorp.mp_MsgList.lh_Head, 0, 0}
  41. };
  42.  
  43.  
  44. struct NewScreen ns = {
  45.         0,0,
  46.         320,200,4, /* & depth */
  47.         BLUE,RED,
  48.         NULL,  /* viewmodes */
  49.         CUSTOMSCREEN,
  50.         NULL, /* default font */
  51.         "Window Test Program",
  52.         NULL, /* no user gadgets */
  53.         NULL
  54. }; /* default bit map */
  55.  
  56. struct NewWindow nw = {
  57.         0, 12,          /* starting position (left,top) */
  58.         320,186,        /* width, height */
  59.         BLUE,WHITE,    /* detailpen, blockpen */
  60.         NULL,  /* flags for idcmp */
  61.         SMART_REFRESH|WINDOWDEPTH|WINDOWSIZING|WINDOWDRAG|ACTIVATE, /* window gadget flags */
  62.         NULL,           /* pointer to 1st user gadget */
  63.         NULL,           /* pointer to user check */
  64.         NULL,            /* no title */
  65.         NULL,           /* pointer to window screen (add after it is open */
  66.         NULL,           /* pointer to super bitmap */
  67.         50,50,         /* min width, height */
  68.         640,200,        /* max width, height */
  69.         CUSTOMSCREEN};
  70. /* own screen defaults */
  71.  
  72. main()
  73. {
  74. struct StandardPacket *packet;
  75.  
  76. if((IntuitionBase=OpenLibrary("intuition.library",0)) == NULL)cleanup(20);
  77. if((DosBase = OpenLibrary(DOSNAME, 0)) == NULL) cleanup(20);
  78. if((GfxBase = OpenLibrary("graphics.library", 0)) ==NULL) cleanup(20);
  79.  
  80. if((screen=OpenScreen(&ns)) == NULL)cleanup(20);
  81. nw.Screen=screen;
  82. if((window=OpenWindow(&nw)) == NULL)cleanup(20); 
  83.  
  84. /* set up the message port */
  85.     if ((iorp.mp_SigBit = AllocSignal(-1)) < 0) {
  86. kprintf("message port error\n");
  87.         cleanup(0);
  88.         exit(35);
  89.     }
  90.     iorp.mp_SigTask = (struct Task *) FindTask((char *) NULL);
  91.  
  92.  
  93. /* Start up new console handler task; pass it new window */
  94.  
  95.     if(!(task = NewConsole(window)))cleanup(20);
  96.  
  97. /* Patch DOS "consoletask" location. Subsequent calls to */
  98. /* Open("*") will refer to the new window created above  */
  99.  
  100.     process = (struct Process *)FindTask(NULL); 
  101.     process -> pr_ConsoleTask = task;
  102.  
  103.     process->pr_WindowPtr=window; /* reset error screen */
  104. /* Open * now refers to the new window */
  105.  
  106.     if (!(handle = Open("*", MODE_OLDFILE))) {
  107.        CloseConsole(task); /* open failed, kill our console task */
  108.        cleanup(20);
  109.     }
  110.  
  111. /* put window into cooked mode */
  112.     if ((packet = (struct StandardPacket *)
  113.         AllocMem(sizeof(*packet), MEMF_PUBLIC|MEMF_CLEAR))) {
  114.         /* this is the console handlers packet port */
  115.         packet->sp_Msg.mn_Node.ln_Name = &(packet->sp_Pkt);
  116.             packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
  117.             packet->sp_Pkt.dp_Port = &iorp;
  118.             packet->sp_Pkt.dp_Type = ACTION_SCREEN_MODE;
  119.             packet->sp_Pkt.dp_Arg1 = 0;
  120.             PutMsg(task, packet);
  121.             WaitPort(&iorp);
  122.             GetMsg(&iorp); /* pull message */
  123.           FreeMem(packet, sizeof(*packet));
  124.     }
  125.  
  126.     Write(handle,"\033[20h",5);    /* Xlate \n to \r\n */
  127.     Write(handle,"This is a custom screen\n",24);
  128.     Write(handle,"And here's my own stupid\n",25);
  129.     Write(handle,"diskcopy message, duh.\n",23);
  130.     Read(handle,buffer,10);
  131.     Execute("diskcopy <* df0: to df1:",0,0);
  132.     cleanup(0);
  133. }
  134.  
  135.  
  136. cleanup(code)
  137. {
  138. struct Process *process;
  139.  
  140.  if (iorp.mp_SigBit != -1) 
  141.     FreeSignal(iorp.mp_SigBit);
  142.  
  143. process = (struct Process *)FindTask(NULL); /* reset error window */
  144. process->pr_WindowPtr=NULL;
  145. process -> pr_ConsoleTask = NULL;;
  146.  
  147. if(handle)Close(handle);
  148. if(screen)CloseScreen(screen);
  149.  
  150. if(GfxBase)CloseLibrary(GfxBase);
  151. if(DosBase)CloseLibrary(DosBase);
  152.  
  153. OpenWorkBench(); /* just in case */
  154. if(IntuitionBase)CloseLibrary(IntuitionBase); 
  155.  
  156. exit(code);
  157.  
  158. }
  159.