      include 'fgraph.fi'

c     Purpose:  Graphics routines to use with MS Compilers

      integer*2 function vopnwk()
      implicit integer*2 (a-z)

      include 'fgraph.fd'

      record    /videoconfig/ myscreen

      integer            jfill,jplot
      logical                        lfil
      common    /instl2/ jfill,jplot,lfil

      common    /vgraph/ idxl,idyl

c     Open workstation, home cursor, set up scaling

      call     getvideoconfig(myscreen)
      status = setvideomode ( $MAXRESMODE )
      call     getvideoconfig( myscreen )
      ixln   = myscreen.numxpixels - 1
      iyln   = myscreen.numypixels - 1
      idxl   = 32640.0/(ixln+1) + 0.5
      idyl   = 22480.0/(iyln+1) + 0.5
      if(myscreen.numcolors .le. 4) then
        jfill = 1
      else
        jfill = 2
      endif
      call     clearscreen( $GCLEARSCREEN )
      vopnwk = 0

      end

      integer*2 function vclrwk()
      implicit integer*2 (a-z)

      include 'fgraph.fd'

c     Clear workstation

      call     clearscreen( $GCLEARSCREEN )
      vclrwk = 0

      end

      integer*2 function vclswk()
      implicit integer*2 (a-z)

      include 'fgraph.fd'

      record /rccoord / s

c     Home cursor - text mode

      call     settextposition( 1 , 1 , s )
      vclswk = settextcursor ( #0607 )
      vclswk = setvideomode  ( $TEXTC80 )
      vclswk = displaycursor ( $GCURSORON )

      end

      integer*2 function vrqstr(len,echoh,ixy,cstr)

c     Input a single character

      integer*2   ixy
      integer     len,echoh
      character*1 cstr
      read(*,'(a1)') cstr
      vrqstr = 0

      end

      integer*2 function vslcol(it)
      implicit integer*2 (a-z)

      include 'fgraph.fd'

      integer*2 ipal(7)
      integer         jfill,jplot
      logical                     lfil
      common /instl2/ jfill,jplot,lfil

c     Set line color

      data ipal/ 15, 4, 2, 1, 14, 3, 5/
      if(it.gt.0 .and. it.le.7 ) then
        icll = ipal(it)
        if(jfill.lt.2) icll = 1
      else
        icll = 0
      endif
      vslcol = setcolor( icll )

      end

      integer*2 function vpline(npt,ixy)
      implicit integer*2 (a-z)

      include 'fgraph.fd'

      integer*2 ixy(2,*), ir1,ir2,irc
      integer   npt
      record /xycoord/ xy
      common /vgraph/ idxl,idyl

c     Draw line

      ir1 = idxl
      ir2 = idyl
      irc = 22200
      call     moveto( ixy(1,1)/ir1 , (irc - ixy (2,1))/ir2 , xy )
      do 100 n = 2,npt
        vpline =  lineto(ixy(1,n)/ir1 ,(irc - ixy(2,n))/ir2 )
100   continue

      end

      integer*2 function vencur()
      implicit integer*2 (a-z)

c     Display cursor

      vencur = 0

      end

      subroutine dplot(x,y,ipen)

c     Purpose: Plot line routine

c     Inputs:
c        x         - X-normalized coordinate to plot
c        y         - Y-normalized coordinate to plot
c        ipen      - Pen action: = 2 draw; = 3 move

c     Outputs:
c        none

      implicit   none

      integer*2  status,vpline
      integer    ipen
      real*8     x,y

      integer*2       ixy
      common /pdata2/ ixy(4)

c     Pen command motions  (ipen = 2, pendown)

      ixy(3) = 22000*x
      ixy(4) = 22000*y
      if(ipen.eq.2) then
        status = vpline(2,ixy)
      endif
      ixy(1) = ixy(3)
      ixy(2) = ixy(4)

      end
