home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2010 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  25.9 KB

  1. From: hot@integow.uucp (Roland van Hout)
  2. Newsgroups: alt.sources
  3. Subject: PD plot(4) librarys (and hercules driver for interactive 386) part 7 of 9
  4. Message-ID: <1395@integow.uucp>
  5. Date: 28 Oct 90 03:57:48 GMT
  6.  
  7.  
  8. #!/bin/sh
  9. # This is part 07 of a multipart archive
  10. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  11.  then TOUCH=touch
  12.  else TOUCH=true
  13. fi
  14. # ============= libplot/cgi/libCGI.c ==============
  15. echo "x - extracting libplot/cgi/libCGI.c (Text)"
  16. sed 's/^X//' << 'SHAR_EOF' > libplot/cgi/libCGI.c &&
  17. X
  18. X/* plot(4) graphics library for the SCO  CGI library under xenix*/
  19. X
  20. X
  21. X#include <stdio.h>    /* for fprintf on stderr    */
  22. X#include <ctype.h>    /*    we are using tolower()    */
  23. X#define MAIN    1    /* causes declarations in the .h files to occur here */
  24. X#include "cgistuff.h"    /*    includes cgitypes.h and cgifctns.h    */
  25. X#include "ctest.h"
  26. X#include <signal.h>
  27. X
  28. X/*VOID close_gin_device( VOID );    /*    in gintests.c    */
  29. X
  30. Xstatic char cgidisplay[]="CGIDISP ";
  31. Xstatic char cgiprinter[]="CGIPRNT ";
  32. Xchar * cgidevice = cgidisplay;
  33. Xstatic void usage_message();
  34. Xint vsl_type_returns;
  35. X
  36. X
  37. X
  38. X
  39. Xfloat gxscrunch,gyscrunch;
  40. Xfloat pitograd;
  41. Xint CGIoffx,CGIoffy;
  42. X
  43. X# include <stdio.h>
  44. X# include <fcntl.h>
  45. X# include "CGI.h"
  46. X# include <math.h>
  47. X
  48. X    herc_args    CGIhv,CGIcurpos;
  49. X
  50. X/* #define DEBUG   /* turn on if no driver calls should be made!*/
  51. X
  52. Xopenpl()
  53. X{
  54. X
  55. X    int strlen( char * );
  56. X#ifndef NO_DEBUGGING
  57. X#ifndef MSDOS
  58. X#ifdef CGIVER
  59. X    extern int scodebug;    /* declared in the bindings in v_opnwk.c */
  60. X#else
  61. X    extern int cgidebug;    /* declared in the bindings in v_opnwk.c */
  62. X#endif
  63. X#endif
  64. X#endif
  65. X                /* setting to TRUE will cause the bindings */
  66. X                /* to print out the execl command rather */
  67. X                /* than executing it when they are forking */
  68. X                /* the agents.    */
  69. X    /* local variables */
  70. X    SINT16    coord_xform_mode;
  71. X    char    *char_pointer;
  72. X    register SINT16    i;
  73. X    char * char_ptr;
  74. X    int defer_mode;
  75. X    int use_defaults;
  76. X
  77. X
  78. X
  79. X    use_defaults = TRUE;
  80. X
  81. X    manual_operation = FALSE;    /* m flag */
  82. X    do_timings = FALSE;        /* t flag */
  83. X    defer_mode = ASAP;    /* b flag sets to (BNI), or a sets to (ASTI) */
  84. X    coord_xform_mode = 0;    /* selected with 0, 1, 2, or 3    */
  85. X
  86. X
  87. X#ifndef NO_DEBUGGING
  88. X#ifndef MSDOS
  89. X#ifdef CGIVER
  90. X    if ( scodebug )
  91. X    {
  92. X        printf( "\nExecute the desired agent with these 4 arguments on a console screen:\n" );
  93. X    }
  94. X    else
  95. X#else
  96. X    if ( cgidebug )
  97. X    {
  98. X        printf( "\nExecute the desired agent with these 4 arguments on a console screen:\n" );
  99. X    }
  100. X    else
  101. X#endif
  102. X#endif
  103. X#endif
  104. X
  105. X    ok_to_use_graphtext = FALSE;
  106. X
  107. X    if ( cgistart( coord_xform_mode, defer_mode )    )
  108. X    {
  109. X        fprintf( stderr, "plotcgi: message: open failed, ctest will exit.\n" );
  110. X        fprintf( stderr, "plotcgi: requires environment variables:\n" );
  111. X        fprintf( stderr, "CGIPATH=   <- specify pathname for location of CGI agents.\n" );
  112. X        fprintf( stderr, "CGIDISP=   <- specify agent name for display\n" );
  113. X/*        fprintf( stderr, "or CGIPRNT=  <- alternate agent name when running plotcgi with -p option.\n" );*/
  114. X        fprintf( stderr, "(instead of CGIPATH, you may need VDIPATH for CGI ver. 1.0 bindings.)\n" );
  115. X        exit (-1);
  116. X    }
  117. X
  118. X    /*    set up the color palettes    */
  119. X    original_palette();
  120. X    normal_graphtext();    /* adjusts graphtext size    */
  121. X
  122. X
  123. X    /*    CGI starts up in graphics mode    */
  124. X    ok_to_use_graphtext = TRUE;
  125. X
  126. X    /*    The workstation should already be clear at this time.    */
  127. X
  128. X        CGIcurpos=CGIhv;
  129. X    linemod("solid");
  130. X}
  131. X
  132. Xclosepl()
  133. X{
  134. X#ifndef DEBUG
  135. X    if (isatty(0)) getchar(); /* stdin is a tty then leave the 
  136. X        screen until a character is pressed */
  137. X    /* close the workstation*/
  138. X    if ( v_clswk(dev_handle) < 0 )
  139. X        report_cgi_error( "v_clswk" );
  140. X#endif
  141. X}
  142. X
  143. Xspace(x0,y0,x1,y1)
  144. Xint x0,y0,x1,y1;
  145. X{
  146. Xint x,y;
  147. Xpitograd=(180.0/M_PI);
  148. X
  149. Xif (x1>0 && y1>0 && y0<y1 && x0<x1) {
  150. X    x=x1-x0;y=y1-y0;
  151. X    gxscrunch=(VDC_X/(float) x);gyscrunch=(VDC_Y/(float) y);
  152. X    CGIoffx = (-1 *(x0*gxscrunch) + 1);
  153. X    CGIoffy=(y0*gyscrunch)-1;
  154. X}
  155. X
  156. X#ifdef DEBUG
  157. Xprintf("offx=%d, offy=%d\n",CGIoffx,CGIoffy);
  158. X#endif
  159. X
  160. X}
  161. X
  162. Xerase()
  163. X{
  164. X#ifndef DEBUG
  165. X    if (isatty(0)) getchar(); /* stdin is a tty then leave the 
  166. X        screen until a character is pressed */
  167. X    v_clrwk(dev_handle);
  168. X#endif
  169. X}
  170. X
  171. Xlabel(s)
  172. Xchar *s;
  173. X{
  174. X#ifndef DEBUG
  175. X    v_gtext(dev_handle, CGIcurpos.x1,CGIcurpos.y1,s);
  176. X#else
  177. X    printf("str=%s, x=%d, y=%d\n",s,CGIhv.x1,CGIhv.y1);
  178. X#endif
  179. X}
  180. X
  181. Xmove(x,y)
  182. Xint x,y;
  183. X{
  184. XSINT16 row,column;
  185. X    x = x*gxscrunch;
  186. X    y = y*gyscrunch;
  187. X    y += CGIoffy ;
  188. X    x +=  CGIoffx ;
  189. X    CGIcurpos.x1 = x;  CGIcurpos.y1 = y;
  190. X    column = x; row = y;
  191. X    vs_curaddress(dev_handle,row,column);
  192. X#ifdef DEBUG
  193. X    printf("move %d, %d\n",x,y);
  194. X#endif
  195. X
  196. X}
  197. X
  198. Xcont(x,y)
  199. Xint x,y;
  200. X{
  201. X    int xo,yo;
  202. X
  203. X    int line_spacing;
  204. X    int start_line;
  205. X    SINT16 polyline_array[256];
  206. X
  207. X    xo = x*gxscrunch;
  208. X    yo = y*gyscrunch;
  209. X    yo += CGIoffy ;
  210. X    xo +=  CGIoffx ;
  211. X    /*    leave room for 5 lines of text at the top    */
  212. X    start_line = VDC_Y - (5 * cell_height);
  213. X    line_spacing = start_line / (LINE_TYPES+1);
  214. X
  215. X
  216. X    /* draw each line type across the screen in default color */
  217. X    polyline_array[0] = CGIcurpos.x1;    /* x1 */
  218. X    polyline_array[2] = xo;    /* x2 */
  219. X    polyline_array[1] = CGIcurpos.y1;/*y1*/
  220. X    polyline_array[3] = yo;    /* y2 */
  221. X    CGIhv.c = CGIcurpos.c;
  222. X#ifndef DEBUG
  223. X    if ( v_pline( dev_handle, 2, polyline_array ) < 0 )
  224. X        report_cgi_error( "v_pline" );
  225. X#else
  226. X        printf("cont = line from %d,%d to %d,%d\n",CGIhv.x1,CGIhv.y1,CGIhv.x2,CGIhv.y2);
  227. X#endif
  228. X        CGIcurpos.x1=xo;CGIcurpos.x2=yo;
  229. X}
  230. X
  231. Xline (x1, y1, x2, y2)
  232. Xint x1,y1,x2,y2;
  233. X{
  234. X    move(x1,y1);
  235. X    cont(x2,y2);
  236. X}
  237. Xcircle(x,y,r)
  238. Xint x,y,r;
  239. X{
  240. XSINT16 xo,yo,ro;
  241. X    xo=(x*gxscrunch);yo=(y*gyscrunch);
  242. X    yo = CGIoffy + yo;
  243. X    xo =  CGIoffx + xo;
  244. X    ro = (r * gxscrunch);
  245. X    v_circle(dev_handle,xo,yo,ro);
  246. X}
  247. X
  248. Xarc(x,y,x0,y0,x1,y1)
  249. Xint x,y,x0,y0,x1,y1;
  250. X{
  251. X#ifdef ARC
  252. Xfloat a1,a2,r1,r2;
  253. XSINT16 xo,yo,c1,c2,r;
  254. X    if ((x-x0) > 0) {
  255. X        r1=(y-y0)/(x-x0);
  256. X        a1=atan(r1);
  257. X        c1=(a1*pitograd*10);
  258. X    }
  259. X    else {
  260. X        c1=1800;
  261. X    }
  262. X    if ((x-x1) > 0) {
  263. X        r2=(y-y1)/(x-x1);
  264. X        a2=atan(r2);
  265. X        c2=(a2*pitograd*10);
  266. X    }
  267. X    else {
  268. X        c2=1800;
  269. X    }
  270. X    
  271. X    xo=(x0*gxscrunch);yo=(y0*gyscrunch);
  272. X    yo = CGIoffy + yo;
  273. X    xo =  CGIoffx + xo;
  274. X    v_arc(dev_handle, xo,yo, ,c1,c2);
  275. X#endif
  276. X}
  277. X
  278. Xdot(xi,yi,dx,n,pat)
  279. Xint xi,yi,dx,n,pat[256];
  280. X{
  281. X}
  282. X
  283. Xpoint(x,y)
  284. Xint x,y;
  285. X{
  286. Xint xo,yo;
  287. X    xo = x*gxscrunch;
  288. X    yo = y*gyscrunch;
  289. X    yo += CGIoffy ;
  290. X    xo +=  CGIoffx ;
  291. X    CGIcurpos.x1 = xo; CGIcurpos.y1 = yo;
  292. X#ifndef DEBUG
  293. X    move(x,y);
  294. X    cont(x,y);
  295. X#else
  296. X        printf("point %d,%d\n",x,y);
  297. X#endif
  298. X}
  299. X
  300. Xlinemod(s)
  301. Xchar *s;
  302. X{
  303. XSINT16 line_type;
  304. X  if (strcmp(s,"dotted")==0) {
  305. X    line_type = 3;
  306. X      }
  307. X  else if (strcmp(s,"solid")==0) {
  308. X    line_type = 1;
  309. X      }
  310. X      else if (strcmp(s,"longdashed")==0) {
  311. X        line_type = 2;
  312. X          }
  313. X         else if (strcmp(s,"shortdashed")==0) {
  314. X            line_type = 7;
  315. X             }
  316. X            else if (strcmp(s,"dotdashed")==0) {
  317. X                line_type = 4;
  318. X                }
  319. Xif ( (vsl_type_returns = vsl_type( dev_handle, line_type )) < 0)
  320. X    report_cgi_error( "vsl_type" );
  321. X}
  322. X
  323. X
  324. Xbox(x0, y0, x1, y1)
  325. X{
  326. X    move(x0, y0);
  327. X    cont(x0, y1);
  328. X    cont(x1, y1);
  329. X    cont(x1, y0);
  330. X    cont(x0, y0);
  331. X    move(x1, y1);
  332. X}
  333. SHAR_EOF
  334. $TOUCH -am 1014213390 libplot/cgi/libCGI.c &&
  335. chmod 0666 libplot/cgi/libCGI.c ||
  336. echo "restore of libplot/cgi/libCGI.c failed"
  337. set `wc -c libplot/cgi/libCGI.c`;Wc_c=$1
  338. if test "$Wc_c" != "6196"; then
  339.     echo original size 6196, current size $Wc_c
  340. fi
  341. # ============= libplot/cgi/README ==============
  342. echo "x - extracting libplot/cgi/README (Text)"
  343. sed 's/^X//' << 'SHAR_EOF' > libplot/cgi/README &&
  344. XThe following files are not included because of SCO copyrights:
  345. Xcgifctns.h cgistart.c cgistuff.c cgistuff.h cgitypes.h ctest.h gtexttests.c
  346. XIf you get Xenix with CGI you will get these files anyway.
  347. SHAR_EOF
  348. $TOUCH -am 1014213590 libplot/cgi/README &&
  349. chmod 0644 libplot/cgi/README ||
  350. echo "restore of libplot/cgi/README failed"
  351. set `wc -c libplot/cgi/README`;Wc_c=$1
  352. if test "$Wc_c" != "199"; then
  353.     echo original size 199, current size $Wc_c
  354. fi
  355. # ============= libplot/cgi/h.c ==============
  356. echo "x - extracting libplot/cgi/h.c (Text)"
  357. sed 's/^X//' << 'SHAR_EOF' > libplot/cgi/h.c &&
  358. X# include <stdio.h>
  359. X# include <fcntl.h>
  360. X# include <math.h>
  361. X
  362. Xmain(argc, argv)
  363. Xint    argc;
  364. Xchar    *argv[];
  365. X{
  366. X    int    i,j;
  367. X    char    strbuff[90];
  368. X
  369. X    openpl();space(0,0,720,350);
  370. X    for (j=1;j<=100;j++) {
  371. X    erase();
  372. X    move(280,280);
  373. X    /* Do some random dots */
  374. X    label("Some random dots.");
  375. X    for (i = 0; i < 100; i ++)
  376. X    {
  377. X        point( abs(lrand48() % 719),abs(lrand48() % 347));
  378. X    };
  379. X/*    sleep(10);
  380. X    /* Do some random lines */
  381. X    erase();
  382. X    move(280,280);
  383. X    /* Do some random dots */
  384. X    label("Some random lines.");
  385. X    for (i = 0; i < 50; i ++)
  386. X    {
  387. X    line( abs(lrand48() % 719),abs(lrand48() % 347),abs(lrand48() % 719),abs(lrand48() % 347));
  388. X    };
  389. X    }
  390. X    closepl();
  391. X}    
  392. SHAR_EOF
  393. $TOUCH -am 0511152090 libplot/cgi/h.c &&
  394. chmod 0666 libplot/cgi/h.c ||
  395. echo "restore of libplot/cgi/h.c failed"
  396. set `wc -c libplot/cgi/h.c`;Wc_c=$1
  397. if test "$Wc_c" != "627"; then
  398.     echo original size 627, current size $Wc_c
  399. fi
  400. # ============= lp.c ==============
  401. echo "x - extracting lp.c (Text)"
  402. sed 's/^X//' << 'SHAR_EOF' > lp.c &&
  403. X/*    @(#)driver.c    5.1        */
  404. X#include <stdio.h>
  405. X#include <math.h>
  406. X#include <errno.h>
  407. X#include "plotlpus.h"
  408. X
  409. Xfloat deltx = 4095.0;
  410. Xfloat delty = 4095.0;
  411. X
  412. Xmain(argc,argv)  char **argv; {
  413. X    int std=1;
  414. X    FILE *fin;
  415. X
  416. X    while(argc-- > 1) {
  417. X        if(*argv[1] == '-')
  418. X            switch(argv[1][1]) {
  419. X                case 'l':
  420. X                    deltx = atoi(&argv[1][2]) - 1;
  421. X                    break;
  422. X                case 'w':
  423. X                    delty = atoi(&argv[1][2]) - 1;
  424. X                    break;
  425. X                case 's':
  426. X                    printer=LASERLOW;
  427. X                    break;
  428. X                case 'm':
  429. X                    printer=LASERMED;
  430. X                    break;
  431. X                case 'h':
  432. X                    printer=LASERHIGH;
  433. X                    break;
  434. X                case 'i':
  435. X                    printer=IBM_PRO;
  436. X                    break;
  437. X                case 'e':
  438. X                    printer=EPSON;
  439. X                    break;
  440. X                }
  441. X
  442. X        else {
  443. X            std = 0;
  444. X            if ((fin = fopen(argv[1], "r")) == NULL) {
  445. X                fprintf(stderr, "can't open %s\n", argv[1]);
  446. X                exit(1);
  447. X                }
  448. X            fplt(fin);
  449. X            }
  450. X        argv++;
  451. X        }
  452. X    if (std)
  453. X        fplt( stdin );
  454. X    exit(0);
  455. X    }
  456. X
  457. X
  458. Xfplt(fin)  FILE *fin; {
  459. X    int c;
  460. X    char s[256];
  461. X    int xi,yi,x0,y0,x1,y1,r,dx,n,i;
  462. X    int pat[256];
  463. X
  464. X    openpl();
  465. X    while((c=getc(fin)) != EOF){
  466. X        switch(c){
  467. X        case 'm':
  468. X            xi = getsi(fin);
  469. X            yi = getsi(fin);
  470. X            move(xi,yi);
  471. X            break;
  472. X        case 'l':
  473. X            x0 = getsi(fin);
  474. X            y0 = getsi(fin);
  475. X            x1 = getsi(fin);
  476. X            y1 = getsi(fin);
  477. X            line(x0,y0,x1,y1);
  478. X            break;
  479. X        case 't':
  480. X            getsd(s,fin);
  481. X            label(s);
  482. X            break;
  483. X        case 'e':
  484. X            erase();
  485. X            break;
  486. X        case 'p':
  487. X            xi = getsi(fin);
  488. X            yi = getsi(fin);
  489. X            point(xi,yi);
  490. X            break;
  491. X        case 'n':
  492. X            xi = getsi(fin);
  493. X            yi = getsi(fin);
  494. X            cont(xi,yi);
  495. X            break;
  496. X        case 's':
  497. X            x0 = getsi(fin);
  498. X            y0 = getsi(fin);
  499. X            x1 = getsi(fin);
  500. X            y1 = getsi(fin);
  501. X            space(x0,y0,x1,y1);
  502. X            break;
  503. X        case 'a':
  504. X            xi = getsi(fin);
  505. X            yi = getsi(fin);
  506. X            x0 = getsi(fin);
  507. X            y0 = getsi(fin);
  508. X            x1 = getsi(fin);
  509. X            y1 = getsi(fin);
  510. X            arc(xi,yi,x0,y0,x1,y1);
  511. X            break;
  512. X        case 'c':
  513. X            xi = getsi(fin);
  514. X            yi = getsi(fin);
  515. X            r = getsi(fin);
  516. X            circle(xi,yi,r);
  517. X            break;
  518. X        case 'f':
  519. X            getsd(s,fin);
  520. X            linemod(s);
  521. X            break;
  522. X        case 'd':
  523. X            xi = getsi(fin);
  524. X            yi = getsi(fin);
  525. X            dx = getsi(fin);
  526. X            n = getsi(fin);
  527. X            for(i=0; i<n; i++)pat[i] = getsi(fin);
  528. X            dot(xi,yi,dx,n,pat);
  529. X            break;
  530. X            }
  531. X        }
  532. X    closepl();
  533. X    }
  534. Xgetsi(fin)  FILE *fin; {    /* get an integer stored in 2 ascii bytes. */
  535. X    short a, b;
  536. X    if((b = getc(fin)) == EOF)
  537. X        return(EOF);
  538. X    if((a = getc(fin)) == EOF)
  539. X        return(EOF);
  540. X    a = a<<8;
  541. X    return(a|b);
  542. X}
  543. Xgetsd(s,fin)  char *s;  FILE *fin; {
  544. X    for( ; *s = getc(fin); s++)
  545. X        if(*s == '\n')
  546. X            break;
  547. X    *s = '\0';
  548. X    return;
  549. X}
  550. X
  551. X
  552. Xmatherr(x)
  553. Xstruct exception *x;
  554. X{
  555. Xif(x->type==DOMAIN)
  556. X    {errno=EDOM;
  557. X    if(!strcmp("log",x->name))x->retval = (-HUGE);
  558. X    else x->retval = 0;
  559. X    return(1);
  560. X    }
  561. Xelse  if ((x->type)==SING)
  562. X    {errno=EDOM;
  563. X    x->retval = (-HUGE);
  564. X    return(1);
  565. X    }
  566. Xelse return(0);
  567. X}
  568. X
  569. X
  570. SHAR_EOF
  571. $TOUCH -am 1014215790 lp.c &&
  572. chmod 0644 lp.c ||
  573. echo "restore of lp.c failed"
  574. set `wc -c lp.c`;Wc_c=$1
  575. if test "$Wc_c" != "2654"; then
  576.     echo original size 2654, current size $Wc_c
  577. fi
  578. # ============= herc/Makefile ==============
  579. if test ! -d 'herc'; then
  580.     echo "x - creating directory herc"
  581.     mkdir 'herc'
  582. fi
  583. echo "x - extracting herc/Makefile (Text)"
  584. sed 's/^X//' << 'SHAR_EOF' > herc/Makefile &&
  585. X# define IX386 for Interactive 386
  586. XDEFINES=-DIX386
  587. XCFLAGS=$(DEFINES)
  588. X
  589. Xherc.o: herc.c herc.h
  590. X    cc -c $(DEFINES) -DINKERNEL herc.c
  591. X
  592. X# must be root to make install
  593. Xinstall: herc.o 
  594. X    cp herc.o herc.c herc.h config Makefile /etc/atconf/modules/herc
  595. X    mkunix
  596. X    mv /etc/atconf/kernels/unix.std.* /unix.test
  597. X
  598. X# must be root to make filesys
  599. X# also edit /etc/atconf/systems/system.std to enter herc as device with 
  600. X# major device number 15
  601. Xfilesys:
  602. X    mknod /dev/herc c 15 0
  603. X    chmod ugo+rwx /dev/herc
  604. X    mkdir /etc/atconf/modules/herc
  605. X
  606. Xtest: test.o  herc.h
  607. X    cc -o test $(DEFINES) test.o 
  608. X
  609. Xprint:
  610. X    srcpub herc.h test.c herc.c config Makefile >PRINT
  611. X    trj PRINT
  612. X    offjet tr.PRINT
  613. SHAR_EOF
  614. $TOUCH -am 1014125090 herc/Makefile &&
  615. chmod 0644 herc/Makefile ||
  616. echo "restore of herc/Makefile failed"
  617. set `wc -c herc/Makefile`;Wc_c=$1
  618. if test "$Wc_c" != "658"; then
  619.     echo original size 658, current size $Wc_c
  620. fi
  621. # ============= herc/bitset.h ==============
  622. echo "x - extracting herc/bitset.h (Text)"
  623. sed 's/^X//' << 'SHAR_EOF' > herc/bitset.h &&
  624. Xstatic char SCCS_x[] = "%W% %G% %U%";
  625. X/*+++
  626. X    bitset.h
  627. X    PURPOSE : bit manipulation macros
  628. X
  629. X    DATE    : 2/15/90
  630. X
  631. X    AUTHOR  : W. Hatch
  632. X
  633. X    PROJECT : WEH Software
  634. X            
  635. X    COMPANY : Computational Engineering
  636. X          14504 Greenview Drive Suite 500
  637. X          Laurel, Maryland 20708
  638. X          Phone (301)470-3839
  639. X          FAX (301)776-5461
  640. X
  641. X    CREDITS : Harbison And Steele, A C Reference Manual
  642. X          Prentice Hall, 1984, Pages 172-180
  643. X
  644. X---*/ 
  645. X/*
  646. X------------------------------------------------------------------------
  647. X  MODIFICATIONS
  648. XDATE-PROGRAMMER    DESCRIPTION
  649. X------------------------------------------------------------------------
  650. X*/
  651. X
  652. X#define    SET        unsigned long
  653. X#define SET_BITS    (sizeof(SET) * 8)    /* number of bits in SET */
  654. X
  655. X#define VALIDBIT(i)    ((i) < SET_BITS && (i) >= 0)
  656. X
  657. X#define    EMPTYSET        ((SET) 0)
  658. X#define SINGLESET(i)        (((SET) 1) << (i))
  659. X#define DOSET(set,i)        ((set | (SINGLESET(i))))
  660. X#define AND(set1,set2)        ((set1) & (set2))
  661. X#define OR(set1, set2)        ((set1) | (set2))
  662. X#define XOR(set1, set2)        ((set1) ^ (set2))
  663. X#define ISSET(i,set)        (SINGLESET((i)) & (set))
  664. X#define MASKSET(set,mask)    ((set) & (mask) == (mask))
  665. SHAR_EOF
  666. $TOUCH -am 1013182190 herc/bitset.h &&
  667. chmod 0644 herc/bitset.h ||
  668. echo "restore of herc/bitset.h failed"
  669. set `wc -c herc/bitset.h`;Wc_c=$1
  670. if test "$Wc_c" != "1086"; then
  671.     echo original size 1086, current size $Wc_c
  672. fi
  673. # ============= herc/config ==============
  674. echo "x - extracting herc/config (Text)"
  675. sed 's/^X//' << 'SHAR_EOF' > herc/config &&
  676. X* 1 "herc/config.c
  677. X
  678. X*ident    "@(#)config    
  679. X
  680. Xcharacter(9)
  681. X
  682. Xprefix = herc
  683. X
  684. Xfunctions = init, open, close, read, write, ioctl
  685. X
  686. SHAR_EOF
  687. $TOUCH -am 1013182190 herc/config &&
  688. chmod 0644 herc/config ||
  689. echo "restore of herc/config failed"
  690. set `wc -c herc/config`;Wc_c=$1
  691. if test "$Wc_c" != "121"; then
  692.     echo original size 121, current size $Wc_c
  693. fi
  694. # ============= herc/herc.c ==============
  695. echo "x - extracting herc/herc.c (Text)"
  696. sed 's/^X//' << 'SHAR_EOF' > herc/herc.c &&
  697. Xstatic char SCCS_hercdent[] = "%W% %G% %U%";
  698. X/*======================================================================*/
  699. X/*  herc.c - hercules graphics card driver for Microport V386/3.0e    */
  700. X/*                                    */
  701. X/*    2/5/90                                */
  702. X/*    Bill Hatch                            */
  703. X/*    uunet!bts!bill                            */
  704. X/*    Computational Engineering                    */
  705. X/*    14504 Greenview Drive Suite 500                    */
  706. X/*    Laurel, Maryland 20708                        */
  707. X/*    Phone (301)470-3839                        */
  708. X/*                                    */
  709. X/*    see herc.h for credits to other programmers and authors        */
  710. X/*======================================================================*/
  711. X#include "herc.h"
  712. Xextern char *sptalloc();
  713. Xextern int  sptfree();
  714. Xextern unsigned char inb();
  715. X
  716. X/*----------------------------------------------------------------------*/
  717. X/* settings for 6845 chips data registers for graphics and text modes    */
  718. X/*----------------------------------------------------------------------*/
  719. Xstatic int gdata[12] = {0x35, 0x2d, 0x2e, 0x7, 0x5b, 0x2, 0x57, 0x57, 0x2,
  720. X    0x3, 0x0, 0x0};
  721. Xstatic int tdata[12] = {0x61, 0x50, 0x52, 0xf, 0x19, 0x6, 0x19, 0x19, 0x2,
  722. X    0xd, 0xb, 0xc};
  723. X
  724. Xstatic char *myvaddr;
  725. Xstatic char *vaddr0;
  726. Xstatic char *vaddr1;
  727. Xstatic int g_mode();
  728. Xstatic int t_mode();
  729. X
  730. Xstatic int clearscreen();
  731. Xstatic int wait_for_retrace();
  732. X
  733. X/*======================================================================*/
  734. X/* hercinit - nothing done                        */
  735. X/*======================================================================*/
  736. Xhercinit(dev)
  737. Xint dev;
  738. X{
  739. X    u.u_error = 0;
  740. X    return;
  741. X}
  742. X/*======================================================================*/
  743. X/* hercopen - enable graphics and clear screen                */
  744. X/*======================================================================*/
  745. Xhercopen(dev,flag)
  746. Xint dev;
  747. Xint flag;
  748. X{
  749. X    int i;
  750. X
  751. X    /*--------------------------------------------------------------*/
  752. X    /* map herc graphics pages to virtual memory and set myvaddr    */
  753. X    /* to page 0                            */
  754. X    /*--------------------------------------------------------------*/
  755. X    if((vaddr0=sptalloc(HERC_SIZE,PG_P, HERC_PAGE_0,0)) == (char *)0 ||
  756. X        (vaddr1=sptalloc(HERC_SIZE,PG_P, HERC_PAGE_1,0)) == (char *)0)
  757. X    {
  758. X        KERROR("hercopen: sptalloc() failed");
  759. X        u.u_error = 1;
  760. X        return;
  761. X    }
  762. X    myvaddr = vaddr0;
  763. X    /*--------------------------------------------------------------*/
  764. X    /* clear both pages of graphics memory                */
  765. X    /*--------------------------------------------------------------*/
  766. X#ifdef DBUG
  767. X    printf("hercopen: vaddr0: %d, vaddr1: %d, \n", vaddr0, vaddr1);
  768. X#endif
  769. X    /*--------------------------------------------------------------*/
  770. X    /* switch to graphics mode                    */
  771. X    /*--------------------------------------------------------------*/
  772. X    if(g_mode() < 0)
  773. X    {
  774. X        KERROR("hercopen: g_mode() failed");
  775. X        u.u_error = 1;
  776. X        return;
  777. X    }
  778. X    clearscreen(vaddr0);
  779. X    clearscreen(vaddr1);
  780. X    u.u_error = 0;
  781. X    return;
  782. X}
  783. X/*======================================================================*/
  784. X/* hercclose - close the herc device                    */
  785. X/*======================================================================*/
  786. Xhercclose(dev)
  787. Xint dev;
  788. X{
  789. X    clearscreen(vaddr0);
  790. X    clearscreen(vaddr1);
  791. X    /*--------------------------------------------------------------*/
  792. X    /* switch to text mode                        */
  793. X    /*--------------------------------------------------------------*/
  794. X    t_mode();
  795. X    /*--------------------------------------------------------------*/
  796. X    /* free mapped virtual memory                    */
  797. X    /*--------------------------------------------------------------*/
  798. X    sptfree(vaddr0, HERC_SIZE,0);
  799. X    sptfree(vaddr1, HERC_SIZE,0);
  800. X
  801. X#ifdef DBUG
  802. X    printf("hercclose:\n");
  803. X#endif
  804. X    u.u_error = 0;
  805. X    return;
  806. X}
  807. X/*======================================================================*/
  808. X/* hercioctl - does nothing                        */
  809. X/*======================================================================*/
  810. Xhercioctl(dev, cmd, arg)
  811. Xint dev;
  812. Xint cmd;
  813. XHERC *arg;
  814. X{
  815. X
  816. X    u.u_error = 0;
  817. X    return;
  818. X}
  819. Xhercread(dev)
  820. Xint dev;
  821. X{
  822. X}
  823. X/*======================================================================*/
  824. X/* hercwrite - perform all herc graphics operations            */
  825. X/*======================================================================*/
  826. Xhercwrite(dev)
  827. Xint dev;
  828. X{
  829. X    HERC    *arg;
  830. X    HERC herc;
  831. X    unsigned char *pc;
  832. X    int x;
  833. X    int y;
  834. X    int cmd;
  835. X    int i;
  836. X
  837. X    unsigned char byte;
  838. X    int byteloc;
  839. X    int myint;
  840. X
  841. X    pc = (unsigned char *)(&herc);
  842. X    arg = (&herc);
  843. X    for(i=0; i < sizeof(HERC); i++)
  844. X    {
  845. X        if( (myint = cpass()) < 0)
  846. X        {
  847. X            printf("i= %d\n", i);
  848. X            KERROR("hercwrite: cpass failed");
  849. X            u.u_error = 1;
  850. X            return;
  851. X        }
  852. X        pc[i] = myint;
  853. X    }
  854. X    /************ an alternate, untested way of accomplishing the above
  855. X    if(copyin(&u.u_base, arg, sizeof(HERC)) != SUCCESS)
  856. X    {
  857. X        printf("u.u_count: %d, u.u_base: %d, u.u_offset: %d\n",
  858. X            u.u_count, u.u_base, u.u_offset);
  859. X        printf("sizeof(HERC): %d\n", sizeof(HERC));
  860. X        KERROR("hercwrite: copyin() failed");
  861. X        u.u_error = 1;
  862. X        return;
  863. X    }
  864. X    **********/
  865. X#ifdef DBUG
  866. X    printf("hercwrite: x: %d, y: %d, cmd: %d\n",
  867. X        arg->phys_x, arg->phys_y, arg->cmd);
  868. X#endif
  869. X    /*--------------------------------------------------------------*/
  870. X    /* extract and validate HERC contents                */
  871. X    /*--------------------------------------------------------------*/
  872. X    if((x=arg->phys_x) > PHYS_X_MAX || x < PHYS_X_MIN
  873. X        || (y=arg->phys_y) > PHYS_Y_MAX || y < PHYS_Y_MIN)
  874. X    {
  875. X        KERROR("hercwrite: illegal arg");
  876. X            printf("arg: %d, cmd: %d, x: %d, y: %d\n", 
  877. X                arg, arg->cmd, x, y);
  878. X        u.u_error = 1;
  879. X        return;
  880. X    }
  881. X    cmd = arg->cmd;
  882. X    /*--------------------------------------------------------------*/
  883. X    /* compute offset of byte to be acted on            */
  884. X    /*--------------------------------------------------------------*/
  885. X    if(cmd == SET_PIXEL || cmd == CLEAR_PIXEL || cmd == REVERSE_PIXEL)
  886. X    {
  887. X        byteloc = BYTE_OFFSET(x,y);
  888. X    }    
  889. X    
  890. X    /*--------------------------------------------------------------*/
  891. X    /* perform action                        */
  892. X    /*--------------------------------------------------------------*/
  893. X    switch(cmd)
  894. X    {
  895. X        case SET_PIXEL:    
  896. X                SET_BIT(myvaddr[byteloc], x);
  897. X                break;
  898. X
  899. X        case CLEAR_PIXEL: 
  900. X                CLEAR_BIT(myvaddr[byteloc], x);
  901. X                break;
  902. X
  903. X        case REVERSE_PIXEL: 
  904. X                REVERSE_BIT(myvaddr[byteloc], x);
  905. X                break;
  906. X
  907. X        case CLEAR_SCREEN_0:
  908. X                clearscreen(vaddr0);
  909. X                break;
  910. X
  911. X        case CLEAR_SCREEN_1:
  912. X                clearscreen(vaddr1);
  913. X                break;
  914. X                
  915. X        /* this switch screen does not work, any comments or     */
  916. X        /* suggestions are welcome  WEH 2/17/90            */
  917. X        case SWITCH_SCREEN_0:
  918. X                myvaddr = vaddr0;
  919. X                wait_for_retrace();
  920. X                if(outb(DMC_PORT, DMC_PAGE_0) == FAILURE)
  921. X                {
  922. X                    KERROR("hercwrite: outb() failed ");
  923. X                    return(FAILURE);
  924. X                }
  925. X                break;
  926. X
  927. X        case SWITCH_SCREEN_1:
  928. X                myvaddr = vaddr1;
  929. X                wait_for_retrace();
  930. X                if(outb(DMC_PORT, DMC_PAGE_1) == FAILURE)
  931. X                {
  932. X                    KERROR("hercwrite: outb() failed ");
  933. X                    return(FAILURE);
  934. X                }
  935. X                break;
  936. X    }
  937. X    u.u_error = 0;
  938. X    return;
  939. X}
  940. X/*======================================================================*/
  941. X/* clearscreen - turn all pixels off                    */
  942. X/*======================================================================*/
  943. Xstatic int clearscreen(vaddr)
  944. Xchar *vaddr;
  945. X{
  946. X    unsigned int i;
  947. X    for(i = 0; i < HERC_PAGE_BYTES; i++)
  948. X    {
  949. X        vaddr[i] = 0;
  950. X    }
  951. X    return(SUCCESS);
  952. X}
  953. X/*======================================================================*/
  954. X/* g_mode - switch to graphics mode                    */
  955. X/*======================================================================*/
  956. Xstatic int g_mode()
  957. X{
  958. X    int i;     
  959. X    unsigned char dmcbyte = (DMC_GRAPHICS|DMC_ON_SCREEN|DMC_PAGE_0);
  960. X    /*--------------------------------------------------------------*/
  961. X    /* enable both graphics pages and turn display off        */
  962. X    /*--------------------------------------------------------------*/
  963. X    wait_for_retrace();
  964. X    if(outb(CONFIG_SWITCH, CF_PAGE_0) == FAILURE ||
  965. X        outb(DMC_PORT, DMC_OFF_SCREEN) == FAILURE)
  966. X    {
  967. X        KERROR("g_mode: outb() to DMC_PORT or CONFIG_SWITCH failed");
  968. X        return(FAILURE);
  969. X    }
  970. X    /*--------------------------------------------------------------*/
  971. X    /* set hardware parameters for graphics mode, failure to do this*/
  972. X    /* may damage the video tube                    */
  973. X    /*--------------------------------------------------------------*/
  974. X    for(i = 0; i < 12; i++)
  975. X    {
  976. X        if(outb(INDEX_REG_6845, i) == FAILURE ||
  977. X            outb(DATA_REG_6845, gdata[i]) == FAILURE)
  978. X        {
  979. X            KERROR("g_mode: outb() to DATA or INDEX REG failed");
  980. X            return(FAILURE);
  981. X        }
  982. X    }
  983. X    /*--------------------------------------------------------------*/
  984. X    /* on retrace, enable graphics and turn display on        */
  985. X    /*--------------------------------------------------------------*/
  986. X    wait_for_retrace();
  987. X    if(outb(DMC_PORT, dmcbyte) == FAILURE)
  988. X    {
  989. X        KERROR("g_mode: outb(DMC_PORT, DMC_GRAPHICS) failed ");
  990. X        return(FAILURE);
  991. X    }
  992. X    return(SUCCESS);
  993. X}
  994. X/*======================================================================*/
  995. X/* t_mode - switch to text mode                        */
  996. X/*======================================================================*/
  997. Xstatic int t_mode()
  998. X{
  999. X    int i;
  1000. X    unsigned char dmcbyte = (DMC_ON_SCREEN|DMC_TEXT);
  1001. X    /*--------------------------------------------------------------*/
  1002. X    /* turn display off                        */
  1003. X    /*--------------------------------------------------------------*/
  1004. X    if(outb(DMC_PORT, DMC_OFF_SCREEN) == FAILURE)
  1005. X    {
  1006. X        KERROR("t_mode: outb to DMC_PORTT) failed ");
  1007. X        return(FAILURE);
  1008. X        
  1009. X    }
  1010. X    /*--------------------------------------------------------------*/
  1011. X    /* set hardware parameters for text mode            */
  1012. X    /*--------------------------------------------------------------*/
  1013. X    for(i = 0; i < 12; i++)        /* set hw sweep rate etc.    */
  1014. X    {
  1015. X        if(outb(INDEX_REG_6845, i) == FAILURE ||
  1016. X            outb(DATA_REG_6845, tdata[i]) == FAILURE)
  1017. X        {
  1018. X            KERROR("t_mode: outb() to 6845 failed");
  1019. X            return(FAILURE);
  1020. X        }
  1021. X    }
  1022. X    delay(0);
  1023. X    /*--------------------------------------------------------------*/
  1024. X    /* set text mode, turn display on                */
  1025. X    /*--------------------------------------------------------------*/
  1026. X    if(outb(DMC_PORT, dmcbyte) == FAILURE)
  1027. X    {
  1028. X        KERROR("t_mode: outb(DMC_PORT, dmcbyte) failed");
  1029. X        return(FAILURE);
  1030. X    }
  1031. X    /*--------------------------------------------------------------*/
  1032. X    /* enable text mode                        */
  1033. X    /*--------------------------------------------------------------*/
  1034. X    if(outb(CONFIG_SWITCH, CF_TEXT_ONLY) == FAILURE)
  1035. X    {
  1036. X        KERROR("t_mode: outb(CONFIG_SWITCH, CF_TEXT_ONLY) failed");
  1037. X        return(FAILURE);
  1038. X    }
  1039. X    return(SUCCESS);
  1040. X}
  1041. X/*======================================================================*/
  1042. X/* wait_for_retrace - loop until vertical retrace            */
  1043. X/*======================================================================*/
  1044. Xstatic int wait_for_retrace()
  1045. X{
  1046. X    unsigned char byte;
  1047. X    byte = inb(DS_PORT);
  1048. X    while(byte & DS_RETRACE)
  1049. X    {
  1050. X        delay(0);
  1051. X        byte = inb(DS_PORT);
  1052. X    }
  1053. X}
  1054. SHAR_EOF
  1055. $TOUCH -am 1013182190 herc/herc.c &&
  1056. chmod 0644 herc/herc.c ||
  1057. echo "restore of herc/herc.c failed"
  1058. set `wc -c herc/herc.c`;Wc_c=$1
  1059. if test "$Wc_c" != "10419"; then
  1060.     echo original size 10419, current size $Wc_c
  1061. fi
  1062. echo "End of part 7, continue with part 8"
  1063. exit 0
  1064.  
  1065.  
  1066.  
  1067.  
  1068. -- 
  1069. UUCP: ..!uunet!mcsun!hp4nl!integow!hot    or  hot@integow.UUCP or hot@hot.mug
  1070. Roland van Hout, Sr. software engineer, Integrity software consultants, 
  1071.          Pelmolenlaan 16, 3447 GW Woerden, Netherlands,
  1072.             tel +31 3480-30131, fax +31 3480-30182
  1073.