 
*  EE4/SHODR   40 col         Jul / 03 / 93
*---------------------
*  All Char / All Mode
 
*  Screen pointers in EE3/DATEN
*  SD EQUates
 
DRL    EQU  32                Unpacked entry length
PGLEN  EQU  16                Entries per directory page
CATL   EQU  13                Length of catalog entry
 
*  HARDF flag set at entry for path access
 
*  General entry to SD code from ED
*----------------------------------
 
STARTD EQU  $
       LWPI DREGS             Use own workspace
       ABS  @RELOFW           Return to FW ?
       JEQ  DIRTCY            No - do directory then
       B    @RELODR           Go to final exit FW reloader
 
*  Display directory
*-------------------
 
DIRTCY EQU  $
       BL   @VMBWD            Make copy in VDP
       DATA TMPBFV            Temp buffer
       DATA FILNAM,>50        Current workfile name
       BL   @MOVE             Fetch from VDP
       DATA TFLBUV            Current LT filename
       DATA DEVNAM,>50        To CPU temp
       BL   @VMBWD            Write back to VDP
       DATA NTFNAP            Bottom line
       DATA DEVNAM,26         Only as much as shows
       BL   @VMBWD            Workfile in CPU already
       DATA NWFNAP            Write after WF:
       DATA FILNAM,26         Only what shows
       BL   @MOVE             Fetch print temp name
       DATA PSDBUV            VDP storage
       DATA DEVNAM,>50        Temp CPU storage
 
* Write up bytes free in text buffer
 
       MOV  @TBLND,R9         Line # table down to here
       S    @EDBFND,R9        Subtract top of line heap
       LI   R12,10            Up to 5 digits
       BL   @RJNUMA           Convert to decimal #
       BL   @VMBWD            Write to screen
       DATA NSFBYT
       DATA RJF#,5
 
*  Check out pathname either way
 
       LI   R9,HDPBUV         Point to HardPath buffer contents
       BLWP @SETVDR           Set read address
       CLR  R8                Reset last byte storage
       SETO R5                Initialize counter
DRCT10 INC  R5                Count one
       MOV  R8,R9             Save last
       MOVB @VDPRD,R8         Fetch byte from VDP
       CB   R8,@DSPACE        Look for first space
       JNE  DRCT10            No - go for next
       CB   R9,@PERIOD        Check for full stop
       JEQ  DRCT20            That's fine
       CLR  R5                Set zero length
       CLR  @HARDF            No good as pathname
       BL   @HONK             Indicate displeasure
DRCT20 BL   @CLMARK           Clear first page of Dir etc
       LI   R9,SITBL2         VR2 for >1000 image table
       BL   @SETRDA           Does a VWTR
       MOV  R5,@HDPLEN        Write as length - null if bad name
       JEQ  DRCT30            Not allowable as path access
       ABS  @HARDF            Path access called for ?
       JNE  DRCT40            Yes
DRCT30 BL   @VSTRU            Write up requester anyway
       DATA DSKX#             Standard "DSK?."
       DATA NSNAM1            On first line
       B    @PRTX
 
DRCT40 CLR  @HARDF            Cancel flag now we know
       LI   R8,KEYRT          Fake up a key return
       MOVB @B30,*R8          "0" for HD
       B    @HRDENT           Go treat as path entry
 
*---------------------------------------*
*  Warm restart entry - directory read  *
*---------------------------------------*
 
ONCEMO EQU  $
       BL   @CLMARK           Reset for new read
       CLR  R3                Cheap way of putting up progress indicator
       BL   @PGDIS            Clear page also
       BL   @VSTRU            Write to screen
       DATA DSKX#,NSNAM1
       BL   @MOVE
       DATA NSNAM1,MFBUF,5
 
 
*  Obtain directory by sector analysis
*-------------------------------------
*  Bring in VIB sector (#0)
 
ONCEMP EQU  $
       CLR  R7                Sector #0
       BL   @SECRD            Get the disk header sector
       BL   @MOVE             Read in name to buffer
PBF1D  DATA PBF1,DRBF+1,10    Write up in DSDETL
 
* Find disk-size & count bit-map
 
       BL   @MOVE             Read disk size word
       DATA PBF1+>A,DREGS,2   Store in R0
FRE0   LI   R7,>100->38       Initialize counter
       LI   R9,PBF1+>38       Point to first byte of bitmap
       BL   @SETRDA           Start to read from Vbuffer
       CLR  R9                Initialize free sector counter
FRE1   MOVB @VDPRD,R8         Fetch a byte
       LI   R5,8              8 bits
FRE2   SLA  R8,1              Shift out
       JOC  FRE3              Check if zero bit
 
       INC  R9                If so count it as free
FRE3   DEC  R5                Tick off 1 bit
       JGT  FRE2              If more bits do again
       DEC  R7                Tick off a byte
       JGT  FRE1              Back for more
 
* Read Sector #1 into PBFC & initialize pointers.
 
       BL   @DSDETL           Disk details and initialize
       INC  R7                Sector #1  -- R7 left as null
       BL   @SECRD            Read sector from disk
       BL   @MOVE             Move to CPU
       DATA PBF1
       DATA PBFC,>100         Overlays L/S also
       LI   R1,PBFC           Initialize pointer into Sector #1
       CLR  R9                Write up "Page 1 of 1"
       BL   @PGC              First #
       CLR  R9                Also 1
       BL   @PGM              Second #
 
*  Build directory
 
NEWFL  EQU  $
       MOV  R3,R9             Current filecount
       BL   @RJNUM            Convert to string
       BL   @VSTRV            Write filecount to screen
       DATA NSFLC
       MOV  *R1+,R7           Fetch Sec #1 entry for FDR
       ABS  R7                Check if null ?
       JNE  NFL2              If not then there are more
       ABS  R4                Check # files on page
       JNE  LSTFL             Keep page then
       DEC  R5                None - back off page counter
       JMP  LSTFL             All done
 
*  Get next file data
 
NFL2   BL   @SECRD            Fetch file header sector
       BL   @MOVE             Fetch filename and flag bytes
       DATA PBF1,DRBF+2,>12   Fetch enough of record for now
       MOVB @DRBF+14,R8       To MSB with file flags
       MOV  @DRBF+16,R7       Copy file length
       MOVB @DRBF+19,R6       To MSB with Reclen
       MOVB R8,R14            Make a copy of file flags
       SRL  R14,9             Check LSBit of MSB
       JNC  DRT10             Not a Program file
 
       LI   R14,>8000         Program
       CLR  R6                Make sure Reclen is stored as zero
       JMP  DRT20             Don't worry about rest
 
DRT10  MOV  R8,R14            Copy file flags
       ANDI R14,>8200         Isolate F/V and D/I bits
       MOV  R14,R11           Copy masked out bits
       SRL  R11,7             F/V bit to LSB in byte
       SOCB R11,R14           0-3 in byte
       SLA  R14,5             Shift to bits 1-2
       ANDI R14,>E000         Mask to those
DRT20  MOVB R6,@DRBF+14       Write Reclen in compressed record
       SLA  R8,5              Check protection bit
       JNC  DRT30             Not set
 
       SOCB @H10,R14          Indicate protected in bit 3
DRT30  INC  R7                Include FDR
       ANDI R7,>0FFF          Only allow up to 4095 sectors
       SOC  R7,R14            Combine
       MOV  R14,@DRBF+12      Write to compressed record
       BL   @MOVE             Fetch 2 bytes of 2nd cluster
       DATA PBF1+>1F          28+3 offset
       DATA DREGS+14,2        Write to R7
       ABS  R7                Check it
       JEQ  DRT40             Null -->> no fractures
       SOCB @B80,@DRBF+2      Set hi-bit on 1st char of name
DRT40  BL   @PAGEIT           Put record in page
       JMP  NEWFL             Back for more
 
*  Finish screen & wait for command
*----------------------------------
*  Initial entry point after setup
 
 
LSTFL  EQU  $
       MOV  R3,@MAXCNT        Save max # files
       MOV  R5,@MAXPAG        Save highest page reached
       MOV  R5,R9             Working copy
       BL   @PGM              Write to screen
PRTX   CLR  R3                Force first page display
PRTY   BL   @BEEP             Job done
 
*--------------------------------
*  Wait for keyboard instructions
*--------------------------------
 
KELOOP EQU  $
KLP10  BL   @PGDIS            Display current page
KLP20  BL   @KWAIT            Get key & convert to upper case
       NOP                    <ESC> ignored here
       MOV  @DELVAL,R9        Key delay loop
KLP25  DEC  R9
       JOC  KLP25             Leave as >ffff
 
       CB   *R8,@B30          Is it below "0"
       JL   KLP30             Yes
       CB   *R8,@ANINE        Above "9"
       JH   KLP30             Not a numeric
 
*  Hard path or from select on numeric
 
HRDENT EQU  $
       MOVB *R8,@DRA#         Write in ASCII # anyway
       SB   @B30,*R8          Remove ASCII bias
       MOVB *R8,@DR#          Copy to storage as flag too
       JNE  HARDIT            Not hard path
 
*  Enter hardpath name
 
       MOV  @HDPLEN,R6        Load for hard path
       JEQ  KELOOP            No valid name
 
       LI   R8,MFBUF          Target pointer
       LI   R9,HDPBUV         Hard path buffer pointer
       BL   @MOVE05           Do the move to CPU buffer
HARDIS MOVB @DSPACE,*R8+      Fill with spaces for display
       CI   R8,MFBUF+>50
       JL   HARDIS
 
       BL   @CLMARK           Clean up
       BL   @VMBWD            Write path to display
       DATA NSNAM1
       DATA MFBUF,27          Not too much
       CLR  R3                Reset display
       BL   @PGDIS            Cheap clear of file display
       B    @VOLFIL           Go get path dir
HARDIT B    @ONCEMO           Go get new floppy dir
 
*  Resume keysearch
*------------------
 
KLP30  INC  R9                Next key comparison
       ABS  @MAXCNT           Any DIR and files in DIR ?
       JNE  KLP40             Yes - no need to limit choices
       CI   R9,NOFLEN         No files ?
       JH   KLP20             Only allow these
 
KLP40  MOVB @KEYTB(R9),R11    Fetch table entry
       JEQ  KLP20             Null terminator
       CB   R11,*R8           Check table entry against keystroke
       JNE  KLP30             Match found
 
       A    R9,R9             Make word index into branch table
       MOV  @ENTRTB(R9),R9    Fetch routine pointer
       BL   *R9               Branch to it with link
       JMP  KELOOP            If come back via link
 
*  MARK file routine
*-------------------
 
MRKLVL B    @NLEVEL            Set up to read next level
 
MARKEY EQU  $                 <M>ARK Key Entry
       MOV  @DVF80,R6          Is it a Sub-Dir ?
       JLT  MRKLVL             Yes
       JEQ  MRKEX              Not marked - leaves DV/F80
 
       LI   R1,>50            Transfer to mailbox
MRK40  MOV  @MFBUF-2(R1),@>9FFE(R1)
       DECT R1
       JGT  MRK40
 
       LI   R9,NWFNAP         Point to Workfile display
MRK50  LI   R8,26             Display length
       C    R6,R8             Is name longer ?
       JH   MRK55             Yes
       MOV  R8,R6             No - cancel adjust
MRK55  S    R8,R6             Adjust start offset
MRK60  LI   R8,MFBUF          Marked filename pointer
       A    R6,R8             Adjust start
       BL   @VMBWL            Write to screen
       DATA 26                Only what fits
MRKEU  BL   @BEEP             Make beep
MRKEX  JMP  KELOOP            Resume keyloop
 
*  Mark Load Temp filename
*-------------------------
 
MARKLT  EQU  $
        MOV  @DVF80,R6        Socially acceptable ?
        JEQ  MRKEX            Most certainly NOT
 
        BL   @VMBWD           Write to TL buffer
        DATA TFLBUV           VDP storage
        DATA MFBUF,>50        Current file name
        LI   R9,NTFNAP
        JMP  MRK50            Make a beep on way back
 
*  Cursor down/up (in file #)
*----------------------------
 
CSRUP  EQU  $
       INC  R3                Next file
       C    R3,@MAXCNT        Compare to max count
       JHE  CRDWN1            Too far
CSRUP1 RT                     ; return pointing to next file
 
CRDOWN MOV  R3,R3             Check if at start
       JEQ  CRDWN2            Yes
 
CRDWN1 DEC  R3                One file back to start
CRDWN2 RT
 
*  Page forward in directory
*---------------------------
 
PAGNX  EQU  $
       BL   @TOPOPG           Find top of page file pointers
       C    R9,@MAXPAG        On last page ?
       JHE  PAGNX1            Yup
 
       MOV  @PGFTOP,R3        Current file at top of page
       AI   R3,PGLEN          Advance to top of next page
       JMP  PAGBK3            Main keylooop again
 
PAGNX1 MOV  @MAXCNT,R3        Put cursor to end of buffer
       DEC  R3                Back up to last displayed file
       JMP  PAGBK2            Return with signal
 
*  Page back in directory
*------------------------
 
PAGBK  EQU  $
       BL   @TOPOPG           Find top of page file pointers
       MOV  R9,R9             Check page #
       JEQ  PAGBK1            On first page already
 
       MOV  @PGFTOP,R3        Current file at top of page
       DEC  R3                Back to last file on previous page
       JMP  PAGBK3            Back to main keyloop
 
PAGBK1 CLR  R3                Send cursor to top of first page
PAGBK2 BL   @BEEPL            Signal no more please
PAGBK3 JMP  MRKEU             Main loop again
 
*  Restart or restore original workfile
*--------------------------------------
 
CLMARK EQU  $
       MOV  R11,R14           Save return
       BL   @VFILI            Clear first page of catalog
       DATA PGLEN*CATL        16*13 = 208
       DATA CATBF
D208   EQU  $-4
       BL   @VFILI
       DATA SW,NSNAM
       CLR  @MAXCNT           Initialize file counter
       CLR  @MAXPAG           Initialize page counter
       JMP  OLDFIM            Most of <O>ldF
 
OLDFIL EQU  $
       MOV  R11,R14
       BL   @MOVE             Recover from temp buffer
       DATA TMPBFV,>A000,80   Full length
OLDFIM BL   @BEEP             Show appreciation
       BL   @VMBWD            Write to screen
       DATA NWFNAP,>A000,26   Only just enough
       B    *R14              Look for key again
 
*  Return to Editor after restoring altered items
*------------------------------------------------
 
EXIT   EQU  $
EXIT2  MOVB @H0F,@CRUSTT
       MOVB @QUERY,@DRA#
       CLR  @HARDF
       LI   R9,SITBL1         Restore normal screen
       BL   @SETRDA           VWTR
       CLR  R3                Force first page
       BL   @PGDIS            Clear display for next time
       LWPI SCNWS             Reload Editor workspace
       LI   R6,COMAND
       B    @DRCODF           Swap DIR & EDIT code
 
*  Volume pseudo-file record for Directory
*-----------------------------------------
 
VOLFIL EQU  $
       MOVB @H0F,@CRUSTT      Reset CRU search start
       LI   R15,PABLRL        Point to record length
       CLR  *R15              Request length return
       BL   @FILPRP           Open file
       DATA >000D             Open, internal, relative, 38
       DATA MFBUF             Filename
       MOVB *R15+,*R15        Use as buffer length too
 
*  Get disk details
 
       BL   @IOREAD           Read first catalog record
       JMP  ERRCAT            Error return
       BL   @CLDRBF           Clear start of DRBF
       LI   R9,PABBUF         VDP buffer
       BL   @VSTGRD           String read for disk name
       BL   @CF2I             Dummy in this record
       BL   @CF2I             Convert disk size to integer
       CB   @FAC+10,@THREE    Check result
       JEQ  VOLF10            Probably overflow with HD
 
       MOV  @FAC,R0           Retrieve result
       CI   R0,9999           Can we display this ?
       JL   VOLF20            Probably overflow with HD
VOLF10 LI   R0,9999           Use this instead
VOLF20 BL   @CF2I             Convert free AUs
       MOV  @FAC,R9           Copy result
       BL   @DSDETL           Disk details and initialize
 
*  Get file details and form directory records
 
HNEWFL EQU  $
       CI   R3,139            In case of sub-dirs also
       JH   HLSTFL            Stop at end of last page
 
       MOV  R3,R9             Current filecount
       BL   @RJNUM            Convert to string
       BL   @VSTRV            Write filecount to screen
       DATA NSFLC             Screen position
       BL   @IOREAD           Get file records
       JMP  ERRCAT            Error return
       LI   R9,PABBUF         VDP buffer
       BLWP @SETVDR           Set for read
       MOVB @VDPRD,R7         Check first byte
       JNE  HNFL2             There is a file
 
       ABS  R4                Check # files on page
       JNE  HLSTFL            Keep page then
       DEC  R5                None - back off page counter
       JMP  HLSTFL            Then leave
 
HNFL2  BL   @CLDRBF           Clear buffer
       INC  R8                Start 2 bytes in
       BL   @VSTGRD           Read string for name
       BL   @CF2I             Convert file type return
       CLR  R11               Clear mask
       MOV  @FAC,R1           Fetch integer 1 - 7
       JGT  HNFL3             Not protected
 
       ABS  R1                Convert to normal form
       LI   R11,>1000         Mask for protect bit
HNFL3  DEC  R1                Make 0 - 4
       SLA  R1,13             Make leading bits
       SOCB R11,R1            Show if protected
       BL   @CF2I             Get AU allocation
       MOV  @FAC,R11          Copy result
       ANDI R11,>0FFF         Mask off to be safe
       SOC  R11,R1            Write in lower part of word
       MOV  R1,@DRBF+12       Copy as next word
       BL   @CF2I             Get record length
       MOVB @FAC+1,@DRBF+14   Put in entry
       BL   @PAGEIT           Do for first page
       JMP  HNEWFL            Back for more
 
*  Close up & go to main loop
 
HLSTFL BL   @CLOSE            Close up shop
       NOP                    IGNORE error
       MOV  @SLRL,@PABLRL     Replace standard record length
       B    @LSTFL
ERRCAT B    @NOPDEV           Error exit
 
 
*  Convert Floating point to Integer
*-------------------------------------
*  Assume VDPRD at start byte at entry
 
CF2I   EQU  $
       LI   R8,FAC-1          Throw away length byte
C2FI10 MOVB @VDPRD,*R8+       Copy from VDP buffer
       CI   R8,FAC+8          F/P entry done ?
       JL   C2FI10            Not yet
 
       LWPI >83E0             GPL WS for system routine
       BL   @>0               Written in at entry
CFIAD  EQU  $-2
       LWPI DREGS             Restore current WS
       RT
 
CLDRBF EQU  $
       LI   R8,DRBF           Record buffer
CLDR10 MOV  @DSPACE,*R8+      Fill with blanks
       CI   R8,DRBF+12        Enough to cover name
       JL   CLDR10            No
       LI   R8,DRBF+1         Preload for later
CLDR20 RT
 
*  Un/Set file protection
*------------------------
 
UNPR   EQU  $
       CLR  @FAC+2            Clear FAC+3
       JMP  PROT10            To common routine
 
PROT   EQU  $
       SETO @FAC+2            Set FAC+3
PROT10 MOVB @DR#,@FAC+2       Is it a hardpath ?
       JEQ  CLDR20            Return immediately
 
       BL   @VMBWD            Use PBF1 for VDP name buffer
       DATA PBF1,MFBUF+5,10
       MOV  @PBF1D,@FAC+4     Load with PBF1
       LI   R9,VDPPAB+10      Point to PAB
       MOV  R9,@SCNAME        Set PAD pointer
       LI   R8,PR             PAB data
       BL   @VSTRW            Write to VDP
       BLWP @TWDSLK           Find & execute DSR
       DATA >A
MORDIS B    @ONCEMO           Redo the directory to show result
 
*  Go to next level of subdirectory
 
NLEVEL EQU  $
       LI   R6,HDPLEN         Point to length
       LI   R8,MFBUF          Start of filename
       LI   R9,HDPBUV         Point to VBuffer
       A    *R6,R8            Point past current "."
       A    *R6,R9            Also
       BLWP @SETVDW           Set write
NLVL10 INC  *R6               Increase length
       CB   *R8,@DSPACE       Space after name ?
       JEQ  NLVL30            Escape on first space
       MOVB *R8+,@VDPWD       Copy across
       JMP  NLVL10            Try next
 
NLVL30 MOVB @PERIOD,@VDPWD    Finish off with a "."
NLVL40 SETO @HARDF            Force a Dir read
NLVL50 B    @DRCT40           Go do it
 
*  Go back a level in directory tree
 
BLEVEL EQU  $
       MOV  @HDPLEN,R6        Fetch existing length
       DECT R6                Back off before "."
       JGT  BLVL20            Has to be some left
BLVL10 B    @KELOOP           Ignore whole business
 
BLVL20 LI   R9,HDPBUV         Point to start of buffer
       A    R6,R9             Set up read pointer
       BLWP @SETVDR           Set read
       DEC  R6                Back off
       JEQ  BLVL10            Run out ?
       CB   @VDPRD,@PERIOD    Is it a "." ?
       JNE  BLVL20            No - do next
 
       INCT R6                Set length again
       MOV  R6,@HDPLEN        Resave
       INC  R9                Point after "."
       BLWP @SETVDW           Set write
BLVL30 MOVB @DSPACE,@VDPWD    Fill with blanks
       INC  R9                Next
       CI   R9,HDPBUV+>50     At end ?
       JL   BLVL30            Not yet
       JMP NLVL40             Exit with forced Dir read
 
 
*  Comparison table for key entries
*----------------------------------
 
KEYTB  BYTE >9D,>B0,>06       <c-=0><f-8>
ENTERK BYTE >0D               <ent>
       TEXT 'VWDO'
       BYTE >90,>98,>85       <c-PXE>
KEYTB1 TEXT ' TXEQAUP'
       BYTE 11,10             <f-XE>
       BYTE 0                 Terminator
NOFLEN EQU  ENTERK-KEYTB
KJTBL  EQU  $-KEYTB
       EVEN
 
*  Branch table for key selection
 
ENTRTB DATA EXIT,BLEVEL,ONCEMO,EXIT
       DATA TYPEFL,TYPEFM,DELETE,OLDFIL
       DATA PRINTD,PAGNX,PAGBK
       DATA MARKEY,MARKLT,CSRUP,CRDOWN,PAGBK,PAGNX
       DATA UNPR,PROT
       DATA CRDOWN,CSRUP
 
*-------------------------------------------------
 
ASCV   EQU  KEYTB
ASCO   EQU  KEYTB+2
ASCB   EQU  KEYTB1+4
 
HDPLEN DATA 0                 Hardpath length
* PBF    DATA PBF1
NULL   BYTE 0
RJN    BYTE >4
RJF#   DATA >0,>0,>2020,>2020
AONE   BYTE '1'
ANINE  BYTE '9'
PN     DATA >0201
H1000  DATA >1000
PR     BYTE >02,>01,>12
MARKED BYTE >01
       TEXT '>'
EQUALS EQU  '='
ERMSG  BYTE >24
       TEXT 'DISK/DEVICE ERROR -~- <BACK> to exit'
RUSURE BYTE RUSLEN
       TEXT 'Delete ? (Y/N)'
RUSLEN EQU  $-RUSURE-1
ASCY   EQU  $-4
ASCN   EQU  $-2
QUERY  EQU  $-7
 
EOFM   BYTE >05
       TEXT '*EoF*'
DSKX#  BYTE 5
       TEXT 'DSK?.'
DRA#   EQU  $-2
       EVEN
 
TYPTBL TEXT 'Dis/Fix Dis/Var '
ASCD   EQU  TYPTBL
       TEXT 'Int/Fix Int/Var '
ASCP   TEXT 'Program Sub-Dir '
       TEXT 'Emulate '
THREE  BYTE >03
B80    BYTE >80
B50    BYTE >50
B30    BYTE >30
H0F    BYTE >0F
H1F    BYTE >1F
H10    BYTE >10
UNDLN  EQU  H1F
       EVEN
 
*------------------------------------------------------
 
