home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / vms / zfiogd.x < prev    next >
Text File  |  1989-11-10  |  10KB  |  413 lines

  1. # Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
  2.  
  3. include <mach.h>
  4. include    <fio.h>
  5.  
  6. # ZFIOGD -- FIO device driver for the interactive binary graphics devices.
  7. # This code is host system dependent (at least in part) as well as node
  8. # dependent, since the set of graphics devices available on a particular node
  9. # can vary greatly.  The devices for which driver subroutines are linked
  10. # into this particular version of ZFIOGD are listed below.  The individual
  11. # driver subroutines must be named explicitly in the case statements in
  12. # each generic driver subroutine.
  13.  
  14. define    DEVICES        "|iism70|iism75|imtool|"
  15. define    DELIMCH        ','
  16. define    MAXDEV        8
  17. define    MAXBYTES    4000        # fifo transfer size, bytes
  18. define    MAXTRYS        50        # fifo timeout
  19. define    DELAY        10        # fifo i/o interval, msec
  20.  
  21. define    IISM70        1        # IIS Model 70 image display
  22. define    IISM75        2        # IIS Model 75 image display
  23. define    IMTOOL        3        # Sun IMTOOL display server
  24. define    NDEVICES    3
  25.  
  26.  
  27. ### VMS/IRAF Imtool implemenation.  Use new ZFIOVI driver instead of ZFIOBF.
  28.  
  29. define    MAXBYTES    8192        # fifo transfer size, bytes
  30.  
  31. define  zopnbf  zopnvi
  32. define  zclsbf  zclsvi
  33. define  zardbf  zardvi
  34. define  zawrbf  zawrvi
  35. define  zawtbf  zawtvi
  36.  
  37. ###
  38.  
  39.  
  40. # ZOPNGD -- Open a binary graphics device.  The format of the DEVINFO string
  41. # is "devname:osdev" (the KI will have already taken care of any node prefix
  42. # by the time we are called).
  43.  
  44. procedure zopngd (devinfo, mode, chan)
  45.  
  46. char    devinfo[ARB]        # PACKED device info string
  47. int    mode            # access mode
  48. int    chan            # receives assigned channel
  49.  
  50. bool    first_time
  51. pointer    sp, info, devname, osdev, fname, pkfname, ip, op
  52. int    dev, oschan1, oschan2, arg1, arg2, i
  53. int    strdic(), ctoi(), gstrcpy()
  54. data    first_time /true/
  55. define    err_ 91
  56.  
  57. int    gd_dev[MAXDEV], gd_oschan1[MAXDEV], gd_oschan2[MAXDEV]
  58. int    gd_status[MAXDEV], gd_arg1[MAXDEV], gd_arg2[MAXDEV]
  59. common    /zgdcom/ gd_dev, gd_oschan1, gd_oschan2, gd_status, gd_arg1, gd_arg2
  60.  
  61. begin
  62.     call smark (sp)
  63.     call salloc (info,    SZ_PATHNAME, TY_CHAR)
  64.     call salloc (devname, SZ_FNAME,    TY_CHAR)
  65.     call salloc (osdev,   SZ_FNAME,    TY_CHAR)
  66.     call salloc (fname,   SZ_FNAME,    TY_CHAR)
  67.     call salloc (pkfname, SZ_FNAME,    TY_CHAR)
  68.  
  69.     if (first_time) {
  70.         do i = 1, MAXDEV
  71.         gd_dev[i] = NULL
  72.         first_time = false
  73.     }
  74.  
  75.     # We are passed a packed string by FIO.
  76.     call strupk (devinfo, Memc[info], SZ_PATHNAME)
  77.  
  78.     # Extract generic device name.
  79.     op = devname
  80.     for (ip=info;  Memc[ip] != EOS && Memc[ip] != DELIMCH;  ip=ip+1) {
  81.         Memc[op] = Memc[ip]
  82.         op = op + 1
  83.     }
  84.     Memc[op] = EOS
  85.     if (Memc[ip] == DELIMCH)
  86.         ip = ip + 1
  87.     else
  88.         goto err_
  89.  
  90.     # Look up the generic device name in the device table.
  91.     dev = strdic (Memc[devname], Memc[osdev], 0, DEVICES)
  92.     if (dev <= 0)
  93.         goto err_
  94.  
  95.     # Get the OS device name.
  96.     op = osdev
  97.     for (;  Memc[ip] != EOS && Memc[ip] != DELIMCH;  ip=ip+1) {
  98.         Memc[op] = Memc[ip]
  99.         op = op + 1
  100.     }
  101.     Memc[op] = EOS
  102.     if (Memc[ip] == DELIMCH)
  103.         ip = ip + 1
  104.  
  105.     # Get optional integer arguments.
  106.     if (ctoi (Memc, ip, arg1) <= 0)
  107.         arg1 = 0
  108.     if (Memc[ip] == DELIMCH)
  109.         ip = ip + 1
  110.     if (ctoi (Memc, ip, arg2) <= 0)
  111.         arg2 = 0
  112.  
  113.     # Allocate a slot in the GD device table for the device.  We need this
  114.     # to vector to the correct sub-driver when an i/o function is called.
  115.  
  116.     for (chan=1;  chan <= MAXDEV;  chan=chan+1)
  117.         if (gd_dev[chan] == NULL)
  118.         break
  119.     if (chan > MAXDEV)
  120.         goto err_
  121.  
  122.     # Try to physically open the device.  [ADD NEW DEVICES HERE].
  123.  
  124.     switch (dev) {
  125.     case IISM70:
  126.         # Bidirectional i/o stream.
  127.         call strpak (Memc[osdev], Memc[osdev], SZ_FNAME)
  128.         call zopm70 (Memc[osdev], mode, oschan1)
  129.     case IISM75:
  130.         # Bidirectional i/o stream.
  131.         call strpak (Memc[osdev], Memc[osdev], SZ_FNAME)
  132.         call zopm75 (Memc[osdev], mode, oschan1)
  133.  
  134.     case IMTOOL:
  135.         # Separate output (to device) and input (from device) streams.
  136.         op = fname + gstrcpy (Memc[osdev], Memc[fname], SZ_FNAME)
  137.         Memc[op+1] = EOS
  138.  
  139.         Memc[op] = 'o'
  140.         call strpak (Memc[fname], Memc[pkfname], SZ_FNAME)
  141.         call zopnbf (Memc[pkfname], WRITE_ONLY, oschan1)
  142.         Memc[op] = 'i'
  143.         call strpak (Memc[fname], Memc[pkfname], SZ_FNAME)
  144.         call zopnbf (Memc[pkfname], READ_ONLY, oschan2)
  145.  
  146.     default:
  147.         oschan1 = ERR
  148.     }
  149.  
  150.     if (oschan1 == ERR)
  151.         goto err_
  152.  
  153.     gd_dev[chan]    = dev
  154.     gd_oschan1[chan] = oschan1
  155.     gd_oschan2[chan] = oschan2
  156.     gd_status[chan] = OK
  157.     gd_arg1[chan] = arg1
  158.     gd_arg2[chan] = arg2
  159.  
  160.     call sfree (sp)
  161.     return
  162. err_
  163.     chan = ERR
  164.     call sfree (sp)
  165. end
  166.  
  167.  
  168. # ZCLSGD -- Close a binary graphics device.
  169.  
  170. procedure zclsgd (chan, status)
  171.  
  172. int    chan            # channel assigned device
  173. int    status            # receives status of close
  174.  
  175. int    gd_dev[MAXDEV], gd_oschan1[MAXDEV], gd_oschan2[MAXDEV]
  176. int    gd_status[MAXDEV], gd_arg1[MAXDEV], gd_arg2[MAXDEV]
  177. common    /zgdcom/ gd_dev, gd_oschan1, gd_oschan2, gd_status, gd_arg1, gd_arg2
  178.  
  179. begin
  180.     # [ADD NEW DEVICES HERE].
  181.  
  182.     if (chan < 1 || chan > MAXDEV) {
  183.         status = ERR
  184.         return
  185.     }
  186.  
  187.     switch (gd_dev[chan]) {
  188.     case IISM70:
  189.         call zclm70 (gd_oschan1[chan], status)
  190.     case IISM75:
  191.         call zclm75 (gd_oschan1[chan], status)
  192.     case IMTOOL:
  193.         call zclsbf (gd_oschan2[chan], status)
  194.         call zclsbf (gd_oschan1[chan], status)
  195.     default:
  196.         status = ERR
  197.     }
  198.  
  199.     gd_dev[chan] = NULL
  200. end
  201.  
  202.  
  203. # ZARDGD -- Read from a binary graphics device.
  204.  
  205. procedure zardgd (chan, buf, maxbytes, offset)
  206.  
  207. int    chan            # channel assigned device
  208. char    buf[ARB]        # buffer to be filled
  209. int    maxbytes        # max bytes to read
  210. long    offset            # file offset (function code else zero)
  211.  
  212. int    nread, nleft, ntries, n, op
  213. int    gd_dev[MAXDEV], gd_oschan1[MAXDEV], gd_oschan2[MAXDEV]
  214. int    gd_status[MAXDEV], gd_arg1[MAXDEV], gd_arg2[MAXDEV]
  215. common    /zgdcom/ gd_dev, gd_oschan1, gd_oschan2, gd_status, gd_arg1, gd_arg2
  216.  
  217. begin
  218.     gd_status[chan] = OK
  219.  
  220.     # [ADD NEW DEVICES HERE].
  221.  
  222.     switch (gd_dev[chan]) {
  223.     case IISM70:
  224.         call zrdm70 (gd_oschan1[chan], buf, maxbytes, offset)
  225.     case IISM75:
  226.         call zrdm75 (gd_oschan1[chan], buf, maxbytes, offset)
  227.  
  228.     case IMTOOL:
  229.         # Nothing special here, except that we can only move 4096 bytes at
  230.         # a time through the pipe to the display server.  Some provision
  231.         # for timeout is necessary in the event that the sender dies during
  232.         # the transfer.
  233.  
  234.         nread  = 0
  235.         ntries = 0
  236.         op = 1
  237.  
  238.         for (nleft=maxbytes;  nleft > 0;  ) {
  239.         n = min (nleft, MAXBYTES)
  240.         call zardbf (gd_oschan2[chan], buf[op], n, offset)
  241.         call zawtbf (gd_oschan2[chan], n)
  242.         if (n < 0) {
  243.             nread = ERR
  244.             break
  245.         }
  246.  
  247.         nread = nread + n
  248.         op = op + n / SZB_CHAR
  249.         nleft = nleft - n
  250.         if (n == 0)
  251.             call zwmsec (DELAY)
  252.  
  253.         ntries = ntries + 1
  254.         if (ntries > MAXTRYS) {
  255.             nread = ERR
  256.             break
  257.         }
  258.         }
  259.  
  260.         gd_status[chan] = nread
  261.  
  262.     default:
  263.         gd_status[chan] = ERR
  264.     }
  265. end
  266.  
  267.  
  268. # ZAWRGD -- Write to a binary graphics device.
  269.  
  270. procedure zawrgd (chan, buf, nbytes, offset)
  271.  
  272. int    chan            # channel assigned device
  273. char    buf[ARB]        # buffer containing the data
  274. int    nbytes            # nbytes to be written
  275. long    offset            # file offset (function code else zero)
  276.  
  277. int    nwrote, nleft, ntries, n, ip
  278. int    gd_dev[MAXDEV], gd_oschan1[MAXDEV], gd_oschan2[MAXDEV]
  279. int    gd_status[MAXDEV], gd_arg1[MAXDEV], gd_arg2[MAXDEV]
  280. common    /zgdcom/ gd_dev, gd_oschan1, gd_oschan2, gd_status, gd_arg1, gd_arg2
  281.  
  282. begin
  283.     gd_status[chan] = OK
  284.  
  285.     # [ADD NEW DEVICES HERE].
  286.  
  287.     switch (gd_dev[chan]) {
  288.     case IISM70:
  289.         call zwrm70 (gd_oschan1[chan], buf, nbytes, offset)
  290.     case IISM75:
  291.         call zwrm75 (gd_oschan1[chan], buf, nbytes, offset)
  292.  
  293.     case IMTOOL:
  294.         # Nothing special here, except that we can only move 4096 bytes at
  295.         # a time through the pipe to the display server.  Some provision 
  296.         # for timeout is necessary to avoid an infinite loop in the event
  297.         # that the receiver dies during the transmission.
  298.  
  299.         nwrote = 0
  300.         ntries = 0
  301.         ip = 1
  302.  
  303.         for (nleft=nbytes;  nleft > 0;  ) {
  304.         n = min (nleft, MAXBYTES)
  305.         call zawrbf (gd_oschan1[chan], buf[ip], n, offset)
  306.         call zawtbf (gd_oschan1[chan], n)
  307.         if (n < 0) {
  308.             nwrote = ERR
  309.             break
  310.         }
  311.  
  312.         ip = ip + n / SZB_CHAR
  313.         nwrote = nwrote + n
  314.         nleft = nleft - n
  315.         if (n == 0)
  316.             call zwmsec (DELAY)
  317.  
  318.         ntries = ntries + 1
  319.         if (ntries > MAXTRYS) {
  320.             nwrote = ERR
  321.             break
  322.         }
  323.         }
  324.  
  325.         gd_status[chan] = nwrote
  326.  
  327.     default:
  328.         gd_status[chan] = ERR
  329.     }
  330. end
  331.  
  332.  
  333. # ZAWTGD -- Wait for i/o to a binary graphics device.
  334.  
  335. procedure zawtgd (chan, status)
  336.  
  337. int    chan            # channel assigned device
  338. int    status            # receives nbytes transferred or ERR
  339.  
  340. int    gd_dev[MAXDEV], gd_oschan1[MAXDEV], gd_oschan2[MAXDEV]
  341. int    gd_status[MAXDEV], gd_arg1[MAXDEV], gd_arg2[MAXDEV]
  342. common    /zgdcom/ gd_dev, gd_oschan1, gd_oschan2, gd_status, gd_arg1, gd_arg2
  343.  
  344. begin
  345.     if (gd_status[chan] == ERR) {
  346.         status = ERR
  347.         return
  348.     }
  349.     
  350.     # [ADD NEW DEVICES HERE].
  351.  
  352.     switch (gd_dev[chan]) {
  353.     case IISM70:
  354.         call zwtm70 (gd_oschan1[chan], status)
  355.     case IISM75:
  356.         call zwtm75 (gd_oschan1[chan], status)
  357.     case IMTOOL:
  358.         status = gd_status[chan]
  359.     default:
  360.         status = ERR
  361.     }
  362. end
  363.  
  364.  
  365. # ZSTTGD -- Get the file status of a binary graphics device.
  366.  
  367. procedure zsttgd (chan, what, lvalue)
  368.  
  369. int    chan            # channel assigned device
  370. int    what            # status parameter being queried
  371. long    lvalue            # receives value of parameter
  372.  
  373. int    gd_dev[MAXDEV], gd_oschan1[MAXDEV], gd_oschan2[MAXDEV]
  374. int    gd_status[MAXDEV], gd_arg1[MAXDEV], gd_arg2[MAXDEV]
  375. common    /zgdcom/ gd_dev, gd_oschan1, gd_oschan2, gd_status, gd_arg1, gd_arg2
  376.  
  377. begin
  378.     # [ADD NEW DEVICES HERE].
  379.  
  380.     switch (gd_dev[chan]) {
  381.     case IISM70:
  382.         call zstm70 (gd_oschan1[chan], what, lvalue)
  383.     case IISM75:
  384.         call zstm75 (gd_oschan1[chan], what, lvalue)
  385.  
  386.     case IMTOOL:
  387.         switch (what) {
  388.         case FSTT_FILSIZE:
  389.         lvalue = gd_arg1[chan] * gd_arg2[chan] * SZB_CHAR
  390.         case FSTT_BLKSIZE:
  391.         lvalue = gd_arg1[chan] * SZB_CHAR
  392.         case FSTT_OPTBUFSIZE:
  393.         lvalue = gd_arg1[chan] * SZB_CHAR
  394.         case FSTT_MAXBUFSIZE:
  395.         lvalue = 32768
  396.         default:
  397.         lvalue = ERR
  398.         }
  399.     default:
  400.         lvalue = ERR
  401.     }
  402. end
  403.                                        
  404.                                                                
  405.                                                                
  406.                                                                
  407.                                                                
  408.                                                               
  409.  
  410.                                                                
  411.                                                                
  412.                                                                
  413.