C
C PLOTROUTINES AND INITIALIZATION FOR PCONE
C
C     ***** VERSION 04-09-84 *****
C
      SUBROUTINE INSIZE
C
C SUBROUTINE TO COMPUTE PLOTPLANESIZE, DEPENDING ON ORIENTATION
C
      COMMON /NXNY/ NX,NY,NGX,NGY,ISIZE
C
C BY CHANGING NYY AND NXX THE DIMENSION OF THE PLOTPLANE MAY BE CHANGED,
C AS LONG AS NY*NX=<1260. NY SHOULD BE A MULTIPLE OF 8/3
C
      NY=80
      NX=126
      NGX=NX*3
      NGY=NY*36/10
      ISIZE=NGY/8*NGX
      RETURN
      END
      SUBROUTINE RESET
      LOGICAL DATA(3780)
      COMMON /GRID/ DATA
      COMMON /POSIT/IX,IY,IOX,IOY
      COMMON /OFFSET/IDIFF
      COMMON /NXNY/ NX,NY,NGX,NGY,ISIZE
C
C IX,IY ARE THE CURRENT COORDINATES IN THE PLOTFIELD, IOX AND IOY ARE
C OFFSETS, NECESSARY TO KEEP COMPATIBILITY WITH CALCOMP CONVENTIONS
C
      IX=1
      IY=1
      IOX=0
      IOY=0
      DO 1 I=1,1260
    1 DATA(I)=0
C
C ISIZE IS THE SIZE OF THE PLOTARRAY
C
      DO 2 I=1,ISIZE
      J=IDIFF+I
    2 DATA(J)=0
      RETURN
      END
      SUBROUTINE SETPC(LX,LY)
C
C SUBROUTINE TO SET A GRIDPOINT IN THE PLOTGRID
C
      LOGICAL IHULP(8),DATA(3780)
      COMMON /GRID/ DATA
      COMMON /OFFSET/IDIFF
      COMMON /NXNY/ NX,NY,NGX,NGY,ISIZE
      DATA IHULP/1,2,4,8,16,32,64,-128/
C
C IF YOU ARE SURE THAT ALL PARAMETERS ARE WITHIN BOUNDS, YOU MAY
C ELIMINATE THE TWO STATEMENTS BELOW
C
      IF((LX.LE. 0).OR.(LY.LE.0)) RETURN
      IF((LX.GT.NGX).OR.(LY.GT.NGY)) RETURN
      LYH=LY-1
      IBIT=MOD(LYH,8)+1
      IAD=LX+(LYH/8)*NGX+IDIFF
      DATA(IAD)=DATA(IAD).OR.IHULP(IBIT)
      RETURN
      END
      SUBROUTINE PRINTP(NX,NY,DATA)
C
C THIS SUBROUTINE PRINTS THE MEMORY ARRAY ON A MX-80 PRINTER-PLOTTER
C ALL PRINTER INITIALIZATION IS HANDLED IN THIS ROUTINE.
C AN ASSEMBLER PRINTERDRIVER MADE BY JAN SCHOUTEN IS USED UNDER CP/M.
C SOME BIOS ROUTINES MAY NOT BE USABLE, BECAUSE THEY SEND ONLY 7 BITS TO
C THE OUTPUT PORT. IN THAT CASE THE OUTPUT PORT HAS TO BE ADRESSED
C DIRECTLY.
C  PARAMETERS: NX: NUMBER OF POINTS IN THE X DIRECTION
C              NY: NUMBER OF POINTS IN THE Y DIRECTION
C              DATA: MEMORY ARRAY
C
C THIS ROUTINE DOES NOT WORK FOR A KAYPRO-4. A FIX IS AVAILABLE
C AS A SEPARATE DRIVER ROUTINE
C
      LOGICAL ESC,ACHT,NX1,NX2,LF,CR,A,FF,FIRST,HULP,CHAR,EMPH,NEG
      LOGICAL MIRROR,DATA(1)
      DATA ESC,ACHT,LF,CR,A,FF,FIRST,NEG/27,8,10,13,65,12,0,9/
    1 FORMAT(' ENTER "E" FOR EMPHASISED "N" FOR NO PLOT: ')
      WRITE(5,1)
    2 FORMAT(A1)
      READ(5,2) CHAR
      IF(CHAR.EQ.78) RETURN
    3 FORMAT(' ENTER "M" FOR MIRROR IMAGE PLOT: ')
      WRITE(5,3)
      READ(5,2) MIRROR
      IF(MIRROR.NE.77) MIRROR=.FALSE.
C
C THIS TRANSFORMATION IS NECESSARY TO MAKE LOGICAL EXPRESSIONS WORK
C AS EVERY NON ZERO CHARACTER IS INTERPRETED AS TRUE
C
      IF(MIRROR) MIRROR=.TRUE.
    4 FORMAT(' MIRROR IMAGE PRINTED')
      IF(MIRROR) WRITE(5,4)
C
C SKIP INITIALIZATION WHEN ALREADY DONE
C
      IF(FIRST) GOTO 30
C
C INITIALIZE THE LIST DEVICE -THIS IS AN ASSEMBLY SUBROUTINE
C
      call initld
C
C initialize the printer to a linefeed of 8/72 inch
C
   30 CALL LSTOUT(ESC)
      CALL LSTOUT(A)
      CALL LSTOUT(ACHT)
      CHAR=(CHAR.NE.69)
      NX1=MOD(NX,256)
      NX2=NX/256
      MY=(NY-1)/8+1
      EMPH=75
C
C SELECT BETWEEN EMPHASISED AND SINGLE PRINT
C
      IF(CHAR) GOTO 60
      NX1=MOD(NX*2,256)
      NX2=NX/128
      EMPH=76
   60 FIRST=FIRST+1
C
C GIVE A FORMFEED AFTER PLOTTING TWO FIGURES, BUT NOT INITIALLY
C
      IF(FIRST.EQ.4) FIRST=2
      IF(FIRST.EQ.3) CALL LSTOUT(FF)
C
C NEW LINE AND CARRIAGE RETURN
C
      CALL LSTOUT(LF)
      CALL LSTOUT(CR)
   40 DO 10 KH=1,MY
C
C PRINTING STARTS AT THE UPPER LEFT CORNER OF THE PLOTMATRIX
C
      I=(MY+1-KH)
      IEIND=I*NX
      ISTART=IEIND-NX+1
C
C SET THE MX-80 IN (EMPHASISED) GRAPHICS MODE
C
      CALL LSTOUT(ESC)
      CALL LSTOUT(EMPH)
C
C INFORM MX-80 OF NUMBER OF GRAPHICS POINTS
C
      CALL LSTOUT(NX1)
      CALL LSTOUT(NX2)
      JH=IEIND+1
      DO 20 J=ISTART,IEIND
      IF(.NOT.MIRROR) JH=J
      IF(MIRROR) JH=JH-1
      LH=JH-1
      IF(LH.LT.ISTART) LH=ISTART
      IF(CHAR) GOTO 50
C
C THE OUTPUT IS "OR-ED" WITH THE PREVIOUS ONE TO GIVE CONTINUITY
C WHEN THE PLOT IS EMPHASISED
C
      HULP=DATA(JH).OR.DATA(LH)
      CALL LSTOUT(HULP)
   50 CALL LSTOUT(DATA(JH))
   20 CONTINUE
C
C NEW LINE AND CARRIAGE RETURN
C
      CALL LSTOUT(LF)
      CALL LSTOUT(CR)
   10 CONTINUE
C
C RESET THE PRINTER TO NORMAL 1/8 INCH LINE SPACING
C
      CALL LSTOUT(ESC)
      CALL LSTOUT(A)
      CALL LSTOUT(NEG)
      RETURN
      END
      SUBROUTINE IPLOT(X,Y,IDR)
      INTEGER X,Y,PX,PY,IX,IY,INCX,INCY,IOX,IOY
      LOGICAL STUURX,STUURY
      COMMON /POSIT/ PX,PY,IOX,IOY
      IF(IDR.GE.0) GOTO 1
      IOX=X
      IOX=Y
      RETURN
    1 IF(IDR.NE.3) GOTO 1000
      PX=X-IOX
      PY=Y-IOY
      RETURN
C
C DETERMINE THE PLOTDIRECTION
C
 1000 IX=MAX0(0,X-IOX)-PX
      IY=MAX0(0,Y-IOY)-PY
C
C DETERMINE THE NUMBER OF STEPS
C
      ISTEP=MAX0(IABS(IX),IABS(IY))
      CALL SETPC(PX,PY)
      IF(ISTEP.EQ.0) RETURN
C
C DETERMINE THE RELATIVE INCREASES
C
 1100 SX=FLOAT(IX)/ISTEP*15000
      SY=FLOAT(IY)/ISTEP*15000
C
C ADD ONE TO PREVENT ROUND-OFF ERROR
C
      INCX=IFIX(ABS(SX))+1
      INCY=IFIX(ABS(SY))+1
      STUURX=0
      STUURY=0
      IF(IX.LT.0) STUURX=-1
      IF(IX.GT.0) STUURX=1
      IF(IY.LT.0) STUURY=-1
      IF(IY.GT.0) STUURY=1
      ITELX=0
      ITELY=0
      IF(INCX.LT.INCY) GOTO 150
      ITELY=0
      DO 100 I=1,ISTEP
      ITELY=ITELY+INCY
      IF(ITELY.LE.15000) GOTO 120
      PX=PX+STUURX
      PY=PY+STUURY
      CALL SETPC(PX,PY)
      ITELY=ITELY-15000
      GOTO 100
  120 PX=PX+STUURX
      CALL SETPC(PX,PY)
  100 CONTINUE
      RETURN
 150  ITELX=0
      DO 160 I=1,ISTEP
      ITELX=ITELX+INCX
      IF(ITELX.LE.15000) GOTO 170
      PX=PX+STUURX
      PY=PY+STUURY
      CALL SETPC(PX,PY)
      ITELX=ITELX-15000
      GOTO 160
  170 PY=PY+STUURY
      CALL SETPC(PX,PY)
  160 CONTINUE
      RETURN
      END
      END












