 
*  EE4/SHODR   40 col    Jul / 04 / 93
 
 
*  Screen pointers
 
SP10   EQU  4
SP15   EQU  25
SP16   EQU  30
SP17   EQU  36
SP20   EQU  40+SP10-1
SP30   EQU  80+3
SP35   EQU  120+11
SP36   EQU  120+24
SP38   EQU  120+33
SP40   EQU  200+7
SP45   EQU  240+6
SP50   EQU  80+24
SP55   EQU  SP50+11
 
 
SPM10  EQU  800+1
SPM20  EQU  880+1
SPM30  EQU  920+3
 
SPN10  EQU  320+5
SPN20  EQU  SPN10-39
 
SPU10  EQU  160+3
SPU20  EQU  760+1
 
STARTD EQU  $
       LWPI DREGS             Use own workspace
       BL   @MOVE             Fetch print temp name
       DATA PSDBUV            VDP storage
       DATA DEVNAM,>50        Temp CPU storage
ONCEMO LI   R4,VSTRU          Byte saver
       BL   @VFILI            Text-mode screen
       DATA 40*24,0
       BL   @VFILJ            Clear first buffer
       DATA 130,CATBF
D130   EQU  $-4
 
 
* Write in drive #
 
       BL   *R4
       DATA DSNAM,SP10
       MOVB @DR#,R8      Fetch drive #
       AI   R8,>3000     Adjust for ASCII
H30    EQU  $-2
       LI   R9,SP10+3    Screen position
       BL   @SETWDA      Write
       MOVB R8,@VDPWD    to screen.
 
* Bring in sector #0
 
STRT10 CLR  R7            Sector #0
       BL   @SECRD
 
* Write up headers for Directory screen.
 
       BL   @HEADRS
       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 SP38
       DATA RJF#,5
 
 
* Transfer name to buffer & then to screen
 
       BL   @MOVE
PBF1D  DATA PBF1,DRBF+2,12
       BL   @VMBWD
       DATA SP10+8
       DATA DRBF+2,10
       MOV  @DRBF+12,R0       Disk size to R0
 
 
* Count bit-map free sectors
 
       LI   R7,>100->38  Initialize counter
       LI   R9,PBF1+>38  Point to first byte of bitmap
       BL   @SETRDA
       CLR  R9           Init free sector counter
FRE1   MOVB @VDPRD,R8    Fetch 1 bytes
       LI   R5,8         16 bits
FRE2   SLA  R8,1         Shift out
       JOC  FRE3         & check if zero.
       INC  R9           If so count it
FRE3   DEC  R5           Tick off 1 bit
       JGT  FRE2         If more bits do again
       DEC  R7           Tick off 2 bytes
       JGT  FRE1         Back for more
 
       CI   R0,1600
       JLE  FRE4
 
       SLA  R9,1
FRE4   S    R9,R0        Sectors used in R0
       BL   @RJNUM       Write # available
       BL   *R4
       DATA RJN,SP35+7
 
       MOV  R0,R9        Now write
       BL   @RJNUM        for #0 & #1 sectors.
       BL   *R4
       DATA RJN,SP30+15
 
* Read Sector #1 into PBF2 & initialize pointers.
 
       LI   R7,1
       BL   @SECRD
       BL   @MOVE
       DATA PBF1
       DATA PBFC,>100
 
       CLR  R9           Write up "Page 1 of 1"
       BL   @PGC
       CLR  R9
       BL   @PGM
 
       LI   R1,PBFC
       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,SPN10    Start on screen
H0F    EQU  $-3
 
NEWFL  EQU  $
       MOV  R3,R9        Display filecount
       BL   @RJNUM        on screen
       LI   R8,RJF#       starting with 0.
       MOVB @THREE,*R8
       BL   @VSTRV
       DATA SP55
       MOV  *R1+,R7      Get header sector #
       ABS  R7           Check if null ?
       JNE  NFL2         If not, we've had the last
       ABS  R4
       JNE  LSTFL        If no files on this page
       DEC  R5            back off page counter
       JMP  LSTFL         before leaving.
 
NFL2   BL   @SECRD       Fetch file header sector
       BL   @DRENT       Extract catalog entry
       MOV  R2,R9        Point to VDP current buffer position
       BL   @VMBWE       Transfer to CATBF
       DATA DRBF+2,>0D
       AI   R2,>0D       Update VDP buffer pointer
       CI   R3,>A        First 10 files up ?
       JHE  NFL3
       BL   @UNPACK      Display form
       MOV  R15,R9
       BL   @VMBWE
       DATA DRBF+1,32
       AI   R15,40       Update screen pointer
NFL3   CB   *R3+,*R4+    Count file in page also
       CI   R4,>A        Page full ?
       JL   NEWFL        If not, get the next entry.
       CLR  R4            else reset counter
       MOV  R5,R9        Write up
       BL   @PGM          max page # reached.
       INC  R5
 
       MOV  R2,R9        Clear another page
       LI   R6,130
       MOVB @DSPACE,R8
       BL   @VFILL
       JMP  NEWFL
 
 
*  Finish screen  &  check program files
 
LSTFL  EQU  $
       MOV  R5,R9             Working copy
       BL   @PGM              Write to screen
       MOV  R5,@MAXPAG        Save highest page reached
       MOV  R3,@MAXCNT        Save max # files
       SETO @FILMRK           Impossible FILMRK
       CLR  R3                Point to first file
PRTX   BL   @INSTR
       BL   @BEEP             Signal job done
 
 
*  Store details for recall
 
       BL   @MOVE             Save first 4 lines of screen
       DATA 0                 Contains disk info
       DATA SDTMBV,>A0        To upper screen buffer
       LI   R11,>50
PSVFIL MOV  @>A000-2(R11),@TMPBF-2(R11)
       DECT R11
       JGT  PSVFIL
 
 
*--------------------------------
*  Wait for keyboard instructions
*--------------------------------
 
KELOOP EQU  $
KLP10  BL   @PGDIS            Display current page
KLP20  BL   @KWAIT            Get key & convert to upper case
       NOP
       MOV  @DELVAL,R9        >1C00
KLP21  DEC  R9
       JNE  KLP21             Finish with R9 cleared
 
*  Check if number key for another drive
 
       CB   *R8,@AONE
       JL   KLP30
       CB   *R8,@ANINE
       JH   KLP30
 
       SB   @H30,*R8          Remove ASCII bias
       MOVB *R8,@DR#          Put where expected
       MOVB @H0F,@CRUSTT      Reset CRU search start
       B    @ONCEMO           Restart
 
 
KLP30  CB   @KEYTB(R9),*R8    Check table entry against keystroke
       JEQ  KLP50             Match found
 
       INC  R9                Advance index
       CI   R9,KJTBL          Past end of table ?
       JL   KLP30             Not yet
       JMP  KLP20             Yes - try keyboard again
 
KLP50  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
*-------------------
 
MARKEY EQU  $                 <M>ARK Key Entry
       ABS  @DVF80            Is is a Dis/... 80
       JEQ  MRKEX
 
       LI   R1,36             Transfer to mailbox
MRK40  MOV  @MFBUF-2(R1),@>9FFE(R1)
       DECT R1
       JGT  MRK40
 
       MOV  R3,@FILMRK        Save marked file pointer
MRKEU  BL   @BEEP             Make beep
MRKEX  JMP  KELOOP            Resume keyloop
 
 
*  Mark Load Temp filename
*-------------------------
 
MARKLT  EQU  $
        ABS  @DVF80           Socially acceptable ?
        JEQ  MRKEX            Most certainly NOT
 
        BL   @VMBWD           Write to TL buffer
        DATA TFLBUV           VDP storage
        DATA MFBUF,36         Current file name
        JMP  MRKEU            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
       A    @W10,R3           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
 
 
*  Restore original workfile
*---------------------------
 
OLDFIL EQU  $
       LI   R11,>50
OLDFIM MOV  @TMPBF-2(R11),@>A000-2(R11)
       DECT R11
       JGT  OLDFIM
       CLR  @FILMRK
       JMP  KELOOP
 
 
*  Return to Editor after restoring altered items
*------------------------------------------------
 
EXIT   EQU  $
 
EXIT2  MOVB @H0F,@CRUSTT
       LWPI SCNWS          Reload Editor workspace
       LI   R6,COMAND
       B    @DRCODF        Swap DIR & EDIT code
 
 
*  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 BL   @VMBWD            Use PBF1 for VDP name buffer
       DATA PBF1,MFBUF+5,10
       MOVB @DR#,@FAC+2       Drive #
       MOV  @PBF,@FAC+4       PBF will contain PBF1
       LI   R9,VDPPAB+10      Point to PAB
       MOV  R9,@SCNAME        Set PAD pointer
       LI   R8,PR             PAB data
       BL   @VSTRW            Write to VDP
       INCT @DSRTYP           Set for subroutine access
       BLWP @TWDSLK           Find & execute DSR
       DECT @DSRTYP           Reset for file access
MORDIS B    @ONCEMO           Redo the directory to show result
 
 
*  Comparison table for key entries
 
KEYTB  BYTE 'V','D','O',>90           <c-P>
       BYTE >98,>85,>06
ENTERK BYTE >0D,>9D
KEYTB1 TEXT ' TXEQAUP'
       BYTE 11,10
KJTBL  EQU  $-KEYTB
       EVEN
 
*  Branch table for key selection
 
ENTRTB DATA TYPEFL,DELETE,OLDFIL,PRINTD
       DATA PAGNX,PAGBK,ONCEMO,EXIT,EXIT
       DATA MARKEY,MARKLT,CSRUP,CRDOWN,PAGBK,PAGNX
       DATA UNPR,PROT,CRDOWN,CSRUP
 
*********************************************
 
ASCV   EQU  KEYTB
ASCO   EQU  KEYTB+2
* ASCB   EQU  KEYTB1+4
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 '>'
USED   BYTE >0E
       TEXT 'Sectors Used ='
AVAIL  BYTE >06
       TEXT 'Free ='
EQUALS EQU  $-1
BYTES  BYTE >07
       TEXT 'Bytes ='
FLCAP  BYTE >1C
       TEXT 'Filename  Size  '
ASCT   TEXT 'Type   Rec P'
ULN2   BYTE >1D
       TEXT '---------- ---- ------- --- -'
FLCT   BYTE >0B
       TEXT 'Filecount ='
PAGNO  BYTE >0B
       TEXT 'Page     of'
 
FWBK   BYTE >26
       TEXT '<Q,^E> <V>iew <Un/P>rot  T,Mark <T,sp>'
KEYS   BYTE >26
       TEXT '<A,^X> <c-P>D <O>ldF <D>elF  Exit<ent>'
ERMSG  BYTE >24
       TEXT 'DISK/DEVICE ERROR -~- <BACK> to exit'
 
RUSURE BYTE >13
       TEXT 'REALLY SURE (Y/N) ?'
ASCY   EQU  RUSURE+14
ASCN   EQU  ASCY+2
EOFM   BYTE >05
       TEXT '*EoF*'
       EVEN
 
TYPTBL TEXT 'Dis/Fix Dis/Var '
ASCD   EQU  TYPTBL
       TEXT 'Int/Fix Int/Var '
ASCP   TEXT 'Program '
THREE  EQU  $
DSNAM  BYTE >3
       TEXT 'DSK'
B80    BYTE >80
B50    BYTE >50
H1F    BYTE >1F
H10    BYTE >10
UNDLN  EQU  H1F
       EVEN
 
