forked from k5mwe/DtCyber
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlp3000.c
928 lines (833 loc) · 26.7 KB
/
lp3000.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
/*--------------------------------------------------------------------------
**
** Copyright (c) 2003-2010, Tom Hunter, Paul Koning
**
** Name: lp3000.c
**
** Description:
** Perform emulation of CDC 3000 series printers/controllers.
**
** This combines the 501 and 512 printers, and the 3152 and 3555
** controllers, because they all look pretty similar.
**
** 501 vs. 512 is selected by which Init function is called from
** init.c via the device table; 3555 is the default but 3152/3256/3659
** emulation can be selected by supplying a name string of "3152".
**
** 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 <errno.h>
#include "const.h"
#include "types.h"
#include "proto.h"
#include "dcc6681.h"
/*
** -----------------
** Private Constants
** -----------------
*/
// Flags stored in the context field:
#define Lp3000Type501 00001
#define Lp3000Type512 00002
#define Lp3000Type3152 00010
#define Lp3000Type3555 00020
#define Lp3555FillImageMem 00100
#define Lp3000IntReady 00200 // Same code as int status bit
#define Lp3000IntEnd 00400 // ditto
#define Lp3000IntReadyEna 02000
#define Lp3000IntEndEna 04000
/*
** Function codes
*/
// Codes common to 3152/3256/3659 and 3555
#define FcPrintRelease 00000
#define FcPrintSingle 00001
#define FcPrintDouble 00002
#define FcPrintLastLine 00003
#define FcPrintEject 00004
#define FcPrintAutoEject 00005
#define FcPrintNoSpace 00006
// Codes for 3152/3256/3659
#define Fc3152ClearFormat 00010
#define Fc3152PostVFU1 00011
#define Fc3152PostVFU2 00012
#define Fc3152PostVFU3 00013
#define Fc3152PostVFU4 00014
#define Fc3152PostVFU5 00015
#define Fc3152PostVFU6 00016
#define Fc3152SelectPreprint 00020
#define Fc3152PreVFU1 00021
#define Fc3152PreVFU2 00022
#define Fc3152PreVFU3 00023
#define Fc3152PreVFU4 00024
#define Fc3152PreVFU5 00025
#define Fc3152PreVFU6 00026
#define Fc3152SelIntReady 00030
#define Fc3152RelIntReady 00031
#define Fc3152SelIntEnd 00032
#define Fc3152RelIntEnd 00033
#define Fc3152SelIntError 00034
#define Fc3152RelIntError 00035
#define Fc3152Release2 00040
// Codes for 3555
#define Fc3555CondClearFormat 00007
#define Fc3555Sel8Lpi 00010
#define Fc3555Sel6Lpi 00011
#define Fc3555FillMemory 00012
#define Fc3555SelExtArray 00013
#define Fc3555ClearExtArray 00014
#define Fc3555SelIntReady 00020
#define Fc3555RelIntReady 00021
#define Fc3555SelIntEnd 00022
#define Fc3555RelIntEnd 00023
#define Fc3555SelIntError 00024
#define Fc3555RelIntError 00025
#define Fc3555ReloadMemEnable 00026
#define Fc3555ClearFormat 00030
#define Fc3555PostVFU1 00031
#define Fc3555PostVFU2 00032
#define Fc3555PostVFU3 00033
#define Fc3555PostVFU4 00034
#define Fc3555PostVFU5 00035
#define Fc3555PostVFU6 00036
#define Fc3555PostVFU7 00037
#define Fc3555PostVFU8 00040
#define Fc3555PostVFU9 00041
#define Fc3555PostVFU10 00042
#define Fc3555PostVFU11 00043
#define Fc3555PostVFU12 00044
#define Fc3555SelectPreprint 00050
#define Fc3555PreVFU1 00051
#define Fc3555PreVFU2 00052
#define Fc3555PreVFU3 00053
#define Fc3555PreVFU4 00054
#define Fc3555PreVFU5 00055
#define Fc3555PreVFU6 00056
#define Fc3555PreVFU7 00057
#define Fc3555PreVFU8 00060
#define Fc3555PreVFU9 00061
#define Fc3555PreVFU10 00062
#define Fc3555PreVFU11 00063
#define Fc3555PreVFU12 00064
#define Fc3555MaintStatus 00065
#define Fc3555ClearMaint 00066
/*
** Status reply
**
** 3152/3256/3659 vs. 3555 have different status codes for the
** most part, but the few we care about are common:
**
*/
#define StPrintReady 00001
#define StPrintIntReady 00200
#define StPrintIntEnd 00400
/*
** -----------------------
** Private Macro Functions
** -----------------------
*/
/*
** -----------------------------------------
** Private Typedef and Structure Definitions
** -----------------------------------------
*/
typedef struct lpContext
{
int flags;
bool printed;
bool keepInt;
} LpContext;
/*
** ---------------------------
** Private Function Prototypes
** ---------------------------
*/
static void lp3000Init(u8 unitNo, u8 eqNo, u8 channelNo, int flags);
static FcStatus lp3000Func(PpWord funcCode);
static void lp3000Io(void);
static void lp3000Activate(void);
static void lp3000Disconnect(void);
static void lp3000DebugData(void);
static char *lp3000Func2String(PpWord funcCode);
/*
** ----------------
** Public Variables
** ----------------
*/
/*
** -----------------
** Private Variables
** -----------------
*/
#if DEBUG
static FILE *lp3000Log = NULL;
#define MaxLine 1000
static PpWord lineData[MaxLine];
static int linePos = 0;
#endif
/*
**--------------------------------------------------------------------------
**
** Public Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Initialise 501 line printer.
**
** Parameters: Name Description.
** eqNo equipment number
** unitNo unit number
** channelNo channel number the device is attached to
** deviceName "3152" to get 3152 controller, null or "3555" for 3555
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void lp501Init(u8 eqNo, u8 unitNo, u8 channelNo, char *deviceName)
{
int flags = Lp3000Type501;
#if DEBUG
if (lp3000Log == NULL)
{
lp3000Log = fopen("lp3000log.txt", "wt");
}
#endif
(void)eqNo;
(void)deviceName;
if (deviceName == NULL ||
strcmp (deviceName, "3555") == 0)
{
flags |= Lp3000Type3555;
}
else if (strcmp (deviceName, "3152") == 0)
{
flags |= Lp3000Type3152;
}
else
{
fprintf (stderr, "Unrecognized LP501 controller type %s\n", deviceName);
exit (1);
}
lp3000Init (unitNo, eqNo, channelNo, flags);
}
/*--------------------------------------------------------------------------
** Purpose: Initialise 512 line printer.
**
** Parameters: Name Description.
** eqNo equipment number
** unitNo unit number
** channelNo channel number the device is attached to
** deviceName "3152" to get 3152 controller, null or "3555" for 3555
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void lp512Init(u8 eqNo, u8 unitNo, u8 channelNo, char *deviceName)
{
int flags = Lp3000Type512;
#if DEBUG
if (lp3000Log == NULL)
{
lp3000Log = fopen("lp3000log.txt", "wt");
}
#endif
(void)eqNo;
(void)deviceName;
if (deviceName == NULL ||
strcmp (deviceName, "3555") == 0)
{
flags |= Lp3000Type3555;
}
else if (strcmp (deviceName, "3152") == 0)
{
flags |= Lp3000Type3152;
}
else
{
fprintf (stderr, "Unrecognized LP512 controller type %s\n", deviceName);
exit (1);
}
lp3000Init (unitNo, eqNo, channelNo, flags);
}
/*
**--------------------------------------------------------------------------
**
** Private Functions
**
**--------------------------------------------------------------------------
*/
/*--------------------------------------------------------------------------
** Purpose: Initialise 3000 class line printer.
**
** Parameters: Name Description.
** unitNo unit number
** eqNo equipment number
** channelNo channel number the device is attached to
** flags Printer type flags
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void lp3000Init(u8 unitNo, u8 eqNo, u8 channelNo, int flags)
{
DevSlot *up;
char fname[80];
LpContext *lc;
up = dcc6681Attach(channelNo, eqNo, unitNo, DtLp5xx);
up->activate = lp3000Activate;
up->disconnect = lp3000Disconnect;
up->func = lp3000Func;
up->io = lp3000Io;
/*
** Only one printer unit is possible per equipment.
*/
if (up->context[0] != NULL)
{
fprintf (stderr, "Only one LP5xx unit is possible per equipment\n");
exit (1);
}
lc = (LpContext *) calloc(1, sizeof(LpContext));
if (lc == NULL)
{
fprintf (stderr, "Failed to allocate LP5xx context block\n");
exit (1);
}
up->context[0] = (void *)lc;
lc->flags = flags;
/*
** Open the device file.
*/
sprintf(fname, "LP5xx_C%02o_E%o", channelNo, eqNo);
up->fcb[0] = fopen(fname, "w");
if (up->fcb[0] == NULL)
{
fprintf(stderr, "Failed to open %s\n", fname);
exit(1);
}
/*
** Print a friendly message.
*/
printf("LP%d/%d initialised on channel %o equipment %o\n",
(flags & Lp3000Type3555) ? 3555 : 3152,
(flags & Lp3000Type501) ? 501 : 512,
channelNo, eqNo);
}
/*--------------------------------------------------------------------------
** Purpose: Remove the paper (operator interface).
**
** Parameters: Name Description.
** params parameters
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
void lp3000RemovePaper(char *params)
{
DevSlot *dp;
int numParam;
int channelNo;
int equipmentNo;
time_t currentTime;
struct tm t;
char fname[80];
char fnameNew[80];
/*
** Operator wants to remove paper.
*/
numParam = sscanf(params,"%o,%o",&channelNo, &equipmentNo);
/*
** Check parameters.
*/
if (numParam != 2)
{
printf("Not enough or invalid parameters\n");
return;
}
if (channelNo < 0 || channelNo >= MaxChannels)
{
printf("Invalid channel no\n");
return;
}
if (equipmentNo < 0 || equipmentNo >= MaxEquipment)
{
printf("Invalid equipment no\n");
return;
}
/*
** Locate the device control block.
*/
dp = dcc6681FindDevice((u8)channelNo, (u8)equipmentNo, DtLp5xx);
if (dp == NULL)
{
return;
}
/*
** Close the old device file.
*/
fflush(dp->fcb[0]);
fclose(dp->fcb[0]);
dp->fcb[0] = NULL;
/*
** Rename the device file to the format "LP5xx_yyyymmdd_hhmmss".
*/
sprintf(fname, "LP5xx_C%02o_E%o", channelNo, equipmentNo);
time(¤tTime);
t = *localtime(¤tTime);
sprintf(fnameNew, "LP5xx_%04d%02d%02d_%02d%02d%02d",
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
t.tm_hour,
t.tm_min,
t.tm_sec);
if (rename(fname, fnameNew) != 0)
{
printf("Could not rename %s to %s - %s\n", fname, fnameNew, strerror(errno));
return;
}
/*
** Open the device file.
*/
dp->fcb[0] = fopen(fname, "w");
/*
** Check if the open succeeded.
*/
if (dp->fcb[0] == NULL)
{
printf("Failed to open %s\n", fname);
return;
}
printf("Paper removed from 5xx printer\n");
}
/*--------------------------------------------------------------------------
** Purpose: Execute function code on 3000 line printer.
**
** Parameters: Name Description.
** funcCode function code
**
** Returns: FcStatus
**
**------------------------------------------------------------------------*/
static FcStatus lp3000Func(PpWord funcCode)
{
FILE *fcb;
LpContext *lc;
fcb = active3000Device->fcb[0];
lc = (LpContext *)active3000Device->context[0];
/*
** Note that we don't emulate the VFU, so all VFU control codes
** are implemented as NOPs.
*/
#if DEBUG
fprintf(lp3000Log, "\n%06d PP:%02o CH:%02o f:%04o T:%-25s > ",
traceSequenceNo,
activePpu->id,
activeDevice->channel->id,
funcCode,
lp3000Func2String(funcCode));
#endif
// Start with the common codes
switch (funcCode)
{
case FcPrintAutoEject:
case FcPrintNoSpace:
case Fc6681MasterClear:
// Treat these as NOPs
return(FcProcessed);
case FcPrintRelease:
// clear all interrupt conditions
lc->flags &= ~(StPrintIntReady | StPrintIntEnd);
// Release is sent at end of job, so flush the print file
if (lc->printed)
{
fflush (fcb);
lc->printed = FALSE;
}
return(FcProcessed);
case FcPrintSingle:
case FcPrintLastLine:
// Treat last-line codes as a single blank line
fputc('\n', fcb);
#if DEBUG
lp3000DebugData();
#endif
return(FcProcessed);
case FcPrintEject:
// Turn eject into a formfeed character
fputc('\f', fcb);
#if DEBUG
lp3000DebugData();
#endif
return(FcProcessed);
case FcPrintDouble:
fprintf(fcb, "\n\n");
#if DEBUG
lp3000DebugData();
#endif
return(FcProcessed);
case Fc6681Output:
if (lc->flags & Lp3555FillImageMem)
{
// Tweak the function code to tell I/O handler to toss this data
funcCode++;
// Now clear the flag
lc->flags &= ~Lp3555FillImageMem;
}
// Initially clear interrupt status flags
lc->flags &= ~(StPrintIntReady | StPrintIntEnd);
// Update interrupt status to reflect what status
// will be when this transfer is finished.
// Ok, so that's cheating a bit...
if (lc->flags & Lp3000IntReadyEna)
{
lc->flags |= Lp3000IntReady;
}
if (lc->flags & Lp3000IntEndEna)
{
lc->flags |= Lp3000IntEnd;
}
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
active3000Device->fcode = funcCode;
return(FcAccepted);
case Fc6681DevStatusReq:
active3000Device->fcode = funcCode;
return(FcAccepted);
}
if (lc->flags & Lp3000Type3555)
{
switch (funcCode)
{
default:
printf("Unknown LP3555 function %04o\n", funcCode);
return(FcProcessed);
case Fc3555CondClearFormat:
case Fc3555Sel8Lpi:
case Fc3555Sel6Lpi:
case Fc3555SelExtArray:
case Fc3555ClearExtArray:
case Fc3555SelIntError:
case Fc3555RelIntError:
case Fc3555ReloadMemEnable:
case Fc3555ClearFormat:
case Fc3555PostVFU1:
case Fc3555PostVFU2:
case Fc3555PostVFU3:
case Fc3555PostVFU4:
case Fc3555PostVFU5:
case Fc3555PostVFU6:
case Fc3555PostVFU7:
case Fc3555PostVFU8:
case Fc3555PostVFU9:
case Fc3555PostVFU10:
case Fc3555PostVFU11:
case Fc3555PostVFU12:
case Fc3555SelectPreprint:
case Fc3555PreVFU1:
case Fc3555PreVFU2:
case Fc3555PreVFU3:
case Fc3555PreVFU4:
case Fc3555PreVFU5:
case Fc3555PreVFU6:
case Fc3555PreVFU7:
case Fc3555PreVFU8:
case Fc3555PreVFU9:
case Fc3555PreVFU10:
case Fc3555PreVFU11:
case Fc3555PreVFU12:
case Fc3555MaintStatus:
case Fc3555ClearMaint:
// All of the above are NOPs
return(FcProcessed);
case Fc3555FillMemory:
// Remember that we saw this function, but this doesn't actually
// start any I/O yet.
lc->flags |= Lp3555FillImageMem;
return(FcProcessed);
case Fc3555SelIntReady:
// Enable next int. If an I/O was done since the last
// time an int enable was issued, don't clear the
// current int. That's because things go very slowly
// otherwise; printer drivers typically issue the write,
// then enable the int shortly after. We've already set
// "ready" by then, unlike physical printers.
lc->flags |= Lp3000IntReady | Lp3000IntReadyEna;
if (lc->keepInt)
{
lc->keepInt = FALSE;
}
else
{
lc->flags &= ~Lp3000IntReady;
}
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
case Fc3555RelIntReady:
lc->flags &= ~(Lp3000IntReadyEna | Lp3000IntReady);
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
case Fc3555SelIntEnd:
lc->flags |= Lp3000IntEnd | Lp3000IntEndEna;
if (lc->keepInt)
{
lc->keepInt = FALSE;
}
else
{
lc->flags &= ~Lp3000IntEnd;
}
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
case Fc3555RelIntEnd:
lc->flags &= ~(Lp3000IntEndEna | Lp3000IntEnd);
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
}
}
else
{
switch (funcCode)
{
default:
printf("Unknown LP3152 function %04o\n", funcCode);
return(FcProcessed);
case Fc3152ClearFormat:
case Fc3152PostVFU1:
case Fc3152PostVFU2:
case Fc3152PostVFU3:
case Fc3152PostVFU4:
case Fc3152PostVFU5:
case Fc3152PostVFU6:
case Fc3152SelectPreprint:
case Fc3152PreVFU1:
case Fc3152PreVFU2:
case Fc3152PreVFU3:
case Fc3152PreVFU4:
case Fc3152PreVFU5:
case Fc3152PreVFU6:
case Fc3152SelIntError:
case Fc3152RelIntError:
case Fc3152Release2:
// All of the above are NOPs
return(FcProcessed);
case Fc3152SelIntReady:
// Enable next int. If an I/O was done since the last
// time an int enable was issued, don't clear the
// current int. That's because things go very slowly
// otherwise; printer drivers typically issue the write,
// then enable the int shortly after. We've already set
// "ready" by then, unlike physical printers.
lc->flags |= Lp3000IntReady | Lp3000IntReadyEna;
if (lc->keepInt)
{
lc->keepInt = FALSE;
}
else
{
lc->flags &= ~Lp3000IntReady;
}
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
case Fc3152RelIntReady:
lc->flags &= ~(Lp3000IntReadyEna | Lp3000IntReady);
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
case Fc3152SelIntEnd:
lc->flags |= Lp3000IntEnd | Lp3000IntEndEna;
if (lc->keepInt)
{
lc->keepInt = FALSE;
}
else
{
lc->flags &= ~Lp3000IntEnd;
}
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
case Fc3152RelIntEnd:
lc->flags &= ~(Lp3000IntEndEna | Lp3000IntEnd);
// Update interrupt summary flag in unit block
dcc6681Interrupt((lc->flags & (Lp3000IntReady | Lp3000IntEnd)) != 0);
return(FcProcessed);
}
}
active3000Device->fcode = funcCode;
return(FcAccepted);
}
/*--------------------------------------------------------------------------
** Purpose: Perform I/O on 3000 line printer.
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void lp3000Io(void)
{
FILE *fcb;
LpContext *lc;
fcb = active3000Device->fcb[0];
lc = (LpContext *)active3000Device->context[0];
/*
** Process printer I/O.
*/
switch (active3000Device->fcode)
{
default:
activeChannel->full = FALSE;
break;
case Fc6681Output:
if (activeChannel->full)
{
#if DEBUG
if (linePos < MaxLine)
{
lineData[linePos++] = activeChannel->data & Mask12;
}
#endif
if (lc->flags & Lp3000Type501)
{
// 501 printer, output display code
fputc(bcdToAscii[(activeChannel->data >> 6) & Mask6], fcb);
fputc(bcdToAscii[activeChannel->data & Mask6], fcb);
}
else
{
// 512 printer, output ASCII
fputc(activeChannel->data & 0377, fcb);
}
activeChannel->full = FALSE;
lc->printed = TRUE;
lc->keepInt = TRUE;
}
break;
case Fc6681Output + 1:
// Fill image memory, just ignore that data
activeChannel->full = FALSE;
break;
case Fc6681DevStatusReq:
// Indicate ready plus whatever interrupts are enabled
activeChannel->data = StPrintReady |
(lc->flags &
(StPrintIntReady | StPrintIntEnd));
activeChannel->full = TRUE;
active3000Device->fcode = 0;
break;
}
}
/*--------------------------------------------------------------------------
** Purpose: Handle channel activation.
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void lp3000Activate(void)
{
}
/*--------------------------------------------------------------------------
** Purpose: Handle disconnecting of channel.
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void lp3000Disconnect(void)
{
FILE *fcb = active3000Device->fcb[0];
if (active3000Device->fcode == Fc6681Output)
{
// Rule is "space after the line is printed" so do that here
fputc('\n', fcb);
#if DEBUG
lp3000DebugData();
#endif
active3000Device->fcode = 0;
}
}
/*--------------------------------------------------------------------------
** Purpose: Dump raw line data.
**
** Parameters: Name Description.
**
** Returns: Nothing.
**
**------------------------------------------------------------------------*/
static void lp3000DebugData(void)
{
#if DEBUG
int i;
if (linePos == 0)
{
return;
}
for (i = 0; i < linePos; i++)
{
if (i % 16 == 0)
{
fputc('\n', lp3000Log);
}
// fprintf(lp3000Log, " %04o", lineData[i]);
fprintf(lp3000Log, "%c%c", bcdToAscii[(lineData[i] >> 6) & Mask6], bcdToAscii[(lineData[i] >> 0) & Mask6]);
}
fputc('\n', lp3000Log);
linePos = 0;
#endif
}
/*--------------------------------------------------------------------------
** Purpose: Convert function code to string.
**
** Parameters: Name Description.
** funcCode function code
**
** Returns: String equivalent of function code.
**
**------------------------------------------------------------------------*/
static char *lp3000Func2String(PpWord funcCode)
{
static char buf[30];
#if DEBUG
switch(funcCode)
{
// case Fc669FormatUnit : return "Fc669FormatUnit";
default:
break;
}
#endif
sprintf(buf, "UNKNOWN: %04o", funcCode);
return(buf);
}
/*--------------------------- End Of File ------------------------------*/