 
*  EE2/ENTHI    40 col        Jul / 11 / 93
*---------------------
*  Minimum Function
 
*-------------------------------------------*
*  Entry routine at end of existing EDITOR  *
*-------------------------------------------*
 
HIBUF  EQU  $
WPC12  EQU  6*40+5
 
*  Entry routine
*---------------
 
       LWPI FWREG             Use FW Regs for now
       BL   @SETVR1           VWTR + pad load
       DATA >B081             TM1 screen off
       MOV  @CPUDEL,@DELVAL   Set sound/delay duration
       SLA  R13,3             Flag Editors for FW
       MOV  @INCOL,@COLCH     Fetch FW color index
       MOV  @COLRS,R1         Color pointer in FW
       LI   R2,TWCOLS         Pointer to color choices in ED
EDNT1  MOV  *R1+,*R2+         R1 preloaded to FWB color list
       CI   R2,TWCOLT
       JL   EDNT1
 
*  Move fast code to PAD
 
       LI   R1,PAD01          Data in program header
       LI   R2,FASTVW         Fast code data
MVFS10 MOV  *R1,*R2+
       CI   R2,FASTVW+38      Expand loop
       JL   MVFS10
 
MVFS20 MOV  *R1+,*R2+         Continue with next bit
       CI   R1,FCEND
       JL   MVFS20
 
*  Fetch user defined VDP values
 
       MOVB @HELPLD,@HPMAX
       LI   R1,PCENTY         Point to 2 byte block
       MOVB *R1+,@PCCENT      Printer entry control
       MOVB *R1,@PCCEXT       Printer exit control
       BLWP *R9               Set >1F midline pattern
       DATA >8F8,ULNDTA,8
 
*  Check for Select screen
 
CHKEYB BLWP @KSCANF           Do a keyscan
       CB   @KEYRT,@DSPACE    Check return for space-bar
       JNE  NOQUIT            Go to language screen
 
*  Editor / Language selection
 
       LWPI FWREG             In case of <esc> to here
       LI   R0,>2000          Space
       BLWP *R8               VFILF
       DATA >0,40*24          Text- mode screen
       BL   @SETVR1           Turn screen on again
       DATA >F081
       BLWP *R9
       DATA 2*40+5
       DATA SLMS10,SLML10
       MOVB @UDLINE,R0        ED underline
       BLWP *R8
       DATA 3*40+5,SLML10
       BLWP *R9
       DATA WPC12
       DATA SLMS20,SLML20
       BLWP *R9
       DATA 2*40+4+WPC12
       DATA SLMS21,SLML21
 
*  Select W/P or P/E
 
       SETO R4                Initialize with flag for Pr/Ed
WPEDC1 BLWP @FILENT           Wait for response
       DATA WPC12,1
       MOVB @FLNBFF,R0        Fetch return
       CB   R0,@INTGRS+1      Is it < "1" ?
       JLT  WPEDC1            No
       CB   R0,@INTGRS+2      Is it "2" or "1"
       JH   WPEDC1            No - loop on it
       JEQ  NEUWRT            P/E so leave as is
 
       CLR  R4                Flag W/P then
 
*  Turn off screen again E/W or no
 
NEUWRT BL   @SETVR1           Turn screen off again
       DATA >B081
 
*  Shut off <Quit>
 
NOQUIT LI   R0,>2000          Clear screen
       BLWP *R8
       DATA 0,960
       SOCB @MASK10,@>83C2    Set flag bit
 
*  Fix up PABdata for Help file loads
 
       LI   R10,NAMBUF        FW name buffer
       LI   R3,PABHLN
       MOVB *R10,R0           Fetch it - includes 2 letter filename
       SRL  R0,8              Make index
       DEC  R0                Includes length byte and "."
       AB   @BYT4,*R10        Adjust for 6 char filename
CFT10  MOVB *R10+,*R3+
       DEC  R0
       JGT  CFT10
 
       LI   R0,6               Move filenames into place
       LI   R14,HLPFLD
CFT20  MOVB *R14+,*R3+
       DEC  R0
       JGT  CFT20
       DEC  R3
       MOV  R3,@INXADR
 
*  Clean storage buffers also
 
RSMSCL MOV  @FILCLN,R11       Cleanup routine pointer
       CLR  R0                Turn off EDBUF load
       BL   *R11              Execute it
       MOV  @CFILE#,R11       Fetch routine entry
       BL   *R11
       DATA >0100             Only 1 needed at a time
       LI   R0,>2020
       BLWP *R8
       DATA RSMSV,LOCLRV-RSMSV
 
*  Stash FWB in upper VDP
 
       MOV  @CMRET,R11        Ready for return
       BLWP *R9               VMBWD
       DATA FWSTOR
       DATA FWPOSN,FWBLEN
 
*  Save command and switch tables in VDP
*  Switch tabs and screen message
*--------------------------------
 
       LI   R2,FRMWP          W/P TAB table
       MOV  R4,R4             Need to change <fctn-2> entry ?
       JEQ  WCTABL            No
 
       LI   R2,FRMPE          Adjust TAB table source pointer
       MOVB @MS28A,@MS27A     Switch screen ID
       MOVB @MS28B,@MS27B
       SZCB @H0F,@NOTABS      Make the JNE a JMP
       LI   R10,REFR05        ASM code block real position
       AI   R10,PRETTY        Offset to aligned insert
       MOV  R10,@FCTINS       Write to command table  <c-M>
       AI   R10,PRDOF1        Offset to aligned insert
       MOV  R10,@FCTDEL       Write to command table  <c-2>
       AI   R10,PRDOF2        Offset to aligned insert
       MOV  R10,@PRTB12       Write to code block for BL @xxxx
       MOV  R10,@PRTB22       Write to code block
WCTABL BLWP *R9               VMBWF
       DATA COMVE             VDP storage
       DATA CTBL,TABLEN       Consecutive tables
       LI   R0,22             Size of Tab table
       LI   R1,FORMO          Target address in hi-mem
PETAB  MOV  *R2+,*R1+
       DECT R0
       JGT  PETAB
 
*  Write in new commands
 
       MOV  @TEXT+CMLPT,R1    Point into offset table
       AI   R1,TEXT           Construct memory pointer
       LI   R0,CMDTBL
NXCOMD MOV  *R1+,*R0
       AI   R0,CMDTE
       CI   R0,CMDTND
       JL   NXCOMD
 
       MOV  *R1+,*R0+         8 byte entries on word bdy
       MOV  *R1+,*R0+
       MOV  *R1+,*R0+
       MOV  *R1+,*R0
       LI   R0,EOFLIN         For EoF indicator
       MOV  *R1+,*R0+
       MOVB *R1,*R0
 
*  Set up RS Verify message in VDP first
 
RSVWRI LI   R0,RSMSV          RS verify message
       MOV  @TEXT+RSMSP,R1    Get offset in message file
       AI   R1,TEXT           Make absolute address
       MOVB *R1+,R2           Length byte
       SRL  R2,8              Make count
       BLWP @VMBWR            FW's standard VMBW
 
*  Expand tab lines in CPU buffer - write over following items
 
       MOV  @TEXT+MMTPT,R1    Get offset from index table
       AI   R1,TEXT+7         Correct to CPU RAM pointer
       MOV  R1,R11            Copy
       AI   R11,80            Construct end pointer
NXDECA LI   R2,INTGRS         Integer block
NXDECB MOVB *R2+,*R1+         Copy it
       CI   R2,INTGRS+10      Done ?
       JL   NXDECB            Not yet
 
       C    R1,R11            Whole line done ?
       JL   NXDECA            No
 
       LI   R0,>2000          For writing spaces
       MOVB R0,*R1+           Write in blanks
       MOVB R0,*R1+           Word align not guaranteed
       MOVB R0,*R1+
 
       LI   R2,NBLNM3        More blanks and bare tab line
NXDECC MOVB *R2+,*R1+
       CI   R2,NBLEND
       JL   NXDECC
 
*  Text messages to VDP
 
       MOV  @TEXT+TXTRAN,@TXTRNL
       BLWP *R9
       DATA TEXTV
       DATA TEXT
TXTRNL DATA >0
 
*  L/S module to VDP storage
 
       BLWP *R9               Store printer codes
       DATA PCEBUV
       DATA PCEDAT,48         Include DSKBUV
       BLWP *R9               Write block to VDP
       DATA LSMODV
       DATA OVRLAY,LSLEN
 
*  Stash SD code & make cursor
 
       BLWP *R9
       DATA SDATV             SD code to VDP
       DATA SDATA,SDLEN
       BLWP @VMBRF
       DATA FCSRP,FCSR,8
 
*  Change to TI-Wr Edit workspace
*  Clear out command table area
*------------------------------------------
*  All data must have been retrieved by now
 
       LWPI SCNWS             Can't use FWREG
       LI   R2,SCLR
COCT   CLR  *R2+              Clear for first entry
       CI   R2,PARBLK         TWO now shifted out of road
       JL   COCT
 
*  Set up screen messages
 
       LI   R10,MSG24         Message pointer
       MOV  R10,@LINT46       Line 17
       AI   R10,86            Underline
       MOV  R10,@LINT48       Line 18
 
*  Set up blanked area in hi-mem
 
       LI   R0,>2020          Word of spaces
       LI   R1,MSG24          Blank area for initial messages
EDNT3  MOV  R0,*R1+
       CI   R1,MSG24+>A6      Enough for 2 display lines
       JL   EDNT3
 
*  Move common message text into blanked area
 
       LI   R2,>1F00
       LI   R1,MSL26
EDNT4  MOVB @MSG26-1(R1),@MSG24+8(R1)
       MOVB R2,@MSG24+8+86(R1)
       DEC  R1
       JGT  EDNT4
 
*  Variations for side
*---------------------
 
       SETO @WDPROC           Initialize for W/P
       MOV  @FWREG+8,R4       TI-Wr or Pr/Ed  ?
       JEQ  MCP20             Wd/Pr
 
*  Program Editor entry details
*------------------------------
*  Replace wordwrap cursor & reformat code
 
 
       LI   R1,8
NWCS10 MOVB @ACSR-1(R1),@WCSR(R1)  Allow for len byte @WCSR
       DEC  R1
       JGT  NWCS10
 
       LI   R1,ASMLEN
NWCS20 MOV  @ASMCM2(R1),@ASMPOS(R1)
       DECT R1
       JGT  NWCS20
 
       LI   R11,UPDA12
       MOV  @BRINS,*R11+
       LI   R1,REFR05
       MOV  R1,*R11
       CLR  @WDPROC
       SETO @LINF
       LI   R15,WORDW
       LI   R1,ASPARS
       JMP  MCP30
 
*  Word processor entry details
*------------------------------
 
MCP20  LI   R1,WDWRAP         To set wordwrap
       LI   R15,START         WP entry
       SETO @CRFLAG           Initialize
       CLR  @LINF
 
*  Common continuation
 
MCP30  SETO *R1               Set appropriate flag
       MOV  R1,@WPMODE        Set WP/PE flag
 
*  Fill VDP Tab buffer with 3 copies
 
       LI   R14,TABBUV        Start of TAB storage
WRMPLT MOV  R14,R9            Running pointer
       LI   R8,FORMO          Current tabset
       BL   @VMBWL            Write a copy to VDP
       DATA 22
       AI   R14,22            Advance VDP pointer
       CI   R14,3*22+TABBUV   Check all done
       JL   WRMPLT            Not yet
 
 
*  Fetch printer name from FW
 
       MOV  @EDPRNT,R8        Get name pointer
       BL   @VSTRV            Write to VDP
       DATA DEVBUV
       MOV  @EDPRNT,R8        Copy for SD Printer also
       BL   @VSTRV
       DATA PSDBUV
 
*  Further Initialization
 
       LI   R1,FORMO          Format table pointer
       MOV  *R1,@LMRG         Set left margin
       MOV  *R1+,R2           Set initial cursor there
       MOV  *R1,@RMRG         Right Margin
       MOV  @SSNLEN,@SCNLEN   Screen length default
       MOV  @CPUADR,@TOPSCN
       BL   @PURGF            Initialize - no lines
       CLR  R5                Char
       BL   @WINDOW
       B    *R15              Preloaded
 
*  Reset path first time round main loop
*---------------------------------------
 
SECOND SETO @REFRSH           Replacement inst'n data
 
FIRST  EQU  $
       LI   R11,RWBRN         Point to first-time branch
       MOV  @SECOND,*R11+     Replace with new instruction
       MOV  @SECOND+2,*R11    And the next word
       BL   @SETVR1           Makes a VWTR
       DATA >F081
BRINS  B    @COMAND           Set command mode
 
*---------------------------------------------------------
 
