-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdd885-42.c
executable file
·1331 lines (1167 loc) · 37.3 KB
/
dd885-42.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
/*--------------------------------------------------------------------------
**
** Copyright (c) 2019, Kevin Jordan, Tom Hunter,and Gerard van der Grinten
**
** Name: dd885_42.c
**
** Description:
** Perform emulation of the CDC 885-42 disk drive and 7155-401 controller.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License version 3 as
** published by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License version 3 for more details.
**
** You should have received a copy of the GNU General Public License
** version 3 along with this program in file "license-gpl-3.0.txt".
** If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
**
**--------------------------------------------------------------------------
*/
#define DEBUG 0
/*
** -------------
** Include Files
** -------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "const.h"
#include "types.h"
#include "proto.h"
/*
** -----------------
** Private Constants
** -----------------
*/
#define DiskType885_42 3
/*
** CDC 885-42 disk drive function and status codes.
*/
#define Fc885_42Seek 00001
#define Fc885_42Read 00004
#define Fc885_42Write 00005
#define Fc885_42OpComplete 00010
#define Fc885_42GeneralStatus 00012
#define Fc885_42Continue 00014
#define Fc885_42DetailedStatus 00023
#define Fc885_42ReadFactoryData 00030
#define Fc885_42ReadUtilityMap 00031
#define Fc885_42ReadProtectedSector 00034
#define Fc885_42ExtendedGeneralStatus 00066
#define Fc885_42InterlockAutoload 00067
#define Fc885_42Autoload 00414
/*
** General status bits.
*/
#define St885_42Abnormal 04000
#define St885_42ControllerReserved 02000
#define St885_42NonrecoverableError 01000
#define St885_42Recovering 00400
#define St885_42CheckwordError 00200
#define St885_42CorrectableAddressError 00100
#define St885_42DriveMalfunction 00020
#define St885_42DriveReservied 00010
#define St885_42AutoloadError 00004
#define St885_42Busy 00002
#define St885_42ControllerRecovery 00001
/*
** Detailed status.
*/
/*
** Physical geometry of 885-42 disk.
** 256 words/sector + 2 12-bit control bytes
** 32 sectors/track
** 10 tracks/cylinder (heads/unit)
** 841 cylinders/unit
*/
#define MaxCylinders 843
#define MaxTracks 10
#define MaxSectors 32
#define SectorSize 256
#define ShortSectorSize 64
#define AutoloadSize 16870
/*
** -----------------------
** Private Macro Functions
** -----------------------
*/
/*
** -----------------------------------------
** Private Typedef and Structure Definitions
** -----------------------------------------
*/
typedef struct sector
{
PpWord control[2];
CpWord data[SectorSize];
} Sector;
typedef struct diskParam
{
/*
** Info for show_disk operator command.
*/
struct diskParam *nextDisk;
u8 channelNo;
u8 eqNo;
char fileName[MaxFSPath];
/*
** Parameter Table
*/
i32 sector;
i32 track;
i32 cylinder;
PpWord generalStatus[5];
PpWord detailedStatus[20];
u8 unitNo;
PpWord emAddress[2];
PpWord writeParams[4];
Sector buffer;
} DiskParam;
/*
** ---------------------------
** Private Function Prototypes
** ---------------------------
*/
static FcStatus dd885_42Func(PpWord funcCode);
static void dd885_42Io(void);
static void dd885_42Activate(void);
static void dd885_42Disconnect(void);
static i32 dd885_42Seek(DiskParam *dp);
static i32 dd885_42SeekNext(DiskParam *dp);
static bool dd885_42Read(DiskParam *dp, FILE *fcb);
static bool dd885_42Write(DiskParam *dp, FILE *fcb);
static char * dd885_42Func2String(PpWord funcCode);
/*
** ----------------
** Public Variables
** ----------------
*/
/*
** -----------------
** Private Variables
** -----------------
*/
static DiskParam *firstDisk = NULL;
static DiskParam *lastDisk = NULL;
#if DEBUG
#define OctalColumn(x) (5 * (x) + 1 + 5)
#define AsciiColumn(x) (OctalColumn(5) + 2 + (2 * x))
#define LogLineLength (AsciiColumn(5))
static FILE *dd885_42Log = NULL;
static void dd885_42LogFlush(void);
static void dd885_42LogByte(int b);
static char dd885_42LogBuf[LogLineLength + 1];
static int dd885_42LogCol = 0;
/*--------------------------------------------------------------------------
** Purpose: Flush incomplete numeric/ascii data line
**
** Parameters: Name Description.
**
** Returns: nothing
**
**------------------------------------------------------------------------*/
static void dd885_42LogFlush(void)
{
if (dd885_42LogCol != 0)
{
fputs(dd885_42LogBuf, dd885_42Log);
}
dd885_42LogCol = 0;
memset(dd885_42LogBuf, ' ', LogLineLength);
dd885_42LogBuf[0] = '\n';
dd885_42LogBuf[LogLineLength] = '\0';
}
/*--------------------------------------------------------------------------
** Purpose: Log a byte in octal/ascii form
**
** Parameters: Name Description.
**
** Returns: nothing
**
**------------------------------------------------------------------------*/
static void dd885_42LogByte(int b)
{
char octal[10];
int col;
col = OctalColumn(dd885_42LogCol);
sprintf(octal, "%04o ", b);
memcpy(dd885_42LogBuf + col, octal, 5);
col = AsciiColumn(dd885_42LogCol);
dd885_42LogBuf[col + 0] = cdcToAscii[(b >> 6) & Mask6];
dd885_42LogBuf[col + 1] = cdcToAscii[(b >> 0) & Mask6];
if (++dd885_42LogCol == 5)
{
dd885_42LogFlush();
}
}
#endif
/*
**--------------------------------------------------------------------------
**
** Public Functions
**
**--------------------------------------------------------------------------
*/
/*
**--------------------------------------------------------------------------
**
** Private Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Initialise specified disk drive.
**
** Parameters: Name Description.
** eqNo equipment number
** unitNo unit number
** channelNo channel number the device is attached to
** deviceName optional device file name
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void dd885_42Init(u8 eqNo, u8 unitNo, u8 channelNo, char *deviceName)
{
DevSlot *ds;
FILE *fcb;
char fname[MaxFSPath];
DiskParam *dp;
time_t mTime;
struct tm *lTime;
u8 yy, mm, dd;
char *opt = NULL;
if (extMaxMemory == 0)
{
fprintf(stderr, "(dd885-42) Cannot configure 885-42 disk, no ECS configured\n");
exit(1);
}
#if DEBUG
if (dd885_42Log == NULL)
{
dd885_42Log = fopen("dd885_42log.txt", "wt");
if (dd885_42Log == NULL)
{
fprintf(stderr, "dd885_42log.txt - aborting\n");
exit(1);
}
}
#endif
/*
** Setup channel functions.
*/
ds = channelAttach(channelNo, eqNo, DtDd885_42);
activeDevice = ds;
ds->activate = dd885_42Activate;
ds->disconnect = dd885_42Disconnect;
ds->func = dd885_42Func;
ds->io = dd885_42Io;
/*
** Save disk parameters.
*/
ds->selectedUnit = -1;
dp = (DiskParam *)calloc(1, sizeof(DiskParam));
if (dp == NULL)
{
fprintf(stderr, "(dd885-42) Failed to allocate dd885_42 context block\n");
exit(1);
}
dp->unitNo = unitNo;
/*
** Determine if any options have been specified.
*/
if (deviceName != NULL)
{
opt = strchr(deviceName, ',');
}
if (opt != NULL)
{
/*
** Process options.
*/
*opt++ = '\0';
fprintf(stderr, "(dd885-42) Unrecognized option name %s\n", opt);
exit(1);
}
/*
** Initialize detailed status.
*/
dp->detailedStatus[0] = 0; // strobe offset & address error status
dp->detailedStatus[1] = 0371; // checkword error status, 885 sequence latches, motor at speed
dp->detailedStatus[2] = 0; // current function & error bits
dp->detailedStatus[3] = 07700 | unitNo; // 7155 controlware, revision #, drive unit number
dp->detailedStatus[4] = 0; // track flaw, factory flaw map flaw, cylinder # bits 9-4
dp->detailedStatus[5] = 0; // cylinder # bits 3-0, track # bits 7-0
dp->detailedStatus[6] = 010; // logical sector number bits 7-0, ready&safe, system maint mode, drive # bits 7-6
dp->detailedStatus[7] = (unitNo << 6) | 037; // drive # bits 5-0, write enable, online, air switch, start switch, motor at speed
dp->detailedStatus[8] = 01640; // DSU status
dp->detailedStatus[9] = 07201; // DSU status
dp->detailedStatus[10] = 0; // DSU status
dp->detailedStatus[11] = 0; // DSU status
dp->detailedStatus[12] = 0; // command causing error or word address of correctable read data
dp->detailedStatus[13] = 0; // first word of correction vector
dp->detailedStatus[14] = 0; // second word of correction vector
dp->detailedStatus[15] = 0; // DSC operating status word
dp->detailedStatus[16] = 0; // coupler buffer status
dp->detailedStatus[17] = 0400; // access A is connected & last function
dp->detailedStatus[18] = 0; // 2nd and 3rd to last functions
dp->detailedStatus[19] = 0; // 3rd to last function
/*
** Link device parameters.
*/
ds->context[unitNo] = dp;
/*
** Link into list of disk units.
*/
if (lastDisk == NULL)
{
firstDisk = dp;
}
else
{
lastDisk->nextDisk = dp;
}
lastDisk = dp;
/*
** Open or create disk image.
*/
if (deviceName == NULL)
{
/*
** Construct a name.
*/
sprintf(fname, "DD885_42_C%02ou%1o", channelNo, unitNo);
}
else
{
strcpy(fname, deviceName);
}
/*
** Try to open existing disk image.
*/
fcb = fopen(fname, "r+b");
if (fcb == NULL)
{
/*
** Disk does not yet exist - manufacture one.
*/
fcb = fopen(fname, "w+b");
if (fcb == NULL)
{
fprintf(stderr, "(dd885-42) Failed to open %s\n", fname);
exit(1);
}
/*
** Write last disk sector to reserve the space.
*/
memset(&dp->buffer, 0, sizeof dp->buffer);
dp->cylinder = MaxCylinders - 1;
dp->track = MaxTracks - 1;
dp->sector = MaxSectors - 1;
fseek(fcb, dd885_42Seek(dp), SEEK_SET);
fwrite(&dp->buffer, sizeof dp->buffer, 1, fcb);
/*
** Position to cylinder with the disk's factory and utility
** data areas.
*/
dp->cylinder = MaxCylinders - 2;
/*
** Zero entire cylinder containing factory and utility data areas.
*/
memset(&dp->buffer, 0, sizeof dp->buffer);
for (dp->track = 0; dp->track < MaxTracks; dp->track++)
{
for (dp->sector = 0; dp->sector < MaxSectors; dp->sector++)
{
fseek(fcb, dd885_42Seek(dp), SEEK_SET);
fwrite(&dp->buffer, sizeof dp->buffer, 1, fcb);
}
}
/*
** Write serial number and date of manufacture.
*/
dp->buffer.data[0] = (CpWord)(((channelNo & 070) << (8 - 3))
| ((channelNo & 007) << (4 - 0))
| ((unitNo & 070) >> (3 - 0))) << 48;
dp->buffer.data[0] |= (CpWord)(((unitNo & 007) << (8 - 0))
| ((DiskType885_42 & 070) << (4 - 3))
| ((DiskType885_42 & 007) << (0 - 0))) << 36;
mTime = getSeconds();
lTime = localtime(&mTime);
yy = lTime->tm_year % 100;
mm = lTime->tm_mon + 1;
dd = lTime->tm_mday;
dp->buffer.data[0] |= ((dd / 10) << 8 | (dd % 10) << 4 | mm / 10) << 24;
dp->buffer.data[0] |= ((mm % 10) << 8 | (yy / 10) << 4 | yy % 10) << 12;
dp->track = 0;
dp->sector = 0;
fseek(fcb, dd885_42Seek(dp), SEEK_SET);
fwrite(&dp->buffer, sizeof dp->buffer, 1, fcb);
}
ds->fcb[unitNo] = fcb;
/*
** For Operator Show Status Command
*/
strcpy(dp->fileName, fname);
dp->channelNo = channelNo;
dp->unitNo = unitNo;
/*
** Reset disk seek position.
*/
dp->cylinder = 0;
dp->track = 0;
dp->sector = 0;
fseek(fcb, dd885_42Seek(dp), SEEK_SET);
/*
** Print a friendly message.
*/
printf("(dd885-42) Disk with %d cylinders initialised on channel %o unit %o\n",
MaxCylinders, channelNo, unitNo);
}
/*
**--------------------------------------------------------------------------
**
** Private Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Execute function code on 885-42 disk drive.
**
** Parameters: Name Description.
** funcCode function code
**
** Returns: FcStatus
**
**------------------------------------------------------------------------*/
static FcStatus dd885_42Func(PpWord funcCode)
{
i8 unitNo;
FILE *fcb;
int ignore;
DiskParam *dp;
unitNo = activeDevice->selectedUnit;
if (unitNo != -1)
{
dp = (DiskParam *)activeDevice->context[unitNo];
fcb = activeDevice->fcb[unitNo];
}
else
{
dp = NULL;
fcb = NULL;
}
#if DEBUG
dd885_42LogFlush();
if (dp != NULL)
{
fprintf(dd885_42Log, "\n%06d PP:%02o CH:%02o f:%04o T:%-25s c:%3d t:%2d s:%2d > ",
traceSequenceNo,
activePpu->id,
activeDevice->channel->id,
funcCode,
dd885_42Func2String(funcCode),
dp->cylinder,
dp->track,
dp->sector);
}
else
{
fprintf(dd885_42Log, "\n%06d PP:%02o CH:%02o DSK:? f:%04o T:%-25s > ",
traceSequenceNo,
activePpu->id,
activeDevice->channel->id,
funcCode,
dd885_42Func2String(funcCode));
}
fflush(dd885_42Log);
#endif
/*
** Catch functions which try to operate on not selected drives.
*/
if (unitNo == -1)
{
switch (funcCode)
{
case Fc885_42Seek:
case Fc885_42OpComplete:
case Fc885_42GeneralStatus:
case Fc885_42ExtendedGeneralStatus:
case Fc885_42InterlockAutoload:
case Fc885_42Autoload:
/*
** These functions are OK - do nothing.
*/
break;
default:
/*
** All remaining functions are declined if no drive is selected.
*/
#if DEBUG
fprintf(dd885_42Log, " No drive selected, function %s declined ", dd885_42Func2String(funcCode));
#endif
return (FcDeclined);
}
}
/*
** Process function request.
*/
switch (funcCode)
{
default:
#if DEBUG
fprintf(dd885_42Log, " !!!!!FUNC %s not implemented & declined!!!!!! ", dd885_42Func2String(funcCode));
#endif
return (FcDeclined);
case Fc885_42Seek:
/*
** Expect unit number, cylinder, track and sector.
*/
activeDevice->recordLength = 4;
break;
case Fc885_42Read:
/*
** Expect EM buffer address.
*/
activeDevice->recordLength = 2;
break;
case Fc885_42Write:
/*
** Expect EM buffer address, disk address, flags, and link byte
*/
activeDevice->recordLength = 6;
break;
case Fc885_42OpComplete:
return (FcProcessed);
case Fc885_42GeneralStatus:
activeDevice->recordLength = 1;
break;
case Fc885_42ExtendedGeneralStatus:
/* TODO: Fix this. Define a static area for extended general status when no unit selected */
if (dp)
{
dp->generalStatus[0] = activeDevice->status;
}
activeDevice->recordLength = 5;
break;
case Fc885_42DetailedStatus:
dp->detailedStatus[2] = (funcCode << 4) & 07760;
dp->detailedStatus[4] = (dp->cylinder >> 4) & 077;
dp->detailedStatus[5] = ((dp->cylinder << 8) | dp->track) & 07777;
dp->detailedStatus[6] = ((dp->sector << 4) | 010) & 07777;
if ((dp->track & 1) != 0)
{
dp->detailedStatus[9] |= 2; /* odd track */
}
else
{
dp->detailedStatus[9] &= ~2;
}
activeDevice->recordLength = 20;
break;
case Fc885_42Continue:
#if DEBUG
fprintf(dd885_42Log, " !!!!!FUNC %s not implemented but accepted!!!!!! ", dd885_42Func2String(funcCode));
#endif
logError(LogErrorLocation, "ch %o, function %s not implemented\n", activeChannel->id, dd885_42Func2String(funcCode));
break;
case Fc885_42InterlockAutoload:
case Fc885_42Autoload:
activeDevice->recordLength = AutoloadSize;
break;
case Fc885_42ReadFactoryData:
case Fc885_42ReadUtilityMap:
case Fc885_42ReadProtectedSector:
ignore = fread(&dp->buffer, sizeof dp->buffer, 1, fcb);
activeDevice->recordLength = ShortSectorSize * 5 + 2;
break;
}
activeDevice->fcode = funcCode;
#if DEBUG
fflush(dd885_42Log);
#endif
return (FcAccepted);
}
/*--------------------------------------------------------------------------
** Purpose: Perform I/O on 885-42 disk drive.
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void dd885_42Io(void)
{
u16 byteIndex;
DiskParam *dp;
FILE *fcb;
i32 pos;
u16 shiftCount;
i8 unitNo;
u16 wordIndex;
unitNo = activeDevice->selectedUnit;
if (unitNo != -1)
{
dp = (DiskParam *)activeDevice->context[unitNo];
fcb = activeDevice->fcb[unitNo];
}
else
{
dp = NULL;
fcb = NULL;
}
switch (activeDevice->fcode)
{
case Fc885_42Seek:
if (activeChannel->full)
{
switch (activeDevice->recordLength--)
{
case 4:
unitNo = activeChannel->data & 07;
if (unitNo != activeDevice->selectedUnit)
{
if (activeDevice->fcb[unitNo] != NULL)
{
activeDevice->selectedUnit = unitNo;
dp = (DiskParam *)activeDevice->context[unitNo];
dp->detailedStatus[12] &= ~01000;
}
else
{
logError(LogErrorLocation, "channel %02o - invalid select: %4.4o",
activeChannel->id, (u32)activeDevice->fcode);
activeDevice->selectedUnit = -1;
}
}
else
{
dp->detailedStatus[12] |= 01000;
}
break;
case 3:
if (dp != NULL)
{
dp->cylinder = activeChannel->data;
}
break;
case 2:
if (dp != NULL)
{
dp->track = activeChannel->data;
}
break;
case 1:
if (dp != NULL)
{
dp->sector = activeChannel->data;
pos = dd885_42Seek(dp);
if ((pos >= 0) && (fcb != NULL))
{
fseek(fcb, pos, SEEK_SET);
}
}
else
{
activeDevice->status = 05020;
}
break;
default:
activeDevice->recordLength = 0;
break;
}
#if DEBUG
fprintf(dd885_42Log, " %04o[%d]", activeChannel->data, activeChannel->data);
#endif
activeChannel->full = FALSE;
}
break;
case Fc885_42Read:
if (activeChannel->full)
{
if (dp != NULL)
{
switch (activeDevice->recordLength--)
{
case 2:
dp->emAddress[0] = activeChannel->data;
break;
case 1:
dp->emAddress[1] = activeChannel->data;
if (dd885_42Read(dp, fcb))
{
pos = dd885_42SeekNext(dp);
if ((pos >= 0) && (fcb != NULL))
{
fseek(fcb, pos, SEEK_SET);
}
}
break;
default:
activeDevice->recordLength = 0;
break;
}
}
#if DEBUG
fprintf(dd885_42Log, " %04o", activeChannel->data);
#endif
activeChannel->full = FALSE;
}
break;
case Fc885_42Write:
if (activeChannel->full)
{
if (dp != NULL)
{
switch (activeDevice->recordLength--)
{
case 6:
dp->emAddress[0] = activeChannel->data;
break;
case 5:
dp->emAddress[1] = activeChannel->data;
break;
case 4:
dp->writeParams[0] = activeChannel->data;
break;
case 3:
dp->writeParams[1] = activeChannel->data;
break;
case 2:
dp->writeParams[2] = activeChannel->data;
break;
case 1:
dp->writeParams[3] = activeChannel->data;
if (dd885_42Write(dp, fcb))
{
pos = dd885_42SeekNext(dp);
if ((pos >= 0) && (fcb != NULL))
{
fseek(fcb, pos, SEEK_SET);
}
}
break;
default:
activeDevice->recordLength = 0;
break;
}
}
#if DEBUG
fprintf(dd885_42Log, " %04o", activeChannel->data);
#endif
activeChannel->full = FALSE;
}
break;
case Fc885_42GeneralStatus:
if (!activeChannel->full)
{
activeChannel->data = activeDevice->status;
activeChannel->full = TRUE;
#if DEBUG
fprintf(dd885_42Log, " %04o", activeChannel->data);
#endif
if (--activeDevice->recordLength == 0)
{
activeChannel->discAfterInput = TRUE;
}
}
break;
case Fc885_42ExtendedGeneralStatus:
if (!activeChannel->full)
{
/* TODO: Fix this. Use a static area when no unit selected */
if (dp)
{
activeChannel->data = dp->generalStatus[5 - activeDevice->recordLength];
}
else
{
activeChannel->data = 0;
}
activeChannel->full = TRUE;
#if DEBUG
fprintf(dd885_42Log, " %04o", activeChannel->data);
#endif
if (--activeDevice->recordLength == 0)
{
activeChannel->discAfterInput = TRUE;
}
}
break;
case Fc885_42DetailedStatus:
if (!activeChannel->full)
{
activeChannel->data = dp->detailedStatus[20 - activeDevice->recordLength];
activeChannel->full = TRUE;
#if DEBUG
fprintf(dd885_42Log, " %04o", activeChannel->data);
#endif
if (--activeDevice->recordLength == 0)
{
activeChannel->discAfterInput = TRUE;
}
}
break;
case Fc885_42InterlockAutoload:
case Fc885_42Autoload:
#if DEBUG
if (activeChannel->full)
{
dd885_42LogByte(activeChannel->data);
if (--activeDevice->recordLength == 0)
{
dd885_42LogFlush();
fprintf(dd885_42Log, "\n Autoload complete: %d bytes loaded", AutoloadSize);
}
}
#endif
activeChannel->full = FALSE;
break;
case Fc885_42OpComplete:
case Fc885_42Continue:
if (activeChannel->full)
{
activeChannel->full = FALSE;
#if DEBUG
fprintf(dd885_42Log, " %04o", activeChannel->data);
#endif
}
break;
case Fc885_42ReadFactoryData:
case Fc885_42ReadUtilityMap:
case Fc885_42ReadProtectedSector:
if (!activeChannel->full)
{
if (activeDevice->recordLength > (ShortSectorSize * 5 + 1))
{
activeChannel->data = dp->buffer.control[0];
--activeDevice->recordLength;
}
else if (activeDevice->recordLength > (ShortSectorSize * 5))
{
activeChannel->data = dp->buffer.control[1];
--activeDevice->recordLength;
}
else
{
byteIndex = (ShortSectorSize * 5) - activeDevice->recordLength;
wordIndex = byteIndex / 5;
shiftCount = 48 - (wordIndex * 12);
activeChannel->data = (dp->buffer.data[wordIndex] >> shiftCount) & 07777;
if (--activeDevice->recordLength == 0)
{
activeChannel->discAfterInput = TRUE;
}
}
activeChannel->full = TRUE;
#if DEBUG
dd885_42LogByte(activeChannel->data);
#endif
}
break;
}
}
/*--------------------------------------------------------------------------
** Purpose: Handle channel activation.
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void dd885_42Activate(void)
{
#if DEBUG
fprintf(dd885_42Log, "\n%06d PP:%02o CH:%02o Activate",
traceSequenceNo,
activePpu->id,
activeDevice->channel->id);
fflush(dd885_42Log);