	.TITLE ATS9
	.GLOBL PACK,FILENM,ASK,CHANGE,DOWE,OCTDEC,FINI
	.GLOBL .DIGCT,A16,A17,BUFFER,IMAGE
	.GLOBL OUTIMG,PCK,ADDR2,UNPCK,PUTIT
	.IODEV INDK,OUTDK,TTI,TTO,TEMPDK,SECOUT,TEMDK5
/
/
/
/  29 AUG 72
/   8 JAN 73 - MOD FOR TOTAL PACKAGE (ELIMINATING THE USE OF PAGER)
/  26 JAN 73 - REFINEMENTS AND USER DEBUG
/  13 FEB 73 - ADD IN DEBUG AND INSTITUE $Z AND $Y COMMANDS
/  16 FEB 73 - DEBUG ABOVE
/  26 FEB 72 - SPLIT ROUTINE INTO TWO PARTS (ATS9 & USER INTERATION)
/  28 FEB 73 - REMOVE EXISTING CODE FOR INDEX COMMANDS AND FIX SPACES
/   7 MAR 73 - DEBUG OPTIONS FOR SPACES
/  17 APR 73 - MAINTENANCE
/   1 MAY 73 - ADD IN FEATURE TO HANDLER NUMBERED SOURCE FILES
/   2 MAY 73 - DEBUG
/  11 MAY 73 - REVISE OUTPUT FOR LINE NUMBERS
/  17 MAY 73 - REMOVE SOME EXTRANEOUS CODE
/  28 MAY 73 - DEBUG FOR BATCH MODE
/   1 AUG 74 - REVISE WIDE MARGIN TECHNIQUE
/   7 JAN 75 - MAJOR REBUILDING IMPLEMENTED (START DATE: SEPT 74)
/  24 JAN 75 - FIRST ON LINE TEST OF REVISED PROGRAM
/  20 FEB 74 - ADD IN $R AND $NR OPTIONS
/  10 MAR 75 - FIX LINE COUNTING OPTION
/  14 APR 75 - FIX LOSSE ENDS IN FORMATTING MODE
/  14 APR 75 - START ADDING CODE FOR HANDLING TABS (INPUT & OUTPUT)
/     	     - ALSO CODE FOR INDEXING
/  29 APR 75 - CONTINUE TO DEBUG
/   6 MAY 75 -       - DITTO -
/   9 MAY 75 - CHANGE CENTERED PAGE PHILOSOPHY
/  14 MAY 75 - DEBUG CONTINUED
/  29 MAY 75 - ADD MORE PROCESSING CODE FOR INDEXING & FIXES FOR BUGS
/   8 MAR 77 (027; MKH,PDH) MAKE IT WORK WITH XVM/DOS
/
	.EJECT
/	ATS9 COMMANDS:
/            (IN THE ORDER THAT THEY APPEAR IN THE SEARCH TABLE)
/
/	*	$U  - UNFORMATTED MODE - DEFAULT - TERMINAL
/	*	$F  - PARAGRAPH FORMATTED MODE - TERMINAL
/	*	$C  - CENTERED LINE MODE - TERMINAL
/		$N  - WANT NUMBERED LINES - WILL TAKE DEFAULT SPACING AT END OF LINE
/		$M  - WANT WIDE LEFT MARGIN
/		$O  - OMIT MODE - WILL IGNORE COMMANDS UNTIL NEXT $O FOUND
/		$S  - WANT SINGLE SPACING - DEFAULT MODE
/		$D  - WANT DOUBLE SPACING
/		$Y  - WANT SPACES LEFT BETWEEN PARAGRAPHS AND/OR GROUPS
/		$Z  - DON'T WANT SPACES LEFT BETWEEN PARAGRAPHS AND/OR GROUPS - DEFAULT
/		$I  - INDEX ENTRY - NOT FUNCTIONAL
/		$J  - WANT A RIGHT JUSTIFIED RIGHT MARGIN
/		$E  - WILL ALLOW TEXT TO EXCEED RIGHT MARGIN
/			(ONLY OPERATIVE IF TEXT NOT RIGHT JUSTIFIED)
/		$T  - OUTPUT ON TELETYPE
/		$R  - ALLOW RESTRICTED SPACES AT BEGINNING OF LINE
/		      FOLLOWING ')', '.' OR '/' FOR CONTROLLED FORMATTING
/********	0   - MARKS END OF FIRST GROUP
/		$NT - OUTPUT NOT ON TELETYPE - DEFAULT OPTION
/	*	$NP - NEW PAGE COMMAND - TERMINAL
/		$NM - NO WIDE LEFT MARGIN - DEFAULT CONDITION
/		$II - INTERMEDITATE INDEX TITLE - NOT YET OPERATIVE
/		$IE - END OF INDEX ENTRY - NEED FOR PROPER PAGING (INOPERATIVE)
/		$NJ - DON'T WANT RIGHT JUSTIFIED MARGIN - DEFAULT CONDITION
/		$IT - INDEX TITLE - NOT YET FUNCTIONAL
/		$NE - TEXT NOT ALLOWED TO EXCEED RIGHT MARGIN - DEFAULT CONDITON
/	*	$CP - CENTERED PAGE MODE - TERMINAL
/		$NN - NO LINE NUMBERS - DEFAULT CONDITION
/		$NO - INHIBIT OUTPUT
/		$ON - ALLOW OUTPUT  - DEFAULT
/		$NR - DISALLOW RESTRICTED SPACES
/********	0   - MARKS END OF SECOND GROUP
/		$NPN - DON'T WANT PAGE NUMBERS - DEFAULT CONDITION
/		$YPN - WANT PAGE NUMBERS
/********	0    - MARKS END ON THIRD GROUP
/	*	$FUXX;XX;XX;...ETC - DOCUMENT FORMAT MODE - TERMINAL
/		$WXX - LINE WIDTH
/		$NXX - NUMBER OF SPACES AFTER END OF LINE WHERE LINE NUMBERS
/		       ARE TO BE INSERTED
/		$HXX - NUMBER OF SPACES ALLOWED FOR HEADER SPACE ON HEACH PAGE
/		$LXX - NUMBER OF LINES PER PAGE (EXCLUDING HEADER SPACE)
/		$SXX - NUMBER OF START PAGE
/	*	$XX - LEAVE XX BLANK LINES REQUEST - QUASI-TERIMINAL
/
	.EJECT
INDK=-14
OUTDK=-15
SECOUT=10
TEMPDK=2
TEMDK5=1
TTI=-2
TTO=-3
/
SRC	.SIXBT 'SRC'
NUM	.SIXBT 'NUM'
SHT	.SIXBT 'SHT'
SHN	.SIXBT 'SHN'
LST	.SIXBT 'LST'
/
IFLAG	0	/DEFAULT  - NO TITLE AND HENCE INDEX FILE PRESENT
		/+1= TITLE RECIEVED AND INDEX FILE PRESENT
		/-1=NO TITLE RECIEVED BUT INDEX FILE PRESENT
REMBS	0	/POINTS TO 2ND ENTRY IN PGTABL FOR $II ENTRY
		/0 INDICATES NO $II AS YET OR $IE PROCESSED PREVIOUSLY
FIRST	-1	/0= $II WAS LAST INDEX COMMAND PROCESSED
		/+1= $I WAS LAST INDEX COMMAND
		/-1= $IE WAS LAST INDEX COMMAND PROCESSED
PARA	10	/DEFAULT INDENTATION FOR NEW PARAGRAPHS
NEW	0	/FLAG FOR NEW PAGE ISSUED PREVIOUSLY - CLEARED WHEN WRITE
		/SUBROUTINE ENTERED AND SET AFTER NEW PAGE ISSUED
		/CHECKED WHEN BLANK LINE SUBROUTINE ENTERED AND SET
		/SET IF BLANK LINE SUBROUTINE ISSUES A NEW PAGE
		/CHECKED WHEN NEW PAGE SUBROUTINE ENTERED - EFFECT - NO NEW
		/PAGE ISSUED AND FLAG CLEARED
MODE	0	/FLAG FOR CURRENT MODE:  0=UNFORMATTED (DEFAULT)
		/    		         1=FORMATTED MODE (DOCUMENT OR PARA)
		/			-1=CENTERED  MODE (LINE OR PAGE)
MAX	-204	/MAX LINE WIDTH IS 132
DOUBLE	0	/FLAG FOR DOUBLE SPACING (0=NO, 1=YES)
WHATIF	0	/FLAG FOR SPACE REQUEST HELD OVER (0=NO, 1=YES)
NOSP	0	/FLAG FOR SPACES BETWEEN GROUPS OR PARAGRAPHS IN FORMATTED
		/MODE (0=NO, 1=YES)
JUST	0	/FLAG FOR RIGHT JUSTIFYING TEXT IN FORMATTED MODE (0=NO, 1=YES)
INFRST	0	/FLAG FOR 1ST INDEXING COMMAND (0=NO, 1=YES)
CENTPG	0	/CENTERED PAGE FLAG (0=NO, 1=YES)
OMTFLG	0	/FLAG FOR IGNORE COMMANDS (0=NO, 1=YES)
LINEN	0	/LINE COUNTER FROM THE BEGINNING OF SOURCE TEST
TTOUT	0	/SECOND FLAG FOR OUTPUT ON TELETYPE - SET WHEN $T ENCOUNTERED
		/RESET WHEN $NT ENCOUNTERED - CHECK WHEN $NJ ENCOUNTERED
		/BECAUSE WHEN JUST IS RESET WE DONT WANT TO RESET TT
		/IN CASE OUTPUT LINE IS RESTRICTED TO SHORT LINES
NUMBER	-74	/DEFAULT LINE WIDTH OF 60
HEADSP	-2	/DEFAULT HEAD SPACE OF 2 (REALLY 3 WITH ONE LINE FOR PAGE NO.)
LENGTH	-71	/DEFAULT PAGE LENGTH OF 57
LINENM	-71	/USED TO REGULATE PAGE LENGTH - MUST BE INITIALIZED
		/ALSO USED IN A POSITIVE SENSE TO COUNT LINES
		/WHEN CENTERED PAGES ARE PROCESSED
SPDEF	-12	/DEFAULT OF 10 SPACES FOR LINE NUMBERS AT END OF EACH LINE
STRPG	1	/DEFAULT STARTING PAGE OF 1
NOTOUT	0	/FLAG FOR INHIBITING OUTPUT (0=DONT INHIBIT, 1=INHIBIT)
YES	0	/FLAG FOR WIDE LEFT MARGIN (0=NO, 1=YES)
WIDES	BUFFER	/BUFFER ADDRESS WHEN WIDE LEFT MARGIN NOT DESIRED (ADDRESS IS
		/BUFFER-4 WHEN WIDE LEFT MARGIN IN EFFECT
ADDR1	BUFFER+2	/INPUT PACKED ASCII ADDRESS
ADDR2	OUTIMG-1	/OUTPUT IMAGE BUFFER ADDRES
TT	0	/FLAG FOR INDICATING WHETHER TEXT CAN EXCEED RIGHT HAND MARGIN
		/(0=YES 1=NO)
FU	0	/FLAG FOR FORMATTING MODE (0=PARAGRAPH, 1=DOCUMENT)
NOPGNM	0	/FLAG FOR OUTPUTTING PAGE NUMBERS (0=YES, 1=NO)
DIDWE	0	/FLAG FOR WHETHER LAST LINE ISSUED WAS A BLANK LINE(0=NO,1=YES)
NONE	1	/FLAG FOR EMPTY OUTIMG BUFFER (0=NO, 1=YES)
		/(0=NO,1=YES)
PAGENM	0	/USED TO AVOID PAGE NUMBERING CONFILTS WITH CENTERED PAGES
NOSPS	0	/USED TO INDICATE SAME ERROR OCCURRING
POINTS	TAB	/USED IN FORMATTED MODE FOR INDENTATIONS
/
/	ORDINARY VARIABLES
/
GETPNT	/USED IN GET AND MUST BE SETUP BEFORE ENTRY
PNTR1	/USED IN: SMOOTH, ALL,  MAKOCT
NUMB	/USED IN:  SMOOTH, GET, MAKOCT
RECORD	/USED IN: CENTIT,CENTER, UNPCK, CKCHAR,SPACES,SWAP,NEWPG
TEMP	/USED IN: HEADSP, SPACES, CNTIT, OMIT,OCTSUB, ALL
	/SMOOTH, ADDON, PCK, HEAD
PNTR	/USED IN:  SMOOTH, ALL
PNTR2	/USED IN:  GET, MAKOCT, SMOOTH, ALL
TEMP1	/USED IN:  OMIT, SMOOTH, HEAD, SPACES
	/ALSO USED IN OCTSUB AND MUST BE SETPU BEFORE ENTRY
SAVEIT	/USED IN: PCK AND ADDON
TEMSAV	/SUED TO SAVE NUMBER OF SPACES REQUESTED TO PUT OUTPUT ON NEXT
	/PAGE
NAMSAV	/USED TO SAVE ACTUAL TITLE LINES FOR A NAMED SPACE THAT IS
	/TO BE PUT OUT ON THE NEXT PAGE
RESERV	/FREE CORE POINTER
SPNUM	/USED AS AN INTERMEDIATE STORE FOR NUMBER OF SPACES AT END
	/OF LINE WHEN LINE NUMBERS ARE ADDED
CNT	/USED IN:  SPACES, MAKOCT, SMOOTH, ALL, HEAD, OCTSUB, PCK
	/	   STPCK, PACK
ADDR3	/USED TO SAVE ADDR2
TSAVE
BCKCNT
LENPNT
WHICH
COUNT
LAST
LONG
MASK
TOUT
SPCNT
IPLACE
OPLACE
OPLSAV
LINCNT
REMB
PLSAV
TABCNT
SPSAVE
SPADDR
CKNUM
HDSP
EXACT
BLOCK
LASTII
BCKSAV	0	/USED TO SAVE NUMBER OF SPACES REQD TO FILL LINE
SAVADR
COUNT1
SPECAL	0
FRSTSP	0	/USED AS FLAG FOR 1ST SPACE DETECTION IF $R IN EFFECT
IEFLAG		/USED TO SAVE ADDRESS OF CURRENT PAGE NUMBER FOR EXTRACTING
		/PAGE NUMBER FOR 'REMB'
CTPNT
PGPNT		/POINTER TO PGTABL
PGOVER
CBLANK
/
AUTO1=10
AUTO2=11
AUTO3=12
AUTO4=13
/
PG60=74
START	.INIT INDK,0,START	/INPUT SOURCE DEVICE
	.INIT OUTDK,1,START
	.INIT TTI,0,FINI
	.INIT TTO,1,FINI
	.INIT SECOUT,1,START
	LAC	(OUTIMG-1
	DAC*	(AUTO2
WHTRED	DZM*	CHANGE
	ISZ*	DOWE
	CLA
	JMS*	ASK	/ASK FOR FILE NAME
	LAC	(START
	DAC	FSTAT+2
	DAC	SEEK+2
	JMS*	FILENM
	BUFFER+2
	START
	LAC	START+2
PCNT	SAD	NUM	/NUMBERED FILE
TEMPS	SKP
	SAD	SHN	/SHORTENED NUMBER FILE
	SKP
	SAD	SHT	/SHORTENED FILE
	JMP	FSTAT
	LAC	SRC	/ASSUME ITS A SOURCE FILE SINCE EXTENSION IS ODD
STORE	DAC	START+2
	JMP	FSTAT
FSTAT	.FSTAT INDK,START
POINT	SZA
	JMP	SEEK
	LAC	(2
	JMS*	ASK	/FILE NOT FOUND - TRY AGAIN
	JMP	WHTRED
/
SEEK	.SEEK INDK,START	/OPEN FILE
	LAC	LST
STORED	DAC	START+2	/MAKE SURE EXTENSION ON OUTPUT FILE IS LST
	.ENTER OUTDK,START
CHECK	JMP	NEXT	/WILL BE USED AS A SUBROUTINE ENTRY POINT WHEN
	LAC	LINENM	/ARE WE STARTING WITH A CENTERED PAGE
	SMA
	JMP	.+3	/YES DON'T SET UP PAGE LENGTH
	LAC	LENGTH		/FIRST NON COMMAND INPUT LINE ENCOUNTERED
	DAC	LINENM	/ENSURE MOST UP-TO-DATE PAGE LENGTH IS IN EFFECT
	LAC	.+2
	DAC	NX1	/RESTORE PROPER PROGRAM FLOW
	JMP	NOT
/
/	GET EACH LINE OF INPUT FILE AND WORK ON IT
/
NEXT	DZM	PCNT	/ZERO COMMAND POINTER NUMBER
	JMS	RASCII	/READ A LINE, CHECK FOR END OF FILE AND UNPCK LINE INTO IMAGE
	SPA
NX0	JMP	FINI	/NEG INDICATES END OF FILE
NXT	SNA	/CHECK AC FOR 0 - INDICATES NOT A COMMAND
NX1	JMS	CHECK	/CHECK INITIAL CONDITIONS BEFORE PROCEEDING
NX2	TAD	(JMP WHERGO
	DAC	WHERGO
NX4	LAC	PCNT
	SAD	(OMITS
	JMP	NXT1
	CMA
	TAD	(1
	TAD	(ENDD
	SMA
	JMP	NXT0
	LAC	(1	/COMMAND NUMBER OUT OF RANGE - TERMINAL ERROR
	DAC*	CHANGE
	LAC	(46
	JMS*	ASK
/
NXT0	LAC	OMTFLG
	SZA
	JMP	PUTOUT
NXT1	JMS	SETIT
	JMP	NEXT
/
SETIT	XX
WHERGO	XX
	JMP	CMODE0	/UNFORMATTED MODE FLAG=0 - T
	JMP	CMODE1	/FORMATTED MODE FLAG=1 - T
	JMP	CMODE1	/CENTERED LINE MODE FLAG=2 - T
	JMP	NUMS	/NUMBERED LINE OPTION
	JMP	WIDER	/WIDE LEFT MARGIN OPTION
	JMP	OTAG	/OMIT OPTION - T
	JMP	CSP	/SINGLE SPACING
	JMP	CSP	/DOUBLE SPACING
	JMP	CSP	/WANT SPACING BETWEEN PARAGRAPHS
	JMP	CSP	/DON'T WANT SPACING WETWEEN PARAGRAPHS
	JMP	I	/$I INDEX COMMAND - T
	JMP	JS	/RIGHT JUSTY OPTION
	JMP	ESY	/ALLOW TEXT PAST RIGHT MARGIN
	JMP	TS	/OUTPUT ON TELETYPE
	JMP	R	/RESTRICTED SPACE OPTION
	JMP	ST	/OUTPUT NOT ON TELETYPE
	JMP	NEWP	/NEW PAGE - T
	JMP	NW	/NO WIDE LEFT MARGIN
	JMP	II	/$II INDEX COMMAND - T
	JMP	IE	/$IE - END OF INDEX ENTRY - T
	JMP	NJ	/TURN OFF RIGHT JUSTIFY OPTION
	JMP	IT	/$IT - INDEX TITLE COMMAND - T
	JMP	CSP	/DON'T ALLOW FOR TEXT BEYOND SPECIFIED LEFT MARGIN
	JMP	CMODE1	/CENTERED PAGE MODE FLAG=2 - T
	JMP	NUMSN	/NO LINE NUMBERS
	JMP	CSP	/INHIBIT OUTPUT
	JMP	CSP	/ALLOW OUTPUT - DEFAULT CONDITION
	JMP	NR	/TURN OFF RESTRICTED SPACE OPTION - DEFAULT
	JMP	PGNMOF	/NO PAGE NUMBERS
	JMP	PGNMON	/ALLOW PAGE NUMBERS
	JMP	CMODE1	/DOCUMENT FORMAT MODE FLAGE=1 - T
	JMP	LWIDTH	/LINE WIDTH
	JMP	SPADD	/NUMBER OF SPACES FOLLOWING END OF TEXT TO INSERT NUMBERS
	JMP	HSP	/NUMBER OF SPACES IN HEADER OF EACH PAGE
	JMP	PLEN	/NUMBER OF LINES PER PAGE
	JMP	STRP	/NUMBER OF STARTING PAGE - DEFAULT IS 1
/
	LAC	LINENM	/IS THIS PART OF A CENTERED PAGE
	SMA
	JMP	.+4	/YES - DON'T GO TO SPACES
	JMS	GETRID	/NO - CARRY ON
	JMS	SPACES	/SPACES REQUEST
	JMP*	SETIT
/
	LAW	-1
	TAD	SPTABL
	CMA
	DAC	SPTABL
CBL.NK	LAC	(ONESP-1
	JMS	INTERC
	ISZ	SPTABL
	JMP	CBL.NK
	JMP*	SETIT
/
NUMS	LAC	(JMS ADDON	/USE DEFAULT NO OF SPACES FOLLOWING OUTPUT TEXT
	DAC	PKOUT	/FOR SOURCE LINE NO INSERTION
	LAC	SPDEF	/DEFAULT IS -12 OCTAL
	DAC	SPNUM
	JMP*	SETIT
/
PGNMON	DZM	PAGENM	/TURN ON PAGE NUMBERS
	LAC	CENTPG	/ARE WE WAITING ON A CENTERED PAGE
	SNA
	DZM	NOPGNM	/NO - JUST RESET FLAG
	JMP*	SETIT
/
PGNMOF	ISZ	PAGENM	/TURN OFF PAGE NUMBERS
	LAC	CENTPG	/ARE WE WAITING ON A CENTERED PAGE
	SNA
	ISZ	NOPGNM	/NO - JUST SET FLAG
	JMP*	SETIT
/
R	LAC	(NOP
	DAC	AGN.
	JMP*	SETIT
/
NR	LAC	SECPL
	DAC	AGN.
	JMP*	SETIT
/
WIDER	LAC	YES
	SZA
	JMP*	SETIT	/COMMAND IS REDUNDANT
	LAC	(BUFFER-4	/WIDE LEFT MARGIN
	DAC	WIDES
	LAC	MODE
	SZA
	JMP	.+4
	LAC	WIDES
	DAC	WR+2
	DAC	WRIT+2
	ISZ	YES
	LAC	(OUTIMG-2
	DAC	ADDR2
	LAC	MAX
	TAD	(10
	DAC	MAX
	JMP*	SETIT
/
JS	ISZ	JUST	/RIGHT JUSTIFIED TEXT
	ISZ	TT
	JMP*	SETIT
/
TS	LAW	-110	/OUTPUT ON TELETYPE
	DAC	MAX
	ISZ	TTOUT
	ISZ	TT
	JMP*	SETIT
/
ST	LAW	-204	/OUTPUT NOT ON TELETYPE
	DAC	MAX
	DZM	TTOUT
	LAC	JUST
	SNA
	DZM	TT
	JMP*	SETIT
/
NW	LAC	YES
	SNA
	JMP*	SETIT	/COMMAND IS REDUNDANT
	LAC	(BUFFER	/NO WIDE LEFT MARGIN
	DAC	WIDES
	LAW	-10
	TAD	MAX
	DAC	MAX
	DZM	YES
	LAC	(OUTIMG-1
	DAC	ADDR2
	JMP*	SETIT
/
NJ	DZM	JUST	/NO RIGHT JUSTIFY
	LAC	TTOUT
	SNA
	DZM	TT
	JMP*	SETIT
/
ESY	DZM	JUST
	DZM	TT
	JMP*	SETIT
/
NUMSN	LAC	(NOP	/REMOVE INSERTION OF SOURCE LINE NUMBERS
	DAC	PKOUT
	JMP*	SETIT
/
LWIDTH	LAC	TABLE	/LINE WIDTH
	CMA
	TAD	(1
	DAC	NUMBER
	LAC	TABLE
	TAD	MAX
	SMA
	JMP	MUCH
	LAW	-10
	TAD	TABLE
	SMA
	JMP*	SETIT
	LAW	-20
	SKP
MUCH	LAC	MAX	/DEFAULT OF MAX IF LINE WIDTH TOO LONG OR IF LINE WIDTH < 16
	DAC	NUMBER	/THEN 16 IS MIN
	JMP*	SETIT
/
SPADD	LAC	TABLE	/USER SPECIFIED NUMBER OF SPACES FOLLOWING
	CMA		/OUTPUT FOR LINE NUMBER INSERTION
	TAD	(1
	DAC	SPNUM
	LAC	(JMS ADDON
	DAC	PKOUT
	JMP*	SETIT
/
HSP	LAC	TABLE	/GET NUMBER OF SPACES REQ'D
	DAC	HDSP
	CMA
	TAD	(1
	DAC	HEADSP	/STORE NEG
	TAD	(2	/CHECK FOR > 2
	SPA
	JMP	HSPBIG
	LAW	-2	/MAKE HEADSP=2
	DAC	HEADSP
	LAC	(2
	DAC	HDSP
	JMP*	SETIT
/
HSPBIG	LAC	LENGTH	/CHECK THAT HEADSP+PG LENGTH IS NOT >58
	TAD	HEADSP
	TAD	(72
	SMA!CMA
	JMP*	SETIT
/
	TAD	(1
	DAC	TEMP	/SAVE + NO > 58
	LAC	LENGTH	/DETERMINE WHICH IS LARGER
	CMA
	TAD	(1	/MAKE LENGTH POSITIVE
	TAD	HEADSP
	SPA
	JMP	SMALL
	LAC	LENGTH
	TAD	TEMP	/LENGTH IS LARGER - REDUCE IT
	DAC	LENGTH
	JMP*	SETIT
/
SMALL	LAC	HEADSP	/HEADSP IS LARGER - REDUCE IT
	TAD	TEMP
	DAC	HEADSP
	CMA
	TAD	(1
	DAC	HDSP
	JMP*	SETIT
/
PLEN	LAC	TABLE	/GET PAGE LENGTH REQ'D
	CMA
	TAD	(1
	DAC	LENGTH	/STORE IT
	TAD	(3	/MAKE SURE IT IS > 3
	SPA
	JMP	HSPBIG
	LAW	-3
	DAC	LENGTH
	JMP*	SETIT
/
STRP	LAC	TABLE
	DAC	STRPG
	JMP*	SETIT
/
NOT	LAC	(IMAGE-1
	DAC*	(AUTO1
	LAC	MODE
	SNA
	JMP	ZEROM	/UNFORMATTED MODE
	SMA
	JMP	FORMAT	/FORMATTED MODE - EITHER DOCUMENT OR PARAGRAPH
	LAC	(OUTIMG-1
	DAC*	(AUTO2
	JMS	CENTIT
	LAC	(BUFFER-1	/ADDRESS FOR INTERC IF IN $CP
	JMP	PUT
/
ZEROM	DZM	MASK
PUTOUT	LAC	PKOUT	/ARE WE ADDING LINE NUMBERS
	SAD	(JMS ADDON
	SKP		/YES - REPACK LINE FROM IMAGE
	JMP	PUT0	/NO - JUST CARRY ON
	LAC	ADDR2
	DAC	ADDR3	/SAVE CURRENT ADDR2 FOR PCK
	LAC	(IMAGE-1
	DAC	ADDR2
	JMS	PCK
	LAC	ADDR3
	DAC	ADDR2
PUT0	LAC	YES	/DO WE HAVE A WIDE LEFT MARGIN
	SNA
	JMP	PUT	/NO - JUST PUT LINE OUT
	LAC	BUFFER	/YES - ADDIN TAB
	TAD	(2000
	DAC	BUFFER-4
	DZM	BUFFER-3
	DZM	BUFFER	/TAB IS CONTAINED IN BUFFER-2 AND BUFFER-1
	DZM	BUFFER+1
PUT	JMS	WRITES
	JMP	NEXT
/
CMODE0	JMS	GETRID
	JMS	SHOVE
	DZM	FU
	LAC	WIDES	/PUT EITHER ADDRESS BUFFER OR BUFFER-4 IN WRITE SUBROUTINE
	DAC	WR+2
	DAC	WRIT+2
	DZM	MODE
CLINE	LAC	CNTS
	DAC	LCNT	/MAKE SURE WE COUNT LINES
	JMS	CKNXT
	JMP	NEXT
/
CMODE1	LAC	(BUFFER
	DAC	WR+2
	DAC	WRIT+2
	LAC	PCNT
	SAD	(CUU
	JMP	C
	SAD	(CU
	JMP	C
	SAD	(FUU
	JMP	F	/DOCUMENT FORMATTED MODE
/
	DZM	FU	/SET PARAGRAPH FLAG
/
FCOM	LAC	(1
	DAC	MODE	/SET FORMAT MODE FLAG
	DZM	LINCNT	/FOR COUNTING SOURCE LINES IN FORMATTED MODE
	LAC	(ISZ LINCNT
	DAC	LCNT
	JMS	GETRID
FCOM0	JMS	SHOVE
	JMS	CKNXT
	JMP	NEXT
/
F	ISZ	FU
	LAC	(TAB-1
	DAC	POINTS
	JMP	FCOM
/
C	JMS	GETRID
	JMS	SHOVE
	LAW	-1
	DAC	MODE
	LAC	PCNT
	SAD	(CUU
	JMP	CLINE
	JMP	CB
/
NEWP	JMS	CKNXT	/ISSUE CENTERED PAGE IF ANY
	LAC	(NOP
	DAC	GETRID+1
	JMS	GETRID
	LAC	NEWP0+1
	DAC	GETRID+1
	LAC	NEW	/WILL BE NON-ZERO WHEN INTERNALLY GENERATED PAGE
	SNA		/HAS JUST OCCURRED
NEWP0	JMS	NEWPG	/ISSUE REQUEST NEW PAGE
	DZM	NEW
	LAC	FU	/CHECK IF DOCUMENT MODE
	SZA
	JMS	RESET	/YES - DO AGAIN IN CASE WE ARE STAYING IN IT
	JMP	NEXT
/
GETRID	XX
	DZM	NEW
	JMS	FLUSH
	LAC	FU
	SZA
	JMS	RESET
	JMP*	GETRID
/
CKNXT	XX
	DZM	MASK
	LAC	CENTPG
	SNA
	JMP*	CKNXT
	JMS	CEND
	JMS	RESET	/DO AGAIN INCASE $FU COMMAND TERMINATED CENTERED PAGE
	JMP*	CKNXT
/
OTAG	JMS	GETRID
	JMS	SHOVE
	LAC	OMTFLG	/OMIT OPTION
	SNA!CLA
	CLC
	DAC	OMTFLG
	JMP	NEXT
/
CSP	LAC	PCNT	/S,D,Y,Z,NE,NO,ON
	SAD	(SY
	DZM	DOUBLE
	SAD	(DY
	ISZ	DOUBLE
	SAD	(YY
	ISZ	NOSP
	SAD	(ZY
	DZM	NOSP
	SAD	(NEY
	ISZ	TT
	SAD	(NON
	ISZ	NOTOUT
	SAD	(OUI
	DZM	NOTOUT
	JMP*	SETIT
/
/	THIS SUBROUTINE CENTERS THE OUTPUT IMAGE LINE IN OUTIMG
/
CENTIT	XX
	LAC	RECORD	/CENTERING MODE
	TAD	(-1	/ACCOUNT FOR UNPACKING CARRIAGE RETURN AS WELL
	TAD	NUMBER	/DETERMINE IF LINE IS TOO LONG
	SMA!CMA
	JMP	PUTOUT	/LINE IS TOO LONG - JUST WRITE IT OUT
	TAD	(1	/GET POSITIVE NUMBER OF SPACES LEFT
	RCR		/DIVIDE BY 2
	SNA!CMA
	JMP	PUTOUT	/LINE IS JUST BIG ENOUGH - WRITE IT OUT
	TAD	(1
	DAC	RECORD
	LAC	(40
BACK	DAC*	AUTO2	/INSERT SPACES INTO OUTPUT BUFFER
	ISZ	RECORD	/ARE WE FINISHED
	JMP	BACK	/NO
BACK1	LAC*	AUTO1	/GET ACTUAL SOURCE TEXT
	DAC*	AUTO2	/PUT INTO OUTPUT IMAGE FILE
	SAD	(175
	JMP	CENERR
	SAD	(15	/ARE WE FINISHED
	SKP		/YES
	JMP	BACK1	/NO
	JMS	PCK
	JMP*	CENTIT
CENERR	ISZ*	CHANGE	/CANNOT HAVE ALTMODE IN CENTERED LINE
	LAC	(43	/DISPLAY LINE AND GET OUT
	JMS*	ASK
/
CB	LAC	CENTPG	/DID WE JUST CENTER A PAGE
	SNA
	JMP	CBEGIN
	LAC	(NOP
	DAC	CNEWPG	/YES - INHIBIT NEW PAGE COMMAND UPON EXIT FROM CEND
	JMS	CEND
	LAC	NEWP0
	DAC	CNEWPG
CBEGIN	DZM	LINENM
	LAC	CNTS
	DAC	LCNT	/MAYBE DONT NEED THESE TWO LINES
	ISZ	CENTPG
	LAC	(CTABLE	/GET ADDRESS OF LINE ADDRESS TABLE
	DAC	CTPNT
	LAW	-1
	TAD*	(102	/START OF FREE CORE BUFFER
	DAC*	CTPNT
	LAC	(JMS INTERC	/CATCH CENTERED PAGE LINES
	DAC	PUT
	JMP	NEXT
/
/	THIS SUBROUTINE INTERCEPTS THE CENTERED PAGE LINES AND STORES
/	THEM IN THE FREE CORE BUFFER WITH THE ADDRESS BEING STORED
/	STORED IN CTABLE
/
INTERC	XX
	ISZ	LINENM	/COUNT LINE
	DAC*	(AUTO3	/SET UP APPROPRIATE INPUT BUFFER ADDRESS
	TAD	(1
	DAC	SAVADR
	LAC*	CTPNT	/GET NEXT FREE PLACE IN FREE CORE BUFFER
	DAC*	(AUTO4
	LAC*	SAVADR
	AND	(377000
	LRSS	10
	CMA
	TAD	(1
	DAC	CNT	/NEG OF NO OF WORDS TRANSFERRED
	LAC*	AUTO3
	DAC*	AUTO4
	ISZ	CNT
	JMP	.-3
	ISZ	CTPNT
	LAC*	CTPNT	/HAVE WE EXCEED NUMBER OF LINES FOR CENTERED PAGE
	SMA
	JMP	.+5
	LAC	(1	/YES - QUIT
	DAC*	CHANGE
	LAC	(20
	JMS*	ASK
	LAC*	(AUTO4
	DAC*	CTPNT
	TAD	(204
	CMA
	TAD	(1
	TAD*	(103
	SMA
	JMP*	INTERC
	JMP	INERR5
/
/	THIS SUBROUTINE OUTPUTS THE CENTERED PAGE FROM CKNXT
/
CEND	XX
	LAW	-1
	DAC*	CTPNT
	LAC	LINENM	/WERE THERE ANY LINES
	SNA
	JMP	CNEW	/NO - JUST OUTPUT A NEW PAGE IF NECESSARY
	LAC	WR+2	/SAVE CURRENT OUTPUT BUFFER ADDRES IN WRITES TO BE REPLACED
	DAC	STORED	/AFTER THIS CENTERED PAGE RELEASED
	LAW	-PG60	/USUALLY 60 LINES FOR 11" PAGE
	TAD	LINENM	/NO OF LINES TO BE CENTERED
	TAD	(1	/TO BIAS  CENTERING UPWARD IF NECESSARY
	STL		/THE ASSUMPTION IS THAT TOO MANY LINES WILL BE
	RAR		/CAUGHT WHEN THE LINES ARE BEING COLLECTED
	DAC	CBLANK	/DIVIDE BY 2
	TAD	HDSP	/ACCOUNT FOR HEADER SPACES
	SPA		/DO WE NEED MORE THAN THE HEADER SPACES
	JMP	CEND0	/YES - PUT OUT NECESSARY SPACES
	SNA		/ARE THERE JUST ENOUGH
	JMP	.+3	/YES - JUST OUTPUT NEW PAGE
	LAC	CBLANK
	DAC	HEADSP	/ALTER HEADSP SO THAT FOR THIS CENTERED PAGE ONLY THE
	JMS	NEWPG	/APPROPRIATE NO OF SPACES WILL BE FORTHCOMING
	LAC	HDSP
	CMA
	TAD	(1
	DAC	HEADSP
	JMP	CEND1
CEND0	DAC	CBLANK	/MAYBE A CONFLICT WITH FLAG WHATIF IN NEWPG
	JMS	NEWPG
	JMS	BLANK
	ISZ	CBLANK
	JMP	.-2
CEND1	LAC	(CTABLE-1
	DAC*	(AUTO3
CEND2	LAC*	AUTO3
	SPA
	JMP	COVER
	TAD	(1	/ACCOUNT FOR USE OF AUTO INDEX REGISTER WHILE COLLECTING
	DAC	WR+2
	DAC	WRIT+2
	JMS	WRITES
	JMP	CEND2
/
COVER	LAC	STORED
	DAC	WR+2
	DAC	WRIT+2
	LAC	(JMS WRITES
	DAC	PUT
CNEW	LAC	PAGENM
	DAC	NOPGNM
CNEWPG	JMS	NEWPG	/ISSUE A NEW PAGE
	DZM	CENTPG
	DZM*	CTPNT	/GET RID OF END OF TEXT MARKER
	JMP*	CEND
/
/	$IT ENTRY - INDEX TITLE
/
IT	JMS	GETRID
	LAC	IFLAG	/HAVE WE INCOUNTERED A TITLE PREVIOUSLY
	SZA
	JMP	INERR3	/ERROR - OUT OF SEQUENCE OR MORE THAN ONE TITLE
	JMS	SFILE	/INITIATE INDEX FILE
	LAC	(JMP NEXT
	DAC	ITIN0
	LAC	(JMP ITIN	/GET SET TO INTERCEPT ENTRY OF TITLE TEXT
	DAC	NX1
	LAC	(JMP IOUT	/GET SET TO RESTORE REGULAR PROGRAM FLOW
	DAC	NX2	/WHEN NEXT COMMAND IS ENCOUNTERED
	LAC	(JMP INERR6	/TAKE CARE OF ABNORMAL EOF
	DAC	NX0
	ISZ	IFLAG	/SET FLAG FOR TITLE RECIEVED
/
ITIN	JMS	WRDAT1	/SEND OUT LINE IN BUFFER TO INDEX FILE
ITIN0	JMP	NOT	/MODIFIED TO 'JMP NEXT' IF INDEX TITLE
/
/	COMMON EXIT ROUTINE FOR TERMINATING AN INDEX ENTRY
/
IOUT	TAD	(JMP WHERGO
	DAC	WHERGO
	LAC	IOUT
	DAC	NX2
	LAC	(JMP NOT
	DAC	NX1
	DAC	ITIN0
	LAC	(JMP FINI
	DAC	NX0	/ALLOW FOR NORMAL EXIT UPON EOF
	.WRITE TEMDK5,2,DOLIE,34
	.WAIT TEMDK5
	JMP	NX4
/
/	$II ENTRY
/
II	JMS	INDEX
	JMS	POVER
	LAC	PGPNT	/SAVE ADDRESS OF 2ND ENTRY THIS $II
	DAC	REMBS
	TAD	(-1
	DAC	LASTII
	ISZ	PGPNT	/POINTS TO NEXT AVAILABLE ENTRY IN TABLE
	DZM	FIRST	/MARK LAST COMMAND AS $II
/
/	COMMON EXIT FOR INITATING AN INDEX ENTRY EXCEPT $IE
/
INDOUT	LAC	(JMP IOUT
	DAC	NX2
	JMS	WRDAT1
	JMP	NOT
/
/	$I ENTRY
/
I	JMS	INDEX
	JMS	POVER
	LAC	REMBS	/CHECK FOR PREVIOUS $II
	SNA
	JMP	INERR2	/NO PREVIOUS $II
	LAC	(1
	SAD	FIRST	/WAS LAST COMMAND A $I
	JMP	.+3	/YES
	DAC	FIRST	/NO - SET FLAG
	JMP	.+3	/IGNORE FIX FOR PREVIOUS $I
	LAC	STRPG	/FIX UP 2ND ENTRY FOR PREVIOUS $I
	DAC*	IEFLAG
	LAC	PGPNT
	DAC	IEFLAG	/SAVE THIS ADDRESS FOR USE ON NEXT INDEX COMMAND
	ISZ	PGPNT	/MOVE POINTER TO NEXT FREE PLACE
	JMP	INDOUT
/
/	$IE ENTRY
/
IE	LAC	REMBS
	SNA
	JMP	INERR1
	LAC	STRPG
	DAC*	REMBS	/ALWAYS UPDATE LAST $II 2ND ENTRY UPON $IE
	LAC	FIRST	/CHECK FOR PREVIOUS COMMAND
	SNA!CMA
	JMP	IE1	/LAST COMMAND WAS $II HAVE FINISHED
	LAC	STRPG
	DAC*	IEFLAG	/MUST PUT 2ND ENTRY FOR LAST $I
	LAW	-1
IE1	DAC	FIRST
	JMP	INDOUT
/
/	INDEX SUBROUTINES
/
INDEX	XX
	LAC	(JMP ITIN
	DAC	NX1	/GET SET TO INTERCEPT INDEX ENTRY
	LAC	(JMP INERR6
	DAC	NX0	/TAKE CARE OF PREMATURE EOF
	JMS	GETRID
	JMS	CKNXT
	LAW	-12
	DAC	COUNT
	LAC	IFLAG
	SZA!CMA
	JMP*	INDEX
	DAC	IFLAG
	JMS	SFILE
	JMP*	INDEX
/
POVER	XX
	LAC*	PGPNT	/CHECK FOR END OF TABLE
	SPA
	JMS	PGREV	/YES - WRITE OUT BLOCK OF PAGE NUMBERS
	LAC	STRPG
	DAC*	PGPNT	/STORE CURRENT PAGE NUMBER FOR THIS $I OR $II
	ISZ	PGPNT	/MOVE POINTER TO SECOND ENTRY
	LAC	FIRST	/WAS PREVIOUS COMMAND $IE
	SPA
	JMP*	POVER	/YES - GET OUT
	LAC	REMBS	/IS THIS FIRST $II
	SNA
	JMP*	POVER	/YES - GET OUT
	LAC	STRPG
	DAC*	REMBS	/FIX UP PREVIOUS $II
	JMP*	POVER
/
PGREV	XX
	LAC*	LASTII
	DAC	TEMP	/SAVE LAST $II FIRST PAGE NO
	LAW	-1
	DAC*	LASTII	/PUT IN EOD OF TABLE MARKER
	.TRAN TEMPDK,1,BLOCK,PGTABL,256
	.WAIT TEMPDK
	ISZ	BLOCK	/MOVE BLOCK NUMBER UP ONE
	LAC	BLOCK
	SAD	(211
	JMP	INERR5	/PAGE NUMBER TABLE OVERFLOW
	LAC	LASTII
	DAC*	(AUTO3	/GET SET TO MOVE REMAINING TABLE NUMBERS TO BEGINNING
	LAC	(PGTABL-1	/OF PGTABL
	DAC*	(AUTO4
	LAC	TEMP
	DAC*	AUTO4	/PUT SAVED 1ST ENTRY IN BEGINNING OF TABLE
	LAC	(PGTABLE+1
	DAC	REMBS	/SET UP POINTER FOR 2ND ENTRY OF LAST $II
PGREV1	LAC*	AUTO3
	SPA
	JMP	PGROUT	/FALL OUT WHEN END OF TABLE REACHED
	DAC*	AUTO4
	JMP	PGREV1
PGROUT	LAC*	(AUTO4
	TAD	(1
	DAC	PGPNT	/SET UP TABLE POINT TO 1ST FREE PLACE
	JMP*	PGREV
/
SFILE	XX
	.INIT TEMDK5,1,START
	.ENTER TEMDK5,IFILE
	LAW	-12
	DAC	COUNT
	LAC	(PGTABL
	DAC	PGPNT
	JMP*	SFILE
/
WRDAT1	XX
	.WRITE TEMDK5,2,BUFFER,56
	.WAIT TEMDK5
	ISZ	COUNT
	SKP
	JMP	INERR4
	JMP*	WRDAT1
/
/	INDEX ERRORS
/
INERR1	LAC	(21
	JMS*	ASK
	JMP	NEXT	/$IE IGNORED BECAUSE IT IS 1ST INDEX COMMAND
/
INERR2	LAC	(13	/NO PREVIOUS $II COMMAND ENCOUNTERED BEFORE THIS
	ISZ*	CHANGE	/$I COMMAND - TERMINAL
	JMS*	ASK
/
INERR3	LAC	(4	/TITLE OUT OF SEQUENCE OR MORE THAN ONE
	JMS*	ASK	/TITLE - IGNORE UNTIL NEXT COMMAND
	LAC	(JMP NEXT
	DAC	NX1
	JMP	NEXT
/
INERR4	LAC	(11	/TOO MANY LINES IN INDEX ENTRY
	ISZ*	CHANGE	/TERMINAL
	JMS*	ASK
/
INERR5	LAC	(10	/TOO MANY INDEX ENTRIES - TABLE OVERFLOW
	ISZ*	CHANGE
	JMS*	ASK
/
/INDEX	JMS	GETRID	/$II, $I AND $IE COME HERE
	JMS	SHOVE
	LAC	(34	/COMMAND NOT IMPLIMENTED
	JMS*	ASK
	LAC	(1	/DISPLAY SOURCE LINE
	JMS*	ASK
IN1	JMS	RASCII	/IGNORE INPUT UNTIL END OF FILE OR NEXT COMMAND
	SPA
	JMP	INERR6
	SZA
	JMP	NXT
	JMP	IN1
/
INERR6	ISZ*	CHANGE	/EOF REACHED WHILE GETTING INDEX LINES
	LAC	(35
	JMS*	ASK
/
/	COME HERE WHEN MODE IS FORMATTED
/
FORMAT	LAC	FU	/ARE WE IN PARAGRAPH MODE?
	SZA
	JMP	FGO	/IN DOCUMENT MODE
	LAC	IMAGE	/IN PARAGRAPH MODE
	SAD	(40	/IS THIS A NEW PARAGRAPH
	SKP
	JMP	FGO	/NO - CARRY ON
	JMS	FLUSH	/GET RID OF RESIDUAL TEXT IF ANY
	JMS	SHOVE	/MAKE SURE THAT BLANK LINE OCCURS BETWEEN GROUPS
	LAC	IMAGE+1	/CHECK IF PARA NEEDS TO BE CHANGED
	SAD	(40
	SKP
	JMP	FOR2
/
	DZM	PARA
FOR0	LAC*	AUTO1	/GET CHARACTER FOR IMAGE
	SAD	(15	/IS IT EOSL
	JMP	FERR1	/BLANK LINE ENCOUNTERED
	SAD	(40
	SKP
	JMP	FOR1
	LAC	(440	/PUT MODIFIED SPACE IN OUTIMG
	DAC*	AUTO2
	ISZ	PARA	/COUNT SPACE
	ISZ	NUMB	/REDUCE CURRENT LINE CHARACTER COUNT
	JMP	FOR0	/CONTINUE
/
FOR1	LAW	-1
	TAD*	(AUTO1
	DAC*	(AUTO1
	JMS	SHORT
	JMP	FGO	/EVERYTHING ALRIGHT - CONTINUE
/
FERR1	ISZ*	CHANGE
	SAD	(440
	LAC	(54	/INDENTATION TOO LARGE
	LAC	(61	/BLANK LINE ENCOUNTERED
	JMS*	ASK
/
FOR2	LAC	PARA
	DAC	TAB
	DZM	TAB+1
	LAW	-1
	DAC	TAB+2
	LAC	(PARA-1	/SETUP OUTIMG INDENTATION FOR 1ST LINE OF PARAGRAPH
	DAC	POINTS
	JMS	RESET
/
FGO	JMS	TRANSF	/TRANSFER TO OUTIMG_IMAGE
	SAD	(15	/EOSL
	JMP	FCK
	SAD	(700000	/EOG
	JMP	FSTAR
/
	LAC	OPLSAV	/DID WE JUST CONTINUE TO FILL A LINE
	SNA
	JMP	FGO1	/NO - CONTINUE AS USUAL
	LAC	BCKCNT	/DID WE ENCOUNTER A SPACE
	SZA
	JMP	FGO1	/YES - CARRY ON
	LAC	EXACT
	SNA
	JMP	FGO0
	DZM	EXACT
	JMP	FGO1
FGO0	LAC	SPCNT	/DID WE SEND OUT A LINE
	SPA!SNA
	JMP	FGO1	/YES - THIS LINE JUST HAS NO SPACES
	TAD	(-1
	DAC	SPCNT
/
	LAC	TEMPS	/NO - SPECIAL CASE
	DAC	BCKCNT
	JMS	FSEE
	SPA
	JMP	FLONG	/LONG LINE - CAN CARRY ON AS USUAL
	LAC	OPLSAV
	DAC	OPLACE
	LAC	(IMAGE-1
	JMP	FSHT0	/CARRY ON AS FOR SHORT LINE
/
FGO1	DZM	OPLSAV
	JMS	FSEE	/REGULAR OUTPUT LINE AVAILABLE SEE IF LONG OR SHORT
	SMA
	JMP	FSHORT
/
FLONG	LAC	(15	/LONG LINE CAN BE USED
	DAC*	AUTO2	/PUT CARRIAGE RETURN IN OUTIMG
/
FORCOM	JMS	SEND	/SEND LINE OUT, RESET NUMB & AUTO2 AND PUT
			/INDENTATION IN FOR NEXT LINE IF IN DOCUMENT MODE
	JMP	FGO	/CONTINUE
/
FSHORT	LAW	-1	/REDUCE EXPANDABLE SPACES BY 1 AND CHECK FOR NON-ZERO
	TAD	SPCNT
	DAC	SPCNT
	SMA!SZA
	JMP	FSHT	/EVERYTHING ALRIGHT PROCEED
/
	LAC	LONG	/LINE HAS NO EXPANDABLE SPACES
	DAC*	(AUTO1	/RESTORE IMAGE POINTER
	ISZ	SPECAL
	LAC	(15
	DAC*	SPECAL	/PLACE IN OUTIMG FOR CARRIAGE RETURN
NOSPER	LAC	NOSPS	/HAS THIS ERROR OCCURRED IN PREVIOUS LINE
	SZA
	JMP	NOSP1	/YES - JUST ISSUE DITTO
	ISZ	NOSPS
	JMS	PCK
	LAC	(60
	JMS*	ASK
	LAC	(1
NOSP0	JMS*	ASK
	JMP	FORCOM
/
NOSP1	LAC	(3
	JMP	NOSP0
/
FSHT	LAC	IPLACE
	SAD	(IMAGE-1	/DID PREVIOUS LINE END EXACTLY
	SKP
	JMP	FSHT0
	LAC	NUMB
	DAC	BCKCNT
	TAD	(2
	SMA
	JMP	.+3
	LAC	BCKSAV
	DAC	BCKCNT
	LAC	IPLACE
FSHT0	DAC*	(AUTO1
	LAC	(15
	DAC*	OPLACE
	LAC	JUST
	SZA
	JMS	SMOOTH
	JMP	FORCOM
/
/	COME HERE WHEN EOSL FOUND
/
FCK	LAC	LAST	/DID WE TRANSFER ANY CHARACTERS
	SNA
	JMP	NEXT	/NO - GET ANOTHER LINE
	LAC	LONG	/DID WE GET BOTH A LONG AND SHORT LINE
	SZA
	JMP	FCK7	/YES - DECIDE WHICH TO USE
	LAC	NUMB
	SAD	(-1	/SEE IF THERE IS MORE THAN ONE PLACE LEFT IN LINE
	SKP
	JMP	FCK1	/ALRIGHT - MORE THAN ONE PLACE LEFT
	DAC	BCKCNT	/SAVE IT FOR POSSIBLE R.J.
	LAC	(15
	DAC*	AUTO2	/PUT CARRIAGE RETURN
	LAC	JUST	/DO WE RIGHT JUSTIFY
	SZA
	JMS	SMOOTH
FCK0	LAC	(NOP	/DO NOT ALLOW INSERTING FOR A BLANK LINE FROM FLUSH
	DAC	FLUSH0
	JMS	FLUSH	/JUST GET RID OF EXISTING TEXT
	LAC	FCOM0	/REPLACE INSERTION OF BLANK LINES FROM FLUSH
	DAC	FLUSH0
	JMP	NEXT	/GET ANOTHER LINE
/
FCK1	LAW	-1	/ONLY SHORT LINE - NEED MORE TO FILL IT
	TAD*	(AUTO1
	DAC	TEMP	/SAVE CURRENT PLACE IN IMAGE
	LAC*	(AUTO2
	TAD	(1
	DAC	TEMP1	/SAVE CURRENT PLACE IN OUTIMG
	DAC	OPLSAV
	LAC	NUMB	/SAVE CHARACTER COUNTER INCASE OF A RESTART
	DAC	TEMPS
	LAC	SPCNT
	DAC	COUNT1
	DZM	REMB
FCK2	LAC*	TEMP	/EXAMINE LAST CHARACTER IN IMAGE
	SAD	(56	/A PERIOD?
	SKP
	SAD	(72	/A COLON?
	JMP	FCK5	/YES - PUT IN 2 SPACES AND GET OUT
	SAD	(40	/A SPACE?
	JMP	FCK4	/YES - SUBRACT SPACE AND FIND NEXT NON SPACE CHARACTER
	AND	(400
	SZA		/IS IT AN ALTERED CHARACTER (IE '.....')
FCK20	JMP	FCK40	/YES - IGNORE THIS ONE AND KEEP LOOKING
	LAC	REMB	/WERE WE PREVIOUSLY LOOKING A ALTERED CHARACTERS
	SZA
	JMP	FCK40	/YES - IGNORE THIS ONE ALSO UNTIL SPACE FOUND
/
FCK22	LAC	(40
FCK3	DAC*	TEMP1	/PUT IN JOINER SPACE
	LAC	TEMP1
	DAC*	(AUTO2	/RESTORE OUTIMG POINTER
	DAC	OPLACE
	LAC	(IMAGE-1
	DAC	IPLACE
	LAC	NUMB	/ SAVE NUMBER OF SPACES NEEDED TO
	DAC	BCKSAV	/ FILL OUT LINE
	LAC	(JMP FCK40
	DAC	FCK20
	ISZ	NUMB
	ISZ	SPCNT
	NOP		/INCASE SPCNT GETS -1
	JMP	NEXT
/
FCK4	LAC	REMB
	SNA
	JMP	FCK4.
	LAC	(JMP FCK22
	DAC	FCK20
FCK4.	DZM	REMB
	LAW	-1
	TAD	SPCNT
	DAC	SPCNT	/REDUCE EXPANDABLE SPACES BY ONE
	SKP
FCK40	ISZ	REMB
	LAW	-1
	TAD	NUMB
	DAC	NUMB	/REDUCE CHARACTER COUNT BY ONE
	SAD	NUMBER
	JMP	FCKERR	/NO MORE CHARACTERS IN LINE
	LAW	-1
	TAD	TEMP
	DAC	TEMP	/MOVE IMAGE POINTER BACK ONE
	LAW	-1
	TAD	TEMP1
	DAC	TEMP1	/MOVE OUTIMG POINT BACK ONE
	JMP	FCK2
/
FCKERR	LAC*	(AUTO2
	TAD	(1
	DAC	TEMP1	/RESTORE OUTIMG POINTER
	LAC	TEMPS
	DAC	NUMB	/RESTORE CHARACTER COUNTER
	LAW	-1
	TAD	COUNT1
	DAC	SPCNT	/SINCE A NON-EXPANDABLE SPACE INSERTED MAKE SURE
	LAC	(440	/THAT WHEN SPCNT INCREMENTED ITS NOT COUNTED
	JMP	FCK3
/
FCK5	LAC	NUMB	/A PERIOD OR COLON ENDS THIS LINE
	SAD	(-2
	SKP!CLC		/ONLY TWO CHARACTERS LEFT THIS LINE
	JMP	FCK6	/MORE THAN TWO CHARACTERS LEFT THIS LINE
	TAD	TEMP1
	DAC*	(AUTO2	/RESTORE OUTIMG POINTER
	JMP	FCK0
/
FCK6	LAC	(40	/PUT IN TWO SPACES AND EXIT AS IF ONLY A JOINER SPACE
	DAC*	TEMP1
	ISZ	NUMB
	ISZ	TEMP1
	LAC	(400040
	JMP	FCK3
/
FCK7	LAC	NUMB
	SAD	(-20
	JMP	FCK0
	LAC	TOUT	/DID WE ENCOUNTER A SPACE AFTER EOL
	SPA
	JMP	FCK9	/NO - TREAT AS A SHORT LINE
	JMS	FSEE	/LONG AND SHORT LINE EXIST WITH CARRIAGE RETURN
	SPA		/ENDING LONG LINE
	JMP	FCK0	/LONG LING
	JMP	FSHORT
/
FCK9	LAC	OPLSAV	/DID WE JUST CONTINUE TO FILL A LINE
	SNA
	JMP	FSHORT
	LAC	BCKSAV
	DAC	NUMB
	JMP	FSHORT
/
FSTAR	LAC	FU	/ARE WE IN PARAGRAPH MODE
	SZA
	JMP	FSTAR.	/NO - CARRY ON
	LAC	(16	/EOG FOUND WHILE IN PARAGRAPH MODE
	JMS*	ASK
	LAC	(17	/LINE IN QUESTION IS
	JMS*	ASK
	LAC*	(AUTO2
	DAC	TEMP
	TAD	(-1
	DAC*	(AUTO2
	LAC	(15
	DAC*	TEMP
	JMS	PCK
	LAC	(1
	JMS*	ASK
	JMS	FLUSH	/GET LINE PUT OUT
FWARN	LAC*	AUTO1
	SAD	(15
	JMP	NEXT
	SAD	(40
	SKP
	SAD	(440
	JMP	FWARN	/IGNORE SPACES AFTER EOG
	LAW	-1
	TAD*	(AUTO1
	DAC*	(AUTO1
	JMP	FGO
FSTAR.	LAC	NUMB
	SAD	(-20
	JMP	FSTAR0
	LAC	LONG	/DID WE GET BOTH A LONG AND SHORT LINE
	SZA
	JMP	FSTAR1	/YES
/
FSTAR0	LAC	CNTS0-1	/SHORT LINE
	DAC	CNTS0	/MAKE SURE WE GET QUICK EXIT FROM SEND
	JMS	FLUSH	/GET RID OF RESIDUAL TEXT IF ANY
	LAC	(NOP
	DAC	CNTS0	/RESTORE SEND SUBROUTINE
	JMS	RESET	/SET UP FOR NEXT GROUP
	LAC*	AUTO1	/GET NEXT CHARACTER
	SAD	(40
	JMP	.-2	/IGNORE ANY SPACES
	SAD	(15	/END OF LINE
	JMP	NEXT	/IF EOSL FOUND, GET NEXT LINE
	LAW	-1	/THIS CODE EXECUTED IF EOG ENCASED IN INPUT LINE
	TAD*	(AUTO1
	DAC*	(AUTO1	/RESTORE IMAGE POINTER
	JMP	FGO
/
FSTAR1	JMS	FSEE
	SPA
	JMP	FSTAR0	/LONG LINE (TREATED AS SHORT LINE IN THIS CASE)
	JMP	FSHORT	/SHORT LINE, PROGRAM WILL RETURN TO FSTAR WHEN
			/EOG INDICATOR ENCOUNTERED AGAIN
/
FINI	JMS	GETRID
	JMS	CKNXT
	LAC	WHATIF
	SZA
	JMS	NEWPG
	.CLOSE SECOUT
	.CLOSE OUTDK
	LAC	IFLAG
	SNA		/DO WE HAVE AN INDEX FILE
	JMP	FINIS	/NO
	LAC	STRPG
	DAC*	REMBS	/FIX UP LAST $II
	LAC	FIRST
	SNA		/IF LAST COMMAND WAS $II - THEN CLOSE FILE AND CONTINUE
	JMP	.+3
	LAC	STRPG	/LAST COMMAND WAS $I
	DAC*	IEFLAG	/FIX UP 2ND ENTRY FOR THIS COMMAND
/
INOUT	LAC	(DOLIE-1
	JMS	INTERC
	LAC	(BUFFER-1
	JMS	INTERC
	.TRAN TEMPDK,1,BLOCK,PGTABL,256
	.WAIT TEMPDK
	.CLOSE TEMPDK
/
/	ACTUAL OUTPUT CODE NOT WRITTEN YET
/
FINIS	.EXIT
/
/
/	THIS ROUTINE READS FROM SOURCE FILE, CHECKS FOR END OF FILE AND
/	UNPACKS LINE INTO IMAGE BUFFER
/
RASCII	XX
	.READ INDK,2,BUFFER,56	/GET A LINE FROM SOURCE FILE
RAS	.WAIT INDK
	LAC	BUFFER	/CHECK FOR END OF FILE
	AND	(7
	SAD	(5
	JMP	OUT
RAS1.1	JMS	UNPCK	/UNPACK LINE INTO IMAGE BUFFER
	DZM	PCNT
	LAC	BUFFER+2
	AND	(777760
	SAD	(221360	/CHECK FOR COMMENT - $/
	JMP	RASCII+1	/IGNORE COMMENT LINES
	AND	(774000
	SAD	(220000	/CHECK FOR COMMAND - $
	JMS	SEARCH	/SET COMMAND POINTER IF A VALID COMMAND
	CLC
LCNT	JMS	CNTIT	/COUNT LINES
	LAC	PCNT
	JMP*	RASCII
OUT	CLC		/NEG AC TO INDICATE END OF FILE
	JMP*	RASCII
/
DEBUG	.BLOCK 50
/
SEARCH	XX
	LAC	(MTABLE-1
	DAC*	(AUTO4
S01	ISZ	PCNT	/CHECK FOR SINGLE CHARACTER COMMAND
	LAC*	AUTO4
	SAD	BUFFER+2
	JMP	S02	/FOUND A MATCH
	SAD	(0	/END OF SINGLE CHARACTER GROUP
	JMP	S04+1
	LAC*	AUTO4	/SKIP SECOND WORD
	JMP	S01
/
S02	LAC	BUFFER+3	/CHECK SECOND WORD OF SINGLE CHARACTER COMMAND
	AND	(700000	
	SAD*	AUTO4
	JMP*	SEARCH	/FOUND A MATCH
	JMP	S01
/
S04	ISZ	PCNT
	LAC*	AUTO4	/CHECK FOR DOUBLE CHARACTER COMMAND
	SAD	BUFFER+2
	JMP	S05
	SAD	(0	/END OF DOUBLE CHARACTER COMMAND GROUP
	JMP	S06+1
	LAC*	AUTO4	/SKIP SECOND WORD
	JMP	S04
/
S05	LAC	BUFFER+3
	AND	(777400	/CHECK SECOND WORD
	SAD*	AUTO4
	JMP*	SEARCH
	JMP	S04
/
S06	ISZ	PCNT	/CHECK FOR TRIPLE CHARACTER COMMAND
	LAC*	AUTO4
	SAD	BUFFER+2
	JMP	S07
	SAD	(0
	JMP	S08+1
	LAC*	AUTO4
	JMP	S06
/
S07	LAC*	AUTO4	/CHECK FOR SECOND WORD OF TRIPLE CHARACTER COMMAND
	SAD	BUFFER+3
	JMP*	SEARCH
	JMP	S06
/
S08	ISZ	PCNT
	LAC	(IMAGE+2
	DAC	POINT	/CHECK FOR $FU
	LAC	BUFFER+2
	SAD*	AUTO4
	SKP		/FOUND A MATCH
	JMP	S10
	LAC	BUFFER+3
	AND	(700000
	SAD*	AUTO4
	SKP		/FOUND $FU
	JMP	SEXIT
/
	ISZ	POINT
S09	LAC	(TAB
	DAC	GETPNT
	LAC	PCNT
	SAD	(FUU
	JMP	SGET
	SAD	(ENDD
	JMP	.+4
	LAC	(TABLE
	DAC	GETPNT
	JMP	SGET
	LAC	(SPTABL
	DAC	GETPNT
SGET	LAC	POINT
	JMS	GET	/GET A NUMBER
	SNA!SPA
SEXIT	DZM	PCNT	/NOT A VALID SEQUENCE
	JMP*	SEARCH
/
S10	LAC*	AUTO4
	ISZ	PCNT
	LAC*	AUTO4
	SAD	(0
	JMP	S12+1
	DAC	CKNXT
	LAC	BUFFER+2
	AND	(777760
	SAD	CKNXT
	JMP	S09
	JMP	S10
/
S12	ISZ	PCNT
	LAW	-1
	TAD	POINT
	DAC	POINT
	JMP	S09
/
MTABLE	.ASCII '$U'<15>		/1 - T
	.ASCII '$F'<15>		/2 - T
CYES	.ASCII '$C'<15>		/3 - T
	.ASCII '$N'<15>		/4
	.ASCII '$M'<15>		/5
OMT	.ASCII '$O'<15>		/6 - T
SYES	.ASCII '$S'<15>		/7
DYES	.ASCII '$D'<15>		/10
YYES	.ASCII '$Y'<15>		/11
ZYES	.ASCII '$Z'<15>		/12
INUM0	.ASCII '$I'<15>		/13 - T
	.ASCII '$J'<15>		/14
	.ASCII '$E'<15>		/15
	.ASCII '$T'<15>		/16
	.ASCII '$R'<15>		/17
	0
	.ASCII '$NT'<15>	/20
	.ASCII '$NP'<15>	/21 - T
	.ASCII '$NM'<15>	/22
IINUM0	.ASCII '$II'<15>	/23 - T
IENDS	.ASCII '$IE'<15>	/24 - T
	.ASCII '$NJ'<15>	/25
	.ASCII '$IT'<15>	/26 - T
NEYES	.ASCII '$NE'<15>	/27
CPYES	.ASCII '$CP'<15>	/30 - T
	.ASCII '$NN'<15>	/31
NONES	.ASCII '$NO'<15>	/32
ALLSS	.ASCII '$ON'<15>	/33
	.ASCII '$NR'<15>	/34
	0
NWANTS	.ASCII '$NPN'<15>	/35
YWANTS	.ASCII '$YPN'<15>	/36
	0
FUS	.ASCII '$FU'	/37 - T (CHECK 1ST WORD AND 2ND ANDED WITH 700000
	.ASCII '$W'	/40  (CHECK 1ST WORD ANDED WITH 777760)
	.ASCII '$N'	/41
	.ASCII '$H'	/42
	.ASCII '$L'	/43
	.ASCII '$S'	/44
ENDS	0		/45 - SPACES REQUEST
/
OMITS=OMT-MTABLE/2+1
SY=SYES-MTABLE/2+1
DY=DYES-MTABLE/2+1
YY=YYES-MTABLE/2+1
ZY=ZYES-MTABLE/2+1
INUM=INUM0-MTABLE/2+1
NEY=NEYES-MTABLE-1/2+1
CUU=CYES-MTABLE/2+1
IEND=IENDS-MTABLE-1/2+1
IINUM=IINUM0-MTABLE-1/2+1
NON=NONES-MTABLE-1/2+1
OUI=ALLSS-MTABLE-1/2+1
NWANT=NWANTS-MTABLE-2/2+1
YWANT=YWANTS-MTABLE-2/2+1
CU=CPYES-MTABLE-1/2+1
FUU=FUS-MTABLE-3/2+1
ENDD=ENDS-MTABLE-3/2+1
/
/	THIS SUBROUTINE COUNTS SOURCE LINES AND PUTS IMAGE IN EMPTY BUFFER
/	0 ENTRY = FROM FORMATTED CODE (NO LINE INCREMENT NEEDED)
/	-1 ENTRY= FROM RASCII (INCREMENT AND PROCESS)
/	+ VE ENTRY = FROM FORMATTED CODE WHERE OUTPUT LINE CONSISTS OF
/		MORE THAN ONE SOURCE LINE
/
CNTIT	XX
	DAC	CKNXT
	LAC	(EMPTY+6
	DAC	TEMP
	LAC	(15
	DAC*	TEMP
	LAC	CKNXT	/CHECK ENTRY NUMBER
	SMA
	JMP	CNT2
	ISZ	LINEN	/IF NEG, INCREMENT AND CONVERT LINE NUMBER
CNT00	LAC	LINEN
	STL
	JMS*	OCTDEC
	EMPTY
	JMP*	CNTIT
/
CNT2	SNA
	JMP	CNT00	/IF ONLY ZERO, THEN DON'T INCREMENT LINE NUMBER
	LAC	LINEN	/+ ENTRY MEANS MORE THAN ONE SOURCE REQD FOR THIS LINE
	STL
	JMS*	OCTDEC
	EMPTY
	LAC	(55	/HYPHEN
	DAC*	TEMP
	LAC	(EMPTY+15
	DAC	TEMP
	LAC	(15
	DAC*	TEMP
	LAC	CKNXT
	TAD	LINEN
	DAC	LINEN
	STL
	JMS*	OCTDEC
	EMPTY+7
	LAC	(EMPTY+7
	DAC	TEMP
CNT5	LAC*	TEMP
	AND	(77
	SAD	(40
	SKP
	JMP*	CNTIT
	DZM*	TEMP
	ISZ	TEMP
	JMP	CNT5
/
/	THIS SUBROUTINE TRANSFERS CHARACTERS FROM IMAGE TO OUTIMG
/	AND RETURNS WHEN EITHER A) CARRIAGE RETURN FOUND (EOSL)
/	OR B) 1ST SPACE PAST LEGITIMATE EOL ENCOUNTERED (WILL EXIT
/	AFTER 16 CHARACTERS IF NO SPACE ENCOUNTERED)
/
/	IPLACE= PLACE IN IMAGE WHERE 1ST SPACE BEFORE EOL OCCURS
/	OPLACE= PLACE IN OUTIMG WHERE 1ST SPACE BEFORE EOL OCCURS
/	SPCNT= NUMBER OF EXPANDABLE SPACES ENCOUNTERED
/	BCKCNT= NUMBER OF CHARACTERS BEFORE EOL TO 1ST SPACE
/	LONG= FLAG FOR LONG LINE EXISTS (0=NO, 1=YES)
/
TRANSF	XX
	DZM	TOUT	/FLAG FOR EXIT ON LONG LINE
	DZM	LONG
	DZM	LAST
	DZM	BCKCNT
	LAC*	AUTO1
	SAD	(40	/THROW AWAY PRECEEDING SPACES
	JMP	.-2
	SKP
/
TBACK	LAC*	AUTO1	/GET CHARACTER FROM IMAGE
	SAD	(15	/IS IT EOSL (END OF SOURCE LINE)
	JMP*	TRANSF
	SAD	(40	/IS IT A SPACE?
	JMP	TSPACE
	SAD	(700000	/IS IT EOG (END OF GROUP)
	JMP*	TRANSF
	DAC	LAST	/SAVE CHARACTER
TIN	DAC*	AUTO2	/STORE CHARACTER IN OUTIMG
	DZM	NONE	/INDICATE RESIDUAL TEXT EXISTS
	ISZ	NUMB	/HAVE WE FILLED THE LINE
	JMP	TBACK	/NO - CONTINUE
/
	LAC	TOUT	/CHECK IF NUMBER HAS RUN OUT ONCE BEFORE
	SPA
	JMP*	TRANSF	/YES
	LAC*	(AUTO1
	DAC	LONG
	LAC*	(AUTO2
	DAC	SPECAL
	LAW	-20
	DAC	NUMB	/ALLOW FOR 16 CHARACTERS PAST EOL
	LAW	-1
	DAC	TOUT
	JMP	TBACK
/
TSPACE	SAD	LAST	/WAS PREVIOUS CHARACTER A SPACE
	JMP	TYES	/PUT IN MODIFIED SPACE
	ISZ	TOUT	/COUNT SPACE OR SKIP OUT IF PAST EOL
	SKP
	JMP	TEND
	LAC	NUMB
	DAC	BCKCNT	/SAVE NUMBER OF CHARACTERS LEFT
	DZM	BCKSAV
	ISZ	SPCNT	/COUNT EXPANDABLE SPACE
	LAC*	(AUTO2
	TAD	(1
	DAC	OPLACE	/SAVE EOOL (END OF OUTPUT LINE)
	LAC*	(AUTO1
	DAC	IPLACE	/SAVE RESTART PLACE IN IMAGE IF SHORT LINE USED
	LAC	(40	/RESTORE AC
	JMP	TIN-1
/
TYES	LAC	(400040
	JMP	TIN
/
TEND	LAC	NUMB
	SAD	(-20
	SKP
	JMP*	TRANSF
	LAC*	(AUTO2
	TAD	(1
	DAC	OPLACE
	DZM	BCKCNT
	ISZ	EXACT
	LAC*	(AUTO1
	DAC	IPLACE
	JMP*	TRANSF
/
/	THIS ROUTINE COUNTS THE SOURCE LINES, PACKS UP OUTIMG
/	WRITES OUT LINE AND IF IN DOCUMENT MODE, SETS UP NEXT LINE'S
/	INDENTATION
/
SEND	XX
	LAC	JUST
	SNA
	DZM	SPCNT	/ZERO EXPANDABLE SPACE COUNTER IF NOT R.J.
	LAC	LINCNT
	SAD	(1	/DID WE ONLY HAVE ONE LINE SINCE THE LAST ONE
	LAW	-1	/YES - ENTER IN ORDINARY WAY
CNTS	JMS	CNTIT
	DZM	LINCNT
	JMS	PCK
	JMS	WRITES
	LAC	(OUTIMG-1
	DAC*	(AUTO2
	LAC	NUMBER
	DAC	NUMB
	LAC	FU
	SNA
	JMP*	SEND
CNTS0	NOP		/A 'JMP* SEND' WILL BE INSERTED IF A RESET REQUIRED
	LAC*	POINTS
	SNA!CMA
	JMP*	SEND	/GO AWAY IF 0 INDENTATION IS REQUESTED
	TAD	(1
	DAC	CNT
	LAC	(440
SEND0	DAC*	AUTO2
	ISZ	NUMB
	SKP
	JMS	SHORT	/IF THIS IS EXECUTED, THEN WILL HAVE TERMINAL
	ISZ	CNT		/EXIT FROM SHORT
	JMP	SEND0
	JMS	SHORT
	JMP*	SEND
/
/	THIS ROUTINE CHECKS FOR TOO LARGE INDENTATION
/	THERE MUST BE AT LEAST 16 CHARACTERS LEFT IN LINE
/
SHORT	XX
	LAC	NUMB
	TAD	(21
	SPA
	JMP*	SHORT
	LAC	(54
	ISZ*	CHANGE
	JMS*	ASK
/
/	THIS ROUTINE GETS RID OF RESIDUAL TEXT WHEN:
/	A) NEW COMMAND ENCOUNTERED
/	B) EOG FOUND
/	C) EOL COINCIDES WITH EOSL
/
FLUSH	XX
	LAC	NONE	/DOES ANY RESIDUAL TEXT EXIST
	SZA
	JMP	FLUSH1	/NO
	DZM	SPCNT	/ZERO EXPANDABLE SPACES COUNTER
	LAC	(15
	DAC*	AUTO2
	JMS	SEND
FLUSH0	JMS	SHOVE	/REPLACED WITH 'NOP' IF LINE IS JUST LONG ENOUGH
	ISZ	NONE
	JMP*	FLUSH
/
FLUSH1	LAC	NUMBER
	DAC	NUMB
	LAC	(OUTIMG-1
	DAC*	(AUTO2
	JMP*	FLUSH
/
/	THIS ROUTINE INSERTS A BLANK LINE BETWEEN GROUPS OR PARAGRAPHS
/	IF OPTION $Y IS IN EFFECT
/
SHOVE	XX
	LAC	NOSP
	SNA
	JMP*	SHOVE
	LAC	DIDWE
	SNA
	JMS	BLANK
	JMP*	SHOVE
/
/	THIS ROUTINUE RESETS THE DOCUMENT TAB TABLE AND FILLS IN
/	1ST LINE'S INDENTATION.  ALSO CALLED WHEN NEW PARAGRAPH STARTED
/	TO PUT IN INDENTATION
/
RESET	XX
	LAC*	(AUTO2
	SAD	(OUTIMG-1
	SKP
	JMP	RESET4	/WE HAVE ALREADY BEEN HERE
	ISZ	POINTS
RESET3	LAC*	POINTS
	SNA		/CHECK FOR 0 INDENTATION REQUEST
	JMP	RESET2	/HAVE 0 INDENTATION MOVE POINTS AND EXIT
	SMA!CMA
	JMP	RESET0
	LAW	-2
	TAD	POINTS
	DAC	POINTS
	JMP	RESET3
RESET0	TAD	(1
	DAC	CNT
	LAC	(440
RESET1	DAC*	AUTO2
	ISZ	NUMB
	SKP
	JMS	SHORT	/DEFINITELY WILL NOT RETURN AFTER THIS CALL - ERROR
	ISZ	CNT
	JMP	RESET1
	JMS	SHORT
RESET2	ISZ	POINTS
	JMP*	RESET
RESET4	LAC	OUTIMG
	SAD	TABIT
	SKP
	JMP*	RESET
	LAC	(OUTIMG-1
	DAC*	(AUTO2
	JMP	RESET3-1
/
/	THIS ROUTINE DETERMINES WHICH IS THE OPTIUM LINE IF LONG
/	AND SHORT LINES ARE PERMISSIBLE
/
/	EXIT = 0 OR + THEN SHORT LINE
/	EXIT = -VE THEN LONG LINE
/
FSEE	XX
	LAC	TT	/ARE LONG LINES PERMISSIBLE
	SZA
	JMP*	FSEE	/NO
	LAC	NUMB	/DID A SPACE OCCUR AFTER EOL
	SNA		/WILL BE <16
	JMP*	FSEE	/NO BECAUSE NUMB HAS RUN OUT
	TAD	(20	/+ NO OF CHARACTERS AFTER EOL
	TAD	BCKCNT	/- NO OF CHARACTERS BEFORE EOL
	JMP*	FSEE
/
/	THIS SUBROUTINE RIGHT JUSTIFIES TEXT IN OUTIMG
/
SMOOTH	XX
	LAC	BCKCNT
SM0	DAC	TEMP	/NEG NUMBER OF EXTRA SPACES REQD THIS LINE
	SNA		/DO WE NEED ANY SPACES ADDED
	JMP	SMOUT	/NO - GET OUT
	TAD	SPCNT	/POST NUMBER OF EXPANDABLE SPACES IN THIS LINE
	DAC	TEMP1	/SAVE THIS NUMBER
	SMA!SZA	/IF NEG OR ZERO - ALL SPACES IN LINE MUST BE EXPANDED
	JMP	DECIDE	/IF POST - THERE ARE MORE AVAILABLE SPACES IN LINE THAN NEEDED
	LAC	SPCNT	/DID THIS LINE HAVE ANY SPACES
	SZA
	JMP	SM2	/YES
	LAC	(JMP SM1
	DAC	NOSP0+1	/SET UP RETURN FROM ERROR INDICATION
	JMP	NOSPER
SM1	LAC	(JMP FORCOM
	DAC	NOSP0+1	/FIX UP ORIGINAL PROGRAM FLOW
	JMP	SMOUT	/CARRY ON
SM2	JMS	ALL	/INCREMENT ALL EXPANDABLE SPACES BY ONE
	LAC	TEMP1	/GET BACK REDUCED NUMBER OF SPACES NEEDED NOW
	JMP	SM0	/CONTINUE
/
/	TEMP=NEG OF NUMBER OF EXPANDABLE SPACES REQD
/	TEMP1=POST NUMBER OF SPACES EXTRA THAT DONT NEED TO BE EXPANDED
/
DECIDE	LAC	(OUTIMG-1
	DAC*	(AUTO3	/POINT TO OUTPUT BUFFER
	LAC	(TEMIMG-1
	DAC*	(AUTO4	/POINT TO TEMPORARY BUFFER
	ISZ	WHICH	/-1=EXPAND STARTING AT END OF LINE
			/ANYTHING ELSE=EXPAND AT BEGINNING OF LINE
	JMP	BEGIN
/
	LAC	TEMP1
	CMA
	TAD	(1
	DAC	TEMP1	/MOVE DOWN IN OUTPUT BUFFER SKIPPING PAST THOSE
			/SPACES THAT DONT NEED TO BE EXPANDED
	LAC*	AUTO3
	DAC*	AUTO4
	SAD	(40
	ISZ	TEMP1
	JMP	.-4
	JMP	BEGIN2
/
BEGIN	LAW	-1
	DAC	WHICH	/ENSURE NEXT LINE INSERTS COME AT END OF LINE
BEGIN2	LAC*	AUTO3
	DAC*	AUTO4
	SAD	(40
	SKP
	JMP	BEGIN2
	LAC	(440	/INSERT A NON-EXPANDABLE SPACE
	DAC*	AUTO4
	ISZ	TEMP
	JMP	BEGIN2
	LAC*	AUTO3	/NOW MOVE DOWN TO THE END OF THE LINE
	DAC*	AUTO4
	SAD	(15
	SKP
	JMP	.-4
	JMS	MOVEBK	/MOVE LINE BACK TO OUTIMG
SMOUT	DZM	SPCNT	/ZERO EXPANDABLE SPACE COUNTER FOR NEXT COMPLETE LINE
	JMP*	SMOOTH
/
/	THIS ROUTINE MOVES IMAGE TEXT FROM TEMIMG TO OUTIMG
/
MOVEBK	XX
	LAC	(TEMIMG-1
	DAC*	(AUTO3
	LAC	(OUTIMG-1
	DAC*	(AUTO4
	LAC*	AUTO3
	DAC*	AUTO4
	SAD	(15
	JMP*	MOVEBK
	JMP	.-4
/
/	THIS SUBROUINE EXPANDS ALL EXPANDABLE SPACES BY ONE
/
ALL	XX
	LAC	(TEMIMG-1
	DAC*	(AUTO4
	LAC	(OUTIMG-1
	DAC*	(AUTO3
/
ALL0	LAC*	(AUTO4
	SAD	(WAITS
	JMP	ALL2
	LAC*	AUTO3
	DAC*	AUTO4
	SAD	(40
	SKP
	JMP	ALL1
	LAC	(440	/PUT IN EXTRA NON-EXPANDABLE SPACE
	DAC*	AUTO4
	JMP	ALL0
/
ALL2	LAC	ALLS
	DAC*	PUTIT
	ISZ*	CHANGE
	LAC	(50
	JMS*	ASK	/PUT PROGRAM SHOULD NOT BE HERE
/
ALL1	SAD	(15
	SKP
	JMP	ALL0
	JMS	MOVEBK
	JMP*	ALL
/
/
/SUBROUTINE TO CONVERT STRINGS OF DECIMAL IMAGE ASCII NOS TO SINGLE
/OCTAL REPRESENTATIONS 'GETPNT' MUST BE SETUP PRIOR TO ENTRY
/
GET	XX	/ENTER WITH IMAGE ADDRESS IN AC
	DAC	CKNUM
	TAD	(-1
	DAC*	(AUTO4	/SET UP POINTER TO IMAGE TEXT
	DAC	PNTR2	/USED TO RETRIEVE OCTAL NUMBER IN CONVRT
	DAC	PNTR1	/USED TO STORE OCTAL NUMBER BACK IN IMAGE
	DZM	SAVEIT	/USED TO COUNT NO OF COMPLETE NOS GOTTEN
	LAC	GETPNT
	DAC	TEMP	/SAVE OUTPUT TABLE ADDRESS FOR LATER FUNCTION CKS
GET0	LAC	(UNITS
	DAC	PNTR	/USED TO POINT TO MULTIPLIER
GET1	LAC*	AUTO4	/GET A CHARACTER
	SAD	(73	/A SEMI COLON?
	JMP	GETMOR	/YES - MORE NUMBERS TO COME
	SAD	(15	/END OF STRING?
	SKP
	SAD	(175
	JMP	GOTALL	/YES - CONVERT LAST NUMBER AND DO FUNCTION CK
	JMS	ISIT	/IS CURRENT CHARACTER A DIGIT
	SPA
	JMP*	GET	/NO GETOUT
	ISZ	PNTR1
	DAC*	PNTR1	/STORE OCTAL NUMBER BACK IN IMAGE
	LAW	-1
	TAD	PNTR
	DAC	PNTR	/MOVE MULTIPLICAN POINTER BACK ONE
	JMP	GET1	/GET ANOTHER CHARACTER
/
GETMOR	ISZ	PNTR1	/MOVE PAST ';'
	JMS	CONVRT	/MAKE A SINGLE OCTAL NO FROM STRING
	JMP	GET0
/
GOTALL	LAC*	CKNUM
	SAD	(15
	SKP!CLC
	JMP	GOTS
	JMP*	GET
GOTS	JMS	CONVRT	/MAKE A SINGLE OCTAL NO FROM STRING
	LAW	-1
	DAC*	GETPNT	/PUT END OF LIST MARKER IN APPROPRIATE TABLE
/
	LAC	TEMP	/CHECK FOR FUNCTION
	SAD	(TAB	/DOCUMENT FORMAT
	JMP	FUXX
	SAD	(SPTABL	/SPACES REQUEST
	JMP	SXX
	LAC	SAVEIT	/ANY OTHER SHOULD HAVE ONE NUMBER
	SAD	(1
	JMP*	GET	/OK - GET OUT
/
NERR	DAC*	CHANGE	/INAPPROPRIATE NO OF NOS FOR FUNCTION
	LAC	(57
	JMS*	ASK
/
FUXX	LAW	-26	/THERE CAN BE ONLY A MAX OF 22 NOS
	TAD	SAVEIT
	SMA!SZA
	JMP	NERR
	LAC	SAVEIT	/ALSO THERE MUST BE AN EVEN NUMBER OF NOS
	AND	(1
	SZA
	JMP	NERR
	JMP	GETOUT
/
SXX	LAW	-2	/CAN ONLY HAVE A MAX OF 2 NUMBERS FOR SPACES REQUEST
	TAD	SAVEIT
	SMA!SZA
	JMP	NERR
GETOUT	LAC	(1
	JMP*	GET
/
/	CHECKS A CHARACTER IN AC FOR BEING A SINGLE DIGIT FROM 0-9
/	0 OR += A NUMBER; NEG AC=NOT A NUMBER
/
ISIT	XX
	TAD	(-60	/IS IT LESS THAN 60
	SPA
	JMP	ERR
	TAD	(-12
	SMA
	JMP	ERR
	TAD	(12	/0 OR + AC OK - DIGIT RETURNED TO AC
	JMP*	ISIT
/
ERR	CLC		/MAKE AC NEG - INDICATES NOT A DIGIT
	JMP*	ISIT
/
/	THIS ROUTINE DOES THE ACTUAL CONVERSION FROM STRING
/	TO SINGLE OCTAL REPRESENTATION
/
CONVRT	XX
	ISZ	SAVEIT
	LAC	PNTR
	DAC*	(AUTO3
	DZM	NUMB
CON0	ISZ	PNTR2
	LAC*	PNTR2	/GET MULTIPLICAN
	DAC	CONPL
	LAC*	AUTO3	/GET MULTIPLIER
	SNA!CLL
	JMP	CONOUT
	MUL
CONPL	XX
	LACQ
	TAD	NUMB
	DAC	NUMB
	JMP	CON0
/
CONOUT	LAC	NUMB
	DAC*	GETPNT
	ISZ	GETPNT
	JMP*	CONVRT
/
/
/	UNPACKING ROUTINE
/
UNPCK	XX
	DZM	RECORD
	DZM	FRSTSP
	LAC	(BUFFER+1
	JMS	STUNPK
	LAC	(IMAGE-1
	DAC*	(AUTO4	/COULD ADD A 'DZM MASK' IF NECESSARY
AGN	ISZ	RECORD
	JMS	UNPACK
	DAC	IMAGE-1
TCONT0	SAD	(15	/EOL
	SKP
	SAD	(175	/EOL
	JMP	UNPKED
	SAD	(47	/A QUOTE?
	SKP
	SAD	(135	/A RIGHT SQUARE BRACKET?
	SKP
	SAD	(52	/A STAR?
	JMP	SECOND
	SAD	TABIT	/A TAB?
	SKP
	JMP	AGN.
	LAW	-1	/YES HAVE A TAB
	TAD	RECORD
	CLL
	IDIV
	10
	TAD	(-10
	DAC	IMAGE-1	/STORE REMAINDER (THIS IS NO OF SPACES TO BE ADDED)
	LAC	IMAGE-2	/DO WE NEED AN EXPANDABLE SPACE
	SAD	(40
	SKP
	SAD	(440
	JMP	TCONT	/NO - JUST PUT IN AS MANY NON-EXPANDABLE SPACES AS NECESSARY
	LAC	(40	/YES - ADD EXPANDABLE SPACE
	XOR	MASK	/MUST USE MASK IN CASE SINGLE QUOTE IN EFFECT
	DAC*	AUTO4
	ISZ	IMAGE-1
	SKP
	JMP	AGN	/ONLY ONE SPACE REQ'D
TCONT	ISZ	RECORD
	LAC	(440
	DAC*	AUTO4
	ISZ	IMAGE-1
	SKP
	JMP	AGN
	ISZ	RECORD
	JMP	TCONT+1
AGN.	JMP	AGN0-1	/IS REPLACED BY 'NOP' IF $R IS IN FORCE
	SAD	(40	/IS THIS CHARACTER A SPACE
	ISZ	FRSTSP	/YES - SET FLAG
	SAD	(51	/IS IT A LEFT BRACKET
	SKP
	SAD	(56	/A PERIOD?
	SKP
	SAD	(57	/A SLASH?
	JMP	FRSTCK	/YES - SEE WHAT NEXT CHARACTER IS IF NECESSARY
/
	XOR	MASK
AGN0	DAC*	AUTO4	/STORE CHARACTER AND CONTINUE
	DAC	IMAGE-2	/SAVE LAST CHARACTER STORED
	JMP	AGN
/
FRSTCK	LAC	FRSTSP	/HAVE WE ENCOUNTERED A SPACE ALREADY
	SNA
	JMP	SECPL+1	/NO
	LAC	IMAGE-1	/YES - CONTINUE AS USUAL
SECPL	JMP	AGN0-1
/
	ISZ	FRSTSP	/NO - SET FLAG AS IF A SPACE WAS ENCOUNTERED
	LAC	IMAGE-1	/GET BACK CURRENT CHARACTER
	XOR	MASK
	DAC*	AUTO4	/STORE IT
	ISZ	RECORD	/COUNT NEXT CHARACTER
	JMS	UNPACK	/GET NEXT CHARACTER
	SAD	(40	/IS IT A SPACE?
	SKP
	JMP	TCONT0-1	/NO - CONTINUE AS USUAL
	LAC	(440	/GET SET TO STORE ALTERED SPACE
	JMP	AGN0
/
SECOND	JMS	UNPACK	/GET NEXT CHARACTER
	DAC	IMAGE-2	/STORE IT
	SAD	(15
	SKP
	SAD	(175
	JMP	SECOT	/EOSL - STORE PREVIOUS CHARACTER & GET OUT
	SAD	(47	/A SECOND QUOTE?
	SKP
	SAD	(135	/A SECOND RIGHT SQUARE BRACKET?
	JMP	SEC1	/YES - SAVE ONE AND CONTINUE
	SAD	(57	/A SLASH?
	JMP	EOG	/YES - REPLACE WITH 452 MARKER AND CONTINUE
SEC0	LAC	IMAGE-1	/GET BACK PREVIOUS CHARACTER
	SAD	(47	/A SINGLE QUOTE?
	JMP	CHGMSK	/YES - CHANGE MASK
	SAD	(135	/A SINGLE RIGHT SQURARE BRACKET
	JMP	.+5	/YES - GET SET TO REMOVE SOURCE LINE NUMBERS
	XOR	MASK
	DAC*	AUTO4	/STORE PREVIOUS CHARACTER
	ISZ	RECORD	/COUNT NEXT CHARACTER
	LAC	IMAGE-2	/GET BACK CURRENT CHARACTER
	JMP	AGN0-1
SEC1	SAD	IMAGE-1
	JMP	AGN0
	JMP	SEC0
T0	LAW	-1
	TAD	RECORD
	DAC	RECORD	/REDUCE CHARACTER COUNTER BY ONE
	LAC*	(AUTO4
	DAC	PNTR	/SAVE CURRENT ADDRESS IN IMAGE BUFFER
/
TAKOUT	LAC*	PNTR
	SAD	(133	/A LEFT SQUARE BRACKET?
	JMP	ELM
	LAW	-1
	TAD	PNTR
	DAC	PNTR
	LAW	-1
	TAD	RECORD
	DAC	RECORD
	JMP	TAKOUT
/
ELM	LAW	-1
	TAD	PNTR
	DAC	PNTR
	LAC*	PNTR
	SAD	(40
	SKP
	JMP	ELM0
	LAW	-1
	TAD	RECORD
	DAC	RECORD
	JMP	ELM
/
ELM0	LAC	PNTR
	DAC*	(AUTO4
	LAC	IMAGE-2	/GET BACK LAST CHARACTER
	SAD	(15
	SKP
	SAD	(175
	JMP	UNPKED	/EOSL - GET OUT
	JMP	AGN
/
SECOT	LAC	IMAGE-1	/GET BACK PREVIOUS CHARACTER
	SAD	(47	/A QUOTE?
	JMP	CHGMSK	/ALTER MASK, THEN STORE CARRIAGE RETURN AND GET OUT
	SAD	(135	/A RIGHT SQUARE BRACKET
	JMP	T0	/MUST FIRST TAKOUT TO LEFT BRACKET BEFORE EXITING
	DAC*	AUTO4	/STORE PREVIOUS CHARACTER
	ISZ	RECORD	/COUNT IT
	LAC	(15
UNPKED	DAC*	AUTO4
	LAC	RECORD
	RCR
	SZL!RAL	/CHECK FOR EVEN OR ODD
	TAD	(3
	ALSS	10
	XOR	(3
	DAC	IMAGE-2	/HEADER WORD PAIR FOR IMAGE IF NECESSARY
	DZM	IMAGE-1
	JMP*	UNPCK
/
EOG	LAC	(700000	/SPECIAL MARKER FOR END OF GROUP IN FORMATTED MODE
	JMP	AGN0
/
CHGMSK	LAC	MASK
	SNA!CLA
	LAC	(400
	DAC	MASK
	LAC	IMAGE-2	/RESTORE FOLLOWING CHARACTER
	SAD	(15
	SKP
	SAD	(175
	JMP	UNPKED-1	/GET OUT
	JMP	AGN0-1	/CARRY ON
/
/
/	NORMALLY PACKS A LINE FROM OUTIMG TO BUFFER AND SETS A HEADER
/	WORD PAIR FOR AN ASCII WRITE TO SOURCE OUTPUT DEVICE
/	CAN BE USED FOR ANY IMAGE-PACKED ASCII BUFFER BY
/	CHANGING ADDR2 (IMAGE BUFFER) AND ADDR1 (PACKED ASCII BUFFER)
/
PCK	XX
	DZM	FRSTSP	/ZERO FLAG FOR DETECTING 1ST SPACE
	LAW	-10
	DAC	TABCNT	/SET UP CHARACTER FIELD COUNTER
	LAC	ADDR1
	TAD	(-2
	DAC	TEMP
	LAC	ADDR1
	JMS	STPCK
	LAC	ADDR2
	DAC*	(AUTO3
PK0	LAC*	AUTO3
	AND	(177
	SAD	(15
	SKP
	SAD	(175
	JMP	PKOUT
	SAD	(40	/IS IT A SPACE?
	JMP	PSPACE	/YES CHECK IT OUT
	DZM	FRSTSP	/RESET FLAG AS A NON-SPACE CHARACTER HAS BEEN FOUND
	SAD	TABIT	/A TAB?
	JMP	PIN0	/RESET TABCNT AND PACK CHAR UP
PIN	ISZ	TABCNT	/ARE WE AT THE END OF A FIELD
	JMP	PCONT	/NO - CARRY ON
PIN0	DAC	IMAGE-1	/SAVE AC TEMPORARILY
	LAW	-10
	DAC	TABCNT	/RESET FIELD WIDTH COUNTER
	LAC	IMAGE-1	/GET BACK AC
PCONT	JMS	PACK
	JMP	PK0
/
PSPACE	LAC	FRSTSP	/SHOULD WE CHECK THIS SPACE
	SNA
	JMP	PS1	/YES
PS0	LAC	(40	/NO - RESTORE AC AND CONTINUE
	JMP	PIN
PS1	ISZ	TABCNT	/HAS FIELD BEEN EXHAUSTED WITH THIS SPACE
	JMP	PSCONT	/NO - KEEP CHECKING
	LAW	-1
	DAC	TABCNT	/GET SET TO RESET TABCNT AND AC
	JMP	PS0
/
PSCONT	ISZ	FRSTSP	/SET FLAG
	LAW	-1
	TAD	TABCNT
	DAC	SPSAVE	/SAVE TAB FIELD COUNTER
	LAW	-1
	TAD*	(AUTO3
	DAC	SPADDR	/SAVE CURRENT PLACE
PSAGN	LAC*	AUTO3	/GET A CHARACTER
	AND	(177	/TRIM WORD
	SAD	(15	/IS IT EOL
	SKP
	SAD	(175
	JMP	PSOUT	/YES - RESTORE AUTO3 AND CONTINUE
	SAD	(40	/A SPACE?
	SKP
	JMP	PSOUT	/NO - EXIT
	ISZ	TABCNT	/DID THE FIELD COUNTER RUN OUT
	JMP	PSAGN	/NO
	LAW	-1
	DAC	TABCNT
	LAC	SPSAVE
	CMA
	TAD	SAVEIT
	DAC	SAVEIT
	DZM	FRSTSP
	LAC	TABIT	/PUT TAB IN AC TO BE PACKED UP
	JMP	PIN
/
PSOUT	LAC	SPADDR
	DAC*	(AUTO3
	LAC	SPSAVE
	DAC	TABCNT
	JMP	PK0
/
PKOUT	NOP		/REPLACED BY JMS ADDON IF INSERTING LINE NUMBERS
	JMS	PACK
	ISZ	CNT	/TAKE CARE OF HEADER-WORD PAIR
	LAC	CNT
	ALSS	11
	XOR	2
	DAC*	TEMP
	ISZ	TEMP
	DZM*	TEMP
	JMP*	PCK
/
STPCK	XX
	DAC	POINT	/STORE OUTPUT BUFFER ADDRESS
	DZM	SAVEIT	/COUNTS CHARACTERS
	DZM	CNT	/COUNTS WORD PAIRS
	LAC	(LEFT
	DAC	SWING
	JMP*	STPCK
/
PACK	XX
	ISZ	SAVEIT	/COUNT CHARACTERS
	CLQ!020000
	JMP*	SWING
SWING	.DSA	LEFT
	TAD*	POINT
	DAC*	POINT
	JMP*	PACK
/
LEFT	ISZ	CNT	/INCREMENT WORD PAIR COUNTER
	RTR
	RTR
	RTR
	RTR		/SHIFT 11 LEFT
	DZM*	POINT
	JMS	SWING
/
LEFT1	RTL
	RTL		/SHIFT 4 LEFT
	JMS	SWING
/
LEFT2	LRS	3
	TAD*	POINT
	DAC*	POINT	/1ST WORD OF PAIR COMPLETE
	ISZ	POINT
	DZM*	POINT
	LACQ
	JMS	SWING
/
LEFT3	RTL
	RTL
	RTL
	RTL		/SHIFT 8 LEFT
	JMS	SWING
/
LEFT4	RAL		/SHIFT 1 LEFT
	JMS	SWING
/
LEFT5	ISZ	POINT
	JMP	LEFT
/
/	THIS SUBROUTINE ADDS SOURCE LINE INDICATOR TO OUTPUT LINE
/
ADDON	XX
	LAC	SAVEIT	/MUST SEE HOW MANY SPACES TO ADD
	TAD	NUMBER
	SMA
	JMP	ADD5	/WE HAVE EITHER A JUST FULL LINE (0) OR LONG LINE (+)
ADD1	TAD	SPNUM	/NOT A FULL LINE ADD REMAIN SPACES
ADD2	DAC	TSAVE
	LAC	TSAVE
	CMA
	TAD	(1	/POSITIVE NO OS SPACES REQUIRED
	TAD	TABCNT	/NEG OF CURRENT FIELD COUNTER
	SPA		/CAN WE ADD ANY TABS
	JMP	ADD30	/NO - ONLY NEED SPACES
ADD3	DAC	TSAVE
	LAC	TABIT
	JMS	PACK	/PACK UP A TAB
	LAC	TSAVE	/IS THERE ANY SPACES LEFT
	SNA
	JMP	ADD31	/NO - JUST ADD ON LINE NO
	TAD	(-10
	SMA		/IS THE NO OF SPACES LEFT SMALLER THAN A FIELD WIDTH
	JMP	ADD3	/NO - PUT IN ANOTHER TAB
	LAC	TSAVE	/YES - MAKE IT NEG AND INSERT SPACES
	TAD	(1
	DAC	TSAVE
ADD30	LAC	(40
	JMS	PACK
	ISZ	TSAVE
	JMP	.-3
ADD31	LAC	(EMPTY-1
	DAC*	(AUTO3
ADD4	LAC*	AUTO3
	AND	(177	/TRIM TO 7 BITS
	SAD	(15
	JMP*	ADDON
	JMS	PACK
	JMP	ADD4
/
ADD5	SNA
	JMP	ADD1	/A LINE THAT'S JUST FULL - ADDON NO OF SPACES
	DAC	TSAVE	/MORE THAN A FULL LINE
	TAD	SPNUM
	SPA
	JMP	ADD2	/ADD REDUCED AMOUNT OF SPACES
	LAW	-1	/LONGEST LINE
	JMP	ADD2
/
/
/	WRITES FROM BUFFER TO OUTPUT SOURCE DEVICE
/
WRITES	XX
	LAC	NOTOUT
	SZA
	JMP	WR1
	LAC	WHATIF
	SNA
	JMP	WRIT0
	LAC	PUTIT
	DAC	TEMP
	LAC	WRITE
	DAC*	TEMP
	ISZ	TEMP
	LAC	WRITE+1
	DAC*	TEMP
	ISZ*	CHANGE
	LAC	(50	/PROGRAM SHOULD NOT BE HERE
	JMS*	ASK
WRIT0	LAS		/DO WE WANT SECONDARY OUTPUT
	SNA
	JMP	WR
WRIT	.WRITE SECOUT,2,BUFFER,34
	.WAIT SECOUT
WR	.WRITE OUTDK,2,BUFFER,34
TAG6	.WAIT OUTDK
WR1	DZM	DIDWE
	DZM	NEW	/MAKE SURE NEW PAGE CAN NOW OCCUR
	LAC	DOUBLE
	SZA
	JMS	BLANK
	ISZ	LINENM
	JMP*	WRITES
	JMS	NEWPG
	ISZ	NEW	/FLAG FOR INTERNALLY GENERATED NEW PAGES
	JMP*	WRITES
/
/	THIS SUBROUTINE PUTS IN HEADER SPACE FOR EACH NEW PAGE
/
HEAD	XX
	LAC	NOTOUT
	SZA
	JMP	HEAD0
	LAS
	SNA
	JMP	HEAD01
	.WRITE SECOUT,2,FORMFD,34
	.WAIT SECOUT
HEAD01	.WRITE OUTDK,2,FORMFD,34
	.WAIT OUTDK
HEAD0	LAC	NOPGNM	/DO WE WANT PAGE NUMBERS
	SNA
	JMP	HEAD1
	ISZ	STRPG	/NO - COUNT PAGE ANYWAY AND ISSUE BLANK LINE
	JMS	BLANK
	JMP*	HEAD
HEAD1	LAC	STRPG	/YES - CONVERT PAGE NUMBER
	STL
	JMS*	OCTDEC
	PGIMG
	ISZ	STRPG
	LAC	NOTOUT
	SZA
	JMP*	HEAD
	LAC	(OUTIMG-1
	DAC*	(AUTO3
	LAC*	.DIGCT	/NUMBER OF DIGITS CONVERTED
	SZA
	JMP	HEAD2
	ISZ*	CHANGE
	LAC	(55	/SHOULD HAVE FOUND A PAGE NO - DIDN'T
	JMS*	ASK
HEAD2	TAD	(5	/WORD PAGE + 1 SPACE
	TAD	NUMBER
	DAC	TEMP1
/
HEAD20	SMA
	JMP	HEAD22
	TAD	(10
	SMA!SZA
	JMP	HEAD21
	DAC	TEMP1
	LAC	TABIT
	DAC*	AUTO3
	LAC	TEMP1
	JMP	HEAD20
HEAD21	LAC	(40
	DAC*	AUTO3
	ISZ	TEMP1	/FILL BEGINNING OF LINE WITH SPACES
	JMP	.-2
HEAD22	LAC	(PGHD-1
	DAC*	(AUTO4
HEAD3	LAC*	AUTO4	/ADD 'PAGE NO. ' AND ACTUAL PAGE NUMBER
	SAD	(760040	/IGNORE SPACES FROM OCTDEC
	JMP	.-2
	DAC*	AUTO3
	SAD	(15
	SKP
	JMP	HEAD3
	JMS	PCK
	ISZ	DIDWE	/INHIBIT INSERTION OF A SPACE
	LAC	WRITES
	DAC	SAVEIT
	LAC	(NOP
	SAD	PKOUT
	JMP	.+3
	DAC	PKOUT
	DAC	HEAD5
	LAC	WR+2	/ACCOUNT FOR POSSIBLE CHANGE OF PACKED BUFFER ADDR
	DAC	STORE	/IF IN UNFORMATTED MODE
	LAC	(BUFFER
	DAC	WR+2
	DAC	WRIT+2
	JMS	WRITES
	LAC	STORE
	DAC	WR+2
	DAC	WRIT+2
	LAC	(JMS ADDON
HEAD5	SKP
	DAC	PKOUT
	LAC	(SKP
	DAC	HEAD5
	LAC	SAVEIT
	DAC	WRITES
	JMP*	HEAD
/
BLANK	XX
	LAC	NOTOUT
BPL	SZA
	JMP	WY
	ISZ	DIDWE
	LAS
	SNA
	JMP	W
	.WRITE SECOUT,2,ONESP,34
	.WAIT SECOUT
W	.WRITE OUTDK,2,ONESP,34
	.WAIT OUTDK
WY	ISZ	LINENM
	JMP*	BLANK
	LAC	BLANK
	DAC	SAVADR
	JMS	NEWPG
	JMP*	SAVADR
/
/
SPACES	XX
	LAC	SPTABL+1
	SPA
	CLA
	DAC	SPTABL+1
	LAC	SPTABL	/SAVE SPACE TABLE
	DAC	TEMPS
	TAD	SPTABL+1	/ADD IN FOR TITLE LINES IF ANY
	TAD	LENGTH	/PG LENGTH-SPACE REQUEST
	SMA
	JMP	SPERR	/ASKED FOR A SPACE LARGER THAN THE PAGE LENGTH
	LAC	LINENM	/NUMBER OF LINES LEFT THIS PAGE
	TAD	SPTABL+1	/SUBT NUMBER OF TITLE LINES IF ANY
	TAD	TEMPS	/NUMBER OF SPACES ASKED FOR
	SPA
	JMP	GO	/ENOUGH LINES LEFT
	SNA
	JMP	OPT1	/WILL JUST FIT - ISSUE NEW PAGE AND GET OUT
	DAC	CNT	/SAVE POSITIVE NUMBER OF SPACES LEFT THIS PAGE
	LAC	WHATIF	/ARE WE ALREADY WAITING TO OUTPUT A FIGURE
	SNA
	JMP	SAGN0
	LAC	PUTIT
	DAC	TEMP
	LAC	SPACE
	DAC*	TEMP
	ISZ	TEMP
	LAC	SPACE+1
	DAC*	TEMP
	ISZ	TEMP
	LAC	SPACE+2
	DAC*	TEMP
	ISZ*	CHANGE
	LAC	(50	/PROGRAM SHOULD NOT BE HERE
	JMS*	ASK
SAGN0	LAC	A17
	DAC	TEMP1	/FOR OCTSUB
	LAW	-1
	TAD	LINENM
	CMA
	JMS	OCTSUB	/CREATE A PACKED ASCII NUMBER OF SPACES LEFT
	LAC	A16
	DAC	TEMP1	/FOR OCTSUB
	LAC	TEMPS	/INSERT NUMBER OF SPACES REQUESTED
	JMS	OCTSUB
	LAC	(5	/TELL USER HOW MUCH SPACE HE REQUIRES
	JMS*	ASK
	LAC	(6	/TELL USER HOW MUCH SPACE AVAILABLE
	JMS*	ASK
	LAC	(7	/ASK USER TO CHOOSE AN OPTION
	JMS	SAGN	/GO GET THE NUMBER
	JMP	SAGN2
SAGN	XX		/THIS ROUTINE ALLOWS FOR USER INTERACTION
	DAC	CNT	/SAVE AC
	DZM*	CHANGE
	ISZ*	DOWE
	JMS*	ASK
	LAC	(TABLE
	DAC	GETPNT
	LAC	(IMAGE
	JMS	GET
	SZA
	JMP*	SAGN
	LAC	(57	/NOT A VALID NUMBER
	JMS*	ASK	/ALLOW USER TO ALTER REQUEST IF HE WANTS TO
	LAC	CNT
	JMP	SAGN+2
/
SAGN2	LAW	-5
	TAD	TABLE
	SPA
	JMP	SETJMP
	LAC	(30	/OPTION CHOICE OUTSIDE RANGE
	JMS*	ASK
	JMP	SAGN
/
SETJMP	LAC	(JMP DISPCH+1
	TAD	TABLE
	DAC	DISPCH
DISPCH	XX
	JMP	OPT0	/ALLOW ENTRY OF NEW NO. OF SPACES
	JMP	OPT1	/WILL ACCEPT REDUCED SPACE
	JMP	OPT2	/MOVE SPACE TO NEXT PAGE AND FILL CURRENT PAGE WITH TEXT
OPT3	JMS	NEWPG	/JUST GO TO NEW PAGE
OPT4	JMP	GO	/SPREAD SPACES OVER TWO PAGES
/
OPT0	LAC	(31	/ALLOW USER TO ALTER NO OF SPACES
	JMS	SAGN
	LAC	TABLE
	DAC	SPTABL
	JMP	SPACES+1
/
OPT1	JMS	NEWPG
	JMP*	SPACES
/
OPT2	LAC	(36	/OPTION NOT IMPLIMENTED - CHOOSE ANOTHER
	JMS*	ASK
	JMP	SAGN-3
	ISZ	WHATIF	/FLAG FOR FIGURE WAITING IN WINGS
	LAC	TEMPS
	DAC	TEMSAV	/SAVE CURRENT SPACE REQUEST
	LAC	SPTABL+1
	SNA!CMA
	JMP*	SPACES	/GET OUT IF NO TITLE LINES
	TAD	(1
	DAC	NAMSAV
	DAC	SPTABL+1
	LAC*	(102
	DAC*	(AUTO2
	LAC	(IMAGE-1
	DAC*	(AUTO1
	LAC	(RECSAV
	DAC	LENPNT
OPTRED	JMS	RASCII
	SZA
	JMP	WARN
	LAC	RECORD
	DAC*	LENPNT
	ISZ	LENPNT
OR1	LAC*	(AUTO1
	SAD*	(103
	JMP	TOVER
	LAC*	AUTO1	/SAVE IMAGE LINES IN FREE CORE
	DAC*	AUTO2
	SAD	(175
	JMP	OPTERR
	SAD	(15
	SKP
	JMP	OR1
	LAC*	(AUTO1
	SAD*	(103
	JMP	TOVER
/
	ISZ	SPTABL+1
	JMP	OPTRED
	LAW	-1
	DAC*	LENPNT
	JMP*	SPACES
TOVER	LAC	(42	/TITLE BUFFER OVERFLOW
	SKP
OPTERR	LAC	(41	/CANNOT HAVE ALTMODE IN TITLE LINES
	SKP
WARN	LAC	(40	/END OF FILE REACHED WHILE GETTING TITLE LINES
	DAC	TEMP
	ISZ*	CHANGE
	LAC	TEMP
	JMS*	ASK
/
SPERR	LAC	LINENM
	DAC	SPTABL+1
	CMA
	TAD	(1
	DAC	CNT	/NUMBER OF SPACES LEFT THIS PAGE
	LAC	(12
	JMS*	ASK	/SPACE REQUEST TOO LARGE
	JMP	SAGN0
/
GO	LAC	TEMPS
	CMA
	TAD	(1
	DAC	TEMPS
	LAC	SPACES
	DAC	PLSAV
	JMS	BLANK
	ISZ	TEMPS
	JMP	.-2
	LAC	PLSAV
	DAC	SPACES
	LAC	SPTABL+1	/ARE THERE ANY TITLE LINES
	SNA!CMA
	JMP*	SPACES	/NO - GET OUT
	TAD	(1	/YES -MAKE # OF LINES NEG
	DAC	SPTABL+1
GETAGN	JMS	RASCII	/GET A TITLE LINE
	SZA
	JMP	WARN
	JMS	CENTIT	/CENTER IT
	JMS	PCK
	JMS	WRITE	/MAYBE SHOULD GO TO PACK FIRST*********
	ISZ	SPTABL+1
	JMP	GETAGN	/NO FINISHED - CONTINUE
	JMP*	SPACES
/
/
/	.TITLE STUNPK & UNPACK
/
/  25 JAN 73
/
STUNPK	XX
	DAC*	(AUTO3
	LAC	(UNFRT
	DAC	HINGE
	JMP*	STUNPK
/
UNPACK	XX
	JMP*	HINGE
HINGE	.DSA	UNFRT
	AND	(177	/TRIM TO 7 BITS
	JMP*	UNPACK
/
UNFRT	LAC*	AUTO3
	DAC	CKNXT
	LMQ
	LLS	7	/1ST CHARACTER
	JMS	HINGE
/
UNF1	LLS	7	/2ND CHARACTER
	JMS	HINGE
/
UNF2	LAC*	AUTO3
	LMQ
	LAC	CKNXT	/GET BACK 1ST WORD
	LLS	3	/3RD CHARACTER
	JMS	HINGE
/
UNF3	LLS	7	/4TH CHARACTER
	JMS	HINGE
/
UNF4	LLS	7	/5TH CHARACTER
	JMS	HINGE
	JMP	UNFRT
/
/
/	COMMON ENTRY POINT FOR OCTDEC
/
OCTSUB	XX
	STL
	JMS*	OCTDEC
	PGIMG
	LAC	TEMP1
	JMS	STPCK
	LAC*	.DIGCT
	CMA
	TAD	(1
	DAC	COUNT1
	TAD	(PGIMG+6
	DAC	TEMP
OCTBK	LAC*	TEMP
	AND	(177	/TRIM TO 7 BITS
	JMS	PACK
	ISZ	TEMP
	ISZ	COUNT1
	JMP	OCTBK
	JMP*	OCTSUB
/
/	NEW PAGE SUBROUTINE
/
NEWPG	XX
	LAC	PKOUT	/SAVE LOCATION INCASE LINE NUMBERS REQ'D
	DAC	TSAVE
	LAC	(NOP
	DAC	PKOUT
	DZM	LINENM
	LAC	HEADSP
	DAC	TEMPS
	JMS	HEAD	/INSERT PAGE NUMBER IF ANY
	JMS	BLANK	/INSERT HEADER BLANK LINES
	ISZ	TEMPS
	JMP	.-2
	LAC	LENGTH	/SETUP NUMBER OF LINES PER PAGE
	DAC	LINENM
	LAC	WHATIF	/ARE WE WAITING TO OUTPUT A FIGURE
	SNA
	JMP	NEWOUT
	LAC	TEMSAV
	DAC	SPTABL
	LAW	-1
	DAC	SPTABL+1
	JMS	SPACES
	LAC	NAMSAV
	SNA
	JMP	NEWOUT
	LAC	(RECSAV
	DAC	LENPNT
	LAC*	(102
	DAC*	(AUTO1
NEWAGN	LAC	(OUTIMG-1
	DAC*	(AUTO2
	LAC	LENPNT
	SPA
	JMP	IMPOS
	DAC	RECORD
	JMS	CENTIT
	JMS	PCK
	JMS	WRITES
	ISZ	LENPNT
	ISZ	NAMSAV
	JMP	NEWAGN
NEWOUT	LAC	TSAVE
	DAC	PKOUT
	LAC	(OUTIMG-1
	DAC*	(AUTO3
	LAC	NUMBER
	DAC	NUMB
	JMP*	NEWPG
IMPOS	ISZ*	CHANGE
	LAC	PUTIT
	DAC	TEMP
	LAC	NEWPG
	DAC*	TEMP
	ISZ	TEMP
	LAC	NEWPAG+1
	DAC*	TEMP
	LAC	(50
	JMS*	ASK
/
/	ARRAYS,VARIABLES AND MESSAGES
/
	.BLOCK 2
	.ASCII <11>
BUFFER	.BLOCK 70
TAB	.BLOCK 26	/BUFFER FOR PRECEEDING SPACES IN FORMATTED DOCUMENT MODE
TABLE	.BLOCK 26	/BUFFER AREA FOR NUMBERS DETERMINED BY GET
SPTABL	.BLOCK 3
RECSAV	.BLOCK 20
CTABLE	.BLOCK 71	/ENOUGH ROOM FOR 57 CENTERED PAGE LINES
	-1
PGTABL	.BLOCK 400	/ENOUGH ROOM FOR 128 INDEX PAGE ENTRIES
	-1
/
IFILE	.SIXBT 'INDEXSRC'
/
/
ONESP	ONES-.*400+2
	0
	.ASCII ' '<15>
ONES=.
/
DOLIE	DOIE-.*400+2
	0
	.ASCII '$IE'<15>
DOIE=.
/
EMPTY	.BLOCK 15
/
	144
	12
UNITS	1
	0
/
WRITE	.ASCII 'WRITE'
SPACE	.ASCII 'SPACES'<15>
ALLS	.ASCII 'ALL'
NEWPAG	.ASCII 'NEWPG'
/
FORMFD	FORM-.*400+2
	0
	.ASCII <14><15>
FORM=.
/
NAME3	.SIXBT 'CFILESSRC'
/
/
PGHD	120	/P
	101	/A
	107	/G
	105	/E
	40	/SPACE
PGIMG	.BLOCK 6
	15	/CARRIAGE RETURN
/
	0
	0
IMAGE	.BLOCK 512
TABIT	11
OUTIMG	.BLOCK 210
TEMIMG	.BLOCK 210
WAITS	.SIXBT 'TITLESSRC'
	.END START
