 
*  ED1/EDIT2                  Apr / 01 / 95
 
*  FlashCursor, ScanKy
*  MargChk, Honk, Hibit, Mark,AutoIns, BumpCsr
*  Lmode, Window
*  SaveWS, RestWS
*  FindStr, RepStr
*-----------------------------------
*  Command, Comsta, ComdExit, Errors
*  DelLines, LineNums
*  L/S module callers
*  Markers, Lin#Mark, TabSets
*  STbuf, RCbuf
*----------------------------------
*  DISPLY, ErrHandl
*  VDP R/W/Reg, ToglN/P, TogIL
*  Num, ParsNums, GSlash, CmdLinChk, RestLA, ClrCmd
*  LfAr,RgAr,Dn/UpCase
*  TAB keys, EoFLine
*--------------------------------------------------
 
*  Cursor flash routine
*---------------------------------
*  Enter with  R9 = screen pointer
*              R0 = <cursor,char>
*  Destroys    R8,R9
 
FLACSR EQU  $
CLRFLA CLR  R8                Clear counter for cursor flash
CLRTIM MOVB R8,@TIMER         Clear the timer from MSB
CHKTIM CB   @TIMER,@B06       Has timer reached 1/10th sec.?
       JL   SCANIT            No, so go scan keyboard
       INC  @DELAY            Inc DELAY ctr every 1/10th sec
       INC  R8                Inc FLASH ctr every 1/10th sec
       C    R8,@FLRATE        Is it time to flash cursor?
       JL   CLRTIM            No, so clear the timer
 
*  Flash cursor
 
       BLWP @SETVDW           R9 = cursor vdp address
       MOVB R0,@VDPWD         Write to screen
       SWPB R0                Swap cursor and chr
       JMP  CLRFLA            Go clear flash counter
 
*  Check keyboard
 
SCANIT BLWP @SCANKY           Check keyboard
       SZCB @ANTI20,@GPLST    Isolate GPL cond'n bit
       JNE  NEWKEY            Yes, it was set
       CB   @KEYRT,@BFF       Is any key down?
       JEQ  CHKTIM            No, so loop
CHKDEL C    @DELAY,@TENS      Has delay reached 1 second?
       JL   CHKTIM            No, so loop
       JMP  PRCKEY            Go process key
 
NEWKEY CLR  @DELAY            Clear the 1 sec delay counter
PRCKEY ABS  @UPCASE           Check if UPcase ordered
       JEQ  CNVL20            All cases allowed
 
*  Check for lower case
 
CNVLC  LI   R8,KEYRT          Do it for key return
CNVLC8 CB   *R8,@LCA          Below "a" ?
       JL   CNVL20            Yes
       CB   *R8,@LCZ          Above "z" ?
       JH   CNVL20            Yes
       SB   @DSPACE,*R8       Convert to UC
CNVL20 RT
 
*  Scan keyboard as BLWP routine
*-------------------------------
 
SCANKY DATA BUFMWS,SCAN10
 
SCAN10 LWPI GPLWS             Must be in GPL workspace
       ABS  @NOINTR           Set by auto wordwrap ?
       JNE  SCAN20            Yup - skip interrupts this once
       LIMI 2                 Give the timer a chance to INC
WTWO   EQU  $-2               Cheap data equates
TWO    EQU  $-1
READ   EQU  $-1
       LIMI 0                 That's enough chance
SCAN20 CLR  @NOINTR           Make sure it is cleared
       BL   @>000E            Console keyboard scan
       LWPI BUFMWS            Restore WSP for return
       RTWP
 
*  Margin checker / Delay / Sound
*--------------------------------
 
MRCHEK EQU  $
       STWP R0                R0 constrained for delay-only path
       MOVB @KEYRT,R10        Copy key return
       JLT  DELXX             <ctrl> key
       CB   @DSPACE,R10       Below blank ?
       JH   DELXX             Must be <fctn> key
       MOV  @RMRG,R10         Copy right margin
       S    R2,R10            Compare current Cursor
       JEQ  MEXIT             On margin - no delay & don't bug sound
       C    @RMGIN,R10        At inset ?    >FFD8
       JNE  DELXX             No bell then - delay only
 
*  Sound or delay
*----------------
 
MBEEP  LI   R8,MBSDAT         Margin bell sound list
SNDENT LI   R0,SOUND          Sound chip
       MOVB *R8+,*R0          First byte
       NOP                    WASTE time
       MOVB *R8+,*R0          Second byte
       NOP                    WASTE time
       MOVB *R8,*R0           Third byte
DELXX  LI   R10,>1200         Time delay / Sound duration
DELVAL EQU  $-2               Written in from FW
DELYY  DECT R10               Count down
       JGT  DELYY             More to go
       MOVB @SNDATA+3,*R0     Voice #1 terminator for all
MEXIT  RT
 
*  Make unpleasant warning noise
 
HONK   LI   R8,SNDATA         Honk data
       JMP  SNDENT
 
*  High-bit toggle - use CMARKR as flag
*--------------------------------------
 
HIBIT  EQU  $
       AB   @H80,@CMARKR      High bit mask
       JMP  MBEEP             Audible
 
*  Line marker fctn-;
 
MARKIT EQU  $
       MOV  R1,@MKTBL         Save current line pointer
       JMP  MBEEP             Audible recognition
 
*  Auto insert routine used by wordwrap
*--------------------------------------
 
AUTOIN EQU  $
       MOV  R11,@AUTXIT+2     Save return address
       MOV  @CMDRT,R11        Illegal in command mode
       JNE  AUTXIT            Quit while ahead
       SETO @CRFLAG           Turn flag on
       CLR  @TOPPAR           No longer at top of paragraph
       MOV  R4,R8             Copy cursor buffer pointer
       CB   @KEYRT,@DSPACE    Was it a space
       JEQ  AUTO15            Yes - no wrap needed
       CLR  R6                Word wrap length
       DEC  R8                Don't count this character.
       MOV  @RMRG,R14         Right margin
       S    @LMRG,R14         Constructs current line length
AUTO05 CB   *R8,@DSPACE       Find last blank
       JEQ  AUTO20            Found it
       INC  R6                Count character
       C    R6,R14            Out of Range?
       JHE  AUTO15            Yes, don't wrap
       DEC  R8                Back up to next char
       JMP  AUTO05            Look for next blank
 
AUTO15 CLR  R2                Can't wrap word, home cursor
       MOVB R5,*R4
       BL   @UPDATE           Update this line
       BL   @INSL50           Insert blank line below
       BL   @SCROLL           Scroll up
       JMP  AUTXIS
 
AUTO20 LI   R9,TEMPM6         Use temp line buffer
       A    @LMRG,R9          Adjust wrap for left margin
       INC  R8                Skip blank
       MOV  R8,R11            R8=Addr of word to wrap
       MOV  R6,R10            R6=Length of word to wrap
       JEQ  AUTO35
AUTO30 MOVB *R8+,*R9+         Wrap word to next line
       DEC  R6
       JGT  AUTO30
AUTO35 MOVB R5,*R9            Output this character
       INC  R10
AUTO40 MOVB @DSPACE,*R11+     R11 -> Addr of wrapped word
       DEC  R10               Blank out rest of current line
       JGT  AUTO40
       S    @TADR,R9          Calculate new cursor position
DSIX   EQU  $+2               Cheap data
       AI   R9,6              Allow for line numbers
       MOV  R9,R2             Update Cursor
       BL   @BUMPC            Bump cursor
AUTO50 SETO @NCHAR            Enter routine comes here
       BL   @UPDATE           Line to buffer
 
*  Entry from EnterKey
 
AUTO60 INC  R1                Cline
       BL   @INSLIN           Insert line (Tempbf)
       MOV  @LINADR,R4        Update Buffer pointer
       A    R2,R4             Add Cursor
       AI   R4,86             Adjust Curadr
       BL   @SCRL03           Adjust screen pointers
AUTXIS SETO @NOINTR           Cancel interrupt on next scan
AUTXIT B    @>0               Exit
 
*  Main cursor positioning routine
*---------------------------------
*  CURSOR == R2
 
BUMPC  EQU  $                 Finds window for current cursor
       ABS  @GOLF             Margin release set ?
       JEQ  BUMP00            No
       LI   R8,FORMO          Point to current margins
       C    R2,*R8            Cursor to left
       JLE  BUMP00            No - not yet
       C    R2,@2(R8)         Too far right then
       JHE  BUMP00            Not yet
       MOV  *R8+,@LMRG        Restore working LMRG
       MOV  *R8,@RMRG         And RMRG from table also
       CLR  @GOLF             Reset margin release flag
 
*  Continue after margin release check
 
BUMP00 C    R2,@LMRG          Where is cursor ?
       JLT  BUMP07            To left
       C    R2,@RMRG          Cursor ?
       JGT  BUMP09            Not to the right
BUMP05 C    R2,*R7            On this screen ?
       JLT  BUMP01            Definitely no
       C    R2,@2(R7)         Maybe ?
       JLE  BUMP10            Yes
BUMP01 LI   R7,WTOP           Start of table then
BUMP06 C    R2,@2(R7)         Check Cursor
       JLE  BUMP10            In first window
       C    *R7+,*R7+         Cheap +4 to next
       MOV  *R7,*R7           Check terminator
       JLT  BUMP01            Yes - restart
       JMP  BUMP06            Check again
 
BUMP07 MOV  @LMRG,R2          Force back to left margin
       JMP  BUMP05
BUMP09 MOV  @RMRG,R2          Force back to right margin
       JMP  BUMP05
 
BUMP10 MOV  R2,R4             Calculate cursor address
       A    @LINADR,R4
       RT
 
*  Horizontal window control
*---------------------------
*  Line & Mode switch
 
LMODE  EQU  $
       ABS  @LINF             Toggle line mode switch
       DEC  @LINF
WINDOW EQU  $
       LI   R8,WNLIN          Line number mode table
       ABS  @LINF             Line number mode?
       JEQ  WIND05            Yes
WINCMD LI   R8,WLIN           Other table
WIND05 LI   R7,WTOP           Top of window table
WIND10 LI   R9,3              3 table entries, each 4 bytes
WIND20 MOVB *R8+,@1(R7)       Put column # in right byte
       MOV  *R7+,*R7          Put column # in column end
       A    @SWIDTH,*R7+      Adjust for end of window
       DEC  R9
       JGT  WIND20
       SETO *R7               Set end of table flag
       LI   R7,WTOP           Restore pointer
       RT
 
*  Save/restore registers 1-7
*----------------------------
 
SAVEWS EQU  $
       LI   R8,SREGS          Storage pointer
SAVW10 LI   R9,SCNWS+2        Start at R1
SAVE10 MOV  *R9+,*R8+         7 registers worth
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       RT
 
*  Restore SCNWS registers
 
RESTWS EQU  $
REST10 LI   R9,SREGS          Storage pointer
RSTW10 LI   R8,SCNWS+2        Restore from R1 on
       JMP  SAVE10
 
*  Set up command mode
*---------------------
 
COMAND EQU  $
       CLR  @TOPPAR           Forget paragraphs
       MOV  @STPLEN,R0        Current temp length
       CLR  R8                Erase marker (color or line)
       BLWP @SHOFRZ           Freeze show/erase
       SZCB @H80,@CMARKR      Turn off hi-bit entry
       LI   R9,COLTM2         >3783
       BL   @SETRDB           Change color table
       SOC  @CHNGED,@PURGED   Register changes
       MOV  @CMDRT,R0         Already in command mode?
       JNE  COMA30            Yes
 
*  Set up Command mode conditions
 
COMA05 LI   R11,COMVC         Command mode table pointer in VDP
       MOV  R11,@CCTABL       Set command table pointer
       BL   @UPDATE           Update line, etc.
       BL   @SAVEWS           Save old pointers away
COMA10 BL   @MRREM            Release margins
       BL   @DISPLY           Display mode message
       DATA COMSTA            Set up command return
       DATA MODEP             Message address in VDP
       MOV  R3,R1             Sbias -> Cline
       INC  R1                Cline to second line
       CLR  @GOLF             Cancel margin release flag
       SETO @UPCASE           Convert entry to upper case
       BL   @WINCMD           Reset display window - ignore LINF
 
*  Return for getting command key entry
*--------------------------------------
 
GETKEY CLR  R2                Cursor to left
COMA20 B    @GO2STT           Force buffer refresh and resume main loop
 
COMA30 BL   @CLRCMD           Flush all these flags
       JMP  COMA10            Back into it
 
*  Exit CMD mode at top of page
*------------------------------
 
CTOPL  MOV  R3,R12            Current top of screen
       JMP  SL10
 
*  Decode command and start the process
*--------------------------------------
 
COMSTA EQU  $
       CLR  @LINTBL+4         Remove error message if any
       BL   @CMLCHK           Scan along command line
       JMP  CMDXIT            Nothing - exit quietly
       JMP  COMS10            Not a number
SL     BL   @NUM              Decode the number
SL10   BL   @RESTWS           Restore previous pointers R1-R7
       MOV  R12,R1            Write # to Cline
       JMP  CMDX05
 
*  Continue Command decode
*-------------------------
 
COMS10 LI   R9,CMDTBL-6       Initialize command list search
COMS20 AI   R9,CMDTE          Next command
       CI   R9,CMDTND         End of table?
       JHE  ERRMSG            Yes, command not recognized
       CB   *R9,*R8           First char = command?
       JNE  COMS20            No use then
       CB   @1(R9),@1(R8)     Next byte
       JNE  COMS20            Yes, found a match
 
*  Process command just found
 
COMS40 INCT R9                Bump along to next data
       MOV  *R9+,@MESGAD      Address of screen message
       JEQ  COMS50            If 0, special, go to processor
       MOV  *R9,@CMDRT        Write in return address
       BL   @DISPLZ           Do it on the command line
       JMP  GETKEY            Get input for command
 
*  Special command process
 
COMS50 MOV  *R9,R9            Next word contains address pointer
       B    *R9               Go to command processor
 
*----------------
*  Error handlers
*----------------
 
ERRMSG BL   @CLRCMD           Clean out flags
ERRM10 BL   @HONK             Horrible noise
WINRTN CLR  @OVRL             Cancel overlay
       JMP  COMA10
 
*  DSR Errors from L/S module
 
DSRERR EQU  $                 Error routine for text buffer full
       MOV  @CMDRT,R0         Text Buffer Full
       JEQ  DSRE10
       BL   @RESTWS           Command mode already,
       ABS  @OVRL             Maybe had a file open?
       JEQ  DSRE10            No
       BL   @CLOSE            Close it just in case
       NOP                    IGNORE any error
DSRE10 BL   @CLRCMD           Set up for re-entry.
       LI   R10,TBFPT         Text buffer full message
       MOV  R10,@ERFLAG       Flag for DISPLY
       BL   @DISPLY
       DATA COMSTA,MODFP      Return, Load/Purge message
       CLR  @NCHAR            Make sure we do not update
       JMP  COMA05
 
*  Exit Command Mode
*-------------------
 
CMDXIT EQU  $
       BL   @RESTWS           Restore Workspace
       C    R1,@EOF           Cline  past EoF ?
       JLT  CMDX10            No
       MOV  @EOF,R1           Use EoF then
       JEQ  CMDX05            Empty file
       DEC  R1                Show last line
CMDX05 MOV  R1,R3             Cline --> Sbias
CMDX10 LI   R11,SSNLEN        Restore Edit  pointers
       MOV  *R11,@SCNLEN
       MOV  *R11,*R11+        STPLEN follows SSNLEN
       MOV  @CPUADR,@TOPSCN
       LI   R9,COLTM1         >2F83
       BL   @SETRDB           Reset color table
 
*  Common code continues
 
       BL   @RESTAB           Restore pointers
       BL   @CLRCMD           Clear running flags
       BL   @WINDOW           Reset lateral window
       LI   R11,COMVE         Restore Edit mode table
       MOV  R11,@CCTABL       Reset command table pointer to Edit
JCOM20 JMP  COMA20
 
*  Delete block of lines
*-----------------------
 
DL     EQU  $
       BL   @NUM              Fetch first number on command line
       MOV  R12,R15           Make copy
       BL   @NUMBER           Fetch second number
       MOV  R12,R14           Save copy
       S    R15,R12           Figure block length
       JLT  BERR2             No can do
       INC  R12               Make inclusive count for DLBLOC
       BL   @DLLSUB           Do the work
DL20   JMP  CMDXIT            All done
BERR2  JMP  ERRMSG            Error exit - not much fuss
 
*-----------------------------------
*  Fetch 3 numbers from command line
*-----------------------------------
 
LINUMS EQU  $
       MOV  R11,R14           Save return
       BL   @NUM              First number
       MOV  R12,R15           Save copy of "from"
       BL   @NUMBER           Second number
       MOV  R12,R13           Save copy of "to"
       BL   @NUMBER           Third number
       A    R0,R12
       MOV  R12,R6            Save copy of "after"
       MOV  R15,R9            Write as low # end - "from" to start with
       MOV  R13,R8            Write as middle pointer
       S    R9,R13            Form C/M block length
       JLT  BERR2             Invalid
       CB   *R8+,*R13+        Make inclusive on both
       MOV  R15,@LINENO       Copy for BufMgr
       C    R12,R8            "after" above "to" ?
       JHE  LINM20            Yes - take as is
       C    R12,R9            "after" below "from" ?
       JLT  LINM10            Yes - acceptable
BERR2J JMP  BERR2             But not otherwise
 
LINM10 MOV  R12,R9            "after" is then lowest line #
       MOV  R8,R6             "to" becomes highest
       MOV  R15,R8            "from" now in middle
LINM20 B    *R14              Set up either way so return
 
*  Calls to functions in SD module
*---------------------------------
 
VIEWS  BLWP @WRISEL           Put up list and select
       DATA VFLVO
       JMP  SD                Just go to SD if no files
       SETO @VIEWSC           Flag direct View entry
       JMP  SD                Now do SD
 
HELPS  BLWP @WRISEL           Select from list
       DATA HLPVO
       JMP  JCOM20            None loaded
       SETO @HLPSCR           Flag it
SD     B    @STARTD           Direct view
 
*  Load Temporary file
*---------------------
 
TL     LI   R15,TLFF
       JMP  LFJ
 
TLFF   BL   @DISPLY           Command display
       DATA LDTP01,MLTPT      Loader return, LTFile request
TL05   LI   R8,FTLNAM         Temp file mailbox
TL10   BL   @RESFIL           Fetch to command entry line
TL15   INC  R2                Pushes cursor to DSK<#>
TL30   JMP  JCOM20            Resume main loop
 
*  Save Temporary file
*---------------------
 
TS     BL   @DISPLY           Command display
       DATA SDTP01,MSTPT      Loader return, LTFile request
       JMP  TL05
 
*  Load File
*-----------
 
LF     LI   R15,LFF           Path if go by safety
LFJ    JMP  QQI10             Safety check
 
LFF    BL   @DISPLY           Command display
       DATA LDSV,MLFPT        Load re-entry, LFile request
       LI   R15,LDADRS        Load entry table
LFF10  LI   R8,FILNAM         Mailbox pointer
BA0    EQU  $-2               Cheap data byte
       BL   @RESFIL           Copy to command line in buffer
       INC  R2                For DSKx. on x
       SETO @CHGNAM           Force addition of existing name
*      LI   R11,LSTSEL        Check for new window
*      MOV  @WFLVO(R11),R11   Forced by Window select for new file
*      JLT  TL30              Go directly to entry
       LI   R11,ENTCTB        Entry count table
       MOV  @WFLVO(R11),R11   Fetch entry
       DEC  R11               Only one ?
       JEQ  LFF20             Yes - forget box but do not add as is
       JLT  LFF20
 
       BL   @DISPL2           Refresh top 2 lines
       BLWP @WRISEL           Write up selection box
       DATA WFLVO             Workfile list
       JMP  TL30              No prior selection for <enter>
LFF20  CLR  @CHGNAM           To see later if any entry
       JMP  TL30              Go fetch workfile name
 
LDSV   BL   @CMLCHK           Check if starts with #
       NOP                    ; Nothing - ignore
       JMP  LDSV20            Not a number
       INCT R15               Use Save/LoadTemp instead
LDSV20 MOV  *R15,R15          Or direct Save/Load
       B    *R15              Fetch and branch to it
 
*  Save File
*-----------
 
SV     MOV  @PURGED,R11       Check for purged
       JNE  SVGO              Has been altered
       BL   @HONK             Do not save !!
       B    @CMDXIT           Go back to edit mode
 
SVGO   BL   @DISPLY           Command display
       DATA LDSV,MSVPT        Save re-entry, SFile request
       LI   R15,SVADRS        Save entry table
       JMP  LFF10             Load command line and restart entry
 
*  Print File
*------------
 
PF     BL   @DISPLY           Command display
       DATA PF20,MPFPT        Print re-entry, PFile request
PF10   BL   @DISPL2           Write top 2 lines ahead of box
       BLWP @WRISEL           Select from box
       DATA PRDVO             Print device
       NOP                    MUST be something there
PF15   CLR  @CHGNAM
TL20   B    @GETKEY           Back into main loop
 
PF20   LI   R15,PF01          Set PF to follow
       JMP  DPRT10            Go enter name if edited
 
*  Print device  name for SD
*---------------------------
 
DP     BL   @DISPLY           Command display
       DATA DPRT,MDPPT        Return code, SDPdevice request
       JMP  PF10
 
DPRT   LI   R15,STARTD        Do SD after recording changes
       BL   @VMBWD            Write back to buffer
       DATA PSDBUV
       DATA CTEXT,>50         Whole of entry line
DPRT10 ABS  @CHGNAM           Any editing ?
       JEQ  DPRT30            No
       LI   R8,CTEXT          New entry pointer
       BLWP @PUSHDN           Add to start of list
       DATA PRDVO             Use same list as PF
       BL   @MBEEP            Acknowledge
DPRT30 B    *R15              Go to Show Directory
 
*  Hard disk pathname for SD
*-----------------------------------------
*  Always rewrite selection as first entry
*  Up/down this tree in SD
 
HDP    BL  @DISPLY            Command display
       DATA HDPX,HDMPT        Return code, hardpath request
       BL   @DISPL2           Make sure it is written up
       BLWP @WRISEL           Pop-up box
       DATA HDPVO             Hard-path names
       NOP                    1 at least already
       JMP  PF15              Getkey
 
HDPX   SETO @HARDF            Set flag for SD
       LI   R8,CTEXT          New entry pointer
       BLWP @PUSHDN           Add to start of list
       DATA HDPVO             Use same list as PF
       B    @STARTD           On way to SD
 
*  Purge buffer or pre-Load check
*--------------------------------
 
PG     LI   R15,PG01          Purge code
QQI10  ABS  @CHNGED           Current file modified ?
       JEQ  PGCHEX            No - purge/exit promptly
PURGEC BL   @DISPLY           Display purge message
       DATA PGCHK,MPGPT       Check response, Save first warning
       JMP  TL20
 
PGCHK  BL   @CMLCHK           Any entry ?
       JMP  ERMJJ             None
       NOP                    ; Not a number
       CB   *R8,@N            Save it ?  (catches # anyway)
       JNE  ERMJJ             Any key other than "N"
PGCHEX B    *R15              <N>o - go do it
 
*  Quit Editor (no safeguards)
*-----------------------------
 
QF     BL   @CMLCHK           First char on CTEXT line
       JMP  ERMJJ             None found
       LI   R15,ELDCON        Set for final exit
       CB   *R8,@TE           Is it "E" for Exit ?
       JEQ  PGCHEX            Yes
       CB   *R8,@P            "P" for Purge then ?
       JEQ  PG                Yes
ERMJJ  B    @ERRMSG           Non-specific error then
 
*  Fetch current filename
*------------------------
 
RESFIL LI   R9,CTEXT          Command entry line
       JMP  RESF05            Destination preloaded in R9
 
*  Save current filename back to buffer
 
SAVFIL MOV  *R11+,R9          Fetch destination data
       LI   R8,CTEXT          Command entry line
RESF05 LI   R12,>50           Buffer size
RESF20 MOV  *R8+,*R9+         Do the shuffle
       DECT R12
       JGT  RESF20
       RT
 
*  Wildcard character entry for FS/RS
*------------------------------------
 
WDCENT BL   @DISPLY           Command display
       DATA WCE,WLDPT         Return, wildcard request
       MOVB @WILDC,@CTEXT     Current wild byte
       JMP  TL20
 
WCE    MOVB @CTEXT,@WILDC     New wildcard
WCEX   BL   @MBEEP            Return via a beep
WCEEX  B    @COMA10           To initial command line
 
*----------------------------------------
*  Tabset choice - select set and process
*----------------------------------------
 
MTCI   EQU  $
       BL   @DISPLY           Set up command display
       DATA MTC,MTABP         Code pointer, tab message
       MOVB @CRNTAB,@CTEXT    Write in current tabset #
       JMP  MTC20             Go do it
 
*  Choose Tabset by number
 
MTC    EQU  $
       BL   @CMLCHK           Check command line
       JMP  ERMJJ             Blank line
       JMP  ERMJJ             Not a number
       MOVB *R8,R8            Copy & check entry
       MOVB R8,@CRNTBL        Save current entry
       SB   @AZERO,R8         Adjust from ASCII
       SRL  R8,8              Make word index
       JNE  MTC10             Not null
       INC  R8                Make 0 -> 1
MTC10  MPY  @D22,R8           Construct table offset
       AI   R9,TABBUV-22      Pointer into VBuffer
       MOV  R9,@LOADS         Save Vpointer for tabset
       BL   @MOVF             Read in from VDP
       DATA FORMO             Over current table
D22    DATA 22
       BL   @DISPLY           Write up Tab line and help
       DATA MTRT,MMTPT        Tab entry, Tab line
       BL   @GENTAB           Generate and copy current tab line
MTC20  B    @GETKEY
 
*  Process TAB entries
*---------------------
 
MTRT   EQU  $
       BL   @RESTAB           Restore previous margins
       LI   R14,FORMO         Restore initial pointer
       CLR  @INDT             Initialize Indent pointer as flag
       LI   R9,CTXTM6
       LI   R15,CTEXT         Initialize TAB string pointer
       LI   R6,16             # of Tabs
MTR10  CI   R15,CTXTND        End of line ?
       JHE  MTR15             Not yet
       MOV  R15,R13           Copy current position
       S    R9,R13
       CB   *R15,@L           Is it an "L" ?
       JNE  MTR10R            No
       MOV  R13,*R14          Write offset as LMrg
MTR22  INC  R15               Next char on line
       JMP  MTR10             Repeat it all
 
MTR10R CB   *R15,@R           Is it an "R"
       JNE  MTR10I            No
       MOV  R13,@2(R14)       Write offset as RMrg
       JMP  MTR15             Repeat
 
MTR10I CB   *R15,@TI          Is it an "I" ?
       JNE  MTR10T            No
       MOV  R13,@INDT         Write offset as Indent
       JMP  MTR22             Repeat
 
MTR10T CB   *R15+,@TT         "T" for Tab ?
       JNE  MTR10             No - repeat all for next char
       SWPB R13               For byte Ops
       MOVB R13,*R8+          Save Tab byte - RESTAB loads R8
       DEC  R6                Count off a Tab entry
       JGT  MTR10             Repeat
MTR15  C    *R14+,*R14        LMrg = or > RMrg
       JHE  ERMJJ             Yes - request another entry
       MOV  R6,R6             Tab table full
       JEQ  MTX10
MTR30  MOVB @D85+1,*R8+       Fill with RMrg value
       DEC  R6                Count
       JGT  MTR30             More
MTX10  MOV  *R8,R11           Check indent
       JNE  MTRC1             Yes - it has been entered
       MOV  @-2(R14),*R8      Write in LMarg then
MTRC1  MOV  @LOADS,R9         VPointer for replacing entry
       BL   @VMBWE            Write to VDP
       DATA FORMO,22          From format table
       LI   R8,CPUSCN         Rewrite to get clean copy
       LI   R9,MMTPT          Rewrite tab template
       BL   @MVISTR           Write it in CPU RAM
       BL   @GENTAB           Fill out details and update line #26
       MOVB @CRNTBL,@CRNTAB   Update current Tab indicator
JCMDX1 BL   @MBEEP            Acknowledge
       B    @CMDXIT           Leave command mode
 
*-------------------------
*  Set marker line in text
*-------------------------
 
EML    EQU  $
       BL   @CMLCHK           Find entry
       JMP  STBFER            Not found
       NOP                    NOT a number - might be E
       BL   @NUMBER           Parse #  with EoF check
       MOV  R12,@MKTBL        Copy result to table
EML10  JMP  JCMDX1
 
*-----------------------------
*  Mark Line # on command line
*-----------------------------
 
MARKLN EQU  $
       LI   R9,CTXTND-6       5 chars from end
       C    R4,R9             Cursor too far along ?
       JH   MRKL99            Yes
MRKL10 MOVB *R9,@5(R9)        Move along - drop end chars
       DEC  R9                Back one
       C    R9,R4             All done  ?
       JHE  MRKL10            Not yet
       LI   R8,CTXTND         Start of next line
       MOVB *R8+,*R4+         Write in top line #
       MOVB *R8+,*R4+         4
       MOVB *R8+,*R4+         digits
       MOVB *R8+,*R4+         worth
       MOVB @DSPACE,*R4+      Finish with a space
       AI   R2,5              Bump cursor
       SETO @ICHRF            Set insert mode
MRKL99 RT
 
*  Insert paste buffer contents into text
*----------------------------------------
 
RTBUF  EQU  $
       BL   @DISPLY           Request where
       DATA PASTE,PSTPT       Paste after reminder
       LI   R4,CTEXT
       BL   @MARKLN           Write in top of screen #
       B    @GETKEY           Resume keyloop
 
*  Paste in after top or nominated line
 
PASTE  EQU  $
       BL   @CMLCHK           Find entry
       JMP  STBFER            Not found
       NOP                    NOT a number - might be E
       BL   @NUMBER           Parse #  with EoF check
       MOV  @MLINT,R6         # lines to insert
       LI   R9,COPASB         Point to copy/paste buffer start
PAST10 MOV  R9,@BUFADR        Use as buffer address
       INC  R12               After line indicated
       MOV  R12,@LINENO       So BfMgr can find it
       BL   @INSL20           Insert int text buffer
       AI   R9,LLL            Next line in copy buffer
       DEC  R6                Count off
       JGT  PAST10            More
       BL   @MBEEP            Friendly noise
       JMP  STBFEX            All done
 
STBFER BL   @HONK
STBFEX B    @COMA10           Exit to CMD mode
 
STBUF  EQU  $
       MOV  @EOF,R9           Get EoF
       S    R3,R9             Remove screen line bias
       C    R9,@MXBLOC        Only 22 at most
       JL   STBF10            OK
       MOV  @MXBLOC,R9        Force max then
STBF10 MOV  R9,@BLOCWS+20     Limit in R10 of mark code
       MOV  @DSIX,@BLOCWS+10  Set left limit & flags Edit
       BLWP @BLOCMM           Mark/copy
       JMP  STBFEX
 
*  Generate tab line entry display
*---------------------------------
*  Tab entries relative to CTXTM6
 
GENTAB EQU  $
       LI   R9,CTXTM6         Command line
GENTAC LI   R8,FORMO          Point to format table
       MOV  *R8+,R6           Copy current L offset
       MOV  *R8+,R14          Copy current R offset
MT10   MOVB *R8+,R12          Fetch Tab byte offset
       SRL  R12,8             Word adjust
       A    R9,R12            Add offset to line start
       MOVB @TT,*R12          Write in a "T"
       CI   R8,TABTND         All done ?
       JLE  MT10              No
       MOV  *R8,R12           Indent offset - at L if none
       A    R9,R12            Offset into line
       MOVB @TI,*R12          Write up an "I"
       A    R9,R6             Offset L pointer
       MOVB @L,*R6            Write up "L"
       A    R9,R14            Offset R pointer
       MOVB @R,*R14           Write up "R"
       MOV  R9,R8             Copy CTEXT pointer as target pointer
       AI   R8,6              Move to buffer start
PLAINU LI   R9,25*80          Bottom tab line display
WRVLIN BLWP @SETVDW           Set for write
       LI   R9,VDPWD          Load for inline code
       B    @CVBLOK           Unrolled loop
 
*  Restore plain ruler line
*--------------------------
 
PLAINT EQU  $
       LI   R11,START         Fake out VMBW exit
       LI   R8,NBLINE         Clean tab line data
       JMP  PLAINU
 
*--------------------------------*
*  Find/Replace string commands  *
*--------------------------------*
 
*  Find string entry
*-------------------
 
FS     EQU  $
       BL   @DISPLY           Show command message
       DATA FS00              Return address
       DATA MFSPT             Find string message
       JMP  RFS00             Use RS code
 
*  Replace string entry
*----------------------
 
RS     EQU  $
       BL   @DISPLY           Command display
       DATA RS00              Return address
       DATA MRSPT             RS message
 
*  Common RS/FS continuation
*---------------------------
 
RFS00  EQU  $                 Fetch current RS/FS display
       BL   @MOVE
       DATA RSFBUV
       DATA CTEXT,LLL
       CLR  @UPCASE           Allow lower case
       B    @GETKEY           Get response
 
 
*  Replace string & Find string
*------------------------------
 
RS00   SETO @VRFY             Flag check when found
       SETO @RSFLAG           Check for 3 delimiters
       JMP  RS01
 
FS00   CLR  @RSFLAG           Make sure of it
RS01   MOV  R1,@MKSAV1        Save for <ctrl-O>
       MOV  R3,@MKSAV3        Also
       BL   @VMBWD            Save entered strings
       DATA RSFBUV            VDP storage
       DATA CTEXT,LLL         Command line entry
 
*   Parse command line for Find/Replace string
 
       LI   R8,CTEXT          On command line
       BL   @PRNUMS           Sort out numbers
       JMP  PRSERJ            Bad result
       MOVB *R8+,@DELIM       First non separator as delimiter
       MOV  R8,@STRING        Store string pointer
       BL   @GSLASH           Look for delimiter
       JMP  PRSERJ            Not found
       MOV  R6,@STRL          Length as word
       MOV  R8,@RSTRNG        Start of replace string
       BL   @GSLASH           Find its delimiter
       CLR  R6                Zero if not found
       MOV  R6,@RSTRL         Save its length
       MOV  @NUMCHK,R6        Copy counter
       JEQ  PRRG20            Two numbers on line
 
*  Get no action count for 0,1,3 #s
 
       MOV  *R9+,@CNT         Copy first as count
       INC  @CNT              For skip count by DEC - 0 if no #s
       DEC  R6                3 #s ?
       JLT  PRRG20            Yup
       CLR  *R9               Initialize for 0 or 1 #
       MOV  @D79,@2(R9)       Last column
 
*  Get and check column pointers
 
PRRG20 LI   R8,79             For column check
D79    EQU  $-2
       MOV  *R9,@NUM1         Enter as start column  COLSTA
       C    *R9,R8            Past last ?
       JGT  JPRSER            Yes - invalid
       C    *R9+,*R9          Compare to next #
       JGT  PRSERR            Can't be bigger
       MOV  *R9,@NUM2         End column   COLEND
       C    *R9,R8            Check against max
JPRSER JGT  PRSERR
 
*  Generate bounding column addresses for search
 
       BL   @RESTLA           Columns start at CTEXT
       LI   R9,LINBUF
       A    R9,@NUM1          Adjust as buffer pointer
       A    R9,@NUM2          Also
 
*  Continue after parsing
 
RFCON  BL   @RESTAB           Restore margins
RS10   BL   @RESTWS           Restore pointers to start search
       BL   @MOVE             Move fast search code to PAD
       DATA FFSCOD,FAC,FFSLEN No DSRs active now
       INC  R2                Start cursor at next char
       MOV  @LINADR,R4        Calc current cursor address
       A    R2,R4             Add Cursor offset to line start
 
*  Check start on present line
 
       C    R4,@NUM1          Cursor address < column start?
       JLT  FS18              Yes -  do search anyway after fixup
       C    R4,@NUM2          No, Cursor addr > column end?
       JLE  FS20              No, ok
 
*  Fetch next line to search
 
FS14   INC  R1                Yes, read next line
FS18   MOV  @NUM1,R4          Restore cursor addr to start
FS20   BL   @GETLC            Get Cline from buffer to @LINADR
       JMP  RSERR             EoF direct return
       MOV  @STRING,R8        Get start of comparison string
       MOV  R8,R12            Make copy
       A    @STRL,R8          End of reference string
       MOV  @NUM2,R6          Loop tightener
       MOVB @WILDC,R13        Fetch wildcard byte
       BL   @FAC              String comparison loop
       JMP  FS14
 
*  Return with string match
 
FS40   MOV  R1,R3             Cline -> Sbias
       MOV  R4,R2             Successful search -> Cursor
       S    @LINADR,R2        Calculate new cursor position
       BL   @SAVEWS           Save new registers for restore
       DEC  @CNT              Ignore while counting
       JGT  RS13              Yup
       JMP  RS15              At the first on now
 
RS13   INC  @SREGS+2          Bump saved Cursor past last find
       JMP  RS10              Have another go
 
RS15   ABS  @RSFLAG           Was it Replace
       JNE  RS30              No - stop when found
RE10J  B    @CMDXIT
PRSERJ JMP  PRSERR            Intermediate jump
 
*  Verify for Replace
*--------------------
 
RS30   ABS  @VRFY             String found, verify for replace ?
       JNE  VERFY             Yes - go ask about it
       MOV  @SWIDTH,R9        No - write up screen #
       AI   R9,-6             In from end of top line
       MOV  @LINADR,R8        Line number as retrieved
       BL   @VMBWL            Write to VDP
       DATA 4                 4-digit #
       JMP  REPLCE            Now go replace it
 
VERFY  BL   @MRREM            Release margins
       BL   @MOVE             Write Verify message
       DATA RSMSV             VDP storage
       DATA CPUSCN            Command advice line
       DATA >56               Full length
       BL   @REST10           Restore workspace with out losing it
       LI   R9,VERRT          Return address after answer
       MOV  R9,@PROMPT        Load for special return
       INCT R1                Fake cursor to real line
       B    @COMA20           Get answer
 
*  Process Verify answer
 
VERRT  BL   @RESTLA           Restore line address
       BL   @REST10
       BL   @CNVLC            Convert lower case
VERR05 CB   *R8,@Y            Yes ?
       JEQ  REPLCE            Go replace string
       CB   *R8,@N            No  ?
       JNE  VERR10            No - continue comparisons
       A    @STRL,@SREGS+2    Bump past find for restart
       DEC  @SREGS+2
       JMP  RS10
 
VERR10 CB   *R8,@S            Stop ?
       JEQ  RE10J             Exit CMD mode
       CB   *R8,@A            All ?
       JEQ  VERR12            Cancel verify & replace all strings.
       CB   *R8,@CTRLC        <esc> ?
       JEQ  RSERR             Let's hear it
       CB   *R8,@B0F          <esc> ?
       JNE  VERFY             No - loop on keychoice
 
*  Error / <esc> exit
 
PRSERR CLR  @COLNUM
RSERR  B    @ERRMSG           Bloop entry
 
VERR12 LI   R9,LINTBL         Line table
       CLR  *R9+              Cancel special on first line
       CLR  *R9               Second also
       CLR  @VRFY             No verify any more
 
*  Do the string replace
 
REPLCE BL   @BKREPB           Blank replace buffer
       MOV  R4,R14            Curadr -> end of first move
       MOV  @LINADR,R8        Start of data
       A    @DSIX,R8          Skip over line #
       LI   R9,REPBUF         Output buffer
RADR   EQU  $-2
REPL10 C    R8,R14            Copy text up to replace start
       JHE  REPL20            Done
       MOVB *R8+,*R9+         Copy bytes
       JMP  REPL10            Write replace string
 
*  Write in replace string after this
 
REPL20 MOV  @RSTRL,R6         Check replace string length
       JEQ  REPL35            Ignore if null
       MOV  @RSTRNG,R10       Fetch pointer to replace string
REPL30 MOVB *R10+,*R9+        Copy bytes over
       DEC  R6                Count off
       JGT  REPL30            More
 
*  Finish rest of line
 
REPL35 MOV  R9,@MARKER        Mark current place
       DEC  @MARKER           Back off to last char
       A    @STRL,R8          Adjust cursor past find string
REPL40 C    R8,@LINEND        At end ?
       JH   REPL50            Yes
       MOVB *R8+,*R9+         Write rest of line.
       JMP  REPL40            More
 
*  Word-wrap or truncate
 
REPL50 ABS  @WDWRAP           Word wrap mode?
       JNE  REPL80            Yes, go reformat
       CLR  @MARKER           Reset marker
       LI   R14,REPBM6        Past line #
RPM6A  EQU  $-2
       A    @RSTRL,@SREGS+2   Push Cline along by Rstring length
       DEC  @SREGS+2          Back off to last char
       A    @RMRG,R14         Blank beyond right margin
       INC  R14               Next char
REPL60 MOVB @DSPACE,*R14+     No worry if run over end
       CI   R14,REPBUF+>50
       JL   REPL60
       MOV  @RADR,@BUFADR     Load for BufMgr
       MOV  R1,@LINENO
       BLWP @UPDTLN           Update line in buffer
       MOV  R0,R0             Error?
       JNE  PRSERR            Yes
       B    @RS10             Back for more
 
*  Bail out here if in word-wrap mode
 
REPL80 EQU  $                 Replace string word wrap mode
       LI   R9,REPBND         SRCEND - temp register use
       CLR  @TOPPAR           Reformat from ALL OF LINE.
       LI   R14,RS10          Set up return address
       B    @RENTRY           Go reformat also
 
*  Display handling routine
*-----------------------------
*  Returns immediately from BL
*  Loads data to final exit
 
DISPLY EQU  $
       MOV  *R11+,@CMDRT      Return address of command
       MOV  *R11+,@MESGAD     Command info line message pointer
DISPLZ MOV  R11,R13           Save return
       CLR  @RSFLAG           No search yet
       CLR  @LINTBL           Make sure we display this stuff
       CLR  @LINTBL+2         Second line too
       LI   R6,C24-2          Set up pointers for command mode
       LI   R9,SCNLEN         Byte saver
       MOV  R6,*R9+           Reduced display length
       MOV  @SSNLEN,@STPLEN   Restore temp length
       LI   R6,CPUSCN         CPU text buffer
       MOV  R6,*R9            Start screen there @TOPSCN
       LI   R10,86*2          Push down 2 lines worth
       A    R10,*R9           Adjust top of screen value
       MOV  R6,R9
DISP10 MOV  @DSPACE,*R6+      Blank out display buffer
       DECT R10               Even addresses
       JGT  DISP10
 
*  Error handling code
 
ERRHAN EQU  $
       MOV  @ERFLAG,R9        Check if error message pending
       JEQ  ERH40             No
       MOV  R9,R10            Copy error #
       CLR  @ERFLAG           We have seen it now
       LI   R8,ERMBUF         Line buffer for error line
       MOV  R8,@ERRLIN        Line table pointer
EHN10  MOV  @DSPACE,*R8+      Clear buffer
       CI   R8,ERMNP1         End of buffer ? (+86)
       JL   EHN10             Not yet
       LI   R8,ERMBP6         Start at text line (+6)
       BL   @MVISTR           Fetch error message from VDP
       CI   R10,IOERP         Was it IO error ?
       JNE  ERH40             No
       MOV  @IORNM,*R8+       Fetch #
ERH40  MOV  @MESGAD,R9        The normal exit
       LI   R8,CPUSCN         Top line of screen
       BL   @MVISTR           Write up specified top-line message
       B    *R13
 
*  CMD line number scanner
*  Uses R0,R6,R8,R8,R10,R12
*--------------------------
 
NUM    EQU  $
       LI   R8,CTEXT          Start of entry area
NUMBER MOV  R8,R9             Save copy
       SETO R6                Initialize digit counter
       MOV  @EOF,R12          Just in case EoF
       CB   *R8+,@EOFLIN      Is it "E" ?
       JEQ  NUM50             Yes - EoF already set
       DEC  R8                Back up to first char again
NUM10  INC  R6                Count one
       CI   R6,4              Max # digits allowed
       JGT  PARERR            Error in entry
       CB   *R8,@DSPACE       Space terminator ?
       JEQ  NUM20             Yes
       CB   *R8,@SLASH        Slash separator ?
       JEQ  NUM20             Yes
       CB   *R8+,@COMMA       Comma separator ?
       JNE  NUM10             No
NUM20  MOV  R6,R6             Any digits at all ?
       JEQ  PARERR            No
       SLA  R6,1              Word adjust for calcs
       CLR  R12               Initialize
       MOV  R9,R8             Restore pointer to start
NUM40  MOVB *R8+,R9           Fetch digit
       SRL  R9,8              Word adjust
       AI   R9,->30           Remove ASCII bias
       JLT  PARERR            Not legit
       CI   R9,9              Above "9"
       JGT  PARERR            Not legit
       MPY  @TEN-2(R6),R9     Factor in power of 10
       A    R10,R12           Accumulate result
       DECT R6                Count off
       JGT  NUM40             Back for more
       C    R12,@EOF          Was it <= EoF ?
       JLE  NUM50             Acceptable in any event
       ABS  @COLNUM           All line #s in this file ?
       JNE  NUM50             No - proceed directly
       MOV  @EOF,R12          Replace by EoF then
NUM50  CLR  R0                Initialize line #0 offset flag
       MOV  R12,R12           Was "0" entered
       JEQ  NUM60             Yes
       INC  R0                Set offset
       DEC  R12               Internally uses zero base
NUM60  INC  R8                For start of next field
       RT                     NORMAL return
 
*  Number parse routine for PARSE versions
*-----------------------------------------
*  Called from RS/FS, L/S PARSLD
 
PRNUMS EQU  $
       SETO @COLNUM           Turn off EoF check
       MOV  R11,R14           Save return
       SETO @NUM1             Initialize first number for CNT
       MOV  @WTWO,@NUMCHK     Initialize counter
PRNU10 BL   @CMLH10           Check command line to end
       JMP  PRNUEX            Only separators
       JMP  PARS40            Non-number
       JMP  PARS50            Numerical digit
 
PARS40 CB   *R8,@EOFLIN       Is it "E" ?
       JNE  PRNU30            No
       CB   @1(R8),@DSPACE    And a space ?
       JNE  PRNU30            Not "EoF"
 
*  Try it as a number then
 
PARS50 BL   @NUMBER           Yes - retrieve number
       DEC  R8                Back up to delimiter
       DEC  @NUMCHK           Count it off
       JLT  PARS12            Must be 3rd #
       JEQ  PARS11            Must be 2nd #
 
*  Enter the numbers
 
       MOV  R0,@SAVER0        For zero correction
       MOV  R12,@NUM1         Save as 1st #
       JMP  PRNU10            Resume search
PARS11 MOV  R12,@NUM2         Save as 2nd #
       JMP  PRNU10            Resume search
PARS12 MOV  R12,@NUM3         Save as 3rd #
       JMP  PRNU10            Resume
 
*  Set up delimiter etc
 
PRNU30 INCT R14               Step over error return
PRNUEX LI   R9,NUM1           Byte saver
       CLR  @COLNUM           Make sure EoF check re-enabled
       B    *R14
PARERR B    @PRSERR
 
*  Check for delimiter
*---------------------
 
GSLASH SETO R6                Initialize counter
GSLA10 CI   R8,CTXTND         At end ?
       JHE  GSLA20            Yes
       INC  R6
       CB   *R8+,@DELIM       Well, is it ?
       JNE  GSLA10            No
       INCT R11
GSLA20 RT
 
*  Check to end of command line
*------------------------------
*  Called from COMSTA, PRNUMS
 
CMLCHK EQU  $
       LI   R8,CTEXT          Start of command line
CMLH10 CI   R8,CTXTND         End of command line ?
       JHE  CMLH40            No more
       CB   *R8+,@COMMA       Commas as separator
       JEQ  CMLH10
       DEC  R8
       CB   *R8+,@DSPACE      Ignore leading blanks
       JEQ  CMLH10
       DEC  R8
       CB   *R8,@AZERO        Check if number digit
       JL   CMLH30            No
       CB   *R8,@H39
       JH   CMLH30            No
       INCT R11               Double step over for number
CMLH30 INCT R11               Return for not a number
CMLH40 RT                     END of line error
 
*  Restore Line Address
*----------------------------------
*  Called from START, RS/FS, COMSTA
 
RESTLA EQU  $
       LI   R9,LINBF0         For find and replace string.
RESTLB MOV  R9,@LINADR        Start of current line data
       AI   R9,85             Point to last char on line
D85    EQU  $-2
       MOV  R9,@LINEND        Save as data
       RT
 
*  Clear flags for CMD mode
*------------------------------------
*  Called from COMAND, ERRMSG, CMDXIT
 
CLRCMD EQU  $
       LI   R8,SCLR           Start (>2000)
CLRBUF CLR  *R8+              Loop on it
       CI   R8,SCLRND
       JL   CLRBUF
       RT
 
*  Cursor left
*-------------
 
LFTAR  EQU  $
       DEC  R2                Back up Cursor
       MOV  @WDWRAP,R0        Word-wrap mode ?
       JEQ  ARRW20            No
       MOV  @CMDRT,R0         Command mode ?
       JNE  ARRW20            Yes
       C    R2,@LMRG          Past left margin ?
       JHE  ARRW20            Not yet
       LI   R11,UPAR          Return via scroll up
       JMP  BTAB15            Set left margin on way
 
*  TAB forward
*-------------
 
TABF   EQU  $
       LI   R8,TABTP          Point to Tab table start
TAB10  CB   @SCNWS+5,*R8      R2LB for cursor offset
       JL   TABSET            Go move to this tab
       INC  R8                Next Tab entry
       CI   R8,TABTND         Past end yet ?
       JLE  TAB10             No
TAB15  MOV  @LMRG,R2          Force back to LMrg
       RT
 
*  Back Tabs
*-----------
 
BTAB   EQU  $
       LI   R8,TABTND         Tab table end
BTAB10 CB   @SCNWS+5,*R8      Compare cursor and entry
       JH   TABSET            Go move to this TAB
       DEC  R8                Next tab to left
       CI   R8,TABTP          Back to start ?
       JHE  BTAB10            Once again
BTAB15 MOV  @RMRG,R2          Else force to RMrg
       RT
 
TABSET MOVB *R8,R2            Write to cursor
       SRL  R2,8              Make word offset
ARRW20 RT                     RETURN
 
*  Two-way case shifting
*---------------------------------------------
*  Includes right cursor and forward line wrap
 
DNCAS  LI   R9,'AZ'           Upper case comparisons
       LI   R15,' *'          Lower to upper correction
       JMP  CASE1
 
UPCAS  LI   R9,'az'           Lower case comparisons
       LI   R15,>E022         Upper to lower conversion
CASE1  CB   *R4,R9            Check *CURADR
       JL   RGTAR             Out of range
       SWPB R9                Other end
       CB   *R4,R9            Check *CURADR
       JH   RGTAR             No interest again
       AB   R15,*R4           Make correction
 
*  Drop into right cursor code
 
RGTAR  INC  R2                Advance CURSOR right
RGTR10 MOV  @WDWRAP,R0        Word-wrap mode ?
       JEQ  ARRW20            No
       MOV  @CMDRT,R0         Command mode ?
       JNE  ARRW20            Yes
       C    R2,@RMRG          Past right margin ?
       JLE  ARRW20            Not yet
       LI   R11,DWNAR         Return via scroll down
       JMP  TAB15             Set left margin on way
 
UCA    EQU  DNCAS+2
UCZ    EQU  DNCAS+3
LCA    EQU  UPCAS+2
LCZ    EQU  UPCAS+3
ASTRIX EQU  DNCAS+7           Don't waste a data byte
DQUOTE EQU  UPCAS+7
 
*  TAB by words
*--------------
 
TABWD  EQU  $
       MOV  R4,R8             Copy Curadr
       MOV  @LINEND,R9        Copy current end of line pointer
TABN10 C    R8,R9             End of line ?
       JHE  TAB15             Yes - force to LMrg
       CB   *R8+,@DSPACE      Search for <space>
       JNE  TABN10            No - check next dhar
 
       MOV  R8,R4             Copy pointer to non-space char
TABN20 C    R8,R9             End of line ?
       JHE  TABN30            Must be last word
       CB   *R8+,@DSPACE      Search for next <non-space>
       JEQ  TABN20            Keep going
       MOV  R8,R4             Set Curadr
       DEC  R4                Back up to first char of word
TABN30 MOV  R4,R2             Copy to Cursor
       S    @LINADR,R2        Remove buffer bias
       JMP  RGTR10            RETURN
 
*  Restore  TAB settings for Edit
*--------------------------------
 
RESTAB EQU  $
       LI   R8,FORMO          Format table pointer
       MOV  *R8+,@LMRG        Restore left margin
       MOV  *R8+,@RMRG        Right margin also
       RT
 
*  EoF line data
*---------------
 
EOFLIN TEXT 'EoF   '
NBLINE TEXT '0....:....1....:....'
       TEXT '2....:....3....:....'
       TEXT '4....:....5....:....'
       TEXT '6....:....7....:....'
AZERO  EQU  NBLINE
AONE   EQU  NBLINE+10
NBLNM3 EQU  NBLINE-3
NBLEND EQU  $
 
       EVEN
 
*----------------------------------------*
 
 
