-
Notifications
You must be signed in to change notification settings - Fork 2
/
fopen.mcr352
3957 lines (3408 loc) · 85.5 KB
/
fopen.mcr352
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
TITLE OPEN - CHANNEL OPENER FOR MUDDLE
RELOCATABLE
;C. REEVE MARCH 1973
.INSRT MUDDLE >
SYSQ
IFE ITS,[
IF1, .INSRT MUDSYS;STENEX >
]
;THIS PROGRAM HAS ENTRIES: FOPEN, FCLOSE, RENAME, READB, PRINTB, FILECOPY, READSTRING,
; PRINTSTRING, NETSTATE, NETACC, NETS, AND ACCESS.
;THESE SUBROUTINES HANDLE I/O STREAMS FOR THE MUDDLE SYSTEM.
; FOPEN - OPENS A FILE FOR EITHER READING OR WRITING. IT TAKES
; FIVE OPTINAL ARGUMENTS AS FOLLOWS:
; FOPEN (<DIR>,<FILE NAME1>,<FILE NAME2>,<DEVICE>,<SYSTEM NAME>)
;
; <DIR> - DIRECTION EITHER READ (INPUT) OR PRINT (OUPUT). DEFAULT IS READ
; <FILE NAME1> - FIRST FILE NAME. DEFAULT INPUT OR OUTPUT.
; <FILE NAME2> - SECOND FILE NAME. DEFAULT MUDDLE.
; <DEVICE> - DEVICE FROM WHICH TO OPEN. DEFAULT IS DSK.
; <SNAME> - SYSTEM (DIRECTORY) NAME. DEFAULT UNAME.
; FOPEN RETURNS AN OBJECT OF TYPE CHANNEL IF IT SUCCEEDS OTHERWISE NIL
; FCLOSE - CLOSES A FILE. TAKES A CHANNEL OBJECT AS ITS ARGUMENT. IT ALSO TAKES
; ACCESS - DOES A .ACCESS ON A CHARACTER BASIS FOR CHARACTER FILES
; A CHANNEL OBJECT IS A VECTOR CONTAINIG THE FOLLOWING INFORMATION
; CHANNO ;ITS I/O CHANNEL NUMBER. 0 MEANS NOT A REAL CHANNEL.
; DIRECT ;DIRECTION (EITHER READ OR PRINT)
; NAME1 ;FIRST NAME OF FILE AS OPENED.
; NAME2 ;SECOND NAME OF FILE
; DEVICE ;DEVICE UPON WHICH THE CHANNEL IS OPEN
; SNAME ;DIRECTORY NAME
; RNAME1 ;REAL FIRST NAME (AS RETURNED BY READING CHANNEL STATUS)
; RNAME2 ;REAL SECOND NAME
; RDEVIC ;REAL DEVICE
; RSNAME ;SYSTEM OR DIRECTORY NAME
; STATUS ;VARIOUS STATUS BITS
; IOINS ;INSTRUCTION EXECUTED TO INPUT OR OUTPUT ONE CHARACTER
; ACCESS ;ACCESS POINTER FOR RAND ACCESS (OR USED FOR DISPLAY INFO)
; RADX ;RADIX FOR CHANNELS NUMBER CONVERSION
; *** THE FOLLOWING FIELDS FOR OUTPUT ONLY ***
; LINLN ;LENGTH OF A LINE IN CHARACTERS FOR THIS DEVICE
; CHRPOS ;CURRENT POSITION ON CURRENT LINE
; PAGLN ;LENGTH OF A PAGE
; LINPOS ;CURRENT LINE BEING WRITTEN ON
; *** THE FOLLOWING FILEDS FOR INPUT ONLY ***
; EOFCND ;GETS EVALUATED ON EOF
; LSTCH ;BACKUP CHARACTER
; WAITNS ;FOR TTY INPUT, BECOMES A .SLEEP WHEN WAITING
; EXBUFR ;FOR TTY INPUT, CONTAINS A WAITING BUFFER LIST
; BUFSTR ;A CHARACTER STRING USED AS BUFFER FOR NON-TTY DEVICES
; THIS DEFINES THE LENGTH OF THE NON-TTY BUFFER
BUFLNT==100
;THIS DEFINES BLOCK MODE BIT FOR OPENING
BLOCKM==2 ;DEFINED IN THE LEFT HALF
IMAGEM==4
;THIS IRP DEFINES THE FIELDS AT ASSEMBLY TIME
CHANLNT==4 ;INITIAL CHANNEL LENGTH
; BUILD A PROTOTYPE CHANNEL AND DEFINE FILEDS
BUFRIN==-1 ;SPECIAL HACK SO LOSERS WON'T SEE TTY BUFFER
SCRPTO==-3 ;SPECIAL HACK FOR SCRIPT CHANNELS
PROCHN:
IRP A,,[[CHANNO,FIX],[DIRECT,CHSTR]
[NAME1,CHSTR],[NAME2,CHSTR],[DEVICE,CHSTR],[SNAME,CHSTR]
[RNAME1,CHSTR],[RNAME2,CHSTR],[RDEVIC,CHSTR],[RSNAME,CHSTR]
[STATUS,FIX],[IOINS,FIX],[LINLN,FIX],[CHRPOS,FIX],[PAGLN,FIX],[LINPOS,FIX]
[ACCESS,FIX],[RADX,FIX],[BUFSTR,CHSTR]]
IRP B,C,[A]
B==CHANLNT-3
T!C,,0
0
.ISTOP
TERMIN
CHANLNT==CHANLNT+2
TERMIN
; EQUIVALANCES FOR CHANNELS
EOFCND==LINLN
LSTCH==CHRPOS
WAITNS==PAGLN
EXBUFR==LINPOS
DISINF==BUFSTR ;DISPLAY INFO
INTFCN==BUFSTR ;FUNCTION (OR SUBR, OR RSUBR) TO BE APPLIED FOR INTERNAL CHNLS
;DEFINE VARIABLES ASSOCIATED WITH TTY BUFFERS
IRP A,,[IOIN2,ECHO,CHRCNT,ERASCH,KILLCH,BRKCH,ESCAP,SYSCHR,BRFCHR,BRFCH2,BYTPTR]
A==.IRPCNT
TERMIN
EXTBFR==BYTPTR+1+<100./5> ;LENGTH OF ADD'L BUFFER
.GLOBAL IPNAME,MOPEN,MCLOSE,MIOT,ILOOKU,6TOCHS,ICLOS,OCLOS,RGPARS,RGPRS
.GLOBAL OPNCHN,CHMAK,READC,TYO,SYSCHR,BRFCHR,LSTCH,BRFCH2,EXTBFR
.GLOBAL CHRWRD,STRTO6,TTYBLK,WAITNS,EXBUFR,TTICHN,TTOCHN,GETCHR
.GLOBAL CHANNO,STATUS,LINPOS,PAGLN,CHRPOS,LINLN,IOINS,ACCESS
.GLOBAL DIRECT,DISINF,RADX,EOFCND,BUFSTR,MODE1,MODE2,GCHACK,GMTYO
.GLOBAL T.CHAN,NAME1,BFCLOS,DOIOTI,DOIOTO,DOACCS,NOTTY,BYTDOP,TNXIN
.GLOBAL DISOPN,DISROP,DISCLS,DCHAR,DISLNL,DISPGL,INSTAT,MTYO
.GLOBAL ECHO,ERASCH,KILLCH,BRKCH,BYTPTR,SYSCHR,CHRCNT,ESCAP,N.CHNS
.GLOBAL REOPN,QUITTE,CHNL0,CHNL1,BUFRIN,IOIN2,IFALSE,GFALS,IDVAL
.GLOBAL BADCHN,WRONGD,CHNCLS,GSNAME,GIBLOK,APLQ,NAPT,ICONS,INCONS,IBLOCK,IDVAL1
.GLOBAL GRB,GWB,R1CHAR,W1CHAR,BFCLS1,TTYOP2,MPOPJ,COMPER,R1C,W1C,WXCT,RXCT
.GLOBAL TMTNXS,TNXSTR,RDEVIC
.VECT.==40000
; PAIR MOVING MACRO
DEFINE PMOVEM A,B
MOVE 0,A
MOVEM 0,B
MOVE 0,A+1
MOVEM 0,B+1
TERMIN
; DEFINITIONS OF THE OFFSETS INTO THE TP STACK FOR OPEN
T.SPDL==0 ; SAVES P STACK BASE
T.DIR==2 ; CONTAINS DIRECTION AND MODE
T.NM1==4 ; NAME 1 OF FILE
T.NM2==6 ; NAME 2 OF FILE
T.DEV==10 ; DEVICE NAME
T.SNM==12 ; SNAME
T.XT==14 ; EXTRA CRUFT IF NECESSARY
T.CHAN==16 ; CHANNEL AS GENERATED
; OFFSETS FROM PSTACK BASE (USED FOR OPENS, .RCHST AND .FDELES)
S.DIR==0 ; CODE FOR DIRECTION 0-IN, 1-OUT, 2-BIN, 3-BOUT,4-DISPLAY
IFN ITS,[
S.DEV==1 ; SIXBIT DEVICE RIGHT JUSTIFIED
S.NM1==2 ; SIXBIT NAME1
S.NM2==3 ; SIXBIT NAME2
S.SNM==4 ; SIXBIT SNAME
S.X1==5 ; TEMPS
S.X2==6
S.X3==7
]
IFE ITS,[
S.DEV==1
S.X1==2
S.X2==3
S.X3==4
]
; FLAGS SPECIFYING STATE OF THE WORLD AT VARIOUS TIMES
NOSTOR==400000 ; ON MEANS DONT BUILD NEW STRINGS
MSTNET==200000 ; ON MEANS ONLY THE "NET" DEVICE CAN WIN
SNSET==100000 ; FLAG, SNAME SUPPLIED
DVSET==040000 ; FLAG, DEV SUPPLIED
N2SET==020000 ; FLAG, NAME2 SET
N1SET==010000 ; FLAG, NAME1 SET
RMT [EXPUNGE N1SET,N2SET,DVSET,SNSET,MSTNET,NOSTOR
]
; TABLE OF LEGAL MODES
MODES: IRP A,,[READ,PRINT,READB,PRINTB,DISPLAY]
SIXBIT /A/
TERMIN
NMODES==.-MODES
; TABLE OF KNOWN DEVICES AND A POINTER TO THEIR OPENERS
IFN ITS,[
DEVS: IRP A,,[DSK,TPL,SYS,COM,TTY,USR,STY,[ST ],NET,DIS,E&S,INT,PTP,PTR
[P ],[DK ],[UT ],[T ],NUL,[AI ]
[ML ],[DM ],[AR ],ARC]B,,[ODSK,ODSK,ODSK,ODSK,OTTY,OUSR,OSTY,OSTY,ONET,ODIS,ODIS
OINT,OPTP,OPTP,ODSK,ODSK,OUTN,OTTY,ONUL,ODSK,ODSK,ODSK,ODSK,ODSK]
B,,(SIXBIT /A/)
TERMIN
]
IFE ITS,[
DEVS: IRP A,,[DSK,TTY,INT,NET]B,,[ODSK,OTTY,OINT,ONET]
B,,(SIXBIT /A/)
TERMIN
]
NDEVS==.-DEVS
;SUBROUTINE TO DO OPENING BEGINS HERE
MFUNCTION NFOPEN,SUBR,[OPEN-NR]
JRST FOPEN1
MFUNCTION FOPEN,SUBR,[OPEN]
FOPEN1: ENTRY
PUSHJ P,MAKCHN ;MAKE THE CHANNEL
PUSHJ P,OPNCH ;NOW OPEN IT
JRST FINIS
; SUBR TO JUST CREATE A CHANNEL
MFUNCTION CHANNEL,SUBR
ENTRY
PUSHJ P,MAKCHN
MOVSI A,TCHAN
JRST FINIS
; THIS ROUTINE PARSES ARGUMENTS TO FOPEN ETC. AND BUILDS A CHANNEL BUT DOESN'T OPEN IT
MAKCHN: PUSH TP,$TPDL
PUSH TP,P ; POINT AT CURRENT STACK BASE
PUSH TP,$TCHSTR
PUSH TP,CHQUOTE READ
MOVEI E,10 ; SLOTS OF TP NEEDED
PUSH TP,[0]
SOJG E,.-1
MOVEI E,0
EXCH E,(P) ; GET RET ADDR IN E
IFE ITS, PUSH P,[0]
IRP ATM,,[DEV,NM1,NM2,SNM]MDF,,[DSK,INPUT,>,[ ]]TMDF,,[DSK,INPUT,MUD,[ ]]
MOVE B,IMQUOTE ATM
IFN ITS, PUSH P,E
PUSHJ P,IDVAL1
GETYP 0,A
CAIN 0,TCHSTR
JRST MAK!ATM
MOVE A,$TCHSTR
IFN ITS, MOVE B,CHQUOTE MDF
IFE ITS, MOVE B,CHQUOTE TMDF
MAK!ATM:
MOVEM A,T.!ATM(TB)
MOVEM B,T.!ATM+1(TB)
IFN ITS,[
POP P,E
PUSHJ P,STRTO6 ; RESULT LEFT ON P STACK AS DESIRED
]
TERMIN
PUSH TP,[0] ; PUSH SLOTS
PUSH TP,[0]
PUSH P,[0] ; EXT SLOTS
PUSH P,[0]
PUSH P,[0]
PUSH P,E ; PUSH RETURN ADDRESS
MOVEI A,0
JUMPGE AB,MAKCH0 ; NO ARGS, ALREADY DONE
GETYP 0,(AB) ; 1ST ARG MUST BE A STRING
CAIE 0,TCHSTR
JRST WTYP1
MOVE A,(AB) ; GET ARG
MOVE B,1(AB)
PUSHJ P,CHMODE ; CHECK OUT OPEN MODE
PMOVEM (AB),T.DIR(TB) ; SAVE MODE NAME IN TEMPS
ADD AB,[2,,2] ; BUMP PAST DIRECTION
MOVEI A,0
JUMPGE AB,MAKCH0 ; CHECK NAME1 BASED ON JUST MODE
MOVEI 0,0 ; FLAGS PRESET
PUSHJ P,RGPARS ; PARSE THE STRING(S)
JRST TMA
; ARGUMENTS PARSED, DO FINAL CHECKS AND BUILD CHANNEL
MAKCH0:
IFN ITS,[
MOVE C,T.SPDL+1(TB)
HLRZS D,S.DEV(C) ; GET DEV
]
IFE ITS,[
MOVE A,T.DEV(TB)
MOVE B,T.DEV+1(TB)
PUSHJ P,STRTO6
POP P,D
HLRZS D
MOVE C,T.SPDL+1(TB)
MOVEM D,S.DEV(C)
]
CAIE D,(SIXBIT /INT/); INTERNAL?
JRST CHNET ; NO, MAYBE NET
SKIPN T.XT+1(TB) ; WAS FCN SUPPLIED?
JRST TFA
; FALLS TROUGH IF SKIP
; NOW BUILD THE CHANNEL
ARGSOK: MOVEI A,CHANLNT ; GET LENGTH
PUSHJ P,GIBLOK ; GET A BLOCK OF STUFF
ADD B,[4,,4] ; HIDE THE TTY BUFFER SLOT
PUSH TP,$TCHAN
PUSH TP,B
HRLI C,PROCHN ; POINT TO PROTOTYPE
HRRI C,(B) ; AND NEW ONE
BLT C,CHANLN-5(B) ; CLOBBER
MOVSI C,TLIST ; TO GIVE HIM A CLEAN LIST OF SCRIPT CHANS
MOVEM C,SCRPTO-1(B)
; NOW BLT IN STUFF FROM THE STACK
MOVSI C,T.DIR(TB) ; DIRECTION
HRRI C,DIRECT-1(B)
BLT C,SNAME(B)
MOVEI C,RNAME1-1(B) ; NOW "REAL" SLOTS
HRLI C,T.NM1(TB)
BLT C,RSNAME(B)
POPJ P,
; HERE TO VALIDIFY ARGUMENTS FOR A NET OPEN
CHNET: CAIE D,(SIXBIT /NET/) ; IS IT NET
IFN ITS, JRST MAKCH1
IFE ITS,[
JRST ARGSOK
]
MOVSI D,TFIX ; FOR TYPES
MOVEI B,T.NM1(TB) ; MAKE SURE ALL ARE FIXED
PUSHJ P,CHFIX
MOVEI B,T.NM2(TB)
PUSHJ P,CHFIX
MOVEI B,T.SNM(TB)
LSH A,-1 ; SKIP DEV FLAG
PUSHJ P,CHFIX
JRST ARGSOK
MAKCH1: TRNN A,MSTNET ; CANT HAVE SEEN A FIX
JRST ARGSOK
JRST WRONGT
IFN ITS,[
CHFIX: TRNE A,N1SET ; SKIP IF NOT SPECIFIED
JRST CHFIX1
]
SETOM 1(B) ; SET TO -1
SETOM S.NM1(C)
MOVEM D,(B) ; CORRECT TYPE
IFE ITS,CHFIX:
GETYP 0,(B)
CAIE 0,TFIX
JRST PARSQ
CHFIX1: ADDI C,1 ; POINT TO NEXT FIELD
LSH A,-1 ; AND NEXT FLAG
POPJ P,
PARSQ: CAIE 0,TCHSTR
JRST WRONGT
IFE ITS, POPJ P,
IFN ITS,[
PUSH P,A
PUSH P,C
PUSH TP,(B)
PUSH TP,1(B)
SUBI B,(TB)
PUSH P,B
MCALL 1,PARSE
GETYP 0,A
CAIE 0,TFIX
JRST WRONGT
POP P,C
ADDI C,(TB)
MOVEM A,(C)
MOVEM B,1(C)
POP P,C
POP P,A
POPJ P,
]
; SUBROUTINE TO CHECK VALIDITY OF MODE AND SAVE A CODE
CHMODE: PUSHJ P,CHMOD ; DO IT
MOVE C,T.SPDL+1(TB)
HRRZM A,S.DIR(C)
POPJ P,
CHMOD: PUSHJ P,STRTO6 ; TO SIXBIT
POP P,B ; VALUE ENDSUP ON STACK, RESTORE IT
CAME B,[SIXBIT /PRINTO/] ; KLUDGE TO MAKE PRINTO AS PRINTB
JRST .+3
MOVEI A,3 ; CODE FOR PRINTB
POPJ P,
MOVSI A,-NMODES ; SCAN TO SEE IF LEGAL MODE
CAME B,MODES(A)
AOBJN A,.-1
JUMPGE A,WRONGD ; ILLEGAL MODE NAME
POPJ P,
IFN ITS,[
; RGPARS -- PARSE THE STRINGS COMPRISING FILE NAMES INTO STANDARD ITS GOODIES
RGPRS: MOVEI 0,NOSTOR ; DONT STORE STRINGS IF ENTER HERE
RGPARS: HRLM 0,(P) ; LH IS FLAGS FOR THIS PROG
MOVSI E,-4 ; FIELDS TO FILL
RPARGL: GETYP 0,(AB) ; GET TYPE
CAIE 0,TCHSTR ; STRING?
JRST ARGCLB ; NO, JUST CLOBBER IT IN RAW
JUMPGE E,CPOPJ ; DON'T DO ANY MORE
PUSH TP,(AB) ; GET AN ARG
PUSH TP,1(AB)
FPARS: PUSH TP,-1(TP) ; ANOTHER COPY
PUSH TP,-1(TP)
PUSHJ P,FLSSP ; NO LEADING SPACES
MOVEI A,0 ; WILL HOLD SIXBIT
MOVEI B,6 ; CHARS PER 6BIT WORD
MOVE C,[440600,,A] ; BYTE POINTER INTO A
FPARSL: HRRZ 0,-1(TP) ; GET COUNT
JUMPE 0,PARSD ; DONE
SOS -1(TP) ; COUNT
ILDB 0,(TP) ; CHAR TO 0
CAIE 0," ; FILE NAME QUOTE?
JRST NOCNTQ
HRRZ 0,-1(TP)
JUMPE 0,PARSD
SOS -1(TP)
ILDB 0,(TP) ; USE THIS
JRST GOTCNQ
NOCNTQ: CAIG 0,40 ; SPACE?
JRST NDFLD ; YES, TERMINATE THIS FIELD
CAIN 0,": ; DEVICE ENDED?
JRST GOTDEV
CAIN 0,"; ; SNAME ENDED
JRST GOTSNM
GOTCNQ: PUSHJ P,A0TO6 ; CONVERT TO 6BIT AND CHECK
JUMPE B,FPARSL ; IGNORE IF AREADY HAVE 6
IDPB 0,C
SOJA B,FPARSL
; HERE IF SPACE ENCOUNTERED
NDFLD: MOVEI D,(E) ; COPY GOODIE
PUSHJ P,FLSSP ; FLUSH REDUNDANT SPACES
JUMPE 0,PARSD ; NO CHARS LEFT
NFL0: PUSH P,A ; SAVE SIXBIT WORD
PUSHJ P,6TOCHS ; CONVERT TO STRING
HRRZ 0,-1(TP) ; RESTORE CHAR COUNT
NFL2: MOVEI C,(D) ; COPY REL PNTR
SKIPGE -1(P) ; SKIP IF STRINGS TO BE STORED
JRST NFL3
ASH D,1 ; TIMES 2
ADDI D,T.NM1(TB)
MOVEM A,(D) ; STORE
MOVEM B,1(D)
NFL3: MOVSI A,N1SET ; FLAG IT
LSH A,(C)
IORM A,-1(P) ; AND CLOBBER
MOVE D,T.SPDL+1(TB) ; GET P BASE
POP P,@SIXTBL(C) ; AND STORE SIXBIT OF IT
POP TP,-2(TP) ; MAKE NEW STRING POINTER
POP TP,-2(TP)
JUMPE 0,.+3 ; SKIP IF NO MORE CHARS
AOBJN E,FPARS ; MORE TO PARSE?
CPOPJ: POPJ P, ; RETURN, ALL DONE
SUB TP,[2,,2] ; FLUSH OLD STRING
ADD E,[1,,1]
ADD AB,[2,,2] ; BUMP ARG
JUMPL AB,RPARGL ; AND GO ON
CPOPJ1: AOS A,(P) ; PREPARE TO WIN
HLRZS A
POPJ P,
; HERE IF STRING HAS ENDED
PARSD: PUSH P,A ; SAVE 6 BIT
MOVE A,-3(TP) ; CAN USE ARG STRING
MOVE B,-2(TP)
MOVEI D,(E)
JRST NFL2 ; AND CONTINUE
; HERE IF JUST READ DEV
GOTDEV: MOVEI D,2 ; CODE FOR DEVICE
JRST GOTFLD ; GOT A FIELD
; HERE IF JUST READ SNAME
GOTSNM: MOVEI D,3
GOTFLD: PUSHJ P,FLSSP
SOJA E,NFL0
; HERE FOR NON STRING ARG ENCOUNTERED
ARGCLB: SKIPGE (P) ; IF NOT STORING, CONSIDER THIS THE END
POPJ P,
MOVE C,T.SPDL+1(TB) ; GET P-BASE
HLRZ A,S.DEV(C) ; GET DEVICE
CAIE A,(SIXBIT /INT/) ; IS IT THE INTERNAL DEVICE
JRST TRYNET ; NO, COUD BE NET
MOVE A,0 ; OFFNEDING TYPE TO A
PUSHJ P,APLQ ; IS IT APPLICABLE
JRST NAPT ; NO, LOSE
PMOVEM (AB),T.XT(TB)
ADD AB,[2,,2] ; MUST BE LAST ARG
JUMPL AB,TMA
JRST CPOPJ1 ; ELSE SUCCESSFUL RETURN
TRYNET: CAIE 0,TFIX ; FOR NET DEV, ARGS MUST BE FIX
JRST WRONGT ; TREAT AS WRONG TYPE
MOVSI A,MSTNET ; BETTER BE NET EVENTUALLY
IORM A,(P) ; STORE FLAGS
MOVSI A,TFIX
MOVE B,1(AB) ; GET NUMBER
MOVEI 0,(E) ; MAKE SURE NOT DEVICE
CAIN 0,2
JRST WRONGT
PUSH P,B ; SAVE NUMBER
MOVEI D,(E) ; SET FOR TABLE OFFSETS
MOVEI 0,0
ADD TP,[4,,4]
JRST NFL2 ; GO CLOBBER IT AWAY
]
; ROUTINE TO FLUSH LEADING SPACES FROM A FIELD
FLSSP: HRRZ 0,-1(TP) ; GET CHR COUNNT
JUMPE 0,CPOPJ ; FINISHED STRING
FLSS1: MOVE B,(TP) ; GET BYTR
ILDB C,B ; GETCHAR
CAILE C,40
JRST FLSS2
MOVEM B,(TP) ; UPDATE BYTE POINTER
SOJN 0,FLSS1
FLSS2: HRRM 0,-1(TP) ; UPDATE STRING
POPJ P,
IFN ITS,[
;TABLE FOR STFUFFING SIXBITS AWAY
SIXTBL: S.NM1(D)
S.NM2(D)
S.DEV(D)
S.SNM(D)
S.X1(D)
]
RDTBL: RDEVIC(B)
RNAME1(B)
RNAME2(B)
RSNAME(B)
IFE ITS,[
; TENEX VERSION OF FILE NAME PARSER (ONLY ACCEPT ARGS IN SINGLE STRING)
RGPRS: MOVEI 0,NOSTOR
RGPARS: HRLM 0,(P) ; SAVE FOR STORE CHECKING
CAMGE AB,[-7,,] ; MULTI-STRING CASE POSSIBLE?
JRST TN.MLT ; YES, GO PROCESS
RGPRSS: GETYP 0,(AB) ; CHECK ARG TYPE
CAIE 0,TCHSTR
JRST WRONGT ; FOR NOW ONLY STRING ARGS WIN
PUSH TP,(AB)
PUSH TP,1(AB)
PUSHJ P,FLSSP ; FLUSH LEADING SPACES
PUSHJ P,RGPRS1
ADD AB,[2,,2]
CHKLST: JUMPGE AB,CPOPJ1
SKIPGE (P) ; IF FROM OPEN, ALLOW ONE MORE
POPJ P,
PMOVEM (AB),T.XT(TB)
ADD AB,[2,,2]
JUMPL AB,TMA
CPOPJ1: AOS (P)
POPJ P,
RGPRS1: PUSH P,[0] ; ALLOW A DEVICE SPEC
TN.SNM: MOVE A,(TP)
HRRZ 0,-1(TP)
JUMPE 0,RPDONE
ILDB A,A
CAIE A,"< ; START "DIRECTORY" ?
JRST TN.N1 ; NO LOOK FOR NAME1
SETOM (P) ; DEV NOT ALLOWED
IBP (TP) ; SKIP CHAR
SOS -1(TP)
PUSHJ P,TN.CNT ; COUNT CHARS TO ">"
JUMPE B,ILLNAM ; RAN OUT
CAIE A,"> ; SKIP IF WINS
JRST ILLNAM
PUSHJ P,TN.CPS ; COPY TO NEW STRING
MOVEM A,T.SNM(TB)
MOVEM B,T.SNM+1(TB)
TN.N1: PUSHJ P,TN.CNT
JUMPE B,RPDONE
CAIE A,": ; GOT A DEVICE
JRST TN.N11
SKIPE (P)
JRST ILLNAM
SETOM (P)
PUSHJ P,TN.CPS
MOVEM A,T.DEV(TB)
MOVEM B,T.DEV+1(TB)
JRST TN.SNM ; NOW LOOK FOR SNAME
TN.N11: CAIE A,">
CAIN A,"<
JRST ILLNAM
MOVEM A,(P) ; SAVE END CHAR
PUSHJ P,TN.CPS ; GEN STRING
MOVEM A,T.NM1(TB)
MOVEM B,T.NM1+1(TB)
TN.N2: SKIPN A,(P) ; GET CHAR BACK
JRST RPDONE
CAIN A,"; ; START VERSION?
JRST .+3
CAIE A,". ; START NAME2?
JRST ILLNAM ; I GIVE UP!!!
HRRZ B,-1(TP) ; GET RMAINS OF STRING
PUSHJ P,TN.CPS ; AND COPY IT
MOVEM A,T.NM2(TB)
MOVEM B,T.NM2+1(TB)
RPDONE: SUB P,[1,,1] ; FLUSH TEMP
SUB TP,[2,,2]
CPOPJ: POPJ P,
TN.CNT: HRRZ 0,-1(TP) ; CHAR COUNT
MOVE C,(TP) ; BPTR
MOVEI B,0 ; INIT COUNT TO 0
TN.CN1: MOVEI A,0 ; IN CASE RUN OUT
SOJL 0,CPOPJ ; RUN OUT?
ILDB A,C ; TRY ONE
CAIE A," ; TNEX FILE QUOTE?
JRST TN.CN2
SOJL 0,CPOPJ
IBP C ; SKIP QUOTED CHAT
ADDI B,2
JRST TN.CN1
TN.CN2: CAIE A,"<
CAIN A,">
POPJ P,
CAIE A,".
CAIN A,";
POPJ P,
CAIN A,":
POPJ P,
AOJA B,TN.CN1
TN.CPS: PUSH P,B ; # OF CHARS
MOVEI A,4(B) ; ADD 4 TO B IN A
IDIVI A,5
PUSHJ P,IBLOCK ; GET BLOCK OF WORDS FOR STRING
POP P,C ; CHAR COUNT BACK
HRLI B,440700
MOVSI A,TCHSTR
HRRI A,(C) ; CHAR STRING
MOVE D,B ; COPY BYTER
JUMPE C,CPOPJ
ILDB 0,(TP) ; GET CHAR
IDPB 0,D ; AND STROE
SOJG C,.-2
MOVNI C,(A) ; - LENGTH TO C
ADDB C,-1(TP) ; DECREMENT WORDS COUNT
TRNN C,-1 ; SKIP IF EMPTY
POPJ P,
IBP (TP)
SOS -1(TP) ; ELSE FLUSH TERMINATOR
POPJ P,
ILLNAM: PUSH TP,$TATOM
PUSH TP,EQUOTE ILLEGAL-TENEX-FILE-NAME
JRST CALER1
TN.MLT: MOVEI A,(AB)
HRLI A,-10
TN.ML1: GETYP 0,(A)
CAIE 0,TFIX
CAIN 0,TCHSTR
JRST .+2
JRST RGPRSS ; ASSUME SINGLE STRING
ADD A,[2,,2]
JUMPL A,TN.ML1
MOVEI A,T.NM1(TB)
HRLI A,(AB)
BLT A,T.SNM+1(TB) ; BLT 'EM IN
ADD AB,[10,,10] ; SKIP THESE GUYS
JRST CHKLST
]
; ROUTINE TO OPEN A CHANNEL FOR ANY DEVICE. NAMES ARE ASSUMED TO ALREADY
; BE ON BOTH TP STACK AND P STACK
OPNCH: MOVE C,T.SPDL+1(TB) ; GET PDL BASE
HRRZ A,S.DIR(C)
ANDI A,1 ; JUST WANT I AND O
HRLM A,S.DEV(C)
; .TRANS S.DEV(C) ; UNDO ANY TRANSLATIONS
; JRST TRLOST ; COMPLAIN
HRRZ A,S.DEV(C) ; GET SIXBIT DEVICE CODE
MOVEI E,(A) ; COPY TO E
ANDI E,777700 ; WITHOUT LAST
MOVEI D,(E) ; AND D
ANDI D,770000 ; WITH JUST LETTER
MOVSI B,-NDEVS ; AOBJN COUNTER
DEVLP: HRRZ 0,DEVS(B) ; GET ONE
CAIN 0,(A) ; FULL DEV?
JRST DISPA
CAIN 0,(D) ; ONE LETTER
JRST CH2DIG
CAIN 0,(E) ; 2 LTTERS
JRST CH1DIG
NXTDEV: AOBJN B,DEVLP ; LOOP THRU
IFN ITS,[
OUSR: HRRZ A,S.DIR(C) ; BLOCK OR UNIT?
TRNE A,2 ; SKIP IF UNIT
JRST ODSK
PUSHJ P,OPEN1 ; OPEN IT
PUSHJ P,FIXREA ; AND READCHST IT
MOVE B,T.CHAN+1(TB) ; RESTORE CHANNEL
MOVE 0,[PUSHJ P,DOIOT] ; GET AN IOINS
MOVEM 0,IOINS(B)
MOVE C,T.SPDL+1(TB)
HRRZ A,S.DIR(C)
TRNN A,1
JRST EOFMAK
MOVEI 0,80.
MOVEM 0,LINLN(B)
JRST OPNWIN
OSTY: HLRZ A,S.DEV(C)
IORI A,10 ; THE DONT LOSE BIT (DONT HANG ON INPUT DO ON OUTPUT)
HRLM A,S.DEV(C)
JRST OUSR
]
IFE ITS,[
PUSH TP,$TATOM
PUSH TP,EQUOTE NO-SUCH-DEVICE?
JRST CALER1
]
; MAKE SURE DIGITS EXIST
CH2DIG: LDB 0,[60600,,A]
CAIG 0,'9 ; CHECK DIGITNESS
CAIGE 0,'0
JRST NXTDEV ; LOSER
CH1DIG: LDB 0,[600,,A] ; LAST CHAR
CAIG 0,'9
CAIGE 0,'0
JRST NXTDEV
; HERE TO DISPATCH IF SUCCESSFUL
DISPA: HLRZ B,DEVS(B)
IFN ITS,[
HRRZ A,S.DIR(C) ; GET DIR OF OPEN
CAIN A,5 ; IS IT DISPLAY
CAIN B,ODIS ; BETTER BE OPENING DISPLAY
JRST (B) ; GO TO HANDLER
JRST WRONGD
]
IFE ITS, JRST (B)
IFN ITS,[
; DISK DEVICE OPNER COME HERE
ODSK: MOVE A,S.SNM(C) ; GET SNAME
.SUSET [.SSNAM,,A] ; CLOBBER IT
PUSHJ P,OPEN0 ; DO REAL LIVE OPEN
]
IFE ITS,[
; TENEX DISK FILE OPENER
ODSK: MOVE B,T.CHAN+1(TB) ; GET CHANNEL
PUSHJ P,STSTK ; EXPAND STRING ONTO STACK (E POINTS TO OLD P)
MOVE A,DIRECT-1(B)
MOVE B,DIRECT(B)
PUSHJ P,STRTO6 ; GET DIR NAME
POP P,C
MOVE D,T.SPDL+1(TB)
HRRZ D,S.DIR(D)
CAMN C,[SIXBIT /PRINTO/]
IORI D,100 ; TURN ON BIT TO SAY USE OLD FILE
MOVSI A,101 ; START SETTING UP BITS EXTRA BIT FOR MSB
TRNE D,1 ; SKIP IF INPUT
TRNE D,100 ; WITE OVER?
TLOA A,100000 ; FORCE NEW VERSION
TLO A,400000 ; FORCE OLD
HRROI B,1(E) ; POIT TO STRING
GTJFN
TDZA 0,0 ; SAVE FACT OF NO SKIP
MOVEI 0,1 ; INDICATE SKIPPED
MOVE P,E ; RESTORE PSTACK
JUMPE 0,GTJLOS ; FIND OUT WHAT HAPPENED
MOVE B,T.CHAN+1(TB) ; GET CHANNEL
HRRZM A,CHANNO(B) ; SAVE IT
ANDI A,-1 ; READ Y TO DO OPEN
MOVSI B,440000 ; USE 36. BIT BYES
HRRI B,200000 ; ASSUME READ
TRNE D,1 ; SKIP IF READ
HRRI B,300000 ; WRITE BIT
HRRZ 0,FSAV(TB) ; SEE IF REF DATE HACK
CAIN 0,NFOPEN
TRO B,400 ; SET DON'T MUNG REF DATE BIT
OPENF
JRST OPFLOS
MOVEI 0,C.OPN+C.READ
TRNE D,1 ; SKIP FOR READ
MOVEI 0,C.OPN+C.PRIN
MOVE B,T.CHAN+1(TB)
HRRM 0,-4(B) ; MUNG THOSE BITS
ASH A,1 ; POINT TO SLOT
ADDI A,CHNL0(TVP) ; TO REAL SLOT
MOVEM B,1(A) ; SAVE CHANNEL
PUSHJ P,TMTNXS ; GET STRING FROM TENEX
MOVE B,CHANNO(B) ; JFN TO A
HRROI A,1(E) ; BASE OF STRING
MOVE C,[111111,,140001] ; WEIRD CONTROL BITS
JFNS ; GET STRING
MOVEI B,1(E) ; POINT TO START OF STRING
SUBM P,E ; RELATIVIZE E
PUSHJ P,TNXSTR ; MAKE INTO A STRING
SUB P,E ; BACK TO NORMAL
PUSH TP,A
PUSH TP,B
PUSHJ P,RGPRS1 ; PARSE INTO FIELDS
MOVE B,T.CHAN+1(TB)
MOVEI C,RNAME1-1(B)
HRLI C,T.NM1(TB)
BLT C,RSNAME(B)
JRST OPBASC
OPFLOS: MOVEI C,(A) ; SAVE ERROR CODE
MOVE B,T.CHAN+1(TB)
HRRZ A,CHANNO(B) ; JFN BACK TO A
RLJFN ; TRY TO RELEASE IT
JFCL
MOVEI A,(C) ; ERROR CODE BACK TO A
GTJLOS: PUSHJ P,TGFALS ; GET A FALSE WITH REASON
JRST OPNRET
STSTK: PUSH TP,$TCHAN
PUSH TP,B
MOVEI A,4+5 ; COUNT CHARS NEEDED (NEED LAST 0 BYTE)
MOVE B,(TP)
ADD A,RDEVIC-1(B)
ADD A,RNAME1-1(B)
ADD A,RNAME2-1(B)
ADD A,RSNAME-1(B)
ANDI A,-1 ; TO 18 BITS
IDIVI A,5 ; TO WORDS NEEDED
POP P,C ; SAVE RET ADDR
MOVE E,P ; SAVE POINTER
PUSH P,[0] ; ALOCATE SLOTS
SOJG A,.-1
PUSH P,C ; RET ADDR BACK
INTGO ; IN CASE OVERFLEW
MOVE B,(TP) ; IN CASE GC'D
MOVE D,[440700,,1(E)] ; BYTE POINTER TO IT
MOVEI A,RDEVIC-1(B)
PUSHJ P,MOVSTR ; FLUSH IT ON
MOVEI A,":
IDPB A,D
HRRZ A,RSNAME-1(B) ; ANY SNAME AT ALL?
JUMPE A,ST.NM1 ; NOPE, CANT HACK WITH IT
MOVEI A,"<
IDPB A,D
MOVEI A,RSNAME-1(B)
PUSHJ P,MOVSTR ; SNAME UP
MOVEI A,">
IDPB A,D
MOVEI A,RNAME1-1(B)
PUSHJ P,MOVSTR
MOVEI A,".
IDPB A,D
ST.NM1: MOVEI A,RNAME2-1(B)
PUSHJ P,MOVSTR
SUB TP,[2,,2]
POPJ P,
MOVSTR: HRRZ 0,(A) ; CHAR COUNT
MOVE A,1(A) ; BYTE POINTER
SOJL 0,CPOPJ
ILDB C,A ; GET CHAR
IDPB C,D ; MUNG IT UP
JRST .-3
; MAKE A TENEX ERROR MESSAGE STRING
TGFALS: PUSH P,A ; SAVE ERROR CODE
PUSHJ P,TMTNXS ; STRING ON STACK
HRROI A,1(E) ; POINT TO SPACE
MOVE B,(E) ; ERROR CODE
HRLI B,400000 ; FOR ME
MOVSI C,-100. ; MAX CHARS
ERSTR ; GET TENEX STRING
JRST TGFLS1
JRST TGFLS1
MOVEI B,1(E) ; A AND B BOUND STRING
SUBM P,E ; RELATIVIZE E
PUSHJ P,TNXSTR ; BUILD STRING
SUB P,E ; P BACK TO NORMAL
TGFLS2: SUB P,[1,,1] ; FLUSH ERROR CODE SLOT
MOVE C,A
MOVE D,B
PUSHJ P,INCONS ; BUILD LIST
MOVSI A,TFALSE ; MAKE IT FALSE
POPJ P,
TGFLS1: MOVE P,E ; RESET STACK
MOVE A,$TCHSTR
MOVE B,CHQUOTE UNKNOWN PROBLEM IN I/O
JRST TGFLS2
]
; OTHER BUFFERED DEVICES JOIN HERE
OPDSK1:
IFN ITS,[
PUSHJ P,FIXREA ; STORE THE "REAL" NAMES INTO THE CHANNEL
]
OPBASC: MOVE C,T.SPDL+1(TB) ; C WAS CLOBBERED, GET IT BACK
HRRZ A,S.DIR(C) ; FIND OUT IF OPEN IS ASCII OR WORD
TRZN A,2 ; SKIP IF BINARY
PUSHJ P,OPASCI ; DO IT FOR ASCII
; NOW SET UP IO INSTRUCTION FOR CHANNEL