First Commit of my working state
[simh.git] / H316 / h316_mt.c
1 /* h316_mt.c: H316/516 magnetic tape simulator
2
3 Copyright (c) 2003-2007, Robert M. Supnik
4
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of Robert M Supnik shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from Robert M Supnik.
25
26 mt 516-4100 seven track magnetic tape
27
28 09-Jun-07 RMS Fixed bug in write without stop (from Theo Engel)
29 16-Feb-06 RMS Added tape capacity checking
30 26-Aug-05 RMS Revised to use API for write lock check
31 08-Feb-05 RMS Fixed error reporting from OCP (found by Philipp Hachtmann)
32 01-Dec-04 RMS Fixed bug in DMA/DMC support
33
34 Magnetic tapes are represented as a series of variable records
35 of the form:
36
37 32b byte count
38 byte 0
39 byte 1
40 :
41 byte n-2
42 byte n-1
43 32b byte count
44
45 If the byte count is odd, the record is padded with an extra byte
46 of junk. File marks are represented by a byte count of 0.
47 */
48
49 #include "h316_defs.h"
50 #include "sim_tape.h"
51
52 #define MT_NUMDR 4 /* number of drives */
53 #define DB_N_SIZE 16 /* max data buf */
54 #define DBSIZE (1 << DB_N_SIZE) /* max data cmd */
55 #define FNC u3 /* function */
56 #define UST u4 /* unit status */
57
58 /* Function codes */
59
60 #define FNC_RBCD2 000
61 #define FNC_RBIN2 001
62 #define FNC_RBIN3 002
63 #define FNC_DMANM 003
64 #define FNC_WBCD2 004
65 #define FNC_WBIN2 005
66 #define FNC_WEOF 006
67 #define FNC_IOBUS 007
68 #define FNC_WBIN3 010
69 #define FNC_FSR 011
70 #define FNC_FSF 012
71 #define FNC_DMAAU 013
72 #define FNC_REW 014
73 #define FNC_BSR 015
74 #define FNC_BSF 016
75 #define FNC_STOPW 017
76 #define FNC_2ND 020 /* second state */
77 #define FNC_NOP (FNC_STOPW|FNC_2ND)
78 #define FNC_EOM 040 /* end of motion */
79
80 /* Status - unit.UST */
81
82 #define STA_BOT 0000002 /* beg of tape */
83 #define STA_EOT 0000001 /* end of tape */
84
85 extern int32 dev_int, dev_enb, chan_req;
86 extern int32 stop_inst;
87
88 uint32 mt_buf = 0; /* data buffer */
89 uint32 mt_usel = 0; /* unit select */
90 uint32 mt_busy = 0; /* ctlr busy */
91 uint32 mt_mdirq = 0; /* motion done int req */
92 uint32 mt_rdy = 0; /* transfer ready (int) */
93 uint32 mt_err = 0; /* error */
94 uint32 mt_eof = 0; /* end of file */
95 uint32 mt_eor = 0; /* transfer done */
96 uint32 mt_dma = 0; /* DMA/DMC */
97 uint32 mt_xtime = 16; /* transfer time */
98 uint32 mt_ctime = 3000; /* start/stop time */
99 uint32 mt_stopioe = 1; /* stop on I/O error */
100 uint8 mtxb[DBSIZE] = { 0 }; /* data buffer */
101 t_mtrlnt mt_ptr = 0, mt_max = 0; /* buffer ptrs */
102
103 int32 mtio (int32 inst, int32 fnc, int32 dat, int32 dev);
104 void mt_updint (uint32 rdy, uint32 mdone);
105 t_stat mt_svc (UNIT *uptr);
106 t_stat mt_reset (DEVICE *dptr);
107 t_stat mt_attach (UNIT *uptr, char *cptr);
108 t_stat mt_detach (UNIT *uptr);
109 t_stat mt_map_err (UNIT *uptr, t_stat st);
110 void mt_wrwd (UNIT *uptr, uint32 dat);
111
112 /* MT data structures
113
114 mt_dev MT device descriptor
115 mt_unit MT unit list
116 mt_reg MT register list
117 mt_mod MT modifier list
118 */
119
120 DIB mt_dib = { MT, IOBUS, MT_NUMDR, &mtio };
121
122 UNIT mt_unit[] = {
123 { UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
124 { UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
125 { UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
126 { UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) }
127 };
128
129 REG mt_reg[] = {
130 { ORDATA (BUF, mt_buf, 16) },
131 { ORDATA (USEL, mt_usel, 2) },
132 { FLDATA (BUSY, mt_busy, 0) },
133 { FLDATA (RDY, mt_rdy, 0) },
134 { FLDATA (ERR, mt_err, 0) },
135 { FLDATA (EOF, mt_eof, 0) },
136 { FLDATA (EOR, mt_eor, 0) },
137 { FLDATA (MDIRQ, mt_mdirq, 0) },
138 { FLDATA (DMA, mt_dma, 0) },
139 { FLDATA (INTREQ, dev_int, INT_V_MT) },
140 { FLDATA (ENABLE, dev_enb, INT_V_MT) },
141 { BRDATA (DBUF, mtxb, 8, 8, DBSIZE) },
142 { DRDATA (BPTR, mt_ptr, DB_N_SIZE + 1) },
143 { DRDATA (BMAX, mt_max, DB_N_SIZE + 1) },
144 { DRDATA (CTIME, mt_ctime, 24), REG_NZ + PV_LEFT },
145 { DRDATA (XTIME, mt_xtime, 24), REG_NZ + PV_LEFT },
146 { URDATA (POS, mt_unit[0].pos, 10, T_ADDR_W, 0, MT_NUMDR, PV_LEFT) },
147 { URDATA (FNC, mt_unit[0].FNC, 8, 8, 0, MT_NUMDR, REG_HRO) },
148 { URDATA (UST, mt_unit[0].UST, 8, 2, 0, MT_NUMDR, REG_HRO) },
149 { ORDATA (CHAN, mt_dib.chan, 5), REG_HRO },
150 { FLDATA (STOP_IOE, mt_stopioe, 0) },
151 { NULL }
152 };
153
154 MTAB mt_mod[] = {
155 { MTUF_WLK, 0, "write enabled", "WRITEENABLED", NULL },
156 { MTUF_WLK, MTUF_WLK, "write locked", "LOCKED", NULL },
157 { MTAB_XTD|MTAB_VUN, 0, "FORMAT", "FORMAT",
158 &sim_tape_set_fmt, &sim_tape_show_fmt, NULL },
159 { MTAB_XTD|MTAB_VUN, 0, "CAPACITY", "CAPACITY",
160 &sim_tape_set_capac, &sim_tape_show_capac, NULL },
161 { MTAB_XTD|MTAB_VDV, 0, NULL, "IOBUS",
162 &io_set_iobus, NULL, NULL },
163 { MTAB_XTD|MTAB_VDV, 0, NULL, "DMC",
164 &io_set_dmc, NULL, NULL },
165 { MTAB_XTD|MTAB_VDV, 0, NULL, "DMA",
166 &io_set_dma, NULL, NULL },
167 { MTAB_XTD|MTAB_VDV, 0, "CHANNEL", NULL,
168 NULL, &io_show_chan, NULL },
169 { 0 }
170 };
171
172 DEVICE mt_dev = {
173 "MT", mt_unit, mt_reg, mt_mod,
174 MT_NUMDR, 10, 31, 1, 8, 8,
175 NULL, NULL, &mt_reset,
176 NULL, &mt_attach, &mt_detach,
177 &mt_dib, DEV_DISABLE
178 };
179
180 /* IO routine */
181
182 int32 mtio (int32 inst, int32 fnc, int32 dat, int32 dev)
183 {
184 uint32 i, u = dev & 03;
185 UNIT *uptr = mt_dev.units + u;
186 static uint8 wrt_fnc[16] = { /* >0 = wr, 1 = chan op */
187 0, 0, 0, 0, 1, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0
188 };
189
190 switch (inst) { /* case on opcode */
191
192 case ioOCP:
193 mt_updint (mt_rdy, 0); /* clear motion intr */
194 mt_eof = 0; /* clear eof */
195 switch (fnc) { /* case on function */
196
197 case FNC_DMANM: /* set DMA/DMC */
198 case FNC_DMAAU:
199 mt_usel = u; /* save unit select */
200 if (mt_dib.chan) mt_dma = 1; /* set DMA if configured */
201 else mt_dma = 0;
202 break;
203
204 case FNC_IOBUS: /* set IOBUS */
205 mt_usel = u; /* save unit select */
206 mt_dma = 0;
207 break;
208
209 case FNC_STOPW: /* stop write */
210 mt_usel = u; /* save unit select */
211 mt_updint (0, mt_mdirq); /* clear ready */
212 if (wrt_fnc[uptr->FNC & 017] == 1) /* writing? */
213 mt_eor = 1; /* set transfer done */
214 break;
215
216 default: /* motion command */
217 if (mt_busy) return dat; /* nop if ctlr busy */
218 mt_eor = 0; /* clr transfer done */
219 mt_err = 0; /* clr error */
220 mt_usel = u; /* save unit select */
221 if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */
222 return (((mt_stopioe? SCPE_UNATT: SCPE_OK) << IOT_V_REASON) | dat);
223 if (sim_is_active (uptr)) return dat; /* nop if busy */
224 if (wrt_fnc[fnc] && sim_tape_wrp (uptr))
225 return ((STOP_MTWRP << IOT_V_REASON) | dat);
226 uptr->FNC = fnc;
227 uptr->UST = 0;
228 mt_busy = 1;
229 for (i = 0; i < MT_NUMDR; i++) /* clear all EOT flags */
230 mt_unit[i].UST = mt_unit[i].UST & ~STA_EOT;
231 sim_activate (uptr, mt_ctime); /* schedule */
232 break;
233 }
234 break;
235
236 case ioINA: /* INA */
237 if (fnc) return IOBADFNC (dat); /* fnc 0 only */
238 if (mt_rdy) { /* ready? */
239 mt_rdy = 0; /* clear ready */
240 return IOSKIP (dat | mt_buf); /* ret buf, skip */
241 }
242 break;
243
244 case ioOTA: /* OTA */
245 if (fnc) return IOBADFNC (dat); /* fnc 0 only */
246 if (mt_rdy) { /* ready? */
247 mt_rdy = 0; /* clear ready */
248 mt_buf = dat; /* store buf */
249 return IOSKIP (dat); /* skip */
250 }
251 break;
252
253 case ioSKS:
254 uptr = mt_dev.units + mt_usel; /* use saved unit sel */
255 switch (fnc) {
256
257 case 000: /* ready */
258 if (mt_rdy) return IOSKIP (dat);
259 break;
260
261 case 001: /* !busy */
262 if (!mt_busy) return IOSKIP (dat);
263 break;
264
265 case 002: /* !error */
266 if (!mt_err) return IOSKIP (dat);
267 break;
268
269 case 003: /* !BOT */
270 if (!(uptr->UST & STA_BOT)) return IOSKIP (dat);
271 break;
272
273 case 004: /* !interrupting */
274 if (!TST_INTREQ (INT_MT)) return IOSKIP (dat);
275 break;
276
277 case 005: /* !EOT */
278 if (!(uptr->UST & STA_EOT)) return IOSKIP (dat);
279 break;
280
281 case 006: /* !EOF */
282 if (!mt_eof) return IOSKIP (dat);
283 break;
284
285 case 007: /* !write prot */
286 if (!sim_tape_wrp (uptr)) return IOSKIP (dat);
287 break;
288
289 case 011: /* operational */
290 if ((uptr->flags & UNIT_ATT) &&
291 ((uptr->FNC & 017) != FNC_REW)) return IOSKIP (dat);
292 break;
293
294 case 012: /* skip if !chan 2 */
295 return IOSKIP (dat);
296
297 case 013: /* skip if !auto */
298 return IOSKIP (dat);
299
300 case 014: /* !rewinding */
301 uptr = mt_dev.units + (dev & 03); /* use specified unit */
302 if ((uptr->FNC & 017) != FNC_REW) return IOSKIP (dat);
303 break;
304 }
305 break;
306
307 case ioEND: /* end of range */
308 mt_eor = 1; /* transfer done */
309 break;
310 }
311
312 return dat;
313 }
314
315 /* Unit service
316
317 If rewind done, reposition to start of tape, set status
318 else, do operation, set done, interrupt
319
320 Can't be write locked, can only write lock detached unit
321 */
322
323 t_stat mt_svc (UNIT *uptr)
324 {
325 int32 ch = mt_dib.chan - 1; /* DMA/DMC ch */
326 uint32 i, c1, c2, c3;
327 t_mtrlnt tbc;
328 t_bool passed_eot;
329 t_stat st, r = SCPE_OK;
330
331 if ((uptr->flags & UNIT_ATT) == 0) { /* offline? */
332 mt_err = 1;
333 mt_busy = 0;
334 mt_updint (0, 1); /* cmd done */
335 return IORETURN (mt_stopioe, SCPE_UNATT);
336 }
337
338 passed_eot = sim_tape_eot (uptr); /* passed EOT? */
339 switch (uptr->FNC) { /* case on function */
340
341 case FNC_REW: /* rewind (initial) */
342 mt_busy = 0; /* ctlr not busy */
343 uptr->FNC = uptr->FNC | FNC_2ND;
344 sim_activate (uptr, mt_ctime);
345 return SCPE_OK; /* continue */
346
347 case FNC_REW | FNC_2ND: /* rewind done */
348 uptr->pos = 0; /* reposition file */
349 uptr->UST = STA_BOT; /* set BOT */
350 uptr->FNC = FNC_NOP; /* nop function */
351 for (i = 0; i < MT_NUMDR; i++) { /* last rewind? */
352 if ((mt_unit[i].FNC & 017) == FNC_REW) return SCPE_OK;
353 }
354 mt_updint (mt_rdy, 1); /* yes, motion done */
355 return SCPE_OK;
356
357 case FNC_WEOF: /* write file mark */
358 if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */
359 r = mt_map_err (uptr, st); /* map error */
360 break; /* sched end motion */
361
362 case FNC_FSR: /* space fwd rec */
363 if (st = sim_tape_sprecf (uptr, &tbc)) /* space fwd, err? */
364 r = mt_map_err (uptr, st); /* map error */
365 break; /* sched end motion */
366
367 case FNC_BSR: /* space rev rec */
368 if (st = sim_tape_sprecr (uptr, &tbc)) /* space rev, err? */
369 r = mt_map_err (uptr, st); /* map error */
370 break; /* sched end motion */
371
372 case FNC_FSF: /* space fwd file */
373 while ((st = sim_tape_sprecf (uptr, &tbc)) == MTSE_OK) ;
374 r = mt_map_err (uptr, st); /* map error */
375 break; /* sched end motion */
376
377 case FNC_BSF: /* space rev file */
378 while ((st = sim_tape_sprecr (uptr, &tbc)) == MTSE_OK) ;
379 r = mt_map_err (uptr, st); /* map error */
380 break; /* sched end motion */
381
382 case FNC_EOM: /* end of motion */
383 uptr->FNC = FNC_NOP; /* nop function */
384 mt_busy = 0; /* not busy */
385 mt_updint (mt_rdy, 1); /* end of motion */
386 return SCPE_OK; /* done! */
387
388 case FNC_RBCD2: case FNC_RBIN2: case FNC_RBIN3: /* read first */
389 mt_ptr = 0; /* clr buf ptr */
390 st = sim_tape_rdrecf (uptr, mtxb, &mt_max, DBSIZE); /* read rec */
391 if (st != MTSE_OK) { /* error? */
392 r = mt_map_err (uptr, st); /* map error */
393 break; /* sched end motion */
394 }
395 uptr->FNC = uptr->FNC | FNC_2ND; /* next state */
396 sim_activate (uptr, mt_xtime); /* sched xfer */
397 return SCPE_OK;
398
399 case FNC_RBCD2 | FNC_2ND: /* read, word */
400 case FNC_RBIN2 | FNC_2ND:
401 case FNC_RBIN3 | FNC_2ND:
402 if (mt_ptr >= mt_max) break; /* record done? */
403 c1 = mtxb[mt_ptr++] & 077; /* get 2 chars */
404 c2 = mtxb[mt_ptr++] & 077;
405 if (uptr->FNC == (FNC_RBCD2 | FNC_2ND)) { /* BCD? */
406 if (c1 == 012) c1 = 0; /* change 12 to 0 */
407 if (c2 == 012) c2 = 0;
408 }
409 if (uptr->FNC == (FNC_RBIN3 | FNC_2ND)) { /* read 3? */
410 if (mt_ptr >= mt_max) break; /* lose wd if not enuf */
411 c3 = mtxb[mt_ptr++] & 017; /* get 3rd char */
412 }
413 else c3 = 0;
414 sim_activate (uptr, mt_xtime); /* no, sched word */
415 if (mt_eor) return SCPE_OK; /* xfer done? */
416 mt_buf = (c1 << 10) | (c2 << 4) | c3; /* pack chars */
417 if (mt_rdy) mt_err = 1; /* buf full? err */
418 mt_updint (1, mt_mdirq); /* set ready */
419 if (mt_dma) SET_CH_REQ (ch); /* DMC/DMA? req chan */
420 return SCPE_OK; /* continue */
421
422 case FNC_WBCD2: case FNC_WBIN2: case FNC_WBIN3: /* write first */
423 mt_ptr = 0; /* clear buf ptr */
424 mt_updint (1, mt_mdirq); /* set ready */
425 if (mt_dma) SET_CH_REQ (ch); /* DMC/DMA? req chan */
426 uptr->FNC = uptr->FNC | FNC_2ND; /* next state */
427 sim_activate (uptr, mt_xtime); /* sched xfer */
428 return SCPE_OK; /* continue */
429
430 case FNC_WBCD2 | FNC_2ND: /* write, word */
431 case FNC_WBIN2 | FNC_2ND:
432 case FNC_WBIN3 | FNC_2ND:
433 if (mt_eor || mt_rdy) { /* done or no data? */
434 if (!mt_rdy) mt_wrwd (uptr, mt_buf); /* write last word */
435 else mt_rdy = 0; /* rdy must be clr */
436 if (mt_ptr) { /* any data? */
437 if (st = sim_tape_wrrecf (uptr, mtxb, mt_ptr)) /* write, err? */
438 r = mt_map_err (uptr, st); /* map error */
439 }
440 break; /* sched end motion */
441 }
442 mt_wrwd (uptr, mt_buf); /* write word */
443 sim_activate (uptr, mt_xtime); /* no, sched word */
444 mt_updint (1, mt_mdirq); /* set ready */
445 if (mt_dma) SET_CH_REQ (ch); /* DMC/DMA? req chan */
446 return SCPE_OK; /* continue */
447
448 default: /* unknown */
449 break;
450 }
451
452 /* End of command, process error or schedule end of motion */
453
454 if (!passed_eot && sim_tape_eot (uptr)) /* just passed EOT? */
455 uptr->UST = uptr->UST | STA_EOT;
456 if (r != SCPE_OK) {
457 uptr->FNC = FNC_NOP; /* nop function */
458 mt_busy = 0; /* not busy */
459 mt_updint (mt_rdy, 1); /* end of motion */
460 return r;
461 }
462 uptr->FNC = FNC_EOM; /* sched end motion */
463 sim_activate (uptr, mt_ctime);
464 return SCPE_OK;
465 }
466
467 /* Write word to buffer */
468
469 void mt_wrwd (UNIT *uptr, uint32 dat)
470 {
471 uint32 c1, c2;
472
473 c1 = (dat >> 10) & 077; /* get 2 chars */
474 c2 = (dat >> 4) & 077;
475 if (uptr->FNC == (FNC_WBCD2 | FNC_2ND)) { /* BCD? */
476 if (c1 == 0) c1 = 012; /* change 0 to 12 */
477 if (c2 == 0) c2 = 012;
478 }
479 if (mt_ptr < DBSIZE) mtxb[mt_ptr++] = c1; /* store 2 char */
480 if (mt_ptr < DBSIZE) mtxb[mt_ptr++] = c2;
481 if ((uptr->FNC == (FNC_WBIN3 | FNC_2ND)) && /* write 3? */
482 (mt_ptr < DBSIZE)) mtxb[mt_ptr++] = mt_buf & 017;
483 return;
484 }
485
486 /* Map tape error status */
487
488 t_stat mt_map_err (UNIT *uptr, t_stat st)
489 {
490 switch (st) {
491
492 case MTSE_FMT: /* illegal fmt */
493 case MTSE_UNATT: /* unattached */
494 mt_err = 1; /* reject */
495 case MTSE_OK: /* no error */
496 return SCPE_IERR; /* never get here! */
497
498 case MTSE_TMK: /* end of file */
499 mt_eof = 1; /* eof */
500 break;
501
502 case MTSE_INVRL: /* invalid rec lnt */
503 mt_err = 1;
504 return SCPE_MTRLNT;
505
506 case MTSE_IOERR: /* IO error */
507 mt_err = 1; /* error */
508 if (mt_stopioe) return SCPE_IOERR;
509 break;
510
511 case MTSE_RECE: /* record in error */
512 case MTSE_EOM: /* end of medium */
513 mt_err = 1; /* error */
514 break;
515
516 case MTSE_BOT: /* reverse into BOT */
517 uptr->UST = STA_BOT; /* set status */
518 break;
519
520 case MTSE_WRP: /* write protect */
521 mt_err = 1; /* error */
522 return STOP_MTWRP;
523 }
524
525 return SCPE_OK;
526 }
527
528 /* Update interrupts */
529
530 void mt_updint (uint32 rdy, uint32 mdirq)
531 {
532 mt_rdy = rdy; /* store new ready */
533 mt_mdirq = mdirq; /* store new motion irq */
534 if ((mt_rdy && !mt_dma) || mt_mdirq) SET_INT (INT_MT); /* update int request */
535 else CLR_INT (INT_MT);
536 return;
537 }
538
539 /* Reset routine */
540
541 t_stat mt_reset (DEVICE *dptr)
542 {
543 int32 i;
544 UNIT *uptr;
545
546 mt_buf = 0; /* clear state */
547 mt_usel = 0;
548 mt_mdirq = 0;
549 mt_eor = 0;
550 mt_busy = 0;
551 mt_rdy = 0;
552 mt_eof = 0;
553 mt_err = 0;
554 mt_dma = 0;
555 CLR_INT (INT_MT); /* clear int, enb */
556 CLR_ENB (INT_MT);
557 for (i = 0; i < MT_NUMDR; i++) { /* loop thru units */
558 uptr = mt_dev.units + i;
559 sim_tape_reset (uptr); /* reset tape */
560 sim_cancel (uptr); /* cancel op */
561 uptr->UST = uptr->pos? 0: STA_BOT; /* update status */
562 uptr->FNC = FNC_NOP;
563 }
564 return SCPE_OK;
565 }
566
567 /* Attach routine */
568
569 t_stat mt_attach (UNIT *uptr, char *cptr)
570 {
571 t_stat r;
572
573 r = sim_tape_attach (uptr, cptr); /* attach unit */
574 if (r != SCPE_OK) return r; /* update status */
575 uptr->UST = STA_BOT;
576 return r;
577 }
578
579 /* Detach routine */
580
581 t_stat mt_detach (UNIT* uptr)
582 {
583 uptr->UST = 0; /* update status */
584 uptr->FNC = FNC_NOP; /* nop function */
585 return sim_tape_detach (uptr); /* detach unit */
586 }