aboutsummaryrefslogtreecommitdiff
path: root/unix/gdev/iism75/zwrm75.x
blob: 38bb0f3cb96b7736002f49139c832684f32f7eec (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<mach.h>
include	"m75.h"
include	"iis.h"

# ZWRM75 -- Initiate an asynchronous write to the IIS.  We are called to
# output the header of all instructions sent to the IIS.  There are 3 types
# of instructions; those which consist only of a header write, those which
# consist of a header write followed by a data write, and those which
# consist of a header write followed by a data read.  Translation of an M70
# instruction into an M75 instruction may involve moving information between
# the header and data block, hence we must save the headers of the read and
# write instructions until the data has been read or written.  The STATE
# variable in the channel descriptor is used to keep track of the instruction
# processing state.

procedure zwrm75 (ifcb, buf, nbytes, offset)

int	ifcb			# pointer to channel descriptor passed as int
char	buf[ARB]		# input buffer
int	nbytes			# number of  bytes to write
long	offset			# not used for this device

pointer	fcb
int	xferid, and()

begin
	fcb = ifcb

	if (FCB_STATE(fcb) == READY) {
	    # Start a new instruction.

	    if (nbytes != SZB_IISHDR) {
		FCB_STATUS(fcb) = ERR
		return
	    }

	    # Save the M70 header in the descriptor.
	    call amovs (buf, FCB_IISHDR(fcb), LEN_IISHDR)
	    xferid = XFERID(buf)

	    # Determine the state for the new instruction.

	    if (THINGCT(buf) == 0)
		FCB_STATE(fcb) = READY
	    else if (and (xferid, IREAD) != 0)
		FCB_STATE(fcb) = DATA_READ
	    else
		FCB_STATE(fcb) = DATA_WRITE

	    # If the new state is READY, no data read or write is needed,
	    # so just translate and output the header.

	    if (FCB_STATE(fcb) == READY)
		call m75put (fcb, buf, nbytes, offset)
	    else {
		# Set up a channel status as if we had just written the new
		# header, so that the next ZWTM75 will not return an error.

		FCB_STATUS(fcb) = IIS_INACTIVE
		FCB_NBYTES(fcb) = SZB_IISHDR
	    }
	    
	} else if (FCB_STATE(fcb) == DATA_WRITE) {
	    # This is the second zwrm75 call for a hdr+data output
	    # instruction.

	    call m75put (fcb, buf, nbytes, offset)
	    FCB_STATE(fcb) = READY

	} else {
	    # ZRDM75 should have been called, set error on the channel.
	    FCB_STATUS(fcb) = ERR
	}
end