From: Ken Thompson Date: Wed, 10 Jan 1979 20:09:28 +0000 (-0500) Subject: Research V7 development X-Git-Tag: Bell-32V^2~411 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/95af7ab2d90729e750f20e0b6086879658a3a427?ds=inline Research V7 development Work on file usr/src/cmd/bas/bas.s Work on file usr/src/cmd/bas/makefile Work on file usr/src/cmd/plot/makefile Work on file usr/src/cmd/plot/driver.c Work on file usr/src/cmd/plot/vplot.c Work on file usr/src/cmd/plot/chrtab.c Synthesized-from: v7 --- diff --git a/usr/src/cmd/bas/bas.s b/usr/src/cmd/bas/bas.s new file mode 100644 index 0000000000..19c65d0280 --- /dev/null +++ b/usr/src/cmd/bas/bas.s @@ -0,0 +1,2128 @@ +/ +/ + +/ bas0 -- basic + +scope = 1 +.globl main +.globl sin, cos, log, exp, atan, pow, sqrt +.globl rand, srand +.globl fptrap +.globl fopen, getc + +indir = 0 /for indirect sys calls. (not in as) +one = 40200 + +main: + mov $1,prfile /initial print file + sys signal; 4; fptrap + setd + sys time + mov r1,r0 + mov r0,randx + jsr pc,srand + sys signal; 1; _done + sys signal; 2; intrup + tst r0 + jeq 1f + sys signal; 2; 1 +1: + mov sp,gsp + clr seeka + mov $'a,r1 +1: + movb r1,tmpf+8 + sys stat; tmpf; line + bes 1f + inc r1 + cmp r1,$'z + blos 1b + br 2f +1: + sys creat; tmpf; 600 + bes 2f + mov r0,tfo + sys open; tmpf; 0 + bec 1f +2: + mov $3f,r0 + jsr pc,print + sys exit +3: + ; .even +1: + mov r0,tfi + + mov gsp,sp + cmp (sp),$2 /is there a file argument + blt noarg + mov 4(sp),r0 + mov $argname,r1 +1: + movb (r0)+,(r1)+ + bne 1b +aftered: / after edit + mov $argname,r0 + jsr r5,fopen; iobuf + bes 1f +noarg: + jsr pc,isymtab + br loop +1: + mov $1f,r0 + jsr pc,print + br loop +1: + ; .even + +intrup: + sys signal; 2; intrup + mov $'\n,r0 + jsr r5,xputc + jsr r5,error + ; .even + +loop: + mov gsp,sp + clr lineno + jsr pc,rdline + mov $line,r3 +1: + movb (r3),r0 + jsr pc,digit + br 1f + jsr r5,atoi + cmp r0,$' / + beq 3f + cmp r0,$' /tab + bne 1f +3: + mov $lintab,r3 + mov r1,r0 + bgt 2f + jsr pc,serror +2: + cmp r0,(r3) + beq 2f + tst (r3) + beq 2f + add $6,r3 + br 2b +2: + cmp r3,$elintab-12. + blo 2f + jsr r5,error + ; .even +2: + mov r0,(r3)+ + mov seeka,(r3)+ + mov tfo,r0 + mov seeka,seekx + sys indir; sysseek + mov $line,r0 + jsr pc,size + inc r0 + add r0,seeka + mov r0,wlen + mov tfo,r0 + mov $line,wbuf + sys indir;syswrit + br loop +1: + mov $line,r3 + jsr pc,singstat + br loop + +nextc: + movb (r3)+,r0 + rts r5 + +size: + clr -(sp) +1: + inc (sp) + cmpb (r0),$'\n + beq 1f + cmpb (r0),$0 + beq 1f + inc r0 + br 1b +1: + mov (sp)+,r0 + rts pc + +rdline: / read input (file or tty) to carr. ret. + mov $line,r1 +1: + jsr r5,getc; iobuf + bes 2f + tst r0 + beq 2f + cmp r1,$line+99. + bhis 2f / bad check, but a check + movb r0,(r1)+ + cmpb r0,$'\n + bne 1b + clrb (r1) + rts pc +2: + mov fi,r0 + beq 1f + sys close + clr fi + br 1b +1: + jmp _done + +error: + tst fi + beq 1f + sys close + clr fi +1: + tst lineno + beq 1f + jsr pc,nextlin + br 1f + mov $line,r0 + jsr pc,print +1: + mov r5,r0 + jsr pc,print + jmp loop + +serror: + dec r3 + tst fi + beq 1f + sys close + clr fi +1: + mov $line,r1 +1: + cmp r1,r3 + bne 2f + mov $'_,r0 + jsr r5,xputc + mov $10,r0 + jsr r5,xputc +2: + movb (r1),r0 + jsr r5,xputc + cmpb (r1)+,$'\n + bne 1b + jmp loop + +print: + mov r0,wbuf + jsr pc,size + mov r0,wlen + mov prfile,r0 + sys indir; syswrit + rts pc + +digit: + cmp r0,$'0 + blo 1f + cmp r0,$'9 + bhi 1f + add $2,(sp) +1: + rts pc + +alpha: + cmp r0,$'a + blo 1f + cmp r0,$'z + bhi 1f + add $2,(sp) +1: + cmp r0,$'A + blo 1f + cmp r0,$'Z + bhi 1f + add $2,(sp) +1: + rts pc + +name: + mov $nameb,r1 + clr (r1) + clr 2(r1) +1: + cmp r1,$nameb+4 + bhis 2f + movb r0,(r1)+ +2: + movb (r3)+,r0 + jsr pc,alpha + br 2f + br 1b +2: + jsr pc,digit + br 2f + br 1b +2: + mov $resnam,r1 +1: + cmp nameb,(r1) + bne 2f + cmp nameb+2,2(r1) + bne 2f + sub $resnam,r1 + asr r1 + add $2,(sp) + rts pc +2: + add $4,r1 + cmp r1,$eresnam + blo 1b + mov $symtab,r1 +1: + tst (r1) + beq 1f + cmp nameb,(r1) + bne 2f + cmp nameb+2,2(r1) + bne 2f + rts pc +2: + add $14.,r1 + br 1b +1: + cmp r1,$esymtab-28. + blo 1f + jsr r5,error + ; .even +1: + mov nameb,(r1) + mov nameb+2,2(r1) + clr 4(r1) + clr 14.(r1) + rts pc + +skip: + cmp r0,$' / + beq 1f + cmp r0,$' / tab + bne 2f +1: + movb (r3)+,r0 + br skip +2: + rts pc + +xputc: +.if scope / for plotting + tstb drflg + beq 1f + jsr pc,drput + rts r5 +1: +.endif + mov r0,ch + mov $1,r0 + sys write; ch; 1 + rts r5 + +nextlin: + clr -(sp) + mov $lintab,r1 +1: + tst (r1) + beq 1f + cmp lineno,(r1) + bhi 2f + mov (sp),r0 + beq 3f + cmp (r0),(r1) + blos 2f +3: + mov r1,(sp) +2: + add $6,r1 + br 1b +1: + mov (sp)+,r1 + beq 1f + mov (r1)+,lineno + mov (r1)+,seekx + mov tfi,r0 + sys indir; sysseek + mov tfi,r0 + sys read; line; 100. + add $2,(sp) +1: + rts pc + +getloc: + mov $lintab,r1 +1: + tst (r1) + beq 1f + cmp r0,(r1) + beq 2f + add $6,r1 + br 1b +1: + jsr r5,error + +argname: +vt: +.even +pname: <\0\0\0\0\0\0> + .even + +resnam: + + + + + + / prompt is like print without \n (cr) + + + + + + + + + + + + / comment +.if scope / for plotting + + + +.endif +eresnam: + +symtnam: + + + + + + + + + + + + +esymtnam: + +/ indirect sys calls: +sysseek: sys lseek; 0; seekx: 0; 0 +syswrit: sys write; wbuf: 0; wlen: 0 +sysread: sys read; rbuf: 0; rlen: 0 +sysopen: sys open; ofile: 0 ; omode: 0 +syscreat: sys creat; cfile: 0; cmode: 0 +.bss +drx: .=.+8 +dry: .=.+8 +drfo: .=.+2 +ch: .=.+2 +drflg: .=.+2 +randx: .=.+2 +gsp: .=.+2 +forp: .=.+2 +exprloc:.=.+2 +sstack: .=.+2 +sublev: .=.+2 +val: .=.+2 +splimit: .=.+2 / statement size limit +iflev: .=.+20. / nested if compile stack: 10 deep +ifp: .=.+2 / current pointer to iflev +line: .=.+100. +prfile: .=.+2 / output from _list or _save +tfi: .=.+2 / input file +lastpr: .=.+8 / last printed number +func: .=.+2 / alternate functions, eg: _list or _save +seeka: .=.+2 / seek offset 1 +lineno: .=.+2 +nameb: .=.+4 +tfo: .=.+2 +symtab: .=.+2800.; esymtab: / symbol=7wds; symtab for 200 +space: .=.+8000.; espace: / code space +exline: .=.+1000.; eexline: / line execute space +lintab: .=.+1800.; elintab: / 3wds per statement = 300 stmts +stack: .=.+800.; estack: + +iobuf: fi: .=.+518. / should be acquired?? diff --git a/usr/src/cmd/bas/makefile b/usr/src/cmd/bas/makefile new file mode 100644 index 0000000000..4fc8b3e9f8 --- /dev/null +++ b/usr/src/cmd/bas/makefile @@ -0,0 +1,5 @@ +bas cp cmp: + @echo Sorry, the bas source will not compile + @echo the object because it calls for old-style + @echo library routines. + @echo It\'s here just in case you want to play. diff --git a/usr/src/cmd/plot/chrtab.c b/usr/src/cmd/plot/chrtab.c new file mode 100644 index 0000000000..4d8a81acc9 --- /dev/null +++ b/usr/src/cmd/plot/chrtab.c @@ -0,0 +1,98 @@ +char chrtab[][16] = { +0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, sp, */ +0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0010,0000,0000,0000,0000,0000, /*, !, */ +0024,0024,0024,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ", */ +0000,0000,0000,0044,0044,0176,0044,0044,0176,0044,0044,0000,0000,0000,0000,0000, /*, #, */ +0000,0010,0010,0010,0076,0101,0100,0076,0001,0101,0076,0010,0010,0000,0000,0000, /*, $, */ +0000,0000,0000,0141,0142,0004,0010,0010,0020,0043,0103,0000,0000,0000,0000,0000, /*, %, */ +0000,0000,0070,0104,0110,0060,0060,0111,0106,0106,0071,0000,0000,0000,0000,0000, /*, &, */ +0004,0010,0020,0040,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ', */ +0000,0004,0010,0020,0040,0040,0040,0040,0040,0040,0020,0010,0004,0000,0000,0000, /*, (, */ +0000,0040,0020,0010,0004,0004,0004,0004,0004,0004,0010,0020,0040,0000,0000,0000, /*, ), */ +0000,0000,0000,0010,0111,0052,0034,0177,0034,0052,0111,0010,0000,0000,0000,0000, /*, *, */ +0000,0000,0000,0000,0010,0010,0010,0177,0010,0010,0010,0000,0000,0000,0000,0000, /*, +, */ +0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0010,0020,0000,0000,0000, /*, ,, */ +0000,0000,0000,0000,0000,0000,0000,0176,0000,0000,0000,0000,0000,0000,0000,0000, /*, -, */ +0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0000,0000,0000,0000,0000, /*, ., */ +0000,0000,0001,0002,0004,0010,0010,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, /, */ +0000,0030,0044,0102,0102,0102,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 0, */ +0000,0010,0030,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, 1, */ +0000,0070,0104,0004,0004,0010,0020,0040,0100,0100,0174,0000,0000,0000,0000,0000, /*, 2, */ +0000,0176,0004,0004,0010,0014,0002,0002,0002,0104,0070,0000,0000,0000,0000,0000, /*, 3, */ +0000,0004,0014,0024,0044,0104,0176,0004,0004,0004,0004,0000,0000,0000,0000,0000, /*, 4, */ +0000,0174,0100,0100,0130,0144,0002,0002,0102,0044,0030,0000,0000,0000,0000,0000, /*, 5, */ +0000,0074,0102,0100,0130,0144,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 6, */ +0000,0176,0004,0004,0010,0010,0020,0020,0040,0040,0040,0000,0000,0000,0000,0000, /*, 7, */ +0000,0034,0042,0101,0042,0076,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, 8, */ +0000,0034,0042,0101,0101,0101,0043,0036,0004,0010,0020,0040,0000,0000,0000,0000, /*, 9, */ +0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0000,0000,0000,0000,0000, /*, :, */ +0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0020,0040,0000,0000,0000, /*, ;, */ +0002,0004,0010,0020,0040,0100,0040,0020,0010,0004,0002,0000,0000,0000,0000,0000, /*, <, */ +0000,0000,0000,0000,0177,0000,0177,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, =, */ +0100,0040,0020,0010,0004,0002,0004,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, >, */ +0000,0030,0044,0102,0001,0002,0004,0010,0010,0000,0010,0000,0000,0000,0000,0000, /*, ?, */ +0000,0074,0102,0101,0115,0123,0121,0121,0121,0111,0046,0000,0000,0000,0000,0000, /*, @, */ +0000,0010,0024,0042,0101,0101,0177,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, A, */ +0000,0176,0101,0101,0101,0176,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, B, */ +0000,0076,0101,0100,0100,0100,0100,0100,0100,0101,0076,0000,0000,0000,0000,0000, /*, C, */ +0000,0176,0101,0101,0101,0101,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, D, */ +0000,0176,0100,0100,0100,0170,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, E, */ +0000,0177,0100,0100,0100,0174,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, F, */ +0000,0076,0101,0100,0100,0117,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, G, */ +0000,0101,0101,0101,0101,0176,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, H, */ +0000,0034,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, I, */ +0000,0016,0004,0004,0004,0004,0004,0004,0104,0104,0070,0000,0000,0000,0000,0000, /*, J, */ +0000,0101,0102,0104,0110,0120,0160,0110,0104,0102,0101,0000,0000,0000,0000,0000, /*, K, */ +0000,0100,0100,0100,0100,0100,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, L, */ +0000,0101,0143,0125,0111,0101,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, M, */ +0000,0101,0141,0121,0111,0105,0103,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, N, */ +0000,0076,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, O, */ +0000,0176,0101,0101,0101,0176,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, P, */ +0000,0076,0101,0101,0101,0101,0101,0101,0131,0105,0076,0002,0001,0000,0000,0000, /*, Q, */ +0000,0176,0101,0101,0101,0176,0104,0102,0101,0101,0101,0000,0000,0000,0000,0000, /*, R, */ +0000,0076,0101,0100,0100,0076,0001,0001,0001,0101,0076,0000,0000,0000,0000,0000, /*, S, */ +0000,0177,0010,0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, T, */ +0000,0101,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, U, */ +0000,0101,0101,0101,0101,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, V, */ +0000,0101,0101,0101,0101,0111,0111,0125,0143,0101,0101,0000,0000,0000,0000,0000, /*, W, */ +0000,0101,0101,0042,0024,0010,0024,0042,0101,0101,0101,0000,0000,0000,0000,0000, /*, X, */ +0000,0101,0042,0024,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, Y, */ +0000,0177,0001,0002,0004,0010,0020,0040,0100,0100,0177,0000,0000,0000,0000,0000, /*, Z, */ +0000,0034,0020,0020,0020,0020,0020,0020,0020,0020,0020,0034,0000,0000,0000,0000, /*, [, */ +0000,0000,0100,0040,0020,0010,0010,0010,0004,0002,0001,0000,0000,0000,0000,0000, /*, , \, */ +0000,0070,0010,0010,0010,0010,0010,0010,0010,0010,0010,0070,0000,0000,0000,0000, /*, ], */ +0010,0024,0042,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ^, */ +0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0377,0000,0000, /*, _, */ +0040,0020,0010,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, `, */ +0000,0000,0000,0000,0000,0074,0002,0076,0102,0102,0076,0000,0000,0000,0000,0000, /*, a, */ +0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0174,0000,0000,0000,0000,0000, /*, b, */ +0000,0000,0000,0000,0000,0074,0102,0100,0100,0102,0074,0000,0000,0000,0000,0000, /*, c, */ +0002,0002,0002,0002,0002,0076,0102,0102,0102,0102,0076,0000,0000,0000,0000,0000, /*, d, */ +0000,0000,0000,0000,0000,0074,0102,0174,0100,0102,0074,0000,0000,0000,0000,0000, /*, e, */ +0000,0016,0020,0020,0020,0176,0020,0020,0020,0020,0020,0000,0000,0000,0000,0000, /*, f, */ +0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0102,0076,0000, /*, g, */ +0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, h, */ +0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, i, */ +0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0010,0010,0010,0050,0020,0000, /*, j, */ +0000,0100,0100,0100,0100,0106,0110,0120,0160,0110,0106,0000,0000,0000,0000,0000, /*, k, */ +0000,0030,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, l, */ +0000,0000,0000,0000,0000,0166,0111,0111,0111,0111,0111,0000,0000,0000,0000,0000, /*, m, */ +0000,0000,0000,0000,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, n, */ +0000,0000,0000,0000,0000,0074,0102,0102,0102,0102,0074,0000,0000,0000,0000,0000, /*, o, */ +0000,0000,0000,0000,0000,0174,0102,0102,0102,0102,0174,0100,0100,0100,0100,0000, /*, p, */ +0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0002,0002,0000, /*, q, */ +0000,0000,0000,0000,0000,0134,0142,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, r, */ +0000,0000,0000,0000,0000,0076,0100,0074,0002,0102,0074,0000,0000,0000,0000,0000, /*, s, */ +0000,0020,0020,0020,0020,0176,0020,0020,0020,0020,0014,0000,0000,0000,0000,0000, /*, t, */ +0000,0000,0000,0000,0000,0102,0102,0102,0102,0102,0075,0000,0000,0000,0000,0000, /*, u, */ +0000,0000,0000,0000,0000,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, v, */ +0000,0000,0000,0000,0000,0111,0111,0111,0111,0111,0066,0000,0000,0000,0000,0000, /*, w, */ +0000,0000,0000,0000,0000,0102,0044,0030,0030,0044,0102,0000,0000,0000,0000,0000, /*, x, */ +0000,0000,0000,0000,0000,0102,0102,0102,0042,0024,0010,0020,0040,0100,0000,0000, /*, y, */ +0000,0000,0000,0000,0000,0176,0004,0010,0020,0040,0176,0000,0000,0000,0000,0000, /*, z, */ +0000,0014,0020,0020,0020,0020,0040,0020,0020,0020,0020,0014,0000,0000,0000,0000, /*, {, */ +0000,0010,0010,0010,0010,0000,0000,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, |, */ +0000,0030,0010,0010,0010,0010,0004,0010,0010,0010,0010,0030,0000,0000,0000,0000, /*, }, */ +0020,0052,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ~, */ +0000,0176,0176,0176,0176,0176,0176,0176,0176,0176,0176,0000,0000,0000,0000,0000, /*, del, */ +}; diff --git a/usr/src/cmd/plot/driver.c b/usr/src/cmd/plot/driver.c new file mode 100644 index 0000000000..52d0b1f30c --- /dev/null +++ b/usr/src/cmd/plot/driver.c @@ -0,0 +1,128 @@ +#include + +float deltx; +float delty; + +main(argc,argv) char **argv; { + int std=1; + FILE *fin; + + while(argc-- > 1) { + if(*argv[1] == '-') + switch(argv[1][1]) { + case 'l': + deltx = atoi(&argv[1][2]) - 1; + break; + case 'w': + delty = atoi(&argv[1][2]) - 1; + break; + } + + else { + std = 0; + if ((fin = fopen(argv[1], "r")) == NULL) { + fprintf(stderr, "can't open %s\n", argv[1]); + exit(1); + } + fplt(fin); + } + argv++; + } + if (std) + fplt( stdin ); + exit(0); + } + + +fplt(fin) FILE *fin; { + int c; + char s[256]; + int xi,yi,x0,y0,x1,y1,r,dx,n,i; + int pat[256]; + + openpl(); + while((c=getc(fin)) != EOF){ + switch(c){ + case 'm': + xi = getsi(fin); + yi = getsi(fin); + move(xi,yi); + break; + case 'l': + x0 = getsi(fin); + y0 = getsi(fin); + x1 = getsi(fin); + y1 = getsi(fin); + line(x0,y0,x1,y1); + break; + case 't': + gets(s,fin); + label(s); + break; + case 'e': + erase(); + break; + case 'p': + xi = getsi(fin); + yi = getsi(fin); + point(xi,yi); + break; + case 'n': + xi = getsi(fin); + yi = getsi(fin); + cont(xi,yi); + break; + case 's': + x0 = getsi(fin); + y0 = getsi(fin); + x1 = getsi(fin); + y1 = getsi(fin); + space(x0,y0,x1,y1); + break; + case 'a': + xi = getsi(fin); + yi = getsi(fin); + x0 = getsi(fin); + y0 = getsi(fin); + x1 = getsi(fin); + y1 = getsi(fin); + arc(xi,yi,x0,y0,x1,y1); + break; + case 'c': + xi = getsi(fin); + yi = getsi(fin); + r = getsi(fin); + circle(xi,yi,r); + break; + case 'f': + gets(s,fin); + linemod(s); + break; + case 'd': + xi = getsi(fin); + yi = getsi(fin); + dx = getsi(fin); + n = getsi(fin); + for(i=0; i + +#define NB 88 +#define BSIZ 512 +#define mapx(x) ((1536*((x)-botx)/del)+centx) +#define mapy(y) ((1536*(del-(y)+boty)/del)-centy) +#define SOLID -1 +#define DOTTED 014 +#define SHORTDASHED 034 +#define DOTDASHED 054 +#define LONGDASHED 074 +#define SETSTATE (('v'<<8)+1) + +int linmod = SOLID; +int again; +int done1; +char chrtab[][16]; +int plotcom[] { 0200, 0, 0}; +int eotcom[] { 0210, 0, 0}; +char blocks [NB][BSIZ]; +int obuf[264]; +int lastx; +int lasty; +double topx = 1536; +double topy = 1536; +double botx = 0; +double boty = 0; +int centx; +int centy; +double delx = 1536; +double dely = 1536; +double del = 1536; + +struct buf { + int bno; + char *block; +}; +struct buf bufs[NB]; + +int in, out; +char *picture = "/usr/tmp/raster"; + +main(argc, argv) +char **argv; +{ + extern int onintr(); + register i; + + if (argc>1) { + in = open(argv[1], 0); + putpict(); + exit(0); + } + signal(SIGTERM, onintr); + if (signal(SIGINT, SIG_IGN) != SIG_IGN) + signal(SIGINT, onintr); +another: + for (i=0; i 1536./2048.) + del = dely; + else + del = delx * (1566./2048.); + centx = 0; + centx = (2048 - mapx(topx)) / 2; + centy = 0; + centy = mapy(topy) / 2; + continue; + + case 'l': + done1 |= 01; + x1 = mapx(getw(stdin)); + y1 = mapy(getw(stdin)); + lastx = mapx(getw(stdin)); + lasty = mapy(getw(stdin)); + line(x1, y1, lastx, lasty); + continue; + + case 'm': + lastx = mapx(getw(stdin)); + lasty = mapy(getw(stdin)); + continue; + + case 't': + done1 |= 01; + while ((x1 = getc(stdin)) != '\n') + plotch(x1); + continue; + + case 'e': + if (done1) { + again++; + return; + } + continue; + + case 'p': + done1 |= 01; + lastx = mapx(getw(stdin)); + lasty = mapy(getw(stdin)); + point(lastx, lasty); + point(lastx+1, lasty); + point(lastx, lasty+1); + point(lastx+1, lasty+1); + continue; + + case 'n': + done1 |= 01; + x1 = mapx(getw(stdin)); + y1 = mapy(getw(stdin)); + line(lastx, lasty, x1, y1); + lastx = x1; + lasty = y1; + continue; + + case 'f': + getw(stdin); + getc(stdin); + switch(getc(stdin)) { + case 't': + linmod = DOTTED; + break; + default: + case 'i': + linmod = SOLID; + break; + case 'g': + linmod = LONGDASHED; + break; + case 'r': + linmod = SHORTDASHED; + break; + case 'd': + linmod = DOTDASHED; + break; + } + while((x1=getc(stdin))!='\n') + if(x1==-1) return; + continue; + + case 'd': + getw(stdin); + getw(stdin); + getw(stdin); + x1 = getw(stdin); + while (--x1 >= 0) + getw(stdin); + continue; + + case -1: + return; + + default: + printf("Botch\n"); + return; + } +} + +plotch(c) +register c; +{ + register j; + register char *cp; + int i; + + if (c<' ' || c >0177) + return; + cp = chrtab[c-' ']; + for (i = -16; i<16; i += 2) { + c = *cp++; + for (j=7; j>=0; --j) + if ((c>>j)&1) { + point(lastx+6-j*2, lasty+i); + point(lastx+7-j*2, lasty+i); + point(lastx+6-j*2, lasty+i+1); + point(lastx+7-j*2, lasty+i+1); + } + } + lastx += 16; +} + +int f; /* versatec file number */ +putpict() +{ + register x, *ip, *op; + int y; + + if (f==0){ + f = open("/dev/vp0", 1); + if (f < 0) { + printf("Cannot open vp\n"); + exit(1); + } + ioctl(f, SETSTATE, plotcom); + } + op = obuf; + lseek(in, 0L, 0); + for (y=0; y<2048; y++) { + if ((y&077) == 0) + read(in, blocks[0], 32*BSIZ); + for (x=0; x<32; x++) { + ip = (int *)&blocks[x][(y&077)<<3]; + *op++ = *ip++; + *op++ = *ip++; + *op++ = *ip++; + *op++ = *ip++; + } + *op++ = 0; + *op++ = 0; + *op++ = 0; + *op++ = 0; + if (y&1) { + write(f, (char *)obuf, sizeof(obuf)); + op = obuf; + } + } +} + +line(x0, y0, x1, y1) +register x0, y0; +{ + int dx, dy; + int xinc, yinc; + register res1; + int res2; + int slope; + + xinc = 1; + yinc = 1; + if ((dx = x1-x0) < 0) { + xinc = -1; + dx = -dx; + } + if ((dy = y1-y0) < 0) { + yinc = -1; + dy = -dy; + } + slope = xinc*yinc; + res1 = 0; + res2 = 0; + if (dx >= dy) while (x0 != x1) { + if((x0+slope*y0)&linmod) + if (((x0>>6) + ((y0&~077)>>1)) == bufs[0].bno) + bufs[0].block[((y0&077)<<3)+((x0>>3)&07)] |= 1 << (7-(x0&07)); + else + point(x0, y0); + if (res1 > res2) { + res2 += dx - res1; + res1 = 0; + y0 += yinc; + } + res1 += dy; + x0 += xinc; + } else while (y0 != y1) { + if((x0+slope*y0)&linmod) + if (((x0>>6) + ((y0&~077)>>1)) == bufs[0].bno) + bufs[0].block[((y0&077)<<3)+((x0>>3)&07)] |= 1 << (7-(x0&07)); + else + point(x0, y0); + if (res1 > res2) { + res2 += dy - res1; + res1 = 0; + x0 += xinc; + } + res1 += dx; + y0 += yinc; + } + if((x1+slope*y1)&linmod) + if (((x1>>6) + ((y1&~077)>>1)) == bufs[0].bno) + bufs[0].block[((y1&077)<<3)+((x1>>3)&07)] |= 1 << (7-(x1&07)); + else + point(x1, y1); +} + +point(x, y) +register x, y; +{ + register bno; + + bno = ((x&03700)>>6) + ((y&03700)>>1); + if (bno != bufs[0].bno) { + if (bno < 0 || bno >= 1024) + return; + getblk(bno); + } + bufs[0].block[((y&077)<<3)+((x>>3)&07)] |= 1 << (7-(x&07)); +} + +getblk(b) +register b; +{ + register struct buf *bp1, *bp2; + register char *tp; + +loop: + for (bp1 = bufs; bp1 < &bufs[NB]; bp1++) { + if (bp1->bno == b || bp1->bno == -1) { + tp = bp1->block; + for (bp2 = bp1; bp2>bufs; --bp2) { + bp2->bno = (bp2-1)->bno; + bp2->block = (bp2-1)->block; + } + bufs[0].bno = b; + bufs[0].block = tp; + return; + } + } + zseek(out, bufs[NB-1].bno); + write(out, bufs[NB-1].block, BSIZ); + zseek(in, b); + read(in, bufs[NB-1].block, BSIZ); + bufs[NB-1].bno = b; + goto loop; +} + +onintr() +{ + exit(1); +} + +zseek(a, b) +{ + return(lseek(a, (long)b*512, 0)); +}