 ORG $0020
*
* LIB GLOBALS
*
* PROGRAM : GLOBALS
*
* GLOBAL DEFINITIONS
*
STACK EQU $01FF
MIKBUG EQU $E0D0
PROMPT EQU $23
CRGRET EQU $0D
BELL   EQU $07
*
* DISK TEMP STORAGE
*
 ORG $0020
*
DSKFLG RMB 1
DRWFLG RMB 1
TTERM RMB 1
ACCT RMB 1
LASTIN RMB 1
INDEX9 RMB 2
SAVEIT RMB 2
BUFEND RMB 2
RBFEND RMB 2
XXX1 RMB 2
XXX2 RMB 2
*
* TEMP STORAGE
*
 ORG $0040
*
TEMP RMB 2
XSAVE RMB 2
BUFPNT RMB 2
BUFSAV RMB 2
CURPOS RMB 2
NEWPOS RMB 2
SRCHPT RMB 2
STRNGB RMB 2
STRNGE RMB 2
STRGB1 RMB 2
STRGE1 RMB 2
STRPNT RMB 2
SPCPT1 RMB 2
SPCPT2 RMB 2
LASTNO RMB 2
ZONE1 RMB 2
ZONE2 RMB 2
ZONBUF RMB 2
CHGPNT RMB 2
CHGEND RMB 2
OCRTMP RMB 2
NUMFLG RMB 1
VERFLG RMB 1
REPEAT RMB 1
MSLFLG RMB 1
PSTZFL RMB 1
OCRCNT RMB 2
FNDFLG RMB 1
STRCN1 RMB 1
OVRBEG RMB 1
OVREND RMB 1
NOCURL RMB 1
LINFLG RMB 1
NXTFLG RMB 1
ALLFLG RMB 1
OCRFLG RMB 1
CHGONF RMB 1
APPCOL RMB 1
STRCNT RMB 1
INCAMT RMB 1
BMPFLG RMB 1
EQUFLG RMB 1
INLMFL RMB 1
MOVFLG RMB 1
REPFLG RMB 1
TMPCHR RMB 1
CHKFLG RMB 1
SNGLIN RMB 1
CHGFLG RMB 1
STRCN2 RMB 1
FNONFL RMB 1
LSTFLG RMB 1
DECCNT RMB 1
PRNFLG RMB 1
CPYDRC RMB 1
DRCTN RMB 1
CHRCNT RMB 2
INZFLG RMB 1
NUMBER RMB 3
TRGLIN RMB 2
DELIM RMB 1
HEDCNT RMB 1
FILBEG RMB 2
FILEND RMB 2
TABPNT RMB 2
TABBUF FCB 8,14,27
 FCB 0
 RMB 16
TABEND FCB 0
FILL FCC / /
LINO FCC /#/
DCC FCB 0
DELAY FCB 6
TONCH FCB 0
TOFCH FCB 0
RONCH FCB 0
ROFCH FCB 0
MEMEND FDB $7FFF
BUFFER RMB 136
*
* DISK SYSTEM EQUATES
*
LINBUF EQU $A080
BSP EQU $AC00
DEL EQU $AC01
EOL EQU $AC02
NFER EQU 4
FEER EQU 3
EFER EQU 8
FCB EQU $A840
TABCH EQU $AC06
BSE EQU $AC07
SASN EQU $AC0B
WASN EQU $AC0C
ASN EQU WASN
SYSFLG EQU $AC0D
LSTTRM EQU $AC11
RETRNR EQU $AC16
CHAR EQU $AC18
PRVCHR EQU $AC19
DMEND EQU $AC2B
DBFPNT EQU $AC14
*
* SYSTEM CONSTANTS
*
CR EQU $0D
LF EQU $0A
SPC EQU $20
NL EQU $08
EL EQU $03
DN EQU $03
*
* SYSTEM ROUTINE ADDRESSES
*
FMSCLS EQU $B403
FMS EQU $B406
WARMS EQU $AD03
RENTER EQU $AD06
GETCHR EQU $AD15
PUTCHR EQU $AD18
INBUF EQU $AD1B
DPSTRN EQU $AD1E
DPCRLF EQU $AD24
NXTCH EQU $AD27
GETFIL EQU $AD2D
SETEXT EQU $AD33
ADDBX EQU $AD36
OUTDEC EQU $AD39
OUTHEX EQU $AD3C
RPTERR EQU $AD3F
*
***********************************
* LIB HISTORY
*
*********************************************
*
* HISTORY FILE
*
* 06/24/83 - UNMODIFIED VERSION PUT
*            TO DISK AND VERIFIED.
*
* 06/24/83 - ADDED PATCH ROUTINE (EDIT9) AND
*            MADE CHANGE IN MAIN "INCHAR" TO
*            ENABLE IT.
*
* 06/30/83 - UPDATED MAIN AND INSERT TO ALLOW
*            USE OF "TAB" KEY. TABS ARE SET TO
*            EVERY EIGHTH COLUMN
*
* 07/01/83 - FIXED TAB TO ALLOW VARIABLE STOPS
*            MADE CHANGES TO "INSERT"
*
*********************************************
*
 ORG $0200
*
* LIB EDIT_TV
* PROGRAM : EDIT_TV
*
* TRANSFER VECTORS
*
* PROGRAM STARTS HERE
*
START  JMP INITLZ
RESTRT JMP PEDIT
*
* EXTERNAL IO ROUTINES
*
INCH  JMP $AD15
OUTCH JMP $AD18
TINCH JMP $AD15 TAPE INPUT ROUTINE
TOUCH JMP $AD18 TAPE OUTPUT ROUTINE
*
***************
* LIB CMDTBL
 TTL CMDTBL
 PAG
*
* THIS IS THE COMMAND TABLE FOR EDIT
*
TABLE FCC /APPEND/
 FCB 0
 FDB APPEND
 FCC /A/
 FCB 0
 FDB APPEND
 FCC /BOTTOM/
 FCB 0
 FDB BOTTOM
 FCC /B/
 FCB 0
 FDB BOTTOM
 FCC /CHANGE/
 FCB 0
 FDB CHANGE
 FCC /COPY/
 FCB 0
 FDB COPY
 FCC /CO/
 FCB 0
 FDB COPY
 FCC /C/
 FCB 0
 FDB CHANGE
 FCC /DELETE/
 FCB 0
 FDB DELETE
 FCC /D/
 FCB 0
 FDB DELETE
 FCC /EXPAND/
 FCB 0
 FDB EXPAND
 FCC /EXP/
 FCB 0
 FDB EXPAND
 FCC /FIND/
 FCB 0
 FDB CFIND
 FCC /F/
 FCB 0
 FDB CFIND
 FCC /GAP/
 FCB 0
 FDB GAP
 FCC /HEADER/
 FCB 0
 FDB HEADER
 FCC /H/
 FCB 0
 FDB HEADER
 FCC /INSERT/
 FCB 0
 FDB INSERT
 FCC /I/
 FCB 0
 FDB INSERT
 FCC /LOG/
 FCB 0
 FDB EXIT
 FCC /MOVE/
 FCB 0
 FDB MOVE
 FCC /MO/
 FCB 0
 FDB MOVE
 FCC /NEW/
 FCB 0
 FDB NEW
 FCC /NEXT/
 FCB 0
 FDB NEXT
 FCC /NUMBERS/
 FCB 0
 FDB NUMSET
 FCC /NU/
 FCB 0
 FDB NUMSET
 FCC /N/
 FCB 0
 FDB NEXT
 FCC /OVERLAY/
 FCB 0
 FDB OVERLA
 FCC /O/
 FCB 0
 FDB OVERLA
 FCC /PRINT/
 FCB 0
 FDB PRINT
 FCC /P/
 FCB 0
 FDB PRINT
 FCC /READ/
 FCB 0
 FDB READ
 FCC /RENUMBER/
 FCB 0
 FDB RENUMB
 FCC /REN/
 FCB 0
 FDB RENUMB
 FCC /REPLACE/
 FCB 0
 FDB REPLAC
 FCC /R/
 FCB 0
 FDB REPLAC
 FCC /SAVE/
 FCB 0
 FDB SAVE
 FCC /SET/
 FCB 0
 FDB SET
 FCC /STOP/
 FCB 0
 FDB EXIT
 FCC /S/
 FCB 0
 FDB EXIT
 FCC /TAB/
 FCB 0
 FDB TAB
 FCC /TOP/
 FCB 0
 FDB TOP
 FCC /T/
 FCB 0
 FDB TOP
 FCC /VERIFY/
 FCB 0
 FDB VERSET
 FCC /V/
 FCB 0
 FDB VERSET
 FCC /WRITE/
 FCB 0
 FDB WRITE
 FCC /W/
 FCB 0
 FDB WRITE
 FCC /X/
 FCB 0
 FDB XCNTRL
 FCC /ZONE/
 FCB 0
 FDB SZONE
 FCC /Z/
 FCB 0
 FDB SZONE
 FCB 0
*
* NEW FILE STRING
*
NWFSTR FCC /NEW FILE:/
 FCB 4
****************************
* LIB INITIAL
 TTL INITIAL
 PAG
*
* THIS IS THE INITIALIZATION ROUTINE
*
INITLZ LDS #STACK
 LDX #BEGPNT
 STX FILBEG
 STX FILEND
 DEX 
 LDAA #$0D
 STAA $00,X
 LDX #RESTRT
 STX $A048 SET RESTART ADDRESS
 LDX #$0001 SET ZONES
 STX ZONE1
 LDX #$0136
 STX ZONE2
 LDAA #70 SET UP HEADER
 STAA HEDCNT
 CLRA 
 STAA OVREND
 STAA INCAMT
 STAA TABBUF
 DECA 
 STAA NUMFLG
 STAA VERFLG
 LDX #EDIT
 STX RETRNR
 CLRA 
 STAA INZFLG
 STAA LASTIN
 STAA DSKFLG
 STAA DRWFLG
 LDX DMEND
 STX MEMEND
 LDAA MEMEND
 CMPA #$77
 BLS DEDIT2
 LDAA #$77
 STAA MEMEND
DEDIT2 LDAB MEMEND+1
DEDI35 STAB BUFEND+1
 STAB RBFEND+1
 TAB 
 LSRB 
 LSRB 
 LSRB 
 SBA 
 STAA BUFEND
 LDAA MEMEND
 DECA 
 STAA RBFEND
 LDX #RFCB
 JSR GETFIL
 BCS DEDI42
 LDAA #$01
 JSR SETEXT
 LDAB #$0C
 LDX #RFCB+3
 STX XXX1
 LDX #WFCB+3
 STX XXX2
DEDI37 LDX XXX1
 LDAA $00,X
 INX 
 STX XXX1
 LDX XXX2
 STAA $00,X
 INX 
 STX XXX2
 DECB 
 BNE DEDI37
 LDX #RFCB
 LDAA #$01
 STAA $00,X
 JSR FMS
 BEQ DEDIT4
 LDAA $01,X
 CMPA #$04
 BNE DEDI55
 INC LASTIN
 BRA DEDIT5
DEDIT4 LDAA LSTTRM
 CMPA #$0D
 BEQ DEDIT6
 CMPA EOL
 BEQ DEDIT6
 LDX #WFCB
 JSR GETFIL
 BCS DEDI42
 LDAA #$01
 JSR SETEXT
 BRA DEDIT5
*
DEDI42 LDX #ILST
DEDI45 JSR PSTRNG
DEDI47 JSR FMSCLS
 JMP WARMS
*
DEDIT5 LDX #WFCB
 LDAA #$02
 STAA $00,X
 JSR FMS
 BEQ DEDIT8
 LDAA $01,X
 CMPA #$03
 BNE DEDI55
 LDX #FEST
 BRA DEDI45
DEDI55 JSR RPTERR
 BRA DEDI47
DEDIT6 LDX #RFCB
 JSR CLSFC1
DEDI61 LDX #RFCB+4
 LDAB #$0B
DEDI62 LDAA $00,X
 STAA $31,X
 INX 
 DECB 
 BNE DEDI62
 LDX #RFCB+49
 CLR $0C,X
 LDAA #$05
 JSR SETEXT
 LDX #RFCB
 LDAA #$0D
 STAA $00,X
 JSR FMS
 BEQ DEDIT7
 LDAA $01,X
 CMPA #$03
 BNE DEDI55
 LDX #DLST
 JSR PSTRNG
 JSR GETCHR
 CMPA #$5F
 BLS DEDI67
 SUBA #$20
DEDI67 CMPA #$59
 BNE DEDI47
 LDX #RFCB
 LDAA #$0C
 STAA $00,X
 JSR FMS
 BNE DEDI55
 LDX #RFCB+4
 LDAB #$0B
DEDI68 LDAA $31,X
 STAA $00,X
 INX 
 DECB 
 BNE DEDI68
 BRA DEDI61
DEDIT7 LDX #RFCB
 LDAA #$01
 STAA $00,X
 JSR FMS
 BNE DEDI55
 JMP DEDIT5
DEDIT8 LDAA WFCB+3
 LDX #FCB
 STAA $03,X
 LDAA #$10
 STAA $00,X
 JSR FMS
 BCS DEDI88
 LDAA #$07
 STAA $00,X
 JSR FMS
 BCS DEDI88
 LDAA $15,X
 LDAB $16,X
 CMPA RFCB+21
 BHI DEDI88
 BCS DEDI85
 CMPB RFCB+22
 BCC DEDI88
DEDI85 LDX #LSST
 JSR PSTRNG
DEDI88 LDAA LASTIN
 BEQ DEDIT9
 LDX #NWFSTR
 JSR PSTRNG
 INC INZFLG
 BRA DEDI95
DEDIT9 INC DSKFLG
 JSR READ1
DEDI95 CLR DSKFLG
*
* RESTART ENTRY POINT
*
PEDIT CLR REPEAT DISABLE COMMAND REPEAT
 LDX FILBEG POINT TO BEGINNING
 STX CURPOS
 CLR MSLFLG
*
*************************
* LIB MAIN
 TTL MAIN
 PAG
*
* THIS IS THE MAIN EDIT LOOP
*
EDIT LDS #STACK SET UP STACK POINTER
 STX TEMP SAVE POINTER
 LDX CURPOS SET CURRENT POSITION
 STX NEWPOS SAVE IT
 LDX #PSTZFL
 CLRA CLEAR ACC.
EDIT1 STAA $00,X CLEAR OUT LOCATION
 INX BUMP POINTER
 CPX #CHRCNT+1
 BNE EDIT1
 LDX TEMP RESTORE POINTER
 LDAA INZFLG INITIALIZE?
 BEQ EDIT2
 CLR INZFLG
 JMP INSER4 GO INSERT LINES
EDIT2 LDAA MSLFLG MULTIPLE ST. PER LINE?
 BNE EDIT55
 STAA CHRCNT+1
 LDX #BUFFER SET POINTER
 JSR PCRLF
 LDAA #$23 SETUP PROMPT
 JSR OUTCH OUTPUT IT
EDIT25 JSR INCH GET INPUT CHAR.
 CMPA #$12 IS IT REPEAT KEY?
 BEQ EDIT26 BRANCH IF SO
 JSR INCHR1 CHECK CHARACTER
 BRA EDIT31
EDIT26 TST REPEAT IS REPEAT ENABLED?
 BNE EDIT5 BRANCH IF SO
 JMP ERROR ELSE, IT'S AN ERROR
EDIT3 JSR INCHAR
EDIT31 BEQ EDIT
EDIT4 STAA $00,X PUT CHAR IN BUFFER
 CMPA #$0D IS IT A C. R.
 BEQ EDIT5
 JSR BUFLIM IS BUFFER FULL?
 BRA EDIT3 REPEAT
EDIT5 LDX #BUFFER RESTORE POINTER
 STX BUFPNT
 LDAA #$01
 STAA REPEAT ENABLE COMMAND REPEAT
EDIT55 CLR MSLFLG
 JSR FINDL PROCESS LINE INFO
 CLRA
 STAA LINFLG CLEAR FLAS
 STAA DRCTN
 STX NEWPOS SAVE POINTER
 LDX BUFPNT
 JSR SKIPSP SKIP SPACES
 STX BUFPNT SAVE POINTER
 CMPA #$3D IS IT AN '='?
 BNE EDIT56
 INX BUMP POINTER
 STX BUFPNT
 LDX #EQUALS GO TO IT
 BRA EDIT85 TEST END
EDIT56 JSR TSTEND
 BNE EDIT58 POINT TO PRINT
 LDX #PRINT
 BRA EDIT85
EDIT58 STX TEMP
 LDX #TABLE POINT TO TABLE
EDIT6 STX TABPNT SAVE IT
 TST $00,X IS IT NULL?
 BEQ EDIT8
 CMPA #$61 CHECK LOWER CASE
 BCS EDIT63
 SUBA #$20 REMOVE BIAS
EDIT63 CMPA $00,X CHECK CHARACTER
 BNE EDIT7 ARE THEY EQUAL?
 LDX BUFPNT RESTORE POINTER
 INX BUMP IT
EDIT65 LDAA $00,X GET NEXT CHAR.
 STX BUFPNT SAVE POINTER
 LDX TABPNT
 INX BUMP THE TABLE PNTR
 BRA EDIT6
EDIT7 INX BUMP THE POINTER
 TST $00,X IS IT NULL?
 BNE EDIT7
 INX BUMP POINTER 3 TIMES
 INX
 INX
 TST $00,X END OF TABLE?
 BEQ ERROR REPORT ERROR
 DEX
 STX TABPNT SAVE THE POINTER
 LDX TEMP
 BRA EDIT65 REPEAT
EDIT8 INX BUMP THE POINTER
 LDX $00,X GET ADDRESS]
 CPX #INSERT IS IT INSERT?
 BNE EDIT85
 LDAA INLMFL
 BNE EDIT88
EDIT85 JSR TSTOVR
 BNE NOTFND
 CLRA CLEAR FLAGS
 STAA OVRBEG
 STAA OVREND
EDIT88 JMP $00,X GO TO IT
*
* ERROR ROUTINE
*
ERROR LDX #ERRSTR POINT TO STRING
*
* PRINT ERROR MESSAGE
*
PREROR BSR PSTRNG
 CLR REPEAT DISABLE COMMAND REPEAT
 CLR MSLFLG CLEAR FLAG
 JMP EDIT RETURN
*
ERRSTR FCC /?/
 FCB 4
*
* PRINT CARRAIGE RETURN AND LINE FEED
*
PCRLF JMP DPCRLF USE FLEX DO CR & LF
*
* REPORT LINE NOT FOUND
*
NOTFND LDX #NOFSTR POINT TO STRING
 BRA PREROR
*
NOFSTR FCC /NO SUCH LINE/
 FCB 4
*
* REPORT SYNTAX ERROR
*
SYNERR LDX #SYNSTR POINT TO STRING
 BRA PREROR
*
SYNSTR FCC /SYNTAX ERROR/
 FCB 4
*
* PRINT STRING ROUTINE
*
PSTRNG BSR PCRLF DO CR & LF
PDATA1 LDAA 0,X GET CHARACTER
 CMPA #4 IS IT TERM?
 BEQ SKIPS2
 JSR OUTCH OUTPUT IT
 INX
 BRA PDATA1
*
* SKIP SPACES
*
SKIPSA INX
SKIPSP LDAA 0,X GET A CHAR.
 CMPA #$20 IS IT A SPACE?
 BEQ SKIPSA REPEAT
SKIPS2 RTS RETURN
*
* INPUT AND CHECK CHARACTER
*
INCHAR JSR INCH GET CHARACTER
 CMPA #$05 IS IT CNTRL E?
 BNE INCHR1 NO - CONTINUE
 JMP EDIT9 YES - USE NEW ROUTINE
*
INCHR1 CMPA BSP IS IT A BACKSPACE?
 BNE INCHR3
 CPX #BUFFER ARE WE AT START OF BUFFER?
 BEQ INCHR4 YES
 DEX NO - SO DECREMENT
 DEC CHRCNT+1
 LDAA BSE GET ECHO CHARACTER
 CMPA #$08 IS IT ALSO A BS?
 BNE INCHR2 NOPE
 LDAA #$20 ERASE CHARACTER ON CRT
 JSR OUTCH OUTPUT IT
 LDAA BSE ECHO THE CHARACTER
INCHR2 JSR OUTCH
 BRA INCHAR
INCHR3 CMPA DEL IS IT DELETE CHAR?
 BEQ INCHR4 YES
 CMPA #$1F IS IT CONTROL?
 BHI INCH35 NO
 CMPA #CRGRET IS IT CR?
 BEQ INCH35
 CMPA #$09 IS THIS A TAB?
 BNE INCHAR
INCH35 INC CHRCNT+1 INC CHAR. COUNT
 RTS RETURN
*
INCHR4 CLRA
 STAA REPEAT DISABLE COMMAND REPEAT
INCHR5 RTS RETURN
*
* CHECK FOR BUFFER OVERFLOW
*
BUFLIM INX BUMP THE POINTER
 CPX #BUFFER+136
 BNE INCHR5
OVER LDAA #BELL LOAD UP BELL
 JSR OUTCH OUTPUT IT
 JSR INCH GET NEW CHAR.
 CMPA BSP IS IT BACKSPACE?
 BNE OVER
 DEX DEC THE POINTER
 DEC CHRCNT+1
 RTS RETURN
*
*************************
* LIB EDIT9
 TTL EDIT9
 PAG
*
* LINE EDITING CONTROL FOR CURSOR MOVEMENT
*
EDIT9 STX TEMP SAVE INDEX
*
* CLEAR THE BUFFER TO END
*
CLEAR CLR 0,X
 INX
 CPX #BUFFER+136
 BNE CLEAR
 LDX TEMP RESTORE INDEX
*
* THIS IS THE INPUT LOOP.
*
INPUT JSR INCH
 CMPA #$0D CRRIAGE RTN TERMINATES
 BNE CONT1
 JMP ENDRTN GO BACK TO BASIC
*
* NOW WE CHECK FOR EDIT CONTROL
* CHARACTERS.
*
CONT1 CMPA #$08
 BEQ BACKSP
 CMPA #$09 CNTRL I?
 BEQ FORWRD
 CMPA #$0C RIGHT ARROW?
 BEQ FORWRD
 CMPA #$04 CNTRL D?
 BEQ DELCH
 CMPA #$01 CNTRL A?
 BEQ ADD
 CMPA #$12 CNTRL R?
 BNE CONT3
 JMP RECALL
*
* IF ANY OTHER CONTROL CHR, IGNORE
*
CONT3 CMPA #$1F
 BMI INPUT
*
* OTHERWISE SORE CHARACTER IN BUFFER
*
STORCH STAA 0,X
*
* NOW MOVE THE CURSOR FORWARD
*
FORWRD LDAA 0,X CHECK FOR BUFF EOL
 BNE CONT21 BRA IF NOT
 LDAA #$08 PUT CURSOR BACK
 JSR OUTCH .WHERE IT BELONGS
 BRA INPUT
*
* MOVE TO NEXT POSITION IN THE BUFFER
*
CONT21 LDAA #$09 THIS IS CNTRL I?
 JSR OUTCH ECHO CHARACTER
CONT2 JSR BUFLIM CHECK FOR BUFF FULL
 BRA INPUT
*
* BACKUP CURSOR
*
BACKSP CPX #BUFFER
 BEQ ATBEG
 DEX
LPBACK BRA INPUT
ATBEG LDAA #$09
 JSR OUTCH
 BRA INPUT
*
* DELETE CHARACTER IN BUFFER AND CRT
*
DELCH STX TEMP
*
* ZERO COUNTER IN ORDER TO REPOSITION CURSOR
*
 CLR NUMBER
*
* MOVE CURSOR AND BUFFER CONTENTS
* ONE POSITION TO THE LEFT.
*
MOVLFT LDAA 1,X
 TAB
 JSR OUTCH
 TBA
 STAA 0,X
 INX
 INC NUMBER COUNT CHR'S TO END
 TSTA
 BNE MOVLFT
*
* PRINT A SPACE
*
SPACE LDAA #$20
 JSR OUTCH
*
* PUT CURSOR BACK TO CORRECT POSITION
*
MOVCSR TST NUMBER CHECK TO SEE IF DONE
 BEQ ENDD
 LDAA #$08
 JSR OUTCH
 DEC NUMBER
 BRA MOVCSR
ENDD LDX TEMP
 BRA LPBACK
*
* ADD SPACE TO BUFFER AT CURSOR POSITION
*
ADD STX TEMP
 CLR NUMBER
 LDAB #$20
*
* MOVE CURSOR AND BUFFER CONTENTS TO
* THE RIGHT ONE PLACE
*
MOVERT TBA
 LDAB 0,X
 STAA 0,X
 JSR OUTCH
 JSR BUFLIM
 INC NUMBER COUNT CHR'S FILLED
 TBA
 BNE MOVERT+1
 BRA MOVCSR
*
ERR JMP NOTFND
*
* RECALL LINE FROM MEMORY AND PLACE
* IN BUFFER
*
RECALL BSR ZERCSR MOVE CURSOR TO SOL
 LDX #BUFFER FIND LINE # IN BUFFER
 JSR CLASS CLASSIFY CHAR
 CMPB #$01 CHECK FOR ERROR
 BNE ERR
 JSR BCDCON CONVERT CHAR TO BCD
 LDAA #'=
 STAA 0,X
 INX
 STX TEMP
 JSR FNDNUM
 TSTB
 BNE ERR
*
* SKIP LINE NUMBER STORED IN MEMORY
*
 INX
 INX
 INX
*
* TRANSFER CHARACTERS FROM MEM TO BUFFER
*
SLOOP LDAA 0,X
 CMPA #$0D
*
* BRANCH IF LAST CHARACTER IN LINE
*
 BEQ ENDR
 INX
 STX NUMBER
 LDX TEMP
 STAA 0,X
 INX
 STX TEMP
 LDX NUMBER
 BRA SLOOP
ENDR LDX TEMP STORE #4 IN BUFF
 LDAA #$04
 STAA 0,X
 LDX #BUFFER PRINT BUFFER
 JSR PDATA1
*
* SET INDEX TO LAST CHARACTER IN BUFFER
*
 LDX TEMP
 CLR 0,X
LOOP2 JMP INPUT
*
ZERCSR CPX #BUFFER AT BEG OF BUFFER?
 BEQ ENDZ YES
 LDAA #$08
 JSR OUTCH
 DEX
 BRA ZERCSR
ENDZ RTS
*
* FIND END OF LINE IN BUFFER
*
ENDRTN LDX #BUFFER-1
 CLRB
LOOP INX
 INCB
 LDAA 0,X
 TSTA
 BNE LOOP
 STAB CHRCNT+1
 LDAA #$0D
 STAA 0,X
 JMP EDIT5
*
***************************
*  LIB PROCLIN
 TTL PROCLIN
 PAG
*
* PROCESS LINE ROUTINE
*
FINDL JSR SKIPSP SKIP SPACES
 CMPA #'= IS IT '='?
 BEQ FINDL0
 INC LINFLG SET FLAG
 JSR CLASS CLASSIFY CHAR.
 CMPB #1 IS IT A LETTER
 BLS FINDL2
FINDL0 LDX NEWPOS SET POINTER
FINDL1 RTS RETURN
FINDL2 BEQ FIND1
 BRA FIND

*TARGET ENTRY POINT

FINDT BSR FINDT0
 STX TRGLIN SAVE TARGET POS.
 RTS RETURN
FINDT0 CLR DRCTN
 JSR SKPCLS
 CMPB #1 IS IT A LETTER?
 BLS FINDT2
FINDT1 JMP SYNERR REPORT SYMTAX ERROR
FINDT2 BEQ FIND62
FIND CLR DRCTN CLEAR DIRECTION
 CMPA LINO IS IT LINE NUMBER
 BNE FIND2
 INX BUMP THE POINTER
 JSR SKIPSP
 STX BUFPNT
FIND1 JSR BCDCON
 STX TEMP SAVE POINTER
 LDX NEWPOS
 LDAA NUMBER GET NUMBER
 CMPA 0,X COMPARE IT
 BNE FIND14
 LDAA NUMBER+1 GET NEXT NUM.
 CMPA 1,X COMPARE
 BNE FIND14
 LDAA NUMBER+2
 CMPA 2,X
FIND14 BCC FIND16
 DEC DRCTN SET DIRECTION
FIND16 LDX TEMP RESTORE POINTER
 JSR FNDNUM FIND LINE NUMBER
 BEQ FINDL1
 STAB NOCURL
 JMP BAKONE
FIND2 JSR TSTEND
 BNE FIND3
 TST NXTFLG CHECK FLAG
 BEQ FINDL0
 LDX NEWPOS SET POINTER
 JMP UPONE UP ONE LINE
FIND3 CMPA #'! IS IT A "!"?
 BNE FIND4
 INX BUMP THE POINTER
 STX BUFPNT
 LDX FILEND SET POINTER
 JMP BAKONE BACKUP ONE LINE
FIND4 CMPA #'^ IS IT A "^"?
 BNE FIND5
 DEC DRCTN SET DIRECTION
 INX BUMP THE POINTER
 STX BUFPNT
 LDX FILBEG SET POINTER TO BEGIN
 RTS RETURN
FIND5 CMPA #'+ IS IT A "+"?
 BEQ FIND6
 CMPA #'- IS IT A "-"?
 BNE FIND7
 DEC DRCTN DEC DIRECTION
FIND6 INX BUMP THE POINTER
 JSR SKPCLS SKIP SPACES
 CMPB #1 IS IT NUMBER?
 BEQ FIND62
 BLS FIND7
 LDAB LINFLG TEST FLAG
 BEQ FINDT1
 JSR CLRNUM
 LDX NEWPOS SET POINTER
 BRA FIND66
FIND62 JSR BCDCON CONVERT NUMBER
 LDX NEWPOS SET POINTER
 TST LINFLG CHECK FLAG
 BNE FIND65
FIND63 JSR TSTNUM IS IT ZERO?
 BEQ FIND67
 JSR DECNUM DEC NUMBER
FIND65 JSR TSTNUM TEST NUMBER
 BEQ FIND67
 JSR DECNUM
FIND66 JSR NXTLIN GOTO NEXT LINE
 JSR TSTOVR CHECK LIMITS
 BEQ FIND65
 LDAA OVREND BEGINNING?
 BNE FIND67
 JSR TSTNUM
 BNE FIND67
 INC INLMFL
FIND67 RTS RETURN
FIND7 BSR SETDEL SET DELIMITER
FIN702 BSR ZONE SET ZONE
 LDX NEWPOS SET POINTER
 JSR NXTLIN GO TO NEXT
FIND71 INX BUMP POINTER 3 TIMES
 INX
 INX
FIN711 JSR FIXZON CHECK FOR POSTZONE
FIND72 JSR DECNUM DEC COLUMN COUNT
 BEQ FIND75
 LDAB #CRGRET
 CMPB 0,X TEST FOR C. R.
 BEQ FIND73
 INX BUMP THE POINTER
 BRA FIND72 REPEAT
FIND73 LDAA CHGFLG CHECK IF CHANGE
 BNE FIND67
 INX BUMP THE POINTER
 CPX FILEND END OF FILE ?
 BEQ FIND78
 DEX
FIND74 LDAA CHGFLG
 BNE FIND67
 DEX DEC THE POINTER
 JSR NXTLIN
 JSR TSTOVR CHECK LIMITS
 BNE FIND77
 BRA FIND71
FIND75 JSR FIXZON FIX UP ZONE
 JSR STRING PROCESS STRING
 TST FNDFLG FIND IT?
 BEQ FIND74
 CLRB
 LDAA CHGFLG
 BNE FIND77
 JSR BAKON2
 STX TRGLIN SAVE TARGET POINTER
FIND77 RTS RETURN
FIND78 LDAA #1 SET FLAG
 STAA OVREND
 RTS RETURN

* SET UP DELIMITERS

SETDEL STAA DELIM SAVE DELIMITER
 CLRB
 INX BUMP THE POINTER
 STX STRNGB SAVE BEGINNING
SETDE2 LDAA 0,X GET A CHARACTER
 BSR TSTEND
 BEQ SETDE4
 CMPA DELIM IS IT A DELIMITER?
 BEQ SETDE4
 INX BUMP THE POINTER
 INCB BUMB COUNTER
 BRA SETDE2 REPEAT
SETDE4 STX STRNGE SAVE END OF STRING
 STAB STRCNT
 BSR TSTEND
 BEQ SETDE5
 INX BUMP THE POINTER
SETDE5 STX BUFPNT
 RTS RETURN

* SET UP ZONE

ZONE JSR CLASS GO CLASSIFY CHAR.
 CLR PSTZFL CLEAR FLAG
 CMPB #1 IS IT A NUMBER
 BNE ZONE3
 JSR BCDCON CONVERT NUMBER
 BSR CMPZN1 CHECK ZONE1
 BCS ZONE3
 BSR CMPZN2 CHECK ZONE2
 BHI ZONE3
 INC PSTZFL SET FLAG
 LDAA NUMBER PUT NUM IN ZONE BUF.
 STAA ZONBUF
 LDAA NUMBER+1
 STAA ZONBUF+1
 RTS RETURN
ZONE3 LDAA ZONE1 PUT ZONE1 IN BUF.
 STAA ZONBUF
 LDAA ZONE1+1
 STAA ZONBUF+1
 RTS RETURN

* COMPARE ZONE1 TO NUMBER

CMPZN1 LDAB NUMBER GET NUMBER
 CMPB ZONE1 CHECK
 BNE CMPZ14
 LDAB NUMBER+1
 CMPB ZONE1+1
CMPZ14 RTS RETURN

* COMPARE ZONE2 TO NUMBER

CMPZN2 LDAB NUMBER GET NUMBER
 CMPB ZONE2 CHECK
 BNE CMPZ24
 LDAB NUMBER+1
 CMPB ZONE2+1
CMPZ24 RTS RETURN

* PUT CORRECT ZONE IN NUMBER

FIXZON LDAA ZONBUF GET ZONE
 STAA NUMBER PUT IN NUMBER
 LDAA ZONBUF+1
 STAA NUMBER+1
 RTS RETURN

* TEST ERMINATOR (C. R. OR EOL)

TSTEND CMPA #CRGRET IS IT C. R. ?
 BEQ TSTEN2
 CMPA EOL
TSTEN2 RTS RETURN

* BUMP NUMBER BY 1, .1, OR .01

BMPNUM LDAA #1
 LDAB INCAMT CHECK AMOUNT
 BEQ INCNUM
 BPL BMPNU4
 LDAA #$10 SET BUMP
BMPNU4 ADDA NUMBER+2 ADD IN
 DAA ADJUST IT
 STAA NUMBER+2 SAVE
 BCS INCNUM
 RTS RETURN

* INCREMENT NUMBER BY ONE

INCNUM LDAA #1 SET UP ONE
 CLRB
 ADDA NUMBER+1 ADD IN ONE
 DAA ADJUST IT
 STAA NUMBER+1 SAVE IT
 TBA
 ADCA NUMBER
 DAA ADJUST IT
 STAA NUMBER SAVE IT
 RTS RETURN

* PUT NUMBER AT X

PUTNUM LDAA NUMBER GET NUMBER
 STAA 0,X SAVE IT
 LDAA NUMBER+1
 STAA 1,X
 LDAA NUMBER+2
 STAA 2,X
 RTS RETURN

* GET NUMBER FROM X

GETNUM LDAA 0,X GET NUMBER
 STAA NUMBER SAVE IT
 LDAA 1,X
 STAA NUMBER+1
 LDAA 2,X
 STAA NUMBER+2
 RTS RETURN

* RENUMBER FILE

RENUMB JSR TFORCR
 LDX FILBEG SET POINTER
RENUM1 CLR INCAMT
 JSR CLRNUM CLEAR NUMBER
RENUM2 BSR BMPNUM BUMP NUMBER
 BSR PUTNUM SAVE IT
 JSR UPONE
 LDAA OVREND HIT LIMIT?
 BEQ RENUM2 NOPE
 LDAA CHKFLG
 BEQ RENUM4
 RTS

RENUM4 JMP PRINT6 RETURN

* GO TO NEXT LINE

NXTLIN LDAA DRCTN CHECK DIRECTION
 BMI NXTLI2
 JMP UPONE MOVE UP ONE
NXTLI2 JMP BAKONE MOVE BACK ONE

* PROCESS STRING ROUTINE

STRING CLR FNDFLG CLEAR FLAG
 LDAB STRCNT
 BNE STRIN1
 INC FNDFLG FOUND NULL STRING
 STX LASTNO SAVE POINTER
 RTS RETURN
STRIN1 LDAB #CRGRET
 STX SRCHPT SAVE POINTER
 STX LASTNO SAVE POINTER
 LDX STRNGB POINT TO BEGIN
STRIN2 STX STRPNT SAVE POINTER
 LDAA 0,X GET A CHARACTER
 LDX SRCHPT RESTORE POINTER
STRIN3 CMPB 0,X C. RET. ?
 BEQ STRIN4
 CMPA DCC CHECK DC DHAR
 BEQ STRIN5 MAKE MATCH!
 CMPA 0,X COMPARE CHAR
 BEQ STRIN5
 TST PSTZFL POST ZONE?
 BNE STRIN4
 TST FNDFLG FOUND?
 BNE STRIN6
 INX BUMP THE POINTER
 STX LASTNO SAVE IT
 PSHA SAVE ACC.
 PSHB
 JSR INCNUM INC NUMBER
 JSR CMPZN2 CHECK ZONE2
 PULB RESTORE ACC
 PULA
 BLS STRIN3
STRIN4 CLR FNDFLG CLEAR FLAG
 RTS RETURN
STRIN5 INX
 STX SRCHPT SAVE IT
 INC FNDFLG SET FLAG
 LDX STRPNT POINT TO STRING
 INX BUMP THE POINTER
 CPX STRNGE END OF STRING?
 BEQ STRIN7
 BRA STRIN2
STRIN6 LDX LASTNO RESTORE POINTER
 INX
 JSR INCNUM BUMP NUMBER
 JSR CMPZN2 CHECK ZONE
 BLS STRING
 BRA STRIN4
STRIN7 LDAB STRCNT GET COUNT
STRIN8 BEQ STRIN9
 PSHB SAVE
 JSR INCNUM FIX COL
 PULB
 DECB DEC COUNT
 BNE STRIN8
STRIN9 LDX LASTNO
 RTS RETURN

* SKIP AND CLASSIFY

SKPCLS JSR SKIPSP

* CLASSIFY CHARACTER

CLASS STX BUFPNT SAVE POINTER
 LDAA 0,X GET CHARACTER
 CLRB
 CMPA #$2F CHECK IF NUMBER
 BLS CLASS4
 CMPA #'9
 BHI CLASS2
 INCB SHOW NUMBER
 RTS RETURN
CLASS2 CMPA #$40 CHECK IF LETTER
 BLS CLASS4
 CMPA #'Z
 BLS CLASS3
 CMPA #$61 CHECK LOWER CASE
 BLO CLASS4
 CMPA #$7A
 BHI CLASS4
CLASS3 LDAB #2 SHOW LETTER
CLASS4 RTS RETURN

* COMVERT ASCII TO BCD

BCDCON BSR CLRNUM CLEAR NUMBER
BCDCO1 BSR CLASS CLASSIFY CHAR.
 CMPB #1 IS IT A NUMBER?
 BEQ BCDCO2
 CMPA #'. IS IT A "."?
 BEQ BCDCO5
BCDC15 STX BUFPNT SAVE POINTER
 RTS RETURN
BCDCO2 INX BUMP THE POINTER
 ANDA #$0F MASK ASCII
 LDAB #4 SET COUNTER
BCDCO4 ASL NUMBER+1
 ROL NUMBER SHIFT EVERYTHING LEFT
 DECB DEC THE COUNTER
 BNE BCDCO4
 ADDA NUMBER+1 ADD IN NUMBER
 STAA NUMBER+1
 BRA BCDCO1
BCDCO5 LDAB #2 SET COUNTER
 STAB DECCNT
BCDCO6 INX BUMP THE POINTER
 BSR CLASS CLASSIFY CHAR.
 CMPB #1 IS IT NUMBER?
 BEQ BCDC65
 CLRA
 DEX DEC THE POINTER
 BRA BCDC67
BCDC65 ANDA #$0F MASK ASCII
BCDC67 LDAB #4 SET COUNTER
BCDCO7 ASL NUMBER+2
 DECB
 BNE BCDCO7
 ADDA NUMBER+2
 STAA NUMBER+2
 DEC DECCNT DEC COUNTER
 BNE BCDCO6
BCDCO8 INX BUMP THE POINTER
 BSR CLASS CLASSIFY CHAR.
 CMPB #1 IS IT NUMBER?
 BEQ BCDCO8
 BRA BCDC15
***************************
*  LIB LINSUBRS
 TTL LINSUBRS
 PAG

* CLEAR NUMBER ROUTINE

CLRNUM CLRA CLEAR ACC.
 STAA NUMBER
 STAA NUMBER+1 CLEAR ALL OUT
 STAA NUMBER+2
 RTS RETURN

* FIND NUMBERED LINE

FNDNUM LDAB NUMBER GET DIGIT
 LDAA NUMBER+1
 LDX FILBEG SET POINTER TO BEGIN
FNDNU1 CPX FILEND END OF FILE?
 BNE FNDNU4
 INC OVREND SET ERROR FLAG
FNDNU2 INCB
 RTS RETURN
FNDNU4 CMPB 0,X COMPARE DIGIT
 BHI FNDNU5
 BNE FNDNU2
 CMPA 1,X COMP NEXT DIGIT
 BHI FNDNU5
 BNE FNDNU2
 LDAB NUMBER+2 NEXT DIGIT
 CMPB 2,X CHECK DIGIT
 BHI FNDNU5
 BNE FNDNU2
 TST SNGLIN
 BNE FNDN45
 TST CHKFLG
 BNE FNDNU2
FNDN45 CLRB
 RTS RETURN
FNDNU5 TST CHKFLG
 BNE FNDN45
 BSR FNDCRT FIND C. R.
 LDAB NUMBER RESTORE NUM
 INX BUMP THE POINTER
 BRA FNDNU1 REPEAT

* FIND THE NEXT CARRIAGE RETURN

FNDCRT PSHA SAVE ACC.
 LDAA #CRGRET
FNDCR2 INX BUMP THE POINTER
 CMPA 0,X CHECK FOR C. R.
 BNE FNDCR2
 PULA RESTORE ACC.
 RTS RETURN

* MOVE BACK ONE LINE

BAKONE CPX FILBEG
 BEQ BAKON6
 LDAB #1 SET COUNTER
BAKON2 DEX DEC THE POINTER
 CPX FILBEG BEGINNING?
 BEQ BAKON5
 LDAA 0,X GET A CHAR.
 CMPA #CRGRET IS IT C. R.?
 BNE BAKON2
 DECB DEC THE COUNTER
 BPL BAKON2
 INX BUMP THE POINTER
 LDAB #1
BAKON4 RTS RETURN
BAKON5 TSTB
 BEQ BAKON4
BAKON6 INC OVRBEG SET ERROR FLAG
 RTS RETURN

* MOVE UP ONE LINE

UPONE CPX FILEND END OF FILE?
 BNE UPONE2
UPONE1 LDAB #1 SET ERROR FLAG
 STAB OVREND
 BRA BAKONE
UPONE2 BSR FNDCRT FIND NEXT C. R.
 INX BUMP THE POINTER
 CPX FILEND END?
 BEQ UPONE1
 RTS RETURN

* TEST FOR OVER END LIMITS

TSTOVR TST OVRBEG BEGINNING?
 BNE TSTOV2
 TST OVREND END?
TSTOV2 RTS RETURN

* DECREMENT NUMBER BY ONE

DECNUM LDAA #$99
 TAB SET UP $9999
 ADDA NUMBER+1 ADD IN
 DAA ADJUST IT
 STAA NUMBER+1 SAVE
 TBA
 ADCA NUMBER
 DAA STAA NUMBER
 STAA NUMBER

* TEST NUMBER FOR ZERO

TSTNUM LDAA NUMBER CHECK IF ZERO
 BNE TSTNU2
 LDAA NUMBER+1
TSTNU2 RTS RETURN

* VERIFY LINE ROUTINE

VERLIN STX NEWPOS SAVE POINTER
 JSR FNDCRT
 STX SPCPT2 SAVE POSITION
 CLRA
 STAA CHRCNT
VERLI1 DEX DEC POINTER
 DEX
 DEX
VERL12 DEX DEC THE POINTER
 LDAB 0,X CHECK SHAR
 CMPB #CRGRET IS IT C. R. ?
 BEQ VERL15
 LDAB 3,X CHECK
 CMPB #' IS IT A SPACE?
 BNE VERL15
 INCA
 BRA VERL12
VERL15 STAA CHRCNT+1 SAVE COUNT
 INX
 INX
 INX BUMP POINTER
 INX
 STX SPCPT1
 JSR DELCHR DELETE SPACES
 LDX NEWPOS
 LDAA VERFLG CHECK FLAG
 BEQ VERLI2
 BSR OUTLIN OUTPUT LINE
 JSR BAKONE BACKUP ONE LINE
VERLI2 STX CURPOS SAVE POINTER
 STX NEWPOS
 RTS RETURN

* PRINT ROUTINE

PRINT BSR TSTEMP
 LDX BUFPNT SET POINTER
 JSR FINDT FIND TARGET
PRINT0 LDX NEWPOS SET POINTER
 INC PRNFLG SET FLAG
 STX CURPOS SAVE IT
PRINT1 CPX TRGLIN TARGET LINE?
 BNE PRIN12
 CLR PRNFLG CLEAR FLAG
PRIN12 BSR OUTLIN
 LDAA PRNFLG CHECK FLAG
 BEQ PRINT5
 LDAA DRCTN CHECK DIRECTION
 BEQ PRINT1
 DEX DEC POINTER TWICE
 DEX
 JSR BAKONE MOVE BACK ONE
 BRA PRINT1
PRINT5 JSR BAKONE MOVE BACK ONE
 STX CURPOS SAVE POINTER
PRINT6 JSR TSTMSL
 JMP EDIT RETURN

* TEST IF FILE EMPTY

TSTEMP LDX FILBEG
 CPX FILEND
 BEQ PRINT6
 RTS

* OUTPUT ONE LINE

OUTLIN JSR PCRLF
 LDAA NUMFLG
 BNE OUTL15
 BSR OUTSPC OUTPUT SPACE
 INX BUMP THE POINTER
 INX
 BRA OUTLI2
OUTL15 BSR OUTBCD OUTPUT LINE NO.
 DEX
OUTLI2 INX
 LDAA 0,X GET A CHAR.
 CMPA #CRGRET IS IT C. R. ?
 BEQ OUTLI4
 JSR OUTCH OUTPUT IT
 BRA OUTLI2 REPEAR
OUTLI4 INX BUMP THE POINTER
 RTS RETURN

* OUTPUT A SPACE

OUTSPC LDAA #' LOAD UP SPACE
 JSR OUTCH OUTPUT IT
 CLC
 RTS RETURN

* OUTPUT A BCD NUMBER

OUTBCD LDAA NUMFLG CHECK FLAG
 BEQ OUTB75
 BSR OUTSPC OUTPUT A SPACE
 LDAB #2 SET COUNTER
 CLC
OUTBC2 LDAA 0,X GET CHAR.
 BITA #$F0 MASK
 BCS OUTBC3
 BEQ OUTB35
OUTBC3 JSR OUTHL OUTPUT DIGIT
 SEC SET FLAG
 BRA OUTBC4
OUTB35 BSR OUTSPC
OUTBC4 LDAA 0,X GET DIGIT
 BITB #$FE CHECK IF DONE
 BEQ OUTBC6
 BITA #$0F MASK
 BCS OUTBC6
 BEQ OUTB65
OUTBC6 BSR OUTHR OUTPUT DIGIT
 SEC
 BRA OUTBC7
OUTB65 BSR OUTSPC
OUTBC7 INX BUMP THE POINTER
 DECB DEC THE COUNTER
 BEQ OUTBC8
 BPL OUTBC2
OUTB75 LDAA #'=
OUTB78 JMP OUTCH OUTPUT A "="
OUTBC8 LDAA #'. OUTPUT A "."
 JSR OUTCH
 SEC
 BRA OUTBC2 GO FINISH

* OUTPUT DIGITS ROUTINE

OUTHL LSRA SHIFT LEFT FOUR TIMES
 LSRA
 LSRA
 LSRA
OUTHR ANDA #$0F MASK
 ADDA #$30 MAKE ASCII
 BRA OUTB78

* SET NUMBERS ON OR OFF

NUMSET BSR ONOFF GET ON OFF
 BEQ NUMSE2
 BMI NUMSE4
 CLR NUMFLG CLEAR FLAG
 BRA NUMSE6
NUMSE2 COMA COM. FLAG
 STAA NUMFLG SAVE IN FLAG
 BRA NUMSE6
NUMSE4 COM NUMFLG COM FLAG
NUMSE6 LDX NEWPOS
 STX CURPOS SET POINTER
 JMP PRINT6

* CHECK FOR ON OR OFF

ONOFF LDX BUFPNT SET POINTER
 JSR SKIPSP SKIP SPACES
 STX BUFPNT SAVE POINTER
 STX TEMP
 LDX #ONOFTB POINT TO TABLE
 JMP EDIT6

* TABLE FOR ON OFF

ONOFTB FCC 'ON'
 FCB 0
 FDB ON
 FCC 'OFF'
 FCB 0
 FDB OFF
 FCB CRGRET
 FCB 0
 FDB TOGGLE
 FCB 0

* ON OFF ROUTINES

ON CLRA
 RTS RETURN
OFF LDAA #1 SET FLAG
 RTS RETURN
TOGGLE LDX BUFPNT
 DEX
 STX BUFPNT FIX
 LDAA #$FF SET FLAG
 RTS RETURN

* SET VARIFY FLAG

VERSET BSR ONOFF CHECK ON OFF
 BEQ VERSE2
 BMI VERSE4
 CLR VERFLG CLEAR FLAG
 BRA VERSE6
VERSE2 COMA
 STAA VERFLG
 BRA VERSE6
VERSE4 COM VERFLG COM. FLAG
VERSE6 BRA NUMSE6

* CURSOR CONTROL COMMAND "X"

XCNTRL BSR TFORCR
 LDX #CNRSTR POINT TO STRING
 JSR PDATA1 OUTPUT IT
 BRA NUMSE6

CNRSTR FCB 0,0,0,0,0,0
 FCB 4 THIS 4 MUST REMAIN !!!

* EXIT ROUTINE

EXIT BSR TFORCR
DEXIT INC DSKFLG SET FLAG
EXIT2 LDX FILBEG SET POINTER
 STX SPCPT1
 LDX FILEND GET END
 STX SPCPT2
 JSR RECOR1 GO WRITE IT
 TST LASTIN FINISHED?
 BNE EXIT5
 JSR RNEW READ NEW
 BRA DEXIT REPEAT
EXIT5 LDX #WFCB POINT TO FCB
 JSR CLSFC1 CLOSE FILE
 JSR FMSCLS CLOSE FMS
 JMP WARMS

* SET POINTER TO BOTTOM

BOTTOM BSR TFORCR
BOTTO1 JSR TSTEMP
 LDX FILEND
 JSR BAKONE MOVE BACK ONE
BOTTO2 STX CURPOS SAVE-POINTER
 JMP PRINT6

* SET POINTER TO TOP

TOP BSR TFORCR
 JSR TSTEMP
 BRA BOTTO2

* TEST OR C. R.

TFORCR LDX BUFPNT SET POINTER
 JSR SKIPSP
 CMPA #CRGRET IS IT C. R. ?
 BEQ TFORC2
 CMPA EOL
 BNE TFORC3
TFORC2 RTS RETURN
TFORC3 JMP SYNERR

* TEST FOR MULTIPLE STATEMENTS PER LINE

TSTMSL LDX BUFPNT GET POINTER
 LDAA #CRGRET GET C. R.
 LDAB EOL GET EOL CHAR.
TSTMS2 CMPA 0,X CHECK CHARACTER
 BEQ TSTMS5
 CMPB 0,X
 BEQ TSTMS4
 INX BUMP POINTER ONE
 BRA TSTMS2 REPEAT
TSTMS4 INX
 STX BUFPNT SAVE BUFFER POINT
 STAA MSLFLG SET FLAG
TSTMS5 RTS RETURN

* PROCESS THE NEXT COMMAND

NEXT INC NXTFLG

* FIND COMMAND

CFIND JSR TSTEMP
 INC LINFLG SET FLAG
 BSR OCCURR CHECK FOR OCCURRENCE
 LDX TRGLIN SET POINTER
 JSR TSTOVR CHECK LIMITS
 BEQ CFIND2
 LDAB NXTFLG CHECK FLAG
 BNE CFIND5
 BRA CFIN12
CFIND1 LDAA ALLFLG CHECK IF ALL
 BNE CFIND6
CFIN12 LDX #CFNTST POINT TO STRING
 JSR PSTRNG OUTPUT IT
 LDX ZONE1 CHECK ZONES
 CPX #$0001
 BNE CFIN13
 LDX ZONE2 CHECK ZONE 2
 CPX #$0136
 BEQ CFIN14
CFIN13 LDX #ZOKSTR POINT TO STRING
 JSR PDATA1 OUTPUT IT
CFIN14 CLR MSLFLG
CFIN15 JMP EDIT RETURN
CFIND2 LDX TRGLIN POINT TO TARGET
 CPX NEWPOS SAME ONE?
 BEQ CFIND6
 STX NEWPOS SAVE IT
CFIND3 LDAB OCRFLG CHECK FLAG
 BEQ CFIND5
 LDAB NXTFLG CHECK FLAG
 BNE CFIND4
 JSR VERLIN VERIFY LINE
CFIND4 JSR NXTOCR CHECK NEXT OCCUR.
 JSR TSTOVR CHECK LIMITS
 BEQ CFIND2
 BRA CFIND9
CFIND5 JSR VERLIN VERIFY LINE
CFIND6 JMP PRINT6
CFIND9 LDAB NXTFLG CHECK FLAG
 BNE CFIND5
 BRA CFIND1

CFNTST FCC 'NOT FOUND'
 FCB 4

ZOKSTR FCC '...ZONES OK?'
 FCB 4

* CHECK FOR OCCURRENCE

OCCURR LDX BUFPNT SET POINTER
 STX BUFSAV SAVE IT
 CLR ALLFLG
 CLR OCRFLG
 JSR FINDT FIND TARGET
 LDX BUFPNT RESTORE POINTER
 JSR SKPCLS
 CMPB #1 IS IT NUMBER?
 BEQ OCCUR3
 CMPA #'* IS IT A "*"?
 BNE OCCUR5
 INC ALLFLG SET FOR ALL OCCUR.
 BRA OCCUR4
OCCUR3 JSR BCDCON GET NUMBER
 JSR TSTNUM ZERO?
 BEQ OCCUR5
 JSR DECNUM DEC NUMBER
 BEQ OCCUR5
 BSR SAVOCR SAVE OCCURRENCE
OCCUR4 INC OCRFLG SET FLAG
OCCUR5 RTS RETURN

* SAVE PRESENT OCCURRENCE COUNT

SAVOCR LDAA NUMBER GET NUMBER
 STAA OCRCNT SAVE IT
 LDAA NUMBER+1
 STAA OCRCNT+1
 RTS RETURN

* PROCESS NEXT OCCURRENCE

NXTOCR LDAA ALLFLG CHECK FOR ALL
 BNE NXTOC1
NXTOC0 LDAA OCRCNT GET COUNT
 STAA NUMBER PUT IN NUMBER
 LDAA OCRCNT+1
 STAA NUMBER+1
 JSR DECNUM DEC THE COUNT
 BEQ NXTOC2
 BSR SAVOCR SAVE COUNT
NXTOC1 LDAA CHGFLG
 BNE NXTOC3
 LDX BUFSAV RESTORE POINTER
 JMP FINDT FIND TARGET AND RET
NXTOC2 CLR OCRFLG CLEAR FLAG
 BRA NXTOC1
NXTOC3 RTS RETURN

* EQUALS COMMAND

EQUALS JSR TSTEMP
 LDX BUFPNT SET POINTER
 CLR BMPFLG
 INC SNGLIN
 INC EQUFLG
 LDAA NOCURL CURRENT LINE?
 BNE INSER1
 LDX NEWPOS
 STX TRGLIN FIX TARGET
 JSR GETNUM GET NUMBER
 INC REPFLG SET FLAG
 LDAA CHRCNT+1
 STAA TMPCHR
 JMP DELET0
***********************
*  LIB INSERT
 TTL INSERT
 PAG

* INSERT ROUTINE

INSERT LDX BUFPNT SET POINTER
 CLR BMPFLG CLEAR FLAG
 LDAA 0,X GET CHAR.
 CMPA #CRGRET
 BEQ INSER4
 INC SNGLIN SET FLAG
 INX BUMP THE POINTER
INSER1 STX BUFPNT SAVE IT
 LDX #BUFFER
 LDAA CHRCNT+1 GET COUNT
INSER2 CPX BUFPNT CHECK POINT
 BEQ INSER3
 DECA DEC THE COUNTER
 INX BUMP THE POINTER
 BRA INSER2
INSER3 ADDA #3 FIX COUNT
 STAA CHRCNT+1
INSER4 CLR REPEAT DISABLE COMMAND REPEAT
 LDX NEWPOS SET POINTER
 STX CURPOS SAVE POINTER
 LDAA EQUFLG
 BEQ INSE42
 LDAA OVRBEG CHECK LIMIT
 BEQ INSE43
 BRA INSER5
INSE42 JSR GETNUM
 LDAA INLMFL CHECK FLAG
 BEQ INSE43
 CPX FILEND EMPTY?
 BEQ INSE43
 CLRB CLEAR ACC.
 STAB NUMBER SAVE IN NUMBER
 STAB NUMBER+1
 BRA INSER5
INSE43 JSR UPONE UP ONE LINE
 LDAB 2,X GET DIGIT
 LDAA OVREND LIMIT?
 BEQ INSER5
INSE45 CLRB
 LDX FILEND
 CPX FILBEG
 BNE INSER5
 JSR CLRNUM CLEAR OUT NUMBER

* CALCULATE LINE NUMBER INCREMENT

INSER5 STX SPCPT1 SAVE POINTER
 LDAA EQUFLG
 BNE INSE60
 LDAA OVREND LIMIT?
 BEQ INSE51
 CLR NUMBER+2
 BRA INSER6
INSE51 LDAA BMPFLG
 BNE INSER6
 LDAA NUMBER+2 GET NUMBER
 STAB TMPCHR
 ORAA TMPCHR
 BEQ INSE55
 LDAA INLMFL CHECK FLAG
 BEQ INSE52
 CLR NUMBER+2
INSE52 LDAA #1
 STAA INCAMT SET AMOUNT
 BRA INSER6
INSE55 DEC INCAMT
INSER6 JSR BMPNUM BUMP NUMBER
 LDAA SNGLIN CHECK IF SINGLE IN
 BEQ INSE61

* ENTER BUFFERED INPUT MODE

INSE60 LDX BUFPNT
 BRA INSE71
INSE61 CLR INLMFL
 JSR PCRLF
 LDX #NUMBER POINT TO NUMBER
 JSR OUTBCD OUTPUT IT
 CLR CHRCNT
 LDAA #3 SET COUNTER
 STAA CHRCNT+1
 STAA BMPFLG SET FLAG
 LDX #BUFFER SET POINTER
INSE62 JSR INCHAR GET A CHARACTER
 BEQ INSE61
 CMPA #CRGRET IS IT C. R. ?
 BEQ INSER7
 CMPA #$09 IS IT TAB?
 BNE INSE63
 JSR DOTAB
INSE63 STAA 0,X
 JSR BUFLIM CHECK LIMIT
 BRA INSE62 REPEAT
INSER7 STAA 0,X
 LDX #BUFFER SET POINTER
INSE71 STX BUFPNT SAVE IT
 LDAA 0,X GET CHAR.
 CMPA LINO ESCAPE?
 BNE INSE72
 LDAA CHRCNT+1
 SUBA #3 FIX COUNT
 STAA CHRCNT+1
 INX BUMP THE POINTER
 
* CHECK IF RENUMBERING NECESSARY

INS710 STX TEMP SAVE POINTER
 LDX NEWPOS
 JSR UPONE UP ONE LINE
 TST OVREND LIMIT?
 BNE INS711
 INC CHKFLG SET FLAG
 LDAB NUMBER GET NUMBER
 LDAA NUMBER+1
 JSR FNDNU4 CHECK NUMBER
 BNE INS711
 CLRA
 STAA INCAMT SET INCREMENT AMOUNT
 STAA NUMBER+2
 JSR RENUM2 RENUMBER THE FILE
 LDX #RENSTR POINT TO STRING
 JSR PSTRNG OUTPUT IT
INS711 LDX TEMP RESTORE POINTER
 TST SNGLIN
 BEQ INS712
 LDX NEWPOS FIX POINTER
 STX CURPOS
 BRA INS713
INS712 INC MSLFLG SET FLAG
INS713 JMP EDIT
*
* ACTUAL LINE INSERT
*
INSE72 BSR MAKSPC MAKE SOME SPACE
 LDX TEMP RESTORE POINTER
 STX NEWPOS
 JSR PUTNUM PUT NUMBER
 INX
 INX
 INX BUMP 3 TIMES
 STX TEMP UPDATE POINTER AND SAVE
INSE75 LDX BUFPNT
 LDAA 0,X GET CHARACTER
 INX
 STX BUFPNT SAVE UPDATED CHARACTER
 LDX TEMP
 STAA 0,X PUT CHARACTER
 INX
 STX TEMP SAVE UPDATED POINTER
 CMPA #CRGRET
 BNE INSE75 REPEAT TILL EOL
 JSR EXPLIN EXPAND TABS
 LDAA SNGLIN
 BNE INS710
 JMP INSER4
*
RENSTR FCC "SOME LINES RENUMBERED"
 FCB 4
*
* MAKE SOME SPACE IN BUFFER FOR NEW LINE
*
MAKSPC CLR DECCNT CLEAR COUNT
 LDX SPCPT1 SET POINTER
 STX TEMP SAVE IT
 CPX FILEND END OF FILE?
 BNE MAKSP1 NO - CONTINUE
 INC DECCNT
MAKSP1 LDX FILEND SET POINTER
 STX SPCPT1 SAVE IT
 LDAB CHRCNT
 LDAA CHRCNT+1
 BNE MAKS21
MAKS18 TSTB
MAKSP2 BEQ MAKSP4
MAKS21 CPX MEMEND END OF MEMORY?
 BEQ MAKSP3
 INX BUMP POINTER
 TST DRCTN WHICH DIRECTION?
 BNE MAKS22
 STX XSAVE SAVE POINTER
 BRA MAK222
MAKS22 TST CPYDRC
 BEQ MAKS23
 STX XSAVE SAVE THE POINTER
 LDX NEWPOS GET POSITION
 INX BUMP IT
 STX NEWPOS SAVE UPDATED POINTER
MAK222 LDX TRGLIN GET TARGET
 INX
 STX TRGLIN
 LDX XSAVE
MAKS23 TSTA
 BNE MAKS24
 DECB
MAKS24 DECA
 BNE MAKS21
 BRA MAKS18 REPEAT
MAKSP3 LDX #NORMST POINT TO STRING
 JSR PSTRNG PRINT IT
 CLR MSLFLG
 JMP EDIT EXIT
*
MAKSP4 STX FILEND SAVE END OF FILE POINTER
 STX SPCPT2
 LDAA DECCNT CHECK
 BNE MAKSP6
MAKSP5 STX SPCPT2 SAVE POINTER
MAKS55 LDX SPCPT1
 CPX TEMP DONE?
 BEQ MAKSP6
 DEX DECREMENT POINTER
 LDAA 0,X GET CHARACTER
 STX SPCPT1 SAVE POINTER
 LDX SPCPT2
 DEX DECREMENT POINTER
 STAA 0,X
 BRA MAKSP5 REPEAT
MAKSP6 RTS
*
NORMST FCC /NOT ENOUGH ROOM/
 FCB 4
*
* INSERT SPACES IF TAB IS ENTERED
*
DOTAB LDAA #$20 SET CHAR = SPACE
 STAA 0,X
 JSR OUTCH
DTLOOP LDAA CHRCNT+1 GET CHARACTER COUNT
 SUBA #$03 TAKE OUT LINE NUMBER
 BSR TABCHK SEE IF AT TAB STOP
 BCS TABRTS YES - EXIT
 JSR BUFLIM
 LDAA #$20 SET CHAR = SPACE
 STAA 0,X
 JSR OUTCH
 INC CHRCNT+1
 BNE DTLOOP LOOP TIL TAB STOP
 INC CHRCNT
 BRA DTLOOP
TABRTS LDAA #$20
 RTS
*
* SEE IF AT TAB STOP POSITION
*
TABCHK  STX     IRSAVE
        LDX     #TABBUF         POINT TO TAB BUFFER
        PSHB
TCLOOP  SEC                     SET NO TAB DEFAULT
        LDAB    0,X
        BEQ     TCRTN
        CBA                     CUR COL POS - TAB STOP POS
        CLC                     SET DO TAB DEFAULT
        BMI     TCRTN           NOT THERE YET
        SEC                     SET NO TAB DEFAULT
        BEQ     TCRTN
        INX                     POINT TO NEXT TAB STOP
        BRA     TCLOOP          LOOP TILL END OF TABBUF
TCRTN   PULB
        LDX     IRSAVE
        RTS
*
IRSAVE FDB     $0000
*
******************
* LIB REPLACE
 TTL REPLACE
 PAG
* PROGRAM :  REPLACE
*
* REPLACE LINES ROUTINE
*
REPLAC INC REPFLG SET FLAG
*
* DELETE LINES ROUTINE
*
DELETE LDX BUFPNT SET POINTER
 JSR FINDT FIND TARGET
 JSR TSTOVR LIMITS?
 BEQ DELET0
DELE02 LDX #NTRCHS POINT TO STRING
 JSR PSTRNG PRINT IT
 CLR REPEAT DISABLE COMMAND RETREAT
 LDX #BUFFER POINT TO BUFFER
DELE04 JSR INCHAR GET A CHARACTER
 BEQ DELE02
 STAA 0,X SAVE IT
 INX
 CMPA #CRGRET C.R.?
 BNE DELE04 NO - REPEAT
 LDX #BUFFER
 JSR SKIPSP SKIP SPACES
 CMPA #'Y WAS IT "Y"ES?
 BEQ DELET0 YES
 LDX #NLDSTR POINT TO STING
 JSR PSTRNG PRINT IT
 BRA DELET5 RETURN
DELET0 LDX NEWPOS SET POINTER
 LDAA DRCTN CHECK DIRECTION
 BEQ DELET1
 JSR UPONE MOVE UP ONE
 LDAA OVREND LIMIT
 BEQ DELE15
 LDX FILEND
DELE15 STX SPCPT2
 LDX TRGLIN GET TARGET
 STX CURPOS MAKE CURRENT
 STX SPCPT1
 LDX SPCPT2 GET POINTER
 BRA DELE25
DELET1 STX SPCPT1 SAVE
 STX CURPOS
 LDX TRGLIN POINT TO TARGET
 JSR UPONE MOVE UP ONE
 LDAA OVREND LIMIT?
 BEQ DELET2
 LDX FILEND POINT TO END
DELET2 STX SPCPT2 SAVE POINTER
DELE25 CLRA
 CLRB
DELET3 CPX SPCPT1
 BEQ DELET4
 INCA
 BNE DELE35
 INCB BUMP THE COUNTER
DELE35 DEX
 BRA DELET3 LOOP
*
DELET4 STAA CHRCNT+1 SAVE COUNT
 STAB CHRCNT
 BSR DELCHR DELETE CHARACTERS
 LDAA REPFLG REPLACE?
 BEQ DELET5
 LDX CURPOS
 JSR BAKONE BAACK UP ONE LINE
 LDAA EQUFLG
 BNE DELET7
 LDAA OVRBEG CHECK LIMIT
 BEQ DELE45
 CLR REPEAT DISABLE COMMAND REPEAT
 JSR CLRNUM CLEAR NUMBER
 STX NEWPOS SAVE NEW POSITION
 JMP INSER5
DELE45 STX NEWPOS SAVE NEW POSITION
 CLR BMPFLG
 JMP INSER4 GO INSERT
DELET5 LDX CURPOS CHECK POSITION
 CPX FILEND END?
 BNE DELET6
 JSR BAKONE MOVE IT BACK
 STX TEMP SAVE POINTER
 LDX #BFRSTR POINT TO STRING
 JSR PSTRNG OUPUT IT
 LDX TEMP RESTORE POINTER
DELET6 STX CURPOS
 JMP PRINT6
DELET7 STX NEWPOS SAVE POINTER
 LDAA TMPCHR GET CHARACTER COUNT
 STAA CHRCNT+1
 CLRA
 STAA BMPFLG CLEAR FLAG
 STAA CHRCNT
 LDX BUFPNT SET POINTER
 JMP INSER1 GO INSERT IT
*
* DELETE CHARACTER BLOCK
*
DELCHR LDX SPCPT2 SET POINTER
 CPX SPCPT1 ARE THEY EQUAL?
 BEQ DELCH5 YES - JUST EXIT
 CPX FILEND END OF FILE?
 BEQ DELCH2
 LDAA 0,X GET A CHAR
 INX
 STX SPCPT2 SAVE UPDATED POINTER
 LDX SPCPT1
 STAA 0,X PUT CHARACTER
 INX
 STX SPCPT1
 BRA DELCHR LOOP TILL DONE
DELCH2 LDAB CHRCNT GET COUNT
 LDAA CHRCNT+1
 BNE DELC31
DELC21 TSTB
DELCH3 BEQ DELCH4
DELC31 DEX DECREMENT POINTER
 TST DRCTN WHICH DIRECTION?
 BNE DELC32
 STX XSAVE
 LDX TRGLIN
 DEX
 STX TRGLIN DECREMENT TARGET LINE POINTER
 LDX XSAVE
DELC32 TSTA TEST COUNT
 BNE DELC34
 DECB DECREMENT THE COUNT
DELC34 DECA
 BNE DELC31
 BRA DELC21
DELCH4 STX FILEND SET NEW END
DELCH5 RTS EXIT
*
NTRCHS FCC 'TARGET NOT REACHED!'
 FCB $D,$A,0,0,0,0
 FCC "YOU SURE? "
 FCB 4
*
NLDSTR FCC "NO LINES DELETED"
 FCB 4
*
BFRSTR FCC "BOTTOM OF FILE REACHED"
 FCB 4
**********************
* LIB CHANGE
 TTL CHANGE
 PAG
*
* PROGRAM : CHANGE.TXT
*
* CHANGE COMMAND ROUTINE
*
CHANGE JSR TSTEMP
 LDX BUFPNT POINT TO BUFFER
 JSR SKPCLS
 JSR TSTEND
 BEQ CHAN12 ERROR
CHANG1 TSTB
 BEQ CHAN15 ERROR
CHAN12 JMP CHANG9
CHAN15 INC CHGFLG SET FLAG
 JSR SETDEL SEET DELIMITERS
 CLRB CLEAR COUNT
CHANG2 LDAA 0,X GET CHARACTER
 JSR TSTEND
 BEQ CHANG3
 CMPA DELIM IS IT A DELIMITER
 BEQ CHANG3 YES - DONE
 INX
 INCB
 BRA CHANG2
CHANG3 STX CHGEND SAVE POINTER
 STAB STRCN2 SAVE COUNT
 JSR TSTEND
 BEQ CHAN35
 INX
CHAN35 STX BUFPNT SAVE POINTER
 LDX NEWPOS
CHAN37 INX GET PAST LINE NUMBER
 INX
 INX
 STX CHGPNT SAVE POINTER
 JSR SVSTPT SAVE STRING POINTER
 CLR CHGFLG
 JSR OCCURR GET TARGET AND OCCUR.
 INC CHGFLG
 JSR RSTSPT RESTORE STRING
 CLR PSTZFL
 LDX OCRCNT GET COUNT
 STX OCRTMP SAVE
 LDAA OCRFLG
 BEQ CHANG4
 LDAA STRCNT CHECK COUNT
 BNE CHANG4
 JMP CHANG9
CHANG4 LDX NEWPOS
 CPX TRGLIN AT TARGET?
 BNE CHANG5
 INC LSTFLG SET FLAG IF SO
CHANG5 JSR ZONE3 SET ZONE
 CLR CHGONF CLEAR FLAG
 LDX CHGPNT
 JSR FIXZON
 JSR FIND72
 BRA CHA510
*
* LOOP THROUGH OCCURRENCES
*
CHAN50 CLR CHGONF
CHAN51 LDX CHGPNT SET POINTER
 JSR FIXZON
 JSR CMPZN2 CHECK ZONE
 BHI CHANG8
 JSR FIND75
CHA510 LDAA NUMBER GET NUMBER
 STAA ZONBUF PUT IN BUFFER
 LDAA NUMBER+1
 STAA ZONBUF+1
 TSTB
 BNE CHANG8
 INCB BUMP COUNTER
 STAB FNONFL SET FLAG
CHAN52 LDAA OCRFLG ANY OCCUR.?
 BEQ CHANG6
 LDAA ALLFLG CHANGE ALL?
 BNE CHANG6
 JSR NXTOC0
CHAN55 LDX LASTNO SET POINTER
 INX
 STX CHGPNT
 BRA CHAN50
*
* DELETE STRING ONE
*
CHANG6 INC CHGONF SET FLAG
 LDX OCRTMP CHECK COUNT
 BEQ CHAN61
 LDAA #1
 STAA OCRFLG
CHAN61 STX OCRCNT FIX COUNT
 LDX LASTNO GET STRING LOCATION
 STX SPCPT1
 LDAB STRCNT
 BEQ CHAN66
 CLR CHRCNT CLEAR COUNT
 STAB CHRCNT+1
CHAN62 BEQ CHAN65
 INX BUMP POINTER
 DECB DECREMENT COUNT
 BRA CHAN62 REPEAT
CHAN65 STX SPCPT2 SAVE POINTER
 JSR DELCHR GO DELETE
*
* INSERT STRING TWO
*
CHAN66 LDAB STRCN2 GET COUNT
 BEQ CHA675
 CLR CHRCNT
 STAB CHRCNT+1 SET COUNTER
 LDX LASTNO SET POINTER
 STX SPCPT1
 JSR MAKSPC GO MAKE ROOM FOR IT
 LDAB CHRCNT+1
 LDX STRNGE POINT TO STRING END
CHAN67 INX BUMP IT
 LDAA 0,X GET CHARACTER
 STX TEMP
 LDX LASTNO
 STAA 0,X PUT CHARACTER
 INX
 STX LASTNO SAVE POINTER
 STX CHGPNT
 LDX TEMP
 DECB DECREMENT COUNTER
 BNE CHAN67
CHA675 LDAA ALLFLG DO ALL?
 BEQ CHAN81
 LDX LASTNO
 STX CHGPNT
 JMP CHAN51 REPEAT
*
* CHANGE CLEANUP AND FINISH
*
CHANG8 CLR OCRFLG CLEAR FLAG
 LDX OCRTMP GET COUNT
 BEQ CHAN80
 LDAA #1 SET FLAG
 STAA OCRFLG
CHAN80 STX OCRCNT SET OCCUR. COUNT
 LDAA FNONFL CHECK FLAG
 BNE CHAN81
 LDAA LSTFLG
 BNE CHANG9 ERROR
CHAN81 LDX NEWPOS
 LDAA CHGONF
 BEQ CHAN82
 JSR VERLIN VERIFY CHANGE
CHAN82 LDAA LSTFLG
 BEQ CHAN84
 CLR CHGONF CLEAR FLAG
 JMP PRINT6
CHAN84 JSR NXTLIN FIND NEXT LINE
 STX NEWPOS SAVE POINTER
 CPX TRGLIN TARGET LINE?
 BNE CHAN86 NO - GO AHEAD
 INC LSTFLG SET LAST FLAG
CHAN86 INX BUMP PAST LINE NUMBER
 INX
 INX
 STX CHGPNT SAVE POINTER
 JMP CHANG5 REPEAT
CHANG9 JMP ERROR
*
* SAVE STRING POINTER INFO
SVSTPT LDX STRNGB GET POINTER
 STX STRGB1 SAVE IT
 LDX STRNGE
 STX STRGE1
 LDAA STRCNT GET COUNT
 STAA STRCN1 SAVE IT
 RTS
*
* RESTORE STRING POINTER INFO
*
RSTSPT LDX STRGB1
 STX STRNGB
 LDX STRGE1
 STX STRNGE
 LDAA STRCN1
 STAA STRCNT
 RTS
*
***********************
* LIB OVERLAY
 TTL OVERLAY
 PAG
*
* PROGRAM : OVERLAY
*
OVERLA JSR TSTEMP
 LDAA #$20 SETUP SPACE
 STAA DELIM AS DELIMITER
 CLR DRCTN
 LDX BUFPNT SET POINTER TO BUFFER
 LDAA 0,X GET A CHARACTER
 CMPA #CRGRET
 BEQ OVRLA1
 JSR CLASS
 TSTB
 BEQ OVRLA0
 JMP SYNERR REPORT ERROR
OVRLA0 STAA DELIM SET DELIMITER
 INX
 LDAA 0,X
 CMPA #CRGRET
 BNE OVRL35
OVRLA1 CLR REPEAT DISABLE COMMAND REPEAT
 LDX NEWPOS SET POINTER
OVRL11 JSR OUTLIN OUPUT CURRENT LINE
 LDAA NUMFLG
 BNE OVRL12
 LDX #OVRLST+8 POINT TO STRING
 BRA OVRL16
OVRL12 LDX #OVRLST POINT TO STRING
OVRL16 JSR PSTRNG OUTPUT IT
 LDX #BUFFER POINT TO IN BUFFER
OVRLA2 JSR INCHAR GET A CHARACTER
 BEQ OVRLA1
 CMPA #CRGRET
 BEQ OVRLA3
 STAA 0,X
 JSR BUFLIM
 BRA OVRLA2
OVRLA3 STAA 0,X
 LDX #BUFFER
OVRL35 STX BUFPNT
 LDAB #CRGRET
 LDX NEWPOS POINT TO POSITION
 INX INCREMENT PAST LINE #
 INX
 INX
 STX TEMP
OVRLA4 LDX BUFPNT 
OVRL41 LDAA 0,X GET A CHARACTER
 INX
 STX BUFPNT
 CMPA #CRGRET
 BEQ OVRLA7
 LDX TEMP
 TST DRCTN
 BNE OVRL43
 CMPB 0,X
 BEQ OVRLA5
 CMPA DELIM IS IT DELIMITER?
 BEQ OVRL45 YES
OVRL43 STAA 0,X PUT CHARACTER
OVRL45 INX
 STX TEMP
 BRA OVRLA4
OVRLA5 LDAA DRCTN CHECK DIRECTION
 BNE OVRLA7
 CLRA  UN-NECCESSAY INSTRUCTION
 STAA CHRCNT CLEAR COUNTER
 LDX BUFPNT
OVRL55 INCA
 CMPB 0,X CHECK CHARACTER
 BEQ OVRLA6
 INX
 BRA OVRL55 REPEAT
OVRLA6 STAA CHRCNT+1 SAVE COUNT
 LDX TEMP
 STX SPCPT1 SET POINTER
 LDAA #1 SET DIRECTION
 STAA DRCTN
 JSR MAKSPC MAKE ROOM
 LDAB #CRGRET
 LDX BUFPNT GET POINTER
 DEX
 BRA OVRL41
OVRLA7 LDX NEWPOS GET POSITION
 JSR VERLIN VERIFY LINE
OVRLA8 JMP EDIT RETURN
*
OVRLST FCC / OVERLAY /
 FCB 4
**************************
*  LIB MOVE
 TTL MOVE
 PAG
*
* PROGRAM : MOVE
*
MOVE INC MOVFLG SET FLAG
 BSR COPY GO DO COPY
 LDAA CPYDRC WHICH DIRECTION
 STAA DRCTN
 LDX TRGLIN GET TARGET
 STX SPCPT2
 LDX NEWPOS GET POSITION
 STX SPCPT1
 LDX CURPOS GET CURRENT POSITION
 STX TRGLIN MAKE IT TARGET
 JSR DELCHR DELETE LINES
 LDX TRGLIN
 STX CURPOS FIX POSITION
 JMP PRINT6
**********************
* LIB COPY
 TTL COPY
 PAG
*
* PROGRAM : COPY
*
* COPY LINES COMMAND
*
COPY LDX BUFPNT POINT TO BUFFER
 INC NXTFLG SET FLAG
 INC LINFLG SET FLAG
 JSR FINDT FIND TARGET
 CPX FILEND
 BEQ COPY0
 CLR LINFLG
 CLR NXTFLG
 CPX FILBEG AT BEGINNING?
 BNE COPY02
 CPX NEWPOS
 BEQ COPY05
COPY02 LDAA DRCTN FIX DIRECTION
 STAA CPYDRC
COPY05 CLR DRCTN
 JSR TSTOVR LIMITS?
 BEQ COPY1
COPY0 JMP NOTFND REPORT ERROR
COPY1 JSR FNDCRT FIND NEXT C.R.
 INX BUMP POINTER ONE
 STX SPCPT1
 LDX BUFPNT
 JSR FINDT GO FIND TARGET
 JSR TSTOVR LIMITS?
 BNE COPY0
 TST DRCTN WHICH DIRECTION
 BNE COPY15
 LDX NEWPOS GET POINTER
 STX TEMP
 LDX TRGLIN
 BRA COPY18
COPY15 LDX TRGLIN GET TARGET LINE
 STX TEMP SAVE IT
 LDX NEWPOS
COPY18 JSR FNDCRT GET NEXT C.R.
 INX
 STX TRGLIN SET TARGET
 LDX TEMP
 STX NEWPOS
 CLRA
 CLRB
COPY2 INX
 INCA
 BNE COPY25
 INCB
COPY25 CPX TRGLIN FINISHED?
 BEQ COPY3
 CPX SPCPT1 OVERLAP?
 BNE COPY2
 LDX #OVLPST POINT TO STRING
 JSR PSTRNG
 CLR MSLFLG
 JMP EDIT
*
COPY3 STAA CHRCNT+1 SAVE COUNT
 STAB CHRCNT
 LDAA #1 SET DIRECTION
 STAA DRCTN
 JSR MAKSPC MAKE ROOM FOR LINES
 LDX SPCPT2
 STX CURPOS SET CURRENT POSITION
 LDX SPCPT1
 STX XSAVE
 LDX TRGLIN GET TARGET
 STX SPCPT1
 LDX NEWPOS
 STX TEMP SET POINTER
 JSR MAKS55 MOVE LINES
 LDX XSAVE RESTORE POINTER
 CLR OVRBEG
 JSR BAKONE MOVEE BAK ONE
 LDAA OVRBEG LIMIT?
 BEQ COPY5
 JSR CLRNUM CLEAR NUMBER
COPY4 INC CHKFLG SET FLAG
 JSR RENUM2 GO RENUMBER
 LDX CURPOS GET POSITION
 JSR BAKONE
 STX CURPOS SET CURRENT POSITION
 LDAA MOVFLG MOVE?
 BEQ COPY45
 RTS
COPY45 JMP PRINT6
COPY5 JSR GETNUM GET LINE NUMBER
 CLRA
 STAA NUMBER+2
 JSR UPONE
 BRA COPY4
*
OVLPST FCC /SOURCE OVERLAPS /
 FCC /DESTINATION/
 FCB 4
**********************
* LIB TABS
 TTL TABS
 PAG
*
* PROGRAM : TAB
*
* TAB SET COMMAND
*
TAB LDX #TABBUF SET POINTER
 STX TABPNT
TAB2 LDX BUFPNT POINT TO BUFFER
 JSR SKIPSP
 STX BUFPNT SAVE
 JSR TSTEND
 BEQ TAB6
 JSR CLASS CLASSIFY CHARACTER
 CMPB #1 IS IT A NUMBER?
 BEQ TAB4
 BHI TAB8
 INX
 STX BUFPNT BUMP POINTER
 BRA TAB2
TAB4 JSR BCDCON GET COLUMN
 STX BUFPNT
 CLRB
 JSR TSTNUM IS IT ZERO?
 BEQ TAB6
TAB5 INCB BUMP COUNT
 PSHB
 JSR DECNUM DECREMENT THE COUNT
 PULB
 BNE TAB5
 LDX TABPNT POINT TO TABS
 STAB 0,X SAVE COUNT
 INX
 STX TABPNT FIX TAB POINTER
 CPX #TABEND
 BEQ TAB6
 BRA TAB2
TAB6 CLRA
 LDX TABPNT
 STAA 0,X CLEAR TAB
 JMP NUMSE6
TAB8 JMP SYNERR REPORT ERROR
*
************************
* LIB HEADER
 TTL HEADER
 PAG
*
* PROGRAM : HEADER
*
* PRINT HEADER COMMAND
*
HEADER LDX #TABBUF SET POINTER
 STX TABPNT
 LDX BUFPNT
 JSR SKIPSP SKIP ALL SPACES
 JSR TSTEND
 BEQ HEAD42
HEADE2 JSR CLASS CLASSIFY CHARACTER
 CMPB #1 IS IT A NUMBER
 BNE TAB8 ERROR
 JSR BCDCON GET NUMBER COUNT
 STX BUFPNT
 JSR TSTNUM IS IT ZERO?
 BEQ HEADE7
 CLRB
HEADE3 INCB BUMP COUNTER
 PSHB
 JSR DECNUM DECREMENT NUMBER
 PULB
 BNE HEADE3
HEADE4 STAB HEDCNT SAVE COUNT
HEAD42 JSR CLRNUM CLEAR NUMBER
 JSR PCRLF OUTPUT C.R./L.F.
 LDAA NUMFLG LINE NUMBERS ON?
 BEQ HEADE5
 LDAB #8 SET COUNT
HEAD45 JSR OUTSPC OUTPUT A SPACE
 DECB
 BNE HEAD45
HEADE5 JSR OUTSPC
 CLRB CLEAR COUNT
HEAD55 PSHB
 JSR INCNUM BUMP NUMBER
 PULB
 INCB
 LDX TABPNT GET TAB COLUMN
 CMPB 0,X THERE?
 BNE HEAD57
 LDAA #'-
 JSR OUTCH
 INX
 STX TABPNT
 BRA HEAD58
HEAD57 LDAA NUMBER+1 GET NUMBER
 JSR OUTHR OUTPUT IT
HEAD58 CMPB HEDCNT
 BNE HEAD55 REPEAT UNTIL DONE
HEADE7 JMP NUMSE6
*
************************
* LIB ZONE
 TTL ZONE
 PAG
*
* PROGRAM : ZONE
*
* SET UP ZONE COLUMN COMMAND
*
SZONE LDX BUFPNT POINT TO BUFFER
 JSR SKIPSP
 JSR TSTEND
 BEQ SZONE2
 JSR CLASS
 CMPB #1 IS IT A NUMBER?
 BEQ SZONE3
 BHI SZONE8
 INX
SZONE2 STX BUFPNT SAVE POINTER
 LDX #$0001 SET COLUMN 1
 BRA SZONE4
SZONE3 JSR BCDCON GET NUMBER
 STX BUFPNT
 LDX NUMBER
SZONE4 STX ZONE1 FIX ZONE ONE
 LDX BUFPNT
SZONE5 JSR SKIPSP SKIP ALL SPACES
 JSR TSTEND
 BEQ SZONE6
 JSR CLASS CLASSIFY CHARACTER
 CMPB #1 IS IT A NUMBER?
 BEQ SZONE7
 BHI SZONE8 ERROR
 INX
 BRA SZONE5
SZONE6 LDX #$0136 SET COLUMN 136
 BRA SZON75
SZONE7 JSR BCDCON GET NUMBER
 STX BUFPNT SAVE POINTER
 LDX NUMBER
SZON75 STX ZONE2
 JMP NUMSE6
SZONE8 JMP ERROR REPORT ERROR
*
**********************
* LIB SETSPCL
 TTL SETSPCL
 PAG
*
* PROGRAM : SETSPCL
*
* SET SPECIAL CHARACTERS COMMAND
*
SET LDX BUFPNT SET POINTER
 JSR SKIPSP
 STX BUFPNT
 STX TEMP SAVE POINTER
 LDX #CHRTBL POINT TO TABLE
 JMP EDIT6
*
* SET SPECIALS HERE
*
****** TAB *****
*
STAB LDX #TABCH POINT TO TAB CHRACTER
 BRA SETC
*
****** FILL ****
*
SFILL LDX #FILL POINT TO FILL
 BRA SETC
*
****** EOL *****
*
SEOL LDX #EOL POINT TO EOL CHARACTER
 BRA SETC
*
****** DCC *****
*
SDCC LDX #DCC POINT TO DCC
 BRA SETC
*
****** LINO ****
*
SLINO LDX #LINO POINT TO IT
*
* SET THE CHARACTER
*
SETC STX TEMP SAVE POINTER
 LDX BUFPNT GO TO BUFFER
 JSR SKIPSP
 CMPA #'= IS IT "="
 BNE SETC8 NO - ERROR
 BSR CHFRQU
 BNE SETC8 ERROR
 BSR CHFRQU
 BNE SETC2
 CLRA
 PSHA SAVE NULL CHARACTER
 BRA SETC4
SETC2 JSR CLASS CLASSIFY CHARACTER
 TSTB
 BNE SETC8 ERROR
 CMPA #CRGRET
 BEQ SETC8 ERROR
 PSHA
 BSR CHFRQU CHECK FOR QUOTE
 BNE SETC8 ERROR
SETC4 INX
 STX BUFPNT SAVE POSITION
 JSR TFORCR TEST FOR C.R.
 PULA GET CHARACTER
 LDX TEMP RESTORE POINTER
 CPX #FILL IS IT A FILL CHARACTER?
 BNE SETC5 NO
 TSTA
 BNE SETC6
 LDAA #'  SPACE
 BRA SETC6
SETC5 CPX #LINO IS IT LINO
 BNE SETC6 NO
 TSTA
 BNE SETC6
 LDAA #'# SET IT
SETC6 STAA 0,X
 JMP NUMSE6 RETURN
SETC8 JMP SYNERR REPORT SYNTAX ERROR
*
* CHECK FOR QUOTE
*
CHFRQU INX BUMP POINTER
 JSR SKIPSP SKIP SPACES
 CMPA #''
 RTS
*
* SPECIAL CHARACTER TABLE
*
CHRTBL FCC "TAB"
 FCB 0
 FDB STAB
 FCC "FILL"
 FCB 0
 FDB SFILL
 FCC "EOL"
 FCB 0
 FDB SEOL
 FCC "LINO"
 FCB 0
 FDB SLINO
 FCC "DCC"
 FCB 0
 FDB SDCC
 FCB 0
*
**********************
* LIB EXPAND
 TTL EXPAND
 PAG
*
* PROGRAM : EXPAND
*
* EXPAND TABS COMMAND
*
EXPAND JSR TSTEMP
 LDX BUFPNT GET POINTER
 JSR FINDT FIND TARGET
 LDX NEWPOS SAVE IT
 LDAA #1
 STAA PRNFLG SET FLAG
EXPAN1 STX CURPOS SET CURRENT POSITION
 CPX TRGLIN LAST LINE?
 BNE EXPAN2
 CLR PRNFLG CLEAR FLAG
EXPAN2 BSR EXPLIN GO DO LINE
 LDAA PRNFLG DONE?
 BEQ EXPAN5
 LDX NEWPOS GET POINTER
 JSR NXTLIN FIND NEXT LINE
 STX NEWPOS SAVE POINTER
 BRA EXPAN1
EXPAN5 JMP PRINT6
*
* EXPAND TABS IN ONE LINE
*
EXPLIN LDAA TABCH GET TAB CHARACTER
 CMPA FILL DOES FILL = TAB?
 BEQ EXPLI7 YES - RETURN
 LDX #TABBUF POINT TO TABS
 STX TABPNT SAVE POINTER
 LDAB 0,X GET FIRST TAB POS
 BEQ EXPLI7 NO TABS SET
 CLRB CLEAR COUNT
 STAB CHRCNT
 LDX NEWPOS GET LINE POINTER
 CPX FILEND ARE WE DONE?
 BNE EXPLI1 NO - CONTINUE
 JMP EDIT YES - BACK TO MAIN LOOP
EXPLI1 INX INCR PAST LINE NUMBER
 INX
 INX
EXPLI2 INCB BUMP COUNTER
 LDAA 0,X GET CHARACTER
 CMPA #CRGRET IS IT C.R.
 BEQ EXPLI7 YES - DONE
 CMPA TABCH IS IT A TAB CHARACTER?
 BEQ EXPLI3 YES - EXPAND
 INX BUMP POINTER
 BRA EXPLI2 LOOP UNTIL DONE
EXPLI3 STX TEMP SAVE POSITION
 LDX TABPNT
EXPL35 CMPB 0,X AT A TAB POSITION?
 BCC EXPLI6 YES
 LDAA #$FF SET COUNT
EXPLI4 INCA
 INCB
 CMPB 0,X TAB COL YET?
 BNE EXPLI4 GET TO TAB POS
 STAA CHRCNT+1 SAVE COUNT
 LDX TEMP
 STX SPCPT1 SET SPACE POINTER
 JSR MAKSPC GO MAKE SOME ROOM
 LDAB CHRCNT+1
 INCB
 LDAA FILL GET FILL CHARACTER
EXPLI5 STAA 0,X PUT IN LINE
 INX
 DECB DECREMENT COUNT
 BNE EXPLI5 LOOP TILL COUNT = 0
 BRA EXPLIN REPEAT
EXPLI6 INX BUMP POINTER
 LDAA 0,X ALREADY AT TAB POS
 BNE EXPL35
EXPLI7 RTS RETURN
***************************
* LIB APPEND
 TTL APPEND
 PAG
*
* PROGRAM : APPEND
*
* APPEND COMMAND
*
APPEND JSR TSTEMP
 LDX BUFPNT GET POINTER
 JSR SKIPSP
 JSR TSTEND ALL?
 BNE APPEN1
APPEN0 JMP SYNERR
APPEN1 JSR CLASS GO CLASSIFY CHARACTER
 TSTB
 BNE APPEN0
 JSR SETDEL SET DELIMITERS
 JSR CLASS CLASSIFY CHARACTER
 CMPB #1 IS IT A NUMBER
 BNE APPEN3
 JSR BCDCON GET COL. NUMBER
 JSR TSTNUM IS IT ZERO
 BEQ APPEN3
 CLRA
APPEN2 INCA BUMP COUNTER
 PSHA
 JSR DECNUM DECREMENT NUMBER
 PULA
 BNE APPEN2
 STAA APPCOL SAVE COUNT
APPEN3 JSR SVSTPT SAVE DELIMITER INFO
 LDX BUFPNT GET POINTER
 JSR FINDT FIND TARGET
 JSR RSTSPT RESTORE DELIM INFO
 CLR CHRCNT
 INC PRNFLG SET FLAG
 LDX NEWPOS SET POINTER
APPE35 CPX TRGLIN AT TARGET?
 BNE APPEN4
 CLR PRNFLG CLEAR FLAG
APPEN4 INX BUMP PAST LINE NUMBER
 INX
 INX
 LDAA APPCOL GET COLUMN NUMBER
 BNE APPEN5
 DEX
 JSR FNDCRT GET TO C.R.
 BRA APPEN7
APPEN5 TAB
APPE53 DECB
 BEQ APPE65 COUNT = 0
 LDAA 0,X CHECK CHARACTER
 CMPA #CRGRET IS IT C.R.?
 BEQ APPEN6 YES
 INX
 BRA APPE53 LOOP
APPEN6 STX SPCPT1 SET POSITION
 STAB CHRCNT+1
 PSHB
 JSR MAKSPC MAKE MORE ROOM
 PULB
 LDAA #$20 SPACE
APPE63 STAA 0,X PUT IN LINE
 INX
 DECB
 BNE APPE63
 BRA APPEN7
APPE65 STX SPCPT1 SET POSITION
 STX TEMP
APPE66 LDAA 0,X GET CHARACTER
 CMPA #CRGRET IS IT C.R.?
 BEQ APPE67 YES -
 INX
 INCB
 BRA APPE66
APPE67 STAB CHRCNT+1
 STX SPCPT2
 JSR DELCHR DELETE REST OF LINE
 LDX TEMP GET POINTER
APPEN7 STX SPCPT1
 LDAA STRCNT GET COUNT
 BEQ APPE78 COUNT = 0
APPE72 STAA CHRCNT+1
 JSR MAKSPC MAKE SOME ROOM
 LDX STRNGE POINT TO STRING
 STX SPCPT1
 LDX STRNGB
 STX TEMP SET END
 JSR MAKS55 PUT IN STRING
 LDX SPCPT2 GET POINTER
APPE78 CLRB
 JSR BAKON2
 JSR VERLIN VERIFY LINE
 LDAA PRNFLG DONE?
 BEQ APPEN8 YES - EXIT
 JSR NXTLIN FIND NEXT LINE
 STX NEWPOS
 BRA APPE35 REPEAT
APPEN8 STX CURPOS
APPEN9 JMP PRINT6
*
********************
* LIB SAVE
 TTL SAVE
 PAG
*
* PROGRAM : SAVE
*
* SAVE CURRENT FILE ON TAPE
*
SAVE JSR TFORCR
 LDX FILBEG SET POINTER
 STX SPCPT1
 LDX FILEND
 STX SPCPT2 SET END
 BSR RECORD GO RECORD IT
SAVE4 JMP NUMSE6
*
* WRITE PART OF FILE TO TAPE
*
WRITE JSR TSTEMP
 LDX BUFPNT SET POINTER
 JSR FINDT FIND TARGET
 LDAA DRCTN CHECK DIRECTION
 BNE WRITE2
 JSR FNDCRT
 INX
 STX SPCPT2 SET POINTER
 LDX NEWPOS
 STX SPCPT1 SET BEGINNIG
 BRA WRITE4
WRITE2 STX SPCPT1
 LDX NEWPOS
 JSR FNDCRT
 INX
 STX SPCPT2 SET END
WRITE4 BSR RECORD GO RECORD IT
WRITE5 BRA SAVE4
*
* RECORD RECORD
*
RECORD LDAA #2 SET CODE
 JSR TORDSK TAPE OR DISK?
 BEQ RECOR1
 LDAA RONCH READER ON
 JSR TOUCH
 BSR TDELAY
RECOR1 LDX SPCPT1 GET POINTER
RECOR2 CPX SPCPT2 FINISHED?
 BEQ RECOR4
 INX BUMP PAST LINE NUMBER
 INX
 INX
RECO25 LDAA 0,X GET CHARACTER
 CMPA #$0D IS IT A C.R.?
 BEQ RECOR3 YES -
 BSR SOUCH OUTPUT CHARACTER
 INX BUMP POINTER
 BRA RECO25
RECOR3 BSR SOUCH OUTPUT CHARACTER
 INX
 BRA RECOR2 REPEAT
RECOR4 LDAA DSKFLG CHECK MODE
 BEQ RECO45 TAPE MODE
 JMP CLSFCB CLOSE THE FILE
RECO45 LDAA #$1A SET EOF CHARACTER
 JSR TOUCH OUTPUT EOF
RECOR5 LDX #$FFFF SET DELAY COUNT
RECOR6 DEX WASTE SOME TIME
 BNE RECOR6 UNTIL X = 0
RECOR7 LDAA ROFCH TURN OFF TAPE
 JSR TOUCH
*
* DELAY FOR TAPE
*
TDELAY LDAA DELAY GET DELAY
DELAY1 BEQ DELAY4 NO DELAY - EXIT
 LDX #$FFFF SET DELAY FACTOR
DELAY2 DEX
 BNE DELAY2
 DECA
 BRA DELAY1
DELAY4 RTS
*
* PUT A GAP ON THE TAPE (40 NULLS)
*
GAP JSR TFORCR CHECK END
 LDAA RONCH GET A CHARACTER
 JSR TOUCH
 BSR TDELAY
 LDAB #40 SET COUNT
GAP2 CLRA SET NULL CHARACTER
 JSR TOUCH OUTPUT IT
 DECB
 BNE GAP2
 BSR RECOR7 FINISH UP
 JMP WRITE5
*
* SPECIAL OUTPUT ROUTINE
*
SOUCH TST DSKFLG DISK OPERATION?
 BEQ SOUCH6 NO - TAPE.
 STX INDEX9 SAVE X REG
 TST DRWFLG READ OR WRITE?
 BEQ SOUCH2 WRITE
 LDX #FCB
 BRA SOUCH3
SOUCH2 LDX #WFCB
SOUCH3 JSR FMS DO DISK IO
 BEQ SOUCH8 NO ERRORS
SOUCH4 JSR RPTERR REPORT ERROR
 LDX INDEX9 RESTORE X REG
 TST DRWFLG
 BNE SOUCH5 READ - RENTER EDIT
 JSR FMSCLS CLOSE FILE
 JMP WARMS EXIT EDITOR
SOUCH5 BSR CLSFCB CLOSE FILE
 JMP EDIT GO TO EDITOR
SOUCH6 JMP TOUCH
SOUCH8 LDX INDEX9 RESTORE X REG
 RTS RETURN
*
* CLOSE FILE ON DISK
*
CLSFCB STX INDEX9
 LDAA DRWFLG TEST RD/WR FLAG
 BEQ CLSFC2
 CLR DRWFLG CLEAR FLAGS
 CLR DSKFLG
 LDX #FCB SET POINTER
CLSFC1 LDAA #4 SET FOR CLOSE
 STAA 0,X SET IN FCB
 JSR FMS CALL FILE MANAGER
 BEQ CLSFC2 ALL IS OK
 JSR RPTERR REPORT ERROR
CLSFC2 LDX INDEX9 RESTORE INDEX
 RTS RETURN
*
***********************
* LIB TAPEDISK
 TTL TAPEDISK
 PAG
*
* PROGRAM : TAPEDISK
*
* ASK IF TAPE OR DISK
*
TORDSK CLR DSKFLG CLEAR FLAGS
 CLR DRWFLG
 STAA ACCT SAVE ACTION
 LDX #TDST POINT TO STRING
 JSR PSTRNG PRINT IT
 JSR GETCHR GET RESPONSE
 CMPA #$5F CHECK LOWER CASE
 BLS TORDS2
 SUBA #$20 BIAS FOR UPPER CASE
TORDS2 CMPA #'D IS IT "DISK"?
 BNE TORDS4 NO -
 LDX DBFPNT GET POINTER
 STX SAVEIT SAVE POINTER
 LDAA LSTTRM GET TERMINATOR
 STAA TTERM SAVE TERMINATOR
TORDS3 LDX #NMST POINT TO "NAME" STRING
 JSR PSTRNG PRINT IT
 LDX #BUFFER POINT TO DOS BUFFER
 STX DBFPNT TELL DOS
TORD32 JSR INCHAR GET NAME
 BEQ TORDS3 DELETE?
 STAA 0,X PUT CHARACTER
 INX BUMP POINTER
 CMPA #$D IS IT C.R.?
 BNE TORD32 NO -
 LDX #FCB
 JSR GETFIL GET FILE NAME TO FCB
 BCC TORD35 NO ERROR
 BSR RESTBF RESTORE BUFFER
 LDX #ILST POINT TO "ILLEGAL" STRING
TORD33 JSR PSTRNG OUTPUT IT
 BRA TORDS6
TORD35 BSR RESTBF RESTORE BUFFER
 LDAA #1
 STAA DSKFLG
 STAA DRWFLG SET FLAGS
 LDX #FCB
 JSR SETEXT SET DEFAULT = TXT
 LDX #FCB
 LDAA ACCT GET ACTION
 STAA 0,X SET IN FCB
 JSR FMS
 BEQ TORDS4 NO ERRORS
 LDAA 1,X GET ERROR CODE
 CMPA #NFER NO FILE?
 BEQ TORD37 THAT'S RIGHT - CREATE IT
 CMPA #FEER FILE ALREADY EXISTS?
 BNE TORDS5
 LDX #FEST "FILE EXISTS" STRING
 BRA TORD33
TORD37 LDX #NFST
 BRA TORD33
TORDS4 RTS RETURN
TORDS5 JSR RPTERR REPORT ERROR
TORDS6 CLRA
 STAA DSKFLG
 STAA DRWFLG CLEAR FLAGS
 JMP EDIT
*
TDST FCC /TAPE OR DISK (T-D)? /
 FCB 4
*
* RESTORE BUFFER
*
RESTBF LDX SAVEIT GET POINTER
 STX DBFPNT
 LDAA TTERM
 STAA LSTTRM
 RTS
*
*********************
* LIB READ
 TTL READ
 PAG
*
* PROGRAM : READ
*
* READ NEW TEXT FROM DISK
*
* READ OVERFLOW
*
ROVER STX INDEX9 SAVE X
 LDAA DSKFLG CHECK DISK IO
 BEQ ROVER2
 LDAA DRWFLG
 BEQ ROVER4
ROVER2 LDX #NORMST NO ROOM MESSAGE
 JSR PSTRNG PRINT STRING
ROVER4 LDX INDEX9
 BRA READ5 JUMP AHEAD
*
* READ ROUTINE
*
READ JSR TFORCR CHECK END
 LDAA #1 SET CODE
 JSR TORDSK TAPE OR DISK?
 BEQ READ1
 NOP
 SEI
 LDAA TONCH TAPE ON
 JSR TOUCH
 JSR TDELAY DELAY FOR SPEED
READ1 JSR CLRNUM CLEAR NUMBER
 LDX FILEND GET END POINTER
 STX TEMP SAVE VALUE
 CPX FILBEG EMPTY FILE?
 BEQ READ2 YES
 JSR BAKONE NO - MOVE BACK ONE
 JSR GETNUM GET NUMBER
 LDX FILEND GET POINTER
READ2 STX INDEX9 SAVE POINTER
 LDAA INDEX9
 TST DRWFLG READ OR WRITE?
 BNE READ25 
 CMPA BUFEND
 BHS ROVER OVER END?
 BRA READ27
*
READ25 CMPA RBFEND
 BHS ROVER
READ27 CLR 0,X CLEAR LINE NUMBER
 INX
 CLR 0,X
 INX
 CLR 0,X
 INX
READ3 JSR SINCH GO GET CHARACTER
 CMPA #$D IS IT A C.R.?
 BEQ READ4 YES -
 CMPA #$1A IS IT EOF?
 BNE READ35
 TST DSKFLG DISK OR TAPE?
 BEQ READ5
 TST DRWFLG READ OR WRITE?
 BNE READ5
 STAA LASTIN SET LAST CHAR READ
 BRA READ5
READ35 CMPA #$1F CONTROL CHARACTER?
 BLS READ3 YES
 STAA 0,X PUT CHARACTER IN LINE
 INX
 BRA READ3 REPEAT
READ4 STAA 0,X
 INX
 BRA READ2
READ5 CLRB
 JSR BAKON2 MOVE BACK
READ6 STX FILEND SET END OF FILE PTR
 INC CHKFLG SET FLAG
 TST DSKFLG DISK OR TAPE?
 BEQ READ65
 JSR CLSFCB CLOSE FILE
 BRA READ7
READ65 LDAA TOFCH TAPE OFF CHARACTER
 JSR TOUCH
 NOP
 CLI
READ7 CPX TEMP CHECK POINTER
 BEQ READ8
 LDX TEMP GET POINTER
 JSR RENUM2
READ8 TST DSKFLG DISK I/O?
 BEQ READ9
 RTS RETURN
READ9 JMP BOTTO1 RETURN
*
* SPECIAL INPUT
*
SINCH TST DSKFLG DISK I/O?
 BNE SINCH2
 JMP TINCH TAPE INPUT
SINCH2 STX INDEX9 SAVE X REG
 TST DRWFLG CHECK FLAG
 BEQ SINCH4
 LDX #FCB SET POINTER
 BRA SINCH5
SINCH4 LDX #RFCB SET FOR READ
SINCH5 JSR FMS
 BEQ SINCH7
 LDAA 1,X CHECK ERROR INDICATOR
 CMPA #8 EOF?
 BEQ SINCH6
 JMP SOUCH4
SINCH6 LDAA #$1A SET EOF FLAG
SINCH7 JMP SOUCH8 FINISH UP
*
* NEW COMMAND
*
NEW JSR TFORCR
 LDX FILBEG GET POINTER
 STX SPCPT1 SAVE IT
 LDX CURPOS GET CURRENT POSITION
 STX SPCPT2 SAVE IT
 INC DSKFLG SET FLAG
 JSR RECOR1 GO WRITE
 CLR DSKFLG CLEAR FLAG
 LDX FILBEG POINT TO BEGINNING
 STX CURPOS SET NEW CURRENT POS
 BSR RNEW GO READ NEW
 JMP PEDIT RETURN
*
* READ NEW TEXT FROM DISK
*
RNEW LDX SPCPT2 GET POINTER
 LDAA #1 SET FLAG
 STAA DSKFLG
 CLRA
 CLRB
RNEW2 CPX SPCPT1 CHECK LIMIT
 BEQ RNEW4
 INCA BUMP COUNT
 BNE RNEW3
 INCB
RNEW3 DEX DECREMENT THE POINTER
 BRA RNEW2 REPEAT
RNEW4 STAA CHRCNT+1
 STAB CHRCNT
 JSR DELCHR DELETE BLOCK
 LDAA LASTIN FINISHED?
 BNE RNEW5
 LDAA FILEND GET POINTER
 CMPA BUFEND CHECK END.
 BHS RNEW5 END OF BUFFER?
 JSR READ1 GO READ IN
RNEW5 CLR DSKFLG CLEAR FLAG
 RTS RETURN
*
**************************
* LIB STRINGS
 TTL STRINGS
 PAG
*
* PROGRAM : STRINGS
*
* STRINGS
*
ILST FCC /ILLEGAL FILE NAME/
 FCB 4
FEST FCC /FILE EXISTS/
 FCB 4
DLST FCC /DELETE BACKUP FILE (Y-N)? /
 FCB 4
NMST FCC /FILE NAME? /
 FCB 4
NFST FCC /NO SUCH FILE/
 FCB 4
LSST FCC /WARNING: LOW DISK SPACE!/
 FCB 4
*
RFCB RMB 320
WFCB RMB 321
*
BEGPNT EQU *
*
**********************
* 
     END START