/#EF# REGIONS, SEARCH

/ SAVE (CLIP.E8) AND DELETE REGION
DELREG,	0
	JMS WRREG		/ SAVE IT
	JMP I DELREG
	ISZ DELREG
	STA			/ BUFFER IS GOING TO CHANGE
	DCA CHANGD
	
	TAD MKFLAG		/ MARK BEFORE OR AFTER POINT?
	SZA CLA
	JMP DLRGA

	TAD MARK		/ BEFORE, GAP = MARK
	DCA GAP
	TAD MARK+1
	DCA GAP+1
	JMP I DELREG

DLRGA,	TAD MARK		/ AFTER, POINT = MAK
	DCA POINT
	TAD MARK+1
	DCA POINT+1
	JMP I DELREG

	PAGE  /-------------------------- 4600

/ WRITE REGION AND SKIP IF NOT EMPTY.
WRREG,	0
	TAD MKFLAG
	SZA CLA
	JMP WRREGA

	TAD (MARK		/ MARK BEFORE GAP, NULL REGION?
	JMS I [SNE15; GAP
	JMP WRREGN

	TAD (MARK		/ NO, WRITE BEFORE GAP
	DCA WRBEG
	TAD [POINT
	DCA WREND
	JMP WRREGB

WRREGA,	TAD (MARK		/ MARK AFTER POINT, NULL REGION?
	JMS I [SNE15; POINT
	JMP WRREGN

	TAD [GAP		/ NO, WRITE AFTER POINT
	DCA WRBEG
	TAD (MARK
	DCA WREND

WRREGB,	TAD (TEMPFN		/ WRITE TO CLIP.E8
	DCA WRNAME
	JMS I [WRITEF
	SKP
	ISZ WRREG
	JMP I WRREG

WRREGN,	TAD (NRMSG		/ NULL REGION, SHOW MESAGE
	JMS I [WR6
	WRMLT
	ISZ MLHOLD
	JMP I WRREG

TEMPFN,	FILENAME CLIP.E8

/ INSERT SAVED REGION
YANK,	0
	TAD (TEMPFN		/ LOOK FOR IT
	JMS I [LUFILE
	JMP I YANK
	JMS I [INSFIL		/ INSERT
	SKP
	ISZ YANK
	JMP I YANK

/ SET SCREEN CURSOR USING ROW, COL
SETCUR,	0
	TAD (ESC
	JMS I [WRTTY
	TAD (LBRAK
	JMS I [WRTTY
	TAD ROW
	IAC
	JMS I [WRDEC
	WRTTY
	TAD (SEMI
	JMS I [WRTTY
	TAD COL
	IAC
	JMS I [WRDEC
	WRTTY
	TAD ("H&177
	JMS I [WRTTY
	JMP I SETCUR

/ IF BUFFER FILLED WHEN READING, READ MORE
RDMORE,	0
	TAD MOREOK
	SNA CLA
	JMP I RDMORE

	STA
	TAD FILBLK
	DCA FILLOC
	JMS CLRBUF
	JMP I RDMORE
	JMS I [INSFIL
	NOP
	ISZ RDMORE
	JMP I RDMORE

/ INCREMENTAL SEARCH

/ LOOK FOR THE <0-TERMINATED SEARCH STRING. START AT SRCHP,
/ UPDATE AND SKIP IF FOUND. IF NOT FOUND SRCHP IS UNDEFINED
SCHSTR,	0
SCSTC,	TAD [SSTRNG
	DCA SCSTP

	TAD I SCSTP		/ NULL SEARCH STRING IS FOUND
	SPA CLA
	JMP SCSTB

	TAD I SCSTP		/ FIND FIRST CHAR OF STRING
	JMS I [SFWD
	JMP I SCHSTR

	TAD SRCHP
	DCA SCSTQ
	TAD SRCHP+1
	DCA SCSTQ+1

SCSTA,	ISZ SCSTP		/ ADVANCE POINTERS
	TAD (SCSTQ
	JMS I [INC15

	TAD I SCSTP		/ DONE?
	SPA CLA
	JMP SCSTB

	TAD (SCSTQ		/ END OF BUFFER?
	JMS I [SNE15; BUFEND
	JMP I SCHSTR

	TAD (SCSTQ		/ NO, COMPARE
	JMS I [GET15
	CIA
	TAD I SCSTP
	SNA CLA
	JMP SCSTA		/ MATCH, KEEP GOING
	
	TAD [SRCHP		/ NO MATCH, FIND NEXT PLACE TO LOOK
	JMS I [INC15
	JMP SCSTC

SCSTB,	ISZ SCHSTR		/ FOUND
	JMP I SCHSTR

SCSTP,	0			/ -> SEARCH STRING
SCSTQ,	0; 0			/ ->15 BUFFER

	PAGE  /-------------------------- 5000

/ INCREMENTAL SEARCH COMMAND
ISRCH,	0
	ISZ ISRCH		/ CAN'T FAIL
	JMS I [CLRMLT		/ PROMPT
	TAD (ISMSG
	JMS I [WR6
	WRMLT

	TAD [SSTRNG		/ INIT SEARCH STRING POINTER
	DCA ISP
	JMS SETPM		/ SET MARK TO STARTING POINT
ISD,	STA 			/ MARK EMPTY SEARCH STRING
	DCA I ISP

ISA,	JMS I [UPDATE
	JMS I [SFWDPT		/ START FROM POINT

ISC,	JMS I [RDTTY
	TAD (-BS		/ BACKSPACE?
	SNA
	JMP ISBS
	TAD (BS-TAB		/ ^I
	SNA
	JMP ISTAB
	TAD (TAB-6		/ ^F?
	SNA
	JMP ISNXT
	TAD (6-23		/ ^S?
	SNA
	JMP ISNXT
	TAD (23-16		/ ^N?
	SNA
	JMP ISNL
	TAD (16-CR		/ CR?
	SNA
	JMP I ISRCH		/ CR, DONE
	TAD (CR-SP		/ OTHER CONTROL CHAR
	SPA
	JMP ISEXE
	TAD [SP			/ REGULAR CHAR

ISREG,	DCA ISCH		/ SAVE IT

	TAD ISP			/ SEARCH STRING FULL?
	TAD (-SSEND+1
	SNA CLA
	JMP ISB

	TAD ISCH		/ PUT IN SEARCH STRING
	DCA I ISP
	ISZ ISP
	STA			/ MARK END OF SEARCH STRING
	DCA I ISP

ISF,	JMS I [SCHSTR		/ LOOK FOR IT
	JMP ISNF

	JMS I [GOFWD		/ FOUND, GO THERE
	TAD ISCH		/ ECHO IN MODE LINE	
	JMS I [WRMLT
	JMP ISA
	
ISBS,	TAD ISP			/ BACKUP. ALREADY AT BEGINNING?
	TAD (-SSTRNG
	SZA CLA
	JMP ISE
	TAD [BELL
	JMS I [WRTTY
	JMP ISC

ISE,	STA			/ NO, DEC POINTER
	TAD ISP
	DCA ISP
	STA
	DCA I ISP

	JMS I [FIXMRK		/ BACK TO STARTING POINT
	JMS EXGPM
	FAIL
	JMS SETPM		/ FIND SHORTER STRING
	JMS I [SFWDPT
	JMS I [SCHSTR
	FAIL			/ MUST BE FOUND
	JMS I [GOFWD		/ GO THERE
	JMS I [ERMLT		/ ERASE CHAR FROM MODE LINE
	JMP ISA

ISTAB,	TAD (TAB
	JMP ISREG

ISNL,	TAD [CR			/ INSERT CR
	JMP ISREG

ISEXE,	TAD [SP			/ OTHER CONTROL CHAR, PUSH IT BACK TO 
	DCA BACKCH		/ INPUT FOR EXECUTION
	JMP I ISRCH

ISNXT,	TAD [SRCHP		/ FIND NEXT OCCURANCE
	JMS I [SNE15; BUFEND	/ AT END OF BUFFER?
	JMP ISB
	TAD [SRCHP		/ NO, ADVANCE 1
	JMS I [INC15
	JMS I [SCHSTR		/ FIND
	JMP ISB

	JMS I [GOFWD		/ GO THERE
	JMP ISA
	
ISB,	TAD [BELL		/ NOT FOUND
	JMS I [WRTTY
	JMP ISA

ISNF,	TAD [BELL		/ NOT FOUND
	JMS I [WRTTY
	STA			/ REMOVE CHAR FROM SEARCH STRING
	TAD ISP
	DCA ISP
	JMP ISD
	
ISCH,	0	/ NEXT CHAR IN SEARCH STRING
ISP,	0	/ -> SEARCH STRING

	PAGE  /-------------------------- 5200

/ SEARCH AGAIN FOR LAST SEARCH STRING
SCHNXT,	0
	TAD SSTRNG		/ ANY STRING?
	SPA CLA
	JMP I SCHNXT

	JMS I [SFWDPT		/ YES, START AT POINT
	TAD [SRCHP		/ AT END OF BUFFER?
	JMS I [SNE15; BUFEND
	JMP I SCHNXT

	TAD [SRCHP		/ NO, SKIP 1
	JMS I [INC15

	JMS I [SCHSTR		/ LOOK FOR STRING
	JMP I SCHNXT

	JMS I [GOFWD		/ FOUND, GO THERE
	ISZ SCHNXT
	JMP I SCHNXT

/ MOVE SRCHP FORWARD ONE WORD FROM POINT
FWORD,	0
	JMS I [SFWDPT

/ SKIP OVER NON-ALPHANUMERIC
FWORDA,	TAD [SRCHP		/ AT END OF BUFFER?
	JMS I [SNE15; BUFEND
	JMP I FWORD
	TAD [SRCHP		/ NO, GET CHAR		
	JMS I [GET15
	JMS I [SKIPAN		/ ALPHANUMERIC?
	SKP
	JMP FWORDB
	TAD [SRCHP		/ NO, KEEP LOOKING
	JMS I [INC15
	JMP FWORDA

/ SKIP OVER ALPHANUMERIC
FWORDB,	TAD [SRCHP		/ ADVANCE ONE
	JMS I [INC15
	TAD [SRCHP		/ AT END OF BUFFER?
	JMS I [SNE15; BUFEND
	JMP FWORDC
	TAD [SRCHP		/ NO, GET CHAR
	JMS I [GET15
	JMS I [SKIPAN		/ ALPHANUMERIC?
	JMP FWORDC
	JMP FWORDB

FWORDC,	ISZ FWORD
	JMP I FWORD

/ MOVE SRCHP BACK ONE WORD FROM GAP
BWORD,	0
	JMS I [SREVGP

/ SKIP NON-ALPHANUMERIC
BWORDA,	TAD [SRCHP		/ AT BEGINNING OF BUFFER?
	JMS I [SNE15; BUF
	JMP I BWORD
	TAD [SRCHP		/ NO, BACK UP
	JMS DEC15
	TAD [SRCHP		/ GET CHAR		
	JMS I [GET15
	JMS I [SKIPAN		/ ALPHANUMERIC
	JMP BWORDA

/ SKIP OVER ALPHANUMERIC
BWORDB,	TAD [SRCHP		/ BACK ONE
	JMS DEC15
	TAD [SRCHP		/ AT BEGINNING OF BUFFER?
	JMS I [SNE15; BUF
	JMP BWORDC
	TAD [SRCHP		/ NO, GET CHAR
	JMS I [GET15
	JMS I [SKIPAN		/ ALPHANUMERIC?
	SKP
	JMP BWORDB

	TAD [SRCHP		/ NO, BACK TO A-N CHAR
	JMS I [INC15

BWORDC,	ISZ BWORD
	JMP I BWORD

/ MOVE POINT FORWARD ONE WORD
FWDWD,	0
	JMS FWORD
	JMP I FWDWD
	JMS I [GOFWD
	ISZ FWDWD
	JMP I FWDWD

/ MOVE POINT BACK ONE WORD
BACKWD,	0
	JMS BWORD
	JMP I BACKWD
	JMS I [GOREV
	ISZ BACKWD
	JMP I BACKWD

/ DELETE WORD FORWARD
DLFWWD,	0
	JMS FWORD
	JMP I DLFWWD
	TAD SRCHP
	DCA POINT
	TAD SRCHP+1
	DCA POINT+1
	STA
	DCA CHANGD
	ISZ DLFWWD
	JMP I DLFWWD

/ DELETE WORD REVERSE
DLRVWD,	0
	JMS BWORD
	JMP I DLRVWD
	TAD SRCHP
	DCA GAP
	TAD SRCHP+1
	DCA GAP+1
	STA
	DCA CHANGD
	ISZ DLRVWD
	JMP I DLRVWD

FIXCLT,	0
	TAD (NL-TAB		/ TAB?
	SNA CLA
	JMP FIXTBA
	ISZ FIXCLT		/ OTHER CONTROL CHAR, TWO COLUMNS
	JMP I FIXCLT
	
FIXTBA,	TAD FIXLOC		/ TAB
	TAD (10
	AND (7770
	DCA FIXLOC
	JMP I FIXCLT
	
	PAGE  /-------------------------- 5400

NFMSG,	TEXT / NOT FOUND/
NEWMSG,	TEXT /NEW FILE/

INSE1,	TEXT /FATAL ERR/
INSE2,	TEXT /EOF?/		/ SHOULD BE IMPOSSIBLE, BUT ...

NOEMSG,	TEXT /ERR OPENING/
NOPMSG,	TEXT /ERR WRITING/
NOCMSG,	TEXT /ERR CLOSING/

MRKMSG,	TEXT /MARK SET/
NRMSG,	TEXT /NO REGION/

SAVMSG,	TEXT /SAVE? (Y, N, ^G):/
GFMSG,	TEXT /FILE: /
ISMSG,	TEXT /SEARCH: /
QRMSG1,	TEXT /REPLACE: /
QRMSG2,	TEXT / WITH: /
QRMSG3,	TEXT /REPLACED /

FAILMS,	TEXT /ASSERT /

/ KEYS DISPATCH TABLES
ARROWS,	PRVLN; NXTLN; FWD; BACK
OTHERS,	BEGLN; 0; DELFWD; ENDLN; REVSCR; FWDSCR; 0; 0

/ VT100 SCROLL ESCAPE SEQUENCES
IFDEF FSCROL <
SUPSEQ,	ESC; LBRAK; WINDHI; WINDLO; "H; ESC; "D; 0
SDNSEQ,	ESC; LBRAK; "H; ESC; "M; 0
>

/ GET SIZE OF AC->STRING, RETURN IN AC
STRSIZ,	0
	DCA SSIZP
	DCA SSIZN
SSIZA,	TAD I SSIZP
	ISZ SSIZP
	SPA CLA
	JMP SSIZB
	ISZ SSIZN
	JMP SSIZA
SSIZB,	TAD SSIZN
	JMP I STRSIZ

SSIZP,	0
SSIZN,	0

	PAGE  /-------------------------- 5600

/ MODE LINE TEXT (MLT) BUFFER
MLTBUF,	ZBLOCK 50
MLTEND,

/ SEARCH STRING BUFFER
SSTRNG,	-1		/ MARK EMPTY
	ZBLOCK 20
SSEND,

/ REPLACE STRING BUFFER
RSTRNG,	-1		/ MARK EMPTY
	ZBLOCK 20
RSEND,

/#EG# RECOVER, QUERY REPLACE

/ MAINTAIN RECOVER ZONE
RCZONE,	0
	TAD [POINT		/ POINT MOVED INTO GAP?
	JMS I [LD24
	TAD (LASTPT
	JMS I [SUB15
	TAD AC24+1
	SPA CLA
	JMP RCZA

	TAD (LASTGP		/ NO, GAP MOVED INTO GAP?
	JMS I [LD24
	TAD [GAP
	JMS I [SUB15
	TAD AC24+1
	SMA CLA
	JMP RCZB

RCZA,	TAD POINT		/ IF EITHER WAS YES, RESET
	DCA RCVPT		/ RECOVER ZONE
	TAD POINT+1
	DCA RCVPT+1

	TAD GAP
	DCA RCVGP
	TAD GAP+1
	DCA RCVGP+1

RCZB,	TAD POINT		/ SAVE POINT-GAP PAIR
	DCA LASTPT
	TAD POINT+1
	DCA LASTPT+1

	TAD GAP
	DCA LASTGP
	TAD GAP+1
	DCA LASTGP+1

	JMP I RCZONE

/ RECOVER ZONE
RECOVR,	0
	TAD [POINT		/ ANY ZONE TO RECOVER?
	JMS I [SNE15; RCVPT
	SKP
	JMP RCVRA

	TAD [GAP
	JMS I [SNE15; RCVGP
	JMP I RECOVR
	
RCVRA,	TAD RCVPT		/ YES, DO IT
	DCA POINT
	TAD RCVPT+1
	DCA POINT+1

	TAD RCVGP
	DCA GAP
	TAD RCVGP+1
	DCA GAP+1

	ISZ RECOVR
	JMP I RECOVR

	PAGE	/------------------------- 6000

/ PROMPT AND READ INPUT FROM USER, SKIP IF NOT QUIT
/	JMS GETSTR
/	-> PROMPT
/	-> BUFFER
/	-> LAST ELEMENT OF BUFFER
/	QUIT RETURN
GETSTR,	0
	TAD I GETSTR		/ PROMPT
	ISZ GETSTR	
	JMS I [WR6
	WRMLT
	JMS I [UPDATE

	TAD I GETSTR		/ FETCH BUFFER POINTERS
	ISZ GETSTR
	DCA GETSBF
	TAD GETSBF
	DCA GETSP
	TAD I GETSTR
	ISZ GETSTR
	CIA
	DCA GETSEN

	STA			/ MARK EMPTY
	DCA I GETSP

GETSA,	JMS I [RDTTY		/ GET AND PROCESS NEXT CHAR
	TAD (-BELL		/ QUIT?
	SNA
	JMP GETSQ
	TAD (BELL-CR		/ NO, END ENTRY?
	SNA
	JMP GETSX
	TAD (CR-10		/ NO, BACHSPACE?
	SNA
	JMP GETSBS
	TAD [10			/ ORDINARY CHARACTER
	DCA GETSCH

	TAD GETSP		/ ROOM FOR IT?
	TAD GETSEN
	SNA CLA
	JMP GETSER

	TAD GETSCH		/ YES, ECHO IT
	JMS I [WRMLT
	JMS I [UPDATE

	TAD GETSCH		/ PUT IN BUFFER
	TAD (-16		/ CONVERT ^N TO NL
	SNA
	TAD (NL-16
	TAD (16
	DCA I GETSP
	ISZ GETSP
	STA			/ MARK END
	DCA I GETSP
	JMP GETSA

GETSQ,	STA			/ QUIT, LEAVE BUFFER EMPTY
	DCA I GETSBF
	JMP I GETSTR

GETSER,	TAD [BELL		/ ERROR
	JMS I [WRTTY
	JMP GETSA

GETSBS,	TAD GETSBF		/ BACKSPACE, ALREADY AT BEGINNING?
	CIA
	TAD GETSP
	SNA CLA
	JMP GETSER

	STA			/ NO, BACKUP
	TAD GETSP
	DCA GETSP
	STA			/ MARK END
	DCA I GETSP
	JMS I [ERMLT		/ ERASE LAST CHAR
	JMS I [UPDATE
	JMP GETSA

GETSX,	ISZ GETSTR		/ NORMAL EXIT
	JMP I GETSTR

GETSP,	0	/ -> END MARKER AS CHARS ARE ENTERED
GETSBF,	0	/ -> BUFFER
GETSEN,	0	/ - ADDRESS OF LAST ELEMENT
GETSCH,	0	/ CHAR BEING INSERTED

/ SCREEN INITIALIZATION
SCINIT,	0
	DCA SCRP
	TAD (-SCRHT
	DCA ROW
	SCRFLD
INITA,	SMARK			/ MARK END OF LINES IN SCREEN COPY
	DCA I SCRP
	TAD SCRP
	TAD [SCRWD
	DCA SCRP
	ISZ ROW
	JMP INITA
	CODFLD

	TAD (CLRSC		/ CLEAR THE SCREEN
	JMS I [WRSTR
	WRTTY
	JMP I SCINIT

/ ADJUST COLUMN TO MAKE ^N, ^P MOVE VERTICALLY
FIXCOL,	0
	TAD UPDOWN		/ PRESERVE COLUMN INDEX
	CIA
	DCA UPDOWN
	DCA FIXLOC		/ INIT CURRENT COL

FIXCLA,	TAD FIXLOC		/ DONE?
	TAD UPDOWN
	SMA CLA
	JMP I FIXCOL

	TAD [POINT		/ GET CHAR AT POINT
	JMS I [GET15
	TAD [-SP		/ CONTROL CHAR?
	SMA
	JMP FIXCLC		/ NO, ONE COL

	TAD (SP-NL		/ YES, NL?
	SNA
	JMP I FIXCOL		/ YES, CAN GO NO FARTHER

	JMS FIXCLT
	JMP FIXCLD

FIXCLB,	ISZ FIXLOC
FIXCLC,	ISZ FIXLOC
	CLA

FIXCLD,	JMS FWD
	JMP I FIXCOL
	JMP FIXCLA

	PAGE  /-------------------------- 6200

WINDHI=TXTHT%12
WINDHO=WINDHI^12
WINDLO=TXTHT-WINDHO+60
WINDHI=WINDHI+60

CLRSC,	ESC; LBRAK; "2; "J
IFDEF FSCROL <
	ESC; LBRAK; "1; SEMI; WINDHI; WINDLO; 162
>
	0

/ QUERY REPLACE
QREPL,	0
QRD,	JMS I [CLRMLT

	JMS GETSTR		/ GET SEARCH STRING
	QRMSG1
	SSTRNG
	SSEND-1
	JMP I QREPL

	TAD [SSTRNG		/ GET SIZE OF SEARCH STRING
	JMS STRSIZ
	SNA			/ IF EMPTY, TRY AGAIN
	JMP QRD
	DCA QRSIZE

	JMS GETSTR		/ GET REPLACE STRING
	QRMSG2
	RSTRNG
	RSEND-1
	JMP I QREPL

	DCA QRNUM		/ ZERO COUNT
QRA,	JMS I [SFWDPT		/ START AT POINT
QRB,	JMS I [SCHSTR		/ LOOK FOR STRING TO REPLACE
	JMP QRX
	JMS I [GOFWD		/ FOUND, GO THERE
	JMS I [UPDATE

QRC,	JMS I [RDTTY		/ WHAT TO DO?
	JMS I [UPPER		/ FOR "N" RESPONSE
	TAD (-CR		/ DONE?
	SNA
	JMP QRX
	TAD (CR-SP		/ REPLACE AND CONTINUE?
	SNA
	JMP QRSP
	TAD (SP-116		/ CONTINUE?
	SNA
	JMP QRNO
	TAD (116-56		/ REPLACE AND QUIT?
	SNA
	JMP QRDOT
	TAD (56-41		/ REPLACE ALL?
	SNA
	JMP QRALL
	TAD [BELL		/ ERROR, TRY AGAIN
	JMS I [WRTTY
	JMP QRC

QRSP,	JMS QRACT		/ REPLACE AND CONTINUE
	JMP QRX
	JMP QRA

QRNO,	JMS I [SFWDPT
	TAD [SRCHP		/ CONTINUE
	JMS I [INC15
	JMP QRB

QRALL,	JMS QRACT		/ REPLACE ALL
	JMP QRX
	JMS I [SFWDPT
	JMS I [SCHSTR
	JMP QRX
	JMS I [GOFWD
	JMP QRALL

QRDOT,	JMS QRACT		/ REPLACE AND QUIT
	NOP

QRX,	JMS I [CLRMLT		/ DONE, SHOW NUMBER OF REPLACEMENTS
	TAD (QRMSG3
	JMS I [WR6
	WRMLT
	TAD QRNUM
	JMS I [WRDEC
	WRMLT
	ISZ MLHOLD

	ISZ QREPL
	JMP I QREPL

QRNUM,	0
QRSIZE,	0

/ REPLACE QRSIZE CHARS AT POINT WITH RSTRNG
QRACT,	0
	CLL			/ DELETE SEARCH STRING
	TAD POINT
	TAD QRSIZE
	DCA POINT	
	SNL
	JMP QRACTA
	TAD POINT+1
	TAD [10
	DCA POINT+1
QRACTA,	STA			/ SET CHANGED IN CASE REPLACE STRING IS NULL
	DCA CHANGD

	TAD (RSTRNG		/ INSERT REPLACE STRING
	DCA QRACTP
QRACTB,	TAD I QRACTP
	ISZ QRACTP
	SPA
	JMP QRACTX
	JMS I [INSERT
	SKP
	JMP QRACTB

	TAD [BELL		/ BUFFER FULL, GIVE UP
	JMS I [WRTTY
	JMP I QRACT

QRACTX,	CLA
	ISZ QRNUM
	ISZ QRACT
	JMP I QRACT

QRACTP,	0

	PAGE  /-------------------------- 6400

KEYS,	0
	JMS I [RDTTY		/ GET ESCAPE CODE
	TAD (-101		/ ARROW KEY?
	DCA KEYSCH
	TAD KEYSCH
	AND (7774
	SZA CLA
	JMP KEYSA

	TAD (ARROWS		/ YES, EXECUTE ARROW KEY
KEYSX,	TAD KEYSCH
	DCA KEYSCH
	TAD I KEYSCH
	SNA
	JMP I KEYS
	DCA KEYSCH
	JMS I KEYSCH
	SKP
	ISZ KEYS
	JMP I KEYS

KEYSA,	TAD KEYSCH		/ NO, OTHER RECOGNIZED KEY?
	TAD (100-60
	DCA KEYSCH
	TAD KEYSCH
	AND (7770
	SZA CLA
	JMP I KEYS

	JMS I [RDTTY		/ YES, MAKE SURE FOLLOWING CHAR
	TAD (-176		/ IS ~
	SZA CLA
	JMP I KEYS

	TAD (OTHERS		/ EXECUTE OTHER KEY
	JMP KEYSX

KEYSCH,	0

/ SCROLL DOWN ONE LINE
SCRLUP,	0
	JMS NXTLN
	STA
	TAD CURROW
	SPA
	JMP SCUPA
	JMS MOVTOS
IFDEF FSCROL <JMS FASTUP>
	ISZ SCRLUP
SCUPA,	CLA
	JMP I SCRLUP

/ SCROLL UP ONE LINE
SCRLDN,	0
	JMS PRVLN
	JMP I SCRLDN
	TAD CURROW
	JMS MOVTOS
IFDEF FSCROL <JMS FASTDN>
	ISZ SCRLDN
	JMP I SCRLDN

IFDEF FSCROL <
FASTUP,	0
	TAD (SUPSEQ		/ SCROLL THE SCREEN WINDOW
	JMS I [WRSTR
	WRTTY

	STA			/ SCROLL THE SCREEN COPY
	DCA TMP0
	TAD (-TXTHT+1
	DCA TMP1
	SCRFLD

FUPA,	TAD TMP0		/ NEXT LINE
	DCA DSTP
	TAD TMP0
	TAD [SCRWD
	DCA TMP0
	TAD TMP0
	DCA SRCP

FUPB,	TAD I SRCP		/ NEXT CHAR
	SPA
	JMP FUPC
	DCA I DSTP
	JMP FUPB

FUPC,	DCA I DSTP
	ISZ TMP1
	JMP FUPA

	SMARK
	DCA I TMP0
	CODFLD
	JMP I FASTUP
			
FASTDN,	0
	TAD (SDNSEQ
	JMS I [WRSTR
	WRTTY

	TAD (TXTHT^SCRWD-SCRWD-1
	DCA TMP0
	TAD (-TXTHT+1
	DCA TMP1
	SCRFLD

FDNA,	TAD TMP0
	DCA DSTP
	TAD TMP0
	TAD (-SCRWD
	DCA TMP0
	TAD TMP0
	DCA SRCP

FDNB,	TAD I SRCP
	SPA
	JMP FDNC
	DCA I DSTP
	JMP FDNB

FDNC,	DCA I DSTP
	ISZ TMP1
	JMP FDNA

	SMARK
	DCA I TMP0
	CODFLD
	JMP I FASTDN
>

	PAGE  /-------------------------- 
IOBUF,	ZBLOCK	400
IOBUFE,

$

