 
*  ED6/COMD   40 col          Jul / 11 / 93
*-------------------
*  Minimum Function
 
*  Set up command mode
*---------------------
 
COMAND EQU  $
       CLR  @TOPPAR
       MOV  @SSNLEN,@STPLEN   Restore temp screen length
       MOV  @CMDRT,R0         Already in command mode?
       JNE  COMA30            Yes
 
*  Set up Command mode conditions
 
COMA05 LI   R11,COMVC         Point to CC table in VDP
       MOV  R11,@CCTABL       Write for key decoder
       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
 
*  Return for getting command key entry
*--------------------------------------
 
GETKEY CLR  R2                Cursor to left
COMA20 B    @GO2STT           Force buffer refresh & 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
 
*  Show line entry
 
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 recovery
*----------------
 
ERRMSG BL   @CLRCMD           Clean out flags
ERRM10 BL   @HONK             Horrible noise
       CLR  @OVRL             Cancel overlay
       JMP  COMA10
 
*  Errors
*--------
 
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            Return address
       DATA MODFP             Message Load..Purge
       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
       MOV  *R11,@SCNLEN      Restore Edit  pointers
       MOV  *R11+,*R11+       To STPLEN
       MOV  @CPUADR,*R11      To TOPSCN
       BL   @RESTAB           Restore pointers
       BL   @CLRCMD           Clear running flags
       BL   @WINDOW           Reset lateral window
       LI   R11,COMVE         Restore Edit mode table
       MOV  R11,@CCTABL
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
 
*  Delete block and adjust marker
*--------------------------------
*  Called from DL and Reformat
 
DLLSUB EQU  $
       LI   R9,MKTBL          Byte saver
       C    R15,*R9           Start above ?
       JH   DLS10             Yes - no action
       JEQ  DLS08             Cancel marker - line gone
       C    R14,*R9           End above marker then ?
       JHE  DLS08             Cancel marker
 
       S    R12,*R9           Excise block then
       JMP  DLS10
 
DLS08  MOV  R15,*R9           Reset marker to startof block
DLS10  MOV  R15,@LINENO       Starting line #
       BLWP @DLBLOC           Delete by contiguous blocks
       JEQ  DLS10             More to do
       RT
 
*-----------------------------------
*  Fetch 3 numbers from command line
*-----------------------------------
 
LINUMS EQU  $                 27w ----
       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
 
 
*--------------------------
*  Load/Save module callers
*--------------------------
 
*  Setup L/S module branch addresses
 
SD     LI   R15,SD01          Show Directory
       SETO @COLNUM
       BL   @NUM
       CLR  @COLNUM
       INC  R12
       SWPB R12
       JMP  LSMOV
HSCR   LI   R15,HLP10
       JMP  LSMOV
PFX    LI   R15,PF01          Print file
       JMP  LSMOV
SVX    LI   R15,SAVE01        Save File
       JMP  LSMOV
LFX    LI   R15,LOAD01        Load file
       JMP  LSMOV
TLX    LI   R15,LDTP01        Load temp file
 
*  Fetch Load/Save Module
*------------------------
 
LSMOV  BL   @MOVE             Data VMBR
       DATA LSMODV            L/S storage in VBank #0
       DATA OVRLAY,LSLEN      Beyond CTEXT line
       SETO @OVRL             Flag overlay in
       B    *R15              Target set in L/S
 
*  Load Temporary file
*---------------------
 
TL     BL   @DISPLY           Command display
       DATA TLX               Return address
       DATA MLTPT             Temp load message
       LI   R9,TFLBUV         Point to TL filename
TL10   BL   @MOVF             Fetch file/device name
       DATA CTEXT,LLL
TL15   INC  R2
       JMP  JCOM20
 
*  Load File
*-----------
 
LF     BL    @DISPLY          Command display
       DATA  LFX              To load L/S module address
       DATA  MLFPT            LF message
       JMP   SV2
 
*  Save File
*-----------
 
SV     BL   @DISPLY           Command display
       DATA SVX
       DATA MSVPT
SV2    BL   @RESFIL           Get name from mailbox
       JMP  TL15
 
*  Print File
*------------
 
PF     BL   @DISPLY           Command display
       DATA PFX               Return address
       DATA MPFPT             Print file message
       LI   R9,DEVBUV         Point to print device name
DPP10  BL   @MOVF
       DATA CTEXT,LLL
TL20   B    @GETKEY
 
*  Print device  name for SD
*---------------------------
 
DP     BL  @DISPLY            Command display
       DATA DPX
       DATA MDPPT
       LI   R9,PSDBUV         VDP storage
       JMP  DPP10             Treat like print device
 
DPX    BL   @VMBWD            Write back to buffer
       DATA PSDBUV
       DATA CTEXT,>50
JCMDX  B    @CMDXIT           Quit command mode
 
*  Purge buffer or Quit Immediate
*--------------------------------
 
QQI    LI   R15,EDEXIT
       JMP  QQI10
PURGEB LI   R15,PG
QQI10  ABS  @CHNGED           Any entry current ?
       JEQ  PGCHEX            No - purge/exit promptly
 
PURGEC BL   @DISPLY           Display purge message
       DATA PGCHK             Code to check response
       DATA MPGPT             Save First ?
       JMP  TL20
 
PGCHK  BL   @CMLCHK           Any entry ?
       JMP  ERMJJ             No
       CB   *R8,@N            Save it ?
       JNE  ERMJJ             Any key other than "N"
PGCHEX B    *R15              <N>o - go do it
 
PG     BL   @PURGE
       JMP  JCMDX
 
*  Quit Editor
*-------------
 
QF     BL   @CMLCHK           First char on CTEXT line
       JMP  ERMJJ
 
       CB   *R8,@TE           Is it "E" for Exit ?
       JEQ  EDEXIT            Yes
 
       CB   *R8,@P            "P" for Purge then ?
       JEQ  PURGEB            Yes
ERMJJ  B    @ERRMSG           Non-specific error then
 
*  On way to final exit
 
EDEXIT EQU  $
       SZCB @MASK10,@>83C2    Restore <Quit>
       BL   @SETVR1           Set VR 1
       DATA >B081             Blank screen while at it
       B    @ELDCON
 
*-------------------------
*  Set marker line in text
*-------------------------
 
EML    EQU  $
       BL   @NUM              Validate and get the number
       MOV  R12,@MKTBL        Copy result to table
       JMP  JCMDX
 
*  Fetch current filename
*------------------------
 
RESFIL LI   R8,FILNAM         Mailbox pointer
BA0    EQU  $-2               Cheap data byte
       LI   R9,CTEXT          Command entry line
       JMP  RESF05
 
*  Save current filename back to buffer
 
SAVFIL LI   R9,FILNAM         Mailbox
       LI   R8,CTEXT          Command entry line
RESF05 LI   R12,>50           Buffer size
       B    @FLOOPC           Use PAD code
 
*  Wildcard character entry for FS/RS
*------------------------------------
 
WDCENT BL   @DISPLY           Command display
       DATA WCE,WLDPT         Return, wildcard request
       MOVB @WILDC,@CTEXT     Current wild byte
TL20J  JMP  TL20
 
WCE    MOVB @CTEXT,@WILDC
       BL   @BEEP
       B    @COMA10
 
*----------------------------------------
*  Tabset choice - select set and process
*----------------------------------------
 
MTCI   EQU  $
       BL   @DISPLY
       DATA MTC
       DATA MTABP
       MOVB @CRNTAB,@CTEXT
       JMP  TL20
 
*  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
 
       CB   R8,@ATHREE        Only 3 in 40 col only
       JH   ERMJJ
 
       MOVB R8,@CRNTBL        Save as ASCII
       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
       DATA MMTPT
       BL   @GENTAB           Generate and copy current tab line
       JMP  TL20J             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
       MOVB @CRNTBL,@CRNTAB
JJCMD  B    @CMDXIT           Leave command mode
 
*  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"
       RT
 
*  Help Screen
*-------------
 
HLP10  EQU  $
       MOVB @HPMAX,R15        Help enabled ?
       JEQ  JJCMD             No - quit now
 
       MOV  @INXADR,R15       Get name index pointer
*      MOVB @UCA,*R15         Reinitialize name
HLP30  BL   @VMBWD            PAB to VDP
       DATA VDPPAB,PABHLD,>20
       LI   R9,VDPPAB+9       Load for DSR
       MOV  R9,@SCNAME        Also
       BLWP @TWDSLK           Call DSR
       JEQ  HLP70             Failure - back up
       LI   R9,VDPPAB+1       Check error return
       BL   @SETRDA           Get byte with flags
       MOVB @VDPRD,R9         To CPU register
       SRL  R9,13             Check error bits
       JNE  HLP70             Failure - back up
 
HLP40  BLWP @SCANKY           Check keyboard
       SZCB @ANTI20,@GPLST
       JEQ  HLP40
 
       BL   @KWAIT            Key loop
       JMP  HLP50             <key>
       JMP  JJCMD             Exit
 
HLP50  BL   @CNVLC            Convert to UC
       CB   *R8,@UCA          Advance one ?
       JNE  HLP60             Check next
       AB   @ONE,*R15         Advance pointer
       JMP  HLP30             Try to load it
HLP60  CB   *R8,@ASCQ         Back one ?
       JNE  HLP40             Loop on key
HLP70  CB   *R15,@UCA         Already far enough ?
       JLE  HLP40             Yes
       SB   @ONE,*R15         Back up
       JMP  HLP30             Load it
 
*  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
MRKL99 RT
 
*-------------------------------------------------
 
 
