-
Notifications
You must be signed in to change notification settings - Fork 13
/
MUDLIB.BCL
2176 lines (2149 loc) · 55.4 KB
/
MUDLIB.BCL
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) 1980 by
Roy Trubshaw & Richard Bartle,
Essex University, Colchester. CO4 3SQ.
This software is furnished on the understanding that
it may be used and or copied only with the inclusion of this
notice. No title or ownership of this software is hereby
transferred. The information in this software is subject to
change without notice. No responsibility is assumed for the
use or reliability of this software.
Released by Richard Bartle exclusively for not for profit use
18 May 2020
*/
$nolist
get "mudlib"
get "dungen"
$list
manifest
$( REGIONSIZE : 6
INTEGRITY : #525252
DEBUGGING : FALSE
SIZE : LH
ISTTY : B14
BUFLENGTH : 150
TMP.BLOCKSIZE : 128
TTY6 : $6"tty"
$)
static
$( region : VEC REGIONSIZE
// **** Order must be same as order of FREESPACE parameters ****
origin : #377
extent : 0
quantum : -2
routine : NIL
nname : "the low-seg' freelist"
// **** ****
page : #377
freelist : 0
scbsize = SC.DEFAULT.SIZE
hibflg = (1<<22)\/1000 //Hibernate flags.
trmpar = (3<<18)\/1 //TRMOP. parameter flags
hwmain = #2776
months = (table //Month names for writedate.
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December")
snoopbuffer = vec 69
//Four word interrupt block
intblk = #4000000 //XWD 4,0
inttyp = 2 //EXP ER.ICC
retadr = 0 //EXP 0
ctcflg = 0 //EXP 0
stack = vec 100 //100 words of PDL stack
//Statics for testing access to mud (leave as NIL!!).
ppn = ? //User's PPn.
peen = ? //User's Pn.
guest = ? //User is a guest (from outside)
ttyno = ? //TTY udx.
jobno = ? //Jobnumber.
ctlno = ? //Controlling job number.
micstatus = ? //MIC status bits.
hsattrib = ? //Hi-seg attributes.
hsname = ? //Name of hi-seg.
hsppn = ? //PPn of hi-seg.
privved = ? //True if privileged.
logstr = false //Non zero means logging enabled.
linebuffer = vec BUFLENGTH //Line buffer.
chcnt = 0 //Character count.
nextch = 0 //next character
roomput = 0 //SCB for the .RM file
textput = 0 //ditto .TM file
objput = 0 //ditto .OM file
comput = 0 //ditto .CM file
perput = 0 //ditto .PM file
mapput = 0 //ditto .MM file
cmndput = 0 //ditto .GM file
oldscore = 0
rec = ? //pointer to record in dmpbuf
bufull = 3690556618 //buffer full name.string termination flag
first = true //for opening .PM file automatically
quitflg = true //Set to true if ^C gets u out.
maint = false //true if maintainer
room.been = ? //whether been in this room or not
dmpbuf = vec BUFFERS //input buffer for textput/roomput/objput/comput/perput/mapput
cbl = vec 1 //argument block to read above in in dump mode
ccnt = 0 //character count on output
//STATICS for vestigal BCPL library (Leave as NIL!!!!).
batch = ?
ccl = ?
callnm = ?
input = ?
output = ?
daytime = ?
udaytime = ?
err = ?
fl = ?
scb = ?
sl = ?
stackbase = ?
savpdl = ?
savt = ?
mainta = ?
chain = ?
lockflg = 0 //lets you out on ^C if 0
$)
let appendfile(dev,file,ext,ppn,error) = VALOF
$( let r,w,last=?,?,?
r_dofile(DEV,FILE,EXT,PPN,LABEL(NX),0,1,lookup.enter,rda,wrb,closefile)
w_words(r); last_w/128+1
useti(r,last)
SC.ERROR^r_LABEL(END.OF.FILE)
SC.READER^R_RDB // NON ASCII READ
SC.APPENDCL^R_SC.CLOSER^R
SC.CLOSER^R_CLOSEA
$( let ch=?
rdb(r,@ch)
wrb(r,ch)
$) repeat
end.of.file:
USETO(R,LAST)
SC.ERROR^R_ERROR
RESULTIS R
NX: resultis dofile(dev,file,ext,ppn,error,0,2,enter,sterr,wrb,closefile)
$)
and detch()=valof
$[ $pjob 2, 0
$setz 1, 0
$trmno. 2, 0
$seto 1, 0
$]
and Enq(chan) be
$( let addr=vec 4
!addr_#1000005
1!addr_142857
2!addr_chan
3!addr_$az"mud"+(-1<<18)
4!addr_0
$[ $move 1, addr
$enq. 1, 0
$trn
$]
$)
and Deq(chan) be
$( let addr=vec 1
!addr_#1000005
1!addr_142857
$[ $move 1, addr
$hrli 1, 1
$deq. 1, 0
$trn
$]
$)
and assign() be jar(@persona.door)<>enq(SC.CHANNEL^perput)
and deassign() be deq(SC.CHANNEL^perput)<>unjar(@persona.door)
AND FINDTMP(F,ERR) = VALOF // FINDS TMP:XXX, DOES A READ-DELETE
$( LET S=NEWVEC(SC.TMPCOR.SIZE+TMP.BLOCKSIZE)
LET NAME,BLOCK=SIXBIT(F),(-TMP.BLOCKSIZE<<18)+(SC.TMPCOR.SIZE-1)+S
LET REPLY=VALOF
$[ $HRLI AC,#2
$HRRI AC,NAME
$TMPCOR AC,0 // TMP: READ AND DELETE INTO S
$SETZM AC
$]
SC.TMPNAME^S_F>>18
UNLESS REPLY IOERROR(S,ERR.FINDTMP,ERR)
SC.FLAGS^S_(SC.TMPCOR.SIZE<<12)+1
SC.READER^S_READTMP
SC.WRITER^S_sterr
SC.CLOSER^S_FCLOSETMP
SC.ERROR^S_ERR
SC.TMPBYTEP^S_(SELECTOR 7:0:(SC.TMPCOR.SIZE-1))+S // JUST BEFORE BUFFER
SC.TMPLIMIT^S_SC.TMPCOR.SIZE+REPLY+S // LAST WORD READ
RESULTIS S
$)
AND READTMP(S,LVCH) BE
$(
!LVCH_VALOF
$[
$HRRZ SCBREG,S
$ILDB AC,SC.TMPBYTEP(SCBREG)
$]
IF (SC.TMPWORD^S)>SC.TMPLIMIT^S THEN !LVCH_'*E'
// WORD IS THE RH OF BYTEP
$)
AND FCLOSETMP(S) BE FREEVEC(S)
and CREATETMP(F,ERR) = VALOF
$( LET S=NEWVEC(SC.TMPCOR.SIZE+TMP.BLOCKSIZE)
IF NUMBARGS<2 THEN ERR_0
SC.FLAGS^S_(SC.TMPCOR.SIZE<<12)+1
SC.WRITER^S_WRITETMP
SC.READER^S_STERR
SC.CLOSER^S_CLOSETMP
SC.ERROR^S_ERR
SC.TMPNAME^S_F>>18
SC.TMPBYTEP^S_(SELECTOR 7:0:(SC.TMPCOR.SIZE-1))+S
RESULTIS S
$)
AND WRITETMP(S,C) BE
$(
$[ $MOVE SCBREG,S
$MOVE AC,C
$IDPB AC,SC.TMPBYTEP(SCBREG)
$]
$)
AND CLOSETMP(S) BE
$( LET NAME,BLOCK,Z=SC.TMPNAME^S<<18,((S+(SC.TMPCOR.SIZE-1)-SC.TMPWORD^S)<<18)\/(S+(SC.TMPCOR.SIZE-1)),0
FOR I=0 TO 4 WRITETMP(S,0) // CLEAR REST OF LAST WORD
UNLESS VALOF
$[
$SETOM AC
$HRLI B,#3
$HRRI B,NAME
$TMPCOR B,0 // TMPCOR WRITE
$SETZM AC
$] sterr()
FREEVEC(S)
$)
AND CLOSEA(R) BE
$( LET WD=SC.OWD^R
LET BUF=SC.OBUF^R+2
SETSTS(R,#17)
WRDMP(R,IOWD(WD-BUF+1,BUF),0)
(SC.APPENDCL^R)(R)
$)
AND LOOKUP.ENTER(CH,FILESPEC)=LOOKUP(CH,FILESPEC)&ENTER(CH,FILESPEC)
AND DOFILE(DEV,FILE,EXT,PPN,ERROR,MODE,BUFFS,SELECT,RD,WR,CL)=VALOF
$( LET SIXDEV, date=DEV=0\/LH&&dev\=0\/(LH&&DEV=0&!DEV=0)->$6 "DSK",SIXBIT(DEV), valof $[ $date 1, 0 $]
and DEVCHR=VALOF
$[ $MOVE AC, SIXDEV
$DEVCHR AC, 0
$]
and DEVSIZ=VALOF
$[ $MOVEI AC, B
$MOVE B, MODE
$MOVE C, SIXDEV
$DEVSIZ AC, 0
$SETZ AC, 0
$]
and scb,ch=?,?
IF MODE = 0 & (DEVCHR&ISTTY)\=0 THEN // INCHWL STREAM
$( LET TTYNAME=VALOF $[ $GETLIN AC, 0 $]
LET PHYSDEV=VALOF $[ $MOVE AC, SIXDEV
$DEVNAM AC, 0
$TRN
$]
IF PHYSDEV=TTYNAME THEN RESULTIS TTY
$)
CH_FINDCHANNEL()
IF CH<0 THEN DOFILE..ERROR(0,ERR.NOCHANNEL,ERROR)
SCB_NEWVEC(SCBSIZE)
clearvec(scb,scbsize)
SC.STATUS^SCB, SC.DEV^SCB, SC.OBUFHDR^SCB, SC.IBUFHDR^SCB_
MODE, SIXDEV, WR=0\/WR=sterr->0, SC.OBUF+SCB, RD=0\/RD=STERR->0, SC.IBUF+SCB
SC.CHANNEL!SCB_CH<<23 // ! TO CLEAR REST OF WORD
SC.COUNT^SCB_6
SC.FILENAME^SCB_SIXBIT(FILE)
SC.EXT^SCB_LH&&SIXBIT(EXT)
SC.PPN^SCB_PPN
SC.FLAGS^SCB_B0+B35
SC.MODE of scb_mode
IF DEVCHR\=!#74 & (DEVCHR & (1 << (BYTE 4:0)&&MODE)) = 0 DOFILE..ERROR(SCB,ERR.BADMODE,ERROR)
SC.READER^SCB_RD
SC.WRITER^SCB_WR
SC.CLOSER^SCB_CL
SC.IN^SCB_$IN<<27\/(CH<<23)
SC.OUT^SCB_$OUT<<27\/(CH<<23)
SC.STATZ^SCB_$STATZ<<27\/(CH<<23)+#740000
SC.PROTECTION^SCB_#477
SC.USETI^SCB_$USETI<<27\/(#36000003)+(CH<<23) // USETI CHANNEL,@3(P)
SC.USETO^SCB_$USETO<<27\/(#36000003)+(CH<<23)
SC.SIZE^SCB_SCBSIZE
SC.TIME^scb_valof $[ $mstime 1, 0 $]/60000
date_((date-61)/372)*372+61
SC.CREATEDATE^SCB_date
SC.HIDATE^SCB_(BYTE 3:12)&&date
SC.ERROR^SCB_ERROR
SC.OBUF!SCB_B0 // VIRGIN OUTPUT BUFFER RING (! TO CLEAR REST OF WORD)
SC.IBUF!SCB_B0 // DITTO INPUT
UNLESS HOPEN(CH,SC.STATUS+SCB) DO DOFILE..ERROR(SCB,ERR.NODEV,ERROR)
UNLESS SELECT(CH,SC.COUNT+SCB) DO DOFILE..ERROR(SCB,ERR.NOFILE,ERROR)
IF BUFFS <= 0 THEN BUFFS_LH&&DEVSIZ
IF (MODE) LE #14 THEN // MAKE THE BUFFER RINGS
$( UNLESS WR=STERR \/ WR=!#74 DO SC.OBUF^SCB_GETRING(OUTBUF,CH,BUFFS,RH&&DEVSIZ)
UNLESS RD=STERR \/ RD=!#74 DO SC.IBUF^SCB_GETRING(INBUF,CH,BUFFS,RH&&DEVSIZ)
$)
RESULTIS SCB
$)
AND GETRING(GETBUF, CHANNEL, NO, SIZE) =VALOF
$( LET T=JBFF
LET BUF=NEWVEC(SIZE*NO-1)
JBFF_BUF
GETBUF(CHANNEL,NO)
JBFF_T
RESULTIS BUF+1
$)
AND CLOSEFILE(SCB) BE
$( LET CH=SC.CHANNEL^SCB
RELEASE(CH,0)
FREEBUFRING( SC.IBUF^SCB )
FREEBUFRING( SC.OBUF^SCB )
FREE( SCB )
$)
AND FREEBUFRING(R) BE UNLESS R=!#74 DO
$( LET P,Q=R,R
$( IF P<Q THEN Q_P; P_RH^P $) REPEATUNTIL P=R
FREE(Q-1)
$)
AND FINDCHANNEL()BE
$[ $MOVEI AC, #17
TRYCH: $MOVE B, AC
$DEVCHR B, 0 // RETURNS 0 IF NO SUCH CHANNEL
$JUMPE B, RESULT
$SOJGE AC, TRYCH
$SETOM 0, AC // RETURN -1 IF NO CHANNEL EXISTS
RESULT:
$]
AND DOFILE..ERROR(SCB,ERR,LAB) BE
$( IF SCB THEN
$( RELEASE(SC.CHANNEL^SCB)
FREE(SCB)
$)
GOTO IOERROR+2 // GO ON AS IOERROR
$)
AND IOERROR(ERRSCB,ERRCODE,ERRPARAM) BE
$( SCB, ERR_ERRSCB, ERRCODE
if errparam jump(errparam)
outz($az"?*C*L?MUDIOE MUD I/O error ")
IOMESSAGE()
FINISH
$)
AND IOMESSAGE() BE outz($az"*C*L")
AND RDA(SCB,LVCH) BE
$[ $MOVE SCBREG, SCB
NEXT: $SOSLE 0, WSC.ICOUNT(SCBREG)
$JRST GETOK
$XCT 0, WSC.IN(SCBREG) // IN CHANNEL,0
$JRST GETOK // NOT AT E-O-F
$XCT 0, WSC.STATZ(SCBREG) // STATZ CHANNEL,#740000
$JRST @ERRSTATUS
$MOVEI AC, '*E'
$MOVEM AC, @LVCH
$( return $)
GETOK: $ILDB AC, WSC.IBYTE(SCBREG)
$JUMPE AC, NEXT // OMIT ZERO CHARACTERS, TOO
$HRRZ 2, WSC.IBYTE(SCBREG) // LOOK AT THE WORD THAT THE BYTE CAME FROM
$TDNE ONE, 0(2) // AND IF B35=1 SKIP THE WORD (IT'S A LINE NUMBER)
$JRST NEXT // EVENTUALLY WE'LL DO THIS FASTER&REMEMBER THE NO
$MOVEM AC, @LVCH // SET THE RESULT
$]
AND RDB(SCB,LVCH) BE
$[ $MOVE SCBREG, SCB
NEXT: $SOSLE 0, WSC.ICOUNT(SCBREG)
$JRST GETOK
$XCT 0, WSC.IN(SCBREG) // IN CHANNEL,0
$JRST GETOK // NO AT E-O-F
$XCT 0, WSC.STATZ(SCBREG) // STATZ CHANNEL,#740000
$JRST @ERRSTATUS // REAL STATUS ERROR
$JRST @EOF // END-OF-FILE CODE
GETOK: $ILDB AC, WSC.IBYTE(SCBREG)
$MOVEM AC, @LVCH // SET RESULT
$]
AND WRB(SCB,CH) BE unless detch()
$[ $MOVE SCBREG, SCB
$SOSLE 0, WSC.OCOUNT(SCBREG)
$JRST PUTOK
$XCT 0, WSC.OUT(SCBREG)
$JRST PUTOK
$JRST @ERRSTATUS
PUTOK: $MOVE AC, CH
$IDPB AC, WSC.OBYTE(SCBREG)
$]
AND RDDMP(SCB,BUFFLIST) BE
$[ $MOVE SCBREG, SCB
$HLL B, WSC.IN(SCBREG)
$HRRI B, BUFFLIST
$XCT 0, B
$( return $)
$XCT 0, WSC.STATZ(SCBREG)
$JRST @ERRSTATUS
$JRST @EOF
$]
AND WRDMP(SCB,BUFFLIST) BE
$[ $MOVE SCBREG, SCB
$HLL B, WSC.OUT(SCBREG)
$HRRI B, BUFFLIST
$XCT 0, B
$( return $)
$JRST @ERRSTATUS
$]
and sterr() = IOERROR
AND NEWVEC(S) = VALOF
$( LET N = S+2
LET Q, P = @FREELIST, FREELIST
UNTIL P=!#74 DO
$( LET S = SIZE^P
IF S>=N THEN
$( LET K = S-N
TEST K<4 THEN
$( LINK^Q_LINK^P
LINK^P_INTEGRITY
RESULTIS P+1
$) OR
$( LET L = P+K
SIZE^P_K
SIZE^L_N
LINK^L_INTEGRITY
RESULTIS L+1
$)
$)
Q_P
P ^_LINK
$)
// Expand the current region if necessary
$( LET D, ORIG, SIZ = NIL, NIL, NIL
AND Q = QUANTUM
TEST QUANTUM<0 THEN
$( D_-1
SIZ_#1000*-QUANTUM
ORIG_#1000*(1+PAGE+QUANTUM)
$) OR
$( D_1
ORIG_#1000*PAGE
SIZ_#1000*QUANTUM
$)
UNTIL Q=!#74 DO
$( UNLESS GETPAGE(PAGE) STOREERROR(S,ERR.NEWPAGE,@ORIGIN)
PAGE+_D
Q-_D
$)
SIZE^ORIG, LINK^ORIG_SIZ, 0
LINK^ORIG_INTEGRITY
FREEVEC(ORIG+1)
RESULTIS NEWVEC(S)
$)
$)
AND FREEVEC(B) BE
$( LET P0, Q, P = B-1, @FREELIST, FREELIST
LET N = SIZE^P0
UNLESS LINK^P0=INTEGRITY DO STOREERROR(B,ERR.FREEBAD,@ORIGIN)
UNTIL P=!#74\/P>P0 DO
$( Q_P
P_LINK^P
$)
TEST P0+N=P THEN
$( N+_SIZE^P
SIZE^P0, LINK^P0_N, LINK^P
$) OR SIZE^P0, LINK^P0_N, P
$( LET S = SIZE^Q
TEST Q+S=P0 THEN SIZE^Q, LINK^Q_S+N, LINK^P0 OR LINK^Q_P0
$)
$)
AND GETPAGE(N) = VALOF TEST (N<<9) < SL THEN RESULTIS FALSE OR
$[ $MOVE B, !((1<<18)+C)
$MOVEI C, 1
$MOVE D, N
$PAGE. B, 0
$CAIN B, 3 //PAGE ALREADY EXISTS?
$JRST OK //THEN OK
$CAIE B, #12 //NO ROOM IN WORKING SET
$JRST FAIL //NO, THEN CANT HELP
$MOVE B, !((1<<18)+C)
$HRLI D, #200000 //TRY TO CREATE ON DISK
$PAGE. B, 0
$CAIN B, 3 //PAGE EXISTS?
$JRST OK //YES, THEN OK
FAIL: $SETZ AC, 0
$( return $)
OK: $MOVE AC, N
$LSH AC, 9
$CAMGE AC, FL //LOWER THAN LAST FL?
$MOVEM AC, FL //YES, BECOMES NEW FL
$SETO AC, 0
$]
AND STOREERROR(S,ERR,ATORIGIN) BE
outz($az"*C*L?MUDNFF - Newvec or Freevec failure.*C*L") <> FINISH
AND OUT(FS,A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z) be
$( LET FV=VEC 128
UNPACKSTRING(FS,FV)
FV!(1+FV!0)_-1
OV(OUTPUT,FV+1,@A)
$)
AND WRITE(ST,FS,A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z) be
$( LET FV=VEC 128
UNPACKSTRING(FS,FV)
FV!(1+FV!0)_-1
OV(ST,FV+1,@A)
$)
and writesecs(str,t) be
$( let h, m, s=t/3600, (t rem 3600/60), t rem 60
if h write(str," :N hr:S", h, h=1->"","s")
if m write(str," :N min:S",m, m=1->"","s")
if s write(str," :N sec:S",s, s=1->"","s")
$)
AND OV(STR,C,A)=VALOF
$( SWITCHON !C INTO
$( CASE -1:
RESULTIS A // END OF STRING
DEFAULT:
WRITECH(STR,!C); C+_1; LOOP
CASE ':':
C+_1
SWITCHON !C INTO
$( CASE 'N':
CASE 'n':
WRITENO(STR,!A)
ENDCASE
CASE '8':
WRITE8(STR,!A)
ENDCASE
case '6':
there_!a
CASE 'F':
case 'f':
WRITE6(STR,!A)
ENDCASE
CASE 'S':
CASE 's':
WRITES(STR,!A)
ENDCASE
case 'P':
case 'p':
writename(str,!A)
endcase
case 'U':
case 'u':
writeuc(str,!a)
endcase
case 'r':
case 'R':
$( let t, r=tabs!(!a-1), random(LH of t)+1
dscribe((r rem 2 -> RH, LH) from t!(r/2), comput)
$)
endcase
case 'i':
case 'I':
inventory(!A, 0)
endcase
case 'D':
case 'd':
writedate(str,!a)
endcase
case 'T':
case 't':
writetime(str,!a)
endcase
CASE 'C':
CASE 'c':
WRITECH(STR,!A)
ENDCASE
CASE 'Z':
CASE 'z':
WRITEZ(STR,!A)
ENDCASE
CASE 'G':
CASE 'g':
ENDCASE
CASE ':':
C+_1
default 0 ... #177:
writech(str,':')
loop
$)
C+_1
A+_1
$)
$) REPEAT
AND WRITE8(S,N) BE
$( UNLESS 0<=N<=7 THEN WRITE8(S,n>>3)
WRITECH(S,(N&7)+'0')
$)
AND WRITENO(S,N) BE
$( IF N<0 THEN N_-N <> WRITECH(S, '-')
WRITEPN(S,N)
$)
AND WRITEPN(S,N) BE
$( IF N>9 THEN WRITEPN(S,(N/10))
WRITECH(S,N REM 10 + '0')
$)
AND OUTS(S) BE
$( let p=selector 7:29:s
and n=valof $[ $LDB AC, p $]
for i=1 to n do writech(output,valof $[ $ILDB AC, p $])
$)
AND WRITES(S,STR) BE
$( let p=selector 7:29:str
and n=valof $[ $LDB AC, P $]
for i=1 to n do writech(s,valof $[ $ILDB AC, p $])
$)
AND WRITE6(S,N) BE
$( MANIFEST $( L6=BYTE 6:30 $) // LEFTMOST 6 BITS
UNTIL N=!#74 DO WRITECH(S,L6&&N+#40)<>N_N<<6
$)
and writez(str,az,nocrlf) be unless detch()
if az then prompted_false<>
test str=tty/\logstr=!#74 /\ snoopedon=!#74 then
$[ $MOVE AC, az
$SKIPN 0(AC)
$( return $)
$OUTSTR 0(AC)
$setz 1, 0
$skipn nocrlf
$skpinc
$( return $)
$outstr $az "*C*L"
$] or
$( let ptr=selector 7:36:az
writech(str,valof
$[ $ILDB AC, ptr
$SKIPN AC
$( return $)
$] ) repeat
if str=tty unless valof
$[ $setz 1, 0
$skipn nocrlf
$skpinc
$seto 1, 0
$] outs("*C*L")
$)
and writeudate() be
$( let when = (LH from ud.time())-(LH from LSTM of rec)
outz($az "Your last game was ")
test when ge 2 then Write(tty, ":N days ago.*C*L", when) or
$( Write(tty, ":Sday at ", when->"yester","to")
when_(RH from LSTM of rec)*24
write(tty,":N::", when/#1000000)
when_(when rem #1000000)*60
if when/#1000000 ls 10 Writech(tty,'0')
write(tty,":N::", when/#1000000)
when_(when rem #1000000)*60
if when/#1000000 ls 10 Writech(tty,'0')
write(tty,":N.*C*L", when/#1000000)
$)
$)
AND RUN(D,F,E,PP,S) BE
$( LET T,U,V,W,X,Y,Z=?,?,?,?,?,?,?
SWITCHON NUMBARGS() INTO
$( CASE 1: F_D;D_$SIXBIT "SYS"
CASE 2: E_0
CASE 3: PP_0
CASE 4: S_0
$)
T,U,V,W,X,Y,Z_SIXBIT(D),SIXBIT(F),SIXBIT(E),0,PP,0,0
$[ $HRLI AC, 7(P) // LV T
$HRRI AC, #144 // JOBS LOWEST CORE+4
$BLT AC, #152 // THE 7 WORD ARG BLOCK
$MOVS AC, CODEX // XWD #140,CODE
$BLT AC, #143 // MOVE THE CODE DOWN
$HRL PDL, S // STARTING OFFSET
$HRRI PDL, #144
$MOVE AC, ONEONE
$JRST #140
CODE: $CORE AC, 0 // REDUCE CORE
$HALT #141
$RUN PDL, 0 // CALL THE PROGRAM
$HALT #143
CODEX: $EXP #140, CODE
ONEONE: $EXP #1, #1
$]
$)
AND SIXBIT(S) = VALOF
$[ $HLRZ AC, S
$JUMPE AC, STRSIX
$MOVE AC, S // ALREADY SIXBIT
$( return $)
STRSIX: $SETZ AC, 0
$SKIPN 0, S
$( return $)
$MOVSI B, LH&&(BYTE 7:29)
$HRR B, S
$LDB C, B
$CAILE C, 6
$MOVEI C, 6
$HRLZI E, #600
SIXL3: $SOSGE 0, C
$( return $)
$ILDB D, B
$CAIL D, #40
$CAILE D, #137
$JRST SIXL1
$SUBI D, #40
SIXL2: $IDPB D, E
$JRST SIXL3
SIXL1: $CAIGE D, #140
$MOVEI D, #100
$SUBI D, #100
$JRST SIXL2
$]
AND LOOKUP(CH,ADDR)=IOUUO($LOOKUP,CH,ADDR)
AND ENTER(CH,ADDR)=IOUUO($ENTER,CH,ADDR)
AND HOPEN(CH,ADDR)=IOUUO($OPEN,CH,ADDR)
AND RELEASE(CH,ADDR)=IOUUO($RELEAS,CH,ADDR)
AND OUTBUF(CH,ADDR)=IOUUO($OUTBUF,CH,ADDR)
AND INBUF(CH,ADDR)=IOUUO($INBUF,CH,ADDR)
AND SETSTS(STREAM,VAL) = IOUUO($SETSTS,SC.CHANNEL^STREAM,VAL)
AND GETSTS(SCB) = VALOF
$[ $MOVE SCBREG, SCB
$MOVE B, SC.CHANNEL(SCBREG)
$IOR B, GWD
$XCT B
$( return $)
GWD: $GETSTS 0, AC
$]
AND USETI(STR,BL) = VALOF
$[ $MOVE SCBREG, STR
$XCT SC.USETI(SCBREG)
$]
AND USETO(STR,BL) = VALOF
$[ $MOVE SCBREG, STR
$XCT SC.USETO(SCBREG)
$]
and inuuo(str,addr)=not iouuo($in,SC.CHANNEL^str,numbargs()=1->0, addr)
and outuuo(str,addr)=not iouuo($out,SC.CHANNEL^str,numbargs()=1->0,addr)
and readch(stream,lvch,val) be
$( (SC.READER^stream)(stream,lvch)
if numbargs()=3 return
if logstr /\ bstr=!#74 then wrb(logstr,!lvch)
unless bstr checksnoop(!lvch)
$)
and outch(c) be writech(output,c)
and checksnoop(ch) be
$( ccnt_valof switchon ch into
$( case '*C': resultis 0
case '*T': resultis (ccnt+8)-(ccnt rem 8)
case '*0' ... '*B':
case '*L' ... '*P': resultis ccnt
default '*0' ... '*D': resultis ccnt+1 //near enough...
$)
if firstsnoop
$( firstsnoop_false
checksnoop(SNOOPROMPT)
$)
if snoopedon then
$( !snoopbuffer+_1
snoopbuffer!!snoopbuffer_ch
if !snoopbuffer=69 \/ linebreak(ch) then
$( for i=!#74 to 35 do if (1<<i) bitand snoopedon then
$( let block=getmblock()
packstring(snoopbuffer,block+2)
send(i, block, K.SNPA,INFO of block)
$)
!snoopbuffer_0
if linebreak(ch) checksnoop(SNOOPROMPT)
$)
$)
$)
and writech(stream,ch) be
$( if logstr /\ stream ne logstr wrb(logstr, ch)
checksnoop(ch) //would be better if did this the logstr way, not differently
$[ $HRRZ SCBREG, stream
$HRRZ AC, WSC.WRITER(SCBREG)
$JRST 2(AC)
$] $)
AND CLOSE(STREAM) BE
$[ $HRRZ SCBREG, STREAM
$HRRZ AC, WSC.CLOSER(SCBREG)
$JRST 2(AC)
$]
AND PACKSTRING(V,S) = VALOF
$[ $MOVSI AC, LH&&(BYTE 7:36)
$HRR AC, S
$MOVE 2, V // THE UNPACKED STRING
$MOVE 3, 0(2) // CHARACTER COUNT
$ANDI 3, #177 // MAX 127 CHARACTERS
$MOVE 5, 3
$IDIVI 3, 5 // WORDS OF DEST'N -> 3
$SETZM 0(AC) // FIRST WORD OF DEST'N STRING
$JUMPE 3, PSLP // BUT NO MORE!
$HRLI 4, 0(AC)
$HRRI 4, 1(AC)
$ADDI 3, #777777(4)
$BLT 4, 0(3)
PSLP: $MOVE 3, 5
PSL: $IDPB 5, AC
$ADDI 2, 1
$MOVE 5, 0(2)
$SOJGE 3, PSL
$MOVE AC, S// RESULTIS THE DESTINATION
$]
AND UNPACKSTRING(V,S) = VALOF
$[ $MOVSI AC, LH&&(BYTE 7:29)
$HRR AC, V
$LDB 3, AC
$MOVEM 3, @S //THE COUNT
$JUMPN 3, SOME
$MOVE AC, S // RESULT FOR ..
$( return $) // ZERO COUNT
SOME: $MOVN 3, 3
$HRLZ 3, 3
$HRR 3, S //-COUNT,,V
UL: $ILDB 4, AC
$MOVEM 4, 1(3)
$AOBJN 3, UL
$MOVE AC, S // RESULTIS THE DESTINATION
$]
AND IOUUO(FN,ACC,ADDR) = VALOF
$[ $SETOM 0, AC
$MOVE B, FN
$LSH B, 27
$HRLZ C, ACC
$LSH C, 5
$IOR B, C
$HRR B, ADDR
$XCT 0, B
$SETZM 0, AC // FALSE IF DIDN'T SKIP
$]
AND IOWD(N,BL) = VALOF
$[ $MOVE AC, BL
$SUBI AC, 1
$MOVN B, N
$HRL AC, B
$]
AND ECHO() BE
$[ $SETO AC, 0
$GETLCH AC
$TLZ AC, B15>>18
$SETLCH AC
$]
AND NOECHO() BE
$[ $SETO AC, 0
$GETLCH AC
$TLO AC, B15>>18
$SETLCH AC
$]
AND WORDS(ST) = VALOF
$[ $SETZ AC, 0
$MOVE SCBREG, ST
$SKIPGE WSC.FLAGS(SCBREG)
$MOVE AC, WSC.WORDS(SCBREG)
$JUMPGE AC, FIN
$HLRE AC, AC
$MOVN AC, AC
FIN:
$]
AND LABEL(LAB) = VALOF
$[ $MOVE AC, P
$SUBI AC, @0(T)
$HRL AC, AC
$HRR AC, LAB
$]
AND JUMP(LAB) BE
$[ $HRRZ AC, LAB
$HLRZ P, LAB
$JRST 0(AC)
$]
and resetgame()=valof
$( let str=?
unless supers
$( str_dofile(disc, mud6, $6"exe",mainta, label(rats),0,0,lookup, sterr,sterr, closefile)
if rename(str) supers_true
$)
Outs("*C*LEverything in the game has been reset to its starting state!*C*L")
rats: resultis supers
$)
and initialise() be
chain_findtmp(callnm->callnm,$6"mud", label(notch))
//dofile(disc,callnm->callnm,$6"mud",$6"tmp",0,label(notch),0,2,lookup,rda,sterr,closefile)
$( let ch,vect,str=?,newvec(2),vec 9
readch(chain,@ch)
if ch ne '*^A' then abort()
readch(chain,@ch)
!str_0
$( !str+_1
str!!str_ch
readch(chain,@ch)
$) repeatwhile 'a' le ch le 'z' \/ !str=9
unless ch=8\/ch=3 abort()
packstring(str,vect)
readno(chain, @str)
unless daytime-str ls TIMECHK \/ daytime+WHOLEDAY-str ls TIMECHK abort()
Readno(chain, @daytime)
readno(chain, @room)
readno(chain,@ps.word)
readno(chain,@oldscore)
room_find.room(room)
if room room_LH of room
logstr_ch=3->false,appendfile($6"dsk",vect,$6"log",ppn,label(prob))
if false do
prob: logstr_false
chain_vect
$)
if false do
notch: chain_false
access()
profile_getmblock()
name_profile+14
me_name
SENDER of profile,LINK of profile_player.no,0
INFO of profile,PNAME of profile_player.bit,name
quitflg_1
player.names!player.no_(profile<<18) bitor name
createprofile()
quitflg_true
unless room room_random(!stlist)!(stlist+1) //Select a random start.
oldroom_room
savescr_SCORE of profile
unless savescr savescr_-1
CROOM of profile_room
JBNUM of profile_jobno
OPR of profile_privved
jobnos!player.no_jobno
unless chain write(tty, "*C*LHello:s, :p!*L*S*C*L", (games.played of profile)>1->" again","",name)
if YOULLBESORRY entered("joined")
room.been_newvec(max.room.no/36)
clearvec(room.been,max.room.no/36)
clearvec(fight,35)
objct_fake.node("that")
test us(me) \/ (A.HIDE bitand ATTRIB of room) then
for i=0 to 35 unless i=player.no
$( let them=player.names!i
unless them loop
them_LH from them
if A.SILENT bitand ATTRIB of CROOM of them loop
if us(PNAME of them) transmit(i,0,K.INH,GAMES.PLAYED of profile-1)
$)
or sendall(true,K.INH,false,true,GAMES.PLAYED of profile-1)
lvrdoor_room+DOOR
lvqdoor_queue.doors+player.no
lvqueue_queue+player.no
lvcarry_@carry
setbit()
unless WIZARD of profile cccnt_CCTRIP*10
if maint Outz($az"^C trap is OFF*C*L")<>Ctrap()
unless BZK/\BERSERK of profile /\ demo
$( describe(room)
been.in(RNUMB of room)_true
$)
alive()
if BZK/\BERSERK of profile/\ demo
$( outz("*C*LSorry, there's a demonstration in progress, no berserkers.*C*L")
quit()
$)
$)
and been.in(num, val)=valof
$( let sel=selector 1:num rem 36:num/36
test numbargs()=2 then sel of room.been_val //alternatively, define lhs()...
or resultis sel of room.been
$)
and readno(str,addr)=valof
$( let ch,neg=?,1
!addr_0
readch(str,@ch)
if ch='-' neg_-1<>readch(str,@ch)
while '0' le ch le '9' do
$( !addr_!addr*10-'0'+ch
readch(str,@ch)
$)
!addr*_neg
resultis !addr
$)
and abort() be
$( outz($az"*C*LSomething suspicious here...*C*L")
finish
$)
and entered(s) be if YOULLBESORRY //all these YOULLBESORRY's to cut down code compiled
$( let ap, ch, tmpfil=?, ?, ?
ap_appendfile(DISC, mud6, $6"log", MPPN, label(wot))
$( LET S = SIXBIT("idm")>>18
LET JOBNO = VALOF $[ $PJOB AC, 0 $]
(BYTE 6:30)&&S,(BYTE 6:24)&&S,(BYTE 6:18)&&S :=
JOBNO/100+('0'-#40),(JOBNO/10)REM 10+('0'-#40),JOBNO REM 10+('0'-#40)
tmpfil_dofile(DISC,s,$6"tmp",0,label(try1),0,2,lookup,rda,sterr,closefile)
if false
try1: tmpfil_dofile(DISC,s,$6"tmp",0,label(try2),0,2,lookup,rda,sterr,closefile)
if false
try2: tmpfil_false
$)
if tmpfil
$( for i=1 to 8
$( Readch(tmpfil, @ch)
Writech(ap, ch)
$)
writech(ap,'*T')
Close(tmpfil)
$)
write(ap,"[:8,:8]*T:D*T:T*T:P :S :6, pts=:N.*C*L",
LH from ppn, RH from PPN,
valof $[ $date ac, 0, $],
valof $[ $mstime ac, 0 $],
me, s, mud6,
STAMINA of profile le 0 -> -1,SCORE of profile)
close(ap)