home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / PIELOGO.ZIP / LPRGRAF.C < prev    next >
C/C++ Source or Header  |  1992-02-02  |  2KB  |  112 lines

  1. /* lprgraf.c     Copyright (c) 1992 Kevin Stokes, Pie in the Sky Software */
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <malloc.h>
  6.  
  7. extern char far *fptr;
  8. extern FILE *lptptr;
  9.  
  10. lprinit()
  11. {
  12.     fptr=farcalloc( (unsigned long) 720*90, (unsigned long) sizeof(char));
  13.        if(fptr==NULL) {printf("\nOut of RAM!\n"); exit(0); }
  14.     lptptr=fopen("PRN","wb");
  15.     if(lptptr == NULL) {printf("can't open PRN device for writing\n");
  16.                  exit(0); }
  17.     setlinesp(24);
  18. }
  19.  
  20.  
  21. lprprint()
  22. {
  23.     int linesp,i,randn;
  24.         unsigned char cdata;
  25.     unsigned long ilong,icol,irow;
  26. /*    lprdrawline(10,10,700,700); */
  27.     for(irow=0; irow < 90; irow=irow+3)    
  28.         {
  29.     lpremit(0x0d);
  30.     lpremit(27);
  31.     lpremit(0x2a);
  32.     lpremit(39);
  33.     lpremit(208);
  34.     lpremit(2);
  35.     for(icol=0; icol < 720; icol++)
  36.       {
  37.          ilong=icol*90+irow;
  38.              cdata=*(fptr+ilong);
  39.          lpremit(cdata);    
  40.              cdata=*(fptr+ilong+1);
  41.          lpremit(cdata);    
  42.              cdata=*(fptr+ilong+2);
  43.          lpremit(cdata);    
  44.           }
  45.     lpremit(0x0d);
  46.     lpremit(0x0a);
  47.     }
  48.     lpremit(0x0d);
  49.     lpremit(0x0a);
  50.     for(ilong=0; ilong < 64800L; ilong++)  /* clear page */
  51.            *(fptr+ilong)=0;
  52. }
  53.  
  54. void setlinesp(nlinesp)
  55. int nlinesp;
  56. {
  57.     if((nlinesp < 0)||(nlinesp > 255)) { 
  58.         printf("\nLinespace value out of range : %d \n",nlinesp);
  59.     }
  60.         else
  61.         {
  62.     lpremit(27);
  63.     lpremit(0x33);
  64.     lpremit(nlinesp);
  65.     printf("\nLine spacing set to %d 180/ths of an inch \n",nlinesp);
  66.     }
  67. }
  68.  
  69. void erroob(ix,iy)
  70. {
  71. printf("\nError: Setpoint out of bounds : %d %d \n",ix,iy);
  72. exit(0);
  73. }
  74.  
  75. void setpoint(ix,iy)
  76. int ix,iy;
  77. {
  78. unsigned long ilong;
  79. unsigned char databit;
  80.  
  81. if((ix<0)||(ix>719)||(iy<0)||(iy>719)) erroob(ix,iy);
  82.  
  83. databit=128 >> (iy & 7);
  84. ilong=iy/8+ix*90;
  85. *(fptr+ilong)=*(fptr+ilong)|databit;
  86. }
  87.  
  88. void lprdrawline(x1,y1,x2,y2)
  89. int x1,y1,x2,y2;
  90. {
  91. float t,delt,length,i;
  92. double ddx,ddy;
  93. int ix,iy,nt;
  94. ddx=(double) (x2-x1);
  95. ddy=(double) (y2-y1);
  96. length= (float) sqrt( ddx*ddx + ddy*ddy);
  97. delt=1./3.;
  98. nt=(int) (length/delt+.5);
  99. for(i=0; i < nt; i++)
  100.   {
  101.   ix=(int) ( (float) i*ddx/(float) nt +(float) x1+.5) ;
  102.   iy=(int) ( (float) i*ddy/(float) nt + (float) y1+.5) ;
  103.   setpoint(ix,iy);
  104.   }
  105. }
  106.  
  107. void lpremit(lchar)
  108. char lchar;
  109. {
  110.     fwrite(&lchar,sizeof(char),1,lptptr);    
  111. }
  112.