aboutsummaryrefslogtreecommitdiff
path: root/pkg/images/tv/iis/ids/idsopenws.x
blob: bd25b260481093e2638b2508d064df7250b58480 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include <mach.h>
include <fset.h>
include	<gki.h>
include	<error.h>
include	"../lib/ids.h"

# IDS_OPENWS -- Open the named workstation.  Once a workstation has been
# opened we leave it open until some other workstation is opened or the
# kernel is closed.  Opening a workstation involves initialization of the
# kernel data structures. Initialization of the device itself is left to
# an explicit reset command.

procedure ids_openws (devname, n, mode)

short	devname[ARB]		# device name
int	n			# length of device name
int	mode			# access mode

long	filesize
bool	need_open, same_dev
pointer	sp, buf, devinfo

long	fstatl()
pointer	ttygdes()
bool	streq(), ttygetb()
int	fopnbf(), ttygets()
extern	zopnim(), zardim(), zawrim(), zawtim(), zsttim(), zclsim()
errchk	ttygdes
int	oldmode
data	oldmode /-1/

include	"../lib/ids.com"

begin
	call smark (sp)
	call salloc (buf, max (SZ_FNAME, n), TY_CHAR)
	call salloc (devinfo, SZ_LINE, TY_CHAR)

	# If a device was named when the kernel was opened then output will
	# always be to that device (i_device) regardless of the device named
	# in the OPENWS instruction.  If no device was named (null string)
	# then unpack the device name, passed as a short integer array.

	if (i_device[1] == EOS) {
	    call achtsc (devname, Memc[buf], n)
	    Memc[buf+n] = EOS
	} else
	    call strcpy (i_device, Memc[buf], SZ_FNAME)

	# find out if first time, and if not, if same device as before
	# note that if (i_kt == NULL), then same_dev is false.

	same_dev = false
	need_open = true
	if ( i_kt != NULL ) {
	    same_dev = (streq(Memc[IDS_DEVNAME(i_kt)], Memc[buf]))
	    if ( !same_dev  || ( oldmode != mode))
		call close(i_out)
	    else
		need_open = false
	}
	oldmode = mode

	# Initialize the kernel data structures.  Open graphcap descriptor
	# for the named device, allocate and initialize descriptor and common.
	# graphcap entry for device must exist.

	if (need_open) {
	    if ((i_kt != NULL) && !same_dev)
		call ttycdes (i_tty)
	    if (!same_dev) {
	        i_tty = ttygdes (Memc[buf])
		if (ttygetb (i_tty, "LC"))
		    call error (1, "operation not supported on device")
	    }

	    if (ttygets (i_tty, "DD", Memc[devinfo], SZ_LINE) <= 0)
		call strcpy (Memc[buf], Memc[devinfo], SZ_LINE)

	    # Open the output file.  The device is connected to FIO as a 
	    # binary file.  mode must be READ_WRITE or WRITE_ONLY
	    # for image display!

	    iferr (i_out = fopnbf (Memc[devinfo], mode, zopnim, zardim,
	        zawrim, zawtim, zsttim, zclsim)) {

	        call ttycdes (i_tty)
	        call erract (EA_ERROR)
	    }
	    call fseti (i_out, F_ADVICE, SEQUENTIAL)

	}

	# Initialize data structures.
	# Device specific initialization will be done in the zinit call
	# from ids_init().

	if (!same_dev) {
	    call ids_init (i_tty, Memc[buf])

	    # Now set the file size to allow mapping of all control registers
	    # as well as all image and graphics planes.  The call to fstatl
	    # returns the size of an image plane (!!).  zinit does whatever
	    # device work it needs to do, and uses its arguments to determine
	    # the total file size, which it returns.
	    # This feature need not be used (and is not for the IIS display).
	    #
	    # We also set the F_ASYNC parameter to YES.

	    i_frsize = fstatl(i_out, F_FILESIZE)
	    filesize = i_frsize
	    call zinit(i_maxframes, i_maxgraph, filesize)
	    call fseti(i_out, F_ASYNC, YES)

	}

	call sfree (sp)
end