 
*  ED4/PARAS   40 Col         Oct / 13 / 93
*--------------------
*  All Versions 40
 
*  NextScn, DelChr, LastPar, NextPar
*  Endfil, HomeCsr, GoTo1, Go2End
*  FindNB, FindCR, Refrmt
*------------------------------------
 
*  Next Screen across
*--------------------
*  <ctrl-5> key
 
NXTSCN EQU  $
       MOV  *R7,R8            Current window
       S    R8,R2             Relative cursor
       C    *R7+,*R7+         Tricky +4 to next entry
       MOV  *R7,*R7           Terminator ?
       JLT  NXTS10            Yes - reset
 
NXTS05 A    *R7,R2            Copy to Cursor
       RT
 
NXTS10 LI   R7,WTOP           Reset to start of table
       JMP  NXTS05
 
*  Delete character
*------------------
 
DELCHR EQU  $
       CLR  @ICHRF            Cancel insert mode
       SETO @NCHAR            Insure line gets updated
       MOV  R4,R9             Copy current Curadr
       MOV  R4,R8             Again
       INC  R8                Point to next byte
DELC10 C    R8,@LINEND        Stop at end of line
       JH   DELC20            There !
       MOVB *R8+,*R9+         Shuffle back one
       JMP  DELC10            Repeat
 
DELC20 MOVB @DSPACE,*R9       Blank last character on line
       RT
 
*  End/Home cursor to File / Page  <c-J/H/L>
*-------------------------------------------
 
ENDFIL EQU  $
       MOV  @EOF,R3           To end of file
       S    @STPLEN,R3        Make sure last page is filled
       JGT  HOMCSR            Yes
 
*  Rely on screen routine if not full page
 
HOMFIL EQU  $
       CLR  R3                Start of buffer
HOMCSR BL   @UPDT10           Current line to buffer
       MOV  R3,R1             Sbias -> Cline
       CLR  R2                Cursor to start of line
       JMP  LAST90            Force refresh on way
 
*  Go to start of line <ctrl-V> without line update or refresh
 
GOTO1  CLR  R2                Cursor to left
       RT
 
*  Go to end of line   <ctrl-Z>
 
GO2END EQU  $
       MOV  @RMRG,R8          Only as far as right margin
GTE10  MOV  @LINADR,R9        Line start pointer
       A    R8,R9             Construct line buffer pointer
       CB   *R9,@DSPACE       Work back to non-space
       JNE  GTE20             Found
       DEC  R8                Back up
       JNE  GTE10             Not done yet
 
GTE20  MOV  R8,R2             Use as cursor
       INC  R2                Past the last
       RT
 
*  Find last paragraph
*---------------------
 
LASTP  EQU  $
       BL   @UPDATE           Update current line
       MOV  @DECLIN,R14       DEC Cline for FINDCR
       MOV  R1,R15            Save current line #
LAST10 MOV  R1,R1             Check if at start of file
       JEQ  NEXT99            Out of range
 
*  Look for previous paragraph
 
       DEC  R1                Previous line
       BL   @FINDCR           Find carriage return or comment line
       BL   @FINDNB           Was it on a blank line ?
       JMP  LAST10            Yup - try again
 
       MOV  R1,R1             Something there - end of last para
       JEQ  LAST35            Can't back up any more
 
*  Common routine for finding last/next <cr>
 
DECLIN DEC  R1                Start searching back in this para
LAST25 BL   @FINDCR           Find carriage return
LAST30 C    R1,@EOFM1         End of file for next para search
       JGT  NEXT99            Out of range
 
INCLIN INC  R1                Bump to next line
       BL   @FINDNB           Find first non blank
       JMP  LAST30            Line is blank, go to next
 
*  Paragraph found
 
LAST35 DEC  R4                Adjust pointer
       MOV  R4,R2             Copy buffer pointer
       S    R8,R2             Convert to line pointer
LANX40 SETO @TOPPAR           Top of paragraph flag
LAST40 MOV  R1,R3             Cline -> Sbias => Top of screen
LAST90 B    @RFSTAT           Includes screen refresh
 
*  Search error exits
 
NEXT99 MOV  R15,R1            Did not find next/last <cr>
       BL   @HONK             Sound error and restore line pointer
       JMP  LAST40
 
*  Find next paragraph
*---------------------
 
NEXTP  EQU  $
       BL   @UPDATE           Update current line
       MOV  @INCLIN,R14       INC Cline operation
       MOV  R1,R15            Save current line #
       JMP  LAST25            Go FINDCR, then FINDNB until done.
 
*  Search subroutines
*-------------------------------------
*  Find <cr>, or initial '*' in ASMode
 
FINDCR EQU  $                 Find next <cr>, or last <cr>
       MOV  R11,R6            Save return
FNCR10 BL   @GETLC            Fetch line from buffer
       JMP  NEXT99            Catches EoF
 
       MOV  @LINADR,R8        Set up pointer for search
       A    @DSIX,R8          Step past line #
       MOV  @WPMODE,R11       Check editor mode
       CI   R11,WDWRAP        Is it W/P ?
       JEQ  FNCR40            Yes - go to <cr> check
 
*  Program comment line check
 
       CB   *R8,@ASTRIX       Assembly comment line ?
       JEQ  FNCREX            Yes
       CB   *R8+,@SLASH       c-99 comment delimiter ?
       JNE  FNCR50            No
       CB   *R8,@ASTRIX       /* ?
       JNE  FNCR50            No - do next line
FNCREX B    *R6
 
*  <cr> check for paragraph
 
FNCR40 CB   *R8+,@EOT         Is it a <cr> ?
       JEQ  FNCREX            Whoopee
       C    R8,@LINEND        Line done ?
       JL   FNCR40            Not yet
 
FNCR50 X    R14               Do direction set
       MOV  R1,R1             Check for start
       JEQ  NEXT99            No more
       JMP  FNCR10            Back for next
 
*  Find non-blank within margins
*-------------------------------
*  No allowance for ASMode
 
FINDNB EQU  $
       MOV  R11,R6            Save return
       MOV  @LINADR,R4        Get next line
       A    @LMRG,R4          Move to left margin
       BL   @GETLC            Fetch next line from text buffer
       JMP  NEXT99            EoF
 
FNDN10 CB   *R4+,@DSPACE      Scan for first non-blank
       JEQ  FNDN20            Blank
       CB   @-1(R4),@EOT      <cr> then ?
       JNE  FNDN30            No - quit on this line
FNDN20 C    R4,@LINEND        End of line?
       JL   FNDN10            No
       B    *R6               Return without step-over
 
FNDN30 INCT R6                Step over next
       B    *R6
 
*---------------------------------------*
*  Reformat routine for word wrap mode  *
*---------------------------------------*
*  No reformat if not in Word wrap or Asm Mode
 
REFRMT EQU  $
       ABS  @WDWRAP           Wordwrap mode ?
       JNE  REFR05            Yes
 
*  If not wordwrap do insert of next line
 
       MOV  R11,R14           Save return
       MOV  R4,R9             Save Curadr buffer pointer
       MOV  R1,@LINENO        Current line
       INC  @LINENO           Point to next
RJ10   LI   R8,SQSBUF         Use as temp buffer
       MOV  R8,@BUFADR        Write as data
       BL   @GETL20           Fetch line & update LINENO
       B    *R14              EoF exit
 
*  Trim and test the next line
 
       LI   R8,SQSBUF+6       Start of copied line
       LI   R13,SQSBUF+85     End of copied line
RJ20   C    R8,R13            All checked ?
       JH   RJ10              Blank - try next
       CB   *R8+,@DSPACE      Space ?
       JEQ  RJ20              Yes
 
       DEC  R8                Back to first non-blank
RJ30   CB   *R13,@DSPACE      At other end - blank ?
       JEQ  RJ35              Yes
       CB   *R13,@EOT         <cr> ?
       JNE  RJ40              Must be a genuine entry
RJ35   DEC  R13               Try char before
       JMP  RJ20              Use line check to bail out
 
*  Set up insert procedure
 
RJ40   S    R8,R13            First n/b
       INC  R13               # chars to insert
       MOV  @LINEND,R0        End of cline
       MOV  R0,R6             Make copy
       S    R4,R6
       INC  R6                Max # chars to replace on cline
       C    R13,R6            How many to move ?
       JGT  RJ70              Will overrun cline - no insert
 
*  Move as insert
 
       MOV  R0,R15            Copy end pointer
       S    R13,R15           Slide alonhg from here
RJ50   MOVB *R15,*R0          Move char
       DEC  R15               Back one from end
       DEC  R0                Back towards cursor
       C    R15,R4            Done ?
       JHE  RJ50              No
 
RJ60   MOVB *R8+,*R9+         At least 1 to  move
       DEC  R13               Count off
       JGT  RJ60              More ?
       B    *R14              Yes
 
*  Move overwrites whole line
 
RJ70   MOVB *R8+,*R9+         Always 1 to move
       C    R9,R0             End of line ?
       JL   RJ70              Not yet
       B    *R14              Exit
 
 
*  Delete original text block after reformat and exit
*----------------------------------------------------
 
REFR50 EQU  $
       BL   @RESTWS           Restore workspace registers
       BL   @BUMPC            Bump cursor
       MOV  @RLINE,R12        Start of block
       MOV  @WLINE,R15        End line of block
       MOV  R15,R14           Save for marker reset
       S    R15,R12           Length
       BL   @DLLSUB           Delete and adjust marker
REFXIT B    @>0               All done now
 
*  Code from here re-written for Program Editor mode
*-----------------------------------------------------------
*  Substitute code in EE3/DATEN -->> ASMcheck, Aligned entry
*  UPDATE comes via this new code in ASMode - & uses R14 !!
 
 
ASMPOS EQU  $-2               REF for ASMode overwrite
REFR05 MOV  R11,R14           Save return
       BL   @UPDATE           Update current line in text buffer
       MOV  R1,@RLINE         Save line pointer
       CLR  @RSTRNG           No replace string
       BL   @GETDAT           Get next line from text buffer
       B    *R14              EoF exit - no work to do
 
*  Entry from REPLCE string to reformat or drop through
 
RENTRY EQU  $
       MOV  R14,@REFXIT+2     Save return from either entry
       CLR  @GOLF             Clamp margins
       CLR  @MFLAG            No marker yet
       CLR  @CRFLAG           Get out of wrap mode
       MOV  R9,R12            Preserve R9 from GETDAT over SAVEWS
       BL   @RESTAB           Restore margins
       BL   @SAVEWS           Save current screen pointers
       MOV  R12,R9            Restore R9 pointer
       MOV  R1,@WLINE         Current line as next to write
       INC  R1                Update Cline to next
       MOV  R1,@RLINE         Next line to read
 
*  Initialize pointers on current line
 
       MOV  R2,R8             Copy current cursor offset
       ABS  @SWSF             Insert mode or replace string?
       JNE  REFR10            Yes, ref from current cursor
 
       MOV  @DSIX,R2          No, reformat entire line.
       MOV  @INDT,R8          Set up for top of paragraph.
       ABS  @TOPPAR           Top of paragraph?
       JNE  REFR20            Yes
 
       MOV  @LMRG,R8          No, adjust margin.
       JMP  REFR20
 
*  Reformat from current cursor
 
REFR10 MOV  @WLINE,@LINENO    This is the next line
       MOV  @TPM6A,@BUFADR    To temp buffer
       BL   @GETL20           Fetch it from text buffer
       JMP  REFXIT            EoF reached
       LI   R14,TEMPM6        Start of TMP buffer
TPM6A  EQU  $-2
       MOV  R14,@DESSAV       Copy TMPline buffer start
       A    @LMRG,@DESSAV     Adjust to left margin for destination
       A    R8,R14            Current cursor as offset
       LI   R6,86             Buffer length
       S    R8,R6             Remaining # of bytes to blank
       BL   @CLRT10           Blank TMPBF to end from cursor
 
*  Reformat from start of line or continue
 
REFR20 MOV  R2,R4             Cursor pointer on line
       AI   R4,REPBM6         Make pointer into REP buffer
       LI   R14,TEMPM6        Destination pointer
       MOV  R14,R10           Copy start
       A    @RMRG,R10         Construct end pointer
       A    R8,R14            Start as offset already set up
       CLR  @SWSF
       DEC  R14               Back off to previous byte
 
*  Get next word
*---------------
 
GETNWD EQU  $
       CLR  R0                Start counter
       MOV  R4,R13            Copy cursor pointer into REPBuf
GETN10 BL   @UPDCSR           Check cursor pointer against MARKER
       C    R13,R9            End of line in REPBuf yet ?
       JL   GETN20            No
 
*  Need the next line
 
       BL   @GETDAT           Yes, get a new line and reset
       JMP  GETN35            No more data, end of file
 
GETN20 CB   *R13+,@DSPACE     Scan for non blank character
       JEQ  GETN10
 
       DEC  R13               Back off to first non-space
       MOV  R13,R4            Copy
       CB   *R13,@EOT         Was it a <cr> ?
       JNE  GETN40            No
 
       INC  R14               Next position for target
GETN30 MOVB *R13,*R14         Put the <cr> in new record
       JMP  PUTN10            Go deal with the line
 
GETN35 LI   R13,EOT           Fake source as <cr> for EoF
       JMP  PUTN10            Done with line
 
*  Get next word from following line
*-----------------------------------
 
GETN40 BL   @UPDCSR           Reached marker now ?
       C    R13,R9
       JHE  GETN45
 
       CB   *R13,@DSPACE      Scan for end of word
       JEQ  GETN50            Found it
       CB   *R13+,@EOT        Check for end of text char
       JNE  GETN40            Found it
       JMP  GETN50
 
GETN45 CB   *R13,@DSPACE      Last character a blank?
       JEQ  GETN50            Yes
 
       INC  R13               No, INC R13 before calc room
GETN50 MOV  R13,R15           ROOM
       S    R4,R15
 
*  Fetch next word
 
PUTNWD MOV  R10,R12           Copy destination end pointer
       S    R14,R12           R12 - DESPTR = Room left
       C    R15,R12           ROOM for next word?
       JLT  PUTN20            Yes
 
       C    R14,@DESSAV       Special case of first long word.
       JEQ  PUTN20
 
*  Done with line
*----------------
 
PUTN10 EQU  $                 Out of room so:
       MOV  @WLINE,@LINENO    Flag this line
       BL   @INSL10           Insert into text buffer
       INC  @RLINE            One done -source
       INC  @WLINE            One done - target
       BL   @CLRTMP           Clear temp buffer
       LI   R14,TEMPM6        TMP buffer start
       MOV  R14,R10           Copy buffer start
       A    @LMRG,R14         Advance to left margin
       DEC  R14               Allow for the blank bump
       MOV  R14,@DESSAV       Preserve start pointer
       A    @RMRG,R10         Set to right margin
       CB   *R13,@EOT         Was R13 End of Text ?
       JNE  PUTN20
       B    @REFR50            Yes -  make final exit now
 
*  Construct rest of TMP buffer contents
 
PUTN20 EQU  $
       INC  R14               Allow 1 blank between words
PUTN30 MOVB *R4+,*R14+        Move word to temp buffer
       DEC  R15               Less ROOM
       JGT  PUTN30
 
       ABS  @MFLAG
       JEQ  PUTN35
 
       MOV  @WLINE,@SREGS     Hit marker, save cline
       MOV  @WLINE,@SREGS+4   Make sbias=cline
       MOV  R4,R6
       S    @MARKER,R6        count # past marker.
       MOV  R14,R2            DESPTR -> new cursor
       S    @TPM6A,R2         Save new cursor.
       S    R6,R2             R6 < ROOM always!!!!
       MOV  R2,@SREGS+2       Update stored Cursor
       CLR  @MFLAG
PUTN35 MOV  R4,R13
       DEC  R13
       CB   *R13,@PERIOD
       JNE  PUTN33
 
       CB   @2(R13),@DSPACE
       JNE  PUTN33
       INC  R14               DESPTR
PUTN33 CB   *R13,@EOT         End of text marker?
       JEQ  PUTN10            Yes, update line, exit
       B    @GETNWD            No, get next word.
 
*  Check against marker
*----------------------
 
UPDCSR EQU  $
       C    R13,@MARKER       Update cursor for replace string.
       JNE  UPDC10            Not at marker
 
       SETO @MFLAG
UPDC10 RT
 
*  Set up data for Replace buffer
*--------------------------------
*  Load next line into first part
 
GETDAT EQU  $
       CLR  @MARKER           Set marker to start
       MOV  @RADR,R13         Start of REPbuf
       MOV  R13,R9            Copy start
       AI   R9,79             Construct end pointer
       MOV  R13,R4            Copy start pointer
       MOV  @RPM6A,@BUFADR    Start of REPbuf as fetch target
       MOV  @RLINE,@LINENO    Line # for TBuf fetch
       BLWP @GETLN            Get line from Text buffer
       MOV  R0,R0             End of file?
       JNE  GETD10            Yes
 
       INC  @RLINE            No, count this line
       INCT R11               Step over error return
GETD10 RT
 
*-------------------------------------------
 
