-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmt679.c
2823 lines (2510 loc) · 78.8 KB
/
mt679.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) 2003-2011, Tom Hunter
**
** Name: mt679.c
**
** Description:
** Perform emulation of CDC 6600 679 tape drives attached to a
** 7021-31 magnetic tape 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>
#ifndef WIN32
#include <unistd.h>
#endif
#include <string.h>
#include "const.h"
#include "types.h"
#include "proto.h"
/*
** -----------------
** Private Constants
** -----------------
*/
/*
** ATS tape function codes:
*/
#define Fc679ClearUnit 00000
#define Fc679Release 00001
#define Fc679FormatUnit 00004
#define Fc679OppositeParity 00005
#define Fc679OppositeDensity 00105
#define Fc679SetReadClipNorm 00006
#define Fc679SetReadClipHigh 00106
#define Fc679SetReadClipLow 00206
#define Fc679SetReadClipHyper 00306
#define Fc679Rewind 00010
#define Fc679RewindUnload 00110
#define Fc679StopMotion 00011
#define Fc679GeneralStatus 00012
#define Fc679DetailedStatus 00112
#define Fc679UnitStatus 00212
#define Fc679Forespace 00013
#define Fc679Backspace 00113
#define Fc679CtrledBackspace 00114
#define Fc679SearchTapeMarkF 00015
#define Fc679SearchTapeMarkB 00115
#define Fc679Connect 00020
#define Fc679WarmstartHighDens 00120
#define Fc679WarmstartLowDens 00320
#define Fc679ReadFwd 00040
#define Fc679ReadBkw 00140
#define Fc679CopyReadConv 00047
#define Fc679CopyWriteConv 00247
#define Fc679Write 00050
#define Fc679WriteShort 00250
#define Fc679WriteTapeMark 00051
#define Fc679Erase 00052
#define Fc679EraseDataSecurity 00252
#define Fc679LoadReadConv 00057
#define Fc679LoadWriteConv 00257
#define Fc679RewindOnEOT 00060
#define Fc679WaitForStop 00061
#define Fc679TestVelocityVect 00071
#define Fc679MeasureGapSizeFwd 00072
#define Fc679MeasureGapSizeBkw 00172
#define Fc679MeasureStartTFwd 00073
#define Fc679SetTransferCheckCh 00074
#define Fc679SetLoopWTRTcu 00075
#define Fc679SetLoopWTR1TU 00175
#define Fc679SetLoopWTR2TU 00275
#define Fc679SetEvenWrParity 00076
#define Fc679SetEvenChParity 00176
#define Fc679ForceDataErrors 00077
#define Fc679MasterClear 00414
/*
** General status reply:
*/
#define St679Alert 04000
#define St679NoUnit 01000
#define St679WriteEnabled 00200
#define St679NineTrack 00100
#define St679CharacterFill 00040
#define St679TapeMark 00020
#define St679EOT 00010
#define St679BOT 00004
#define St679Busy 00002
#define St679Ready 00001
/*
** Detailed status error codes.
*/
#define EcMissingRing 006
#define EcBlankTape 010
#define EcBackPastLoadpoint 030
#define EcIllegalUnit 031
#define EcIllegalFunction 050
#define EcNoTapeUnitConnected 051
#define EcNoFuncParams 052
#define EcDiagnosticError 070
/*
** Misc constants.
*/
#define MaxPpBuf 40000
#define MaxByteBuf 60000
#define MaxPackedConvBuf (((256 * 8) + 11) / 12)
#define MaxTapeSize 1250000000 // this may need adjusting for shorter real tapes
/*
** -----------------------
** Private Macro Functions
** -----------------------
*/
/*
** -----------------------------------------
** Private Typedef and Structure Definitions
** -----------------------------------------
*/
/*
** ATS controller.
*/
typedef struct ctrlParam
{
FILE *convFileHandle;
u8 readConv[4][256];
u8 writeConv[4][256];
PpWord packedConv[MaxPackedConvBuf];
u8 selectedConversion;
bool packedMode;
u8 density;
u8 minBlockLength;
bool lwrMode;
bool writing;
bool oddFrameCount;
PpWord controllerStatus[17]; // first element not used
} CtrlParam;
/*
** ATS tape unit.
*/
typedef struct tapeParam
{
/*
** Info for show_tape operator command.
*/
struct tapeParam * nextTape;
u8 channelNo;
u8 eqNo;
u8 unitNo;
char fileName[_MAX_PATH + 1];
/*
** Dynamic state.
*/
bool alert;
bool endOfTape;
bool fileMark;
bool unitReady;
bool ringIn;
bool characterFill;
bool flagBitDetected;
bool rewinding;
bool suppressBot;
u32 rewindStart;
u16 blockCrc;
u8 errorCode;
u32 blockNo;
PpWord recordLength;
PpWord deviceStatus[17]; // first element not used
PpWord ioBuffer[MaxPpBuf];
PpWord *bp;
} TapeParam;
/*
** ---------------------------
** Private Function Prototypes
** ---------------------------
*/
static void mt679ResetStatus(TapeParam *tp);
static void mt679SetupStatus(TapeParam *tp);
static void mt679PackConversionTable(u8 *convTable);
static void mt679UnpackConversionTable(u8 *convTable);
static void mt679Unpack6BitTable(u8 *convTable);
static FcStatus mt679Func(PpWord funcCode);
static void mt679Io(void);
static void mt679Activate(void);
static void mt679Disconnect(void);
static void mt679FlushWrite(void);
static void mt679PackAndConvert(u32 recLen);
static void mt679FuncRead(void);
static void mt679FuncForespace(void);
static void mt679FuncBackspace(void);
static void mt679FuncReadBkw(void);
static char *mt679Func2String(PpWord funcCode);
/*
** ----------------
** Public Variables
** ----------------
*/
/*
** -----------------
** Private Variables
** -----------------
*/
static TapeParam *firstTape = NULL;
static TapeParam *lastTape = NULL;
static u8 rawBuffer[MaxByteBuf];
#if DEBUG
static FILE *mt679Log = NULL;
#endif
/*
**--------------------------------------------------------------------------
**
** Public Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Initialise 679 tape drives.
**
** Parameters: Name Description.
** eqNo equipment number
** unitNo number of the unit to initialise
** channelNo channel number the device is attached to
** deviceName optional device file name
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void mt679Init(u8 eqNo, u8 unitNo, u8 channelNo, char *deviceName)
{
DevSlot *dp;
FILE *fcb;
TapeParam *tp;
#if DEBUG
if (mt679Log == NULL)
{
mt679Log = fopen("mt679log.txt", "wt");
}
#endif
/*
** Attach device to channel.
*/
dp = channelAttach(channelNo, eqNo, DtMt679);
/*
** Setup channel functions.
*/
dp->activate = mt679Activate;
dp->disconnect = mt679Disconnect;
dp->func = mt679Func;
dp->io = mt679Io;
dp->selectedUnit = -1;
/*
** Setup controller context.
*/
if (dp->controllerContext == NULL)
{
dp->controllerContext = calloc(1, sizeof(CtrlParam));
/*
** Optionally read in persistent conversion tables.
*/
if (*persistDir != '\0')
{
CtrlParam *cp = dp->controllerContext;
char fileName[256];
/*
** Try to open existing backing file.
*/
sprintf(fileName, "%s/mt679StoreC%02oE%02o", persistDir, channelNo, eqNo);
cp->convFileHandle = fopen(fileName, "r+b");
if (cp->convFileHandle != NULL)
{
/*
** Read conversion table contents.
*/
if ( fread(cp->writeConv, 1, sizeof(cp->writeConv), cp->convFileHandle) != sizeof(cp->writeConv)
|| fread(cp->readConv, 1, sizeof(cp->readConv), cp->convFileHandle) != sizeof(cp->readConv)
|| fread(cp->packedConv, 1, sizeof(cp->packedConv), cp->convFileHandle) != sizeof(cp->packedConv))
{
printf("Unexpected length of MT679 backing file, clearing tables\n");
memset(cp->writeConv, 0, sizeof(cp->writeConv));
memset(cp->readConv, 0, sizeof(cp->readConv));
memset(cp->packedConv, 0, sizeof(cp->packedConv));
}
}
else
{
/*
** Create a new file.
*/
cp->convFileHandle = fopen(fileName, "w+b");
if (cp->convFileHandle == NULL)
{
fprintf(stderr, "Failed to create MT679 backing file\n");
exit(1);
}
}
}
}
/*
** Setup tape unit parameter block.
*/
tp = calloc(1, sizeof(TapeParam));
if (tp == NULL)
{
fprintf(stderr, "Failed to allocate MT679 context block\n");
exit(1);
}
dp->context[unitNo] = tp;
/*
** Link into list of tape units.
*/
if (lastTape == NULL)
{
firstTape = tp;
}
else
{
lastTape->nextTape = tp;
}
lastTape = tp;
/*
** Open TAP container if file name was specified.
*/
if (deviceName != NULL)
{
strncpy(tp->fileName, deviceName, _MAX_PATH);
fcb = fopen(deviceName, "rb");
if (fcb == NULL)
{
fprintf(stderr, "Failed to open %s\n", deviceName);
exit(1);
}
dp->fcb[unitNo] = fcb;
tp->blockNo = 0;
tp->unitReady = TRUE;
}
else
{
dp->fcb[unitNo] = NULL;
tp->unitReady = FALSE;
}
/*
** Setup show_tape values.
*/
tp->channelNo = channelNo;
tp->eqNo = eqNo;
tp->unitNo = unitNo;
/*
** All initially mounted tapes are read only.
*/
tp->ringIn = FALSE;
/*
** Print a friendly message.
*/
printf("MT679 initialised on channel %o equipment %o unit %o\n", channelNo, eqNo, unitNo);
}
/*--------------------------------------------------------------------------
** Purpose: Optionally persist conversion tables.
**
** Parameters: Name Description.
** dp Device pointer.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void mt679Terminate(DevSlot *dp)
{
CtrlParam *cp = dp->controllerContext;
/*
** Optionally save conversion tables.
*/
if (cp->convFileHandle != NULL)
{
fseek(cp->convFileHandle, 0, SEEK_SET);
if ( fwrite(cp->writeConv, 1, sizeof(cp->writeConv), cp->convFileHandle) != sizeof(cp->writeConv)
|| fwrite(cp->readConv, 1, sizeof(cp->readConv), cp->convFileHandle) != sizeof(cp->readConv)
|| fwrite(cp->packedConv, 1, sizeof(cp->packedConv), cp->convFileHandle) != sizeof(cp->packedConv))
{
fprintf(stderr, "Error writing MT679 backing file\n");
}
fclose(cp->convFileHandle);
cp->convFileHandle = NULL;
}
}
/*--------------------------------------------------------------------------
** Purpose: Load a new tape (operator interface).
**
** Parameters: Name Description.
** params parameters
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void mt679LoadTape(char *params)
{
static char str[200];
DevSlot *dp;
int numParam;
int channelNo;
int equipmentNo;
int unitNo;
TapeParam *tp;
FILE *fcb;
u8 unitMode;
/*
** Operator inserted a new tape.
*/
numParam = sscanf(params,"%o,%o,%o,%c,%s",&channelNo, &equipmentNo, &unitNo, &unitMode, str);
/*
** Check parameters.
*/
if (numParam != 5)
{
printf("Not enough or invalid parameters\n");
return;
}
if (channelNo < 0 || channelNo >= MaxChannels)
{
printf("Invalid channel no\n");
return;
}
if (unitNo < 0 || unitNo >= MaxUnits)
{
printf("Invalid unit no\n");
return;
}
if (unitMode != 'w' && unitMode != 'r')
{
printf("Invalid ring mode (r/w)\n");
return;
}
if (str[0] == 0)
{
printf("Invalid file name\n");
return;
}
/*
** Locate the device control block.
*/
dp = channelFindDevice((u8)channelNo, DtMt679);
if (dp == NULL)
{
return;
}
/*
** Check if the unit is even configured.
*/
tp = (TapeParam *)dp->context[unitNo];
if (tp == NULL)
{
printf("Unit %d not allocated\n", unitNo);
return;
}
/*
** Check if the unit has been unloaded.
*/
if (dp->fcb[unitNo] != NULL)
{
printf("Unit %d not unloaded\n", unitNo);
return;
}
/*
** Open the file in the requested mode.
*/
if (unitMode == 'w')
{
fcb = fopen(str, "r+b");
if (fcb == NULL)
{
fcb = fopen(str, "w+b");
}
}
else
{
fcb = fopen(str, "rb");
}
dp->fcb[unitNo] = fcb;
/*
** Check if the open succeeded.
*/
if (fcb == NULL)
{
printf("Failed to open %s\n", str);
return;
}
/*
** Setup show_tape path name.
*/
strncpy(tp->fileName, str, _MAX_PATH);
/*
** Setup status.
*/
mt679ResetStatus(tp);
tp->ringIn = unitMode == 'w';
tp->blockNo = 0;
tp->unitReady = TRUE;
printf("Successfully loaded %s\n", str);
}
/*--------------------------------------------------------------------------
** Purpose: Unload a mounted tape (operator interface).
**
** Parameters: Name Description.
** params parameters
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void mt679UnloadTape(char *params)
{
DevSlot *dp;
int numParam;
int channelNo;
int equipmentNo;
int unitNo;
TapeParam *tp;
/*
** Operator inserted a new tape.
*/
numParam = sscanf(params,"%o,%o,%o",&channelNo, &equipmentNo, &unitNo);
/*
** Check parameters.
*/
if (numParam != 3)
{
printf("Not enough or invalid parameters\n");
return;
}
if (channelNo < 0 || channelNo >= MaxChannels)
{
printf("Invalid channel no\n");
return;
}
if (unitNo < 0 || unitNo >= MaxUnits2)
{
printf("Invalid unit no\n");
return;
}
/*
** Locate the device control block.
*/
dp = channelFindDevice((u8)channelNo, DtMt679);
if (dp == NULL)
{
return;
}
/*
** Check if the unit is even configured.
*/
tp = (TapeParam *)dp->context[unitNo];
if (tp == NULL)
{
printf("Unit %d not allocated\n", unitNo);
return;
}
/*
** Check if the unit has been unloaded.
*/
if (dp->fcb[unitNo] == NULL)
{
printf("Unit %d not loaded\n", unitNo);
return;
}
/*
** Close the file.
*/
fclose(dp->fcb[unitNo]);
dp->fcb[unitNo] = NULL;
/*
** Clear show_tape path name.
*/
memset(tp->fileName, '0', _MAX_PATH);
/*
** Setup status.
*/
mt679ResetStatus(tp);
tp->unitReady = FALSE;
tp->ringIn = FALSE;
tp->rewinding = FALSE;
tp->rewindStart = 0;
tp->blockCrc = 0;
tp->blockNo = 0;
printf("Successfully unloaded MT679 on channel %o equipment %o unit %o\n", channelNo, equipmentNo, unitNo);
}
/*--------------------------------------------------------------------------
** Purpose: Show tape status (operator interface).
**
** Parameters: Name Description.
**
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void mt679ShowTapeStatus(void)
{
TapeParam *tp = firstTape;
while (tp)
{
printf("MT679 on %o,%o,%o", tp->channelNo, tp->eqNo, tp->unitNo);
if (tp->unitReady)
{
printf(",%c,%s\n", tp->ringIn ? 'w' : 'r', tp->fileName);
}
else
{
printf(" (idle)\n");
}
tp = tp->nextTape;
}
}
/*
**--------------------------------------------------------------------------
**
** Private Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Reset device status at start of new function.
**
** Parameters: Name Description.
** tp pointer to tape parameters
**
** Returns: Nothing
**
**------------------------------------------------------------------------*/
static void mt679ResetStatus(TapeParam *tp)
{
if (tp != NULL)
{
tp->alert = FALSE;
tp->endOfTape = FALSE;
tp->fileMark = FALSE;
tp->characterFill = FALSE;
tp->flagBitDetected = FALSE;
tp->suppressBot = FALSE;
tp->errorCode = 0;
}
}
/*--------------------------------------------------------------------------
** Purpose: Setup device status based on current tape parameters.
**
** Parameters: Name Description.
** tp pointer to tape parameters
**
** Returns: Nothing
**
**------------------------------------------------------------------------*/
static void mt679SetupStatus(TapeParam *tp)
{
CtrlParam *cp = activeDevice->controllerContext;
if (tp != NULL)
{
tp->deviceStatus[0] = 0; // unused
/*
** General status.
*/
tp->deviceStatus[1] = St679NineTrack;
if (tp->alert)
{
tp->deviceStatus[1] |= St679Alert;
}
if (tp->ringIn)
{
tp->deviceStatus[1] |= St679WriteEnabled;
}
if (tp->characterFill)
{
tp->deviceStatus[1] |= St679CharacterFill;
}
if (tp->fileMark)
{
tp->deviceStatus[1] |= St679TapeMark;
}
if (tp->endOfTape)
{
tp->deviceStatus[1] |= St679EOT;
}
if (tp->rewinding)
{
tp->deviceStatus[1] |= St679Busy;
if (labs(cycles - tp->rewindStart) > 1000)
{
tp->rewinding = FALSE;
tp->blockNo = 0;
}
}
else
{
if (tp->blockNo == 0 && !tp->suppressBot)
{
tp->deviceStatus[1] |= St679BOT;
}
}
if (tp->unitReady)
{
tp->deviceStatus[1] |= St679Ready;
if (ftell(activeDevice->fcb[activeDevice->selectedUnit]) > MaxTapeSize)
{
tp->deviceStatus[1] |= St679EOT;
}
}
tp->deviceStatus[2] = (tp->blockCrc & Mask9) << 3;
/*
** Detailed status.
*/
tp->deviceStatus[3] = tp->errorCode;
tp->deviceStatus[5] = 0;
if (tp->flagBitDetected)
{
tp->deviceStatus[5] |= 00004;
}
tp->deviceStatus[6] = 0;
tp->deviceStatus[7] = 0;
tp->deviceStatus[8] = 0;
if (cp->packedMode)
{
tp->deviceStatus[8] |= 01000;
}
if (cp->selectedConversion != 0)
{
tp->deviceStatus[8] |= 02000;
}
tp->deviceStatus[9] = 0;
tp->deviceStatus[10] = 0500;
/*
** Unit status.
*/
tp->deviceStatus[11] = 04072; // GCR, dual density, 6250 cpi, 100 ips
tp->deviceStatus[12] = 0;
tp->deviceStatus[13] = 00043; // parked + cartridge open and present
tp->deviceStatus[14] = 00132; // auto hub activated, tape present & loaded
tp->deviceStatus[15] = 0;
tp->deviceStatus[16] = 00040; // IBG counter
}
else
{
/*
** General status.
*/
cp->controllerStatus[0] = 0;
cp->controllerStatus[1] = St679NoUnit | St679NineTrack;
cp->controllerStatus[2] = 0;
/*
** Detailed status.
*/
cp->controllerStatus[3] = 0;
cp->controllerStatus[5] = 0;
cp->controllerStatus[6] = 0;
cp->controllerStatus[7] = 0;
cp->controllerStatus[8] = 01000;
if (cp->selectedConversion != 0)
{
cp->controllerStatus[8] |= 02000;
}
cp->controllerStatus[9] = 0;
cp->controllerStatus[10] = 0500;
/*
** Unit status.
*/
cp->controllerStatus[11] = 0;
cp->controllerStatus[12] = 0;
cp->controllerStatus[13] = 0;
cp->controllerStatus[14] = 0;
cp->controllerStatus[15] = 0;
cp->controllerStatus[16] = 0;
}
}
/*--------------------------------------------------------------------------
** Purpose: Pack a conversion table into PP words.
**
** Parameters: Name Description.
** convTable conversion table
**
** Returns: FcStatus
**
**------------------------------------------------------------------------*/
static void mt679PackConversionTable(u8 *convTable)
{
CtrlParam *cp = activeDevice->controllerContext;
PpWord *op = cp->packedConv;
u8 *ip = convTable;
u16 c1, c2, c3;
int i;
for (i = 0; i < 85; i++)
{
c1 = *ip++;
c2 = *ip++;
c3 = *ip++;
*op++ = ((c1 << 4) | (c2 >> 4)) & Mask12;
*op++ = ((c2 << 8) | (c3 >> 0)) & Mask12;
}
c1 = *ip++;
c2 = *convTable; // wrap
*op++ = ((c1 << 4) | (c2 >> 4)) & Mask12;
}
/*--------------------------------------------------------------------------
** Purpose: Pack a conversion table into PP words.
**
** Parameters: Name Description.
** convTable conversion table
**
** Returns: FcStatus
**
**------------------------------------------------------------------------*/
static void mt679Pack6BitTable(u8 *convTable)
{
CtrlParam *cp = activeDevice->controllerContext;
PpWord *op = cp->packedConv;
u8 *ip = convTable;
int i;
memset(cp->packedConv, 0, MaxPackedConvBuf * sizeof(PpWord));
for (i = 0; i < 128; i++)
{
*op++ = ((ip[0] << 6) | ip[1]) & Mask12;
ip += 2;
}
}
/*--------------------------------------------------------------------------
** Purpose: Unpack PP words into a conversion table.
**
** Parameters: Name Description.
** convTable conversion table
**
** Returns: FcStatus
**
**------------------------------------------------------------------------*/
static void mt679UnpackConversionTable(u8 *convTable)
{
CtrlParam *cp = activeDevice->controllerContext;
PpWord *ip = cp->packedConv;
u8 *op = convTable;
int i;
for (i = 0; i < 85; i++)
{
*op++ = ((ip[0] >> 4) & 0xFF);
*op++ = ((ip[0] << 4) & 0xF0) | ((ip[1] >> 8) & 0x0F);
*op++ = ((ip[1] >> 0) & 0xFF);
ip += 2;
}
*op++ = ((ip[0] >> 4) & 0xFF); // discard last 4 bits
#if DEBUG
{
int i;
fprintf(mt679Log, "\nConversion Table %d", cp->selectedConversion);
for (i = 0; i < 256; i++)
{
if (i % 16 == 0)
{
fprintf(mt679Log, "\n%02X :", i);
}
fprintf(mt679Log, " %02X", convTable[i]);
}
}
fprintf(mt679Log, "\n");
#endif
}
/*--------------------------------------------------------------------------
** Purpose: Unpack PP words into a conversion table.
**
** Parameters: Name Description.
** convTable conversion table
**
** Returns: FcStatus
**
**------------------------------------------------------------------------*/
static void mt679Unpack6BitTable(u8 *convTable)
{
CtrlParam *cp = activeDevice->controllerContext;
PpWord *ip = cp->packedConv;
u8 *op = convTable;
int i;