Path: utzoo!attcan!uunet!husc6!rutgers!rochester!udel!mmdf From: iphwk%MTSUNIX1.BITNET@cunyvm.cuny.edu (Bill Kinnersley) Newsgroups: comp.sys.amiga Subject: Re: ARP commands--How do you make them so small? Message-ID: <3633@louie.udel.EDU> Date: 7 Aug 88 22:55:09 GMT Sender: mmdf@udel.EDU Lines: 336 [In "Re: ARP commands--How do you make them so small?", Kim DeVaughn said:] > > In article <1702@eneevax.UUCP>, lbruck@eneevax.UUCP (Lewis S.Bruck) writes: > > In article <444@jc3b21.UUCP> fgd3@jc3b21.UUCP (Fabbian G. Dufoe) writes: > > > I thought the idea behind ARP was to rewrite AmigaDOS in C. Are you > > >sure everything is done in assembler? Was that a departure from the > > >original intention or did I just misunderstand? > > > > I think the intention was to get the commands away from BCPL (the native > > language of TRIPOS, on which AmigaDOS was based). This allowed better > integration > > into the C-based environment of the Amiga (in terms of data structures and > > data types (bye bye BPTRs). Another goal was standardizing the syntax of > > the commands and giving a more useful wildcard implementation. > > Exactly right, Lewis. And while I can't say that positively *everything* > is in assembler, I believe that that is the case. Certainly the majority > of the ARP distribution is (user commands, and arp.library, that is). > BCPL commands have a considerable size advantage over C simply because they access their own run-time library in Kickstart. This library is not directly available to C programs. Some of the calls in that library have been brought out and made available to the C world as the AmigaDOS library. Some of them duplicate what you would find in c.lib or lc.lib. A few of them, however, are not otherwise available. So there's more than just a size advantage. BCPL programs can do things that C programs cannot! Instead of going the ARP route and writing everything in assembler, an easier approach is to find a way to interface C to this library. An example of how to do this is shown below. To avoid flames I've shortened this to the bare minimum. If anyone is interested, I can mail them further details on the contents of the library, and replacement programs written in C for: newcli.c endcli.c run.c Bill Kinnersley Physics Department BITNET: iphwk@mtsunix1 Montana State University INTERNET: iphwk%mtsunix1.bitnet@cunyvm.cuny.edu Bozeman, MT 59717 CSNET: iphwk%mtsunix1.bitnet@relay.cs.net (406)994-3614 UUCP: ...psuvax1!mtsunix1.bitnet!iphwk "This message was packed as full as practicable by modern electronic equipment. Some settling of contents may have occurred during transmission." ------------------ /* hello.c - An Example Of Calling The BCPL Library From C /* /* Compile and link with Manx 3.4: /* cc hello /* ln hello.o bcpllib.o -lc /* /* Author: Bill Kinnersley /* Date: Mar 12, 1988 /* Mail: Physics Dept. /* Montana State University /* Bozeman, MT 59717 /* BITNET: iphwk@mtsunix1 /* INTERNET: iphwk%mtsunix1.bitnet@cunyvm.cuny.edu /* UUCP: psuvax1!mtsunix1.bitnet!iphwk */ #include #include #include #include "BCPL.h" void *AllocMem(); extern long *a; main() { long proc, root, n, num; struct Process *mytask; char *s, *t, *buf; BPTR bs, bt; BCPLInit(); proc = BCPL(FINDTASK); printf("My CLI Process is at %lx\n",proc); root = BCPL(FINDROOT); printf("The root is at %lx\n", root); s = "Here's a tab:%T5, a signed:%N, and an unsigned:%U8\n"; bs = MakeBSTR(s); BCPL(WRITEF, bs, -1L, -1L); BCPL(NEWLINE); FreeBSTR(bs); BCPLQuit(); } ------------------- /* bcpllib.c - An Interface Permitting Calls To The BCPL Library From C /* /* Compile using Manx 3.4a /* cc bcpllib.c /* /* Author: Bill Kinnersley /* Date: Mar 12, 1988 /* Mail: Physics Dept. /* Montana State University /* Bozeman, MT 59717 /* BITNET: iphwk@mtsunix1 /* INTERNET: iphwk%mtsunix1.bitnet@cunyvm.cuny.edu /* UUCP: psuvax1!mtsunix1.bitnet!iphwk */ #include #include #include long a0[3], /* for a copy of the BCPL registers */ *a1, *a; BCPLInit() { struct DosLibrary *doslib; struct Task *mytask; long *splower; doslib = (struct DosLibrary *)OpenLibrary("dos.library",0L); a0[0] = doslib->dl_A2; a0[1] = doslib->dl_A5; a0[2] = doslib->dl_A6; a1 = (long *)AllocMem(2000L, MEMF_CLEAR); a = &a1[3]; /* a points to memory allocated for my BCPL stack. (Yes, I know, I could have put this on the process stack) */ } BCPLQuit() { FreeMem(a1, 2000L); } long BCPL(n) long n; { #asm movem.l d4-d7/a2-a5,-(a7) movea.l a7,a0 adda.l #40,a0 movem.l (a0),d0-d4 adda.l #4,a0 movea.l _a,a1 moveq #9,d5 l1: move.l (a0)+,(a1)+ dbf d5,l1 movea.l _a1,a1 lea _a0,a0 movem.l (a0)+,a2/a5-a6 suba.l a0,a0 move.l 0(a2,d0.l),a4 moveq #$c,d0 jsr (a5) move.l d1,d0 movem.l (a7)+,d4-d7/a2-a5 #endasm } BPTR MakeBSTR(s) char *s; { long len; char *bs; len = (long)strlen(s); bs = (char *)AllocMem(len+2L,MEMF_CLEAR); if (!bs) {printf("Can't allocate\n"); exit(0);} bs[0] = len; strcpy(&bs[1], s); return ((long)bs)>>2; } FreeBSTR(bs) long bs; { char *s; s = (char *)BADDR(bs); FreeMem(s,(long)(*s)+2L); } ---------------- /* bcpl.h - Header File To Allow Calls To The BCPL Library /* From C Language Programs /* Author: Bill Kinnersley /* Date: Mar 12, 1988 /* Mail:Physics Dept. /* Montana State University /* Bozeman, MT 59717 /* BITNET: iphwk@mtsunix1 /* INTERNET: iphwk%mtsunix1.bitnet@cunyvm.cuny.edu /* UUCP: psuvax1!mtsunix1.bitnet!iphwk */ long BCPLInit(), BCPL(), MakeBSTR(); #define bptr(p) (((long)p) >>2) #define SYSREQUEST -0x84L #define TOCSTR -0x80L #define TOBSTR -0x7cL #define EXECUTEC -0x6cL #define ISINTERACT -0x68L #define DATESTAMPC -0x64L #define SETPROTECT -0x60L #define SETCOMMENT -0x5cL #define DEVICEPROCC -0x58L #define QUEUEPKT -0x54L #define CLEARMEM -0x50L #define LOADSEG -0x4cL #define CREATEPROCC -0x48L #define IOERR -0x44L #define CURRENTDIR -0x40L #define CREATEDIRC -0x3cL #define INFO -0x38L #define EXNEXT -0x34L #define EXAMINE -0x30L #define LOCKC -0x2cL #define RENAMEC -0x28L #define DELETEFILE -0x24L #define SEEK -0x20L #define WRITE -0x18L #define READ -0xcL #define STRNCPY -0x8L #define OPEN -0x4L #define START 0x4L #define EXIT 0x8L #define MULTIPLY 0xcL #define DIVIDE 0x10L #define MOD 0x14L #define SETIO 0x18L #define PACKLW 0x20L #define UNPACKLW 0x24L #define SETRES2 0x28L #define MAKEGV 0x34L #define FINDTASK 0x38L #define GETBYTE 0x3cL #define PUTBYTE 0x40L #define LEVEL 0x44L #define LONGJUMP1 0x48L #define ALLOCMEM 0x4cL #define LONGJUMP2 0x50L #define DOIO 0x54L #define SENDIO 0x58L #define CREATECO 0x5cL #define DELETECO 0x60L #define CALLCO 0x64L #define COWAIT 0x68L #define RESUMECO 0x6cL #define INSTALLSEG 0x70L #define GETVEC1 0x74L #define FREEVEC 0x78L #define OPENDEV 0x7cL #define CLOSEDEV 0x80L #define CREATEPROCB 0x84L #define REMPROCESS 0x88L #define PARENTDIR 0x8cL #define SETSIGS 0x90L #define CLEARSIGS 0x94L #define DOSALERT 0x98L #define FINDROOT 0x9cL #define READINC 0xa0L #define TASKWAIT1 0xa4L /* same as 190 */ #define PUTPKT 0xa8L #define WRITEOUTC 0xacL #define PACKSTRING 0xb0L #define UNPACKSTRING 0xb4L #define HOLDTASK 0xb8L #define DELAY 0xbcL #define SENDPKT 0xc0L #define RETURNPKT 0xc4L #define OPENWINDOW 0xc8L #define SETCURDIR 0xccL #define BUILDSYSREQ 0xd0L #define WRITET 0xd4L #define RDCH 0xd8L #define UNRDCH 0xdcL #define WRCH 0xe0L #define READINB 0xe4L #define WRITEOUTB 0xe8L #define FINDINPUT 0xecL #define FINDOUTPUT 0xf0L #define SELECTINPUT 0xf4L #define SELECTOUTPUT 0xf8L #define ENDREAD 0xfcL #define ENDWRITE 0x100L #define INPUT 0x104L #define OUTPUT 0x108L #define READN 0x10cL #define NEWLINE 0x110L #define WRITEI 0x114L #define WRITEN 0x118L #define WRITEHEX 0x11cL #define WRITEOCT 0x120L #define WRITES 0x124L #define WRITEF 0x128L #define TOUPPER 0x12cL #define CHARCMP 0x130L #define STRCMP 0x134L #define RDARGS 0x138L #define RDLINE 0x13cL #define PARSESTRING 0x140L #define LOAD 0x144L #define UNLOAD 0x148L #define TIDYUP 0x150L #define ADDDEVICE 0x154L #define DATESTAMPB 0x158L #define WAITFORCHAR 0x15cL #define EXECLIB 0x160L #define FINDSEGARRAY 0x164L #define DELETEOBJ 0x168L #define RENAMEB 0x16cL #define CLOSE 0x174L #define GETWORD 0x178L #define PUTWORD 0x17cL #define TASKWAIT2 0x190L /* same as a4 */ #define EXECUTEB 0x194L #define DEVICEPROCB 0x198L #define LIBCALL 0x19cL #define WRITEERR 0x1a0L #define FINDCONHAND 0x1a4L #define FINDFILEHAND 0x1a8L #define EXTDEVNAME 0x1acL #define LOCKB1 0x1b0L /* same as 1ec */ #define UNLOCK 0x1b4L #define GETLONG 0x1b8L #define PUTLONG 0x1bcL #define OPENFILE 0x1c0L #define DUPLOCK 0x1c4L #define MAKESYSREQ 0x1c8L #define STRCPY 0x1ccL #define RUNLOADED 0x1e4L #define LOCKB2 0x1ecL /* same as 1b0 */ #define FINDDEVINFO 0x1f0L #define CREATEDIRB 0x1f4L #define CMPTIME 0x1f8L #define TIMERIO 0x1fcL #define SETTIME 0x200L #define FINDCLI 0x218L ----------------