home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / CLISP / CLISPSRC.TAR / clisp-1995-01-01 / amiga / jchlib / misc / setmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-19  |  1.6 KB  |  55 lines

  1. #include <exec/types.h>
  2. #include <dos/dosextens.h>
  3.  
  4. #include <inline/exec.h>
  5. #include <inline/dos.h>
  6.  
  7. /* From Ralph Babel, The Amiga GURU book, p. 278 */
  8. /* SetMode() for pre-2.0 systems         */
  9.  
  10. typedef struct StandardPacket StdPkt;
  11.  
  12. LONG setmode(BPTR fh, LONG mode)
  13. { register struct MsgPort *fh_type = ((struct FileHandle *)BADDR(fh))->fh_Type;
  14.   if (NULL == fh_type) return DOSFALSE; /* NIL: has no message port */
  15.                /* should also set Result2 */
  16.   else
  17.     { struct MsgPort *mp;
  18.       char SP[sizeof(StdPkt) + 2]; /* LONG-align, 2 is enough since stack is even */
  19.       register StdPkt *sp = (StdPkt *)((ULONG)(SP + 2) & ~3);
  20.  
  21.       mp = &((struct Process *)FindTask(NULL))->pr_MsgPort;
  22.  
  23.       sp->sp_Msg.mn_Node.ln_Name = (char *)&sp->sp_Pkt;
  24.       sp->sp_Pkt.dp_Link     = &sp->sp_Msg;
  25.       sp->sp_Pkt.dp_Port     = mp;
  26.       sp->sp_Pkt.dp_Type     = ACTION_SCREEN_MODE;
  27.       sp->sp_Pkt.dp_Arg1     = mode; /* DOSFALSE (0) for CON */
  28.  
  29.       PutMsg(fh_type, &sp->sp_Msg);
  30.       (void)WaitPort(mp);
  31.       (void)GetMsg(mp);        /* assumes that no other packets are pending */
  32.       return sp->sp_Pkt.dp_Res1;
  33.     }
  34. }
  35.  
  36.  
  37. #if defined(MAIN) && defined(JCHLIB) /* make a very small executable */
  38.  
  39. /*struct ExecBase * SysBase;*/
  40. struct DosLibrary * DOSBase = NULL;
  41. /* UWORD _OS_Version; */
  42.  
  43. /* With no arg, set CON: mode, else RAW: on the Input() filehandle */
  44.  
  45. LONG _main(LONG arglen, UBYTE* arg)
  46. {
  47.   LONG res;
  48.   if (NULL == (DOSBase = (struct DosLibrary *)OpenLibrary(DOSNAME,0L)))
  49.     { return 20; }    /* don't use exit()! */
  50.   res = setmode(Input(), arglen > 1 ? DOSTRUE : DOSFALSE);
  51.   CloseLibrary((struct Library *)DOSBase);
  52.   return res /* DOSTRUE */ ? 0 : 5;
  53. }
  54. #endif
  55.