home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / sigmv307.ark / RDIR15P.LBR / RDIR15+.MZC / RDIR15+.MAC
Encoding:
Text File  |  1988-12-10  |  22.1 KB  |  1,094 lines

  1. ;
  2. ;
  3. ;NOTE: ---->>>>  SYSLIB required to assemble (v2.7B or higher)
  4. ;
  5. ;
  6. ;Remote DIRectory program
  7. ;
  8. ;rdir.com     by simon ewins
  9. ;
  10. ;--> v1.5+ Updated the program for CP/M Plus compatibility:
  11. ;  7-7-84  Added CP/M Plus test and freespace calculation.  Added test for
  12. ;       label, XFCB, and SFCB file entries in the print routine to bypass
  13. ;       trying to display those entries.    George Peace
  14. ;
  15. ;--> v1.5  added 2400 baud support (2400 is on the way
  16. ;       in, you know...). Also removed unnecessary global status
  17. ;       from all labels.            S. Kluger
  18. ;
  19. ;--> v1.4  fixed problem with display of files > 512k, adapted
  20. ;       for new SDIR module in SYSLIB, defaulted MSPEED to
  21. ;       300 baud if speed code is invalid.    S. Kluger
  22. ;       (all changes in lower case)
  23. ;
  24. ;--> v1.3  added control-c break without using control-s first.
  25. ;          fixed summary line to make it shorter so that large
  26. ;          files or disks won't spill over the end of the line.
  27. ;
  28. ;--> v1.2  adds maximum user and maximum drive to the config table.
  29. ;          if requested user area or drive is greater than those
  30. ;          in the table then the current user or drive is taken
  31. ;          instead. this provides high security as the only way a
  32. ;          user or drive in excess of the one in the table can be
  33. ;          accessed is if the user is logged into it!
  34. ;
  35. ;rdir is a remote directory routine that in addition to the usual
  36. ;directory functions will indicate the transfer times for the file
  37. ;at each of the 6 most popular baudrates.
  38. ;
  39. ;the 'switches' at 106h and 107h serve as the default info as well
  40. ;as flags for allowing either option. the values of the two locations
  41. ;are stuck into place and then if options are allowed they can be
  42. ;changed by the /switch. a secure system, obviously would have 106h,
  43. ;107h and 10Ah set to 0 as default or 10Ah set to 1 with 117h set to 1
  44. ;to enable options but only if the password is correct.
  45. ;
  46. ;Patch information:  () = setting as distributed
  47. ;"""""""""""""""""
  48. ; 103h (0) lsb of BSPEED in BYE
  49. ; 104h (0) msb of BSPEED in BYE
  50. ; 105h (5) baudrate code (see below) if 104h=0000h then this used for speed
  51. ; 106h (0) 1=show system files, 0=don't show system files
  52. ; 107h (0) 1=show all user areas, 0=show only current user area
  53. ; 108h (3) number of columns (2 or 3)
  54. ; 109h (21) number of lines on screen -1
  55. ; 10Ah (1) 1=allow options, 0=no options
  56. ; 10Bh  =  default filespec 0???????????
  57. ; 117h (0) 1=passworded option protection, 0=no password
  58. ; 118h  =  10 character password (right-padded with 0) PASSWORD
  59. ; 122h (15) maximum user area allowed
  60. ; 123h (2) maximum drive allowed
  61. ;
  62. ;--->> NOTE: maxusr and maxdrv can ONLY be overcome by being logged to
  63. ;            a drive/user that is greater than the values at 122h/123h.
  64. ;
  65. ;
  66. ;NOTE:  (for those wishing to use this program on a 'local' system)
  67. ;
  68. ;The baud-rate is gained from reading an address pointed to by the 2 bytes
  69. ;at 104H. Set these to the address of BSPEED in BYE. If you aren't running
  70. ;BYE and want this to work as a non-remote directory program then set 103H
  71. ;& 104H to 0000H and set 105H to one of the following:
  72. ;        0 = 110  baud
  73. ;        1 = 300  baud
  74. ;        2 = 450  baud
  75. ;        3 = 600  baud
  76. ;        4 = 710  baud
  77. ;        5 = 1200 baud
  78. ;        6 = 2400 baud
  79. ;        7 = 4800 baud
  80. ;   (by using the /b# option the above rates can be set at runtime)
  81. ;
  82. ;
  83. ;the listing is 3 columns wide and looks like this:
  84. ;
  85. ;TEST    .AQM   3k   3:34 | BYE     .COM   3k   3:45 | FILEFIND.COM   6k   6:22
  86. ;
  87. ;>> A5:  Files: 3  Used: 12k  Free: 178k  Time: 0:13:30 @ 110bps
  88. ;
  89. ;
  90. ;if 10Ah is set to 1 then the following options are allowed:
  91. ;
  92. ;RDIR       =   show all files as determined by bytes 105h -> 109h
  93. ;RDIR /b#   =   show times using bps code #, where # = 0 to 7 above
  94. ;RDIR /s    =   show system files
  95. ;RDIR /a    =   show all user areas
  96. ;
  97. ;by changing the ambiguous filespec at 10Bh the above will display only
  98. ;whatever fits with no filespec entered unless a filespec is entered.
  99. ;
  100. ;full drive and user and filespecs are supported.
  101. ;
  102. ;RDIR b4:rcpm-*.l?t /b2  =  show files matching on b4: using 600 baud times
  103. ;RDIR 5:                 =  show files using defaults on current drive/user 5
  104. ;RDIR B2: /S             =  show files using defaults, incl. system files
  105. ;                           on drive b:/user 2
  106. ;
  107. ;if a filespec is provided then /s is not allowed, /a is still allowed.
  108. ;
  109. ;the initial password, as distributed, is PASSWORD (all in upper case).
  110. ;a non-secure system being used locally would probably have 105h set
  111. ;permanently to the user's most frequently used baudrate and 103h/104h
  112. ;set to 0000h to disable the search for the bye baudrate code. further,
  113. ;the following would allow all options, without a password and show files
  114. ;only on the current user area:
  115. ;106h = 1
  116. ;107h = 0
  117. ;10Ah = 1
  118. ;117h = 0
  119. ;108h = columns (2 or 3)
  120. ;109h = lines (22 as distributed)
  121. ;
  122. ;forward any comments or suggestions to Simon Ewins at:
  123. ;
  124. ;Willowdale CBBS   (416) 226-9260
  125. ;Toronto EMX RCP/M (416) 484-9663
  126. ;CP/M-NET East     (201) 249-0691
  127. ;
  128. ;------------------------------------------------------------------------------
  129. ;
  130. ;equates:
  131. ;
  132. CR    EQU    13
  133. LF    EQU    10
  134. BEL    EQU    7
  135. BDOS    EQU    5
  136. FCB    EQU    5CH
  137. FCB2    EQU    6CH
  138. DMA    EQU    80H
  139. CTAIL    EQU    DMA
  140. ;
  141. ;start of transient program: rdir.com
  142. ;
  143.     .Z80
  144.     CSEG
  145.     JP    START
  146. ;
  147. ;switches and initial data:
  148. ;
  149. BSPEED:
  150.     DW    0000H        ;address of baudrate code from BYE
  151. BAUDCD:
  152.     DB    5        ;if bspeed=0000h then this value used for times
  153. SYSFIL:
  154.     DB    0        ;1=show system files, 0=no show system files
  155. USRARA:
  156.     DB    0        ;1=show all user areas, 0=show current area
  157. NUMCOL:
  158.     DB    3        ;number of columns displayed
  159. NUMLIN:
  160.     DB    21        ;number of lines per page
  161. OPTION:
  162.     DB    1        ;1=allow options, 0=not allowed
  163. DEFSPC:
  164.     DB    0,'???????????'    ;default file spec
  165. PASSON:
  166.     DB    0        ;1=ask password if option=1, 0=no password
  167. PASSWD:
  168.     DB    'PASSWORD',0,0    ;10 character password if passon=1
  169. MAXUSR:
  170.     DB    15        ;maximum allowed user area
  171. MAXDRV:
  172.     DB    2        ;maximum allowed drive
  173. ;
  174. ;set up local stack
  175. ;
  176. START:
  177.     LD    HL,0
  178.     ADD    HL,SP
  179.     LD    (CCPSTK),HL    ;save stack
  180.     LD    SP,STACK    ;start local stack
  181.     CALL    RETUD##
  182.     LD    A,B
  183.     LD    (CURDRV),A
  184.     LD    (OLDDRV),A
  185.     LD    A,C
  186.     LD    (CURUSR),A
  187.     LD    (OLDUSR),A
  188.     CALL    PUTUD##        ;save current disk/user
  189.     JP    START0        ;go get command line
  190. ;
  191. ;exit back to ccp control
  192. ;
  193. EXIT:
  194.     CALL    GETUD##        ;get original disk/user
  195.     LD    HL,(CCPSTK)    ;get old stack pointer
  196.     LD    SP,HL        ;place it in position
  197.     RET            ;go to it
  198. ;
  199. ;local stack
  200. ;
  201. CCPSTK:
  202.     DS    2        ;ccp stack
  203.     DB    '(c)1984 Simon J. Ewins, '
  204.     DB    'all rights reserved...'
  205.     DS    100        ;stack area
  206. STACK:
  207.     DS    2        ;start of stack
  208. ;
  209. ;set flags based on default info... may be changed by use of /options
  210. ;as required and relative to base flags above.
  211. ;
  212. START0:
  213.     LD    A,(SYSFIL)
  214.     LD    (SYSOPT),A    ;set system shown or not
  215.     LD    A,(USRARA)
  216.     LD    (USROPT),A    ;set show all user areas or not
  217.     LD    HL,(BSPEED)    ;get address of baudrate code
  218.     LD    A,H
  219.     OR    L        ;if address is zero then use BAUDCD as is
  220.     JR    Z,GETCOM
  221.     LD    A,(HL)        ;get speed code
  222.     cp    7        ;valid code?
  223.     jr    c,spok        ;yes, skip...
  224.     ld    a,1        ;...else default to 300
  225. spok:    LD    (BAUDCD),A    ;store it in place
  226. ;
  227. ;get command line info, see if anything entered at all first
  228. ;
  229. GETCOM:
  230.     LD    HL,CTAIL
  231.     LD    A,(HL)        ;get character count
  232.     OR    A
  233.     JP    Z,DODIR        ;nothing entered so do default directory
  234.     INC    HL        ;point to first character entered
  235.     PUSH    HL        ;save it
  236.     ADD    A,L        ;point at one passed end of string entered
  237.     LD    L,A
  238.     XOR    A
  239.     LD    (HL),A        ;set 0 to mark end
  240.     POP    HL        ;get back first character
  241.     DEC    HL        ;ready for next inc
  242. ;
  243. ;determine if filespec entered or just option switch, help, or junk
  244. ;
  245. GETLOP:
  246.     INC    HL        ;point to next character
  247.     LD    A,(HL)
  248.     OR    A        ;at end of entry?
  249.     JP    Z,HELP        ;not filespec or options so show how to use
  250.     CP    '?'
  251.     JP    Z,HELP        ;wants help
  252.     CP    '/'
  253.     JP    Z,DOOPT        ;just options so process them
  254.     CP    ' '
  255.     JR    Z,GETLOP    ;get passed any leading spaces
  256. ;
  257. ;got filespec so initialize fcb
  258. ;
  259.     LD    A,1
  260.     LD    (SPCFLG),A    ;flag that we need to move filespec
  261.     LD    DE,FCB
  262.     CALL    FNAME##        ;set filespec to fcb
  263.     JP    Z,HELP        ;user or drive not legal
  264.     PUSH    HL        ;save pointer to next character in string
  265.     LD    A,B
  266.     CP    0FFH
  267.     JR    Z,GETDRV
  268.     LD    D,A        ;move to d to check ....
  269.     LD    A,(MAXDRV)    ;.... max drive against requested drive
  270.     CP    D
  271.     JR    C,GETDRV    ;too high
  272.     LD    A,D        ;okay so get back request
  273.     DEC    A        ;adjust drive spec
  274.     LD    (CURDRV),A    ;save it
  275.     JR    CHKUSR
  276. GETDRV:
  277.     LD    A,(OLDDRV)
  278.     LD    (CURDRV),A    ;make it current drive
  279. CHKUSR:
  280.     LD    A,C
  281.     CP    0FFH
  282.     JR    Z,GETUSR
  283.     LD    B,A        ;move to b to check ....
  284.     LD    A,(MAXUSR)    ;.... max user against requested area
  285.     CP    B
  286.     JR    C,GETUSR    ;requested is greater than that allowed
  287.     LD    A,B        ;okay user so get back wanted area
  288.     LD    (CURUSR),A
  289.     JR    LOGIN
  290. GETUSR:
  291.     LD    A,(OLDUSR)
  292.     LD    (CURUSR),A    ;make it current user
  293. LOGIN:
  294.     LD    A,(CURDRV)
  295.     LD    B,A
  296.     LD    A,(CURUSR)
  297.     LD    C,A
  298.     CALL    LOGUD##        ;log in drive and user (either new or current)
  299. ;
  300.     POP    HL        ;get pointer to next character
  301.     LD    A,(HL)
  302.     OR    A        ;terminated ?
  303.     JP    Z,DODIR        ;yes, so done with command line
  304.     INC    HL
  305.     LD    A,(HL)
  306.     CP    '/'
  307.     JR    Z,DOOPT
  308.     JP    DODIR        ;no options so do directory
  309. ;
  310. SIZE:
  311.     DB    16
  312. CCNT:
  313.     DS    1
  314. LINE:
  315.     DS    17        ;input buffer
  316. ;
  317. DOOPT:
  318.     INC    HL        ;point to first character after /
  319.     PUSH    HL        ;save pointer to options
  320.     LD    A,(OPTION)    ;options allowed?
  321.     OR    A
  322.     JP    Z,DODIR        ;0=no
  323.     LD    A,(PASSON)    ;need password check?
  324.     OR    A
  325.     JP    Z,NOPASS    ;0=no
  326.     CALL    PRINT##
  327.     DB    CR,LF
  328.     DB    'Password: ',0
  329.     XOR    A
  330.     LD    HL,SIZE
  331.     CALL    BLINE##
  332.     LD    DE,PASSWD
  333. PMATCH:
  334.     LD    A,(DE)
  335.     OR    A
  336.     JR    Z,ENDSTR
  337.     CP    (HL)        ;match?
  338.     JP    NZ,EXIT        ;nope
  339.     INC    DE
  340.     INC    HL
  341.     JR    PMATCH
  342. ENDSTR:
  343.     LD    A,(HL)        ;see if also at end of passwd string
  344.     OR    A
  345.     JP    NZ,EXIT        ;end of input string before end of passwd
  346.     CALL    CRLF##
  347. ;
  348. NOPASS:
  349.     POP    HL        ;get pointer to option(s)
  350. OPTLOP:
  351.     LD    A,(HL)
  352.     OR    A
  353.     JP    Z,DODIR        ;no more so do directory listing
  354.     CP    'S'
  355.     JR    Z,SETSYS
  356.     CP    'A'
  357.     JR    Z,SETALL
  358.     CP    'B'
  359.     JR    Z,SETBPS
  360. OPTRET:
  361.     INC    HL
  362.     JR    OPTLOP        ;keep getting options
  363. ;
  364. SETSYS:
  365.     LD    A,1
  366.     LD    (SYSOPT),A    ;set flag
  367.     JR    OPTRET
  368. ;
  369. SETALL:
  370.     LD    A,1
  371.     LD    (USROPT),A    ;set flag
  372.     JR    OPTRET
  373. ;
  374. SETBPS:
  375.     INC    HL        ;point to number
  376.     LD    A,(HL)
  377.     OR    A
  378.     JR    Z,DODIR        ;at end of string so go do it
  379.     CP    '0'
  380.     JR    C,OPTRET    ;must be valid number 0-6
  381.     CP    '6'+1
  382.     JR    NC,OPTRET
  383.     SUB    30H        ;make it binary
  384.     LD    (BAUDCD),A    ;store it
  385.     XOR    A        ;set BSPEED address to 0
  386.     LD    (BSPEED),A
  387.     LD    (BSPEED+1),A
  388.     JR    OPTRET
  389. ;
  390. OLDDRV:            ;initial drive
  391.     DB    0
  392. OLDUSR:            ;initial user
  393.     DB    0
  394. CURDRV:            ;working drive
  395.     DB    0
  396. CURUSR:            ;working user
  397.     DB    0
  398. SELBYT:            ;byte to determine files to select
  399.     DB    0
  400. SPCFLG:            ;whether to load fn.ft into defspc
  401.     DB    0
  402. FSIZ:                ;total file size
  403.     DW    0
  404. FREE:                ;free space left
  405.     DW    0
  406. FILES:                ;number of files scanned
  407.     DW    0
  408. COLCNT:            ;current column number
  409.     DB    0
  410. LINCNT:            ;current line number
  411.     DB    0
  412. RECCNT:            ;number of records in current file
  413.     DW    0
  414. MINS:                ;xmodem minutes
  415.     DB    0
  416. SECS:                ;xmodem seconds
  417.     DB    0
  418. TMINS:                ;accumulated time in minutes
  419.     DW    0
  420. TSECS:                ;accumulated time in seconds
  421.     DW    0
  422. FMASK:                ;mask for file display
  423.     DB    '        .   ',0
  424. SPACER:            ;divider for columns
  425.     DB    'k',0
  426. FENCE:
  427.     DB    ' | ',0
  428. BTAB:
  429.     DB    5,13,20,25,29,48,96,0
  430. RECTAB:
  431.     DB    192,74,48,38,32,20,10,0
  432. BPSTAB:
  433.     DB    '110 ',0
  434.     DB    '300 ',0
  435.     DB    '450 ',0
  436.     DB    '600 ',0
  437.     DB    '710 ',0
  438.     DB    '1200',0
  439.     db    '2400',0
  440. ;
  441. ;do directory load, sort and print using values placed in code for
  442. ;structuring the directory listing.
  443. ;
  444. DODIR:
  445.     LD    IY,SELBYT    ;point to bit-mapped selection byte
  446.     LD    A,(SPCFLG)    ;need to move fcb?
  447.     OR    A
  448.     JR    Z,SYSOPT-1    ;no move
  449.     LD    DE,DEFSPC
  450.     LD    HL,FCB
  451.     LD    BC,12
  452.     LDIR
  453. ;
  454. SYSOPT    EQU    $+1        ;in-code modification
  455.     LD    A,0
  456.     OR    A
  457.     JR    Z,NOSYS
  458.     SET    6,(IY)
  459.     SET    7,(IY)
  460.     JR    USROPT-1
  461. NOSYS:
  462.     SET    7,(IY)
  463.     RES    6,(IY)
  464. ;
  465. USROPT    EQU    $+1        ;in-code modification
  466.     LD    A,0
  467.     OR    A
  468.     JR    Z,USRCUR
  469.     SET    5,(IY)
  470.     RES    4,(IY)
  471.     RES    3,(IY)
  472.     RES    2,(IY)
  473.     RES    1,(IY)
  474.     RES    0,(IY)
  475.     LD    A,(IY)
  476.     JR    GETDIR
  477. USRCUR:
  478.     RES    5,(IY)
  479.     LD    A,(CURUSR)
  480.     AND    0FH        ;clear out top 4 bits
  481.     ADD    A,(IY)        ;a=selection bits
  482. ;
  483. GETDIR:
  484.     PUSH    AF        ;save bit map
  485.     CALL    CODEND##    ;get end of code
  486.     LD    DE,DEFSPC    ;point to filespec
  487.     POP    AF        ;get back bit map
  488.     CALL    DIRFS##        ;read directory with sizing
  489. ;
  490.     LD    (FILES),BC    ;save number files selected
  491. ;
  492. ; Calculate # of K free on selected drive now so that the FREE figure
  493. ; will not reflect either the creation or additions to the SD.DIR file
  494. ; (which we would probably erase or move anyway).
  495. ;
  496.     PUSH    AF
  497.     PUSH    BC
  498.     PUSH    HL
  499.     LD    C,12        ;CP/M version number
  500.     CALL    BDOS
  501.     LD    A,L        ;get version
  502.     CP    30H        ;3.0?
  503.     JP    C,FREE20    ;use old method if not
  504.     LD    A,(CURDRV)    ;get drive #
  505.     LD    E,A        ;use new Compute Free Space BDOS call
  506.     LD    C,46
  507.     CALL    BDOS
  508.     LD    C,3        ;answer is a 24-bit integer
  509. ;
  510. FRE3L1:    LD    HL,82H        ;answer is in 1st 3 bytes of DMA adr
  511.     LD    B,3        ;convert it from sectors to K
  512.     OR    A        ;by dividing by 8
  513. ;
  514. FRE3L2:    LD    A,M
  515.     RRA
  516.     LD    M,A
  517.     DEC    HL
  518.     DEC    B
  519.     JP    NZ,FRE3L2    ;loop for 3 bytes
  520.     DEC    C
  521.     JP    NZ,FRE3L1    ;shift 3 times
  522.     LD    HL,(80H)    ;now get result in K
  523.     LD    (FREE),HL
  524.     POP    HL
  525.     POP    BC
  526.     POP    AF
  527.     JP    GOTFRE
  528. ;
  529. FREE20:    POP    HL
  530.     POP    BC
  531.     POP    AF
  532. ;
  533. ;
  534.     CALL    DFREE##        ;get free space
  535.     LD    (FREE),DE    ;save free space in k bytes
  536. ;
  537. GOTFRE:    LD    A,B
  538.     OR    C        ;if no files then ....
  539.     JP    Z,NOFILE
  540. ;
  541. ;print each name, size and time
  542. ;
  543. PRNTF:
  544.     CALL    CRLF##
  545.     LD    A,(NUMCOL)
  546.     INC    A        ;offset for base 1
  547.     LD    (COLCNT),A    ;column count to storage
  548.     LD    A,(NUMLIN)
  549.     INC    A        ;offset for base 1
  550.     LD    (LINCNT),A    ;line count to storage
  551.     LD    BC,(FILES)    ;get number of files loaded
  552.     INC    BC        ;base 1
  553.     PUSH    BC        ;save it
  554. ;
  555. ;loop here for number of files now in bc
  556. ;
  557. PRTLOP:
  558.     POP    BC
  559.     DEC    BC        ;knock down counter
  560.     LD    A,B
  561.     OR    C
  562.     JP    Z,PLOPDN    ;0=done
  563.     PUSH    BC
  564.     PUSH    HL        ;save current file pointer
  565. ;
  566. ;check for special CP/M Plus directory entry, if so, bypass it
  567. ;
  568.     LD    A,M        ;get drive/user byte
  569.     CP    16        ;label, XFCB, or SFCB? (special=drive+16
  570.     JP    C,PRTLP1    ;no, continue with file display
  571.     LD    BC,(FILES)    ;retrieve number of files selected
  572.     DEC    BC        ;drop the count by one
  573.     LD    (FILES),BC    ;replace the adjusted file count
  574.     JP    BMPPTR        ;don't display this file
  575. PRTLP1:
  576. ;
  577. ;see if user wants to pause
  578. ;
  579.     CALL    CONDIN##    ;see if character at keyboard
  580.     CP    'C'-40H        ;quit??
  581.     JP    Z,EXIT        ;quit
  582.     CP    'S'-40H        ;pause?
  583.     CALL    Z,WAIT        ;pause
  584. ;
  585. ;see if time for a new line
  586. ;
  587.     LD    A,(COLCNT)
  588.     DEC    A        ;columns - 1
  589.     LD    (COLCNT),A
  590.     OR    A
  591.     CALL    Z,NEWLIN    ;need new line
  592. ;
  593. ;print file name
  594. ;
  595.     POP    HL        ;get pointer back
  596.     PUSH    HL        ;save it again
  597.     INC    HL        ;point past drive/user byte
  598.     LD    DE,FMASK    ;point to print mask
  599.     LD    BC,8
  600.     LDIR
  601.     INC    DE
  602.     LD    BC,3
  603.     LDIR            ;move filename.typ to mask
  604.     LD    HL,FMASK    ;point to string
  605.     CALL    PSTR##        ;print it
  606. ;
  607. ;get size of file and print it
  608. ;
  609.     POP    HL        ;get pointer
  610.     PUSH    HL        ;store it again
  611.     CALL    FSIZE##        ;get size
  612.     LD    HL,(FSIZ)    ;get total size so far
  613.     ADD    HL,DE        ;add new file
  614.     LD    (FSIZ),HL    ;store result
  615.     CALL    PTFMT        ;show result
  616.     LD    HL,SPACER    ;point to fence stuff
  617.     CALL    PSTR##        ;print it
  618. ;
  619. ;calculate number of records in file
  620. ;
  621.     POP    HL
  622.     PUSH    HL        ;point to first byte of record
  623.     LD    DE,12        ;offset to # extents used
  624.     ADD    HL,DE
  625.     PUSH    HL
  626.     LD    A,(HL)
  627.     LD    HL,128        ;multiply by 128
  628.     LD    H,L        ;move to h first
  629.     CALL    MULHA
  630.     LD    (RECCNT),HL    ;save partial result
  631.     POP    HL        ;pointer to byte 13
  632.     INC    HL        ;... to 14
  633.     INC    HL        ;... to 15
  634.     push    hl
  635.     ld    a,(hl)        ;check S1 byte
  636.     or    a
  637.     jr    z,novfl        ;no overflow extents
  638.     ld    hl,0
  639.     ld    de,4096        ;4096 sectors per ov extent
  640. lp:    add    hl,de
  641.     dec    a
  642.     jr    nz,lp
  643.     ld    de,(reccnt)
  644.     add    hl,de
  645.     ld    (reccnt),hl
  646. novfl:    pop    hl
  647.     INC    HL        ;point to records in last extent
  648.     LD    A,(HL)
  649.     LD    E,A
  650.     LD    D,0
  651.     LD    HL,(RECCNT)    ;get partial result
  652.     ADD    HL,DE        ;merge to get total records
  653.     LD    (RECCNT),HL    ;store it
  654. ;
  655. ;calculate minutes to send
  656. ;
  657.     LD    A,(BAUDCD)    ;get baudrate code
  658.     LD    D,0
  659.     LD    E,A        ;table offset
  660.     LD    HL,BTAB
  661.     ADD    HL,DE
  662.     LD    A,(HL)        ;factor in a
  663.     LD    HL,(RECCNT)
  664.     CALL    DIVHA        ;divide recs/min
  665.     PUSH    HL
  666.     LD    A,L
  667.     LD    (MINS),A    ;save minutes
  668. ;
  669. ;total minutes so far
  670. ;
  671.     LD    HL,(TMINS)    ;get total so far
  672.     LD    D,0
  673.     LD    E,A
  674.     ADD    HL,DE
  675.     LD    (TMINS),HL    ;total minutes so far
  676. ;
  677. ;calculate seconds
  678. ;
  679.     LD    HL,RECTAB
  680.     LD    D,0
  681.     LD    A,(BAUDCD)
  682.     LD    E,A
  683.     ADD    HL,DE
  684.     LD    A,(HL)
  685.     POP    HL        ;get back remainder
  686.     CALL    MULHA        ;h*a
  687.     CALL    SHFTHL
  688.     CALL    SHFTHL
  689.     CALL    SHFTHL
  690.     CALL    SHFTHL
  691.     LD    A,L
  692.     LD    (SECS),A    ;save seconds
  693. ;
  694. ;total seconds so far
  695. ;
  696.     LD    HL,(TSECS)    ;get total so far
  697.     LD    D,0
  698.     LD    E,A
  699.     ADD    HL,DE
  700.     LD    (TSECS),HL    ;total seconds so far
  701. ;
  702. ;now show transfer time
  703. ;
  704.     LD    A,(MINS)
  705.     LD    D,0
  706.     LD    E,A
  707.     CALL    PTFMT
  708.     LD    A,':'
  709.     CALL    COUT##
  710.     LD    A,(SECS)
  711.     LD    D,0
  712.     LD    E,A
  713.     CALL    PTFMT2
  714. ;
  715. ;if at last column, don't print fence
  716. ;
  717.     LD    A,(COLCNT)
  718.     CP    1
  719.     JR    Z,BMPPTR
  720.     LD    HL,FENCE
  721.     CALL    PSTR##
  722. ;
  723. ;now bump to next filename
  724. ;
  725. BMPPTR:
  726.     LD    DE,16
  727.     POP    HL        ;get pointer to current file
  728.     ADD    HL,DE
  729.     JP    PRTLOP
  730. ;
  731. ;done with files so print footer
  732. ;
  733. PLOPDN:
  734.     CALL    CRLF##
  735.     CALL    CRLF##
  736. ;
  737. ;current drive
  738. ;
  739.     LD    A,(CURDRV)
  740.     ADD    A,41H        ;make drive a letter
  741.     CALL    COUT##        ;print it
  742. ;
  743. ;current user area
  744. ;
  745.     LD    A,(CURUSR)
  746.     LD    H,0
  747.     LD    L,A
  748.     CALL    PB2ASC        ;print user number
  749.     LD    HL,USRMSG
  750.     CALL    PSTR##
  751. ;
  752. ;number of files
  753. ;
  754.     LD    HL,(FILES)
  755.     CALL    PB2ASC
  756. ;
  757. ;total size of all files
  758. ;
  759.     LD    A,(NUMCOL)    ;if number of columns less than 3
  760.     CP    3        ;then print crlf and gobble 2 spaces
  761.     JR    NC,SIZOV3
  762.     CALL    CRLF##
  763.     LD    HL,SIZMSG+2
  764.     JR    SIZPRT
  765. SIZOV3:
  766.     LD    HL,SIZMSG
  767. SIZPRT:
  768.     CALL    PSTR##
  769.     LD    HL,(FSIZ)
  770.     CALL    PB2ASC
  771. ;
  772. ;space free on disk
  773. ;
  774.     LD    HL,FREMSG
  775.     CALL    PSTR##
  776.     LD    HL,(FREE)
  777.     CALL    PB2ASC
  778. ;
  779. ;time to transfer entire disk, calculate seconds mod 60 and add to
  780. ;minutes and minutes mod 60 and add to hours as required.
  781. ;
  782.     LD    HL,TIMMSG
  783.     CALL    PSTR##
  784. ;
  785.     LD    HL,(TSECS)
  786.     LD    A,60        ;divide seconds by 60
  787.     CALL    DIVHA        ;seconds divided by minutes
  788.     PUSH    HL
  789.     LD    L,H
  790.     LD    H,0
  791.     LD    (TSECS),HL    ;remainder is seconds
  792.     POP    HL
  793.     LD    D,0
  794.     LD    E,L
  795.     LD    HL,(TMINS)    ;now add quotient to minutes
  796.     ADD    HL,DE
  797.     LD    A,60
  798.     CALL    DIVHA        ;minutes divided by 60
  799.     PUSH    HL
  800.     LD    L,H
  801.     LD    H,0
  802.     LD    (TMINS),HL    ;remainder is minutes
  803.     POP    HL
  804.     LD    H,0        ;quotient in l is hours
  805. ;
  806. ;don't need to format hours
  807. ;
  808.     CALL    PB2ASC
  809.     LD    A,':'
  810.     CALL    COUT##
  811. ;
  812. ;format minutes to 2 characters
  813. ;
  814.     LD    DE,(TMINS)
  815.     CALL    PTFMT2
  816.     LD    A,':'
  817.     CALL    COUT##
  818. ;
  819. ;need to format seconds as well
  820. ;
  821.     LD    DE,(TSECS)
  822.     CALL    PTFMT2
  823.     LD    HL,BPSMSG
  824.     CALL    PSTR##
  825. ;
  826. ;show baudrate used for calculation
  827. ;
  828.     LD    HL,BPSTAB
  829.     LD    D,0
  830.     LD    A,(BAUDCD)
  831.     ld    e,a
  832.     add    a,e
  833.     add    a,e
  834.     add    a,e
  835.     add    a,e
  836.     LD    E,A
  837.     ADD    HL,DE
  838.     CALL    PSTR##
  839. ;
  840. ;wrap it up
  841. ;
  842.     LD    HL,CLSMSG
  843.     CALL    PSTR##
  844.     CALL    CRLF##
  845.     JP    EXIT
  846. ;
  847. ;messages
  848. ;
  849. USRMSG:
  850.     DB    '>>  Files: ',0
  851. SIZMSG:
  852.     DB    '  Used: ',0
  853. FREMSG:
  854.     DB    'k  Free: ',0
  855. TIMMSG:
  856.     DB    'k  Time: ',0
  857. BPSMSG:
  858.     DB    ' at ',0
  859. CLSMSG:
  860.     DB    ' baud',0
  861. ;
  862. ;subroutines:
  863. ;~~~~~~~~~~~
  864. ;
  865. ;multiply h*a hl=result
  866. ;
  867. MULHA:
  868.     LD    B,A        ;set counter
  869.     LD    D,0
  870.     LD    E,H
  871.     LD    L,H
  872.     LD    H,0
  873. MULLP:
  874.     DEC    B
  875.     RET    Z
  876.     ADD    HL,DE
  877.     JR    MULLP
  878. ;
  879. ;divide hl/a h=remainder, l=quotient
  880. ;
  881. DIVHA:
  882.     PUSH    BC
  883.     LD    B,8
  884.     LD    C,A
  885. DIV2:
  886.     XOR    A
  887.     ADD    HL,HL
  888.     LD    A,H
  889.     SUB    C
  890.     JP    M,DIV3
  891.     LD    H,A
  892.     LD    A,L
  893.     OR    1
  894.     LD    L,A
  895. DIV3:
  896.     DEC    B
  897.     JP    NZ,DIV2
  898.     POP    BC
  899.     RET
  900. ;
  901. ;shift hl one right
  902. ;
  903. SHFTHL:
  904.     LD    A,L
  905.     RRA
  906.     LD    L,A
  907.     OR    A        ;clear carry
  908.     LD    A,H
  909.     RRA
  910.     LD    H,A
  911.     RET    NC
  912.     LD    A,80H
  913.     OR    L
  914.     LD    L,A
  915.     RET
  916. ;
  917. ;prints de as 2 or 3 characters left padded with spaces
  918. ;
  919. PTFMT2:
  920.     PUSH    DE        ;save number
  921.     LD    HL,99
  922.     AND    A        ;clear carry
  923.     SBC    HL,DE        ;de > 99 ?
  924.     JR    C,PRT00        ;3 digits
  925.     LD    A,E
  926.     CP    10
  927.     JR    NC,PRT00    ;2 digits
  928.     LD    A,'0'
  929.     CALL    COUT##
  930.     JR    PRT00        ;1 digit (leading 0)
  931. PTFMT:
  932.     PUSH    DE        ;save number
  933.     ld    hl,999
  934.     and    a
  935.     sbc    hl,de
  936.     jr    c,prt00
  937.     LD    HL,99
  938.     AND    A        ;clear carry
  939.     SBC    HL,DE        ;de > 99 ?
  940.     JR    C,PRT0        ;filesize > 99
  941.     LD    A,E
  942.     CP    10        ;2 digits?
  943.     JR    NC,PRT1        ;filesize < 100 > 9
  944. PRT2:                ;must be single digit
  945.     LD    A,' '
  946.     CALL    COUT##
  947. PRT1:                ;2 digits
  948.     LD    A,' '
  949.     CALL    COUT##
  950. PRT0:
  951.     ld    a,' '
  952.     call    cout##
  953. prt00:    POP    HL
  954.     CALL    PB2ASC        ;print size
  955.     RET
  956. ;
  957. ;prints binary number in hl as decimal number with no leading spaces
  958. ;
  959. PB2ASC:
  960.     LD    A,H
  961.     OR    L        ;see if 0
  962.     JR    Z,PZERO        ;yes so skip all this next stuff
  963.     PUSH    IY        ;save register
  964.     XOR    A
  965.     LD    (PBFLG),A    ;show no digit printed yet
  966.     LD    IY,P10        ;point to powers of ten table
  967. PBLP0:
  968.     XOR    A        ;clear digit count
  969.     LD    D,(IY+1)
  970.     LD    E,(IY)
  971. PBLP1:
  972.     OR    A        ;clear carry
  973.     SBC    HL,DE        ;sub pow of 10
  974.     JP    C,PBJP1        ;finished
  975.     INC    A        ;bump count
  976.     JP    PBLP1
  977. PBJP1:
  978.     ADD    HL,DE        ;make positive
  979.     ADD    A,30H
  980.     CP    '0'        ;see if a 0
  981.     JP    NZ,PBJP1B    ;if not then print it
  982. ;
  983. PBFLG    EQU    $+1
  984.     LD    A,0        ;if is 0 then get flag
  985.     CP    1        ;see if before 1-9 digit
  986.     JP    Z,PBJP1A    ;no, so print it
  987.     JP    PBJP2        ;yes, so don't print
  988. PBJP1A:
  989.     LD    A,'0'        ;restore digit
  990. PBJP1B:
  991.     PUSH    HL
  992.     PUSH    DE
  993.     CALL    COUT##        ;print digit
  994.     POP    DE
  995.     POP    HL
  996.     LD    A,1
  997.     LD    (PBFLG),A    ;set character printed flag
  998. PBJP2:
  999.     INC    IY
  1000.     INC    IY        ;point next power of ten
  1001.     LD    A,E
  1002.     CP    1        ;see if 5 digits yet
  1003.     JP    NZ,PBLP0
  1004.     POP    IY        ;restore msgarr pointer
  1005.     RET            ;done
  1006. P10:
  1007.     DW    10000
  1008.     DW    1000
  1009.     DW    100
  1010.     DW    10
  1011.     DW    1
  1012. ;
  1013. PZERO:
  1014.     LD    A,'0'
  1015.     CALL    COUT##
  1016.     RET
  1017. ;
  1018. NEWLIN:
  1019.     LD    A,(NUMCOL)    ;reset counter
  1020.     LD    (COLCNT),A
  1021.     CALL    CRLF##
  1022.     LD    A,(LINCNT)
  1023.     DEC    A
  1024.     LD    (LINCNT),A    ;save new line count
  1025.     OR    A
  1026.     CALL    Z,PGPAUS    ;wait for keystroke
  1027.     RET
  1028. PGPAUS:
  1029.     LD    A,(NUMLIN)    ;reset counter
  1030.     LD    (LINCNT),A
  1031.     CALL    PRINT##
  1032.     DB    '       [ More ]',13,0
  1033. WAIT:
  1034.     CALL    CONDIN##
  1035.     JR    Z,WAIT
  1036.     CP    'C'-40H
  1037.     JP    Z,EXIT        ;ctrl-c ends it all
  1038.     RET
  1039. ;
  1040. HELP:
  1041.     CALL    PRINT##
  1042.     DB    CR,LF,LF
  1043.     DB    'Remote DIRectory v1.5+ -- (c)1984 Simon J. Ewins'
  1044.     DB    CR,LF,LF
  1045.     DB    'Usage:',CR,LF,LF
  1046.     DB    'RDIR      :show all files with xfer times at current baudrate'
  1047.     DB    CR,LF
  1048.     DB    'RDIR /s   :show all files + system files + xfer times'
  1049.     DB    CR,LF
  1050.     DB    'RDIR /a   :show all files in all user areas + xfer times'
  1051.     DB    CR,LF
  1052.     DB    'RDIR /b#  :change baudrate times to # (0-7)'
  1053.     DB    CR,LF,LF
  1054.     DB    'Any combination of /asb# is allowed.'
  1055.     DB    CR,LF,LF
  1056.     DB    'RDIR du:afn.aft /options   (drive/user & wildcards allowed).'
  1057.     DB    CR,LF,LF
  1058.     DB    '/options may be disallowed on some systems.'
  1059.     DB    CR,LF,LF,0
  1060.     JP    EXIT
  1061. ;
  1062. NOFILE:
  1063.     CALL    PRINT##
  1064.     DB    CR,LF,LF
  1065.     DB    '>>> ',0
  1066.     LD    A,(CURDRV)
  1067.     ADD    A,41H
  1068.     CALL    COUT##
  1069.     LD    A,(CURUSR)
  1070.     LD    H,0
  1071.     LD    L,A
  1072.     CALL    PB2ASC
  1073.     CALL    PRINT##
  1074.     DB    ':  No files (',0
  1075.     LD    HL,(FREE)
  1076.     CALL    PB2ASC
  1077.     CALL    PRINT##
  1078.     DB    'k free) <<<'
  1079.     DB    CR,LF,LF,0
  1080.     JP    EXIT
  1081. ;
  1082. ;
  1083. ;*
  1084.     END
  1085. ;*
  1086. :  No files (',0
  1087.     LD    HL,(FREE)
  1088.     CALL    PB2ASC
  1089.     CALL    PRINT##
  1090.     DB    'k free) <<<'
  1091.     DB    CR,LF,LF,0
  1092.     JP    EXIT
  1093. ;
  1094. ;