phillip@cbmvax.cbm.UUCP (Phillip Lindsay) (09/02/86)
[eat me I'm yours] Here is a general purpose subroutine to send AmigaDos packets...It works well with Aztec 16or32...Have not tried it under Lattice. ============================================================================== Phillip Lindsay - Commodore Business Machines - Amiga Technical Support uucp: {ihnp4|seismo|caip}!cbmvax!phillip arpa: cbmvax!phillip@seismo -or- phillip@cbmvax.UUCP@{seismo | harvard} Tel.: (215) 431-9180 ============================================================================== ***CUT HERE /* sendpacket.c - send packet to dos handler */ /* Phillip Lindsay - Commodore-Amiga */ #include "exec/types.h" #include "exec/ports.h" #include "exec/io.h" #include "exec/memory.h" #include "libraries/dos.h" #include "libraries/dosextens.h" #include <stdio.h> #include "functions.h" /* aztec C include */ #define ACTION_SCREEN_MODE 994L /* The packet type we will be playing with */ #define DOSTRUE -1L /* AmigaDos TRUE */ #define MAXARGS 7L /* limit in packet structure (dosextens.h) */ long sendpkt(pid,action,args,nargs) struct MsgPort *pid; /* process indentifier ... (handlers message port ) */ long action, /* packet type ... (what you want handler to do ) */ args[], /* a pointer to a argument list */ nargs; /* number of arguments in list */ { struct MsgPort *replyport; struct StandardPacket *packet; long count, *pargs, res1; if(nargs > MAXARGS) exit(FALSE); replyport = (struct MsgPort *) CreatePort(NULL,NULL); /* make reply port */ if(!replyport) return(NULL); packet = (struct StandardPacket *) AllocMem((long)sizeof(*packet),MEMF_PUBLIC | MEMF_CLEAR); if(!packet) { FreeMem(packet,(long)sizeof(*packet)); return(NULL); } packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt); /* link packet- */ packet->sp_Pkt.dp_Link = &(packet->sp_Msg); /* to message */ packet->sp_Pkt.dp_Port = replyport; /* set-up reply port */ packet->sp_Pkt.dp_Type = action; /* what to do... */ /* move all the arguments to the packet */ pargs = &(packet->sp_Pkt.dp_Arg1); /* address of first argument */ for(count=NULL;count < nargs;count++) pargs[count]=args[count]; PutMsg(pid,packet); /* send packet */ #ifdef DEBUG kprintf("Waiting for packet...\n"); #endif WaitPort(replyport); /* wait for packet to come back */ GetMsg(replyport); /* pull message */ res1 = packet->sp_Pkt.dp_Res1; /* get result */ /* all done clean up */ FreeMem(packet,(long)sizeof(*packet)); DeletePort(replyport); return(res1); } /* end of sendpkt.c */ /* start of example */ #define NARGS 1L /* number of arguments */ #define ESC 27L main() { struct MsgPort *conid; /* for process id */ long arg[NARGS] /* array of arguments */ ,res1; /* holds result */ struct Process *myprocess; /* me! */ UBYTE a_char; /* our input */ myprocess = (struct Process *) FindTask(NULL); conid = (struct MsgPort *) myprocess->pr_ConsoleTask; /* get console handler */ arg[0]=DOSTRUE; /* arg1=TRUE - set RAW mode */ res1 = sendpkt(conid,ACTION_SCREEN_MODE,arg,NARGS); if(!res1) exit(TRUE); /* error? */ puts("In RAW: mode...type something...press ESC to exit."); while((a_char=getchar()) != ESC) putchar(a_char); arg[0]=FALSE; /* turn RAW mode off */ res1 = sendpkt(conid,ACTION_SCREEN_MODE,arg,NARGS); } /* eof */ -- ============================================================================== Phillip Lindsay - Commodore Business Machines - Amiga Technical Support uucp: {ihnp4|seismo|caip}!cbmvax!phillip arpa: cbmvax!phillip@seismo -or- phillip@cbmvax.UUCP@{seismo | harvard} Tel.: (215) 431-9180 ==============================================================================