1 /* ***********************************************************
  2    *                                                         *
  3    * Copyright, (C) Honeywell Information Systems Inc., 1982 *
  4    *                                                         *
  5    * Copyright (c) 1972 by Massachusetts Institute of        *
  6    * Technology and Honeywell Information Systems, Inc.      *
  7    *                                                         *
  8    *********************************************************** */
  9 
 10 
 11 
 12 /* PRTDIM_ATTACH - Attach/Detach module for the printer DIM.
 13    coded 10/30/74 by Noel I. Morris     */
 14 /* Modified: 27 November 1981 by G. Palter to clear new reload_vfc_train_when_ready flag */
 15 
 16 
 17 prtdim_attach:                                              /* attach a printer */
 18      procedure (stream_name, prt, device, mode, iostatus, sdb_ptr);
 19 
 20 dcl  stream_name char (*),                                  /* name of IO stream */
 21      prt char (*),                                          /* name of DIM being attached */
 22      device char (*),                                       /* printer device name */
 23      mode char (*),                                         /* attachment mode */
 24      iostatus bit (72) aligned;                             /* IOS status */
 25 
 26 dcl  area_ptr ptr,                                          /* pointer to system free area */
 27      listen_based_area area ((16374)) based (area_ptr),     /* area in which to allocate sdb */
 28      wksp_max fixed bin (19),                               /* max size of IOI workspace buffer */
 29      time_max fixed bin (52),                               /* max time for IOI connect to complete */
 30      rcp_state fixed bin,                                   /* state variable from check_attach */
 31      rcode fixed bin (35);                                  /* error code */
 32 
 33 dcl  get_system_free_area_ entry (ptr),
 34      ipc_$create_ev_chn entry (fixed bin (71), fixed bin (35)),
 35      ipc_$block entry (ptr, ptr, fixed bin (35)),
 36      ipc_$delete_ev_chn entry (fixed bin (71), fixed bin (35)),
 37      convert_ipc_code_ entry (fixed bin (35)),
 38      rcp_$attach entry (char (*), ptr, fixed bin (71), char (*), bit (36) aligned, fixed bin (35)),
 39      rcp_$check_attach entry (bit (36) aligned, ptr, char (*), fixed bin, fixed bin (19), fixed bin (52),
 40      fixed bin, fixed bin (35)),
 41      ioi_$workspace entry (fixed bin, ptr, fixed bin (18), fixed bin (35)),
 42      rcp_$detach entry (bit (36) aligned, bit (*), fixed bin, char (*), fixed bin (35)),
 43      prtdim_util$init entry (ptr, fixed bin (35)),
 44      prtdim_util$load_vfc entry (ptr, fixed bin (35));
 45 
 46 
 47 
 48 /* ^L */
 49 
 50 dcl  error_table_$ionmat fixed bin (35) ext,
 51      error_table_$no_room_for_dsb fixed bin (35) ext,
 52      error_table_$no_operation fixed bin (35) ext,
 53      config_deck$ ext;
 54 
 55 dcl 1 rcp_info like printer_info aligned auto;              /* automatic copy of RCP info structure */
 56 
 57 dcl 1 ipc_message aligned,
 58     2 chname fixed bin (71),                                /* Chan over which message arrived */
 59     2 message fixed bin (71),                               /* 2-word event message */
 60     2 sender bit (36),                                      /* Sending process */
 61     2 origin,                                               /* Origin of event message */
 62       3 devsignal bit (18),                                 /* 1 = device signal */
 63       3 ring bit (18),                                      /* Senders ring number */
 64     2 channel_index fixed bin;
 65 
 66 dcl (addr, null, ptr, substr, unspec) builtin;
 67 
 68 
 69 /* ^L */
 70 
 71 % include prt_sdb;
 72 
 73 
 74 /* ^L */
 75 
 76 % include rcp_printer_info;
 77 
 78 % include prt_info;
 79 
 80 
 81 /* ^L */
 82 
 83 % include prt_conv_info;
 84 
 85 /* ^L */
 86 
 87 % include iom_pcw;
 88 
 89 /* ^L */
 90 
 91           iostatus = "0"b;                                  /* Clear returned status. */
 92           if sdb_ptr ^= null () then do;                    /* Check for multiple attachments */
 93                substr (iostatus, 1, 36) = unspec (error_table_$ionmat); /* If multiple attachment return code */
 94                go to exit;
 95           end;                                              /* End sdb_ptr not null do group */
 96 
 97           call get_system_free_area_ (area_ptr);            /* Get ptr to area in listen_ before alloc */
 98           allocate sdb in (listen_based_area) set (sdb_ptr); /* Create stream data block */
 99           if sdb_ptr = null then do;                        /* If this - then no room for sdb */
100                substr (iostatus, 1, 36) = unspec (error_table_$no_room_for_dsb); /* Send message */
101                go to exit;                                  /* Exit */
102           end;                                              /* End sdb_ptr null do group */
103 
104           sdb.areap = area_ptr;                             /* Save pointer to free area. */
105 
106           outer_module_name = prt;                          /* Put name this outer module in sdb */
107           device_name_list_ptr = addr (sdb.device_name);    /* Set pointer */
108           next_device_ptr = null;                           /* Only one device allowed */
109           name_size = 32;                                   /* Set name size */
110           name = device;                                    /* Put attached device name in sdb */
111           sdb.stream_name = stream_name;                    /* record the name of this attachment */
112 
113           call ipc_$create_ev_chn (evchan, rcode);          /* Create event channel so that the supervisor
114                                                                knows who to wake when we are blocked */
115           if rcode ^= 0 then do;
116                call convert_ipc_code_ (rcode);
117                go to free1;
118           end;
119           ev_list.count = 1;                                /* Set count in event list. */
120 
121           pip = addr (sdb.info);                            /* Get pointer to printer info. */
122           prt_info.devname = name;                          /* Set device name in structure. */
123 
124           printer_info_ptr = addr (rcp_info);               /* Get pointer to RCP info for printer. */
125           rcp_info.version_num = 1;                         /* Set up the RCP info structure. */
126           rcp_info.usage_time = 0;                          /* Don't know how long we'll use printer. */
127           rcp_info.wait_time = 0;                           /* We are not willing to wait. */
128           rcp_info.system_flag = "0"b;                      /* Not system process. */
129           rcp_info.device_name = name;                      /* Set device name. */
130 
131           call rcp_$attach ("printer", printer_info_ptr, evchan, "", rcp_id, rcode);
132           if rcode ^= 0 then go to free;                    /* Attempt to attach the printer. */
133 
134 check:    call rcp_$check_attach (rcp_id, printer_info_ptr, "", prt_info.devx, wksp_max, time_max,
135                rcp_state, rcode);                           /* Check on progress of attachment. */
136           if rcode ^= 0 then go to free;
137 
138           go to attach_state (rcp_state);                   /* Dispatch on state variable. */
139 
140 attach_state (1):                                           /* Short wait needed */
141           call ipc_$block (addr (sdb.ev_list), addr (ipc_message), rcode);
142           if rcode ^= 0 then do;                            /* Wait for attachment to complete. */
143                call convert_ipc_code_ (rcode);
144                go to free;
145           end;
146           go to check;                                      /* Perform check again. */
147 
148 attach_state (2):                                           /* long wait */
149 attach_state (3):                                           /* error occurrence */
150           go to free;                                       /* This is an error condition. */
151 
152 attach_state (0):                                           /* Successful attachment */
153           prt_info.model = rcp_info.model;                  /* Extract info from RCP info structure. */
154           prt_info.train = rcp_info.print_train;
155           prt_info.line_length = rcp_info.line_length;
156 
157           call ioi_$workspace (prt_info.devx, wsegp, 1024, rcode); /* To wire down space for DCW list */
158           if rcode ^= 0 then go to free;                    /* Check error code */
159 
160           call prtdim_util$init (sdb_ptr, rcode);           /* Initialize printer information. */
161           if rcode ^= 0 then go to free;                    /* If unable to initialize printer ... */
162 
163           if mode ^= "save_vfc" then do;                    /* are we to load a vfc now? */
164                call prtdim_util$load_vfc (sdb_ptr, rcode);  /* data is in  sdb.conv_info */
165                if rcode = error_table_$no_operation then rcode = 0;
166                else if rcode ^= 0 then go to free;          /* load error */
167           end;
168 
169           idcwp = addr (prt_info.print_idcw);               /* Get pointer to IDCW for printing. */
170           idcw.control = "10"b;                             /* Set continue bit in IDCW. */
171 
172           stop, bgin, prev = 0;                             /* Initialize DCW list pointers. */
173           wait_flag = "0"b;                                 /* Reset waiting for special flag. */
174           running = "0"b;                                   /* Indicate channel not running. */
175           marker_count = 0;                                 /* Clear the marker status counter. */
176           paper_low = "0"b;                                 /* Reset paper low flag. */
177           error_count = 0;                                  /* Clear the error counter. */
178           reload_vfc_train_after_special = "0"b;            /* Reset request to reload VFC/train after a special */
179           chars_printed = 0;
180 
181           return;                                           /* All finished. */
182 
183 /* ^L */
184 
185 free:
186 free1:    substr (iostatus, 1, 36) = unspec (rcode);        /* Return error code. */
187 
188           go to detach;                                     /* try to clean up, but retain this error code */
189                                                             /* Drop into normal detach code. */
190 
191 
192 prtdim_detach: entry (sdb_ptr, device, mode, iostatus);     /* Detach entry point */
193 
194           iostatus = "0"b;                                  /* clear the status code */
195 
196 detach:   call ipc_$delete_ev_chn (evchan, rcode);          /* Delete event channel */
197           if rcode ^= 0 then if substr (iostatus, 1, 36) = "0"b then do;
198                     call convert_ipc_code_ (rcode);
199                     substr (iostatus, 1, 36) = unspec (rcode);
200                end;
201 
202           pip = addr (sdb.info);                            /* Get pointer to info structure. */
203 
204           call rcp_$detach (rcp_id, "0"b, error_count, "", rcode);
205           if rcode ^= 0 then                                /* Attempt to detach the device. */
206                if substr (iostatus, 1, 36) = "0"b then      /* report error if none exists */
207                     substr (iostatus, 1, 36) = unspec (rcode); /* Put error code in return status */
208 
209           area_ptr = sdb.areap;                             /* Get pointer to area. */
210           free sdb in (listen_based_area);                  /* Free-up allocated sdb */
211 
212 exit:     substr (iostatus, 52, 1) = "1"b;                  /* Set ioname detached bit */
213           substr (iostatus, 41, 1) = "1"b;                  /* Set transaction terminated bit */
214           return;
215 
216 
217 
218 
219      end prtdim_attach;