-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathi7000_mt.c
1414 lines (1303 loc) · 48.6 KB
/
i7000_mt.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* i7090_mt.c: IBM 7090 Magnetic tape controller
Copyright (c) 2005-2016, Richard Cornwell
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
RICHARD CORNWELL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Magnetic tapes are represented as a series of variable records
of the form:
32b byte count
byte 0
byte 1
:
byte n-2
byte n-1
32b byte count
If the byte count is odd, the record is padded with an extra byte
of junk. File marks are represented by a byte count of 0.
*/
#include "i7000_defs.h"
#include "sim_tape.h"
#ifndef NUM_DEVS_MT
#define NUM_DEVS_MT 0
#endif
#if (NUM_DEVS_MT > 0) || defined(MT_CHANNEL_ZERO)
#define BUFFSIZE (MAXMEMSIZE * CHARSPERWORD)
#define UNIT_MT(x) UNIT_ATTABLE | UNIT_DISABLE | UNIT_ROABLE | \
UNIT_S_CHAN(x)
#define MTUF_LDN (1 << MTUF_V_UF)
#define MTUF_ONLINE (1 << UNIT_V_UF_31)
/* in u3 is current frame of tape */
/* in u5 holds the commands */
#define MT_RDS 1
#define MT_RDSB 2
#define MT_WRS 3
#define MT_WRSB 4
#define MT_WEF 5
#define MT_BSR 6
#define MT_BSF 7
#define MT_REW 8
#define MT_SDN 9
#define MT_RUN 10
#define MT_SKIP 11 /* Do skip to end of record */
#define MT_WRITE 12 /* Actual transfer operation */
#define MT_SKR 13
#define MT_ERG 14
#define MT_RDB 15
#define MT_LREW 16 /* Low speed rewind */
#define MT_HREW 17 /* High speed rewind */
#define MT_CMDMSK 000037 /* Command being run */
#define MT_RDY 000040 /* Device is ready for command */
#define MT_IDLE 000100 /* Tape still in motion */
#define MT_MARK 000200 /* Hit tape mark */
#define MT_EOT 000400 /* At End Of Tape */
#define MT_RM 001000 /* Hit a record mark character */
#define MT_EOR 002000 /* Set EOR on next record */
#define MT_UNLOAD 004000 /* Unload when rewind done */
#define MT_EGAP 010000 /* Write extended gap on next write */
#define MT_LWR 020000 /* Last command was a write */
#define MT_CLRIND 040000 /* On I7010 flag for SKR to clear indicator */
/* u6 holds the current buffer position */
/* Flags for mt_chan */
#define MTC_SEL 0020 /* Controller executing read/write */
#define MTC_BSY 0040 /* Controller is busy - executing cmd */
#define MTC_UNIT 0017 /* device Channel is on */
/* Timing for tape */
#define IPS 75 /* Inches per second 75 or 112 */
#define HS_IPS 500 /* High speed rewind Inches per second */
#define LD 300
#define HD 150
#define LT_GAP_LEN ((3 * LD)/ 4) /* Gap length for low density */
#define HT_GAP_LEN ((3 * HD)/ 4) /* Gap length for high density */
#define LT (1000000/(LD * IPS)) /* Time per char low density */
#define HT (1000000/(HD * IPS)) /* Time per char high density */
#define LT_GAP_TIM (LT_GAP_LEN * LT) /* Time per char low density */
#define HT_GAP_TIM (HT_GAP_LEN * HT) /* Time per char high density */
/* Normal frame time */
#define T1 ((uptr->flags & MTUF_LDN) ?LT:HT)
#define T1_us us_to_ticks(T1)
/* Gap time */
#define T2 ((uptr->flags & MTUF_LDN) ?LT_GAP_TIM:HT_GAP_TIM)
#define T2_us us_to_ticks(T2)
/* Start time */
#define T3 (((uptr->flags & MTUF_LDN) ?LT_GAP_TIM:HT_GAP_TIM) + 500)
#define T3_us us_to_ticks(T3)
#define GAP_LEN ((uptr->flags & MTUF_LDN) ?LT_GAP_LEN:HT_GAP_LEN)
/* Definitions */
uint32 mt_cmd(UNIT *, uint16, uint16);
t_stat mt_srv(UNIT *);
t_stat mt_boot(int32, DEVICE *);
void mt_ini(UNIT *, t_bool);
t_stat mt_reset(DEVICE *);
t_stat mt_attach(UNIT *, CONST char *);
t_stat mt_detach(UNIT *);
t_stat mt_rew(UNIT * uptr, int32 val, CONST char *cptr,
void *desc);
t_stat mt_tape_density(UNIT * uptr, int32 val, CONST char *cptr,
void *desc);
t_stat mt_help (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag,
const char *cptr);
const char *mt_description (DEVICE *dptr);
extern t_stat chan_boot(int32, DEVICE *);
#ifdef I7010
extern uint8 chan_io_status[NUM_CHAN]; /* Channel status */
#endif
#ifdef MT_CHANNEL_ZERO
#define NUM_DEVS (NUM_DEVS_MT + 1)
#else
#define NUM_DEVS (NUM_DEVS_MT)
#endif
/* Channel level activity */
uint8 mt_chan[NUM_CHAN];
/* One buffer per channel */
uint8 mt_buffer[NUM_DEVS][BUFFSIZE];
UNIT mta_unit[] = {
/* Controller 1 */
#if (NUM_DEVS_MT > 0)
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 0 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 1 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 2 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 3 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 4 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 5 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 6 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 7 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 8 */
{UDATA(&mt_srv, UNIT_MT(1), 0), 0}, /* 9 */
#if (NUM_DEVS_MT > 1)
/* Controller 2 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 0 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 1 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 2 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 3 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 4 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 5 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 6 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 7 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 8 */
{UDATA(&mt_srv, UNIT_MT(2), 0), 0}, /* 9 */
#if (NUM_DEVS_MT > 2)
/* Controller 3 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 0 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 1 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 2 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 3 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 4 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 5 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 6 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 7 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 8 */
{UDATA(&mt_srv, UNIT_MT(3), 0), 0}, /* 9 */
#if (NUM_DEVS_MT > 3)
/* Controller 4 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 0 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 1 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 2 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 3 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 4 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 5 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 6 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 7 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 8 */
{UDATA(&mt_srv, UNIT_MT(4), 0), 0}, /* 9 */
#if (NUM_DEVS_MT > 4)
/* Controller 5 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 0 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 1 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 2 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 3 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 4 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 5 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 6 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 7 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 8 */
{UDATA(&mt_srv, UNIT_MT(5), 0), 0}, /* 9 */
#if (NUM_DEVS_MT > 5)
/* Controller 6 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 0 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 1 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 2 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 3 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 4 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 5 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 6 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 7 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 8 */
{UDATA(&mt_srv, UNIT_MT(6), 0), 0}, /* 9 */
#endif
#endif
#endif
#endif
#endif
#endif
#ifdef MT_CHANNEL_ZERO
/* Controller 7 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 0 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 1 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 2 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 3 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 4 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 5 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 6 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 7 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 8 */
{UDATA(&mt_srv, UNIT_MT(0), 0), 0}, /* 9 */
#endif
};
MTAB mt_mod[] = {
{ MTAB_XTD|MTAB_VUN, 0, "write enabled", "WRITEENABLED",
&set_writelock, &show_writelock, NULL, "Write ring in place" },
{ MTAB_XTD|MTAB_VUN, 1, NULL, "LOCKED",
&set_writelock, NULL, NULL, "no Write ring in place" },
{MTUF_LDN, 0, "high density", "HIGH", &mt_tape_density, NULL, NULL,
"556 BPI"},
{MTUF_LDN, MTUF_LDN, "low density", "LOW", &mt_tape_density, NULL, NULL,
"200 BPI"},
#ifdef I7090
{MTUF_ONLINE, 0, "offline", "OFFLINE", NULL, NULL, NULL,
"Tape offline"},
{MTUF_ONLINE, MTUF_ONLINE, "online", "ONLINE", NULL, NULL, NULL,
"Tape Online"},
#endif
{MTAB_XTD | MTAB_VUN, 0, "FORMAT", "FORMAT",
&sim_tape_set_fmt, &sim_tape_show_fmt, NULL,
"Set/Display tape format (SIMH, E11, TPC, P7B)"},
{MTAB_XTD | MTAB_VUN, 0, "LENGTH", "LENGTH",
&sim_tape_set_capac, &sim_tape_show_capac, NULL,
"Set unit n capacity to arg MB (0 = unlimited)" },
{MTAB_XTD | MTAB_VUN, 0, NULL, "REWIND",
&mt_rew, NULL, NULL, "Rewind tape"
},
#ifdef I7090
{MTAB_XTD | MTAB_VDV | MTAB_VALR, 0, "CHAN", "CHAN", &set_chan, &get_chan,
NULL, "Device Channel"},
#endif
{0}
};
#ifdef MT_CHANNEL_ZERO
DEVICE mtz_dev = {
"MT", &mta_unit[NUM_DEVS_MT * 10], NULL, mt_mod,
NUM_UNITS_MT, 8, 15, 1, 8, 8,
NULL, NULL, &mt_reset, &mt_boot, &mt_attach, &mt_detach,
&mt_dib, DEV_BUF_NUM(NUM_DEVS_MT) | DEV_DISABLE | DEV_DEBUG | DEV_TAPE, 0, dev_debug,
NULL, NULL, &mt_help, NULL, NULL, &mt_description
};
#endif
#if (NUM_DEVS_MT > 0)
DEVICE mta_dev = {
"MTA", mta_unit, NULL, mt_mod,
NUM_UNITS_MT, 8, 15, 1, 8, 8,
NULL, NULL, &mt_reset, &mt_boot, &mt_attach, &mt_detach,
&mt_dib, DEV_BUF_NUM(0) | DEV_DISABLE | DEV_DEBUG | DEV_TAPE, 0, dev_debug,
NULL, NULL, &mt_help, NULL, NULL, &mt_description
};
#if (NUM_DEVS_MT > 1)
DEVICE mtb_dev = {
"MTB", &mta_unit[10], NULL, mt_mod,
NUM_UNITS_MT, 8, 15, 1, 8, 8,
NULL, NULL, &mt_reset, &mt_boot, &mt_attach, &mt_detach,
&mt_dib, DEV_BUF_NUM(1) | DEV_DISABLE | DEV_DEBUG | DEV_TAPE, 0, dev_debug,
NULL, NULL, &mt_help, NULL, NULL, &mt_description
};
#if (NUM_DEVS_MT > 2)
DEVICE mtc_dev = {
"MTC", &mta_unit[20], NULL, mt_mod,
NUM_UNITS_MT, 8, 15, 1, 8, 8,
NULL, NULL, &mt_reset, &mt_boot, &mt_attach, &mt_detach,
&mt_dib, DEV_BUF_NUM(2) | DEV_DISABLE | DEV_DEBUG | DEV_TAPE, 0, dev_debug,
NULL, NULL, &mt_help, NULL, NULL, &mt_description
};
#if (NUM_DEVS_MT > 3)
DEVICE mtd_dev = {
"MTD", &mta_unit[30], NULL, mt_mod,
NUM_UNITS_MT, 8, 15, 1, 8, 36,
NULL, NULL, &mt_reset, &mt_boot, &mt_attach, &mt_detach,
&mt_dib, DEV_BUF_NUM(3) | DEV_DISABLE | DEV_DEBUG | DEV_TAPE, 0, dev_debug,
NULL, NULL, &mt_help, NULL, NULL, &mt_description
};
#if (NUM_DEVS_MT > 4)
DEVICE mte_dev = {
"MTE", &mta_unit[40], NULL, mt_mod,
NUM_UNITS_MT, 8, 15, 1, 8, 8,
NULL, NULL, &mt_reset, &mt_boot, &mt_attach, &mt_detach,
&mt_dib, DEV_BUF_NUM(4) | DEV_DIS | DEV_DISABLE | DEV_DEBUG | DEV_TAPE, 0, dev_debug,
NULL, NULL, &mt_help, NULL, NULL, &mt_description
};
#if (NUM_DEVS_MT > 5)
DEVICE mtf_dev = {
"MTF", &mta_unit[50], NULL, mt_mod,
NUM_UNITS_MT, 8, 15, 1, 8, 8,
NULL, NULL, &mt_reset, &mt_boot, &mt_attach, &mt_detach,
&mt_dib, DEV_BUF_NUM(5) | DEV_DIS | DEV_DISABLE | DEV_DEBUG | DEV_TAPE, 0, dev_debug,
NULL, NULL, &mt_help, NULL, NULL, &mt_description
};
#endif
#endif
#endif
#endif
#endif
#endif
uint8 parity_table[64] = {
/* 0 1 2 3 4 5 6 7 */
0000, 0100, 0100, 0000, 0100, 0000, 0000, 0100,
0100, 0000, 0000, 0100, 0000, 0100, 0100, 0000,
0100, 0000, 0000, 0100, 0000, 0100, 0100, 0000,
0000, 0100, 0100, 0000, 0100, 0000, 0000, 0100,
0100, 0000, 0000, 0100, 0000, 0100, 0100, 0000,
0000, 0100, 0100, 0000, 0100, 0000, 0000, 0100,
0000, 0100, 0100, 0000, 0100, 0000, 0000, 0100,
0100, 0000, 0000, 0100, 0000, 0100, 0100, 0000
};
/* Rewind tape drive */
t_stat
mt_rew(UNIT * uptr, int32 val, CONST char *cptr, void *desc)
{
/* If drive is offline or not attached return not ready */
if ((uptr->flags & (UNIT_ATT | MTUF_ONLINE)) == 0)
return SCPE_NOATT;
/* Check if drive is ready to recieve a command */
if ((uptr->u5 & MT_RDY) == 0)
return STOP_IOCHECK;
return sim_tape_rewind(uptr);
}
/* Start off a mag tape command */
uint32 mt_cmd(UNIT * uptr, uint16 cmd, uint16 dev)
{
int chan = UNIT_G_CHAN(uptr->flags);
DEVICE *dptr = find_dev_from_unit(uptr);
int time = us_to_ticks(100);
int unit = dev & 017;
unit -= mt_dib.addr & 017; /* Adjust to origin zero */
if (unit == 10)
unit = 0;
/* Make sure valid drive number */
if (unit > NUM_UNITS_MT || unit < 0)
return SCPE_NODEV;
uptr += unit;
/* If unit disabled return error */
if (uptr->flags & UNIT_DIS) {
return SCPE_NODEV;
}
/* Check status of the drive */
/* Can't do nothing if controller is busy */
if (mt_chan[chan] & MTC_BSY) {
return SCPE_BUSY;
}
/* If drive is offline or not attached return not ready */
if ((uptr->flags & (UNIT_ATT | MTUF_ONLINE)) !=
(UNIT_ATT | MTUF_ONLINE)) {
sim_messagef(SCPE_OK, "Attempt to access offline unit %s%d\n\r", dptr->name, unit);
return SCPE_IOERR;
}
/* Check if drive is ready to recieve a command */
if ((uptr->u5 & MT_RDY) == 0) {
/* Return indication if not ready and doing TRS */
if (cmd == IO_TRS) {
return SCPE_IOERR;
} else {
return SCPE_BUSY;
}
}
uptr->u5 &= ~(MT_CMDMSK | MT_RDY);
time = us_to_ticks(12000);
if ((uptr->u5 & MT_IDLE) == 0)
time = us_to_ticks(15000);
switch (cmd) {
case IO_RDS:
if (sim_tape_bot(uptr))
time = us_to_ticks(21000);
if (mt_chan[chan] & MTC_SEL) {
uptr->u5 |= MT_RDY;
return SCPE_BUSY;
}
#ifdef I701
uptr->u5 |= MT_RDSB;
#else
if (dev & 020)
uptr->u5 |= MT_RDSB;
else
uptr->u5 |= MT_RDS;
#endif
chan_set_sel(chan, 0);
chan_clear_status(chan);
mt_chan[chan] = MTC_BSY | MTC_SEL | unit;
uptr->u5 &= ~(MT_RM|MT_EOR|MT_EGAP);
uptr->u6 = -1;
uptr->hwmark = -1;
#if I7010 | I7080
chan_set(chan, STA_TWAIT);
#endif
sim_debug(DEBUG_CMD, dptr, "RDS %s unit=%d %d\n",
((uptr->u5 & MT_CMDMSK) == MT_RDS) ? "BCD" : "Binary",
unit, dev);
break;
case IO_WRS:
if (sim_tape_bot(uptr))
time = us_to_ticks(40000);
if (mt_chan[chan] & MTC_SEL) {
uptr->u5 |= MT_RDY;
return SCPE_BUSY;
}
if (sim_tape_wrp(uptr)) {
sim_debug(DEBUG_EXP, dptr,
"WRS %d attempted on locked tape\n", unit);
uptr->u5 |= MT_RDY;
return SCPE_IOERR;
}
#ifdef I701
uptr->u5 |= MT_WRSB;
#else
if (dev & 020)
uptr->u5 |= MT_WRSB;
else
uptr->u5 |= MT_WRS;
#endif
time += T2_us;
uptr->u6 = 0;
uptr->hwmark = 0;
chan_set_sel(chan, 1);
chan_clear_status(chan);
mt_chan[chan] = MTC_BSY | MTC_SEL | unit;
uptr->u5 &= ~(MT_MARK | MT_EOT);
#if I7010 | I7080
chan_set(chan, STA_TWAIT);
#endif
sim_debug(DEBUG_CMD, dptr, "WRS %s unit=%d %d\n",
((uptr->u5 & MT_CMDMSK) == MT_WRS) ? "BCD" : "Binary",
unit, dev);
break;
case IO_RDB:
if (mt_chan[chan] & MTC_SEL) {
uptr->u5 |= MT_RDY;
return SCPE_BUSY;
}
uptr->u5 |= MT_RDB;
chan_set_sel(chan, 0);
chan_clear_status(chan);
mt_chan[chan] = MTC_BSY | MTC_SEL | unit;
uptr->u5 &= ~(MT_RM|MT_EOR|MT_EGAP);
uptr->u6 = -1;
uptr->hwmark = -1;
#if I7010 | I7080
chan_set(chan, STA_TWAIT);
#endif
sim_debug(DEBUG_CMD, dptr, "RDB unit=%d %d\n", unit, dev);
break;
case IO_WEF:
if (sim_tape_bot(uptr))
time = us_to_ticks(40000);
uptr->u5 &= ~(MT_EOT|MT_MARK);
if (sim_tape_wrp(uptr)) {
sim_debug(DEBUG_EXP, dptr,
"WRS %d attempted on locked tape\n", unit);
uptr->u5 |= MT_RDY;
return SCPE_IOERR;
}
uptr->u5 |= MT_WEF;
#if I7010
chan_set_sel(chan, 1);
chan_clear_status(chan);
mt_chan[chan] = MTC_BSY | MTC_SEL | unit;
chan_set(chan, STA_TWAIT);
#else
mt_chan[chan] = MTC_BSY;
#endif
sim_debug(DEBUG_CMD, dptr, "WEF unit=%d\n", unit);
break;
case IO_BSR:
uptr->u5 &= ~(MT_MARK);
/* Check if at load point, quick return if so */
if (sim_tape_bot(uptr)) {
sim_debug(DEBUG_CMD, dptr, "BSR unit=%d at BOT\n", unit);
uptr->u5 |= MT_RDY;
uptr->u3 = 0;
chan_set(chan, CHS_BOT);
return SCPE_OK;
}
uptr->u5 |= MT_BSR;
mt_chan[chan] = MTC_BSY;
sim_debug(DEBUG_CMD, dptr, "BSR unit=%d\n", unit);
break;
case IO_BSF:
uptr->u5 &= ~(MT_MARK);
/* Check if at load point, quick return if so */
if (sim_tape_bot(uptr)) {
sim_debug(DEBUG_CMD, dptr, "BSF unit=%d at BOT\n", unit);
uptr->u5 |= MT_RDY;
uptr->u3 = 0;
chan_set(chan, CHS_BOT);
return SCPE_OK;
}
uptr->u5 |= MT_BSF;
mt_chan[chan] = MTC_BSY;
sim_debug(DEBUG_CMD, dptr, "BSF unit=%d\n", unit);
break;
case IO_SKR:
if (sim_tape_bot(uptr))
time = us_to_ticks(21000);
uptr->u5 &= ~(MT_MARK|MT_EGAP);
uptr->u5 |= MT_SKR;
mt_chan[chan] = MTC_BSY;
sim_debug(DEBUG_CMD, dptr, "SKR unit=%d\n", unit);
break;
case IO_ERG:
sim_debug(DEBUG_CMD, dptr, "ERG unit=%d\n", unit);
#ifdef I7080
uptr->u5 &= ~(MT_MARK);
uptr->u5 |= MT_ERG;
mt_chan[chan] = MTC_BSY;
chan_set(chan, STA_TWAIT);
break;
#else
uptr->u5 |= MT_EGAP|MT_RDY; /* Command is quick */
return SCPE_OK;
#endif
case IO_REW:
uptr->u5 &= ~(MT_EOT|MT_MARK|MT_EGAP);
/* Check if at load point, quick return if so */
if (sim_tape_bot(uptr)) {
sim_debug(DEBUG_CMD, dptr, "REW unit=%d at BOT\n", unit);
uptr->u5 |= MT_RDY;
uptr->u3 = 0;
return SCPE_OK;
}
time = 1000;
uptr->u5 |= MT_REW;
mt_chan[chan] = MTC_BSY;
sim_debug(DEBUG_CMD, dptr, "REW unit=%d\n", unit);
sim_cancel(uptr);
sim_activate(uptr, time);
return SCPE_OK;
case IO_RUN:
uptr->u5 &= ~(MT_EOT|MT_MARK|MT_EGAP);
chan_clear_status(chan);
uptr->u5 |= MT_RUN;
mt_chan[chan] = MTC_BSY;
time = 1000;
sim_debug(DEBUG_CMD, dptr, "RUN unit=%d\n", unit);
sim_cancel(uptr);
sim_activate(uptr, time);
return SCPE_OK;
case IO_SDL:
uptr->u5 |= MT_RDY; /* Command is quick */
uptr->flags |= MTUF_LDN;
sim_tape_set_dens (uptr, MT_DENS_200, NULL, NULL);
sim_debug(DEBUG_CMD, dptr, "SDN unit=%d low\n", unit);
return SCPE_OK;
case IO_SDH:
uptr->u5 |= MT_RDY; /* Command is quick */
uptr->flags &= ~MTUF_LDN;
sim_tape_set_dens (uptr, MT_DENS_556, NULL, NULL);
sim_debug(DEBUG_CMD, dptr, "SDN unit=%d high\n", unit);
return SCPE_OK;
case IO_DRS:
uptr->flags &= ~MTUF_ONLINE;
uptr->u5 |= MT_RDY; /* Command is quick */
sim_debug(DEBUG_CMD, dptr, "DRS unit=%d\n", unit);
return SCPE_OK;
case IO_TRS:
uptr->u5 |= MT_RDY; /* Get here we are ready */
sim_debug(DEBUG_CMD, dptr, "TRS unit=%d\n", unit);
return SCPE_OK;
}
sim_cancel(uptr);
sim_activate(uptr, time);
return SCPE_OK;
}
#if I7090 | I704 | I701
/* Read a word from tape, used during boot read */
int
mt_read_buff(UNIT * uptr, int cmd, DEVICE * dptr, t_uint64 *word)
{
int chan = UNIT_G_CHAN(uptr->flags);
int bufnum = GET_DEV_BUF(dptr->flags);
int i;
uint8 ch;
int mode = 0;
int mark = 1;
int parity = 0;
uptr->u5 &= ~MT_MARK;
if (cmd == MT_RDS)
mode = 0100;
*word = 0;
for(i = CHARSPERWORD-1; i >= 0 && uptr->u6 < (int32)uptr->hwmark; i--) {
ch = mt_buffer[bufnum][uptr->u6++];
/* Do BCD translation */
if ((parity_table[ch & 077] ^ (ch & 0100) ^ mode) == 0) {
parity = 1;
}
ch &= 077;
/* Not needed on decimal machines */
if (mode) {
/* Map BCD to internal format */
ch ^= (ch & 020) << 1;
if (ch == 012)
ch = 0;
if (ch == 017 && mark) {
chan_set_error(chan); /* Force CRC error. */
ch = 0;
mark = 0;
uptr->u6++; /* Skip next character */
i--;
}
}
if (i >= 0)
*word |= ((t_uint64) ch) << (6 * i);
}
if (parity) {
chan_set_error(chan); /* Force redundency error */
return 0;
}
return 1;
}
#endif
/* Map simH errors into machine errors */
t_stat mt_error(UNIT * uptr, int chan, t_stat r, DEVICE * dptr)
{
switch (r) {
case MTSE_OK: /* no error */
break;
case MTSE_TMK: /* tape mark */
sim_debug(DEBUG_EXP, dptr, "MARK ");
chan_set_eof(chan);
break;
case MTSE_WRP: /* write protected */
case MTSE_UNATT: /* unattached */
sim_debug(DEBUG_EXP, dptr, "ATTENTION %d ", r);
chan_set_attn(chan);
break;
case MTSE_IOERR: /* IO error */
case MTSE_FMT: /* invalid format */
case MTSE_RECE: /* error in record */
chan_set_error(chan); /* Force redundency error */
chan_set_attn(chan); /* Set error */
sim_debug(DEBUG_EXP, dptr, "ERROR %d ", r);
break;
case MTSE_BOT: /* beginning of tape */
chan_set(chan, CHS_BOT); /* Set flag */
sim_debug(DEBUG_EXP, dptr, "BOT ");
break;
case MTSE_INVRL: /* invalid rec lnt */
case MTSE_EOM: /* end of medium */
uptr->u5 |= MT_EOT;
sim_debug(DEBUG_EXP, dptr, "EOT ");
#ifdef I7010
chan_set_attn(chan); /* Set error */
#endif
break;
}
return SCPE_OK;
}
/* Handle processing of tape requests. */
t_stat mt_srv(UNIT * uptr)
{
int chan = UNIT_G_CHAN(uptr->flags);
DEVICE *dptr = find_dev_from_unit(uptr);
int unit = (uptr - dptr->units) & MTC_UNIT;
int cmd = uptr->u5 & MT_CMDMSK;
int bufnum = GET_DEV_BUF(dptr->flags);
t_mtrlnt reclen;
t_stat r = SCPE_ARG; /* Force error if not set */
uint8 ch;
int mode = 0;
#ifdef I7010
extern uint8 astmode;
#endif
/* Call channel proccess to make sure data is ready */
chan_proc();
/* Channel has disconnected, abort current read. */
if ((mt_chan[chan] & 037) == (MTC_SEL | unit) &&
chan_test(chan, DEV_DISCO)) {
uptr->u5 &= ~MT_CMDMSK;
reclen = uptr->hwmark;
if (cmd == MT_WRS || cmd == MT_WRSB) {
if (uptr->u6 > 0) {
uptr->u3 += GAP_LEN;
sim_debug(DEBUG_DETAIL, dptr,
"Write flush unit=%d %s Block %d chars\n",
unit, (cmd == MT_WRS) ? "BCD" : "Binary", reclen);
r = sim_tape_wrrecf(uptr, &mt_buffer[bufnum][0], reclen);
mt_error(uptr, chan, r, dptr); /* Record errors */
}
} else if (cmd == MT_RDS || cmd == MT_RDSB) {
sim_debug(DEBUG_DETAIL, dptr,
"Read flush unit=%d %s at %d Block %d chars\n",
unit, (cmd == MT_RDS) ? "BCD" : "Binary", uptr->u6, reclen);
/* Keep moving until end of block */
if (uptr->u6 < (int32)reclen ) {
reclen -= uptr->u6;
uptr->u3 += reclen;
uptr->u5 |= MT_SKIP|MT_IDLE;
uptr->u6 = 0;
uptr->hwmark = 0;
chan_clear(chan, DEV_WEOR );
sim_activate(uptr, reclen * T1_us);
return SCPE_OK;
} else {
#ifndef I7010
if (uptr->u5 & MT_MARK) {
/* We hit tapemark, Back up so next read hits it */
/* Or write starts just before it */
/* This is due to SIMH returning mark after read */
(void) sim_tape_sprecr(uptr, &reclen);
uptr->u5 &= ~MT_MARK;
uptr->u3 -= GAP_LEN + reclen;
}
#endif
}
}
/* Allow time for tape to be restarted, before stop */
sim_activate(uptr, us_to_ticks(500));
uptr->u6 = 0;
uptr->hwmark = 0;
sim_debug(DEBUG_CHAN, dptr, "Disconnect unit=%d\n", unit);
uptr->u5 |= MT_IDLE|MT_RDY;
mt_chan[chan] = 0;
chan_clear(chan, DEV_DISCO | DEV_WEOR | DEV_SEL);
#if I7010 | I7080
chan_clear(chan, STA_TWAIT);
#endif
return SCPE_OK;
}
uptr->u5 &= ~MT_IDLE;
switch (cmd) {
case 0: /* No command, stop tape */
uptr->u5 |= MT_RDY; /* Ready since command is done */
mt_chan[chan] &= ~MTC_BSY;
sim_debug(DEBUG_DETAIL, dptr, "Idle unit=%d\n", unit);
return SCPE_OK;
case MT_SKIP: /* Record skip done, enable tape drive */
uptr->u5 &= ~MT_CMDMSK;
uptr->u5 |= MT_RDY | MT_IDLE;
#if I7090 | I704 | I701
chan_clear(chan, DEV_SEL);
#else
chan_clear(chan, DEV_SEL|STA_TWAIT);
#endif
mt_chan[chan] = 0;
sim_debug(DEBUG_DETAIL, dptr, "Skip unit=%d\n", unit);
/* Allow time for tape to be restarted, before stop */
sim_activate(uptr, us_to_ticks(500));
return SCPE_OK;
case MT_RDS:
mode = 0100;
/* Fall through */
case MT_RDSB:
uptr->u5 &= ~MT_LWR; /* Not write command */
/* Post EOR */
if (uptr->u5 & MT_EOR) {
sim_debug(DEBUG_DETAIL, dptr, "Read unit=%d post EOR\n", unit);
chan_set(chan, DEV_REOR);
uptr->u5 &= ~ MT_EOR;
sim_activate(uptr, T1_us);
return SCPE_OK;
}
/* If tape mark pending, return it */
if (chan_test(chan, DEV_FULL) == 0 && uptr->u5 & MT_MARK) {
sim_debug(DEBUG_DETAIL, dptr, "Read unit=%d post ", unit);
uptr->u5 &= ~(MT_CMDMSK|MT_MARK);
#ifdef I7010
if (astmode) {
ch = mode?017:054;
chan_write_char(chan, &ch, DEV_REOR);
if (mode) {
chan_clear(chan, STA_TWAIT);
sim_activate(uptr, us_to_ticks(100));
return SCPE_OK;
}
}
#endif
chan_set_attn(chan);
sim_activate(uptr, us_to_ticks(100));
return mt_error(uptr, chan, MTSE_TMK, dptr);
}
/* If at end of record, fill buffer */
if (uptr->u6 == (int32)uptr->hwmark) {
sim_debug(DEBUG_DETAIL, dptr, "Read unit=%d ", unit);
uptr->u3 += GAP_LEN;
if ((r = sim_tape_rdrecf(uptr, &mt_buffer[bufnum][0], &reclen,
BUFFSIZE)) != MTSE_OK) {
if (r == MTSE_TMK && uptr->u6 != -1) {
sim_debug(DEBUG_DETAIL, dptr, "pend TM\n");
uptr->u5 |= MT_MARK;
r = MTSE_OK;
} else {
sim_debug(DEBUG_DETAIL, dptr, "error=%d\n", r);
uptr->u5 &= ~MT_CMDMSK;
#ifdef I7010
/* Translate TM characters for 7010 */
if (r == MTSE_TMK && astmode) {
sim_debug(DEBUG_DETAIL, dptr, "Read TM ");
ch = mode?017:054;
chan_write_char(chan, &ch, 0);
chan_set_attn(chan);
chan_set(chan, DEV_REOR);
chan_clear(chan, STA_TWAIT);
if (mode) {
sim_activate(uptr, T1_us);
return SCPE_OK;
}
chan_set_error(chan);
}
#else
chan_set(chan, DEV_REOR);
chan_set_attn(chan);
#endif
}
sim_activate(uptr, T1_us);
return mt_error(uptr, chan, r, dptr);
}
uptr->u6 = 0;
uptr->hwmark = reclen;
chan_clear(chan, CHS_EOF|CHS_ERR);
sim_debug(DEBUG_DETAIL, dptr, "%s Block %d chars\n",
(cmd == MT_RDS) ? "BCD" : "Binary", reclen);
#ifdef I7010
if (mode && mt_buffer[bufnum][0] == 017)
chan_set_eof(chan);
#endif
}
ch = mt_buffer[bufnum][uptr->u6++];
uptr->u3++;
/* Do BCD translation */
if ((parity_table[ch & 077] ^ (ch & 0100) ^ mode) == 0) {
sim_debug(DEBUG_DETAIL, dptr, "%s parity error %d %03o\n",
(cmd == MT_RDS) ? "BCD" : "Binary", uptr->u6-1, ch);
#ifdef I7010
if (astmode)
ch = 054;
#endif
chan_set_error(chan);
}
#if I7090 | I704 | I701
/* Not needed on decimal machines */
if (mode) {
/* Map BCD to internal format */
ch ^= (ch & 020) << 1;
if (ch == 012)
ch = 0;
if (ch == 017) {
chan_set_error(chan); /* Force CRC error. */
if ((uptr->u5 & MT_RM) == 0) {
ch = 0;
uptr->u5 |= MT_RM;
mt_buffer[bufnum][uptr->u6] = 0;
}
}
}
#endif
#ifdef I7010
if (mode) {
if (ch == 0120)
ch = 0;
}
#endif
ch &= 077;
/* Convert one word. */
switch (chan_write_char(chan, &ch, 0)) {
case END_RECORD:
sim_debug(DEBUG_DATA, dptr, "Read unit=%d EOR\n", unit);
/* If not read whole record, skip till end */
uptr->u5 |= MT_EOR;
if (uptr->u6 < (int32)uptr->hwmark) {
sim_activate(uptr, (uptr->hwmark-uptr->u6) * T1_us);
uptr->u3 += (uptr->hwmark - uptr->u6);
uptr->u6 = uptr->hwmark; /* Force read next record */
}
sim_activate(uptr, T1_us);
break;
case DATA_OK:
sim_debug(DEBUG_DATA, dptr, "Read data unit=%d %d %02o\n",
unit, uptr->u6, ch);
if (uptr->u6 >= (int32)uptr->hwmark) /* In IRG */
uptr->u5 |= MT_EOR;
sim_activate(uptr, T1_us);
break;
case TIME_ERROR:
sim_debug(DEBUG_DATA, dptr, "Read unit=%d timeout\n", unit);
uptr->u3 += (uptr->hwmark - uptr->u6);
uptr->u5 &= ~MT_CMDMSK;
uptr->u5 |= MT_SKIP;
sim_activate(uptr, ((uptr->hwmark - uptr->u6) * T1_us) + T2_us);
uptr->u6 = uptr->hwmark; /* Force read next record */
break;
}
return SCPE_OK;
/* Check mode */
case MT_WRS:
mode = 0100;
/* fall through */
case MT_WRSB:
uptr->u5 |= MT_LWR; /* write command */
if (uptr->u5 & MT_EGAP) {
sim_debug(DEBUG_DETAIL, dptr, "Write extended Gap unit=%d\n", unit);
uptr->u5 &= ~MT_EGAP;
r = sim_tape_wrgap(uptr, 35);
sim_activate(uptr, 10*T3_us);
return SCPE_OK;
}
switch (chan_read_char(chan, &ch,
(uptr->u6 > BUFFSIZE) ? DEV_WEOR : 0)) {
case TIME_ERROR:
#if I7090 | I701 | I704
uptr->u5 &= ~MT_CMDMSK;
uptr->u5 |= MT_SKIP;
/* If no data was written, simulate a write gap */
if (uptr->u6 == 0) {
r = sim_tape_wrgap(uptr, 35);
if (r != MTSE_OK) {
mt_error(uptr, chan, r, dptr); /* Record errors */
return SCPE_OK;