
	SUBROUTINE DDMATE (CONTRL, INTIN, PTSIN, INTOUT, PTSOUT)
C  *******29/6/83   12:00  WF   COLOR   ************
C  28/MAERZ/1984 08:15     WF  SOFT CHARACTER GENERATOR IMPLEMENTED 8*8
C  DEVICE DRIVER FOR NCR DECISION MATE
	IMPLICIT INTEGER (A-Z)
	INTEGER CONTRL(1), INTIN(1), PTSIN(1), INTOUT(1), PTSOUT(1)
        INTEGER*1 HOLLOW, SOLID, HATCH, PATTRN
	INTEGER XROT(40), YROT(40)
	INTEGER MODES(4), CHRWID(16), CHRHGT(16), CELWID(16), CELHGT(16)
	INTEGER CHRMID(16)
C  DEFINITION OF COMMON AREA FOR DECISION MATE DRIVER
	INTEGER NDLNTP, NDCLRL, NDCLRM, NDMKTP, NDCLRT, NDFSTL
	INTEGER NDFLIN, NDCLRF, CLRTBL(2,3), NDWRMD, NDTXRT, NDTXSZ
        INTEGER NDLCMD, NDVLMD, NDCHMD, NDSTMD
	COMMON /CMMATE/ NDLNTP, NDCLRL, NDCLRM, NDMKTP, NDCLRT, NDFSTL,
     *                  NDFLIN, NDCLRF, CLRTBL, NDWRMD, NDTXRT, NDTXSZ,
     *                  NDLCMD, NDVLMD, NDCHMD, NDSTMD, NDTFNT
C
	DATA MODES /32, 35, 33, 34/
        DATA XROT /0,1,0,-1,
     *		   0,9,0,-9,
     *		   0,9,0,-9,
     *	           0,9,0,-9,
     *		   0,9,0,-9,
     *		   0,1,0,-1,
     *		   0,9,0,-9,
     *		   0,9,0,-9,
     *		   0,9,0,-9,
     *		   0,7,0,-7/
        DATA YROT /-1,0,1,0,
     *		   -9,0,9,0,
     *		   -9,0,9,0,
     *		   -9,0,9,0,
     *             -9,0,9,0,
     *		   -1,0,1,0,
     *		   -9,0,9,0,
     *             -9,0,9,0,
     *		   -9,0,9,0,
     *		   -7,0,7,0/
	DATA HOLLOW, SOLID, HATCH, PATTRN /0, 1, 2, 3/
C *     CHARACTER WIDTH AND HEIGHT FOR 16 DIFFERENT SIZES
	DATA CHRWID /5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80/
	DATA CHRHGT /7,14,21,28,35,42,49,56,63,70,77,84,91,98,105,112/
        DATA CHRMID /10,17,24,31,38,45,52,59,66,73,80,87,94,101,108,115/
C *    CHARACTER CELL WIDTH AND HEIGHT FOR 16 DIFFERENT SIZES
	DATA CELWID /8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128/ 
	DATA CELHGT /8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128/
C
	CONTRL(3) = 0
	OPCODE = CONTRL(1)
C
C  OPEN WORKSTATION
C
	IF (OPCODE .NE. 1) GO TO 2000
	   CONTRL(3) = 6
	   CONTRL(5) = 45
	   NDLNTP = INTIN(2) - 1
           IF (NDLNTP .LT. 0 .OR. NDLNTP .GT. 15) NDLNTP = 0
C	POLYLINE COLOR INDEX
           NDCLRL = INTIN(3)
C	MARKER TYPE
	   NDMKTP = INTIN(4)
	   IF (NDMKTP .LT. 1 .OR. NDMKTP .GT. 5) NDMKTP = 1
C	POLYMAKER COLOR INDEX
	   NDCLRM = INTIN(5)
C	TEXT COLOR INDEX
	   NDCLRT = INTIN(7)
	   NDFSTL = INTIN(8)
	   NDFLIN = INTIN(9)
C	FILL COLOR INDEX
	   NDCLRF = INTIN(10)
C
C	GET COLOR INDEX FROM HARDWARE
	   CALL GETCOL (INTOUT(36),INTOUT(14),INTOUT(40))
C	RED
	   CLRTBL(1,1) = 0
C	GREEN	
	   CLRTBL(1,2) = 0
C	BLUE
	   CLRTBL(1,3) = 0
C	RED
	   CLRTBL(2,1) = 1000
C	GREEN
	   CLRTBL(2,2) = 1000
C	BLUE
	   CLRTBL(2,3) = 1000
C *        GRAPHIC MODE ON
           CALL GRAPON
C *	   SET DEFAULT DRAWING MODE TO REPLACE
	   CALL DRAWM (32)
	   NDWRMD = 32
C *        SET DEFAULT CHARACTER SIZE TO SMALLEST
	   NDTXSZ = 1
	   CALL ZOOMA (NDTXSZ-1)
C *        SET CHARCTER UP VECTOR TO NO ROTATION
	   NDTXRT = 0
C *	   SET FONT TO NORMAL
	   NDTFNT = 0
	   CALL FONT (NDTFNT)
C *        SET INPUT MODE TO REQUEST MODE FOR LOCATOR, VALUATOR, CHOICE
C *        AND STRING
	   NDLCMD = 1
           NDVLMD = 1
           NDCHMD = 1
           NDSTMD = 1
	   GO TO 99000
C
C  CLOSE WORKSTATION
C
2000	CONTINUE
	IF (OPCODE .NE. 2) GO TO 3000
	   CALL GRAPOF
	   GO TO 99000
C
C  CLEAR WORKSTATION
C
3000    CONTINUE
	IF (OPCODE .NE. 3) GO TO 8000
	   CALL GCLSCR 
C *	   RESTORE DRAWING MODE SINCE CLEAR SCREEN SETS IT TO ERASE
	   CALL DRAWM (NDWRMD) 
           GO TO 99000
C
C  POLYLINE
C
C
C  TEXT
C
8000	CONTINUE
	IF (OPCODE .NE. 8) GO TO 11000
	   X = PTSIN(1)
	   Y = PTSIN(2)
C * 	   MODIFY COORDINATES BASED ON ROATION & SIZE TO MAKE LOWER
C *        LEFT HAND CORNER OF CHARACTER APPEAR AT SPECIFIED LOCATION.
C *        TO DO THIS, YOU MUST COMPENSATE FOR THE 4 RASTER GAP AT
C *        THE BOTTOM OF A CHARACTER CELL AND THE 1 RASTER GAP AT THE
C *        LEFT OF THE CHARACTER CELL.
	   I = 4 * NDTFNT + (NDTXRT + 1)
	   X = X + (NDTXSZ * XROT(I))
	   Y = Y + (NDTXSZ * YROT(I))
	   X = MIN0 (MAX0 (X, 0), 639)
	   Y = MIN0 (MAX0 (Y, 0), 399)
C *        MOVE TO STARTING POSITION
	   CALL KURS (X, Y)
C *        OUTPUT THE TEXT STRING
	   J = CONTRL(4)
	   CALL GRCD (J, INTIN, NDTXRT*2)
	   GO TO 99000
C
C  GENERALIZED DRAWING PRIMITIVE
C
11000	CONTINUE
	IF (OPCODE .NE. 11) GO TO 12000
	   OPCODE = CONTRL(6)
C *        IS THIS A BAR OPCODE ?
           IF (OPCODE .EQ. 1) GO TO 11100
	   GO TO 99000
C *        BAR
11100      CONTINUE
C *        COMPUTE HORIZONTAL AND VERTICAL DISPLACEMENT
	      I = PTSIN(3) - PTSIN(1)
	      J = PTSIN(4) - PTSIN(2)
	      IF (I .LT. 0 .OR. I .EQ. 0) I= 1
	      IF (J .LT. 0 .OR. J .EQ. 0) J= 1	 	
              CALL KURS (PTSIN(1), PTSIN(2))
C *        IF INTERIOR FILL STYLE IS HOLLOW , DRAW A RECTANGLE
C *        OTHERWISE, DRAW A FILLED BOX
	      IF (NDFSTL .NE. HOLLOW) GO TO 11300
	         CALL CH (0)
                 CALL REC (I, J, 0)
                 GO TO 99000
C *        FILL STYLE IS SOLID 
11300         CONTINUE
	      IF (NDFSTL .EQ. SOLID) CALL CH (0)
C *        FILL STYLE IS PATTERN OR HATCH
	   IF(NDFSTL .EQ. PATTRN .OR. NDFSTL .EQ. HATCH)CALL CH(NDFLIN)
	      CALL ZOOMA (0)
	      CALL BOX (I, J, 0)
	      GO TO 99000  
C
C  SET CHARACTER HEIGHT
C
12000	CONTINUE
	IF (OPCODE .NE. 12) GO TO 21000
C *	   GET REQUESTED CHARACTER HEIGHT
	   NDTXSZ = ptsin(2)
C *        MAKE SURE SIZE BETWEEN 1 AND 16
	   IF (NDTXSZ .LT. 1) NDTXSZ = 1
	   IF (NDTXSZ .GT. 16) NDTXSZ = 16
	   CONTRL(3) = 2
C *        MAP 1 - 16 TO 0 - 15 AND SET CHARACTER ZOOM FACTOR
	   CALL ZOOMA (NDTXSZ-1)
	   GO TO 99000
C
C  SET TEXT FONT
C 
21000	CONTINUE
	IF (OPCODE .NE. 21 ) GO TO 28000
	   NDTFNT = INTIN (1)
	   CALL FONT (NDTFNT)
	   GO TO 99000
C
C  INPUT LOCATOR
C
28000	CONTINUE
	IF (OPCODE .NE. 28) GO TO 30000
	CALL DRAWM(33)
	X=NDMKTP
	NDMKTP=2
28001	CALL CURMRK(PTSIN(1),PTSIN(2))
	A=PTSIN(1)
	B=PTSIN(2)
	CALL INLOC (Y,A,B)
	CALL CURMRK(PTSIN(1),PTSIN(2))
	PTSIN(1)=A
	PTSIN(2)=B
	IF (Y.EQ.0) GOTO 28001	
	CONTRL(3)=1
	CONTRL(5)=1
	INTOUT(1)=Y
	PTSOUT(1)=PTSIN(1)
	PTSOUT(2)=PTSIN(2)
	NDMKTP=X
	CALL DRAWM(NDWRMD)
	   GO TO 99000
C
C  INPUT CHOICE
C
30000	CONTINUE
	IF (OPCODE .NE. 30) GO TO 31000
	CALL CHOICE (I)
	INTOUT(1) = I
	CONTRL(5) = 0
	CONTRL(3) = 0
	IF (I .LT. 224) GO TO 99000
	INTOUT(1) = INTOUT(1) - 223
	CONTRL(5) = 1
        GO TO 99000   
C
C  INPUT STRING
C
31000	CONTINUE
	IF (OPCODE .NE. 31) GO TO 32000
	CONTRL(3) = 0
	CONTRL(5) = 0
	I=1
	IF (INTIN(3) .NE. 1) GO TO 31200
	   X = PTSIN(1)
	   Y = PTSIN(2)
C * 	   MODIFY COORDINATES BASED ON ROATION & SIZE TO MAKE LOWER
C *        LEFT HAND CORNER OF CHARACTER APPEAR AT SPECIFIED LOCATION.
C *        TO DO THIS, YOU MUST COMPENSATE FOR THE 4 RASTER GAP AT
C *        THE BOTTOM OF A CHARACTER CELL AND THE 1 RASTER GAP AT THE
C *        LEFT OF THE CHARACTER CELL.
	   I = 4 * NDTFNT + (NDTXRT + 1)
	   X = X + (NDTXSZ * XROT(I))
	   Y = Y + (NDTXSZ * YROT(I))
	   X = MIN0 (MAX0 (X, 0), 639)
	   Y = MIN0 (MAX0 (Y, 0), 399)
C *        MOVE TO STARTING POSITION
	   CALL KURS (X, Y)
	   A=INTIN(2)
	   CALL ZEILE(1)
	   DO 31100 I=1,A
	      CALL GRCD (1,95,0)
31100	CONTINUE
	   CALL ZEILE(0)
	   I=1
	   CALL KURS (X,Y)
	   CALL ZEILE(1)
31200   IF (INTIN(2) .EQ. 0) GO TO 31400
	CALL DRAWM (33)
	CALL GRCD (1,127,0)
	CALL KEYIN (INTOUT(I))
	CALL GRCD (1,8,0)
	CALL GRCD (1,127,0)
	CALL DRAWM (NDWRMD)	
	CALL GRCD (1,8,0)
	IF (INTOUT(I) .EQ. 13) GO TO 31500
	if (INTOUT(I) .EQ. 27) GO TO 31500
	IF (INTOUT(I) .EQ. 8 ) GO TO 31300
	CONTRL(5)=CONTRL(5)+1
	IF (INTIN(3) .EQ. 1) GO TO 31250
31220	I = I + 1
	INTIN(2) = INTIN(2) -1
	GO TO 31200
31250   CONTINUE
	CALL DRAWM (34)
	CALL GRCD (1,95,0)
	CALL GRCD (1,8,0)
	CALL DRAWM (NDWRMD) 
	CALL GRCD(1,INTOUT(I),0)
	GO TO 31220
31300	CONTINUE
	IF (I .EQ. 1 ) GO TO 31200
	IF (INTIN(3) .NE. 1 ) GO TO 31350
	CALL GRCD(1,8,0)
	CALL DRAWM (34)
	I=I-1
	CALL GRCD (1,INTOUT(I),0)
	I=I+1
	CALL DRAWM (NDWRMD)
	CALL GRCD (1,8,0)
	CALL GRCD (1,95,0)
	CALL GRCD (1,8,0) 
31350	CONTINUE
	I = I - 1
	CONTRL(5) = CONTRL(5) - 1
	INTIN(2) = INTIN(2)+1
	GO TO 31200  
31400	CONTINUE
	CALL KEYIN (INTOUT(I))
	IF (INTOUT(I) .EQ. 8) GO TO 31300
31500	CONTINUE
	IF (INTIN(3) .EQ. 1) CALL ZEILE(0)
	GOTO 99000
C
C  SET WRITING MODE
C
32000	CONTINUE
	IF (OPCODE .NE. 32) GO TO 33000	
C *	   MAKE SURE WRITING MODE IS VALID.  IF NOT, SET TO REPLACE
	   I = INTIN(1)
	   IF (I .LT. 1 .OR. I .GT. 4) I = 1
C *	   LOOK UP 7220 CODE FOR WRITING MODE IN TABLE
	   NDWRMD = MODES(I)
	   CALL DRAWM (NDWRMD)
C *	   RETURN WRITING MODE SELECTED
	   INTOUT(1) = I
	   GO TO 99000
C
C  SET INPUT MODE
C
33000	CONTINUE
	IF (OPCODE .NE. 33) GO TO 99000
C *	   DEVICE ONLY HAS REQUEST MODE INPUT
	   INTOUT(1) = 1
	   GO TO 99000
C
C *	EXIT FROM DEVICE DRIVER
C
99000	CONTINUE
	RETURN
	END
