home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11rtd.mac < prev    next >
Text File  |  2020-01-01  |  24KB  |  896 lines

  1.     .title    k11rtd    wildcard directory lookup for RT11
  2.     .ident    /2.17/
  3.  
  4. ;     18-Jun-84  16:33:01  Brian Nelson
  5. ;
  6. ;
  7. ;     Copyright (C) 1984 Change Software, Inc
  8. ;
  9. ;     17-Sep-86  13:23:00 Handle Labels stuffed in by VMS Exchange
  10.  
  11.  
  12. ;    Include things we want for kermit
  13.  
  14.  
  15.  
  16.     .if ndf, K11INC
  17.     .ift
  18.     .include    /IN:K11MAC.MAC/
  19.     .endc
  20.  
  21.     .iif ndf, k11inc,   .error    ; .INCLUDE failed
  22.  
  23.     .psect
  24.  
  25.     .enabl    gbl
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.     .sbttl    local data offsets and definitions
  37.  
  38.  
  39.     .mcall    .csispc ,.dstat ,.fetch ,.lookup,.readw ,.close ,.cstat
  40.     .mcall    .serr    ,.herr    ,.purge
  41.  
  42.     topmem    =    50
  43.     errbyt    =    52
  44.  
  45.     DEV$LD    =    46        ;/45/ LD: identification
  46.  
  47.     tent    =    400        ; status for a tentative file
  48.     empty    =    1000        ; status for an empty entry
  49.     perm    =    2000        ; status bit for a permanent file
  50.     endseg    =    4000        ; end of a segment bits
  51.  
  52. ;;    star    =    134745        ; from .csispc for a '*' (rt11/rsts)
  53.     star    =    132500        ; from .csispc for a '*' (real RT11)
  54.  
  55.     .psect    rtdir    ,rw,d,lcl,rel,con
  56.  
  57.  
  58. hd$blk    =    1            ; vbn of the home block
  59. hd$fir    =    724            ; offset into home block for first block
  60. hd$vol    =    730            ; RT11A and seven spaces usually
  61. hd$sys    =    760            ; always DECRT11A
  62.  
  63.  
  64. outlun: .word    0
  65. dirbuf: .blkb    2000            ; 2 block buffer for directory segments
  66. name1:    .blkb    12
  67. name2:    .blkb    12
  68.  
  69.     .save
  70.     .psect    rtdir1    ,rw,d,gbl,rel,con
  71. contex: .word    0            ; current file number
  72. hd.fir: .word    0            ; block number of first entry
  73. itsopen:.word    0
  74. time:    .word    0,45
  75. devtyp: .word    0
  76.     .restore
  77. junk:    .blkb    20
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. ;     information from the directory header
  89.  
  90. h$nseg    =    0            ; offset for segment count in buffer
  91. h$next    =    2            ; offset for next block link
  92. h$max    =    4            ; offset for highest segment in use
  93. h$ext    =    6            ; offset for number of extra words
  94. h$blk    =    10            ; offset for first block # of data
  95.  
  96. h.nseg: .blkw    1            ; number of segments in the directory
  97. h.next: .blkw    1            ; link to the next directory segment
  98. h.max:    .blkw    1            ; max segment actually in use
  99. h.ext:    .blkw    1            ; number of extra words per entry
  100. h.blk:    .blkw    1            ; data block number for the segment
  101.  
  102.  
  103. ;     information from the current directoty entry
  104.  
  105. f.stat    =    0            ; entry status word
  106. f.nam    =    2            ; all three words of the name+type
  107. f.nam1    =    2            ; first three rad50 characters of name
  108. f.nam2    =    4            ; last three rad50 characters of name
  109. f.type    =    6            ; all three rad50 characters of type
  110. f.len    =    10            ; file size
  111. f.misc    =    12            ; we don't care about this stuff
  112. f.date    =    14            ; creation date
  113.  
  114.  
  115.     .save
  116.     .psect    rtdir1    ,rw,d,gbl,rel,con
  117. loklen: .word    0            ;/38/ added for server
  118. lokdate:.word    0            ;/38/ added for server
  119. dirsiz: .blkw    1            ; total size of a directory entry
  120. filnam: .blkw    4            ; the .csispc parsed filename+type
  121. resnam: .blkw    4            ; the name we found
  122.     .restore
  123.  
  124.     .psect
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.     .psect    $code
  136.  
  137. lookup::save    <r1,r2,r3>        ; save all the temps please
  138.     copyz    2(r5)    ,6(r5)        ; return the passed name for starters
  139.     tst    nowild            ;/51/ Perhaps send a DEVICE?
  140.     beq    30$            ;/51/ No
  141.     clr    r0            ;/51/ Assume success
  142.     tst    @4(r5)            ;/51/ Second time for sending device?
  143.     beq    20$            ;/51/ No
  144.     mov    #ER$NMF ,r0        ;/51/ Yes, br 100$ all done
  145.     br    100$            ;/51/ Exit
  146. 20$:    inc    @4(r5)            ;/51/ Success, increment context.
  147.     br    100$            ;/51/ Exit
  148.  
  149. 30$:    tst    @4(r5)            ; new call sequence today?
  150.     bne    40$            ; no
  151.     clr    context            ; yes, flag so
  152.     clr    h.max            ; also init a flag
  153.     .close    #lun.sr            ; close the old device up also
  154.     clr    r0            ; no errors please
  155.     clr    itsopen            ; device is no longer open
  156.  
  157. 40$:    tst    itsopen            ; need to open it up
  158.     bne    50$            ; no, already established a context
  159.     call    opndev            ; get the disk opened up please
  160.     tst    r0            ; any errors ?
  161.     bne    100$            ; yes, we will have to die then
  162.     mov    sp    ,itsopen    ; device is open for next call
  163. 50$:    call    getnth            ; lookup the next one please
  164.     tst    r0            ; errors ?
  165.     bne    90$            ; no
  166.     inc    @4(r5)            ; return correct context
  167.     br    100$
  168.  
  169. 90$:    push    r0            ;    yes, close the device please
  170.     .close    #lun.sr            ; close the device up on errors
  171.     clr    context            ; insure current context is cleared
  172.     clr    itsopen            ; insure we do an open next time
  173.     pop    r0            ; restore the error code now
  174.  
  175. 100$:    unsave    <r3,r2,r1>        ; pop temps and exit please
  176.     return                ; return any errors in r0
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.     .sbttl    print directory listing
  188.  
  189.  
  190.  
  191. ;     D O D I R
  192. ;
  193. ;     input: @r5    wildcarded filespec
  194. ;     output:    r0    error code
  195. ;
  196. ;     DODIR prints a directory listing at the local terminal.
  197. ;
  198. ;
  199. ;     S D O D I R
  200. ;
  201. ;     Passed:    @r5    wildcarded name
  202. ;     Return:    r0    error code, zero for no errors
  203. ;            r1    next character in the directory listing
  204. ;
  205. ;     SDODIR is called by the server to respond to a remote directory
  206. ;     command.  Instead of the pre 2.38 method of dumping output to a
  207. ;     disk file and then sending the disk file in an extended replay,
  208. ;     SDODIR     returns the next  character so that  BUFFIL can use it.
  209. ;     The routine  GETCR0  is actually a dispatch routine to call the
  210. ;     currently selected GET_NEXT_CHARACTER routine.
  211.  
  212.  
  213.     .save
  214.     .psect    dirmap    ,rw,d,gbl,rel,ovr
  215. dirnam: .blkw    1            ;/51/ Filled in at startup
  216. dirbfr: .blkw    1            ;/51/ Ditto
  217.  
  218.     .psect    rtdir1    ,rw,d,gbl,rel,con
  219. diridx: .word    0
  220. dirptr: .word    0
  221. wild:    .asciz    /*.*/
  222. dspace: .byte    40,0
  223. dcrlf:    .byte    15,12,0
  224.     .even
  225.     .restore
  226.  
  227.  
  228.  
  229.  
  230. dodir:: save    <r1,r2,r3,r5>        ; save these please
  231.     mov    2(r5)    ,outlun
  232. 10$:    mov    @r5    ,-(sp)
  233.     mov    #1    ,-(sp)
  234.     mov    sp    ,r5
  235.     call    .dodir
  236.     cmp    (sp)+    ,(sp)+
  237. 100$:    unsave    <r5,r3,r2,r1>
  238.     clr    r0
  239.     return
  240.  
  241.  
  242. .dodir: tst    itsopen            ; need to open it up
  243.     beq    10$            ; yes
  244.     .close    #lun.sr            ; please close up shop first
  245.     clr    itsopen            ; say it's closed now
  246. 10$:    call    opndev            ; get the disk opened up please
  247.     tst    r0            ; any errors ?
  248.     bne    100$            ; yes, we will have to die then
  249.     mov    sp    ,itsopen    ; device is open for next call
  250. 50$:    call    pridir            ; lookup the next one please
  251.     tst    r0            ; errors ?
  252.     beq    50$            ; no
  253.  
  254. 90$:    mov    r0    ,-(sp)        ; yes, close the device please
  255.     .close    #lun.sr            ; close the device up on errors
  256.     clr    itsopen            ; insure we do an open next time
  257.     mov    (sp)+    ,r0        ; restore the error code now
  258.  
  259. 100$:    return                ; return any errors in r0
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.     .sbttl    SDODIR    directoty stuff for a server
  271.  
  272.  
  273. sdirin::strcpy    dirnam    ,@r5        ; copy name over
  274.     mov    dirbfr    ,dirptr        ; yes, init pointers please
  275.     clr    diridx            ; ditto
  276.     call    dirini            ; init for calls to sdodir
  277.     bcs    100$
  278.     mov    dirbfr    ,dirptr        ; yes, init pointers please
  279.     clrb    @dirptr            ; yes, zap the buffer
  280.     call    dirnex            ; preload buffer
  281. 100$:    return
  282.  
  283.  
  284. sdodir::save    <r2,r3,r4>
  285. 10$:    movb    @dirptr ,r1        ; get the next character please
  286.     bne    20$            ; something was there
  287.     mov    dirbfr    ,dirptr        ; reset the pointer
  288.     clrb    @dirptr            ; yes, zap the buffer
  289.     call    dirnex            ; empty buffer, load with next file
  290.     bcs    90$            ; no more, return ER$EOF
  291.     br    10$            ; and try again
  292. 20$:    inc    dirptr            ; pointer++
  293.     clr    r0            ; no errors
  294.     br    100$            ; exit
  295. 90$:    mov    #ER$EOF ,r0        ; failure, return(EOF)
  296. 95$:    clr    r1            ; return no data also
  297.     clr    diridx            ; init for next time through
  298. 100$:    unsave    <r4,r3,r2>
  299.     return
  300.  
  301.  
  302.  
  303. dirini: clr    diridx            ; clear context flag
  304.     mov    dirbfr    ,dirptr        ; set pointer up for SDODIR
  305.     clrb    @dirptr            ; clear buffer
  306.     return                ; thats all folks
  307.  
  308.  
  309.  
  310. dirnex: movb    defdir    ,-(sp)        ; anything in DEFDIR ?
  311.     bne    10$            ; yes, don't alter it please
  312.     strcpy    #defdir ,#wild        ; nothing, insert *.*;*
  313. 10$:    mov    dirbfr    ,r2        ; pointer to buffer
  314.     mov    #junk    ,r3        ; pointer to work buffer
  315.     calls    lookup    ,<#3,dirnam,#diridx,r2>
  316.     tst    r0            ; successfull?
  317.     bne    80$            ; no
  318.     strlen    r2            ; get the length of the string
  319.     mov    #20    ,r1        ; and format the string
  320.     sub    r0    ,r1        ; number of spaces to append
  321.     ble    30$            ; can't happen
  322. 20$:    strcat    r2    ,#dspace    ; append spaces please
  323.     sob    r1    ,20$        ; next please
  324. 30$:    deccvt    loklen    ,r3        ; filesize
  325.     clrb    6(r3)            ; insure .asciz please
  326.     strcat    r2    ,r3        ; append it please
  327.     strcat    r2    ,#dspace    ; a space
  328.     mov    lokdate ,r0        ; get date converted
  329.     bne    40$            ; valid
  330.     dec    r0            ; invalid, force 00-xxx-00
  331. 40$:    calls    cvtdat    ,<r3,r0>,nogbl    ; append the date please
  332.     strcat    r2    ,r3        ;
  333.     strcat    r2    ,#dcrlf        ; yes, append <cr><lf>
  334.     clr    r0            ; success
  335.     br    100$            ; exit
  336. 80$:    cmp    r0    ,#ER$NMF    ; no more files error ?
  337.     bne    90$            ; no
  338.     tst    diridx            ; ever do anything?
  339.     bne    90$            ; yes
  340.     mov    #ER$FNF ,r0        ; no, convert to file not found
  341. 90$:    sec
  342. 100$:    movb    (sp)+    ,defdir        ; restore DEFDIR
  343.     return
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.     .sbttl    open the disk up to search the directory
  356.  
  357. opndev: .SERR                ;/51/ Trap fatal errors please
  358.     sub    #20.    ,sp        ; allocate buffer for the
  359.     mov    sp    ,r2        ; device status call
  360.     sub    #40.*2    ,sp        ; allocate a buffer for the
  361.     mov    sp    ,r1        ; .csispc data
  362.  
  363. 1$:    mov    #defdir ,r3        ; insert default device name
  364.     scan    #':    ,2(r5)        ; check for a device already there
  365.     tst    r0            ; well ?
  366.     bne    6$            ; yep. don't try to put one in please
  367. 5$:    movb    (r3)+    ,@r1        ; copy it
  368.     beq    6$            ; all done
  369.     inc    r1            ; not null, next please
  370.     br    5$            ;
  371. 6$:    mov    2(r5)    ,r0        ; string address
  372. 10$:    movb    (r0)+    ,(r1)+        ; copy it to the csi buffer
  373.     bne    10$            ; until a null byte is found.
  374.     dec    r1            ; get back to the last character
  375.     cmpb    -1(r1)    ,#':        ; is the just just a device only?
  376.     bne    15$            ; no
  377.     movb    #'*    ,(r1)+        ; yes, insert *.*
  378.     movb    #'.    ,(r1)+        ; yes, insert *.*
  379.     movb    #'*    ,(r1)+        ; yes, insert *.*
  380. 15$:    movb    #'=    ,(r1)+        ; fake an output filespec here
  381.     clrb    @r1            ; and .asciz
  382.     mov    sp    ,r1        ; reset pointer (also saving sp)
  383.     .csispc r1,#defext,r1        ; and try to parse the name
  384.     mov    r1    ,sp        ; restore from any switches
  385.     bcs    80$            ; oops
  386.     calls    fetch    ,<@r1>        ; try to get the thing loaded
  387.     tst    r0            ; well ?
  388.     bne    120$            ; no, exit with mapped error
  389.     mov    devidx    ,devtyp        ;/45/ Save device type from .FETCH
  390. 20$:    tst    @r1            ; a specific device name ?
  391.     bne    30$            ; yes
  392.     mov    #^RDK    ,@r1        ; no, stuff DK: into it then
  393.  
  394. 30$:    mov    r1    ,r0        ; copy the pointer to .csispc results
  395.     mov    #filnam ,r2        ; and save the results
  396.     mov    (r0)+    ,(r2)+        ; copy the device spec first of all
  397.     mov    @r0    ,(r2)+        ; copy the first 3 rad50 of filename
  398.     bne    40$            ; something was indeed there
  399.     mov    #star    ,-2(r2)        ; nothing, convert to wilcard
  400. 40$:    clr    (r0)+            ; and clear any filenames please
  401.     mov    @r0    ,(r2)+        ; copy the last 3 rad50 of filename
  402.     clr    (r0)+            ; and clear any filenames please
  403.     mov    @r0    ,(r2)+        ; copy the 3 rad50 of filetype
  404.     .if eq,-1            ;/58/ not longer implied wildcard here
  405.     bne    50$            ; something was passed for filetype
  406.     mov    #star    ,-2(r2)        ; nothing there, stuff a wilcard in
  407.     .endc
  408. 50$:    clr    (r0)+            ; and clear any filetypes please
  409.     clr    (r0)+            ; to be sure
  410.     .lookup #rtwork,#lun.sr,r1    ; open the file for input
  411.     bcs    100$            ; can not find it
  412.     clr    r0            ; no errors
  413.     br    120$            ; and exit
  414.  
  415. 60$:    mov    #dsterr ,r1
  416.     br    110$
  417. 80$:    mov    #csierr ,r1        ; .csispc error mapping
  418.     br    110$            ; get the correct error now
  419. 90$:    mov    #feterr ,r1        ; .fetch error codes
  420.     br    110$
  421. 100$:    mov    #lokerr ,r1        ; .lookup error mapping
  422.     br    110$
  423.  
  424. 110$:    movb    @#errbyt,r0        ; get the error code now
  425.     bpl    115$            ;/51/ Normal RT11 error
  426.     com    r0            ;/51/ Make positive
  427.     add    #faterr ,r0        ;/51/ Map to fatal error list
  428. 115$:    asl    r0            ; times 2 for indexing into error map
  429.     add    r0    ,r1        ; now map the rt11 error into a fake
  430.     mov    @r1    ,r0        ; of a rms11 error
  431.  
  432. 120$:    add    #<40.*2>+20.,sp        ; pop all the tiny buffers now.
  433.     push    r0            ;/51/ Successfull?
  434.     beq    130$            ;/51/ Yes
  435.     .PURGE    #LUN.SR            ;/51/ No, purge the channel now
  436. 130$:    .HERR                ;/51/ Restore normal error control
  437.     pop    r0            ;/51/ Pop actual error code
  438.     return                ; and get out
  439.  
  440.  
  441.     .save
  442.     .psect    rtdir
  443. defext: .word    star,star,star,star    ;/58/ default ext. are wildcards
  444.     .restore
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.     .sbttl    read the home block in please
  456.  
  457. gethom: save    <r1,r2>            ;/54/
  458.     .readw    #rtwork,#lun.sr,#dirbuf,#400,#hd$blk
  459.     bcs    90$            ; it failed, bye
  460.     mov    #dirbuf ,r2        ; point to the buffer now
  461.     mov    hd$fir(r2),hd.fir    ; get the first directory block number
  462.     bne    5$            ; /56/
  463.     mov    #6    ,hd.fir        ; /56/ Disk had no init data
  464. 5$:    add    #hd$sys ,r2        ; point to the volume ident
  465.     cmpb    devtyp    ,#DEV$LD    ;/45/ Logical disk ?
  466.     beq    30$            ;/45/ Yes, skip the check
  467.     tst    rtvol            ; really verify volume ?
  468.     beq    30$            ; no
  469.     mov    r2    ,r1        ;/54/ Check
  470.     mov    #rt    ,r0        ;/54/ ...
  471. 10$:    tstb    @r0            ;/54/ Done
  472.     beq    30$            ;/54/ Yes, exit
  473.     cmpb    (r0)+    ,(r1)+        ;/54/ Same
  474.     beq    10$            ;/54/ Yes, keep looking
  475.     mov    r2    ,r1        ;/54/ Check
  476.     mov    #vms    ,r0        ;/54/ ...
  477. 20$:    tstb    @r0            ;/54/ Done
  478.     beq    30$            ;/54/ Yes, exit
  479.     cmpb    (r0)+    ,(r1)+        ;/54/ Same
  480.     beq    20$            ;/54/ Yes, keep looking
  481.     br    80$            ;/54/ Not valid
  482. 30$:    clr    r0            ; no errors
  483.     br    100$            ; and exit
  484.  
  485. 80$:    mov    #er$vol ,r0        ; return an error code and exit
  486.     br    100$            ; bye
  487.  
  488. 90$:    movb    @#errbyt,r0        ; get the error code
  489.     asl    r0            ; times two
  490.     mov    reaerr(r0),r0        ; map it into a unique global error
  491.  
  492. 100$:    unsave    <r2,r1>            ;/54/
  493.     return                ; bye
  494.  
  495.     .save                ;/54/
  496.     .psect    $PDATA    D        ;/54/
  497. rt:    .asciz    /DECRT11/        ;/54/
  498. vms:    .asciz    /DECVMSEX/        ;/54/ From EXCHANGE under VMS4.x
  499.     .even                ;/54/
  500.     .restore            ;/54/
  501.  
  502.  
  503. gethdr: .readw    #rtwork,#lun.sr,#dirbuf,#1000,r1
  504.     bcs    90$            ; it failed, bye
  505.     mov    #dirbuf ,r0        ; point to the buffer now
  506.     mov    h$nseg(r0),h.nseg    ; get the total segment count now
  507.     asl    h$next(r0)        ; segments are two blocks in length
  508.     beq    5$            ; no more segments if zero
  509.     add    #4    ,h$next(r0)    ; and at last, the offset
  510. 5$:    mov    h$next(r0),h.next    ; get the link to the next one
  511.     tst    h.max            ; already set up ?
  512.     bne    10$            ; yes, don't touch it please
  513.     mov    h$max(r0) ,h.max    ; get the maximum segment in use
  514. 10$:    mov    h$ext(r0) ,h.ext    ; get the extra words per dir entry
  515.     mov    h$blk(r0) ,h.blk    ; and the starting block for data
  516.     mov    #7*2    ,dirsiz        ; the default entry size
  517.     add    h$ext(r0),dirsiz    ; plus extra bytes per entry
  518.     clr    r0            ; no errors
  519.     br    100$            ; and exit
  520.  
  521. 90$:    movb    @#errbyt,r0        ; get the error code
  522.     asl    r0            ; times two
  523.     mov    reaerr(r0),r0        ; map it into a unique global error
  524.  
  525. 100$:    return                ; bye
  526.  
  527.  
  528.     global    <rtvol>
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.     .sbttl    print the directory out
  540.  
  541.  
  542.  
  543. pridir: save    <r1,r2,r3>        ; save temps
  544.     call    gethom            ; read in the home block
  545.     tst    r0            ; did it work ?
  546.     bne    100$            ; no, exit with the error please
  547.     mov    hd.fir    ,r1        ; get this directory entry
  548. 10$:    tst    r1            ; end of the directory list ?
  549.     beq    90$            ; yes, return 'no more files' please
  550.     call    gethdr            ; the the first directory header
  551.     tst    r0            ; did this work out ?
  552.     bne    100$            ; no, return mapped error code please
  553.     mov    #dirbuf ,r3        ; point to the directory buffer
  554.     add    #5*2    ,r3        ; skip past the header information
  555. 20$:    bit    #endseg ,f.stat(r3)    ; end of this segment ?
  556.     bne    80$            ; yes, try the next one please
  557.     bit    #perm    ,f.stat(r3)    ; is this a real file ?
  558.     beq    70$            ; no, skip it please
  559.     call    match            ; see if the file matches up
  560.     tst    r0            ; well ?
  561.     beq    70$            ; no, try again please
  562.     mov    #junk    ,r2        ; a local buffer to use
  563.     call    convert            ; convert to asciz
  564.     mov    #junk    ,-(sp)        ; push the buffer address
  565.     call    110$            ; dump it please
  566.     deccvt    f.len(r3),#junk        ; convert size to decimal
  567.     clrb    junk+6            ; insure .asciz please
  568.     mov    #junk    ,-(sp)        ; push the buffer address
  569.     call    110$            ; and do it
  570.     mov    #210$    ,-(sp)        ; push buffer
  571.     call    110$            ; dump it
  572.     mov    f.date(r3),r0        ; a real date today?
  573.     bne    60$            ; yes
  574.     dec    r0            ; no, force 00-xxx-00
  575. 60$:    calls    cvtdat    ,<#junk,r0>,nogbl; and convert the date
  576.     mov    #junk    ,-(sp)        ; same again
  577.     call    110$            ;
  578.     mov    #200$    ,-(sp)        ;
  579.     call    110$            ;
  580.  
  581.  
  582. 70$:    add    dirsiz    ,r3        ; skip to the next entry please
  583.     br    20$            ; and check this one out please
  584. 80$:    mov    h.next    ,r1        ; end of segment, check the next one
  585.     br    10$            ; simple to do
  586.  
  587. 90$:    mov    #er$nmf ,r0
  588.  
  589. 100$:    unsave    <r3,r2,r1>        ; pop temps and exit
  590.     return
  591.  
  592.  
  593. 110$:    save    <r0,r1,r2,r3>        ; save registers
  594.     mov    12(sp)    ,r3        ; get the buffer address
  595.     tst    outlun            ; output to disk or terminal
  596.     beq    150$            ; tt:
  597.     strlen    r3            ; disk, get the buffer size
  598.     mov    r0    ,r2        ; save it please
  599.     beq    190$            ; nothing to do
  600. 120$:    movb    (r3)+    ,r0        ; get the next character
  601.     mov    outlun    ,r1        ; set the lun up also
  602.     call    putcr0            ; dump the character
  603.     sob    r2    ,120$        ; and get the next one
  604.     br    190$            ; exit
  605. 150$:    .print    r3            ; output to tt:
  606. 190$:    unsave    <r3,r2,r1,r0>        ; pop registers and exit
  607.     mov    (sp)+    ,(sp)        ; move return address up and exit
  608.     return                ; bye
  609.  
  610.  
  611. 200$:    .byte    15,12,0
  612. 210$:    .byte    40,40,40,0
  613.     .even
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.     .sbttl    get the next entry matching a possibly wildcarded name
  625.  
  626.  
  627. getnth: save    <r1,r2,r3,r4>        ; save temps
  628.     clr    r4            ; counter for number of matches
  629.     call    gethom            ; read in the home block
  630.     tst    r0            ; did it work ?
  631.     bne    100$            ; no, exit with the error please
  632.     mov    hd.fir    ,r1        ; get this directory entry
  633. 10$:    tst    r1            ; end of the directory list ?
  634.     beq    90$            ; yes, return 'no more files' please
  635.     call    gethdr            ; the the first directory header
  636.     tst    r0            ; did this work out ?
  637.     bne    100$            ; no, return mapped error code please
  638.     mov    #dirbuf ,r3        ; point to the directory buffer
  639.     add    #5*2    ,r3        ; skip past the header information
  640.  
  641. 20$:    bit    #endseg ,f.stat(r3)    ; end of this segment ?
  642.     bne    80$            ; yes, try the next one please
  643.     bit    #perm    ,f.stat(r3)    ; is this a real file ?
  644.     beq    70$            ; no, skip it please
  645.     call    match            ; see if the file matches up
  646.     tst    r0            ; well ?
  647.     beq    70$            ; no, try again please
  648.     cmp    r4    ,context    ; a match here ?
  649.     bne    50$            ; no, try again please
  650.     mov    6(r5)    ,r2        ; a buffer to convert into
  651.     call    convert            ; convert to asciz
  652.     mov    r2    ,r0        ; not get rid off ALL spaces in the name
  653. 30$:    tstb    @r0            ; end of the string yet ?
  654.     beq    40$            ; yes
  655.     cmpb    @r0    ,#40        ; if it's a space, then ignore it
  656.     beq    35$            ; skip it please
  657.     movb    @r0    ,(r2)+        ; not a space, please copy it then
  658. 35$:    inc    r0            ; point to the next character now
  659.     br    30$            ; and check the next character please
  660. 40$:    clrb    @r2            ; insure returned string is .asciz
  661.     mov    F.DATE(r3),lokdate    ;/38/ save this
  662.     mov    F.LEN(r3),loklen    ;/38/ save this
  663.     clr    r0            ; success
  664.     inc    context            ; next one next time please
  665.     br    100$            ; bye
  666. 50$:    inc    r4            ; matches := succ( matches )
  667.     br    70$            ; next try please
  668.  
  669. 70$:    add    dirsiz    ,r3        ; skip to the next entry please
  670.     br    20$            ; and check this one out please
  671. 80$:    mov    h.next    ,r1        ; end of segment, check the next one
  672.     br    10$            ; simple to do
  673.  
  674. 90$:    mov    #er$nmf ,r0
  675.  
  676. 100$:    unsave    <r4,r3,r2,r1>        ; pop temps and exit
  677.     return
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.     .sbttl    convert current directory entry to asciz
  689.  
  690. ;     input: r2    buffer for the result
  691. ;            r3    current directory entry pointer
  692.  
  693.  
  694. convert:mov    r2    ,-(sp)        ; save the passed pointer to a buffer
  695.     calls    rdtoa    ,<r2,filnam>    ; convert the device name please
  696.     cmpb    @r2    ,#40        ; a space for device name ?
  697.     bne    10$            ; no
  698.     movb    #'D&137 ,@r2        ; yes, stuff 'DK' in please
  699.     movb    #'K&137 ,1(r2)        ; simple to do
  700. 10$:    add    #2    ,r2        ; skip past it and insert a ':'
  701.     cmpb    @r2    ,#40        ; a space (no unit number?)
  702.     beq    20$            ; no
  703.     tstb    (r2)+            ; a real unit, skip over number
  704. 20$:    movb    #':    ,(r2)+        ; yes, get DD: format of device name
  705.     calls    rdtoa    ,<r2,f.nam1(r3)>; convert first 3 filename to ascii
  706.     add    #3    ,r2        ; and skip over those three characters
  707.     calls    rdtoa    ,<r2,f.nam2(r3)>; now get the rest of the filename
  708.     add    #3    ,r2        ; point to place a dot into the name
  709.     movb    #'.    ,(r2)+        ; a dot
  710.     calls    rdtoa    ,<r2,f.type(r3)>; get the filetype at last
  711.     clrb    3(r2)            ; and insure .asciz please
  712.     mov    (sp)+    ,r2        ; pop the pointer and exit
  713.     return                ; bye
  714.  
  715.     .enabl    lsb
  716.  
  717.     percent = '.            ;/58/ percent in a filspc string
  718.     wildc    = '?            ;/58/ wildcard flag
  719.  
  720. match:    save    <r1,r2>            ; we may need these here
  721.     mov    filnam+2,rtwork+0    ; copy the name and type please
  722.     mov    filnam+4,rtwork+2    ; copy the name and type please
  723.     mov    filnam+6,rtwork+4    ; copy the name and type please
  724.     mov    #name1    ,r1        ; was not a simple pattern so convert
  725.     mov    #rtwork ,r2        ; both names back to ascii and check
  726.     mov    #3    ,r0        ; for individual character wildcarding
  727. 40$:    calls    rdtoa    ,<r1,(r2)+>    ; convert the patter filename back
  728.     add    #3    ,r1        ; increment the pointer by 3 char's.
  729.     sob    r0    ,40$        ; next please
  730.                     ;
  731.     mov    #name2    ,r1        ; a buffer for the file we just found
  732.     mov    r3    ,r2        ; on the disk. Now get the address of
  733.     add    #f.nam1 ,r2        ; the name and filetype, convert this
  734.     mov    #3    ,r0        ; to ascii in a loop
  735. 50$:    calls    rdtoa    ,<r1,(r2)+>    ; convert
  736.     add    #3    ,r1        ; next please
  737.     sob    r0    ,50$        ;
  738.                     ;
  739. 60$:    mov    #name1    ,r1        ; the filename pattern
  740.     mov    #name2    ,r2        ; the current filename on disk
  741.     mov    #6.    ,r0        ; the loop count for scanning
  742.     call    200$            ;/58/ compare filename
  743.     bcs    90$            ;/58/  /B on match failure
  744.     mov    #name1+6,r1        ; the filetype pattern
  745.     mov    #name2+6,r2        ; the current filetype on disk
  746.     mov    #3.    ,r0        ; the loop count for scanning
  747.     call    200$            ;/58/ compare filetype
  748.     bcs    90$            ;/58/  /B on match failure
  749.     mov    sp    ,r0        ; flag success and exit
  750.     br    100$            ; bye
  751.                     ;
  752. 90$:    clr    r0            ; failure, exit
  753.                     ;
  754. 100$:    unsave    <r2,r1>            ; restore registers
  755.     return                ;   and exit at last
  756.                     ;
  757. 200$:    mov    r0    ,311$        ;/58/ save for later re-use
  758.     mov    r1    ,310$        ;/58/
  759. 201$:    cmpb    @r1    ,@r2        ;/58/ if they match, no problem
  760.     beq    202$            ;/58/ simply check the next character
  761.     cmpb    @r1    ,#wildc        ;/58/ a translated "* wildcard ?
  762.     beq    210$            ;/58/  yes - alternativ check
  763.     cmpb    @r1    ,#percent    ;/58/ a translated "% wildcard ?
  764.     bne    231$            ;/58/  no  - match failure ...
  765. 202$:    inc    r1            ;/58/ match so far,
  766.     inc    r2            ;/58/    update pointers
  767.     sob    r0    ,201$        ;/58/    and check the next ones
  768.     call    300$            ;/58/ are we at end of string?
  769.     bcs    230$            ;/58/  yes - success
  770.     cmpb    @r1    ,#space        ;/58/  no - see if wildcarded
  771.     beq    230$            ;/58/          if so, success
  772.     br    231$            ;/58/          else failure ...
  773.                     ;/58/
  774. 210$:    inc    r1            ;/58/ point to char. after wildc
  775.     call    300$            ;/58/ are we at end of string?
  776.     bcs    230$            ;/58/  if so, success ...
  777. 211$:    cmpb    @r1    ,#space        ;/58/  a spaces?
  778.     beq    230$            ;/58/     end of matching check
  779.     cmpb    @r1    ,#percent    ;/58/ a translated "% wildcard ?
  780.     bne    220$            ;/58/  no - compare strings
  781.     inc    r1            ;/58/ point to char. after wildc
  782.     sob    r0,211$            ;/58/  otherwise loop to find a char.
  783.     br    230$            ;/58/ all "%'s - assume success
  784.                     ;/58/
  785. 220$:    cmpb    @r1    ,@r2        ;/58/ find a matching character
  786.     bne    221$            ;/58/    not yet, see next ...
  787.     cmpb    1(r2)    ,@r2        ;/58/ next = same?
  788.     bne    202$            ;/58/    no - verify remainder
  789. 221$:    inc    r2            ;/58/    else point to next
  790.     sob    r0,220$            ;/58/         and loop until done
  791.     br    231$            ;/58/ match failure
  792.                     ;/58/
  793. 230$:    tst    (pc)+            ;/58/ bump next instr. and clr carry
  794. 231$:    sec                ;/58/ flag failure
  795.     return                ;/58/  back to caller
  796.                     ;/58/
  797. 300$:    push    r0            ;/58/ save temp
  798.     mov    r1    ,r0        ;/58/ copy searched string pointer
  799.     sub    (pc)+    ,r0        ;/58/ make match count
  800. 310$:    .word    0            ;/58/     searched string base address
  801.     cmp    (pc)+    ,r0        ;/58/ compare with char. count
  802. 311$:    .word    0            ;/58/     string width
  803.     beq    320$            ;/58/    yes - flag end string
  804.     tst    (pc)+            ;/58/    else skip next instr.
  805. 320$:    sec                ;/58/ flag end-of-string
  806.     pop    r0            ;/58/ restore reg
  807.     return
  808.  
  809.     .dsabl    lsb
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.     .sbttl    ascdat    convert to ascii date for RT11
  820.     .mcall    .date
  821.  
  822.  
  823. ;     input: @r5    output buffer address
  824. ;        2(r5)    value of date, zero implies current
  825. ;
  826. ;     I certainly could use my ASH and DIV macros, but may as
  827. ;     well do it this way for future possibilities.
  828. ;
  829. ;     N O T E :  This is a LOCAL copy of ASCDAT so I can overlay
  830. ;            the real ACSDAT oppossing this overlay.
  831.  
  832.  
  833.  
  834. cvtdat: save    <r0,r1,r2,r3>        ; save these please
  835.     mov    @r5    ,r1        ; the result address
  836.     cmp    2(r5)    ,#-1        ; if -1, then return 00-XXX-00
  837.     bne    5$            ; no
  838.     copyz    #310$    ,r1        ; yes, then exit
  839.     br    100$            ; bye
  840. 5$:    mov    2(r5)    ,r0        ; get the date desired please
  841.     bne    10$            ; it's ok
  842.     .date                ; zero, assume todays date then
  843. 10$:    bic    #100000 ,r0        ; undefined
  844.     mov    r0    ,r3        ; copy the date
  845.     asr    r3            ;/2
  846.     asr    r3            ;/2 again
  847.     asr    r3            ; ditto
  848.     asr    r3            ; sigh
  849.     asr    r3            ; at last
  850.     bic    #^C37    ,r3        ; the date, at last
  851.     call    200$            ; convert it
  852.     mov    r0    ,r3        ; get the date once again please
  853.     swab    r3            ; get the month to bits 2..7
  854.     asr    r3            ;/2
  855.     asr    r3            ;/2 again
  856.     bic    #^C17    ,r3        ; get rid of the unwanted bits now
  857.     dec    r3            ; convert to 0..11
  858.     asl    r3            ; convert to word offset
  859.     asl    r3            ; quad offset
  860.     add    #300$    ,r3        ; the address of the text
  861.     movb    #'-    ,(r1)+        ; copy it over please
  862.     movb    (r3)+    ,(r1)+        ; three characters please
  863.     movb    (r3)+    ,(r1)+        ; three characters please
  864.     movb    (r3)+    ,(r1)+        ; three characters please
  865.     movb    #'-    ,(r1)+        ; copy it over please
  866.     mov    r0    ,r3        ; copy the date
  867.     bic    #^C37    ,r3        ; the year, at last
  868.     add    #110    ,r3        ; plus the bias please
  869.     call    200$            ; convert
  870.     clrb    @r1            ; .asciz and exit
  871. 100$:    unsave    <r3,r2,r1,r0>
  872.     return
  873.  
  874. 200$:    clr    r2            ; subtract 10 a few times
  875. 210$:    inc    r2            ; high digit number
  876.     sub    #12    ,r3        ; until we get a negative number
  877.     tst    r3            ; done yet ?
  878.     bge    210$            ; no
  879.     dec    r2            ; yes
  880.     add    #12    ,r3        ; correct it please
  881.     add    #'0    ,r2        ; and copy the day number please
  882.     add    #'0    ,r3        ; simple
  883.     movb    r2    ,(r1)+        ; copy it
  884.     movb    r3    ,(r1)+        ; copy it
  885.     return
  886.  
  887.     .nlist    bex
  888. 300$:    .ascii    /Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec /
  889. 310$:    .asciz    /00-XXX-00/
  890.     .list    bex
  891.     .even
  892.  
  893.  
  894.  
  895.     .end
  896.