home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-1.LHA / CLISP960530-sr.lha / amiga / jchlib / misc / setmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-09  |  1.9 KB  |  61 lines

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