64bc8643d8c0aff54bb63a13b54ae07c20b715e9
[pdp8.git] / sw / rescue / lab8e_goettingen / disk1_im6100 / rka / paroff / clock.ra
1 EXTERN #DISP /SYSTEM PAGE 0,NEEDED TO
2 /PUT CLOCK STATUS ON PG0
3 /(CSTAT) FOR USE BY GEN
4 /USER CLOCK SERVICE ROUTS
5 EXTERN #T812 /RTS CPTYP
6 EXTERN ONQI /INTERRUPT QUEUER
7 CLZE=6130 /CLOCK IOTS
8 CLSK=6131
9 CLLR=6132 /ALSO CLOE
10 CLAB=6133
11 CLEN=6134
12 CLSA=6135
13 CSTAT=157 /IDOCLK PUTS CLSA BITS
14 /IN HERE
15 \f BASE FTMP0
16 INDEX FCNWD
17 FIELD1 SYNC
18 JSA SETUP /HERE TO READ A STRIG
19 /INITIALIZE ARGS
20 TRAP4 DOSYNC /FCNWD (XR) HOLDS STRIG
21 /TO READ
22 XTA FCNWD /=ANS=0,1
23 FSTA% FTMP1 /GIVE ANS TO CALLER
24 JA GOBAK
25 FTMP0, F 0.0 /BASE PAGE
26 FTMP1, F 0.0
27 RPTR, 27;ADDR RTBL /PTR TO RATE TBL, ALSO
28 /USED TO FLT OVRCNT (NOTE
29 /THAT THE EXPONENT=27)
30 MINRAT, F .02 /MIN ALLOWABLE RATE
31 TOVR, F 0.0
32 NAME, TEXT +CLOCK +
33 ORG 10*3+FTMP0
34 FNOP
35 JA NAME+3
36 0
37 GOBAK, JA .
38 RTBL, F 16.0 /CONSTANT USED TO CHK FOR
39 /EXT CLK BIT IN FCNWD
40 /THIS CONST MUST BE NE 0
41 MAXRAT,
42 F4096, F 4096.0 /USED TO GET OVRFLO COUNT
43 F 100000.0 /FASTEST RATE IN HERTZ
44 F 10000.0 /NEXT FASTEST RATE
45 F 1000.0
46 F 100.0 /SLOWEST RATE
47 F 1.0 /USED BY TIME FOR EXT CLK
48 \f BASE 0
49
50 SETUP, 0;0 /HERE TO INIT ALL FPP SUBS
51 STARTD
52 FLDA 30 /PICK UP RTN TO CALLER
53 FSTA GOBAK
54 FLDA 0 /GET PTR TO CALLERS ARGS
55 SETX FCNWD /CLOCK XR AND BASE
56 SETB FTMP0
57 BASE FTMP0
58 FSTA FTMP1
59 FLDA% FTMP1,P1
60 FSTA FTMP0 /PTR TO 1ST ARG
61 FLDA% FTMP1,P2
62 FSTA FTMP1 /PTR TO 2ND ARG
63 FLDA #T812 /TELLS PDP8,PDP12
64 ATX CPTYP /0=8=DK8ES,1=12=KW12A
65 STARTF
66 FLDA% FTMP0 /=1ST ARG
67 ATX FCNWD /ALWAYS IN FCNWD
68 JA SETUP
69 \f ENTRY CLOCK
70 CLOCK, JSA SETUP /HERE FOR CLOCK START
71 FLDA% FTMP0
72 FSUB RTBL /FCNWD IS IN FAC,IF GE 16
73 JGE ITSEXT /(RTBL=16.0) THEN USER IS
74 /REQUESTING AN EXTERNAL
75 /CLOCK I.E. B8 OF FCNWD
76 /IS SET.
77 FLDA% FTMP1 /=REQUESTED RATE IN HERTZ
78 FSUB MINRAT /.LE. MINUMUM RATE
79 JLE GOTR-2 /MEANS STOP CLOCK.
80 FADD MINRAT
81 FSUB MAXRAT /CHK FOR TOO FAST
82 JGT GOTR-2
83 LDX -4,OVRFLO /THERE ARE 4 BASIC RATES
84 LDX 1,RATE /=INDEX INTO RTBL; UPON
85 /TRAP(CLOCK) RATE=(0,
86 /2,3,4,5,6) 0=STOP,
87 /6=EXTERNAL
88 /2-5=PROGRAMMABLE RATES
89 LOP0, FLDA% RPTR,RATE+
90 /GET NEXT SLOWEST RATE
91 FDIV% FTMP1 /=REQUESTED RATE IN HZ.
92 /FAC=OVRFLO COUNT;
93 FSUB F4096 /MUST BE MODULO 12 BITS.
94 JLE GOTR /FOUND IT
95 JXN LOP0,OVRFLO+
96 LDX 0,RATE /RATE IS TOO SLOW, STOP
97 /CLOCK.
98 GOTR, FADD F4096 /RESTORE
99 FSTA TOVR
100 ATX OVRFLO /OVER FLOW COUNT
101 TRAP4 SETCLK /GO START CLOCK
102 JA GOBAK /RTN TO CALLER
103 ITSEXT, LDX 6,RATE /=RATE FOR EXT CLK
104 FLDA% FTMP1 /REQUESTED RATE IS
105 /INTERPRETED AS OVRFLO
106 JA GOTR+1 /WHEN RATE IS EXTERNAL
107 \f/MAGIC TABLE USED BY SETCLK TO SET CLOCK ENABLE
108 /BITS. EVEN NUMBERED ENTRIES ARE FOR THE DK8ES;
109 /ODD NUMBERED ONES ARE FOR THE KW12A.
110
111 CLKTBL, 0675 /"STANDARD" DK BITS
112 300 /STND KW BITS
113 1 /DK STRIG1 BIT
114 60 /KW STRIG1 BITS
115 2 /DK S2
116 14 /KW S2
117 4 /S3
118 P3, 3 /S3
119 40 /DK ADC ON OVR BIT
120 400 /KW ADC ON OVR BIT
121
122 /IF NOT NEXT PAGE DO ORG
123 IFNEG .-200 < ORG .-SYNC&7600+200+SYNC >
124 \fSETCLK, 0 /TRAP HERE TO START CLK
125 /THIS ROUT HANDLES BOTH
126 /DK8ES AND KW12A.
127 CLLR /STOP KW AND SET MODE 0;
128 /NOP FOR DK.
129 CLEN /CLR KW12 ENABLE OR
130 /READ DK ENABLE.
131 CLA
132 TAD P7540 /TOGGLE KW MODE 0 TO 1 TO
133 CLLR /CLR CLK COUNTER, OR SET
134 /DK ENABLE BITS, RATE FOR
135 CLA CMA /BOTH NOW=7=STOP.
136 CLZE /CLR ALL DK ENABLE BITS,
137 CLSA /CLR STATUS OF BOTH, ALL
138 CLA /IS NOW CLEAR.
139 TAD FCNTBL+1 /SET PTR TO CLKTBL FOR
140 /SETTING OF ENABLE REGS.
141 TAD CPTYP /=0 IF PDP8 =1 IF PDP12
142 DCA FCNPTR /TBL ENTRIES ALTERNATE
143 /FOR 8 AND 12. CPTYP SETS
144 /PTR TO 1ST 8 OR 1ST 12
145 /ENTRY
146 TAD IDOCLK /(AC=JMP AROUND). THE
147 /FOLLOWING IS ONCE ONLY
148 /CODE. THESE LOCS ARE
149 /SUBSEQUENTLY USED AS
150 /OPERANDS
151 DCA .-1
152 /THE TAG "ISVBIT" MUST BE
153 /IN FRONT OF THE STRIG
154 /FLAGS (STFLG) TO COVER
155 /THE ILLEGAL CASE OF
156 /STRIG 0 IN A FORT CALL
157 /TO SYNC.
158 ISVBIT, TAD CPTYP /(AC=0,1) MAKE THE INST
159 /RAR CLL (FOR DK) OR THE
160 /INST RTR CLL FOR IDOCLK;
161 STFLG, RAL CLL /BECAUSE STATUS BITS FOR
162 TAD RARCLL /STRIGS DIFFER ON DK,KW.
163 DCA LOP2+1 /SEE SUB IDOCLK.
164 /THE ABOVE 3 LOCS ARE
165 /SCHMITT TRIGGER FLAGS.
166 /THE ORDER IS S1,S2,S3
167 /FOR PDP8 AND S3,S2,S1
168 /FOR PDP12. THE MAIN
169 /REASON FOR REVERSING
170 /THE ORDER IS BECAUSE
171 /ENGINEERS NEVER CONSULT
172 /PROGRAMMERS WHEN THEY
173 /ARE BUILDING NEW
174 /HARDWARE (CHK THE STATUS
175 /BITS FOR DK AND KW).
176 JMS% KONQI+1 /PUT CLOCK ON THE
177 ITMP0, CLSK /INTERRUPT QUE
178 /VIA ONQI.
179 CLENAB, ADDR IDOCLK /THIS LOC WILL HOLD THE
180 /ENABLE BITS FOR DK,KW
181 AROUND, TAD RATE /(AC=0,2,3,4,5,6) RATE IS
182 /SET BY FPP
183 RTR CLL /START TO POSITION RATE
184 RAR /BITS. B3-B5 FOR DK
185 /B0-B2 FOR KW
186 TAD CPTYP /(THIS IS TRICKY) NEED
187 RAR /CPTYP IN LNK BECAUSE
188 /POSITION OF RATE BITS
189 /DIFFER FOR DK KW.
190 TAD% FCNPTR /AC="STANDARD"
191 /ENABLE BITS FOR DK,KW.
192 SZL /IF ITS A KW THE RATE AND
193 /AND STND BITS ARE ALREADY
194 /POSITIONED AS FOLLOWS:
195 /RRR011000000
196 /B0-B3 AND B5 WILL GO TO
197 /KW CONTROL. B4,B5 WILL
198 /GO TO ENABLE. B3 IS ADC
199 /ON OVRFLO AND MAY BE SET
200 /BELOW. B5 ON CONTROL IS
201 /MODE 1. B4 AND B5 ON
202 /ENABLE ARE BUFF PRESET TO
203 /CLOCK COUNTER AND INTRUPT
204 /ON OVRFLO RESPECTIVELY.
205 JMP NOBIT-1 /ITS KW GO PUT IN CLENAB.
206 RTR /ITS DK; POSITION RATE TO
207 RAR /B3-B5. NOTE THAT THE LNK
208 /(CPTYP=0) IS BEING USED.
209 CMA /NOTE ALSO THAT THE RATE
210 /AND STND BITS ARE THE 1S
211 /COMP. OF WHAT THEY SHOULD
212 /BE, IE CPTYP=LNK=0
213 /BECOMES
214 /B2=1 OF ENABLE=BUFF
215 /PRESET TO CLK CNTR ON
216 /OVERFLO. LOOK AT THE RATE
217 /BITS IN THE HANDBOOK FOR
218 /BOTH DK,KW. R2,R5
219 /FOR DK IS 100HZ, 100KHZ
220 /RESPECTIVELY. R2,R5 FOR
221 /KW IS 100KHZ,100HZ.
222 /1S COMP.OF 2=5 ETC.
223 /SMARTEN UP STEVE!
224 /THE FINAL VALUE OF THE
225 /STND DK ENABLE BITS (1ST
226 /ENTRY IN CLKTBL) IS LEFT
227 /AS AN EXERCISE FOR THE
228 /PROGRAMMER.
229 JMP NOBIT-1 /GO PUT IN CLENAB
230 LOP1, RAR CLL /ROT 1 FCN BIT INTO LNK.
231 /B7=EXT CLK AND IS
232 /IGNORED HERE. B8=ADC ON
233 /OVRFLO, B9-B11 ARE STRIG3
234 /-STRIG1 RESP. BX=1=ENABLE
235 /FCN. 0=DISABLE
236 DCA FCNWD /PUT IT BACK (FCNWD IS
237 /SET BY FPP)
238 SNL /ENABLE FCN ?
239 JMP NOBIT /NO
240 TAD% FCNPTR /GET BITS FROM THE MAGIC
241 TAD CLENAB /TABLE.
242 DCA CLENAB /UPDATE ENABLE WORD.
243 NOBIT, ISZ FCNPTR /ADV TO NEXT
244 ISZ FCNPTR /TBL ENTRY.
245 TAD FCNWD /WHEN FCNWD GOES TO 0
246 AND P17 /WE ARE ALL DONE.
247 /THE "AND" IS DONE TO
248 /PROTECT AGAINST A BAD
249 /ARG FROM THE FORT CALL.
250 /IN A FRIENDLY ENIVORN,
251 /ITS NOT NECESSARY.
252 /NEVER TRUST A FORTRAN
253 /"PROGRAMMER".
254 P7540, SMA SZA /SMA IS SUPERFLOUS TO
255 /THE ROUT; BUT IT
256 /CREATES A NICE CONST.
257 JMP LOP1 /MORE TO DO
258 DCA STFLG /CLR THE SCHMITT
259 DCA STFLG+1 /TRIGGER FLAGS.
260 \f DCA STFLG+2
261 TAD OVRFLO /SET BUFF PRESET
262 CIA /(FPP SET THIS ARG)
263 CLAB
264 CLA
265 TAD CLENAB /THIS IS FOR KW ONLY.
266 AND P377 /AC=3XX. 3= OR BUFF PRE
267 /INTO CLK CNTR AND ENAB
268 /INT ON OVRFLO.
269 /XX ARE THE STRIGS.
270 CLEN /SET KW ENABLE OR
271 CLA /READ DK ENABLE.
272 DCA OVRCNT+1 /CLR NUM OF CLK OVRFLOS
273 DCA OVRCNT /SINCE TIME 0.
274 TAD CPTYP /NEED TYPE IN ORDER TO
275 RARCLL, RAR CLL /ISOLATE CONTROL
276 TAD CLENAB /BITS FOR
277 SZL /KW ?
278 AND P7540 /YES, B0-B2 IS RATE,
279 /B3 IS ADC, B5 IS BUFF
280 /PRE TO CLK CNTR ON
281 /OVRFLO, B6 IS MOX NIX.
282 /IF DK ALL BITS MAY HAVE
283 /MEANING
284 CLLR /START THE CLOCK
285 CLA
286 CIF CDF
287 JMP% SETCLK /RTN TO RTS
288 \fDOSYNC, 0 /HERE TO DISPOSITION A
289 /A SCHMITT TRIGGER.
290 TAD CPTYP /DK AND KW FLAGS ARE IN
291 RAR CLL /REVERSE ORDER. IF DK
292 /ARG IS OK; IF KW THEN
293 /MUST SET 1=3, 2=2, 3=1
294 /TO GET INDEX TO
295 /CORRECT FLAG.
296 TAD FCNWD /=REQUESTED STRIG=1,2,3
297 /(SET BY FPP)
298 SZL /DK ?
299 CIA /NO KW
300 AND P3 /IE 1 GOES TO -1 GOES
301 /TO 3 ETC. "AND" ALSO
302 /INSURES RANGE IS 0-3.
303 /IF ARG IS 0 RESULT IS
304 /ALWAYS 0.
305 TAD KSTFLG+1 /GET PTR TO FLAG
306 DCA SETCLK
307 TAD% SETCLK /FLAG=0 IF TRIG HAS NOT
308 /TRIPPED SINCE THE LAST
309 /CALL TO SYNC; =1
310 /OTHERWISE IE RTN 0=FALSE
311 DCA FCNWD /,1=TRUE (FPP WILL PICK
312 / UP FCNWD)
313 DCA% SETCLK /CLR FLAG ANYWAY
314 CIF CDF
315 JMP% DOSYNC /RTN TO RTS
316 \fIDOCLK, JMP AROUND /HERE ON CLOCK INTERRUPT
317 /(JMP AROUND IS A ONCE
318 /ONLY CONSTANT).
319 TAD KSTFLG+1 /SET PTR TO STRIG FLAGS.
320 DCA ITMP0
321 CLSA /GET CLOCK BITS.
322 DCAZ CSTAT /SAVE THEM FOR SOME
323 TADZ CSTAT /BODY ELSE.
324 SPA /OVER FLOW ?
325 ISZ OVRCNT+1 /YES BUMP LO ORD CNTR
326 SKP
327 ISZ OVRCNT /BUMP HI ORD
328 JMP DOTRIG /(HI ORD ISZ SKP IS
329 /HARMLESS)
330 LOP2, ISZ ITMP0 /ADV STRIG FLAG PTR.
331 RAR CLL /(OR RTR CLL IF KW)
332 /IE PUT STRIG BIT IN LNK.
333 /IF DK THE ORDER OF
334 /INTERROGATION IS S1,S2,S3
335 /IF KW THE ORDER IS S3,
336 /S2,S1. THE STATUS BITS
337 /FOR DK ARE ADJACENT IE
338 / B9(S3),B10(S2),B11(S1)
339 /FOR KW ITS EVERY OTHER,
340 /B6(S1),B8(S2),B10(S3).
341 DCA ISVBIT /SAVE WHATS LEFT.
342 RAL /COPY LNK INTO FLAG IF=1
343 SZA /IE DONT CLR FLAG WHEN
344 DCA% ITMP0 /ITS SET.
345 TAD ISVBIT
346 DOTRIG, AND P377 /THE "AND" INSURES THAT
347 /THE HI ORD BITS ARE
348 /CLRED SO THAT ISVBIT
349 /GOES TO 0 WHEN ALL
350 /STRIGS HAVE BEEN
351 /DISPOSITIONED. IE
352 /CLR OVRFLO BIT FOR DK,KW
353 /AND CLR PRE-EVENT BIT
354 /ON KW IF IT IS SET
355 SZA /DONE ?
356 JMP LOP2 /NO
357 TAD #CLINT /CALL USER EXTENDED
358 SZA CLA /CLOCK ROUT ?
359 JMS% #CLINT+1 /YES
360 JMP% IDOCLK /RTN TO IHANDL
361 \fFCNPTR,
362 OVRCNT,
363 KONQI, ADDR ONQI
364 P17, 17
365 P377, 377
366 FCNWD, 0 /FPP XRS
367 CPTYP, 0
368 RATE, 0
369 P1, 1
370 P2, 2
371 OVRFLO,
372 FCNTBL, ADDR CLKTBL
373 KSTFLG, ADDR STFLG-1
374 ENTRY #CLINT
375 #CLINT, 0;0
376 ENTRY TIME /FIGURE WHAT TIME IT IS
377 TIME, JSA SETUP
378 FLDA RPTR /=27;X;X IS USED TO FLOAT
379 STARTD
380 FLDA# OVRCNT /NUM OF CLK OVRFLOS SINCE
381 STARTF /TIME 0
382 FNORM
383 FMUL TOVR /=NUM OF BASIC TICKS PER
384 /CLOCK OVER FLOW.
385 /FAC=NUM OF TICKS SINCE
386 /TIME 0.
387 FDIV% RPTR,RATE /DIV BY BASIC RATE IN HZ
388 /OR 1 IF EXTERNAL CLK.
389 FSTA% FTMP0 /GIVE ANS TO CALLER, ALSO
390 /LEAVE ANS IN FAC IN
391 /CASE TIME WAS A FCN
392 /CALL. ANS=ELAPSED TIME IN
393 /SECONDS SINCE TIME 0 OR
394 /NUM OF EXTERNAL UNIT
395 JA GOBAK /TICKS
396 \f\1a