 
*  EE5/DIREC   40 Col         Jul / 04 / 93
*--------------------
*  All Characters
 
*------------------------------------------------------------
*  PGDIS  Display on screen a 10 line page of catalog entries
*         Line # in R3 - selects page containing that line
*------------------------------------------------------------
 
*  Locate Top of Page in buffer  16/page
*---------------------------------------
 
TOPOPG EQU  $
       MOV  R3,R14            Copy current file pointer
       MOV  R3,R15            Second copy
       SRL  R14,4             Divide by 16 on page
       MOV  R14,R9            Page # for immediate use
       SLA  R14,4             # pages x files/page
       MOV  R14,@PGFTOP       Save for use
       S    R14,R15           Remainder
       MOV  R15,@CSRFIL       Copy # files down on page
CPOINT MPY  @W0D,R14          Offset to file entry in CATBF
       AI   R15,CATBF         Set up CATBF first page pointer
       RT
 
*  Write up disk details
*-----------------------
 
DSDETL EQU  $
       MOV  R11,@DSDLEX+2     Establish return
       CI   R0,1600           Max at 1 sec/AU
       JLE  FRE4
 
       SLA  R9,1              2 sec/AU then
FRE4   S    R9,R0             Sectors used in R0
       BL   @RJNUM            Convert # available
       BL   @VSTRV            Write up to screen
       DATA NSSFRE            To sectors free
       MOV  R0,R9             Sectors used
       BL   @RJNUM            Convert to string
       BL   @VSTRV            Write up
       DATA NSSUSD            To advice block
       BL   @VMBWD            Write up name
       DATA NSNAM2,DRBF+1,10  From record buffer
       LI   R2,CATBF          Pointer in Catalog buffer in VDP
       CLR  R3                File count from 0
       CLR  R4                File # within page
       CLR  R5                Page count from 0
       LI   R15,NSFID         Start on screen
DSDLEX B    @>0
 
*  Construct directory page
*--------------------------
 
PAGEIT EQU  $
       MOV  R11,@PGITEX+2     Set return
       MOV  R2,R9             Point to VDP current buffer position
       BL   @VMBWE            Store entry
       DATA DRBF+2,CATL
       AI   R2,CATL           Update VDP buffer pointer
       CI   R3,PGLEN          First 16 file page done ?
       JHE  PGIT10            Yes - quit immediate display
 
*  Display first page of entry on the run
 
       BL   @UNPACK           Unsqueeze and display directory entry
       MOV  R15,R9            Copy screen pointer
       AI   R15,SW            Advance to next line
       BL   @VMBWE            Write up unpacked record
       DATA DRBF+1,DRL-1      Assume length
PGIT10 CB   *R3+,*R4+         Count file in page also
       CI   R4,PGLEN          Page full ?
       JL   PGITEX            If not, get the next entry.
 
*  Finish off page & set up next before leaving
 
PGFIN  CLR  R4                Else reset counter
       MOV  R5,R9             Working copy of page #
       BL   @PGM              Write up max page # reached.
       INC  R5                Index to next page
       MOV  R2,R9             Clear another page
       LI   R6,13*PGLEN       16 entries worth
       MOVB @DSPACE,R8        Blank
       BL   @VFILL            Fill the block
PGITEX B    @>0
 
 
*------------------------------------------------------------
*  PGDIS  Display on screen a 16 line page of catalog entries
*         Line # in R3 - selects page containing that line
*------------------------------------------------------------
 
PGDIS  EQU  $
       MOV  R11,@PGDRTN       Save return
       BL   @TOPOPG           Construct pointers
       BL   @PGC              Page # already in R9
       CLR  R4                Start counter for 16 files per page
       LI   R13,NSFID         First line for entries
 
PDS1   BL   @UNPACJ           Decompress entry
       MOV  R13,R9            Copy for use
       BL   @VMBWE            Write to DIR display
       DATA DRBF+1,DRL-1      Asssume length
       C    R4,@CSRFIL        Is it the one with the cursor
       JNE  PDS2              No
 
*  Construct MAIL-MIRROR entry and clear to length
 
       LI   R8,MFBUF          Point to buffer
       MOV  @HDPLEN,R6        Path name length
       MOVB @DR#,R11          Was it a drive # ?
       JEQ  PDS10             No - hard path
 
       LI   R6,5              Standard length
PDS10  A    R6,R8             R8 points to where filename starts
       LI   R11,DRBF+2        Fetch name from packed entry
       SZCB @MASK80,*R11      Remove any fracture flag
NMENT1 CB   *R11,@DSPACE      Gheck for actual end
       JEQ  NMENT2            End of name
       INC  R6                Not yet, count it
NMENT2 MOVB *R11+,*R8+        Copy to target after DSKx.
       CI   R11,DRBF+12       All 10 chrs max. done ?
       JL   NMENT1            Not yet
NMENT3 MOVB @DSPACE,*R8+      Fill rest of buffer with blanks
       CI   R8,MFBUF+>50
       JL   NMENT3
 
       MOV  @TEMPF,@DVF80     Save type flag for file under cursor
       JEQ  NMENT4            Not for View
       JLT  NMENT4            Sub-dir flagged
       MOV  R6,@DVF80         Replace JGT by actual count
 
NMENT4 MOV  R13,R9            Screen pointer for entry
       BL   @VSTRM            Write in front of entry
       MOV  R13,R9            Copy  name screen pointer
       AI   R9,11             At end of name
       BL   @VSTRM            Write up mark
 
*  Next entry
 
PDS2   INC  R4                Count one done
       AI   R13,SW            Update screen pointer
D40    EQU  $-2               Handy data
       AI   R15,CATL          Update buffer pointer by >0D
W0D    EQU  $-2
H0D    EQU  $-1
       CI   R4,PGLEN          Page's worth -- 16 ?
       JL   PDS1              Repeat if more to go
       B    @>0               Restored return address
PGDRTN EQU  $-2
 
 
*  PGC/PGM  Display page #
*  -----------------------
 
PGC    EQU  $
       LI   R0,NSPG1          Current page
       JMP  PGN
PGM    LI   R0,NSPG2          Total pages
PGN    INC  R9                Make into actual page count
       MOV  R9,R8             Copy page #
       SWPB R8                For byte op
       AI   R8,>3000          Add ASCII bias
       MOV  R0,R9             Fetch screen pointer
       BLWP @SETVDW           Set for write
       MOVB R8,@VDPWD         Only 1 digit
       RT
 
 
*  RJNUM  Takes integer in R9 and puts STR$
*         in RJF# with leading zeros suppressed.
*         Uses R6,R8,9,10,12
*  ------------------------------------------------------
 
 
RJNUM0 EQU  $
       INC  R9                Base 0 -> display base 1
RJNUM  EQU  $
       LI   R12,8             Enter at RJNUMA for 5 digits
RJNUMA MOV  R11,R6            Save return
       MOV  R10,R14           Save R10 contents
       LI   R10,RJF#          Buffer
       BL   @NXDIG            BufMgr routine
       LI   R10,RJF#          Suppress
RJ3    CB   *R10,@AZERO       leading
       JNE  RJ4               zeros
       CI   R10,RJF#+3        except
       JEQ  RJ4               for
       MOVB @DSPACE,*R10+     last.
       JMP  RJ3
RJ4    MOV  R14,R10           Restore R10
       LI   R8,RJN            Byte saver
       B    *R6
 
 
*  Unpack Buffer entry
*---------------------
 
UNPACJ EQU  $
       MOV  R11,R10           Save return - alternate entry
       MOV  R15,R9            Copy catalog buffer pointer
       BL   @MOVF             Fetch from VDP
       DATA DRBF+2,CATL       13 bytes into DRBF
       JMP  UNPC10
 
UNPACK EQU  $
       MOV  R11,R10           Save return
UNPC10 LI   R11,>2020         Set length byte
       LI   R14,DRBF          Coincidentally an ASCII space
       MOV  R11,*R14+         At start of buffer area
       C    *R14,R11          Spaces ?
       JNE  UNPC30            Entry exists
 
*  Clear line and quit
 
UNPC20 MOV  R11,*R14+
       CI   R14,DRBF+36
       JL   UNPC20
       JMP  UNPKEX            Return immediately
 
*  Process entry
 
UNPC30 LI   R8,DRBF+15        Blank out buffer
UNPC40 MOVB R11,*R8+
       CI   R8,DRBF+36
       JL   UNPC40
 
       MOVB *R14,*R14         Check first byte of name
       JGT  UNPC50            Normal ->> unfractured
       MOVB @ASTRIX,@DRBF+17  Indicate fracture then
       SZCB @MASK80,*R14      Clear fracture indicator
UNPC50 MOV  @DRBF+12,R14      Type(3)+Prt(1)+File(12)
       SRL  R14,13            Protected ?
       JNC  UNPC60            No
 
       MOVB @ASCP,@DRBF+30    Write in indicator
UNPC60 SLA  R14,3             x 8 again on Type
       LI   R0,TEMPF          Point to temp flag
       CLR  *R0               Initialize for no action
       CI   R14,4*8           Check offset value
       JNE  UNPC65            Not a program file
       CLR  R9                Make sure for program
       JMP  UNPC75            Skip other tests
 
UNPC65 MOVB @DRBF+14,R9       Get Reclen
       CI   R14,1*8           D/F or D/V ?
       JH   UNPC70            No
       CB   R9,@B80           Reclen = 80 ?
       JH   UNPC75            No
 
       INC  *R0               OK for <V>iew
UNPC70 CI   R14,5*8           Sub-dir entry ?
       JNE  UNPC75            No
 
       DEC  *R0               Flags a sub-dir
UNPC75 AI   R14,TYPTBL        Index into list
       LI   R0,DRBF+18        Move Type into buffer
       MOV  *R14+,*R0+        Write 8 bytes
       MOV  *R14+,*R0+        Even to even
       MOV  *R14+,*R0+
       MOV  *R14,*R0+
       SRL  R9,8              Word value for Reclen
       JEQ  UNPC80            Must have been program file
 
       BL   @RJNUM            Convert to string
       INCT R8                Ignore leading blank
       MOVB *R8+,*R0+         Byte address unfortunately
       MOVB *R8+,*R0+
       MOVB *R8,*R0
UNPC80 LI   R0,DRBF+12
       MOV  *R0,R9            Fetch Size again
       ANDI R9,>0FFF          Mask to size
       BL   @RJNUM            Convert to string
       INC  R8                Past length byte
       MOVB @DSPACE,*R0+      Clear where it was
       MOVB *R8+,*R0+         Byte addressing needed again
       MOVB *R8+,*R0+
       MOVB *R8+,*R0+
       MOVB *R8,*R0
UNPKEX B    *R10
 
 
*  Sector reading routine, setup VDP buffer first
*  Expects sector # in R7, uses R9,10
*  ----------------------------------------------
 
SECRD  EQU  $
       MOV  R11,R10      Save return
SECRN  LI   R9,VDPPAB    Point to PAB
       MOV  R9,@SCNAME
       LI   R8,PN
       BL   @VSTRW
       LI   R11,FAC+2    Byte saver
       MOVB @DR#,*R11+   Disk drive selected
       MOVB @READ,*R11+  Set for read op
       MOV  @PBF1D,*R11+ Point to sector buffer
       MOV  R7,*R11      Sector #
       BLWP @TWDSLK      Find & execute DSR
       DATA >A
       JEQ  DSERR
       MOVB *R11,R12     Check if error returned
       JEQ  DSREX
 
       A    @CRUINC,@CRUSTT   Next DSR
       C    @CRUSTT,@CRUEND   Last ?
       JL   SECRN             Try it
 
DSERR  BL   @VSTRU            Error message
       DATA ERMSG,NSPERR+1
HOLD   BL   @KWAIT            Wait for key
       JMP  HOLD
       LI   R8,>1F00
       BL   @VFILJ
       DATA SW-2,NSPERR
HLD10  LI   R10,EXIT
DSREX  B    *R10
 
 
*  Form catalog printline
*------------------------
 
CATLIN MOV  R11,R0       Save return
       BL   @CPOINT      Absolute buffer pointer
       MOV  R15,R9       Copy VDP pointer
       BL   @MOVF        VMBR
       DATA DRBF+2,CATL
       MOV  R0,R11
       B    @UNPACK      Form screen entry and return
 
*  Draw line
*-----------
 
LINDRW MOV  R11,R15      Save return
       BL   *R1          Move
       DATA LINBUV       Prepared line stored
       DATA LINBUF,80
       BL   @C2V         Transfer to VDP
       BL   *R5          Write out to device
       MOV  R15,R11      Restore return
LINCLR LI   R14,LINBUF   Now clear line bufer
       B    @MFILL       Go back this way
 
 
*-------------
*  Delete file
*-------------
 
DELETE EQU  $
       MOV  R11,R13      Save return
       BL   @VSTRU       Cautionary message
       DATA RUSURE,NSPERR
       BL   @VMBWD
       DATA NSPERR+18,MFBUF,15
       BL   @BEEP        Audible feedback
DELT20 BL   @KWAIT       Check key
       NOP
       CB   *R8,@ASCY    A definite <Y>es ?
       JEQ  DELT30       Yup
       CB   *R8,@ASCN
       JNE  DELT20
       JMP  DELT40
 
DELT30 BL   @FILPRP      File preparation
       DATA >0700        Delete
       DATA MFBUF        Name in mailbox
       LI   R13,HRDENT   Set to redo Dir after delete
DELT40 LI   R8,KEYRT     Repoint
       MOVB @DRA#,*R8    Restore drive #
       B    @LEAV10      Leave via cleanup
 
 
*  Setup PAB and open file
*-------------------------
 
FILPRP EQU  $
       MOV  *R11+,@PABOC File op data
       MOV  *R11+,R8     Name location
       MOV  R8,R14       Copy
       MOV  R11,R10      Save return
       MOVB @H0F,@CRUSTT Reset DSRLNK
       AI   R14,>4E      End of buffer
       CLR  @LFLAG       For TI-Wr routine
       CLR  @PABRN       Reset record #
       CLR  R0           Initialize counter
       LI   R9,VDPPAB+10 Name start in PAB
       BLWP @SETVDW      VDP write address
SKIP10 C    R8,R14       At end ?
       JHE  NOPDEV       Yes - must be all blank
       CB   @DSPACE,*R8+ Space before name ?
       JEQ  SKIP10       Yes - try next
       DEC  R8           Back off for first nonspace
SKIP20 CB   @DSPACE,*R8  Look for space after name
       JEQ  SKIP30       Found
       INC  R0           Count length
       MOVB *R8+,@VDPWD  Write to PAB
       JMP  SKIP20       Get next
SKIP30 MOV  R0,@PABSO    PAB name length
       LI   R5,WRITEP    Byte savers
       LI   R1,MOVE
       LI   R4,VINIT
       MOV  @PBFNOM,@PABBAD
SKIP40 BL   @IO          Calls TI-Wr
       JMP  NOPDEV       Failure
       B    *R10         Normal return
 
*  Write to printer
*------------------
 
WRITEP MOVB @WRITE,@PABOC Set write op
       MOV  @SLRL,@PABLRL
READIT MOV  R11,R10      Save return
       JMP  SKIP40
 
 
*  Error trapping for View/PDir
*------------------------------
 
NOPDEV LI   R13,KELOOP
       BL   @VSTRU       Error message
       DATA ERMSG,NSPERR
       BL   @HONK        Noise
       BL   @KWAIT       Wait for <esc>
       JMP  $-4
       B    @CLOSIT      Go restore status quo
 
*  Print directory
*-----------------
 
PRINTD EQU  $
       MOV  R11,R13      Save return
       BL   @FILPRP      File preparation
       DATA >0016        Append
       DATA DEVNAM       SD-Print device in Editor
 
       BL   @LINDRW           Write out first line and clear for next
       MOVB @DR#,R0           Is it a hard path-name ?
       JEQ  HDINFL
 
*  Data for floppy disk
 
       BL   *R1               Fetch second line template
       DATA SDHBUV
       DATA LINBUF,>50
       BL   *R1               Move
       DATA NSSFRE            # free
       DATA LINBUF+HLSFCN,4
       BL   *R1               Move
       DATA NSSUSD            # used
       DATA LINBUF+HLSCUN,4
       JMP  HDINFM
 
*  Data for hard-path
 
HDINFL LI   R8,LINBUF+8
       LI   R9,'Pa'
       MOV  R9,*R8+
       LI   R9,'th'
       MOV  R9,*R8+
       LI   R9,': '
       MOV  R9,*R8
       BL   *R1               Move
       DATA HDPBUV            Hard-path name buffer
       DATA LINBUF+8+6,40
 
*  Continue with filecount entry
 
HDINFM BL   *R1               Move
       DATA NSFLC             File-count
       DATA LINBUF+HLFLCN,4
       BL   @C2V              Transfer to VDP
       BL   *R5               Write to device
       BL   @LINDRW           Underline it all
 
*  Write in entry column headers
 
       BL   *R1
       DATA NSDHD
       DATA LINBUF+8,29
       BL   *R1
       DATA NSDHD
       DATA LINBUF+43,29
       BL   @C2V
       BL   *R5
       BL   *R1
       DATA NSDHDU
       DATA LINBUF+8,29
       BL   *R1
       DATA NSDHDU
       DATA LINBUF+43,29
       BL   @C2V
       BL   *R5
 
*  Now do files in 2 columns
 
       MOV  @MAXCNT,R2  # pages-1
       INC  R2
       SRL  R2,1
       CLR  R7
PRT10  C    R7,R2
       JHE  PRT40
 
       BL   *R4
       MOV  R7,R14
       BL   @CATLIN
       BL   @VSTRU
       DATA DRBF,PABBUF+7
       MOV  R7,R14
       A    R2,R14
       BL   @CATLIN
       BL   @VSTRU
       DATA DRBF,PABBUF+42
 
       BL   *R5
       INC  R7
       JMP  PRT10
 
PRT40  BL   @LINDRW
       BL   *R4               Do a blank line
       BL   *R5               Drop through to Close File
       JMP  CLOSIT
 
*  Close file
*------------
 
LEAVE  BL   @VFILI            Clear Edit screen
       DATA 24*SW,0
       LI   R9,SITBL2
       BL   @SETRDA
CLOSIT BL   @CLOSE            Close file
       NOP                    IGNORE close error
 
LEAV10 LI   R9,NSPERR
       LI   R6,SW-2
       BLWP @SETVDW
LEAV20 MOVB @H1F,@VDPWD
       DEC  R6
       JGT  LEAV20
       B    *R13
 
*  Read error
 
RDERRA CI   R9,5              End of file ?
       JEQ  RDERRB            Yes
       B    @NOPDEV           No - much worse
 
RDERRB BL   @VSTRU            EOF to screen
       DATA EOFM,23*SW
       BL   @BEEPL            Beep it
       BL   @KWAIT
       NOP
       JMP  LEAVE             <esc>
 
 
*  Readout file to screen
*------------------------
 
TYPEFM EQU  $
       SETO @TEMPF            Half line only
       JMP  TYPEFN
 
TYPEFL EQU  $
       CLR  @TEMPF
TYPEFN MOV  R11,R13           Save return
       BL   @VFILI            Clear Edit screen
       DATA 24*SW,0
       BL   @FILPRP           File prep
DVFOP  DATA >0014             Open
       DATA MFBUF             From mailbox
       LI   R9,SITBL1         Switch to it
       BL   @SETRDA
       BL   @VMBWD            Write filename from markfile buffer
       DATA 23*SW+1,MFBUF,26
       CLR  R2                Line counter
READFL BL   @VFILI            Clear screen
       DATA 23*SW,0           But not last line
       MOV  R2,R9             Copy last count
       INC  R9                Next at top
       BL   @RJNUM            Decimal
       BL   @VSTRU            Display
       DATA RJN,23*SW+30
 
       CLR  R15               Start of screen
RDFL05 CI   R15,21*SW         End of "Type" area
       JL   RDFL20            No
 
RDFL10 BL   @KWAIT            Check key
       JMP  READFL            Any key - continue
       JMP  LEAVE             Back - shut off
 
RDFL20 MOVB @READ,@PABOC      Read opcode
       MOV  R15,@PABBAD
       BL   @IOREC            Read record
       JMP  RDERRA            Error
 
       INC  R2                Line count
       MOV  R2,R9             Copy
       BL   @RJNUM            To decimal #
       BL   @VSTRU            Display
       DATA RJN,955
 
       LI   R8,SW            Screen width 40
       A    R8,R15           Update write pointer 1xSW
       MOV  R15,R9           Copy
       ABS  @TEMPF
       JEQ  RDFL40
 
       BLWP @SETVDW          Cover short write on next line
RDFL30 MOVB @DSPACE,@VDPWD   Fill 2nd half with blanks
       DEC  R8
       JGT  RDFL30
       JMP  RDFL05
 
RDFL40 BL   @SETRDA
RDFL50 CB   @VDPRD,@DSPACE    Check for blank half line
       JNE  RDFL60
       DEC  R8
       JGT  RDFL50
       JMP  RDFL05            Last line blank
 
RDFL60 AI   R15,40            Step over second half also
       JMP  RDFL05            Next record
 
 
SVPRTN DATA >BBBB
 
*  End in main file
 
