aboutsummaryrefslogtreecommitdiff
path: root/sys/gio/gki
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/gio/gki
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/gio/gki')
-rw-r--r--sys/gio/gki/README84
-rw-r--r--sys/gio/gki/gki.com8
-rw-r--r--sys/gio/gki/gkicancel.x28
-rw-r--r--sys/gio/gki/gkiclear.x28
-rw-r--r--sys/gio/gki/gkiclose.x65
-rw-r--r--sys/gio/gki/gkideact.x42
-rw-r--r--sys/gio/gki/gkieof.x23
-rw-r--r--sys/gio/gki/gkiesc.x40
-rw-r--r--sys/gio/gki/gkiexe.x178
-rw-r--r--sys/gio/gki/gkifa.x37
-rw-r--r--sys/gio/gki/gkifaset.x35
-rw-r--r--sys/gio/gki/gkifetch.x80
-rw-r--r--sys/gio/gki/gkifflush.x24
-rw-r--r--sys/gio/gki/gkiflush.x40
-rw-r--r--sys/gio/gki/gkigca.x87
-rw-r--r--sys/gio/gki/gkigcur.x106
-rw-r--r--sys/gio/gki/gkigetwcs.x44
-rw-r--r--sys/gio/gki/gkiinit.x22
-rw-r--r--sys/gio/gki/gkiinline.x23
-rw-r--r--sys/gio/gki/gkikern.x30
-rw-r--r--sys/gio/gki/gkiopen.x67
-rw-r--r--sys/gio/gki/gkipca.x47
-rw-r--r--sys/gio/gki/gkipl.x37
-rw-r--r--sys/gio/gki/gkiplset.x37
-rw-r--r--sys/gio/gki/gkipm.x37
-rw-r--r--sys/gio/gki/gkipmset.x37
-rw-r--r--sys/gio/gki/gkiprint.x820
-rw-r--r--sys/gio/gki/gkirca.x30
-rw-r--r--sys/gio/gki/gkircval.x51
-rw-r--r--sys/gio/gki/gkireact.x42
-rw-r--r--sys/gio/gki/gkiredir.x34
-rw-r--r--sys/gio/gki/gkiscur.x37
-rw-r--r--sys/gio/gki/gkisetwcs.x46
-rw-r--r--sys/gio/gki/gkititle.x51
-rw-r--r--sys/gio/gki/gkitx.x57
-rw-r--r--sys/gio/gki/gkitxset.x51
-rw-r--r--sys/gio/gki/gkiwesc.x59
-rw-r--r--sys/gio/gki/gkiwrite.x26
-rw-r--r--sys/gio/gki/gkptxparg.x47
-rw-r--r--sys/gio/gki/mkpkg46
-rw-r--r--sys/gio/gki/zzdebug.x44
41 files changed, 2727 insertions, 0 deletions
diff --git a/sys/gio/gki/README b/sys/gio/gki/README
new file mode 100644
index 00000000..171de8d9
--- /dev/null
+++ b/sys/gio/gki/README
@@ -0,0 +1,84 @@
+GKI -- The graphics kernel interface.
+
+ The GKI package is used to encode and decode the GKI instructions used to
+communicate with a graphics kernel. The kernel may be resident in the same
+process, in the CL process, or in a subprocess of the CL. Output may also
+be spooled in a metafile. The purposes of the GKI interface are to isolate GIO
+from the kernel, to hide the details of packing and unpacking GKI metacode
+from both GIO and the kernels, and to hide the details of the communications
+protocols required to communicate with the different types of kernels.
+
+ Before any i/o can be done on a GKI graphics stream, GKI must be informed
+of the residency of the kernel associated with the stream. Three calls are
+provided for this purpose:
+
+ gki_redir (stream, fd, old_type, old_fd) [1]
+ gki_inline (stream, dd) [2]
+ gki_subkernel (stream, pid, epa_prpsio) [3]
+
+Use [1] in the normal case of GIO talking to the CL or to a metafile. The
+first call will set, rather than redirect, the FD for a stream. Subsequent
+calls may be made to truely redirect a stream and then restore its normal
+dataflow. Use [2] when the graphics kernel is in the same process. The
+kernel must already have been opened with the driver for the kernel in the
+DD array. This is the most efficient mode of operation if a high data
+bandwidth is required. Kernel type [2] is used by GIOTR in the CL process
+to communicate with external kernels. A slightly different protocol is
+required in this case since the input must be switched to the subprocess
+before it can read or write the graphics stream.
+
+
+ Summary Of Procedures
+
+1. Initialize GKI
+
+ gki_redir (stream, fd, old_fd, old_type)
+ gki_inline_kernel (stream, dd)
+ gki_subkernel (stream, pid, prpsio_epa)
+
+
+2. Metacode interpretation
+
+ gki_fetch_next_instruction (fd, instruction) (EOF|nwords)
+ gki_execute (gki, dd)
+ gki_write (fd, gki)
+
+
+3. Instructions
+
+ gki_cancel (fd)
+ gki_clear (fd)
+ gki_closews (fd, device)
+ gki_deactivatews (fd)
+ gki_eof (fd)
+ gki_escape (fd, fn, instruction, nwords)
+ gki_faset (fd, ap)
+ gki_fillarea (fd, points, npts)
+ gki_flush (fd)
+ gki_getcellarray (fd, m, nx, ny, x1,y1, x2,y2)
+ gki_getcursor (fd, x, y, key, cursor)
+ gki_getwcs (fd, wcs, len_wcs)
+ gki_mftitle (fd, title)
+ gki_openws (fd, device, mode)
+ gki_plset (fd, ap)
+ gki_pmset (fd, ap)
+ gki_polyline (fd, points, npts)
+ gki_polymarker (fd, points, npts)
+ gki_putcellarray (fd, m, nx, ny, x1,y1, x2,y2)
+ gki_reactivatews (fd)
+ gki_setcursor (fd, x, y, cursor)
+ gki_setwcs (fd, wcs, len_wcs)
+ gki_text (fd, x, y, text)
+ gki_txset (fd, ap)
+
+
+4. Instructions for encoding return values
+
+ gki_retcellarray (fd, m, np)
+ gki_retcursorvalue (fd, x, y, key, cursor)
+
+
+5. Initialization of the GKIPRINT kernel
+
+ gkp_install (dd, out_fd, verbose_output)
+ gkp_close ()
diff --git a/sys/gio/gki/gki.com b/sys/gio/gki/gki.com
new file mode 100644
index 00000000..4c5e3152
--- /dev/null
+++ b/sys/gio/gki/gki.com
@@ -0,0 +1,8 @@
+# Common for the GKI (graphics kernel interface) package.
+
+int gk_type[LAST_FD] # type of output
+int gk_fd[LAST_FD] # output file descriptor
+int gk_dd[LEN_GKIDD] # local device driver
+int gk_prpsio # EPA of pr_psio procedure
+
+common /gkicom/ gk_type, gk_fd, gk_dd, gk_prpsio
diff --git a/sys/gio/gki/gkicancel.x b/sys/gio/gki/gkicancel.x
new file mode 100644
index 00000000..ff2bc5f4
--- /dev/null
+++ b/sys/gio/gki/gkicancel.x
@@ -0,0 +1,28 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_CANCEL -- Cancel graphics output and reset internal parameters.
+#
+# BOI GKI_CANCEL 0
+#
+# L(i) set to the constant 3 (no data fields)
+
+procedure gki_cancel (fd)
+
+int fd # output file
+
+int epa
+short gki[GKI_CANCEL_LEN]
+data gki[1] /BOI/, gki[2] /GKI_CANCEL/, gki[3] /LEN_GKIHDR/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_CANCEL]
+ if (epa != 0)
+ call zcall1 (epa, 0)
+ } else
+ call write (gk_fd[fd], gki, GKI_CANCEL_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkiclear.x b/sys/gio/gki/gkiclear.x
new file mode 100644
index 00000000..ac1e5961
--- /dev/null
+++ b/sys/gio/gki/gkiclear.x
@@ -0,0 +1,28 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_CLEAR -- Clear the workstation screen.
+#
+# BOI GKI_CLEAR 0
+#
+# L(i) set to the constant 3 (no data fields)
+
+procedure gki_clear (fd)
+
+int fd # output file
+
+int epa
+short gki[GKI_CLEAR_LEN]
+data gki[1] /BOI/, gki[2] /GKI_CLEAR/, gki[3] /LEN_GKIHDR/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_CLEAR]
+ if (epa != 0)
+ call zcall1 (epa, 0)
+ } else
+ call write (gk_fd[fd], gki, GKI_CLEAR_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkiclose.x b/sys/gio/gki/gkiclose.x
new file mode 100644
index 00000000..e7ceea15
--- /dev/null
+++ b/sys/gio/gki/gkiclose.x
@@ -0,0 +1,65 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_CLOSEWS -- Close workstation.
+#
+# BOI GKI_CLOSEWS L N D
+#
+# L(i) 4 + N
+# N(i) number of characters in field D
+# D(Nc) device name as in graphcap file
+
+procedure gki_closews (fd, device)
+
+int fd # output file
+char device[ARB] # device name
+
+int epa
+int ip, nchars, n
+pointer sp, gki, op
+int strlen()
+include "gki.com"
+
+begin
+ call smark (sp)
+
+ n = strlen (device)
+ call salloc (gki, GKI_CLOSEWS_LEN + n, TY_SHORT)
+
+ # Pack the device name as a SHORT integer array.
+ op = gki + GKI_CLOSEWS_D - 1
+ for (ip=1; ip <= n; ip=ip+1) {
+ Mems[op] = device[ip]
+ op = op + 1
+ }
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_CLOSEWS]
+ if (epa != 0)
+ call zcall2 (epa, Mems[gki+GKI_CLOSEWS_D-1], n)
+ } else {
+ Mems[gki ] = BOI
+ Mems[gki+1] = GKI_CLOSEWS
+ Mems[gki+2] = GKI_CLOSEWS_LEN + n
+ Mems[gki+GKI_CLOSEWS_N-1] = n
+
+ # Send a copy of the close workstation directive to PSIOCTRL in
+ # the CL process to connect the graphics stream to a kernel,
+ # before writing to the graphics stream. The GKI instruction
+ # must be preceded by the integer value of the stream number.
+
+ nchars = (GKI_CLOSEWS_LEN + n) * SZ_SHORT
+ if (IS_FILE(fd) && (fd >= STDGRAPH && fd <= STDPLOT)) {
+ call write (PSIOCTRL, fd, SZ_INT32)
+ call write (PSIOCTRL, Mems[gki], nchars)
+ call flush (PSIOCTRL)
+ }
+
+ # Now send a copy to the graphics kernel.
+ call write (gk_fd[fd], Mems[gki], nchars)
+ }
+
+ call sfree (sp)
+end
diff --git a/sys/gio/gki/gkideact.x b/sys/gio/gki/gkideact.x
new file mode 100644
index 00000000..b742f7ed
--- /dev/null
+++ b/sys/gio/gki/gkideact.x
@@ -0,0 +1,42 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_DEACTIVATEWS -- Deactivate the workstation (disable graphics).
+#
+# BOI GKI_DEACTIVATEWS L F
+#
+# L(i) 4
+# F flags (0,AW_PAUSE,AW_CLEAR)
+
+procedure gki_deactivatews (fd, flags)
+
+int fd # output file
+int flags # action modifier flags
+
+int epa, nchars
+short gki[GKI_DEACTIVATEWS_LEN]
+data gki[1] /BOI/, gki[2] /GKI_DEACTIVATEWS/, gki[3] /GKI_DEACTIVATEWS_LEN/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_DEACTIVATEWS]
+ if (epa != 0)
+ call zcall1 (epa, flags)
+
+ } else {
+ # Send a copy to the pseudofile i/o controller.
+ gki[GKI_DEACTIVATEWS_F] = flags
+ nchars = GKI_DEACTIVATEWS_LEN * SZ_SHORT
+ if (IS_FILE(fd) && (fd >= STDGRAPH && fd <= STDPLOT)) {
+ call write (PSIOCTRL, fd, SZ_INT32)
+ call write (PSIOCTRL, gki, nchars)
+ call flush (PSIOCTRL)
+ }
+
+ # Now send a copy to the graphics kernel.
+ call write (gk_fd[fd], gki, nchars)
+ }
+end
diff --git a/sys/gio/gki/gkieof.x b/sys/gio/gki/gkieof.x
new file mode 100644
index 00000000..05700156
--- /dev/null
+++ b/sys/gio/gki/gkieof.x
@@ -0,0 +1,23 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_EOF -- Signal end of file on a metacode stream.
+#
+# BOI GKI_EOF 0
+#
+# L(i) set to the constant 3 (no data fields)
+
+procedure gki_eof (fd)
+
+int fd # output file
+
+short gki[GKI_EOF_LEN]
+data gki[1] /BOI/, gki[2] /GKI_EOF/, gki[3] /LEN_GKIHDR/
+include "gki.com"
+
+begin
+ if (!IS_INLINE(fd))
+ call write (gk_fd[fd], gki, GKI_EOF_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkiesc.x b/sys/gio/gki/gkiesc.x
new file mode 100644
index 00000000..a33c769d
--- /dev/null
+++ b/sys/gio/gki/gkiesc.x
@@ -0,0 +1,40 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_ESCAPE -- Pass a device dependent instruction on to the kernel.
+#
+# BOI GKI_ESCAPE L FN N DC
+#
+# L(i) 5 + N
+# FN(i) escape function code
+# N(i) number of escape data words
+# DC(i) escape data words
+
+procedure gki_escape (fd, fn, instruction, nwords)
+
+int fd # output file
+int fn # function code
+short instruction[ARB] # instruction sequence of unknown format
+int nwords # number of shorts in instruction
+
+int epa
+short gki[GKI_ESCAPE_LEN]
+data gki[1] /BOI/, gki[2] /GKI_ESCAPE/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_ESCAPE]
+ if (epa != 0)
+ call zcall3 (epa, fn, instruction, nwords)
+ } else {
+ gki[GKI_ESCAPE_L] = GKI_ESCAPE_LEN + nwords
+ gki[GKI_ESCAPE_N] = nwords
+ gki[GKI_ESCAPE_FN] = fn
+
+ call write (gk_fd[fd], gki, GKI_ESCAPE_LEN * SZ_SHORT)
+ call write (gk_fd[fd], instruction, nwords * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkiexe.x b/sys/gio/gki/gkiexe.x
new file mode 100644
index 00000000..05e8ec8d
--- /dev/null
+++ b/sys/gio/gki/gkiexe.x
@@ -0,0 +1,178 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gki.h>
+
+# GKI_EXECUTE -- Execute a metacode instruction. The instruction is decoded
+# and a graphics kernel driver subroutine is called to execute the instruction.
+# If the device driver does not include a procedure for the instruction the
+# instruction is discarded. Integer and real parameters are unpacked from
+# their short integer metacode representation. Character data is passed by
+# reference, i.e., as a SHORT integer array (not EOS delimited char!!), along
+# with the character count. Attribute packets are passed to the set attribute
+# procedure by reference as a short integer array.
+
+procedure gki_execute (gki, dd)
+
+short gki[ARB] # graphics kernel instruction
+int dd[ARB] # device driver
+
+int kp # kernel procedure
+int m, n, cn, fn, dummy, flags
+int x, y, x1, y1, x2, y2
+
+begin
+ switch (gki[GKI_HDR_OPCODE]) {
+
+ case GKI_OPENWS:
+ kp = dd[GKI_OPENWS]
+ if (kp != NULL) {
+ m = gki[GKI_OPENWS_M]
+ n = gki[GKI_OPENWS_N]
+ call zcall3 (kp, gki[GKI_OPENWS_D], n, m)
+ }
+ case GKI_CLOSEWS:
+ kp = dd[GKI_CLOSEWS]
+ if (kp != NULL) {
+ n = gki[GKI_CLOSEWS_N]
+ call zcall2 (kp, gki[GKI_CLOSEWS_D], n)
+ }
+ case GKI_REACTIVATEWS:
+ kp = dd[GKI_REACTIVATEWS]
+ if (kp != NULL) {
+ flags = gki[GKI_REACTIVATEWS_F]
+ call zcall1 (kp, flags)
+ }
+ case GKI_DEACTIVATEWS:
+ kp = dd[GKI_DEACTIVATEWS]
+ if (kp != NULL) {
+ flags = gki[GKI_DEACTIVATEWS_F]
+ call zcall1 (kp, flags)
+ }
+ case GKI_MFTITLE:
+ kp = dd[GKI_MFTITLE]
+ if (kp != NULL) {
+ n = gki[GKI_MFTITLE_N]
+ call zcall2 (kp, gki[GKI_MFTITLE_T], n)
+ }
+ case GKI_CLEAR:
+ kp = dd[GKI_CLEAR]
+ if (kp != NULL) {
+ call zcall1 (kp, dummy)
+ }
+ case GKI_CANCEL:
+ kp = dd[GKI_CANCEL]
+ if (kp != NULL) {
+ call zcall1 (kp, dummy)
+ }
+ case GKI_FLUSH:
+ kp = dd[GKI_FLUSH]
+ if (kp != NULL) {
+ call zcall1 (kp, dummy)
+ }
+ case GKI_POLYLINE:
+ kp = dd[GKI_POLYLINE]
+ if (kp != 0) {
+ n = gki[GKI_POLYLINE_N]
+ call zcall2 (kp, gki[GKI_POLYLINE_P], n)
+ }
+ case GKI_POLYMARKER:
+ kp = dd[GKI_POLYMARKER]
+ if (kp != 0) {
+ n = gki[GKI_POLYMARKER_N]
+ call zcall2 (kp, gki[GKI_POLYMARKER_P], n)
+ }
+ case GKI_TEXT:
+ kp = dd[GKI_TEXT]
+ if (kp != NULL) {
+ x = gki[GKI_TEXT_P]
+ y = gki[GKI_TEXT_P+1]
+ n = gki[GKI_TEXT_N]
+ call zcall4 (kp, x, y, gki[GKI_TEXT_T], n)
+ }
+ case GKI_FILLAREA:
+ kp = dd[GKI_FILLAREA]
+ if (kp != 0) {
+ n = gki[GKI_FILLAREA_N]
+ call zcall2 (kp, gki[GKI_FILLAREA_P], n)
+ }
+ case GKI_PUTCELLARRAY:
+ kp = dd[GKI_PUTCELLARRAY]
+ if (kp != NULL) {
+ x1 = gki[GKI_PUTCELLARRAY_LL]
+ y1 = gki[GKI_PUTCELLARRAY_LL+1]
+ x2 = gki[GKI_PUTCELLARRAY_UR]
+ y2 = gki[GKI_PUTCELLARRAY_UR+1]
+ m = gki[GKI_PUTCELLARRAY_NC]
+ n = gki[GKI_PUTCELLARRAY_NL]
+ call zcall7 (kp, gki[GKI_PUTCELLARRAY_P], m, n, x1,y1, x2,y2)
+ }
+ case GKI_SETCURSOR:
+ kp = dd[GKI_SETCURSOR]
+ if (kp != NULL) {
+ cn = gki[GKI_SETCURSOR_CN]
+ x = gki[GKI_SETCURSOR_POS]
+ y = gki[GKI_SETCURSOR_POS+1]
+ call zcall3 (kp, x, y, cn)
+ }
+ case GKI_PLSET:
+ kp = dd[GKI_PLSET]
+ if (kp != NULL) {
+ call zcall1 (kp, gki)
+ }
+ case GKI_PMSET:
+ kp = dd[GKI_PMSET]
+ if (kp != NULL) {
+ call zcall1 (kp, gki)
+ }
+ case GKI_TXSET:
+ kp = dd[GKI_TXSET]
+ if (kp != NULL) {
+ call zcall1 (kp, gki)
+ }
+ case GKI_FASET:
+ kp = dd[GKI_FASET]
+ if (kp != NULL) {
+ call zcall1 (kp, gki)
+ }
+ case GKI_GETCURSOR:
+ kp = dd[GKI_GETCURSOR]
+ if (kp != NULL) {
+ cn = gki[GKI_GETCURSOR_CN]
+ call zcall1 (kp, cn)
+ }
+ case GKI_GETCELLARRAY:
+ kp = dd[GKI_GETCELLARRAY]
+ if (kp != NULL) {
+ x1 = gki[GKI_GETCELLARRAY_LL]
+ y1 = gki[GKI_GETCELLARRAY_LL+1]
+ x2 = gki[GKI_GETCELLARRAY_UR]
+ y2 = gki[GKI_GETCELLARRAY_UR+1]
+ m = gki[GKI_GETCELLARRAY_NC]
+ n = gki[GKI_GETCELLARRAY_NL]
+ call zcall6 (kp, m, n, x1,y1, x2,y2)
+ }
+ case GKI_ESCAPE:
+ kp = dd[GKI_ESCAPE]
+ if (kp != NULL) {
+ fn = gki[GKI_ESCAPE_FN]
+ n = gki[GKI_ESCAPE_N]
+ call zcall3 (kp, fn, gki[GKI_ESCAPE_DC], n)
+ }
+ case GKI_SETWCS:
+ kp = dd[GKI_SETWCS]
+ if (kp != NULL) {
+ n = gki[GKI_SETWCS_N]
+ call zcall2 (kp, gki[GKI_SETWCS_WCS], n)
+ }
+ case GKI_GETWCS:
+ kp = dd[GKI_SETWCS]
+ if (kp != NULL) {
+ n = gki[GKI_SETWCS_N]
+ call zcall2 (kp, gki[GKI_SETWCS_WCS], n)
+ }
+ default:
+ kp = dd[GKI_UNKNOWN]
+ if (kp != NULL)
+ call zcall1 (kp, gki)
+ }
+end
diff --git a/sys/gio/gki/gkifa.x b/sys/gio/gki/gkifa.x
new file mode 100644
index 00000000..328ec7cc
--- /dev/null
+++ b/sys/gio/gki/gkifa.x
@@ -0,0 +1,37 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_FILLAREA -- Output the fill area instruction.
+#
+# BOI GKI_FILLAREA L N P
+#
+# L(i) 4 + (N * 2)
+# N(i) number of points defining the polygon to be filled
+# P(Np) list of points (x,y pairs)
+
+procedure gki_fillarea (fd, points, npts)
+
+int fd # output file
+short points[ARB] # polygon defining area to be filled
+int npts # number of (x,y) points in polygon
+
+int epa
+short gki[GKI_FILLAREA_LEN]
+data gki[1] /BOI/, gki[2] /GKI_FILLAREA/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_FILLAREA]
+ if (epa != 0)
+ call zcall2 (epa, points, npts)
+ } else {
+ gki[GKI_FILLAREA_L] = GKI_FILLAREA_LEN + (npts * 2)
+ gki[GKI_FILLAREA_N] = npts
+
+ call write (gk_fd[fd], gki, GKI_FILLAREA_LEN * SZ_SHORT)
+ call write (gk_fd[fd], points, (npts * 2) * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkifaset.x b/sys/gio/gki/gkifaset.x
new file mode 100644
index 00000000..7531be73
--- /dev/null
+++ b/sys/gio/gki/gkifaset.x
@@ -0,0 +1,35 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+include <gio.h>
+
+# GKI_FASET -- Set the fill area attributes.
+#
+# BOI GKI_FASET L FS CI
+#
+# L(i) 5
+# FS(i) fill style (0=clear,1=hollow,2=solid,3-6=hatch)
+# CI(i) fill area color index
+
+procedure gki_faset (fd, ap)
+
+int fd # output file
+pointer ap # pointer to fillarea attribute structure
+
+int epa
+short gki[GKI_FASET_LEN]
+data gki[1] /BOI/, gki[2] /GKI_FASET/, gki[3] /GKI_FASET_LEN/
+include "gki.com"
+
+begin
+ gki[GKI_FASET_FS] = FA_STYLE(ap)
+ gki[GKI_FASET_CI] = FA_COLOR(ap)
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_FASET]
+ if (epa != 0)
+ call zcall1 (epa, gki)
+ } else
+ call write (gk_fd[fd], gki, GKI_FASET_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkifetch.x b/sys/gio/gki/gkifetch.x
new file mode 100644
index 00000000..53fa315b
--- /dev/null
+++ b/sys/gio/gki/gkifetch.x
@@ -0,0 +1,80 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gki.h>
+
+define LEN_DEFIBUF 2048
+define ONEWORD SZ_SHORT
+define TWOWORDS (2*SZ_SHORT)
+
+# Header fields of a GKI instruction.
+define I_BOI Mems[$1+GKI_HDR_BOI-1]
+define I_OPCODE Mems[$1+GKI_HDR_OPCODE-1]
+define I_LENGTH Mems[$1+GKI_HDR_LENGTH-1]
+define I_DATA Mems[$1+GKI_DATAFIELDS-1]
+
+# GKI_FETCH_NEXT_INSTRUCTION -- Fetch the next GKI metacode instruction from the
+# input stream. A pointer to a short integer buffer containing the instruction
+# is returned as an output argument. EOF is returned as the function value
+# when EOF is seen on the input stream. The instruction buffer may be
+# deallocated by our caller at any time, if desired. A new buffer will be
+# created automatically when next we are called.
+
+int procedure gki_fetch_next_instruction (fd, instruction)
+
+int fd # input file containing metacode
+pointer instruction # pointer to instruction (output)
+
+int len_ibuf, nchars
+pointer ibuf
+int read()
+errchk read, malloc, realloc
+data ibuf /NULL/
+
+begin
+ # Allocate a default sized instruction buffer. We can reallocate
+ # a larger buffer later if necessary.
+
+ if (ibuf == NULL) {
+ call malloc (ibuf, LEN_DEFIBUF, TY_SHORT)
+ len_ibuf = LEN_DEFIBUF
+ }
+
+ # Advance to the next instruction. Nulls and botched portions of
+ # instructions are ignored. Read the instruction header to determine
+ # the length of the instruction, and then read the rest of instruction
+ # into buffer. If the entire instruction cannot be read we have a
+ # botched instruction and must try again.
+
+ repeat {
+ repeat {
+ if (read (fd, I_BOI(ibuf), ONEWORD) == EOF)
+ return (EOF)
+ } until (I_BOI(ibuf) == BOI)
+
+ if (read (fd, I_OPCODE(ibuf), TWOWORDS) == EOF)
+ return (EOF)
+
+ # Make instruction buffer large enough to hold instruction.
+ # Compute length of remainder of instruction in chars.
+
+ if (I_LENGTH(ibuf) > len_ibuf) {
+ len_ibuf = I_LENGTH(ibuf)
+ call realloc (ibuf, len_ibuf, TY_SHORT)
+ }
+
+ nchars = (I_LENGTH(ibuf) - LEN_GKIHDR) * SZ_SHORT
+ if (nchars == 0)
+ break
+
+ } until (read (fd, I_DATA(ibuf), nchars) == nchars)
+
+ instruction = ibuf
+
+ # Check for a soft end of file, otherwise return the length of the
+ # instruction as the function value.
+
+ if (I_OPCODE(ibuf) == GKI_EOF)
+ return (EOF)
+ else
+ return (I_LENGTH(ibuf))
+end
diff --git a/sys/gio/gki/gkifflush.x b/sys/gio/gki/gkifflush.x
new file mode 100644
index 00000000..9eebf406
--- /dev/null
+++ b/sys/gio/gki/gkifflush.x
@@ -0,0 +1,24 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <fio.h>
+include <gki.h>
+
+# GKI_FFLUSH -- Flush a graphics stream. This does not issue the GKI_FLUSH
+# graphics instruction to the graphics kernel, it merely flushes any buffered
+# data in the output stream, and is a no-op in the case of an inline kernel.
+
+procedure gki_fflush (fd)
+
+int fd # output file
+
+errchk seek
+include "gki.com"
+
+begin
+ if (IS_SUBKERNEL(fd)) {
+ call seek (fd, BOFL)
+ call zcall3 (gk_prpsio, KERNEL_PID(fd), fd, FF_WRITE)
+ } else if (!IS_INLINE(fd))
+ call flush (gk_fd[fd])
+end
diff --git a/sys/gio/gki/gkiflush.x b/sys/gio/gki/gkiflush.x
new file mode 100644
index 00000000..878502d4
--- /dev/null
+++ b/sys/gio/gki/gkiflush.x
@@ -0,0 +1,40 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <fio.h>
+include <gki.h>
+
+# GKI_FLUSH -- Flush any buffered output.
+#
+# BOI GKI_FLUSH 0
+#
+# L(i) set to the constant 3 (no data fields)
+
+procedure gki_flush (fd)
+
+int fd # output file
+
+int epa
+short gki[GKI_FLUSH_LEN]
+data gki[1] /BOI/, gki[2] /GKI_FLUSH/, gki[3] /LEN_GKIHDR/
+errchk write, seek
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_FLUSH]
+ if (epa != 0)
+ call zcall1 (epa, 0)
+ } else {
+ call write (gk_fd[fd], gki, GKI_FLUSH_LEN * SZ_SHORT)
+
+ # If writing to a subkernel we must call PR_PSIO to give the
+ # kernel a chance to read the spooled metacode.
+
+ if (IS_SUBKERNEL(fd)) {
+ call seek (fd, BOFL)
+ call zcall3 (gk_prpsio, KERNEL_PID(fd), fd, FF_WRITE)
+ } else
+ call flush (gk_fd[fd])
+ }
+end
diff --git a/sys/gio/gki/gkigca.x b/sys/gio/gki/gkigca.x
new file mode 100644
index 00000000..07abf9d3
--- /dev/null
+++ b/sys/gio/gki/gkigca.x
@@ -0,0 +1,87 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <syserr.h>
+include <fset.h>
+include <fio.h>
+include <gki.h>
+
+# GKI_GETCELLARRAY -- Input a cell array (pixel array).
+#
+# BOI GKI_GETCELLARRAY L LL UR NC NL
+#
+# L(i) 9
+# LL(p) coordinates of lower left corner of input area
+# UR(p) coordinates of upper right corner of input area
+# NC(i) number of columns in array
+# NL(i) number of lines in array
+
+procedure gki_getcellarray (fd, m, nx, ny, x1,y1, x2,y2)
+
+int fd # output file
+int nx, ny # number of columns and lines in M
+short m[nx,ny] # output array
+int x1, y1 # lower left corner of window to be read
+int x2, y2 # upper right corner of window to be read
+
+int epa, nchars, npts
+short ca[GKI_CELLARRAY_LEN]
+short gki[GKI_GETCELLARRAY_LEN]
+int read()
+data gki[1] /BOI/, gki[2] /GKI_GETCELLARRAY/, gki[3] /GKI_GETCELLARRAY_LEN/
+errchk write, seek, flush, read
+include "gki.com"
+
+begin
+ # If the kernel is inline it will return the cell array value in the
+ # graphics stream FIO buffer just as if the kernel were resident
+ # in another process. We rewind the buffer after the kernel writes
+ # into it in preparation for the read below.
+
+ if (IS_INLINE(fd)) {
+ call fseti (fd, F_CANCEL, OK)
+ epa = gk_dd[GKI_GETCELLARRAY]
+ if (epa != 0)
+ call zcall6 (epa, nx,ny, x1,y1, x2,y2)
+ call seek (fd, BOFL)
+
+ } else {
+ # Write get cell array instruction to the kernel.
+
+ gki[GKI_GETCELLARRAY_LL] = x1
+ gki[GKI_GETCELLARRAY_LL+1] = y1
+ gki[GKI_GETCELLARRAY_UR] = x2
+ gki[GKI_GETCELLARRAY_UR+1] = y2
+ gki[GKI_GETCELLARRAY_NC] = nx
+ gki[GKI_GETCELLARRAY_NL] = ny
+
+ call write (gk_fd[fd], gki, GKI_GETCELLARRAY_LEN)
+
+ # If the kernel is a subprocess we must call PR_PSIO to allow the
+ # kernel to read the instruction and return the cell array value.
+
+ if (IS_SUBKERNEL(fd)) {
+ call seek (fd, BOFL)
+ call zcall3 (gk_prpsio, KERNEL_PID(fd), fd, FF_READ)
+ call seek (fd, BOFL)
+ } else
+ call flush (gk_fd[fd])
+ }
+
+ # Read and decode the cell array value.
+
+ nchars = GKI_CELLARRAY_LEN * SZ_SHORT
+ if (read (fd, ca, nchars) < nchars) {
+ call syserr (SYS_GGCELL)
+ } else if (ca[1] != BOI || ca[2] != GKI_CELLARRAY ||
+ ca[GKI_CELLARRAY_NP] <= 0) {
+ call syserr (SYS_GGCELL)
+ } else {
+ npts = ca[GKI_CELLARRAY_NP]
+ nchars = min (nx * ny, npts) * SZ_SHORT
+ if (read (fd, m, nchars) < nchars)
+ call syserr (SYS_GGCELL)
+ }
+
+ call fseti (fd, F_CANCEL, OK)
+end
diff --git a/sys/gio/gki/gkigcur.x b/sys/gio/gki/gkigcur.x
new file mode 100644
index 00000000..e87e030e
--- /dev/null
+++ b/sys/gio/gki/gkigcur.x
@@ -0,0 +1,106 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <syserr.h>
+include <fset.h>
+include <fio.h>
+include <gki.h>
+
+# GKI_GETCURSOR -- Read the cursor position in device coordinates.
+#
+# BOI GKI_GETCURSOR L CN
+#
+# L(i) 4
+# CN(i) cursor number
+#
+# The kernel reads graphics cursor number CN and returns the
+# keystroke value (if any) and the cursor position in NDC
+# coordinates. The cursor attributes are returned in the
+# following format:
+#
+# BOI GKI_CURSORVALUE L CN KEY SX SY RN RX RY
+#
+# where
+#
+# L(i) 10
+# CN(i) cursor number
+# KEY(i) keystroke value (>= 0 or EOF)
+# SX(i) NDC X screen coordinate of cursor
+# SY(i) NDC Y screen coordinate of cursor
+# RN(i) raster number or zero
+# RX(i) NDC X raster coordinate of cursor
+# RY(i) NDC Y raster coordinate of cursor
+#
+# The screen or display window coordinates SX and SY of the cursor are
+# returned for all devices. Only some devices support multiple rasters.
+# If the device supports rasters and the cursor is in a rasters when read, the
+# rasters number and rasters coordinates are returned in RN,RX,RY. This is in
+# addition to the screen coordinates SX,SY. If rasters coordinates are not
+# returned, the rasters number will be set to zero and RX,RY will be the same
+# as SX,SY.
+
+procedure gki_getcursor (fd, cursor, cn, key, sx, sy, raster, rx, ry)
+
+int fd #I output file
+int cursor #I cursor to be read
+int cn #O cursor number actually read
+int key #O keystroke value or EOF
+int sx, sy #O screen coordinates of cursor
+int raster #O raster number
+int rx, ry #O raster coordinates of cursor
+
+int epa
+int nchars, read()
+short gki[GKI_GETCURSOR_LEN]
+short cur[GKI_CURSORVALUE_LEN]
+data gki[1] /BOI/, gki[2] /GKI_GETCURSOR/, gki[3] /GKI_GETCURSOR_LEN/
+include "gki.com"
+errchk write, flush, read
+
+begin
+ # If the kernel is inline it will return the cursor value in the
+ # graphics stream FIO buffer just as if the kernel were resident
+ # in another process. We rewind the buffer after the kernel writes
+ # into it in preparation for the read below.
+
+ if (IS_INLINE(fd)) {
+ call fseti (fd, F_CANCEL, OK)
+ epa = gk_dd[GKI_GETCURSOR]
+ if (epa != 0)
+ call zcall1 (epa, cursor)
+ call seek (fd, BOFL)
+
+ } else {
+ # Write cursor read instruction to the kernel.
+ gki[GKI_GETCURSOR_CN] = cursor
+ call write (gk_fd[fd], gki, GKI_GETCURSOR_LEN * SZ_SHORT)
+
+ # If the kernel is a subprocess we must call PR_PSIO to allow the
+ # kernel to read the instruction and return the cursor value.
+
+ if (IS_SUBKERNEL(fd)) {
+ call seek (fd, BOFL)
+ call zcall3 (gk_prpsio, KERNEL_PID(fd), fd, FF_READ)
+ call seek (fd, BOFL)
+ } else
+ call flush (gk_fd[fd])
+ }
+
+ # Read and decode the cursor value instruction.
+ nchars = GKI_CURSORVALUE_LEN * SZ_SHORT
+ if (read (fd, cur, nchars) < nchars)
+ key = EOF
+ else if (cur[1] != BOI || cur[2] != GKI_CURSORVALUE)
+ call syserr (SYS_GGCUR)
+ else {
+ cn = cur[GKI_CURSORVALUE_CN]
+ key = cur[GKI_CURSORVALUE_KEY]
+ sx = cur[GKI_CURSORVALUE_SX]
+ sy = cur[GKI_CURSORVALUE_SY]
+ raster = cur[GKI_CURSORVALUE_RN]
+ rx = cur[GKI_CURSORVALUE_RX]
+ ry = cur[GKI_CURSORVALUE_RY]
+ }
+
+ call fseti (fd, F_CANCEL, OK)
+end
diff --git a/sys/gio/gki/gkigetwcs.x b/sys/gio/gki/gkigetwcs.x
new file mode 100644
index 00000000..f6aa07c2
--- /dev/null
+++ b/sys/gio/gki/gkigetwcs.x
@@ -0,0 +1,44 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <syserr.h>
+include <gki.h>
+
+# GKI_GETWCS -- Retrieve the WCS from the CL process. Used when opening a
+# (non-metafile) device in append mode.
+#
+# BOI GKI_GETWCS L N
+#
+# L(i) 3
+# N(i) number of words of WCS data to be read
+
+procedure gki_getwcs (fd, wcs, len_wcs)
+
+int fd # input/output file
+int wcs[ARB] # array of WCS structures (output)
+int len_wcs # number of ints (struct units) in array
+
+int nchars, nwords, read()
+short gki[GKI_GETWCS_LEN]
+data gki[1] /BOI/, gki[2] /GKI_GETWCS/, gki[3] /GKI_GETWCS_LEN/
+errchk syserr, read, write, flush
+include "gki.com"
+
+begin
+ nwords = (len_wcs * SZ_INT / SZ_SHORT)
+ gki[GKI_GETWCS_N] = nwords
+
+ # Request CL to send SETWCS instruction back to us. The directive
+ # must be sent on the pseudofile control stream.
+
+ call write (PSIOCTRL, fd, SZ_INT32)
+ call write (PSIOCTRL, gki, GKI_GETWCS_LEN * SZ_SHORT)
+ call flush (PSIOCTRL)
+
+ # Read the wcs data. This is returned on the process CLIN channel
+ # by the CL.
+
+ nchars = nwords * SZ_SHORT
+ if (read (CLIN, wcs, nchars) != nchars)
+ call syserr (SYS_GGETWCS)
+end
diff --git a/sys/gio/gki/gkiinit.x b/sys/gio/gki/gkiinit.x
new file mode 100644
index 00000000..0813a708
--- /dev/null
+++ b/sys/gio/gki/gkiinit.x
@@ -0,0 +1,22 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_INIT -- Initialize GKI i/o on a graphics stream. Called by GOPEN to
+# make the connection to either a metacode stream file or an inline kernel.
+# If the stream has already been directed to a kernel we do nothing, else
+# we initialize the stream as for a metacode file or remote kernel. If
+# gki_inline is called before gopen then this procedure is a nop.
+
+procedure gki_init (stream)
+
+int stream # graphics stream to be redirected
+include "gki.com"
+
+begin
+ if (gk_type[stream] == NULL) {
+ gk_type[stream] = TY_FILE
+ gk_fd[stream] = stream
+ }
+end
diff --git a/sys/gio/gki/gkiinline.x b/sys/gio/gki/gkiinline.x
new file mode 100644
index 00000000..87fc1f29
--- /dev/null
+++ b/sys/gio/gki/gkiinline.x
@@ -0,0 +1,23 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_INLINE_KERNEL -- Identify a graphics stream for use with an inline
+# kernel, i.e., with a kernel linked into the same process as the high level
+# code which calls the GKI procedures. At present there may be at most one
+# inline kernel at a time. The entry point addresses of the kernel procedures
+# are passed in the array DD. Subsequent GKI calls for the named stream will
+# result in direct calls to the inline kernel without encoding and decoding
+# GKI instructions, hence this is the most efficient mode of operation.
+
+procedure gki_inline_kernel (stream, dd)
+
+int stream # graphics stream to be redirected
+int dd[ARB] # device driver for the kernel
+include "gki.com"
+
+begin
+ gk_type[stream] = TY_INLINE
+ call amovi (dd, gk_dd, LEN_GKIDD)
+end
diff --git a/sys/gio/gki/gkikern.x b/sys/gio/gki/gkikern.x
new file mode 100644
index 00000000..95c8e648
--- /dev/null
+++ b/sys/gio/gki/gkikern.x
@@ -0,0 +1,30 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_SUBKERNEL -- Identify a graphics stream for use with a kernel in a
+# connected subprocess of the current process. This type of kernel is
+# equivalent to a file for all of the output instructions, but the input
+# instructions (e.g., read cursor) must fiddle with process i/o and need
+# additional information to do so, i.e., the process id number of the kernel
+# process, and the entry point address of the PR_PSIO procedure. We do not
+# wish to directly reference the latter procedure as this would require
+# all processes which use GKI to link in the process control code, even if
+# they never talk directly to a process. Note that processes which talk to
+# an external kernel via the CL do so with the normal file interface, hence
+# do not need to call us. We are called by the GIOTR (cursor mode) code in
+# the CL process when an external kernel is spawned.
+
+procedure gki_subkernel (stream, pid, prpsio_epa)
+
+int stream # graphics stream to be redirected
+int pid # process id of kernel process
+int prpsio_epa # epa of the etc$prpsio procedure.
+include "gki.com"
+
+begin
+ gk_type[stream] = pid
+ gk_fd[stream] = stream
+ gk_prpsio = prpsio_epa
+end
diff --git a/sys/gio/gki/gkiopen.x b/sys/gio/gki/gkiopen.x
new file mode 100644
index 00000000..562ed8c3
--- /dev/null
+++ b/sys/gio/gki/gkiopen.x
@@ -0,0 +1,67 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_OPENWS -- Open workstation.
+#
+# BOI GKI_OPENWS L M N D
+#
+# L(i) 5 + N
+# M(i) access mode (APPEND=4, NEW_FILE=5, TEE=6)
+# N(i) number of characters in field D
+# D(Nc) device name as in graphcap file
+
+procedure gki_openws (fd, device, mode)
+
+int fd # output file
+char device[ARB] # device name
+int mode # access mode
+
+int ip, n, epa, nchars
+pointer sp, gki, op
+int strlen()
+include "gki.com"
+
+begin
+ call smark (sp)
+
+ n = strlen (device)
+ call salloc (gki, GKI_OPENWS_LEN + n, TY_SHORT)
+
+ # Pack the device name as a SHORT integer array.
+ op = gki + GKI_OPENWS_D - 1
+ for (ip=1; ip <= n; ip=ip+1) {
+ Mems[op] = device[ip]
+ op = op + 1
+ }
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_OPENWS]
+ if (epa != 0)
+ call zcall3 (epa, Mems[gki+GKI_OPENWS_D-1], n, mode)
+ } else {
+ Mems[gki ] = BOI
+ Mems[gki+1] = GKI_OPENWS
+ Mems[gki+2] = GKI_OPENWS_LEN + n
+ Mems[gki+GKI_OPENWS_M-1] = mode
+ Mems[gki+GKI_OPENWS_N-1] = n
+
+ # Send a copy of the open workstation directive to PSIOCTRL in
+ # the CL process to connect the graphics stream to a kernel,
+ # before writing to the graphics stream. The GKI instruction
+ # must be preceded by the integer value of the stream number.
+
+ nchars = (GKI_OPENWS_LEN + n) * SZ_SHORT
+ if (IS_FILE(fd) && (fd >= STDGRAPH && fd <= STDPLOT)) {
+ call write (PSIOCTRL, fd, SZ_INT32)
+ call write (PSIOCTRL, Mems[gki], nchars)
+ call flush (PSIOCTRL)
+ }
+
+ # Now send a copy to the graphics kernel.
+ call write (gk_fd[fd], Mems[gki], nchars)
+ }
+
+ call sfree (sp)
+end
diff --git a/sys/gio/gki/gkipca.x b/sys/gio/gki/gkipca.x
new file mode 100644
index 00000000..b2cf30ab
--- /dev/null
+++ b/sys/gio/gki/gkipca.x
@@ -0,0 +1,47 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_PUTCELLARRAY -- Output a cell array (pixel array).
+#
+# BOI GKI_PUTCELLARRAY L LL UR NC NL P
+#
+# L(i) 9 + (NC * NL)
+# LL(p) coordinates of lower left corner of output area
+# UR(p) coordinates of upper right corner of output area
+# NC(i) number of columns in array
+# NL(i) number of lines in array
+# P(NCNLi) array of color indices (pixels) stored by row
+
+procedure gki_putcellarray (fd, m, nx, ny, x1,y1, x2,y2)
+
+int fd # output file
+int nx, ny # number of columns and lines in M
+short m[nx,ny] # pixel array
+int x1, y1 # lower left corner of window to be written
+int x2, y2 # upper right corner of window to be written
+
+int epa
+short gki[GKI_PUTCELLARRAY_LEN]
+data gki[1] /BOI/, gki[2] /GKI_PUTCELLARRAY/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_PUTCELLARRAY]
+ if (epa != 0)
+ call zcall7 (epa, m, nx,ny, x1,y1, x2,y2)
+ } else {
+ gki[GKI_PUTCELLARRAY_L] = GKI_PUTCELLARRAY_LEN + (nx * ny)
+ gki[GKI_PUTCELLARRAY_LL] = x1
+ gki[GKI_PUTCELLARRAY_LL+1] = y1
+ gki[GKI_PUTCELLARRAY_UR] = x2
+ gki[GKI_PUTCELLARRAY_UR+1] = y2
+ gki[GKI_PUTCELLARRAY_NC] = nx
+ gki[GKI_PUTCELLARRAY_NL] = ny
+
+ call write (gk_fd[fd], gki, GKI_PUTCELLARRAY_LEN)
+ call write (gk_fd[fd], m, (nx * ny) * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkipl.x b/sys/gio/gki/gkipl.x
new file mode 100644
index 00000000..7d36b749
--- /dev/null
+++ b/sys/gio/gki/gkipl.x
@@ -0,0 +1,37 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_POLYLINE -- Output a polyline.
+#
+# BOI GKI_POLYLINE L N P
+#
+# L(i) 4 + (N * 2)
+# N(i) number of points in the polyline
+# P(Np) list of points (x,y pairs)
+
+procedure gki_polyline (fd, points, npts)
+
+int fd # output file
+short points[ARB] # polyline
+int npts # number of (x,y) points in polyline
+
+int epa
+short gki[GKI_POLYLINE_LEN]
+data gki[1] /BOI/, gki[2] /GKI_POLYLINE/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_POLYLINE]
+ if (epa != 0)
+ call zcall2 (epa, points, npts)
+ } else {
+ gki[GKI_POLYLINE_L] = GKI_POLYLINE_LEN + (npts * 2)
+ gki[GKI_POLYLINE_N] = npts
+
+ call write (gk_fd[fd], gki, GKI_POLYLINE_LEN * SZ_SHORT)
+ call write (gk_fd[fd], points, (npts * 2) * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkiplset.x b/sys/gio/gki/gkiplset.x
new file mode 100644
index 00000000..1a7b092f
--- /dev/null
+++ b/sys/gio/gki/gkiplset.x
@@ -0,0 +1,37 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+include <gio.h>
+
+# GKI_PLSET -- Set the polyline attributes.
+#
+# BOI GKI_PLSET L LT LW CI
+#
+# L(i) 6
+# LT(i) linetype number
+# LW(r) linewidth scale factor
+# CI(i) polyline color index
+
+procedure gki_plset (fd, ap)
+
+int fd # output file
+pointer ap # pointer to polyline attribute structure
+
+int epa
+short gki[GKI_PLSET_LEN]
+data gki[1] /BOI/, gki[2] /GKI_PLSET/, gki[3] /GKI_PLSET_LEN/
+include "gki.com"
+
+begin
+ gki[GKI_PLSET_LT] = PL_LTYPE(ap)
+ gki[GKI_PLSET_LW] = GKI_PACKREAL (PL_WIDTH(ap))
+ gki[GKI_PLSET_CI] = PL_COLOR(ap)
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_PLSET]
+ if (epa != 0)
+ call zcall1 (epa, gki)
+ } else
+ call write (gk_fd[fd], gki, GKI_PLSET_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkipm.x b/sys/gio/gki/gkipm.x
new file mode 100644
index 00000000..ea493b54
--- /dev/null
+++ b/sys/gio/gki/gkipm.x
@@ -0,0 +1,37 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_POLYMARKER -- Output a polymarker.
+#
+# BOI GKI_POLYMARKER L N P
+#
+# L(i) 4 + (N * 2)
+# N(i) number of points in the polymarker
+# P(Np) list of points (x,y pairs)
+
+procedure gki_polymarker (fd, points, npts)
+
+int fd # output file
+short points[ARB] # polymarker
+int npts # number of (x,y) points in polymarker
+
+int epa
+short gki[GKI_POLYMARKER_LEN]
+data gki[1] /BOI/, gki[2] /GKI_POLYMARKER/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_POLYMARKER]
+ if (epa != 0)
+ call zcall2 (epa, points, npts)
+ } else {
+ gki[GKI_POLYMARKER_L] = GKI_POLYMARKER_LEN + (npts * 2)
+ gki[GKI_POLYMARKER_N] = npts
+
+ call write (gk_fd[fd], gki, GKI_POLYMARKER_LEN * SZ_SHORT)
+ call write (gk_fd[fd], points, (npts * 2) * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkipmset.x b/sys/gio/gki/gkipmset.x
new file mode 100644
index 00000000..7bdc27ac
--- /dev/null
+++ b/sys/gio/gki/gkipmset.x
@@ -0,0 +1,37 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+include <gio.h>
+
+# GKI_PMSET -- Set the polymarker attributes.
+#
+# BOI GKI_PMSET L MT MW CI
+#
+# L(i) 6
+# MT(i) marktype (not used at present)
+# MW(i) marksize, NDC coords (not used at present)
+# CI(i) marker color index
+
+procedure gki_pmset (fd, ap)
+
+int fd # output file
+pointer ap # pointer to polymarker attribute structure
+
+int epa
+short gki[GKI_PMSET_LEN]
+data gki[1] /BOI/, gki[2] /GKI_PMSET/, gki[3] /GKI_PMSET_LEN/
+include "gki.com"
+
+begin
+ gki[GKI_PMSET_MT] = PM_LTYPE(ap)
+ gki[GKI_PMSET_MW] = GKI_PACKREAL (PM_WIDTH(ap))
+ gki[GKI_PMSET_CI] = PM_COLOR(ap)
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_PMSET]
+ if (epa != 0)
+ call zcall1 (epa, gki)
+ } else
+ call write (gk_fd[fd], gki, GKI_PMSET_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkiprint.x b/sys/gio/gki/gkiprint.x
new file mode 100644
index 00000000..14e623bd
--- /dev/null
+++ b/sys/gio/gki/gkiprint.x
@@ -0,0 +1,820 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <mach.h>
+include <gset.h>
+include <gki.h>
+include <gio.h>
+
+.help gkiprint
+.nf __________________________________________________________________________
+GKIPRINT -- Graphics kernel for decoding metacode. This graphics kernel
+formats metacode instructions into readable form and prints them on the output
+file. The gkiprint kernel is useful for examining metafiles and for
+debugging kernels which drive specific devices. The driver consists of the
+following procedures:
+
+ gkp_openws (devname, n, mode)
+ gkp_closews (devname, n)
+ gkp_deactivatews (flags)
+ gkp_reactivatews (flags)
+ gkp_mftitle (title, n) **
+ gkp_clear (dummy)
+ gkp_cancel (dummy)
+ gkp_flush (dummy)
+ gkp_polyline (p, npts)
+ gkp_polymarker (p, npts)
+ gkp_text (x, y, text, n)
+ gkp_fillarea (p, npts)
+ gkp_getcellarray (m, nx, ny, x1,y1, x2,y2)
+ gkp_putcellarray (m, nx, ny, x1,y1, x2,y2)
+ gkp_setcursor (x, y, cursor)
+ gkp_plset (gki)
+ gkp_pmset (gki)
+ gkp_txset (gki)
+ gkp_faset (gki)
+ gkp_getcursor (cursor)
+ gkp_escape (fn, instruction, nwords) **
+ gkp_setwcs (wcs, nwords) **
+ gkp_getwcs (wcs, nwords) **
+ gkp_unknown (gki) **
+
+A GKI driven device driver may implement any subset of these procedures.
+The starred procedures should be omitted by most drivers. In particular,
+the SETWCS and GETWCS instructions are internal instructions which should
+be ignored by ordinary device drivers. The procedure names may be anything,
+but the arguments lists must be as shown. All coordinates are in GKI units,
+0 to 32767. Character strings are passed in ASCII, one character per metacode
+word. Whenever a GKI character string appears as an array argument in the
+argument list of a procedure, the count N of the number of characters in the
+string follows as the next argument. GKI character strings are not EOS
+delimited. Polyline, polymarker, and fillarea data is passed as an array
+of (x,y) points P, in GKI coordinates, defining the polyline or polygon to
+be plotted.
+
+One additional procedure, GKP_INSTALL, is called by the main program of the
+graphics kernel task to install the debugging driver, i.e., to fill the DD
+array with the entry point addresses of the driver procedures. For a normal
+driver this function is performed by a user supplied procedure named
+GKOPEN (graphics kernel open). The user supplied kernel procedures will
+be called to execute each instruction as the instructions are decoded by the
+main routine. The user supplied procedure GKCLOSE will be called when
+interpretation ends and the task is about to exit.
+
+ gkopen (dd)
+ gkclose ()
+
+Do not confuse GKOPEN and GKCLOSE, which open and close the graphics kernel,
+with GKI_OPENWS and GKI_CLOSEWS, the metacode instructions used to direct
+an opened kernel to open and close workstations.
+.endhelp ___________________________________________________________________
+
+
+# GKP_INSTALL -- Install the GKI debugging kernel as a graphics kernel
+# device driver. The device table DD consists of an array of the entry
+# point addresses for the driver procedures. If a driver does not implement
+# a particular instruction the table entry for that procedure may be set
+# to zero, causing the interpreter to ignore the instruction.
+
+procedure gkp_install (dd, out_fd, verbose_output, use_gkiunits)
+
+int dd[ARB] # device table to be initialized
+int out_fd # output file
+int verbose_output # verbose output desired
+int use_gkiunits # print coords in GKI units rather than NDC
+
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+extern gkp_openws(), gkp_closews(), gkp_mftitle(), gkp_clear(), gkp_cancel()
+extern gkp_flush(), gkp_polyline(), gkp_polymarker(), gkp_text()
+extern gkp_fillarea(), gkp_putcellarray(), gkp_setcursor(), gkp_plset()
+extern gkp_pmset(), gkp_txset(), gkp_faset(), gkp_getcursor()
+extern gkp_getcellarray(), gkp_escape(), gkp_setwcs(), gkp_getwcs()
+extern gkp_unknown(), gkp_reactivatews(), gkp_deactivatews()
+
+begin
+ # Set the GDC internal parameters.
+ fd = out_fd
+ stream = NULL
+ gkiunits = use_gkiunits
+ verbose = verbose_output
+
+ # Install the device driver.
+ call zlocpr (gkp_openws, dd[GKI_OPENWS])
+ call zlocpr (gkp_closews, dd[GKI_CLOSEWS])
+ call zlocpr (gkp_reactivatews, dd[GKI_REACTIVATEWS])
+ call zlocpr (gkp_deactivatews, dd[GKI_DEACTIVATEWS])
+ call zlocpr (gkp_mftitle, dd[GKI_MFTITLE])
+ call zlocpr (gkp_clear, dd[GKI_CLEAR])
+ call zlocpr (gkp_cancel, dd[GKI_CANCEL])
+ call zlocpr (gkp_flush, dd[GKI_FLUSH])
+ call zlocpr (gkp_polyline, dd[GKI_POLYLINE])
+ call zlocpr (gkp_polymarker, dd[GKI_POLYMARKER])
+ call zlocpr (gkp_text, dd[GKI_TEXT])
+ call zlocpr (gkp_fillarea, dd[GKI_FILLAREA])
+ call zlocpr (gkp_putcellarray, dd[GKI_PUTCELLARRAY])
+ call zlocpr (gkp_setcursor, dd[GKI_SETCURSOR])
+ call zlocpr (gkp_plset, dd[GKI_PLSET])
+ call zlocpr (gkp_pmset, dd[GKI_PMSET])
+ call zlocpr (gkp_txset, dd[GKI_TXSET])
+ call zlocpr (gkp_faset, dd[GKI_FASET])
+ call zlocpr (gkp_getcursor, dd[GKI_GETCURSOR])
+ call zlocpr (gkp_getcellarray, dd[GKI_GETCELLARRAY])
+ call zlocpr (gkp_escape, dd[GKI_ESCAPE])
+ call zlocpr (gkp_setwcs, dd[GKI_SETWCS])
+ call zlocpr (gkp_getwcs, dd[GKI_GETWCS])
+ call zlocpr (gkp_unknown, dd[GKI_UNKNOWN])
+end
+
+
+# GKP_CLOSE -- Close the GKP kernel.
+
+procedure gkp_close()
+begin
+end
+
+
+# GKP_GRSTREAM -- Set the FD of the graphics stream, from which we shall read
+# metacode instructions and to which we shall return cell arrays and cursor
+# values.
+
+procedure gkp_grstream (graphics_stream)
+
+int graphics_stream # FD of the new graphics stream
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ stream = graphics_stream
+end
+
+
+# GKP_OPENWS -- Open the named workstation.
+
+procedure gkp_openws (devname, n, mode)
+
+short devname[ARB] # device name
+int n # length of device name
+int mode # access mode
+
+int junk
+pointer sp, buf
+int itoc()
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call smark (sp)
+ call salloc (buf, max (SZ_FNAME, n), TY_CHAR)
+
+ call achtsc (devname, Memc[buf], n)
+ Memc[buf+n] = EOS
+
+ call fprintf (fd, "open_workstation '%s', mode=%s\n")
+ call pargstr (Memc[buf])
+ switch (mode) {
+ case NEW_FILE:
+ call pargstr ("new_file")
+ case APPEND:
+ call pargstr ("append")
+ default:
+ junk = itoc (mode, Memc[buf], SZ_FNAME)
+ }
+
+ call sfree (sp)
+end
+
+
+# GKP_CLOSEWS -- Close the named workstation.
+
+procedure gkp_closews (devname, n)
+
+short devname[ARB] # device name
+int n # length of device name
+pointer sp, buf
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call smark (sp)
+ call salloc (buf, n, TY_CHAR)
+
+ call achtsc (devname, Memc[buf], n)
+ Memc[buf+n] = EOS
+
+ call fprintf (fd, "close_workstation '%s'\n")
+ call pargstr (Memc[buf])
+ call flush (fd)
+
+ call sfree (sp)
+end
+
+
+# GKP_REACTIVATEWS -- Reactivate the workstation (enable graphics).
+
+procedure gkp_reactivatews (flags)
+
+int flags # action flags
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "reactivatews %d\n")
+ call pargi (flags)
+end
+
+
+# GKP_DEACTIVATEWS -- Deactivate the workstation (disable graphics).
+
+procedure gkp_deactivatews (flags)
+
+int flags # action flags
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "deactivatews %d\n")
+ call pargi (flags)
+ call flush (fd)
+end
+
+
+# GKP_MFTITLE -- Metafile title or comment. A nonfunctional instruction used
+# to document a metafile.
+
+procedure gkp_mftitle (title, n)
+
+short title[ARB] # title string
+int n # length of title string
+pointer sp, buf
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call smark (sp)
+ call salloc (buf, n, TY_CHAR)
+
+ call achtsc (title, Memc[buf], n)
+ Memc[buf+n] = EOS
+
+ call fprintf (fd, "title '%s'\n")
+ call pargstr (Memc[buf])
+
+ call sfree (sp)
+end
+
+
+# GKP_CLEAR -- Clear the workstation screen.
+
+procedure gkp_clear (dummy)
+
+int dummy # not used at present
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "clear\n")
+end
+
+
+# GKP_CANCEL -- Cancel output.
+
+procedure gkp_cancel (dummy)
+
+int dummy # not used at present
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "cancel\n")
+ call flush (fd)
+end
+
+
+# GKP_FLUSH -- Flush output.
+
+procedure gkp_flush (dummy)
+
+int dummy # not used at present
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "flush\n")
+ call flush (fd)
+end
+
+
+# GKP_POLYLINE -- Draw a polyline.
+
+procedure gkp_polyline (p, npts)
+
+short p[ARB] # points defining line
+int npts # number of points, i.e., (x,y) pairs
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ # Print statistics on polyline.
+ call gkp_pstat (fd, p, npts, "polyline", verbose, gkiunits)
+end
+
+
+# GKP_POLYMARKER -- Draw a polymarker.
+
+procedure gkp_polymarker (p, npts)
+
+short p[ARB] # points defining line
+int npts # number of points, i.e., (x,y) pairs
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ # Print statistics on polymarker.
+ call gkp_pstat (fd, p, npts, "polymarker", verbose, gkiunits)
+end
+
+
+# GKP_FILLAREA -- Fill a closed area.
+
+procedure gkp_fillarea (p, npts)
+
+short p[ARB] # points defining line
+int npts # number of points, i.e., (x,y) pairs
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ # Print statistics on the fillarea polygon.
+ call gkp_pstat (fd, p, npts, "fillarea", verbose, gkiunits)
+end
+
+
+# GKP_TEXT -- Draw a text string.
+
+procedure gkp_text (x, y, text, n)
+
+int x, y # where to draw text string
+short text[ARB] # text string
+int n # number of characters
+
+pointer sp, buf
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call smark (sp)
+ call salloc (buf, n, TY_CHAR)
+
+ call achtsc (text, Memc[buf], n)
+ Memc[buf+n] = EOS
+
+ if (gkiunits == YES) {
+ call fprintf (fd, "text %5d, %5d, '%s'\n")
+ call pargi (x)
+ call pargi (y)
+ call pargstr (Memc[buf])
+ } else {
+ call fprintf (fd, "text %4.2f, %4.2f, '%s'\n")
+ call pargr (real(x) / GKI_MAXNDC)
+ call pargr (real(y) / GKI_MAXNDC)
+ call pargstr (Memc[buf])
+ }
+
+ call sfree (sp)
+end
+
+
+# GKP_PUTCELLARRAY -- Draw a cell array, i.e., two dimensional array of pixels
+# (greylevels or colors).
+
+procedure gkp_putcellarray (m, nx, ny, x1,y1, x2,y2)
+
+int nx, ny # number of pixels in X and Y
+short m[nx,ny] # cell array
+int x1, y1 # lower left corner of output window
+int x2, y2 # lower left corner of output window
+
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "put_cellarray nx=%d, ny=%d, ")
+ call pargi (nx)
+ call pargi (ny)
+
+ if (gkiunits == YES) {
+ call fprintf (fd, "x1=%5d, y1=%5d, x2=%5d, y2=%5d\n")
+ call pargi (x1)
+ call pargi (y1)
+ call pargi (x2)
+ call pargi (y2)
+ } else {
+ call fprintf (fd, "x1=%4.2f, y1=%4.2f, x2=%4.2f, y2=%4.2f\n")
+ call pargr (real(x1) / GKI_MAXNDC)
+ call pargr (real(y1) / GKI_MAXNDC)
+ call pargr (real(x2) / GKI_MAXNDC)
+ call pargr (real(y2) / GKI_MAXNDC)
+ }
+
+ if (verbose == YES)
+ call gkp_dump (fd, m, (nx * ny))
+end
+
+
+# GKP_GETCELLARRAY -- Input a cell array, i.e., two dimensional array of pixels
+# (greylevels or colors).
+
+procedure gkp_getcellarray (nx, ny, x1,y1, x2,y2)
+
+int nx, ny # number of pixels in X and Y
+int x1, y1 # lower left corner of input window
+int x2, y2 # lower left corner of input window
+
+pointer sp, buf
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "get_cellarray nx=%d, ny=%d, ")
+ call pargi (nx)
+ call pargi (ny)
+
+ if (gkiunits == YES) {
+ call fprintf (fd, "x1=%5d, y1=%5d, x2=%5d, y2=%5d\n")
+ call pargi (x1)
+ call pargi (y1)
+ call pargi (x2)
+ call pargi (y2)
+ } else {
+ call fprintf (fd, "x1=%4.2f, y1=%4.2f, x2=%4.2f, y2=%4.2f\n")
+ call pargr (real(x1) / GKI_MAXNDC)
+ call pargr (real(y1) / GKI_MAXNDC)
+ call pargr (real(x2) / GKI_MAXNDC)
+ call pargr (real(y2) / GKI_MAXNDC)
+ }
+
+ if (stream == NULL)
+ return
+
+ call smark (sp)
+ call salloc (buf, nx * ny, TY_SHORT)
+ call amovks (short(-1), Mems[buf], nx * ny)
+
+ call flush (fd)
+ iferr {
+ call gki_retcellarray (stream, Mems[buf], nx * ny)
+ call flush (stream)
+ } then
+ ;
+
+ call sfree (sp)
+end
+
+
+# GKP_SETCURSOR -- Set the position of a cursor.
+
+procedure gkp_setcursor (x, y, cursor)
+
+int x, y # new position of cursor
+int cursor # cursor to be set
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ if (gkiunits == YES) {
+ call fprintf (fd, "set_cursor %5d, %5d, cursor=%d\n")
+ call pargi (x)
+ call pargi (y)
+ call pargi (cursor)
+ } else {
+ call fprintf (fd, "set_cursor %4.2f, %4.2f, cursor=%d\n")
+ call pargr (real(x) / GKI_MAXNDC)
+ call pargr (real(y) / GKI_MAXNDC)
+ call pargi (cursor)
+ }
+end
+
+
+# GKP_GETCURSOR -- Get the position of a cursor.
+
+procedure gkp_getcursor (cursor)
+
+int cursor
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "get_cursor cursor=%d\n")
+ call pargi (cursor)
+ call flush (fd)
+
+ if (stream != NULL)
+ iferr {
+ # gki_retcursorvalue (stream, cn, key, sx, sy, rn, rx, ry)
+ call gki_retcursorvalue (stream, 0, EOF, 0, 0, 0, 0, 0)
+ call flush (stream)
+ } then
+ ;
+end
+
+
+# GKP_PLSET -- Set the polyline attributes.
+
+procedure gkp_plset (gki)
+
+short gki[ARB] # attribute structure
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "set_polyline ltype=%d, lwidth=%0.2f, color=%d\n")
+ call pargs (gki[GKI_PLSET_LT])
+ call pargr (GKI_UNPACKREAL (gki[GKI_PLSET_LW]))
+ call pargs (gki[GKI_PLSET_CI])
+end
+
+
+# GKP_PMSET -- Set the polymarker attributes.
+
+procedure gkp_pmset (gki)
+
+short gki[ARB] # attribute structure
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "set_polymarker mtype=%d, mwidth=%0.2f, color=%d\n")
+ call pargs (gki[GKI_PMSET_MT])
+ call pargr (GKI_UNPACKREAL (gki[GKI_PMSET_MW]))
+ call pargs (gki[GKI_PMSET_CI])
+end
+
+
+# GKP_FASET -- Set the fillarea attributes.
+
+procedure gkp_faset (gki)
+
+short gki[ARB] # attribute structure
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "set_fillarea style=%d, color=%d\n")
+ call pargs (gki[GKI_FASET_FS])
+ call pargs (gki[GKI_FASET_CI])
+end
+
+
+# GKP_TXSET -- Set the text drawing attributes.
+
+procedure gkp_txset (gki)
+
+short gki[ARB] # attribute structure
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "set_text up=%d, path=%d, hjustify=%s, ")
+ call pargs (gki[GKI_TXSET_UP])
+ call gkp_txparg (gki[GKI_TXSET_P])
+ call gkp_txparg (gki[GKI_TXSET_HJ])
+ call fprintf (fd, "vjustify=%s, font=%s,\n")
+ call gkp_txparg (gki[GKI_TXSET_VJ])
+ call gkp_txparg (gki[GKI_TXSET_F])
+
+ call fprintf (fd, "\tsize=%0.2f, spacing=%0.2f, color=%d, quality=%s\n")
+ call pargr (GKI_UNPACKREAL (gki[GKI_TXSET_SZ]))
+ call pargr (GKI_UNPACKREAL (gki[GKI_TXSET_SP]))
+ call pargs (gki[GKI_TXSET_CI])
+ call gkp_txparg (gki[GKI_TXSET_Q])
+end
+
+
+# GKP_ESCAPE -- Device dependent instruction.
+
+procedure gkp_escape (fn, instruction, nwords)
+
+int fn # function code
+short instruction[ARB] # instruction data words
+int nwords # length of instruction
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "escape %d, nwords=%d\n")
+ call pargi (fn)
+ call pargi (nwords)
+
+ # Dump the instruction.
+ if (verbose == YES)
+ call gkp_dump (fd, instruction, nwords)
+end
+
+
+# GKP_SETWCS -- Set the world coordinate systems. Internal GIO instruction.
+
+procedure gkp_setwcs (wcs, nwords)
+
+short wcs[ARB] # WCS data
+int nwords # number of words of data
+
+int i, nwcs
+pointer sp, wcs_temp, w
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call smark (sp)
+ call salloc (wcs_temp, LEN_WCSARRAY, TY_STRUCT)
+
+ call fprintf (fd, "set_wcs nwords=%d\n")
+ call pargi (nwords)
+
+ nwcs = nwords * SZ_SHORT / SZ_STRUCT / LEN_WCS
+ if (verbose == YES && nwcs > 1) {
+ call amovi (wcs, Memi[wcs_temp], nwcs * LEN_WCS)
+
+ do i = 1, nwcs {
+ w = ((i - 1) * LEN_WCS) + wcs_temp
+ if ((WCS_WX1(w) > EPSILON) ||
+ (abs(1.0 - WCS_WX2(w)) > EPSILON) ||
+ (WCS_WY1(w) > EPSILON) ||
+ (abs(1.0 - WCS_WY2(w)) > EPSILON)) {
+
+ call fprintf (fd, "\t%2d %g %g %g %g ")
+ call pargi (i)
+ call pargr (WCS_WX1(w))
+ call pargr (WCS_WX2(w))
+ call pargr (WCS_WY1(w))
+ call pargr (WCS_WY2(w))
+
+ call fprintf (fd, "%4.2f %4.2f %4.2f %4.2f ")
+ call pargr (WCS_SX1(w))
+ call pargr (WCS_SX2(w))
+ call pargr (WCS_SY1(w))
+ call pargr (WCS_SY2(w))
+
+ call fprintf (fd, "%d %d %d\n")
+ call pargi (WCS_XTRAN(w))
+ call pargi (WCS_YTRAN(w))
+ call pargi (WCS_CLIP(w))
+ }
+ }
+ }
+
+ call sfree (sp)
+end
+
+
+# GKP_GETWCS -- Get the world coordinate systems. Internal GIO instruction.
+
+procedure gkp_getwcs (wcs, nwords)
+
+short wcs[ARB] # WCS data
+int nwords # number of words of data
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "get_wcs nwords=%d\n")
+ call pargi (nwords)
+end
+
+
+# GKP_UNKNOWN -- The unknown instruction. Called by the interpreter whenever
+# an unrecognized opcode is encountered. Should never be called.
+
+procedure gkp_unknown (gki)
+
+short gki[ARB] # the GKI instruction
+int fd, stream, verbose, gkiunits
+common /gkpcom/ fd, stream, verbose, gkiunits
+
+begin
+ call fprintf (fd, "unknown\n")
+end
+
+
+# GKP_PSTAT -- Compute and print on the standard error output a statistical
+# summary of a sequence of (x,y) points. If verbose mode is enabled, follow
+# this by the values of the points themselves.
+
+procedure gkp_pstat (fd, p, npts, label, verbose, gkiunits)
+
+int fd # output file
+short p[npts] # array of points, i.e., (x,y) pairs
+int npts # number of points
+char label[ARB] # type of instruction
+int verbose # verbose output desired
+int gkiunits # print coords in GKI rather than NDC units
+
+int i
+real x, y, xsum, xmin, xmax, ysum, ymin, ymax, scale
+
+begin
+ if (gkiunits == YES)
+ scale = 1.0
+ else
+ scale = 1.0 / GKI_MAXNDC
+
+ xsum = 0
+ xmin = 1.0
+ xmax = 0
+ ysum = 0
+ ymin = 1.0
+ ymax = 0
+
+ # Compute mean, minimum, and maximum values.
+ do i = 1, npts * 2, 2 {
+ x = real (p[i]) * scale
+ xsum = xsum + x
+ if (x < xmin)
+ xmin = x
+ if (x > xmax)
+ xmax = x
+
+ y = real (p[i+1]) * scale
+ ysum = ysum + y
+ if (y < ymin)
+ ymin = y
+ if (y > ymax)
+ ymax = y
+ }
+
+ # Print summary of statistics.
+ call fprintf (fd, "%s np=%d, ")
+ call pargstr (label)
+ call pargi (npts)
+
+ if (gkiunits == YES)
+ call fprintf (fd, "xmin=%d,xmax=%d,xavg=%d, ")
+ else
+ call fprintf (fd, "xmin=%4.2f,xmax=%4.2f,xavg=%4.2f, ")
+ if (npts == 0) {
+ do i = 1, 3
+ call pargr (INDEF)
+ } else {
+ call pargr (xmin)
+ call pargr (xmax)
+ call pargr (xsum / npts)
+ }
+
+ if (gkiunits == YES)
+ call fprintf (fd, "ymin=%d,ymax=%d,yavg=%d\n")
+ else
+ call fprintf (fd, "ymin=%4.2f,ymax=%4.2f,yavg=%4.2f\n")
+ if (npts == 0) {
+ do i = 1, 3
+ call pargr (INDEF)
+ } else {
+ call pargr (ymin)
+ call pargr (ymax)
+ call pargr (ysum / npts)
+ }
+
+ # Dump the points if verbose output is enabled.
+ if (verbose == NO && npts > 0)
+ return
+
+ call fprintf (fd, "\t")
+ for (i=1; i <= npts * 2; i=i+2) {
+ if (i > 1 && mod (i-1, 10) == 0)
+ call fprintf (fd, "\n\t")
+ if (gkiunits == YES)
+ call fprintf (fd, "%5d %5d ")
+ else
+ call fprintf (fd, "%5.3f %5.3f ")
+ call pargr (real(p[i]) * scale)
+ call pargr (real(p[i+1]) * scale)
+ }
+ call fprintf (fd, "\n")
+end
+
+
+# GKP_DUMP -- Print a sequence of metacode words as a table, formatted eight
+# words per line, in decimal.
+
+procedure gkp_dump (fd, data, nwords)
+
+int fd # output file
+short data[ARB] # metacode data
+int nwords # number of words of data
+int i
+
+begin
+ if (nwords <= 0)
+ return
+
+ call fprintf (fd, "\t")
+
+ for (i=1; i <= nwords; i=i+1) {
+ if (i > 1 && mod (i-1, 8) == 0)
+ call fprintf (fd, "\n\t")
+ call fprintf (fd, "%7d")
+ call pargs (data[i])
+ }
+
+ call fprintf (fd, "\n")
+end
diff --git a/sys/gio/gki/gkirca.x b/sys/gio/gki/gkirca.x
new file mode 100644
index 00000000..54b38813
--- /dev/null
+++ b/sys/gio/gki/gkirca.x
@@ -0,0 +1,30 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gki.h>
+
+# GKI_RETCELLARRAY -- Return a cell array (pixel array). Used by a graphics
+# kernel to return a cell array to GIO in response to a GETCELLARRAY
+# instruction.
+#
+# BOI GKI_CELLARRAY L NP P
+#
+# L(i) 4 + NP
+# NP(i) number of pixels in cell array
+# P(NPi) cell array
+
+procedure gki_retcellarray (fd, m, np)
+
+int fd # output file
+short m[ARB] # cell array
+int np # number of pixels in cell array
+
+short gki[GKI_CELLARRAY_LEN]
+data gki[1] /BOI/, gki[2] /GKI_CELLARRAY/
+
+begin
+ gki[GKI_CELLARRAY_L] = GKI_CELLARRAY_LEN + np
+ gki[GKI_CELLARRAY_NP] = np
+
+ call write (fd, gki, GKI_CELLARRAY_LEN * SZ_SHORT)
+ call write (fd, m, np * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkircval.x b/sys/gio/gki/gkircval.x
new file mode 100644
index 00000000..9bfb3052
--- /dev/null
+++ b/sys/gio/gki/gkircval.x
@@ -0,0 +1,51 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gki.h>
+
+# GKI_RETCURSORVALUE -- Return a cursor value. Used by a graphics kernel to
+# return a cursor value to GIO in response to a GETCURSOR instruction.
+#
+# BOI GKI_CURSORVALUE L CN KEY SX SY RN RX RY
+#
+# where
+#
+# L(i) 10
+# CN(i) cursor number
+# KEY(i) keystroke value (>= 0 or EOF)
+# SX(i) NDC X screen coordinate of cursor
+# SY(i) NDC Y screen coordinate of cursor
+# RN(i) raster number or zero
+# RX(i) NDC X raster coordinate of cursor
+# RY(i) NDC Y raster coordinate of cursor
+#
+# The screen or display window coordinates SX and SY of the cursor are
+# returned for all devices. Only some devices support multiple rasters.
+# If the device supports rasters and the cursor is in a raster when read, the
+# raster number and raster coordinates are returned in RN,RX,RY. This is in
+# addition to the screen coordinates SX,SY. If raster coordinates are not
+# returned, the raster number will be set to zero and RX,RY will be the same
+# as SX,SY.
+
+procedure gki_retcursorvalue (fd, cn, key, sx, sy, raster, rx, ry)
+
+int fd #I output file
+int cn #I cursor number
+int key #I keystroke value
+int sx, sy #I screen coordinates of cursor (GKI coords)
+int raster #I raster number
+int rx, ry #I raster coordinates of cursor (GKI coords)
+
+short gki[GKI_CURSORVALUE_LEN]
+data gki[1] /BOI/, gki[2] /GKI_CURSORVALUE/, gki[3] /GKI_CURSORVALUE_LEN/
+
+begin
+ gki[GKI_CURSORVALUE_CN ] = cn
+ gki[GKI_CURSORVALUE_KEY] = key
+ gki[GKI_CURSORVALUE_SX ] = sx
+ gki[GKI_CURSORVALUE_SY ] = sy
+ gki[GKI_CURSORVALUE_RN ] = raster
+ gki[GKI_CURSORVALUE_RX ] = rx
+ gki[GKI_CURSORVALUE_RY ] = ry
+
+ call write (fd, gki, GKI_CURSORVALUE_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkireact.x b/sys/gio/gki/gkireact.x
new file mode 100644
index 00000000..a84ad95d
--- /dev/null
+++ b/sys/gio/gki/gkireact.x
@@ -0,0 +1,42 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_REACTIVATEWS -- Reactivate the workstation (enable graphics).
+#
+# BOI GKI_REACTIVATEWS L F
+#
+# L(i) 4
+# F flags (0,AW_PAUSE,AW_CLEAR)
+
+procedure gki_reactivatews (fd, flags)
+
+int fd # output file
+int flags # action modifier flags
+
+int epa, nchars
+short gki[GKI_REACTIVATEWS_LEN]
+data gki[1] /BOI/, gki[2] /GKI_REACTIVATEWS/, gki[3] /GKI_REACTIVATEWS_LEN/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_REACTIVATEWS]
+ if (epa != 0)
+ call zcall1 (epa, flags)
+
+ } else {
+ # Send a copy to the pseudofile i/o controller.
+ gki[GKI_REACTIVATEWS_F] = flags
+ nchars = GKI_REACTIVATEWS_LEN * SZ_SHORT
+ if (IS_FILE(fd) && (fd >= STDGRAPH && fd <= STDPLOT)) {
+ call write (PSIOCTRL, fd, SZ_INT32)
+ call write (PSIOCTRL, gki, nchars)
+ call flush (PSIOCTRL)
+ }
+
+ # Now send a copy to the graphics kernel.
+ call write (gk_fd[fd], gki, nchars)
+ }
+end
diff --git a/sys/gio/gki/gkiredir.x b/sys/gio/gki/gkiredir.x
new file mode 100644
index 00000000..3e204bf0
--- /dev/null
+++ b/sys/gio/gki/gkiredir.x
@@ -0,0 +1,34 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_REDIR -- Redirect (or set) a graphics stream. All i/o will be to the
+# file FD until the graphics stream is reset in another call to GKI_REDIR.
+# The current encoded value for a stream is retured so that a subsequent call
+# (with FD=0) may be made to undo the redirection. A call with FD<0 may be
+# used to stat the stream without changing anything. NOTE: This procedure
+# (or either GKI_INLINE_KERNEL or GKI_SUBKERNEL) must be called before using
+# the GKI package for a graphics stream.
+
+procedure gki_redir (stream, fd, old_fd, old_type)
+
+int stream # graphics stream to be redirected
+int fd # file to be connected to the stream
+int old_fd, old_type # old values for later restoration
+
+include "gki.com"
+
+begin
+ if (fd == NULL) {
+ gk_type[stream] = old_type
+ gk_fd[stream] = old_fd
+ } else {
+ old_type = gk_type[stream]
+ old_fd = gk_fd[stream]
+ if (fd > 0) {
+ gk_type[stream] = TY_FILE
+ gk_fd[stream] = fd
+ }
+ }
+end
diff --git a/sys/gio/gki/gkiscur.x b/sys/gio/gki/gkiscur.x
new file mode 100644
index 00000000..f3ca7c53
--- /dev/null
+++ b/sys/gio/gki/gkiscur.x
@@ -0,0 +1,37 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_SETCURSOR -- Set the position of a device cursor.
+#
+# BOI GKI_SETCURSOR L CN POS
+#
+# L(i) 6
+# CN(i) cursor number
+# POS(p) new cursor position
+
+procedure gki_setcursor (fd, x, y, cursor)
+
+int fd # output file
+int x, y # new cursor position
+int cursor # cursor to be set
+
+int epa
+short gki[GKI_SETCURSOR_LEN]
+data gki[1] /BOI/, gki[2] /GKI_SETCURSOR/, gki[3] /GKI_SETCURSOR_LEN/
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_SETCURSOR]
+ if (epa != 0)
+ call zcall3 (epa, x, y, cursor)
+ } else {
+ gki[GKI_SETCURSOR_CN] = cursor
+ gki[GKI_SETCURSOR_POS] = x
+ gki[GKI_SETCURSOR_POS+1] = y
+
+ call write (gk_fd[fd], gki, GKI_SETCURSOR_LEN * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkisetwcs.x b/sys/gio/gki/gkisetwcs.x
new file mode 100644
index 00000000..f8d0e896
--- /dev/null
+++ b/sys/gio/gki/gkisetwcs.x
@@ -0,0 +1,46 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_SETWCS -- Copy the set of 16 WCS to the graphics controller in the CL
+# process. The WCS are transmitted as a binary array of WCS structures.
+#
+# BOI GKI_SETWCS L N WCS
+#
+# L(i) 4 + N
+# N(i) length of WCS field in words
+# WCS binary copy of the 16 WCS structures, transmitted
+# in a single call to WRITE
+
+procedure gki_setwcs (fd, wcs, len_wcs)
+
+int fd # output file
+int wcs[ARB] # array of WCS structures
+int len_wcs # number of ints (struct units) in array
+
+int nshorts
+short gki[GKI_SETWCS_LEN]
+data gki[1] /BOI/, gki[2] /GKI_SETWCS/
+include "gki.com"
+
+begin
+ if (IS_FILE(fd)) {
+ nshorts = (len_wcs * SZ_INT) / SZ_SHORT
+ gki[GKI_SETWCS_L] = GKI_SETWCS_LEN + nshorts
+ gki[GKI_SETWCS_N] = nshorts
+
+ if (fd >= STDGRAPH && fd <= STDPLOT) {
+ # Send a copy of the WCS information to the PSIO control
+ # stream if the graphics output is a standard graphics stream.
+
+ call write (PSIOCTRL, fd, SZ_INT32)
+ call write (PSIOCTRL, gki, GKI_SETWCS_LEN * SZ_SHORT)
+ call write (PSIOCTRL, wcs, nshorts * SZ_SHORT)
+ call flush (PSIOCTRL)
+ }
+
+ call write (gk_fd[fd], gki, GKI_SETWCS_LEN * SZ_SHORT)
+ call write (gk_fd[fd], wcs, nshorts * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkititle.x b/sys/gio/gki/gkititle.x
new file mode 100644
index 00000000..397bd50a
--- /dev/null
+++ b/sys/gio/gki/gkititle.x
@@ -0,0 +1,51 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_MFTITLE -- Write the metafile title.
+#
+# BOI GKI_MFTITLE L N T
+#
+# L(i) 4 + N
+# N(i) number of characters in field T
+# T(Nc) title string identifying metafile
+
+procedure gki_mftitle (fd, title)
+
+int fd # output file
+char title[ARB] # title string
+
+int epa
+int ip, n
+pointer sp, gki, op
+int strlen()
+include "gki.com"
+
+begin
+ call smark (sp)
+
+ n = strlen (title)
+ call salloc (gki, GKI_MFTITLE_LEN + n, TY_SHORT)
+
+ # Pack the title name as a SHORT integer array.
+ op = gki + GKI_MFTITLE_T - 1
+ for (ip=1; ip <= n; ip=ip+1) {
+ Mems[op] = title[ip]
+ op = op + 1
+ }
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_MFTITLE]
+ if (epa != 0)
+ call zcall2 (epa, Mems[gki+GKI_MFTITLE_T-1], n)
+ } else {
+ Mems[gki ] = BOI
+ Mems[gki+1] = GKI_MFTITLE
+ Mems[gki+2] = GKI_MFTITLE_LEN + n
+ Mems[gki+3] = n
+ call write (gk_fd[fd], Mems[gki], (GKI_MFTITLE_LEN + n) * SZ_SHORT)
+ }
+
+ call sfree (sp)
+end
diff --git a/sys/gio/gki/gkitx.x b/sys/gio/gki/gkitx.x
new file mode 100644
index 00000000..7cc616ba
--- /dev/null
+++ b/sys/gio/gki/gkitx.x
@@ -0,0 +1,57 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_TEXT -- Text drawing instruction.
+#
+# BOI GKI_TEXT L P N T
+#
+# L(i) 6 + N
+# P(p) starting point of character string
+# N(i) number of characters in string T
+# T(Nc) string of N ASCII characters
+
+procedure gki_text (fd, x, y, text)
+
+int fd # output file
+int x, y # position at which text is to be drawn
+char text[ARB] # text string to be drawn
+
+int epa
+int ip, n
+pointer sp, gki, op
+int strlen()
+include "gki.com"
+
+begin
+ call smark (sp)
+
+ n = strlen (text)
+ call salloc (gki, GKI_TEXT_LEN + n, TY_SHORT)
+
+ # Pack the text string as a SHORT integer array.
+ op = gki + GKI_TEXT_T - 1
+ for (ip=1; ip <= n; ip=ip+1) {
+ Mems[op] = text[ip]
+ op = op + 1
+ }
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_TEXT]
+ if (epa != 0)
+ call zcall4 (epa, x, y, Mems[gki+GKI_TEXT_T-1], n)
+ } else {
+ Mems[gki ] = BOI
+ Mems[gki+1] = GKI_TEXT
+ Mems[gki+2] = GKI_TEXT_LEN + n
+ Mems[gki+GKI_TEXT_L-1] = GKI_TEXT_LEN + n
+ Mems[gki+GKI_TEXT_P-1] = x
+ Mems[gki+GKI_TEXT_P-1+1] = y
+ Mems[gki+GKI_TEXT_N-1] = n
+
+ call write (gk_fd[fd], Mems[gki], (GKI_TEXT_LEN + n) * SZ_SHORT)
+ }
+
+ call sfree (sp)
+end
diff --git a/sys/gio/gki/gkitxset.x b/sys/gio/gki/gkitxset.x
new file mode 100644
index 00000000..93f427b9
--- /dev/null
+++ b/sys/gio/gki/gkitxset.x
@@ -0,0 +1,51 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+include <gio.h>
+
+# GKI_TXSET -- Set the text drawing attributes.
+#
+# BOI GKI_TXSET L UP SZ SP P HJ VJ F Q CI
+#
+# L(i) 12
+# UP(i) character up vector (degrees)
+# SZ(r) character size scale factor
+# SP(r) character spacing
+# P(i) path (0,1=right,2=left,3=up,4=down)
+# HJ(i) horizontal justification
+# (0=normal,1=center,2=left,3=right)
+# VJ(i) vertical justification
+# (0=normal,1=center,2=up,3=down)
+# F(i) font (0,1=roman,2=greek,3=italic,4=bold)
+# Q(i) quality (0=normal,1=low,2=medium,3=high)
+# CI(i) text color index
+
+procedure gki_txset (fd, ap)
+
+int fd # output file
+pointer ap # pointer to attribute structure
+
+int epa
+short gki[GKI_TXSET_LEN]
+data gki[1] /BOI/, gki[2] /GKI_TXSET/, gki[3] /GKI_TXSET_LEN/
+include "gki.com"
+
+begin
+ gki[GKI_TXSET_UP] = TX_UP(ap)
+ gki[GKI_TXSET_SZ] = GKI_PACKREAL (TX_SIZE(ap))
+ gki[GKI_TXSET_SP] = GKI_PACKREAL (TX_SPACING(ap))
+ gki[GKI_TXSET_P ] = TX_PATH(ap)
+ gki[GKI_TXSET_HJ] = TX_HJUSTIFY(ap)
+ gki[GKI_TXSET_VJ] = TX_VJUSTIFY(ap)
+ gki[GKI_TXSET_F ] = TX_FONT(ap)
+ gki[GKI_TXSET_Q ] = TX_QUALITY(ap)
+ gki[GKI_TXSET_CI] = TX_COLOR(ap)
+
+ if (IS_INLINE(fd)) {
+ epa = gk_dd[GKI_TXSET]
+ if (epa != 0)
+ call zcall1 (epa, gki)
+ } else
+ call write (gk_fd[fd], gki, GKI_TXSET_LEN * SZ_SHORT)
+end
diff --git a/sys/gio/gki/gkiwesc.x b/sys/gio/gki/gkiwesc.x
new file mode 100644
index 00000000..bd4c8571
--- /dev/null
+++ b/sys/gio/gki/gkiwesc.x
@@ -0,0 +1,59 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_WESCAPE -- Write a GKI escape instruction, used to pass device
+# dependent instructions on to a graphics kernel. This version of gki_escape
+# is used in cases where the escape instruction consists of the escape header
+# followed by a block of data, and it is inconvenient to have to combine the
+# header and the data into one array.
+#
+# BOI GKI_ESCAPE L FN N DC
+#
+# L(i) 5 + N
+# FN(i) escape function code
+# N(i) number of escape data words
+# DC(i) escape data words
+
+procedure gki_wescape (fd, fn, hdr, hdrlen, data, datalen)
+
+int fd #I output file
+int fn #I escape function code
+short hdr[ARB] #I escape instruction header
+int hdrlen #I header length, shorts
+short data[ARB] #I escape instruction data
+int datalen #I data length, shorts
+
+pointer sp, buf
+int epa, nwords
+short gki[GKI_ESCAPE_LEN]
+data gki[1] /BOI/, gki[2] /GKI_ESCAPE/
+include "gki.com"
+
+begin
+ nwords = hdrlen + datalen
+
+ if (IS_INLINE(fd)) {
+ call smark (sp)
+ call salloc (buf, nwords, TY_SHORT)
+
+ call amovs (hdr, Mems[buf], hdrlen)
+ call amovs (data, Mems[buf+hdrlen], datalen)
+
+ epa = gk_dd[GKI_ESCAPE]
+ if (epa != 0)
+ call zcall3 (epa, fn, Mems[buf], nwords)
+
+ call sfree (sp)
+
+ } else {
+ gki[GKI_ESCAPE_L] = GKI_ESCAPE_LEN + nwords
+ gki[GKI_ESCAPE_N] = nwords
+ gki[GKI_ESCAPE_FN] = fn
+
+ call write (gk_fd[fd], gki, GKI_ESCAPE_LEN * SZ_SHORT)
+ call write (gk_fd[fd], hdr, hdrlen * SZ_SHORT)
+ call write (gk_fd[fd], data, datalen * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkiwrite.x b/sys/gio/gki/gkiwrite.x
new file mode 100644
index 00000000..65d911b1
--- /dev/null
+++ b/sys/gio/gki/gkiwrite.x
@@ -0,0 +1,26 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <gki.h>
+
+# GKI_WRITE -- Write a GKI metacode instruction to a graphics kernel. If the
+# kernel is inline the kernel is directly called to execute the instruction,
+# otherwise the instruction is written into the graphics stream for the
+# kernel. This procedure is functionally equivalent to GKI_EXECUTE, but works
+# for both inline and external kernels.
+
+procedure gki_write (fd, gki)
+
+int fd # graphics stream
+short gki[ARB] # encoded instruction
+int length
+include "gki.com"
+
+begin
+ if (IS_INLINE(fd))
+ call gki_execute (gki, gk_dd)
+ else {
+ length = gki[GKI_HDR_LENGTH]
+ call write (gk_fd[fd], gki, length * SZ_SHORT)
+ }
+end
diff --git a/sys/gio/gki/gkptxparg.x b/sys/gio/gki/gkptxparg.x
new file mode 100644
index 00000000..75d7325a
--- /dev/null
+++ b/sys/gio/gki/gkptxparg.x
@@ -0,0 +1,47 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gset.h>
+
+# GKP_TXPARG -- Convert a short integer text attribute code into a string
+# and pass the string to FMTIO.
+
+procedure gkp_txparg (code)
+
+short code # defined in <gset.h>
+
+begin
+ switch (code) {
+ case GT_NORMAL:
+ call pargstr ("normal")
+ case GT_CENTER:
+ call pargstr ("center")
+ case GT_LEFT:
+ call pargstr ("left")
+ case GT_RIGHT:
+ call pargstr ("right")
+ case GT_UP:
+ call pargstr ("up")
+ case GT_DOWN:
+ call pargstr ("down")
+ case GT_TOP:
+ call pargstr ("top")
+ case GT_BOTTOM:
+ call pargstr ("bottom")
+ case GT_ROMAN:
+ call pargstr ("roman")
+ case GT_GREEK:
+ call pargstr ("greek")
+ case GT_ITALIC:
+ call pargstr ("italic")
+ case GT_BOLD:
+ call pargstr ("bold")
+ case GT_LOW:
+ call pargstr ("low")
+ case GT_MEDIUM:
+ call pargstr ("medium")
+ case GT_HIGH:
+ call pargstr ("high")
+ default:
+ call pargstr ("??")
+ }
+end
diff --git a/sys/gio/gki/mkpkg b/sys/gio/gki/mkpkg
new file mode 100644
index 00000000..c71f2e71
--- /dev/null
+++ b/sys/gio/gki/mkpkg
@@ -0,0 +1,46 @@
+# Make the GKI (graphics kernel interface) package.
+
+$checkout libex.a lib$
+$update libex.a
+$checkin libex.a lib$
+$exit
+
+libex.a:
+ gkicancel.x gki.com <config.h> <gki.h>
+ gkiclear.x gki.com <config.h> <gki.h>
+ gkiclose.x gki.com <config.h> <gki.h>
+ gkideact.x gki.com <config.h> <gki.h>
+ gkieof.x gki.com <config.h> <gki.h>
+ gkiesc.x gki.com <config.h> <gki.h>
+ gkiexe.x <gki.h>
+ gkifa.x gki.com <config.h> <gki.h>
+ gkifaset.x gki.com <config.h> <gio.h> <gki.h>
+ gkifetch.x <gki.h>
+ gkifflush.x gki.com <config.h> <fio.h> <gki.h>
+ gkiflush.x gki.com <config.h> <fio.h> <gki.h>
+ gkigca.x gki.com <config.h> <fio.h> <fset.h> <gki.h>
+ gkigcur.x gki.com <config.h> <fio.h> <fset.h> <gki.h>
+ gkigetwcs.x gki.com <config.h> <gki.h>
+ gkiinit.x gki.com <config.h> <gki.h>
+ gkiinline.x gki.com <config.h> <gki.h>
+ gkikern.x gki.com <config.h> <gki.h>
+ gkiopen.x gki.com <config.h> <gki.h>
+ gkipca.x gki.com <config.h> <gki.h>
+ gkipl.x gki.com <config.h> <gki.h>
+ gkiplset.x gki.com <config.h> <gio.h> <gki.h>
+ gkipm.x gki.com <config.h> <gki.h>
+ gkipmset.x gki.com <config.h> <gio.h> <gki.h>
+ gkiprint.x <config.h> <gio.h> <gki.h> <gset.h> <mach.h>
+ gkirca.x <gki.h>
+ gkircval.x <gki.h>
+ gkireact.x gki.com <config.h> <gki.h>
+ gkiredir.x gki.com <config.h> <gki.h>
+ gkiscur.x gki.com <config.h> <gki.h>
+ gkisetwcs.x gki.com <config.h> <gki.h>
+ gkititle.x gki.com <config.h> <gki.h>
+ gkitx.x gki.com <config.h> <gki.h>
+ gkitxset.x gki.com <config.h> <gio.h> <gki.h>
+ gkiwesc.x gki.com <config.h> <gki.h>
+ gkiwrite.x gki.com <config.h> <gki.h>
+ gkptxparg.x <gset.h>
+ ;
diff --git a/sys/gio/gki/zzdebug.x b/sys/gio/gki/zzdebug.x
new file mode 100644
index 00000000..e56c5cc0
--- /dev/null
+++ b/sys/gio/gki/zzdebug.x
@@ -0,0 +1,44 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <fset.h>
+include <fio.h>
+include <gki.h>
+
+task ggcur = t_ggcur
+
+
+# GGCUR -- Debug cursor read in inline graphics kernel.
+
+procedure t_ggcur()
+
+pointer gp
+char device[SZ_FNAME]
+
+real cx, cy
+int key, xres, yres, hardchar
+int dd[LEN_GKIDD]
+pointer gopen()
+
+begin
+ call clgstr ("device", device, SZ_FNAME)
+ hardchar = YES
+ xres = 0
+ yres = 0
+
+ call fseti (STDGRAPH, F_TYPE, SPOOL_FILE)
+ call fseti (STDGRAPH, F_CANCEL, OK)
+
+ call stg_open (device, dd, STDIN, STDOUT, xres, yres, hardchar)
+ call gki_inline_kernel (STDGRAPH, dd)
+
+ gp = gopen (device, NEW_FILE, STDGRAPH)
+ call ggcur (gp, cx, cy, key)
+
+ call gclose (gp)
+ call stg_close()
+
+ call printf ("cx=%f, cy=%f, key=%d\n")
+ call pargr (cx)
+ call pargr (cy)
+ call pargi (key)
+end