-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtell.mud
138 lines (117 loc) · 4.71 KB
/
tell.mud
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
<NEWTYPE PSTRING WORD>
;"A PSTRING is a 36-bit string containing 5 characters of 7 bits. This is of course grossly PDP-10 specific, but easily fakeable provided WORD is at least 35 bits"
<DEFINE PSTRING (INSTR "AUX" (BP 36) (OBJ #PSTRING 0))
<MAPF <>
<FUNCTION (CH)
<COND (<G? <SET BP <- .BP 7>> 0>
<SET OBJ <CHTYPE <PUTBITS .OBJ <BITS 7 .BP> <ASCII .CH>> PSTRING>>)
(T <MAPLEAVE .OBJ>)
>
>
.INSTR>
>
; STRINGP converts a PSTRING to a STRING
<DEFINE STRINGP (OBJ "AUX" (BP 36) C)
<MAPF ,STRING
<FUNCTION ()
<COND (<G? <SET BP <- .BP 7>> 0>
<COND (<N==? <SET C <CHTYPE <GETBITS .OBJ <BITS 7 .BP>> FIX>>
0>
<MAPRET <ASCII .C>>)
(T <MAPRET>)>)
(T <MAPSTOP>)>>>>
;"F1 upper 18 bits are length to print (from S1?), if not zero"
<DEFINE TELL(S1 "OPTIONAL" (F1 ,POST-CRLF) S2 S3 "AUX" L)
#DECL ("VALUE" ATOM <PRIMTYPE STRING> "OPTIONAL" FIX
<OR STRING FALSE> <OR STRING FALSE>)
<AND <NOT <0? <CHTYPE <ANDB .F1 ,PRE-CRLF> FIX>>> <CRLF>>
<SET L <CHTYPE <GETBITS .F1 <BITS 18 18>> FIX>>
<AND <0? .L> <SET L <LENGTH .S1>>>
<PRINTSTRING .S1 .OUTCHAN .L>
<AND <ASSIGNED? S2> <PRINTSTRING .S2>>
<AND <ASSIGNED? S3> <PRINTSTRING .S3>>
<AND <NOT <0? <CHTYPE <ANDB .F1 ,POST-CRLF> FIX>>> <CRLF>>
<SETG TELL-FLAG T>
>
; Read a line after printing the prompt
; ALT means accept only alternate terminator character
; (ALT not supported yet)
<DEFINE READST (INBUF PROMPT ALT)
<PRINC .PROMPT>
<PRINC !\ >
<READSTRING .INBUF .INCHAN %<STRING <ASCII 10>> >
>
;"A DSKDATE contains
Time in half-seconds in 0-17
day of month ( 1-31) in 5 bits at bit 18
month number ( 1-12) in 4 bits at bit 23
year of century in 7 bits at bit 27
(Yes, it's not Y2K safe)"
;"It's not necessary to do all the sets, but nesting putbits calls will
make my head hurt a lot -- MTR"
<DEFINE DSKDATE ("AUX" (DVEC <GETTIMEDATE>) (W #WORD 0) TM)
<SET W <PUTBITS .W <BITS 18 0> <+ </ <7 .DVEC> 500000> <* <1 .DVEC> 2> <* <2 .DVEC> 120> <* <3 .DVEC> 7200>>>>
<SET W <PUTBITS .W <BITS 7 27> <MOD <6 .DVEC> 100>>> ;"Year"
<SET W <PUTBITS .W <BITS 4 23> <5 .DVEC>>> ;"Month"
<SET W <PUTBITS .W <BITS 5 18> <4 .DVEC>>> ;"Day of Month"
>
; "ATMFIX takes the atom, gets the first 36 bits of the PNAME (as with PSTRING), does some bit manipulation on it and on the value of SRUNM (the user name), and returns the result as a fix. Probably intended to prevent save file sharing
ATMFIX may also be passed a PSTRING, in which case it does the same bit
manipulation as it would on an atom PNAME
The bit manipulation rests on the assumption that the top two bits of a character
are never both set (no lowercase or a few other symbols)"
<DEFINE ATMFIX (A)
<COND
(<TYPE? .A ATOM> <ATMFIX1 <PSTRING <PNAME .A>>>)
(ELSE <ATMFIX1 .A>)
>
>
<DEFINE ATMFIX1 (PNW "AUX" (MSK *402010040200*))
<CHTYPE <XORB <ORB <LSH <ANDB .PNW .MSK> -1> .PNW> <PSTRING ,SRUNM>> FIX>
>
; "FIXSTR is the inverse of ATMFIX. It takes a FIX and returns a STRING
which is the PNAME of the ATOM which was previously given to ATMFIX."
<DEFINE FIXSTR (F "AUX" PNW (MSK *402010040200*))
;"Missing is the <XOR ... <PNAME ,SRUNM>>, applied to .F before the below"
<SET F <XORB <PSTRING ,SRUNM> .F>>
<STRINGP <ANDB <XORB <LSH <ANDB .F .MSK> -1> <EQVB>> .F>>
>
<DEFINE WINDOW-YEAR (Y)
<COND (<G=? .Y 75> <+ 1900 .Y>) (T <+ 2000 .Y>)>
>
<DEFINE GXUNAME () "MTRZORK">
<SETG XUNM "MTRZORK">
<SETG SCRIPT-CHANNEL <>>
<DEFINE STARTER () 1>
<DEFINE GETSYS () <> >
<DEFINE TTY-INIT (ARG) T>
<DEFINE TTY-UNINIT () T>
<DEFINE EXCRUCIATINGLY-UNTASTEFUL-CODE () <> > ;"I don't know what this is supposed to do"
<DEFINE CTRL-S () <>> ;"Interrupt handler -- not implemented"
<SETG STACKDUMP-ATOMS-TO-SKIP '(COND REPEAT PROG BIND AND OR * + /)>
<DEFINE STACKDUMP ("OPT" (CF <FFRAME>))
<REPEAT ()
<COND (<NOT <MEMQ <FUNCT .CF> ,STACKDUMP-ATOMS-TO-SKIP>>
<PRINT <FUNCT .CF>>
<PRINT <ARGS .CF>>)
>
<AND <=? <FUNCT .CF> TOPLEVEL!-> <CRLF> <RETURN>>
<SET CF <FFRAME .CF>>
>
>
<DEFINE GET-NAME ("OPTIONAL" (CHAN .OUTCHAN))
<STRING <10 .CHAN> <7 .CHAN>
<COND (<EMPTY? <8 .CHAN>> "") (T <STRING !\. <8 .CHAN>>)>
>
>
;" Dispatch -- runs a thing, possibly with an argument"
<DEFINE DISPATCH (NO "OPT" OV)
<COND (<TYPE? .NO FUNCTION SUBR>
<COND (<AND <ASSIGNED? OV> .OV> <APPLY .NO .OV>)
(ELSE <APPLY .NO >)
>)
(ELSE <ERROR "Wrong dispatch type" <TYPE .NO> .NO>)
>
>
<AND <NOT <GASSIGNED? NULL>> <SETG NULL <INSERT <ATOM ""> <ROOT>>>> ;",NULL is an atom with a name containing a single rubout in real MDL. Here it's a totally empty atom (which probably isn't legal in real mdl) "
""