/ PDP12 OVERLAY FOR 16K U/W-FOCAL(V-4E)		-JVZ-
/ 16KXII.PA
/REVISIONS:
/	I/O PRESET ADDED AT 5400
/	

/THIS OVERLAY ADDS THE SCOPE HANDLER, THE 'OUTPUT SCOPE',
/'VIEW', 'HESITATE', AND 'KONTROL' COMMANDS,  AND 8 NEW
/FUNCTIONS: 'FLS', 'FRS' 'FSS', 'FXL', 'FADC' AND 'FTIM'
/'FBUF' AND 'FTRG' FOR 16K PDP12 USERS.

/THE FUNCTIONS 'FLS', 'FRS', 'FSS' AND 'FXL' PROVIDE AC-
/CESS TO THE LEFT AND RIGHT SWITCHES, THE SENSE SWITCHES,
/AND THE 'EXTERNAL LEVELS'.  'FADC' HAS BEEN MODIFIED TO
/READ ANY OF THE 16 ANALOG CHANNELS WHILE 'FTIM' CAN BE
/USED TO KEEP TRACK OF THE CLOCK AND 'FBUF' PROVIDES AC-
/CESS TO THE POINT-PLOT DISPLAY BUFFER.  'FTRG' MONITORS
/THE OCCURANCE OF ANY SIGNALS DETECTED BY THE SCHMITTS.

/'FLS' RETURNS AN UNSIGNED VALUE FROM THE LEFT SWITCHES
/'FRS' (THE SAME AS 'FSR') RETURNS A SIGNED VALUE
/'FSS(N)' RETURNS -1 IF SWITCH N IS OFF, +1 IF IT IS ON
/'FXL(N)' RETURNS -1 IF THE LINE IS OPEN, +1 IF LOW
/'FADC(N)' READS CHANNEL N (RANGE -512 TO +511)
/'FTIM()' RETURNS THE NUMBER OF CLOCK OVERFLOWS
/'FTIM(-1)' ZEROS THE COUNTER AND 'FTIM(N)' PRESETS IT
/'FBUF(I)' RETURNS THE VALUE AT RELATIVE LOCATION 'I'
/'FUBF(I,J)' STORES VALUE OF EXPRESSION J AT LOC. 'I'
/'FTRG()' WILL RETURN THE WEIGHTED SUM OF ALL EVENTS.
/'FTRG(2)' WILL ONLY CHECK (AND CLEAR) INPUT 3, ETC.

/THE 'KONTROL' COMMAND LOADS THE RELAY REGISTER AND THE
/'HESITATE' COMMAND RUNS THE CLOCK.  THE LATTER IS SOME-
/WHAT COMPLICATED: BOTH THE OSCILLATOR FREQUENCY AND THE
/NUMBER OF CLOCK PULSES TO COUNT BEFORE GENERATING AN
/OVERFLOW CAN BE SET.  THE OSCILLATOR FREQUENCY IS PRO-
/GRAMMED BY A -NEGATIVE- ARGUMENT WHILE THE NUMBER OF
/PULSES IS SPECIFIED AS A -POSITIVE- NUMBER; BOTH MAY BE
/INCLUDED IN A SINGLE 'HESITATE' COMMAND.  IN ADDITION,
/CALLING 'HESITATE' WITHOUT ANY ARGUMENT (OR WITH ZERO)
/CAUSES THE PROGRAM TO DELAY UNTIL THE CLOCK OVERFLOWS.

/SPECIFYING TOO HIGH A CLOCK RATE MAY CAUSE THE PROGRAM
/TO 'HANG' WITH NO TIME FOR PROCESSING.  TO GET OUT OF
/THIS CONDITION, HIT 'STOP', 'I/O PRESET' IN '8' MODE,
/AND RESTART AT LOCATION 100.

/PRELIMINARY TESTING INDICATES THAT IT IS MORE OR LESS
/POSSIBLE TO MAINTAIN A 30 MILLISECOND SAMPLE LOOP IF
/THE NUMBER OF OPERATIONS WITHIN THE LOOP IS LIMITED TO
/ONLY 1 OR 2 COMMANDS.  THIS DOES NOT INCLUDE I/O TIME.

/THE 'HESITATE' COMMAND MUST BE USED TO INITIALIZE THE
/CLOCK BEFORE THE 'FTRG' FUNCTION WILL RESPOND TO ANY
/INPUT.  AN INNOCUOUS CALL (WHICH LEAVES THE CLOCK OFF)
/IS: 'H -8,1'.
/THE 'O S' COMMAND WILL SWITCH OUTPUT TO THE SCOPE ('O S'
/IS ASSUMED WHEN FOCAL IS LOADED) WHILE THE COMMAND 'O E'
/WILL RETURN TO THE TERMINAL.  THE 'VIEW' COMMAND MAY BE
/USED TO CONTROL THE DISPLAY:  'V +1' TURNS IT ON WHILE
/'V 0' (OR JUST 'V') TURNS IT OFF.  THE DISPLAY IS ACTIVE
/WHILE WAITING FOR KEYBOARD INPUT AND ALSO DURING A 'HESI-
/TATE' OR 'LOGICAL BRANCH' COMMAND.  IT IS ALSO REFRESHED
/WHENEVER A RUNNING PROGRAM COMES TO THE END OF A LINE.
/THIS LATTER FEATURE CREATES A 'LIVE' DISPLAY, BUT IT DOES
/SLOW THINGS DOWN QUITE A BIT.  YOU MAY PREFER TO DISABLE
/THE DISPLAY AND USE AN 'ASK :-1' COMMAND TO PAUSE FOR IN-
/TERMEDIATE RESULTS.  OR YOU CAN PUT IN A 'HESITATE' TO
/'FLASH' THE ANSWERS SO THE PROGRAM CAN RUN UNATTENDED.

/UP TO 85 CHARACTERS CAN BE DISPLAYED ON A SINGLE LINE,
/WITH AUTOMATIC 'WRAP-AROUND' IF NECESSARY.  THE DISPLAY
/'SCROLLS' (LINES AT THE TOP OF THE SCREEN ARE REMOVED)
/IF MORE CHARACTERS OR MORE LINES THAN CAN BE ACCOMODATED
/ARE OUTPUT.  A 'FORMFEED' (CTRL/L) IS USED TO ERASE THE
/SCREEN.  THIS MAY DONE AT ANY TIME WHILE ENTERING TEXT
/OR NUMERICAL VALUES WITHOUT AFFECTING THE RESULT.  THE
/SCREEN IS NOT CLEARED BY 'CTRL/L' DURING A 'MODIFY' OR
/'MOVE' COMMAND, HOWEVER.  THE '#' OPERATOR IN 'ASK' AND
/'TYPE' COMMANDS IS THE EASIEST WAY TO CLEAR THE SCREEN
/IN A PROGRAM, BUT ONE COULD ALSO USE 'FOUT(140)' TO DO
/THE SAME THING.  TYPING 'RUBOUT' OR 'DELETE' WHILE EDIT-
/ING WILL REMOVE THE PREVIOUS CHARACTER FROM THE SCREEN!
/THIS MAY ALSO BE DONE BY EXECUTING A 'FOUT(92)'.

/THE 'VIEW X,Y' COMMAND FOR DISPLAYING DATA IS ALSO IN-
/CLUDED.  THIS COMMAND WILL CREATE AN ENTRY IN THE VIEW
/BUFFER WHICH WILL BE INTENSIFIED DURING EACH REFRESH
/CYCLE.  'VIEW -1' WILL CLEAR ALL POINTS FROM THE BUFFER
/WHILE 'VIEW 0' (OR JUST 'V') WILL DISABLE THE REFRESH.
/'VIEW 1' OR ANY INPUT FROM THE KEYBOARD MAY BE USED TO
/TURN IT ON AGAIN.  SEPARATE CHANNELS ARE USED FOR THE
/PLOT (CHANNEL 1) AND THE TEXT (CHANNEL 2).

/THE DISPLAY ROUTINES OCCUPY 4000-4177 IN FIELD 1.  THIS
/ALLOWS THEM TO USE 2 CONVENIENT BETA REGISTERS LOCATED
/ON THIS PAGE.  THE DISPLAY CODES AND THE DISPLAY BUFFER
/ARE STORED IN THE UPPER FIELD FROM 6200 TO 7777, REDUC-
/ING THE MAXIMUM PROGRAM SIZE BY 3 BLOCKS.  THE 'VIEW'
/BUFFER USES HALF OF THE SYMBOL TABLE: 33776-37775.

/ACKNOWLEDGMENTS:  THE DISPLAY ALGORITHM WAS ADAPTED FROM
/ONE WRITTEN BY DOUGLAS E. WREGE OF THE GEORGIA INSTITUTE
/OF TECHNOLOGY FOR USE WITH THE OS/8 EDITOR.  THE COMPACT
/CHARACTER DISPLAY WAS INVENTED BY TIM CLARK, OF FRELAN
/ASSOCIATES (MENLO PARK, CA.), AND THE CHARACTER PATTERNS
/(AND SOME OF THE DISPLAY LOGIC) COME FROM THE -SCROLL-
/EDITOR WRITTEN BY CLYDE G. ROBY JR. (WEST VIRGINIA UNIV.
/MEDICAL CENTER).  PAUL C. DIEGENBACH AT THE UNIVERSITY
/OF AMSTERDAM CONTRIBUTED THE ORIGINAL FORMS OF SEVERAL
/OF THE FUNCTIONS.
/DEFINITIONS FOR VERSION 4E (OCTOBER 1978)

	P134=0
	P337=2
	XRT=14
	BUFEND=27
	TXTEND=30
	TABEND=33
	EXP=44
	HORD=45
	DAY=55
	OUTDEV=57
	P7=73
	P77=77
	C100=100
	P17=101
	M14=107
	BETA=163
	CRT=223
	INLIST=226
	ECHOFF=253
	GOTO=610
	COMGO=722
	EVAL=1610
	FNTABL=2157
	FNTABF=2357
	RUB1=2466
	KEYCK=3000
	XI33=3007
	XINT=3127
	ACCEPT=5521
	FINALZ=5525
	ECODEV=6323
	FMQ=6563
	ACTION=6571
	OSCOPE=6722

	PUSHA=4520
	POPA=4521
	PUSHJ=4522
	POPJ=5523
	SORTJ=4526
	TSTCMA=4543
	NEGATE=4557
	FIXIT=4560
	ERROR2=4576
	FLOAT=4552
	FLOATR=5553
	FL0ATR=5554
	RETURN=5555
	CONTINUE=5434
	FENT=4407
FIXMRI	FGET=0000
	FEXT=0000

	P=10
	T=20
	B=30

	FIELD 0

	*CRT
	OSCOPE		/IMPLEMENT 'O S'

	*OSCOPE-1
	SCOPE

	*5400
	IOF
	6141	/L MODE
	1020	/LDA I
	20
	4	/ESF - ISSUE I/O PRESET
	2	/PDP MODE
		
	*FINALZ+2
	NOP		/CAN'T RUN UNDER ANYTHING


	FIELD 1

	*BUFEND
	-6177		/LAST TEXT LOCATION

	*TXTEND
	-6221		/INPUT LIMIT

	*OUTDEV
	SCOPE		/START UP THE DISPLAY!

	*113
E27,	27		/CLOCK REGISTERS
HCNT,	0
LCNT,	0
OFLO,	0
FLAGS,	0

	*164
DSW,	XI33+1		/DISPLAY SWITCH
		
	*INLIST+1
	ECHOFF		/SO WE CAN ERASE THE SCREEN

	*1241
	CMA		/LET '#' CLEAR THE SCREEN

	*COMGO-1
	REFRSH		/ADD REFRESH AT END OF LINE

	*COMGO+"H-"@
	TATE
	*COMGO+"K-"@
	KONTRL
	*COMGO+"V-"@
	VIEW

	*FNTABF+15
	FLS
	*FNTABF+31
	FADC
	FTRG
	FBUF
	FTIM
	FXL
	FSS
	*FNTABF+43
	FDA

	*FNTABL+16
	"R-200^4+"S-200	/RS
	*FNTABL+35
	"X-200^4+"L-200	/XL
	"S-200^4+"S-200	/SS

	*KEYCK
	KDISPL		/PATCH THE INPUT LOOP

	*ECODEV
	SCOPE		/MAKE THIS THE DEFAULT

	*ACTION+3
	ACCEPT-1	/ACTIVATE FF DURING ASK

	*7577
	BDISPL		/DISPLAY ON A BRANCH
	*4000		/THE DISPLAY PROCESSOR
YVAL,	0		/THE VERTICAL COORDINATE
XVAL,	0		/THE HORIZONTAL COORDINATE

SCOPE,	0		/FILL THE OUTPUT BUFFER
	DCA YVAL	/SAVE THE CHARACTER CODE
	TAD YVAL
	SORTJ		/CHECK FOR LF,FF,CR,BA,BELL,RUB
M1,	    P134-1
	    SCOPGO-P134
SBA,	TAD YVAL	/NOTHING SPECIAL
	AND P77		/ONLY USE 6 BITS
	CLL RAL		/MULTIPLY BY TWO
	TAD TBS		/ADD START OF THE TABLE
SCR,	DCA YVAL	/SAVE PATTERN POINTER

	TAD CHRCNT	/OK NOW, BUILD POINTER
	TAD BUF		/TO THE NEXT LOCATION
	DCA XRT		/-> AUTO INDEX REG.
	TAD YVAL	/GET THE PATTERN ADDRESS
	CDF T		/DISPLAY BUFFER LOCATION
	DCA I XRT	/SAVE IT
	STL RTL		/ADD ONE TO THE COUNT

SRO,	TAD CHRCNT	/RUBOUT = ERASE ONE CHARACTER
	SZA		/WATCH OUT FOR MISTAKES HERE
	TAD M1
SFF,	DCA CHRCNT	/FF = ERASE THE ENTIRE SCREEN

	TAD CHRCNT	/DO A LITTLE CHECKING
	TAD (SBUFR-7600	/YE OLDE BUFFER SIZE!
	SMA CLA
	JMS SCROLL	/TIME TO REMOVE A LINE
BEL,	CDF P		/BELL: DON'T DISPLAY 'G'
SLF,	JMP I SCOPE	/IGNORE LF'S COMPLETELY
BUF=	BEL

CHRCNT,	0

SCOPGO,	SRO
	BEL
	SBA
	SFF
	SLF
	SCR
	SBA

/RELEVANT LINC-MODE INSTRUCTIONS

	LDAI=1020
	DSCI=1760
	DSC=1740
	STC=4000
	ADD=2000
	LDF=0640
BDISPL,	TAD (GOTO-XI33	/DO A DISPLAY CYCLE ON A BRANCH
KDISPL,	TAD DSW		/WHILE WAITING FOR KEYBOARD INPUT
	PUSHA		/SAVE THE RETURN ADDRESS

REFRSH,	TAD I DSW	/CHECK THE 'DISPLAY SWITCH'
	SPA SNA CLA
	POPJ		/NOTHING DOING
	TAD CHRCNT
	CMA
	DCA SCROLL	/SAVE NUMBER OF CHARACTERS
	TAD BUF
	DCA XRT		/INITIALIZE THE INDEX REGISTER
	CDF T
	TAD P337	/START DISPLAY AT THE TOP

NULINE,	DCA YVAL	/INITIALIZE FOR A NEW LINE
	TAD (7002	/=2 + UNSEEN SIGN BITS
	DCA XVAL	/AND ALSO SETS CHANNEL 2

RFEND,	ISZ SCROLL	/DONE?
	JMP RFLUP	/NOT YET
SM20,	SNL SMA SZA CLA	/THINK IT WILL SKIP?
	JMS SCROLL	/SCREEN FULL, REMOVE A LINE
	JMP I (PTPLOT	/REFRESH THE VIEW BUFFER

RFLUP,	TAD I XRT	/GET THE NEXT CHARACTER
	SNA		/CR?
	JMP RFEOL	/YES
	DCA SCOPE	/PUT ADDRESS IN LINC REG. 2
	TAD YVAL
	CIF P		/INHIBIT INTERRUPTS BRIEFLY
	LINC
	LDF 13		/POINT TO THE PATTERN TABLE
	DSC 2		/DISPLAY COLUMNS 1 & 3
	LDAI;-4		/-3 IN ONE'S COMPLEMENT
	ADD 1		/BACKUP THE X-COORDINATE
	STC 1		/AND SAVE IT AGAIN
	ESF		/SET SMALL LETTERS
	YVAL&1777 ADD	/RELOAD THE Y-COORDINATE
	DSCI 2		/DISPLAY COLUMNS 2 & 4
	PDP		/BACK TO THE REAL WORLD
	CLA		/GET RID OF THE Y VALUE
	ISZ XVAL	/SPACE AND CHECK FOR OVERFLOW
	JMP RFEND	/CONTINUE WITH THE NEXT ONE

RFEOL,	TAD P337	/START A NEW LINE
	TAD YVAL
	SPA CLA		/FILLED THE SCREEN?
	JMP SM20+1	/YES
	TAD SM20
	TAD YVAL
	JMP NULINE	/DO A LINEFEED
SCROLL,	0		/REMOVE A LINE FROM THE TOP
	TAD BUF
	DCA XRT

	TAD CHRCNT	/REDUCE THE CHAR COUNT
	SNA
	JMP I SCROLL	/NO CR'S IN THE BUFFER!
	TAD M1
	DCA CHRCNT
	TAD I XRT	/LOOK FOR A CR
	SZA CLA
	JMP SCROLL+3

	TAD BUF		/SET THE SECOND POINTER
	DCA YVAL
	TAD CHRCNT	/NEW VALUE
	CIA
	DCA XVAL	/HANDY REGISTER
	TAD I XRT	/SHUFFLE THINGS DOWN
	ISZ YVAL
TBS,	DCA I YVAL
	ISZ XVAL	/COUNT
	JMP .-4
	JMP I SCROLL

/ 'FTRG' TESTS FOR THE OCCURANCE OF ANY SCHMITT TRIGGER
/ THE ARGUMENT (2,8,32) SERVES AS A MASK; '0'=ALL FLAGS
/ THE VALUE RETURNED IS THE WEIGHTED SUM OF THE EVENTS.

FTRG,	FIXIT		/GET THE MASK
	SNA
	CMA CLL RAR	/'0' = ALL
	AND FLAGS	/COMPARE
	FLOAT		/SAVE
	TAD HORD	/RECALL
	CMA
	AND FLAGS	/REMOVE THE BITS WE TESTED
	DCA FLAGS
	RETURN

FLS,	CIF P		/READ THE LEFT SWITCHES
	LINC
	LSW
	PDP
	FL0ATR		/AS AN UNSIGNED NUMBER

	PAGE
/THE 'VIEW X,Y' POINT-PLOT COMMAND FOR THE PDP12:

/'VIEW X,Y' WILL BRIGHTEN THE POINT (X,Y) DURING EACH RE-
/FRESH CYCLE.  0<X<1023 AND -512<Y<511.  'VIEW' WITH ONLY
/A SINGLE ARGUMENT IS USED TO TURN THE DISPLAY ON AND OFF
/OR TO CLEAR THE POINT-DISPLAY BUFFER USING 'V -1'.

	*3400		/START A NEW PAGE
DISB,	4000-1		/THE STARTING LOCATION
PNTR,	4000-1		/THE CURRENT LOCATION

VIEW,	PUSHJ		/GET THE FIRST PARAMETER
	    EVAL
	TSTCMA		/IS THERE ANOTHER ONE?
	JMP ONLY1	/NO
	JMS STORE	/PUT 'X' IN THE BUFFER
	PUSHJ
	    EVAL
	JMS STORE	/PUT 'Y' IN THE BUFFER
	CONTINUE

STORE,	0		/LOOKS SIMPLE ENOUGH
	STL IAC RAL	/= -(BEND-1)
	TAD PNTR	/WATCH OUT FOR OVERFLOW
	SZL CLA
	ERROR2		/TOO MANY!
	ISZ PNTR
	FIXIT
	CDF B		/B=T FOR 12K, B=V FOR 16K
	DCA I PNTR
	CDF P
	TAD DISB
	DCA TABEND	/REDUCE THE NO. OF VARIABLES
	JMP I STORE

ONLY1,	FIXIT		/SPECIAL CASE
	AND P17		/BE CAREFUL
	ISZ HORD	/TEST FOR -ANYTHING
	DCA I DSW	/SET THE DISPLAY SWITCH
	SNA CLA		/TEST FOR -1
	CONTINUE	/SOMETHING ELSE
	CMA CLL RTL	/-3 (16K LIMIT)
	DCA TABEND	/RESET SYMBOL LIMIT
	TAD DISB
	DCA PNTR	/CLEAR THE SCREEN BUT DON'T
	CONTINUE	/MESS UP THE DISPLAY SWITCH
/////
BEND=	-1
/PROVIDE THE PROGRAM WITH ACCESS TO THE VIEW BUFFER

FBUF,	FIXIT		/ACCESS TO THE VIEW BUFFER
	TAD DISB
	PUSHA		/SAVE THE INDEX VALUE
	TSTCMA		/READ OR WRITE?
	JMP RBUF	/READ
	PUSHJ		/WRITE
	    EVAL
	TAD PNTR	/SAVE THE 'VIEW' POINTER
	DCA XRT
	POPA
	DCA PNTR
	JMS STORE
	TAD XRT
	DCA PNTR
	RETURN

RBUF,	POPA		/READ FROM THE BUFFER
	DCA XRT
	CDF B
	TAD I XRT	/NO LIMIT CHECKING
	FLOATR

/EXTEND THE REFRESH CYCLE TO INCLUDE THE VIEW BUFFER

PTPLOT,	TAD DISB	/SETUP THE ADDRESS REGISTER
	DCA XRT
	CDF B

PTLOOP,	TAD XRT		/CURRENT
	STL CMA
	TAD PNTR	/THE END
	SZL CLA
	POPJ		/END REFRESH
	TAD I XRT	/GET X
	CLL RAR		/ASSUME 10 BITS, BUT ONLY USE 9
	CDI P		/INHIBIT LINC-MODE INTERRUPTS
	DCA I BETA	/THIS POINTS TO BETA 14
	CDF B
	TAD I XRT	/GET THE Y VALUE IN THE AC
	CLL RAR		/SO WE CAN DISPLAY A/D READINGS
	LINC
	DIS 14		/PLOT IT ON CHANNEL 1
	PDP
	CLA
	JMP PTLOOP
/THE 'FSS', 'FXL' AND 'FADC' FUNCTIONS

	*3514		/SET THE ERROR CODES
N6,	-6
P446,	SNS+6
P414,	SXL+14

FSS,	FIXIT		/CLEARS THE LINK
	TAD N6		/TEST ARGUMENT
	SZL
	ERROR2		/NEGATIVE OR .GT. 5
	TAD P446
	JMP TST-3

FXL,	FIXIT		/TEST EXTERNAL LEVELS
	TAD M14
	SZL
	ERROR2		/ARGUMENT NOT IN RANGE 0<N<12
	TAD P414
	DCA TST
	CIF P		/PREVENT INTERRUPTS
	LINC
TST,	0		/THIS IS A LINC-MODE SKIP
	COM		/SET -1 IF OPEN
	PDP
	STL RAL		/0 BECOMES +1, -1 IS UNCHANGED!
	FLOATR		/RETURNS: +1 IF SET, -1 IF NOT

FADC,	FIXIT		/GET THE CHANNEL NUMBER
	CIF P
	AND P17
	TAD C100	/COMPUTE THE INSTRUCTION
	DCA .+2
	LINC
	SAM		/'SAM' = '100'
	PDP
	FLOATR
/////
/THE RELAYS ARE TREATED AS A 6-BIT NUMBER SO THEY CAN BE
/SET OR CLEARED SIMULTANEOUSLY.  THE TABLE BELOW EXPLAINS:

/		RELAY	DECIMAL
/		  0	  32
/		  1	  16
/		  2	   8
/		  3	   4
/		  4	   2
/		  5	   1

/THUS DECIMAL 25 WILL CLOSE RELAYS 1,2 & 5, OPEN THE OTHERS

KONTRL,	PUSHJ		/'K 1' CLOSES RELAY 5, ETC.
	    EVAL
	FIXIT
	CIF P		/INHIBIT INTERRUPTS
	LINC
	ATR
	PDP
	CONTINUE	/COULD CHECK FOR MORE ARGUMENTS
/////

	*FMQ
FMQ,	FIXIT		/LOAD THE MQ WITH A LINC SHIFT
	CIF P
	LINC
	ROR 14		/WITH EAE THIS IS UNNECESSARY-
	PDP
	RETURN		/JUST USE THE STANDARD VERSION
/////

	*RUB1+5
FDA,	FIXIT		/MOVE THIS OUT OF THE WAY
	CIF 20
	JMP DAY
/////

/LINC-MODE INSTRUCTIONS:

	LSW=0517
	SNS=0440
	SXL=0400
	ROR=0300
	DIS=0140
	SAM=0100
	COM=0017
	ATR=0014
	ESF=0004
	PDP=0002
/CLOCK ROUTINE FOR THE KW12A - THE 'HESITATE' COMMAND

/START WITH 'H -5,Q' WHERE Q IS THE TIME IN UNITS OF 0.01
/SECONDS.  THUS Q=100 IS A 1 SECOND COUNTING PERIOD.  TO
/CHOOSE OTHER UNITS, CHANGE THE FIRST PARAMETER (WHICH MUST
/BE NEGATIVE) TO SELECT A DIFFERENT TIME BASE.  THUS -4 =
/0.001 SECONDS (MILLISECONDS) AND -6 = RATE DETERMINED BY
/INPUT #1.  (SEE THE LABORATORY COMPUTER HANDBOOK.)

/IT IS NOT NECESSARY TO SET THE UNITS UNLESS YOU WISH TO
/CHANGE IT FROM 0.001 SECONDS, BUT IF YOU DO YOU MUST GIVE
/A NEW DELAY COUNT TOO. (DELAY MUST BE LESS THAN 4096.)
/'H' THEN WAITS UNTIL THE END OF THE NEXT COUNTING CYCLE.

/TO RING THE BELL OF THE TTY EVERY 4 SECONDS:

/	1.1 H 4000;C OR: H -5,400
/	1.2 H FOUT(135);L B 1.2;R

/FOR ANOTHER APPROACH SEE DECUSCOPE 14 #2 P.27 (1975)

	*4460		/AFTER 'FCOM'
WATE,	PUSHJ		/REFRESH WHILE WE'RE WAITING
	    REFRSH
	TAD OFLO	/CHECK FOR OVERFLOW
	SNA CLA
	JMP WATE
	DCA OFLO	/CLEAR FOR THE NEXT TIME

HESI,	TSTCMA		/ANY MORE ARGUMENTS?
	CONTINUE	/NO
TATE,	PUSHJ		/'HESITATE' ENTRY POINT
	    EVAL
	NEGATE		/AND CHECK FOR ZERO
	SZL		/ZERO ARGUMENT?
	JMP WATE+2	/YES, WAIT FOR TIMEOUT
	FIXIT		/CONVERT TO INTEGER FORMAT
	ISZ HORD	/RATE OR DELAY?
	JMP RATE	/SET THE NEW RATE
	CLAB		/LOAD THE CLOCK BUFFER
	CLA
	CLLR		/SET MODE 0, STOP THE CLOCK
	TAD TIME
	CLLR
	STA		/ENABLE ALL INPUTS, INTERRUPTS
	CLEN
	JMP WATE+3

RATE,	AND P7		/BE PRUDENT
	RTR		/SHIFT RATE BITS INTO PLACE
	RTR
	TAD C100	/MODE 1
	DCA TIME
	JMP HESI	/MORE?
TIME,	4100		/MILLISECONDS
/THE 'FTIM' FUNCTION COUNTS CLOCK OVERFLOWS

FTIM,	TAD HORD	/READ OR SET THE ELAPSED TIME
	SZA
	JMP CLEAR
	FENT		/	ARG < 0 -> CLEAR
	FGET E27	/	ARG = 0 -> READ
	FEXT		/	ARG > 0 -> PRESET

CLEAR,	SPA CLA		/CLEAR OR PRESET?
	DCA EXP		/CLEAR
	FIXIT
	DCA LCNT
	TAD HORD
	DCA HCNT
	RETURN		/ALWAYS RETURNS THE COUNTER!

/THIS IS THE CLOCK INTERRUPT HANDLER:

CINT,	CLSK		/ANY ACTIVITY?
	JMP I LINT	/NO
	CMA CLL RAR	/=3777
	AND FLAGS	/REMOVE THE CLOCK FLAG
	CLSA		/MERGE THE EVENT FLAGS
	DCA FLAGS	/SAVE EVERYTHING
	TAD FLAGS
	SMA CLA		/CLOCK OVERFLOW?
	JMP I LINT	/NO
	ISZ LCNT	/ADD ONE
	SKP
	ISZ HCNT	/ADD 4096
	ISZ OFLO	/TELL 'HESITATE' ABOUT IT
	TAD HCNT
	SPA CLA		/KEEP IT DOWN TO 23 BITS
	DCA HCNT
	JMP I LINT

/LEAVE ROOM FOR THE INTERNAL LPT: HANDLER...

	*4565
LINT,	XINT+2

	*XINT
	JMP I .+1	/REPLACE TWO 'NOP'S
	CINT

/ '8-MODE' IOT CODES:

	CLSK=6131
	CLLR=6132
	CLAB=6133
	CLEN=6134
	CLSA=6135
	LINC=6141
	CDI=6203
/PATTERN TABLE FOR THE DSC INSTRUCTION

	FIELD 2
SBUFR=	CIF P		/'SBUFR-1' = 'CDF P'

	*7600		/AFTER THE SCOPE BUFFER
STABL,	5536;3541
	4477;7744
	5177;2651
	4136;2241
	4177;3641
	4577;4145
	4477;4044
	4536;2641
	1077;7710
	4141;0077
	7642;4041
	2477;4310
	0177;0301
	3077;7730
	0677;7730
	4177;7741
	4477;3044
	4336;3745
	4677;3144
	5121;4651
	7740;4040
	0177;7701
	0276;7401
	0177;7706
	1463;6314
	0770;7007
	5143;6145
	0077;0041
	0640;0130
	4100;7700
	3700;1010
	1010;1034

	0000;0000
	0000;0075
	7070;0000
	7714;1477
	7121;4657
	3361;4366
	2626;0551
	7000;0000
	4100;0036
	3600;0041
	2424;0010
	3704;0404
	0600;0005
	0404;0404
	0300;0003
	3001;4006
	5136;3645
	7701;0121
	5123;2145
        5122;2641
        7714;0424
        5172;0651
        2506;4215
        5043;6044
        5126;2651
        5122;3651
        6600;0066
        6600;0065
        4210;0024
        1212;1212
        2400;1042
        5520;2040
        $$$$;$$$$       /END OF THE PATTERN TABLE
