
CANUTE PART 2   MAIN SUBROUTINES

X1=10
X2=11

APPEND,	0
	CHKONE
	SKP
	JMP CONERR
	LAC LAST#N
	DAC THISN
	LAC L#AST
	DAC THIS
	LAC (NOP
	DAC TISW		/TELETYPE INPUT SWITCH
	DZM LSTCHR	/STORAGE FOR LAST CHARACTER SEEN
	LAC (JMS TONE	/SET SWITCH IN PACK ROUTINE TO
	DAC ON		/FROM TELTYPE
	JMS A		/APPEND ALL LINES AND RESET POINTERS
	JMP I APPEND

A,	0
	JMS PACK	/ADD ONE LINE
	JMP .-1
	JMP I A

TONE,	0		/TYPE IN
	TTI
	ISZ TONE		/INDEX RETURN IF NOT DONE
	DAC LSTC#HR	/SAVE CHARACTER FIR CHECK IF BLANK KEY TYPED
	JMP I TONE

BLANK,	LAC LSTCHR
	SAD (77
	JMP I TONE	/NO DELETE IF LAST CHARACTER WAS CR
	JMS DECR		/OTHERWISE ERASE ONE CHARACTER
	JMP TONE+1

DECR,	0
	LAC P#CNT		/IF CHARACTER CNT IS -2 MUST BACK UP 1 WORD
	SAD (-2
	JMP FUR
	ADD (-1		/OTHERWISE DECREMENT CHARACTER COUNT BY 1
	DAC PCNT
	LAC PT#EM		/GET PARTIAL ACCUMULATION
DE1,	AND (777700	/AND OUT LAST CHARACTER
	CLL
	RTR	RTR	RTR
	DAC PTEM		/ROTATE WORD BACK ONE CHARACTER
	JMP I DECR


OUTTEM,	0

/APPEND CONTIUED

FUR,	LAC X1		/ASKED TO ERASE TOO MANY?
	SAD BUF#FER
	JMP SET
	DAC TE#M	/POINTER TO WORD TO ERASE
	ADD (-1		/NO, DECREMENT STORAGE POINTER
	DAC X1
	CLC
	DAC PCNT		/SET CNT FOR ONE MORE CHARACTER
	LAC I TEM	/GET WORD BACK AGAIN
	DAC PTEM
	JMP DE1-1	/GO SHIFT IT BACK ONE

/CHANGE

CHANGE,	0
	CHKARG
	JMP NEED
	JMS DELETE
	JMS INSERT
	JMP I CHANGE

/FIND THE NEXT TAG
/THIS ROUTINE REQUIRES ONE ARGUMENT
/A "TAG" IS FOUND IF THE LINE DOESN'T BEGIN WITH CR, TAB, OR SLASH

G,TAG,	0
	CHKARG
	JMP NEED
	LAC ARG0
	SAD LASTN
	SKP
	ADD (1
	DAC ARG0
	DAC THISN
	JMS FIND
	DAC THIS
	LAC LASTN
	CMA
	ADD ARG0
	DAC ARG1
	LAC (NOP
	DAC FIOCAS
	DAC SUPSW
	LAC (JMP TTEST
	DAC SUPSW+1
	JMS UNPACK
	JMP CONERR

TTEST,	SAD (77
	JMP MORE
	SAD (36
	JMP MORE
	SAD (21
	JMP MORE
	LAC THISN
	DAC ARG0
	DAC ARG2
	CLC
	DAC ARG1
	JMS LIST
	JMP I G

INS1,	0
	DAC ON
	LAC (NOP
	DAC TISW
	CLC
	TAD ARG#0
	DAC THIS#N
	JMS FIND
	DAC TH#IS
	JMS PACK
	JMP .-1
	JMP I INS1

INSERT,	0
	LAC (JMS TONE
	JMS INS1
	JMP I INSERT

X,	0
	LAC ARG0
	CMA
	ADD (1
	DAC CRC
	READST
	LAC ARG2
	ADD (1
	DAC ARG0
	LAC (JMP RGET
	JMS INS1
	JMP I X

/KILL

KILL,	0
	LAC BUFFER
	CMA
	TAD BUFBEG
	DAC BUFFER
	LAC BUFBEG
	DAC X1
	DAC X2
	DZM I X1		/CLEAR 1 BUFFER
	DZM I X2		/UP TO THE LAST
	ISZ BUFFER		/LOCATION USED
	JMP .-3
	LAC BUFBEG#
	DAC BUFFER	/RESET FREE STORAGE
	DZM FIRST	/MAKE FIRST POINTER ZERO TO INDICATE END
	DZM THISN	/NUMBER OF .
	DZM LASTN	/NUMBER OF /
	LAW FIRST
	DAC LAST
	DAC THIS
	JMP I KILL

OALL,	0
	CHKARG
	SKP
	JMP CONERR
	JMS PUN
	JMS STOP
	JMS KILL
	JMP I OALL

/LIST

LIST,	0
	CHKARG
	JMP NEED
	LAC (NOP
	DAC FIOCAS
	LAC (SKP
	DAC SUPSW
	LAC (TTO		/SET OUTPUT IN UNPACK TO TELETYPE
	DAC OUTPUT
	JMS UNPACK	/UNPACK AND OUTPUT LINES ACCORDING TO ARG0 ETC.
	JMP I LIST


/PUNCH OUT THIS PAGE AND GET THE NEXT

NEXT,	0
	CHKONE
	CLC
	DAC NC#NT
	JMS NOARG
	JMS PUN
	JMS STOP
	JMS KILL
	JMS READ
	ISZ NCNT
	JMP .-5
	JMP I NEXT


/PUNCH

PUN,	0
	LAC FIRST
	SNA
	JMP CONERR
	LAC (SKP
	DAC SUPSW
	CHKARG
	JMS SETPUN
PUN1,	LAC (PUNLDB	/SET UNPACK TO PUNCH OUTPUT
	DAC OUTPUT
	LAM -140
	J FEEDC
PUNALL,	JMS UNPACK	/OUPUT ALL LINES BETWEEM ARG0 AND ARG2
	JMP I PUN

SETPUN,	0		/SET UP M + N TO ENCOMPASS BUFFER
	LAC (1
	DAC ARG0
	LAC LASTN
	DAC ARG2
	CMA
	ADD ARG0
	SMA
	CLC
	DAC ARG1
	JMP I SETPUN


/TYPE ONLY UP TO SECOND TAB

Q,	0
	LAC FI#RST
	SNA
	JMP CONERR
	LAC (NOP
	DAC FIOCAS
	DAC SUPSW
	LAC (JMP QTEST
	DAC SUPSW+1
	CHKARG
	JMS SETPUN
	LAC (TTO
	DAC OUTPUT
	DZM Q#CNT
	JMS UNPACK
	JMP I Q

QTEST,	DAC Q#TEM
	SAD (77
	DZM QC#NT
	SAD (77
	JMP SUPSW+2
	SAD (36
	ISZ QCNT
	LAM -1
	ADD QCNT
	SMA
	JMP . 3
	LAC QTEM
	JMP SUPSW+2

	LAC (77
	TTO
	DZM QCNT
	JMP MORE

/READ

READ,	0
	LAC (JMP RGET	/SET INPUT TO PAPER TAPE
	DAC ON
	LAC (NOP
	DAC FIOCAS
	DAC TISW		/TELTYPE INPUT SWITCH
	CHKONE
	CLA
	DAC CRC
	LAC LAST
	DAC THIS
	READST
	JMS A		/ADD ON THE LINES; RESET POINTERS
	JMP I READ


RGET,	GETCHR		/GET CHARACTER FROM READER
	JMP ON+1		/RETURN IF NO MORE CHARACTERS
	DAC R#TEM
	LAS
	RAR
	SZL
	JMP NOERR
	LAC RTEM
PARERR,	JMS PARCHK	/CHECK PARITY
	SNL
	JMP TYERR	/PARITY ERROR
NOERR,	LAC RTEM
	JMP ON+2		/RETURN FOR NOT DONE YET

PARCHK,	0
	DAC P#ARTEM
	DZM #PARITY
	RCR
	SZL!RCR
	ISZ PARITY
	SZA
	JMP .-3
	SZL
	JMP .-5
	LAC PARITY
	RAR
	LAC PARTEM
	AND (77
	JMP I PARCHK

TYERR,	LAW PRM1
	JMS TYPE
	SETDEC
	LAC THISN
	ADD (1
	DECPNT
	LAW PRM2
	JMS TYPE
	SETOCT
	LAC RTEM
	DECPNT
	JMS TCR
	LAC (76		/WILL PRINT AS &  IN TEXT
	JMP ON 2

PRM1,	TEXT .
PARITY IN LINE .

PRM2,	TEXT . CHAR IS .

/SKIP N PAGES

SKIP,	0
	CHKONE
	CLC
	DAC CNT
	READST
	GETCHR
	SKP
	JMP .-2
	ISZ CNT
	JMP .-5
	JMP I SKIP

/STOP CODE

STOP,	0
	LAM -5		/PUNCH SMALL AMOUNT OF TAPE FEED
	JMS FEEDC
	LAC (13
	PUNLDB		/AND STOP CODE
	JMP I STOP

CNT,	0

/TAPE TO TAPE TRANSFER

TAPE,	0
	CHKONE
	CLC
	DAC T#CNT
	JMS NOARG
TAP1,	JMS KILL		/KILL TEH BUFFER
	JMS READ		/READ IN A PAGE
	LAC FIRST
	SNA
	JMP TA1
	JMS PUN		/PUNCH IT
	JMS STOP		/AND A STOP CODE
	JMS KILL		/KILL THE BUFFER
TA1,	ISZ TCN#T
	JMP TAP1
	JMP I TAPE


/LIST THE BUFFER

WRITE,	0
	JMS SETPUN	/SET UP COUNTERS FOR WHOLE BUFFER
	LAC (NOP
	DAC NARG
	JMS LIST		/LIST REQUIRED LINES
	JMP I WRITE

/DELETE

DELETE,	0
	CHKARG
	JMP NEED
	LAC ARG1
	TAD LASTN
	DAC LASTN
SNA
	JMP DELK
	CLC
	TAD ARG0
	JMS FIND
	DAC THIS
	CLC
	TAD ARG0
	DAC THISN

DEL0,	LAC I THIS
	DAC DEL#TEM
	LAC I DELTEM
	DAC I THIS
	ISZ ARG1
	JMP DEL0
	LAC LASTN
	JMS FIND
	DAC LAST
	JMP I DELETE

DELK,	JMS KILL
	JMP I DELETE


/FIND

FIND,	0
	CMA
	SMA
	CLC
	DAC C#NTF
	LAW FIRST
	JMP . 3
	LAC I FTEM#
	SZA
	DAC FTEM
	ISZ CNTF
	JMP .-4
	LAC FTEM
	JMP I FIND

/CHARACTER CORRECTION MODE

Y,	0
	CHKONE
	JMP CONERR
	CLC
	TAD ARG0
	DAC THISN
	LAC (JMP DSET
	DAC TISW
	LAC (JMS TONE
	DAC ON
	LAC (SKP
	DAC DLYSWT
	JMS PACK
	NOP
	JMP I Y

/UNPACK AND OUPUT ARG1 LINES

UNPACK,	0
	LAC ARG0		/FIND ADDRESS OF FIRST LINE
	DAC THISN
	JMS FIND
	DAC THIS
	DAC X2		/RETURNS IN AC, PUT IN AUTO-INDEX
LTALLY,	LAM -2		/MAIN LOOP TO UNPACK 1 WORD
	DAC L#CNT
	LAC I X2
	DAC FTEM
TAL,	LAC FTEM
	RTL	RTL	RTL
	DAC FTEM
	RAL
	AND (77
	SAD (13
	JMP MORE		/MORE LINES TO BE OUTPUT?
SUPSW,	XX		/NOP OR SKP
	XX		/JMP TO PRINT SUPPRESSING ROUTINE
	JMS PARCHK
	SNL
	ADD (200
OUTPUT,	XX		/TTO OR PUNLDB
	LAC OUTPUT
	SAD (TTO
	SKP
	JMP . 4
	LAS
	SPA
	JMP NOMORE

	ISZ LCNT
	JMP TAL
	JMP LTALLY


MORE,	ISZ ARG1
	SKP
	JMP I UNPACK
	ISZ THISN
	LAC I THIS
	JMP UNPACK 4

NOMORE,	LAC (77
	TTO
	LAC ARG2
	DAC THISN
	JMS FIND
	DAC THIS
	JMP CONTROL
/FEED N LINES

FEED,	0
	CHKONE
	CLC
	JMS FEEDC
	JMP I FEED

FEEDC,	0
	DAC FEE#DCNT
	CLA
	PUNLDB
	ISZ FEEDCNT
	JMP .-3
	JMP I FEEDC

/ADDS A LINE TO THE PAGE AND RESETS BUFFER, LASTN, AND THIS

PACK,	0
	LAM -2
	DAC PCNT
	DZM PTEM
	LAC BUFFER
	DAC X1
	JMS CHECK
ON,	XX
	JMP  SET
	AND (77
	SAD (77
	JMP DONE
	JMS P1
	JMP ON

P1,	0
	CLL
	DAC C#1
	LAC PTEM
	RTL	RTL	RTL
	ADD C1
	DAC PTEM
	ISZ PCNT
	JMP I P1
	JMS CHECK
	LAC PTEM
	DAC I X1
	LAM -2
	DAC PCNT
	DZM PTEM
	JMP I P1

CHECK,	0
	LAC X1
	SAD ALMO#ST
	JMP ALFULL
	CMA
	ADD (1
	ADD BUFEND#
	SMA
	JMP I CHECK
FULL,	LAW FULLM
	JMS TYPE
	JMP CONTROL
	

/MORE ADD ONE LINE TO THE BUFFER

DONE,	JMS P1
	LAC (13
	JMS P1
	LAC PTEM
	SZA
	JMP .-4
	LAC I THIS
	DAC I BUFFER
	SZA
DONE1,	JMP . 3
	LAC BUFFER
	DAC LAST
	LAC BUFFER
	DAC I THIS
	DAC THIS
	ISZ THISN
	LAC X1
	ADD (1
	DAC BUFFER
	CMA
	ADD (1
	ADD BUFEND
	SPA
	JMP FULL
	ISZ LASTN
	JMP I PACK

SET,	ISZ PACK
SPECXT,	JMP I PACK

/START HERE


GO,	DAC BUFBEG#
	LAC 17762
	AND (10000
	ADD (7661
	DAC ALM#OST
	ADD (100
	DAC BUFEND#
	DAC BUFFER

GOI,	LAC (JMP INTRP
	DAC 1
	JMS KILL		/CLEAR BUFFER, RESET PNTRS., ETC.
	JMS CLFLAG
	TTYSET
	PUNSET
	JMP CONTROL

/SOME DIAGNOSTIG

NEED,	LAW NEEDM
	JMS TYPE
	JMP CONTROL

NEEDM,	TEXT .ARG MISSING
.
ALFULL,	CLC
	DAC CRC#
	LAW ALM
	JMS TYPE
	JMP I CHECK

ALM,	TEXT .BUFFER ALMOST FULL
.

FULLM,	TEXT .BUFFER FULL
.

START GO
