 
*  ED2/VIDEO                  May / 13 / 95
*------------------------------------------
*  General VDP handling routines
*  Edit ring, Exit code
 
*  BLWP vector table
*-------------------
 
SETVDW DATA FAC+4,STVW10      Register free SetWDA
SETVDR DATA FAC+4,STVR10      Register free SetRDA
FVLFIL DATA FAC+4,FVFL00      Fast LLL VFILL
FVINIT DATA FAC+4,FVIN00      Fast VINIT
BOX    DATA FAC+4,BOX00       Box clear/outline
RJCONV DATA FAC+4,RJCN00      Right justified int -> dec
BLOCMM DATA BLOCWS,BLOC00     Block marking code
SHOFRZ DATA BUFMWS,SHOF80     Screen control - BLWP vector
WRISEL DATA OVRWSP,WRISLC     Write up and select
SHOEDT DATA OVRWSP,SHOE00     Display only of window list
PUSHDN DATA OVRWSP,PUSHVF     Push down View list
REPEDW DATA OVRWSP,RPED00     Replace Edit window entry
 
 
*  Move indexed string to CPU RAM
 
MVISTR EQU  $                 Preserve return
       AI   R9,TEXTV          VDP table start
       BLWP @SETVDR           Set read address
       MOVB @VDPRD,R9         First byte of string pointer
       SWPB R9                To LSByte
       MOVB @VDPRD,R9         Second byte of string pointer
       SWPB R9                To regular address
       AI   R9,TEXTV          Offset from table start
 
*  External Vstring read entry (R9 - VDP string pointer)
 
VSTGRD BLWP @SETVDR           Set to read string length
       MOVB @VDPRD,R6         Fetch string length byte
       SRL  R6,8              Make count
       JEQ  MOVE50            Ignore if null
       JMP  MOVE40            Do the move
 
*  Data or Register VMBR from here
 
MOVE   MOV  *R11+,R9          VDP pointer
MOVF   MOV  *R11+,R8          CPU target
MOVG   MOV  *R11+,R6          Count
MOVE05 BLWP @SETVDR           Set VDP read address
MOVE40 MOVB @VDPRD,*R8+       Fetch byte
       DEC  R6                Count off
       JGT  MOVE40            More
MOVE50 RT
 
*  Toggles on VRegs #8 & #9
*--------------------------
 
TOGLBL EQU  $
       LI   R14,>8000         Set bit mask
       JMP  TOGL              Go adjust VR9
 
TOGLNP EQU  $
       LI   R14,>0200         *NT bit
       JMP  TOGL
 
TOGLIL EQU  $
       LI   R14,>0800         IL bit
TOGL   LI   R8,V9SAV          VR9 storage
       MOV  *R8,R9            Fetch current saved value
       XOR  R14,R9            Toggle bit
       MOV  R9,*R8            Store again
       JMP  SETRDB            Go set VReg
 
*  Color switches
*----------------
 
TOGBCL EQU  $
       LI   R6,BCOLC          Command line color index
       JMP  COLX10
 
COLORC EQU  $
       LI   R6,COLCH          Main screen color index
COLX10 INC  *R6               Next one
       C    *R6,@TENS         Ten ?
       JNE  NXCOLX            No
       CLR  *R6               Reset cycle
NXCOLX MOV  *R6+,R9           VReg #
       MOVB @TWCOLS(R9),*R6   Color list
       MOV  *R6,R9
       JMP  SETRDB            VWTR - bypass SWPB
 
*  Set VDP Read/Write/Register
*-----------------------------
 
SETWDA EQU  $                 Use >00 as null data later
       ORI  R9,>4000          Write vdp address for write
SETRDA SWPB R9                Write vdp address for read
SETRDB MOVB R9,@VDPWA         Use as entry for SETVRG
       SWPB R9
       MOVB R9,@VDPWA
       RT
 
*  Register free VWTR call
 
SETVR1 EQU  $
       MOVB *R11,@>83D4       For VR1 console key data
SETVRG MOVB *R11,@VDPWA       First byte - value
       INC  R11               Time waster
       MOVB *R11+,@VDPWA      Second byte - register
       RT
 
*  BLWP Versions to avoid register use
*-------------------------------------
*  Workspace in FAC/DSR area
 
STVW10 MOV @R9+R9(R13),R9     SETVDW from R9
       BL  @SETWDA
       RTWP
 
STVR10 MOV  @R9+R9(R13),R9    SETVDR from R9
STVR20 BL   @SETRDA
       RTWP
 
*  All registers VMBW
 
VMWREG BLWP @SETVDW
VMRG10 MOVB *R8+,@VDPWD
       DEC  R6
       JGT  VMRG10
       RT
 
*  Data VMBWD as BL routine
 
VMBWD  MOV  *R11+,R9          For VDP address
VMBWE  MOV  *R11+,R8          For CPU address
VMBWL  BLWP @SETVDW           Set for write
       MOV  *R11+,R9          Now for count
       JMP  VMBW10            Faster loop code in PAD
 
*  String writing variation
 
VSTRU  MOV  *R11+,R8          Get CPU string pointer
VSTRV  MOV  *R11+,R9          VDP target
VSTRW  BLWP @SETVDW           R9 = vdp address
       MOVB *R8+,R9           First byte of date = length
       SRL  R9,8              Make word count
       JEQ  VF99              Bail out if null
VMBW10 B    @FLOOPC           Faster loop code in PAD
 
* VMBW10 MOVB *R8+,@VDPWD       Write date using length byte
*        DEC  R9                Tick off
*        JGT  VMBW10            All done ?
* VMBW20 B    *R11              Return
 
 
*  VFILL - VDP fill from MSB of R8
*---------------------------------
*  Count in R6, VDPA in R9
 
VFILI  LI   R8,>2000          Load with blanks
VFILJ  MOV  *R11+,R6          Count data
VFILK  MOV  *R11+,R9          VDP pointer data
VFILL  BLWP @SETVDW           Set write address
VF1    MOVB R8,@VDPWD         Write byte
       DEC  R6                Tick off
       JNE  VF1               Do it again
VF99   B    *R11
 
*  Switch VDP banks for R/W
*--------------------------
 
NULL   EQU  SETWDA+3          Convenient data
 
BANK0  EQU  $
       MOVB @NULL,@VDPWA      Set lowest bank for DSR use
       JMP  BANKT             Does for delay too
 
BANK1  EQU  $
       MOVB @ONE,@VDPWA       Set first bank
       JMP  BANKT
 
BANK2  EQU  $
       MOVB @TWO,@VDPWA       Set second bank
       JMP  BANKT             DELAY
 
*  Set Vbank and R/W address from R0 pointer
 
SETBAD EQU  $
       MOV  R0,R9             Copy 64K buffer pointer
       ANDI R9,>3FFF          Mask off address in bank
       ANDI R0,>C000          Leading 2 bits give Vbank #  0-3
       SRL  R0,6              Make MSByte index in R0
       AI   R0,>0400
BANKR0 MOVB R0,@VDPWA         Use MSB of R0
BANKT  NOP                    EXTRA delay
       MOVB @H8E,@VDPWA       Specify VR #14
       RT
 
*  Fast line VFILL with 80 spaces in inline code
*-----------------------------------------------
 
FVFL00 EQU  $
       MOV  @R9+R9(R13),R9
FLVL10 BL   @SETWDA
       LI   R10,VDPWD
       MOV  @DSPACE,R12
       BL   @FVBLOK           Inline code
       RTWP
 
*  Fast VINIT at PABBAD
 
FVIN00 EQU  $
       MOV  @PABBAD,R9
       JMP  FLVL10
 
*  Convert integer to RJ decimal - suppress leading zeros
*--------------------------------------------------------
*  Call as  LI   R8,2*(# of digits)
*           LI   R9,integer
*           BLWP @RJCONV
 
RJCN00 MOV  @R8+R8(R13),R12   Fetch # digits
       MOV  @R9+R9(R13),R9    Save R10 contents
       LI   R10,RJF#          Buffer
       BL   @NXDIG            BufMgr routine
       LI   R10,RJF#          Suppress
RJ3    CB   *R10,@ZERO        leading
       JNE  RJ4               zeros
       CI   R10,RJF#3         except
       JEQ  RJ4               for
       MOVB @DSPACE,*R10+     last.
       JMP  RJ3
RJ4    RTWP
 
*  Color screen freeze lines
*--------------------------------------
*  Use only scratch registers in BUFMWS
 
SHOF80 EQU  $
       MOV  *R13,R8           Copy line count from caller's R0
       MPY  @TENS,R8          Calc offset into line table
       AI   R9,COLTB1         Absolute pointer for VFILL
       LI   R6,COLTB1+>F0     Down to line #24
       S    R9,R6             Bytes to change
       JEQ  SHOF82
       MOV  @16(R13),R8       Fetch set or clear
       BL   @SETVRG           Set VRAM bank
       DATA >018E             Where COLTB1 lives
       BL   @VFILL            Fill bottom of page
       BL   @SETVRG           Back to base VBank
       DATA >008E
SHOF82 RTWP
 
*  Block marking/copying routine
*----------------------------------------------------
*  R6,R7 top of mark (0-21), top of area after (1-22)
*  R8,R9 scratch, R10 max-size, R12 block-size
*  R11 BL & temp, R13-R15 BLWP
 
BLOC00 EQU  $
       CLR  R6                Initialize upper block limit
       CLR  R7                Lower too
       BL   @VSTRU            Write up help message
       DATA LHELPM            Data pointer
       DATA LLL-LHMLEN-2      Screen position (base >0000)
BLOC10 INC  R7                Start or increase block
BLOC20 MOV  R7,R12            Copy past-block pointer
       S    R6,R12            Construct current mark length
 
* Paint mark on screen
 
BLOC30 BL   @BANK1            Color table is in VB #2
       LI   R9,COLTB2+20      Start at line 2 in color table
       BL   @SETWDA           Set write
       MOV  R6,R8             Copy start pointer on screen
       JEQ  BLOC40            No area above mark
       BL   @MARCLR           Upper area to primary colors
BLOC40 MOV  R12,R8            Copy mark size
       JEQ  BLOC50            No mark
       SETO R0                Set for secondary color
       BL   @MARSET           Color mark
BLOC50 MOV  R10,R8            Copy end of page pointer
       S    R7,R8             Size of post-mark on page
       JEQ  BLOC60            None
       BL   @MARCLR           Set to primary color
BLOC60 BL   @BANK0
       MOV  R12,R12           Was there any mark
       JEQ  BLOC99            No
 
*  Key control loop
 
GTMK00 BL   @KMDELY
GTMK20 BLWP @SCANKY           Check keyboard
       LI   R11,>0010         Start to construct JMP
       LI   R8,MBKTAB-1       Initialize comparison pointer
GTMK30 INC  R8                Next entry
       CI   R8,MKTBND         All done ?
       JH   GTMK20            Yes
       CB   @KEYRT,*R8+       Match entry ?
       JNE  GTMK30            No - advance
       MOVB *R8,R11           Get JMP span
       SWPB R11               Make JMP instruction format
BLCJMP X    R11               Execute JMP
 
*  Move/shrink block up
 
BLCE10  MOV R6,R6             At top already ?
        JEQ GTMK00            Yes
        DEC R6
BLC610  DEC R7                Shrink (R7>R6 during mark)
        JMP BLOC20
 
*  Move block down
 
BLCX10 C    R7,R10            Bottom at end ?
       JHE  GTMK00            Get another key
       INC  R6                Top down one line
       JMP  BLOC10            Bottom also and re-color
 
*  Expand towards bottom
 
BLC410 C    R7,R10            Bottom at end ?
       JHE  GTMK00            Key again
       JMP  BLOC10
 
*  Copy mark to clipboard
 
BLCC10 CLR  R7                Offset in clipboard
       MOV  R12,@MLINT        Copy for ReCall reference
BLCC15 AI   R7,COPASB         Adjust to clipboard
       MOV  R6,R8             Copy start line pointer
       INCT R8                Starts 2 lines down on screen
       MOV  R8,R2             Find start of buffer text
       MPY  @D86,R2           Offset in text buffer
       AI   R3,CPUSCN         Text buffer pointer
       MPY  @D80,R8           Convert to byte on screen
       MOV  R5,R5             Check for offset as flag
       JNE  BLCC25            Must be from Edit
 
*  Fetch from screen for COpy from View
 
BLCC20 BL   @SETRDA           Set for read
       LI   R6,LLL            Line length
D80    EQU  $-2               Handy data
       A    R6,R9             Update VDP pointer
BLCC30 MOVB @VDPRD,*R7+       Read out to clipboard
       DEC  R6                Count
       JGT  BLCC30            Done ?
       DEC  R12               Count off line
       JGT  BLCC20            More of mark to copy
       JMP  BLC020            All done
 
*  Fetch from CPU buffer
 
BLCC25 A    R5,R3             Skip over line # in buffer
       LI   R6,LLL
BLCC35 MOV  *R3+,*R7+         Copy words
       DECT R6                Do 2 bytes at a time
       JGT  BLCC35
       DEC  R12               Count off line
       JGT  BLCC25            More of mark to copy
       JMP  BLC020            All done
 
*  Append if enough space
 
BLCA10 LI   R0,MLINT          Point to size in buffer
       MOV  *R0,R11           Copy current contents
       A    R12,R11           Add new mark
       CI   R11,22            Check for size
       JH   GTMK20            Do not allow
       MOV  *R0,R8            Copy current
       MPY  @D80,R8           Calculate buffer offset
       MOV  R9,R7             Copy to buffer offset
       A    R12,@MLINT        Update content info
       JMP  BLCC15            Join copy and exit
 
*  Exit - escape, copy done
 
BLC010 BL   @KMDELY           Delay
BLC020 CLR  R6                Force null block and screen clear
       CLR  R7
       JMP  BLOC20            Clear mark
BLOC99 RTWP
 
*  Write to color table
 
MARCLR EQU  $
       CLR  R0                Clear to primary colors
MARSET MPY  @TENS,R8          10 bytes per line
MARS10 MOVB R0,@VDPWD         Write for 8 chars
       DEC  R9                Count off
       JGT  MARS10            More
       RT
 
KMDELY EQU  $
       MOV  @DELVAL,R8        Calibrated delay
GTMK10 DEC  R8                Delay count
       JNE  GTMK10            More
       RT
 
*  Key and jump tables
 
MXBLOC DATA 22                Max block sixe
MBKTAB BYTE >83               <c-C>  escape
       BYTE BLC010-BLCJMP-2/2
       BYTE >0F               <f-9>  escape
       BYTE BLC010-BLCJMP-2/2
       BYTE >0B               <f-E>  block up
       BYTE BLCE10-BLCJMP-2/2
       BYTE >0A               <f-X>  block down
       BYTE BLCX10-BLCJMP-2/2
       BYTE >02               <f-4>  expand
       BYTE BLC410-BLCJMP-2/2
       BYTE >0C               <f-6>  shrink
       BYTE BLC610-BLCJMP-2/2
       BYTE '|'               <F-A>  append
       BYTE BLCA10-BLCJMP-2/2
MKTBND BYTE >60               <f-C>  copy and exit
       BYTE BLCC10-BLCJMP-2/2
LHELPM BYTE LHMLEN
       TEXT ' <f-4X6E><f-CA>'
LHMLEN EQU  $-LHELPM-1
       EVEN
 
*  Box outline data
*-------------------
 
BOXTD  DATA 6,>AC00,>AA11,>AF00
BOXBD  DATA 6,>AE00,>AB11,>B100
BOXTPW EQU  BOXTD+5
BOXBTW EQU  BOXBD+5
 
VWLP0  EQU  4*LLL+8           Screen pointer for box UL
VWLP1  EQU  VWLP0+LLL+2       Offset into box
VWLSIZ EQU  >3208             Inner size of box
VWRSP  EQU  4*86+8+CPUSCN     Pointer in screen buffer
VWRLL  EQU  >32+2             Length to restore
VWRL#  EQU  10                # of lines to restore
 
*  Workspace for UNPACV
*----------------------
 
UNPAWS EQU  $
       DATA >0                R0   Uesd by UNPACV
       DATA >0                R1   "
       DATA >0                R2   "
BOXSD  DATA 6                 R3   Side data
       DATA >AD00             R4
       DATA >2011             R5
       DATA >B000             R6
UNPACV DATA UNPAWS            R7   BLWP vector
UNPENT DATA UNPAC1            R8   "
       DATA >0                R9   for SETWDA
       DATA SETWDA            R10  byte saver
       DATA >0                R11  for BL return
       DATA VDPWD             R12  byte saver
       DATA >0                R13
       DATA >0                R14
       DATA >0                R15
BOXSDW EQU  BOXSD+5
 
*  Overlay workspace
*-------------------
 
OVRWSP EQU  $
       DATA >0,>0,>0,>0
       DATA LINBUF            R4       Permanent data
       DATA '1.'              R5       Permanent data
       DATA >0                R6       Counter for VM BLs
       DATA >0                R7       Range check
       DATA >0,>0             R8,R9    Pointers for VM
       DATA LLL               R10      Permanent data
       DATA >0                R11      BL
       DATA >0                R12      Use for index
       DATA >0,>0,>0          R13-R15  BLWP return
 
*  Code for various outlined box functions
*-----------------------------------------
*  Can use as overlay from here on
 
*  UNPACV for RLE data to VDP
*----------------------------
*  Call as LI   R0,VDPtr
*          BLWP @UNPACV
*          DATA Data-list  starting with # bytes (2 x entries)
 
UNPAC1 EQU  $                 16 w -----
       MOV  *R13,R9           Fetch screen address
       MOV  *R14+,R0          Fetch list pointer
       BL   *R10              SETWDA from R9
       MOV  *R0+,R11          First word is count of bytes in list
       JEQ  UNPAC5            Null - quit while ahead
UNPAC2 MOVB *R0+,R2           First byte of word is byte for VDP
       MOVB R2,*R12           Write it
       MOVB *R0+,R1           Second is # of repetitions
       SRL  R1,8              Word adjust
       JEQ  UNPAC4            No repeats - count off entry
UNPAC3 MOVB R2,*R12           Write to VDP again
       DEC  R1                Count off
       JGT  UNPAC3            More left
UNPAC4 DECT R11               Count off entry
       JNE  UNPAC2            Not done yet
UNPAC5 RTWP                   ALL done
 
*  BOX Drawing routine
* --------------------
*  Call as  BLWP @BOX
*           DATA VDPtr
*           DATA <horiz,vert>  as inner size
*  Uses     R0,R1
 
BOX00  EQU   $                28 w -----
       MOV  *R14+,R0          Fetch VDP pointer for UR corner
       MOV  *R14+,R1          Horiz/Vert inner size
       SB   @ONE,R1           Count is # repetitions horizontally
       MOVB R1,@BOXTPW        Write in (inner width - 1)
       MOVB R1,@BOXSDW        For sides
       MOVB R1,@BOXBTW        For bottom also
       ANDI R1,>007F          Mask to vertical count only
       BLWP @UNPACV           Decompress top line data
       DATA BOXTD             Top line data
BOX10  AI   R0,LLL            Next line indexed by global pointer
       BLWP @UNPACV           UNPACV sides one line at a time
       DATA BOXSD             Side data
       DEC  R1                Count off
       JGT  BOX10             Do another
       AI   R0,LLL            Now for the bottom line
       BLWP @UNPACV           Decompress bottom line
       DATA BOXBD             Data pointer
       RTWP                   RETURN
 
*  Selection data tables
 
NOWSEL DATA >FFFF             Current selection
 
*  Data/pointer tables for pop-up windows
 
LSTSEL DATA >0        0-7     Last selection  0-7 as word
       DATA >FFFF             JLT -> no previous
       DATA >0                0 if initialized with one entry
       DATA >0
       DATA >0
       DATA >0
 
ENTCTB DATA >0        1-8     # of help screens loaded
ENTCTV DATA >0                # of view files
       DATA >1                # in L/S list
       DATA >1                Initial print device
       DATA >1                Initial hard-path
ENTCRF DATA >8                8 max in this model
 
NSTTAB DATA HLPBUV            Help screen names VBuffer
       DATA VFLBUV            View files VBuffer
       DATA WFLBUV            Workfile project list
       DATA PRDBUV            Print device project list
       DATA HDPBUV            Hard-path list
       DATA EDWBUV            Edit window project list
 
RSLTAB DATA MGBUF             Just to use same code as others
       DATA MGBUF             Currently used for VwFile entry
       DATA CTEXT             Workfile mailbox
       DATA CTEXT             PrDev for editing
       DATA CTEXT             Hard-path for editing
       DATA >0                No rewrite for Edit window data
 
ASOCLT DATA >0                Associated line # table
       DATA ELNTAB
       DATA >0
       DATA >0
       DATA >0
       DATA EDWTAB
 
*  Window contents related tables
 
ELNTAB DATA >0,>0,>0,>0       Table of start line #s for View
       DATA >0,>0,>0,>0
EDWTAB DATA >0,>0,>0,>0       Table of current line counts
       DATA >0,>0,>0,>0
CHETAB DATA >0,>0,>0,>0       Table of current Edit status
       DATA >0,>0,>0,>0       Null if no changes
ELNTM2 EQU  ELNTAB-2          For REF/DEF
 
*  Write up list and select
*----------------------------------------------------------
*  Exit screen restore is for appearance of Edit file change
*  Call as  BLWP @WRISEL
*           DATA selector index
*           JMP  no selection available (no list shown)
*  Returns  Selection in at NOWSEL
*  <escape> Resumes command mode
 
WRISLC MOV  *R14+,R12         Use as index
       MOV  @ENTCTB(R12),R0   Null checked before entry
       JEQ  WRIS99            Continue
 
*  Set up selection box and select
 
       BL   @CREBOX           Create list in box
WRIS30 BL   @KYLIFT           Wait for keylift
WRIS40 BL   @KWAIT            Wait for entry
       JMP  WRIS50            General key
       LI   R14,COMAND        <esc> exit
       DECT R14               Allow for final INCT
       JMP  WRIS80            Clear box on way
 
*  <Enter> gives last selection if any
 
WRIS50 CB   *R8,@ENTERK       Check for <ent> first
       JNE  WRIS60            No
       MOV  @LSTSEL(R12),R8   Retrieve last selection
       JLT  WRIS40            First time - no previous
       CI   R12,WFLVO         Workfile box ?
       JEQ  WRIS80            Yes - exit now to command line
       JMP  WRIS70            Use previous
 
*  Check for <1-8> selection and return selection data
 
WRIS60 CB   *R8,R7            Compare to max "1" - "8"
       JHE  WRIS40            Out of range
       CB   *R8,R5            Compare to "1"
       JL   WRIS40            Out of range
       MOVB *R8,R8            Copy selection
       SB   R5,R8             Adjust for 0-base
       SRL  R8,8              Make index as word
       MOV  R8,@LSTSEL(R12)   Record last selection
WRIS70 MOV  R8,@NOWSEL        Copy
       MPY  R10,R8            Returns offset to VDP entry in R9
       A    @NSTTAB(R12),R9   Construct V-adr
       MOV  @RSLTAB(R12),R8   Fetch return buffer address
       JEQ  WRIS80            Skip copy to CPU buffer
       BL   @MOVG             Copy from VDP
       DATA LLL               Standard buffer length
WRIS80 INCT R14               Step over error return
 
*  Erase list box before exit
 
WRIS90 BL   @SETVRG           Reset register
       DATA COLTM2            Restore CMD color
       LI   R0,VWRL#          # lines
       LI   R1,VWRSP          CPU screen buffer pointer
       LI   R2,VWLP0          UL screen pointer for box
WRIS95 MOV  R1,R8             Copy for use
       MOV  R2,R9             Screen pointer also
       AI   R1,LLL+6          Update for next line
D86    EQU  $-2               Offset data
       AI   R2,LLL            Also
       BL   @VMBWL            Write to screen
       DATA VWRLL             Box outer width
       DEC  R0                Count off
       JGT  WRIS95            More
       BL   @SETVRG           Reset register
       DATA EDPATT            Restore Ed pattern table
WRIS99 RTWP
 
*  Edit status check - display but no choice
*-------------------------------------------
 
SHOE00 EQU  $
       LI   R12,EDWVO         Offset directly to Ed window list
       MOV  @ENTCTB(R12),R0   Fetch # of files in ring
       BL   @CREBOX           Create the list box
       BL   @KYLIFT           Wait for keylift
       BL   @KWAIT            Wait for entry
       JMP  WRIS90            General key
       LI   R14,COMAND        <esc> exit
SHOE80 JMP  WRIS90            Clear box
 
*  Create / erase  selection box and entries
*------------------------------------------------
*  Input R12 as (word) offset pointer into NSTTAB
*  Assumes permanent data in OVRWSP
 
CREBOX MOV  R11,@CREB99+2
       CLR  @OVRL             Force refresh on return
       MOV  R0,R7             Keep copy for range check
       SWPB R7                For byte comparisons
       AB   R5,R7             Convert to ASCII 1-8 range
       BL   @SETVRG           Set new color table
       DATA COLTM5            Preloaded for selection box
       BL   @SETVRG           Use known pattern table
       DATA SDPATT            >0C84 as for SD
       BLWP @BOX              Draw listbox outline
       DATA VWLP0             Towards upper left
       DATA VWLSIZ            Enough for 8 entries
       MOV  @NSTTAB(R12),R1   Namelist pointer
       LI   R2,VWLP1          First display position
       MOV  R5,R3             Display counter preload '1.'
 
*  Write up the list as far as it goes
 
CREB10 MOV  R4,R8             Use LINBUF as temp buffer
       MOV  R3,*R8+           Write in index #
       MOVB @DSPACE,*R8+      Blank between # and entry
       MOV  R1,R9             Running VDP read pointer
       A    R10,R1            Update for next line
       BL   @MOVG             Fetch to CPU buffer
       DATA >2C               Covers Help screen name
       AB   @ONE,R3           Update index # for next entry
       MOV  R4,R8             Reset pointer
       MOV  R2,R9             Set VDP display position
       A    R10,R2            Update for next entry
       BL   @VMBWL            Write up enough for display
       DATA >2F               Enough to show
       DEC  R0                Count down
       JGT  CREB10            Get next
 
*  Line counts
 
       MOV  @ASOCLT(R12),R6   Check for associated line # table
       JEQ  CREB99            None - so no edit status either
       LI   R3,VWLP1          Start pointer
       AI   R3,>2B            For line count placement
       CLR  R2                Initialize
CREB20 MOV  R6,R8             Copy table address
       A    R2,R8             Index into table
       MOV  *R8,R9            Fetch entry
       INCT R2                To next entry
       BL   @RJNUM            Convert to decimal
       MOV  R3,R9             Screen position
       BL   @VSTRW            Write up
 
*  Edit/Changed status
 
       CI   R12,EDWVO         Is it Ed window list ?
       JNE  CREB30            No - quit now
       MOV  R3,R9             Refresh VDP pointer
       AI   R9,5              Advance past line count
       MOV  @CHETAB-2(R2),R0  Fetch file edited flag
       JEQ  CREB30            Virgin
       LI   R0,>0145          String "E"
       STWP R8                Point to it
       BL   @VSTRW            Write up
CREB30 A    R10,R3            Next line
       MOV  @ENTCTB(R12),R11  Fetch entry count
       A    R11,R11           Make word index
       C    R2,R11            Check how many
       JL   CREB20            More to do
CREB99 B    @>0
 
*  Add an entry from SD cursor at head of list
*---------------------------------------------
*  Assumes VB #0 already set
*  Call as  LI   R8,<where in CPU to be found>
*           BLWP @PUSHDN
*           DATA selector index
 
PUSHVF EQU  $
       MOV  *R14+,R12         Identifier from caller
       MOV  @ENTCTB(R12),R11  Fetch count
       JNE  PSVF05            Some already
       CLR  @LSTSEL(R12)      None - make new top the last
PSVF05 CI   R11,8             Max count
       JHE  PSVF10            Pure pushdown
       INC  @ENTCTB(R12)      Add one to incomplete list
 
*  Shuffle entries down one in buffer
 
PSVF10 MOV  @NSTTAB(R12),R1   Index to VBuffer
       MOV  R1,R2             Copy for use
       AI   R2,7*LLL          Initialize to last line (write target)
PSVF30 MOV  R2,R9             Copy as read V-adr
       S    R10,R9            Back up to previous line
       MOV  R4,R8             Use LINBUF as temp C-adr
       MOV  R10,R6            Set length at full line
       BL   @MOVE05           Read from VDP to temp
       MOV  R2,R9             Set write target
       MOV  R4,R8             Reset C-adr
       BL   @VMBWL            Write to entry after read
       DATA LLL               Full display line worth
       S    R10,R2            To previous entry
       C    R2,R1             At first line ?
       JH   PSVF30            Not yet - do next
 
*  Add new entry at head of list - parse to first space
 
       MOV  @DSPACE,R8        Clear it out first
       MOV  R1,R9             Copy start
       MOV  R10,R6            One line worth
       BL   @VFILL            Fill with blanks
       MOV  R1,R9             Back to starttarget V-adr
       BLWP @SETVDW           Set for write
       MOV  @R8+R8(R13),R8    Nominate line length buffer
       MOV  R8,R9             Copy start
       A    R10,R9            Max allowed is >50 = LLL
PSVF40 C    R8,R9             Remove blanks up to start of name
       JHE  PSVF99            Buffer end
       CB   *R8+,@DSPACE      <blank> ?
       JEQ  PSVF40            Look at next
       DEC  R8                No, back up
       S    R8,R9             # bytes to write
       BL   @FLOOPC           Fast loop in PAD
PSVF99 RTWP
 
*  Add Load/Save filename to work-list
*-------------------------------------
 
RCDNAM EQU  $
       ABS  R15               Was it a temp load ?
       JEQ  LODN10            Yes- do not register name
       ABS  @CHGNAM           Has it been edited ?
       JEQ  LODN10            No
       LI   R8,CTEXT          Assume on command line
       BLWP @PUSHDN           Push down workfile stack
       DATA WFLVO
       BLWP @REPEDW           Change window entry also
LODN10 RT
 
*  Replace Edit Window entry
*-------------------------------
*  Uses EDWIDN for ENTRY#  (0-7)
 
RPED00 EQU  $
       MOV  @EDWIDN,R8        Fetch index
       MPY  R10,R8            Figure offset
       AI   R9,EDWBUV         Pointer into buffer
       BL   @VMBWE            Write to name buffer
       DATA FILNAM,>28        Use current workfile
       RTWP
 
*  Set file in Edit Ring
*----------------------------
*  Replace "E" with current #
*  <esc> leaves command mode
 
EDRNT  BL   @DISPLY           Construct details
       DATA COMA10,EDTPT      Load CPU image
       BL   @WINED#           Construct string "1"
       SLA  R15,1             Word index
       MOV  @EOF,@EDWTAB(R15)    Refresh line count
       MOV  @CHNGED,@CHETAB(R15) Register edited status
       BLWP @WRISEL              Choose from box
       DATA EDWVO             Selector index
       NOP                    : Always a list here
       MOV  @NOWSEL,R0        New selection
       BL   @WINEE#           Replace # on screen
       BL   @SWRING           Save old and fetch new
       MOV  @PURGED,R11       Check if purged
       JEQ  EDRNT6            No entry since
       SETO @WFLVO+LSTSEL     Cancel prior workfile selection
EDRNT6 B    @CMDXIT           Restore edit mode
 
*  Write up ring #
 
WINED# MOV  @EDWIDN,R0        Convert to entry #
WINEE# MOV  R0,R15
       AI   R0,>0131          Construct string "1"
       SWPB R0
       MOVB R0,@CTEXT
DISPL2 MOV  R11,R14           Save return
       BL   @VMBWD            Command line to screen
       DATA 0                 Top of page
       DATA CPUSCN,LLL        Already in CPU image
       BL   @VMBWD            CTEXT line to screen
       DATA LLL+6             Over for command mode
       DATA CTEXT,LLL-6       Do not overflow
       B    *R14
 
*  Edit ring swap code
*---------------------------------------
*  Record Edit flag state
*  Save line table and data block as one
*  Uses R8-9,R12-14
*  Always copy current to store
*  Retrieve only if changed file
 
SWRINI EQU  $                 Initializing entry
       MOV  R13,@EDWIDN       R13 has ring #
       MOV  R13,@NOWSEL       Fake in as selection of same #
SWRING MOV  @EDWIDN,R13       Save/Swap entry - fetch window ID
       MOV  R11,R14           Save return
 
*  Save current ring-file line/data
 
       LI   R8,SVERGS         Save 8 words to VDP with other data
       LI   R9,SREGS          Use Edit mode saved values
       BL   @SAVE10           Edit registers 1-7
       MOV  @TBLND,*R8        R1 of BUFMWS - Tblend
       LI   R12,VMWREG        Set for write to VDP
       BL   @RINGMV           Do the transfer
 
*  Retrieve ring-file data from VDP
 
       MOV  @NOWSEL,R13       Fetch current window ID
       C    R13,@EDWIDN       Check again for same (for INI)
       JEQ  SWRF99            Same - do not copy back
       LI   R12,MOVE05        Set for read back from VDP
       BL   @RINGMV           Transfer data
       LI   R9,SVERGS         Restore edit registers
       LI   R8,SREGS          Into backup to restore immediately
       BL   @SAVE10           Restore registers
       MOV  *R9,@TBLND        R1 in BUFMWS also
       BLWP @RNGSEG           Set new buffer segment limits
SWRF99 B    *R14
 
*  Move ring-file data to/from storage
 
RINGMV MOV  R11,R10           Assumes VBank #3 already set
       BL   @SETVRG           Set VRegister for bank switch
       DATA >038E             Use VBank #3 for LT storage
       SLA  R13,1             Make word index
       MOV  @LTSTOR(R13),R9   VDP pointer from table
       LI   R8,FILNAM         Fil/Ftl name buffers in CPU
       LI   R6,>A0            2 lines long
       S    R6,R9             Store below LT
       BL   *R12              Read/Write VDP storage
       MOV  @LTSTOR(R13),R9   VDP pointer from table
       MOV  @LNTSAV,R8        CPU start of line table
       MOV  @LNTLEN,R6        Max length of line table
       BL   *R12              Read/Write VDP storage
       SRL  R13,1             Restore normal index
       BL   @BANK0            Restore base VBank
       B    *R10              VBank #0 reset by caller
 
*-------------------------*
*  Final irrevocable exit *
*-------------------------*
*  Well, maybe anyway
 
EXCHEK EQU  $
       MOV  @CHNGED,R11       Check current file
       JNE  EXWN10
       LI   R6,CHETAB         Examine edit table
EXCH20 MOV  *R6+,R11          Check Modified flag
       JNE  EXWARN            Set - issue warning
       CI   R6,CHETAB+16      Done ?
       JL   EXCH20            No
       JMP  ELDCON            Nihil obstat
 
EXWARN BLWP @SHOEDT           Display ring edit status
EXWN10 BL   @HONK             Audible warning
       LI   R15,ELDCON        Set final exit
       B    @PURGEC           Wait for entry
 
ELDCON EQU  $
       LWPI SCNWS             For entry screen <esc>
       BL   @SETVR1           VWTR for VR1
       DATA >3081             Turn off screen
       LI   R5,SETVRG         Byte saver
       BL   *R5               VWTR
       DATA >008A             Turn off high color
       BL   *R5               VWTR
       DATA >018E             VBank #1
       BL   *R5               VWTR
       DATA >008D             Turn off blink
       BL   @MOVE             FW restore
       DATA >2000,>E000       Includes original PTBL
       DATA >1FD8
       BL   *R5               VWTR
       DATA >008E             Back to Vbank #0
       BL   *R5               VWTR
V9EXIT DATA >0089             FW value - 24 line, NTSC, No IL
       BLWP @VMBWF            Restore original pattern table
       DATA >800,>E000,PTTBLN Now in VDP
       LI   R0,>2000          Load with blanks
       BLWP @VFILF            Clear TM1 screen
       DATA 0,960
       BL   *R5               Reset normal mode
       DATA >0080             VR #0
       BL   *R5               VWTR
       DATA >008C             Turn off alternate colors
       SZCB @MASK10,@>83C2    Enable <Quit> key
       MOV  @COLCH,@INCOL     Pass color index back to FW
       LWPI FWREG             FW registers
       RT                     R4 is whatever it was
 
       DATA >BBBB             Block marker - easy find
 
*------------------------------------------------
 
