 
*  ED8/DISPLY   40 col        Nov / 20 / 92
 
*  DISPLY, VDP R/W/Reg,
*  NUM, PRNUMS, GSLASH, CMLCHK, RESTLA, CLRCMD
*  TAB keys
 
 
*  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
       MOV  R6,@SCNLEN        Display stuff.
       LI   R6,CPUSCN         CPU text buffer
       MOV  R6,@TOPSCN        Start screen there
       LI   R10,86*2          Push down 2 lines worth
       A    R10,@TOPSCN       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
       JEQ  ERH40             No
 
       MOV  R9,R10            Copy error #
       CLR  @ERFLAG           We have seen it now
       MOV  R11,R13           Temporary save
       LI   R8,ERMBUF         Line buffer for error line
       MOV  R8,@ERRLIN        Line table pointer
EHN10  MOV  @DSPACE,*R8+      Clear buffer
       CI   R8,ERMBUF+86      End of buffer ?
       JL   EHN10             Not yet
 
       LI   R8,ERMBUF+6       Start at text line
       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           Drop through to MVISTR
       B    *R13
 
 
*  Modify MOVEM to move indexed strings
*--------------------------------------
*  R8  -->>  CPU target
*  R9  -->>  Pointer into VDP pointer table
*  Version to allow separate language files
 
MVISTR EQU  $                 Preserve return
       AI   R9,TEXTV          VDP table start
       BLWP @SETVDR           Set read address
       LI   R6,VDPRD          Byte saver
       MOVB *R6,R9            First byte of string pointer
       SWPB R9                To LSByte
       MOVB *R6,R9            Second byte of string pointer
       SWPB R9                To regular address
       AI   R9,TEXTV          Offset from table start
       BLWP @SETVDR           Set to read string length
       MOVB *R6,R6            Fetch string length byte
       SRL  R6,8              Make count
       JMP  MOVE40            Do the move
 
*  Data 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
       B    *R11
 
*  Color switches
*----------------
 
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  $
VADW   EQU  $
       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
 
*  No register use version
 
SETVR1 EQU  $
       MOVB *R11,@>83D4       Load for next console keyscan
SETVRG MOVB *R11+,@VDPWA
       MOVB *R11+,@VDPWA
       RT
 
 
*  BLWP Versions
*------------------
*  BLWP vector data
 
SETVDW DATA >FFDC,STVW10
SETVDR DATA >FFDC,STVR10
 
 
STVW10 MOV @18(R13),R9        SETVDW
       BL  @SETWDA
       RTWP
 
STVR10 MOV  @18(R13),R9       SETVDR
       BL   @SETRDA
       RTWP
 
 
*  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
 
*  String writing variation
 
VSTRM  LI   R8,MARKR
       JMP  VSTRW
 
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  VMBW20
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, uses R14
*  -----------------------------------------
 
VFILH  LI   R8,>2000          For VINIT
       LI   R6,80             Saves bytes in L/S
       JMP  VFILL
VFILI  LI   R8,>2083
VFILJ  MOV  *R11+,R6
VFILK  MOV  *R11+,R9
VFILL  BLWP @SETVDW
VF1    MOVB R8,@VDPWD
       DEC  R6
       JNE  VF1
       B    *R11
 
 
*--------------------------
*  CMD line number scanner
*  Uses R0,R6,R8,R8,R10,R12
*--------------------------
 
NUM    EQU  $                56w  ----
       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           Was it a line # entry ?
       JNE  NUM50             No - worry about it elsewhere
 
       MOV  @EOF,R12          Too big so use EoF anyway
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  $
       MOV  R11,R14           Save return
       SETO @COLNUM           Turn off EoF check
       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  PRNU30            Non-number
 
*  Try it as a number then
 
       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
 
 
*  Parse command line for L/S
*----------------------------
 
PARSLD LI   R8,CTEXT          Point to start of command line
PARSLE MOV  R11,R13           Save return
       BL   @PRNUMS           Parse 1 to 3 numbers
       JMP  PARERR            Error
       MOVB @DSPACE,@DELIM    Use space as filename delimiter
       MOV  R8,@STRING        Start pointer
       BL   @GSLASH           Chase delimiter after name
       JMP  PARERR            None found
       MOV  R6,@STRL          Save length byte
       MOV  @NUMCHK,R6        Check count of #s
       JEQ  PRLDEX            Must be 2 #s
       DEC  R6                Test again   - necessary ????
       JGT  PRLDEX            No #s entered
       C    *R9,@EOF          1 or 3 - limit first by EoF
       JLT  PRLDEX            No problem
       MOV  @EOF,*R9          Make it EoF then
PRLDEX B    *R13              Return
 
 
*  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,SCLR+CMDCL
       JL   CLRBUF
       RT
 
*  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      Compaare 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
 
       MOV  @RMRG,R2          Else force to RMrg
       RT
 
TABSET MOVB *R8,R2            Write to cursor
       SRL  R2,8              Make word offset
       RT                     RETURN
 
*  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
       RT                     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
 
*  Line # display for L/S/P-F
*----------------------------
 
LNDISP EQU  $
       MOV  R11,R14
       LI   R10,CPUSCN+80     Use end of first line in buffer
       BL   @BINDEC           Convert to decimal
       BL   @VMBWD            Write to end of command line
       DATA 40-6              Allow for 4 chars + 2 spaces
       DATA CPUSCN+80,6       Where written
       B    *R14
 
*  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
ATHREE EQU  NBLINE+30
NBLNM3 EQU  NBLINE-3
NBLEND EQU  $
 
       EVEN
 
*----------------------------------------*
 
