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

  1.     .title    K11RTU    copy,rename and delete for RT11, no wildcarding
  2.     .ident    /2.20/
  3.  
  4. ;    Copyright (C) 1984 Change Software, Inc.
  5. ;
  6. ;    18-Jul-84  16:14:46 Brian Nelson
  7. ;
  8. ;    If wildcarding is added, this MUST be moved from
  9. ;    the overlay it's in into the root.
  10.  
  11.  
  12.     .mcall    .csispc    ,.delete,.dstat    ,.fetch    ,.rename
  13.  
  14.  
  15.     .if ndf, K11INC
  16.     .ift
  17.     .include    /IN:K11MAC.MAC/
  18.     .endc
  19.  
  20.     .enabl    gbl
  21.     .psect    $code
  22.     .save
  23.     .psect    rendat    ,rw,d,lcl,rel,con
  24.  
  25. defext:    .word    0,0,0,0,0
  26. renlst:    .blkw    12
  27. rtdsta:    .blkw    5
  28.     .restore
  29.  
  30.  
  31.  
  32.     topmem    =    50
  33.     errbyt    =    52
  34.     star    =    132500
  35.  
  36.  
  37.  
  38.     .sbttl    the real work of rename
  39.  
  40.  
  41. ;    input:    @r5    first filename, .asciz
  42. ;        2(r5)    second filename, .asciz
  43. ;        4(r5)    if ge 0, print a log of files renamed
  44.  
  45. rename::save    <r2,r3,r4>        ; save these please
  46.     clr    r4            ; no files renamed as of yet
  47.     mov    #renlst    ,r3        ; where to build the .rename list
  48.     mov    @r5    ,r0        ; string address
  49.     call    docsi            ; do the first one
  50.     bcs    100$            ; oops
  51.     mov    2(r5)    ,r0        ; now do the second filename
  52.     call    docsi            ; ok
  53.     bcs    100$            ; oops
  54.     mov    #renlst    ,r1        ; check for wildcarding
  55.     mov    @r1    ,10(r1)        ; first, force same device name
  56.     mov    #4*2    ,r2        ; eight words to check for wildcards
  57. 10$:    cmp    (r1)+    ,#star        ; a wildcard today ?
  58.     beq    80$            ; yes, die
  59.     sob    r2    ,10$        ; no, check the next one please
  60.     mov    renlst    ,r0        ; get the device name
  61.     call    devload            ; get device loaded if need be
  62.     bcs    100$            ; it did not work
  63.     .rename    #rtwork,#lun.in,#renlst    ; do the rename please
  64.     bcs    90$            ; oops
  65.     call    200$            ; log it please
  66.     mov    #1    ,r4        ; one file renamed
  67.     clr    r0            ; no errors
  68.     br    100$            ; and exit
  69.  
  70. 80$:    mov    #er$wld    ,r0        ; no wildcarding today
  71.     br    100$            ; exit
  72.  
  73. 90$:    movb    @#errbyt,r0        ; map the .rename error
  74.     asl    r0            ; times 2 as always
  75.     mov    renerr(r0),r0        ; simple
  76.  
  77. 100$:    mov    r4    ,r1        ; return rename count
  78.     beq    120$            ; never got any files, exit
  79.     cmp    r0    ,#er$nmf    ; no more files error?
  80.     beq    110$            ; yes, say no errors
  81.     cmp    r0    ,#er$fnf    ; same goes for file not found
  82.     bne    120$            ; exit
  83. 110$:    clr    r0            ; no errors
  84. 120$:    unsave    <r4,r3,r2>        ; pop these and exit
  85.     return
  86.  
  87.  
  88.  
  89.     .sbttl    log for the rt11 rename command
  90.  
  91. 200$:    tst    4(r5)            ; print a log of this out
  92.     bmi    210$            ; nothing to do
  93.     print    @r5            ; no wildcarding simplifies things
  94.     print    #290$            ; more
  95.     print    2(r5)            ; next
  96.     print    #295$            ;
  97. 210$:    return
  98.  
  99.  
  100. 290$:    .asciz    / renamed to /
  101. 295$:    .byte    cr,lf,0
  102.     .even
  103.     
  104.  
  105.     .sbttl    the real work of delete
  106.  
  107.  
  108. ;    input:    @r5    first filename, .asciz
  109. ;        2(r5)    second filename, .asciz
  110. ;        4(r5)    if ge 0, print a log of files renamed
  111.  
  112. delete::save    <r2,r3,r4>        ; save these please
  113.     clr    r4            ; no files renamed as of yet
  114.     mov    #renlst    ,r3        ; where to build the .rename list
  115.     mov    @r5    ,r0        ; string address
  116.     call    docsi            ; do the first one
  117.     bcs    100$            ; oops
  118.     mov    #renlst    ,r1        ; check for wildcarding
  119.     mov    #4    ,r2        ; four words to check for wildcards
  120. 10$:    cmp    (r1)+    ,#star        ; a wildcard today ?
  121.     beq    80$            ; yes, die
  122.     sob    r2    ,10$        ; no, check the next one please
  123.     mov    renlst    ,r0        ; get the device name
  124.     call    devload            ; get device loaded if need be
  125.     bcs    100$            ; it did not work
  126.     .delete    #rtwork,#lun.in,#renlst    ; do the delete please
  127.     bcs    90$            ; oops
  128.     call    200$            ; log it please
  129.     mov    #1    ,r4        ; one file renamed
  130.     clr    r0            ; no errors
  131.     br    100$            ; and exit
  132.  
  133. 80$:    mov    #er$wld    ,r0        ; no wildcarding today
  134.     br    100$            ; exit
  135.  
  136. 90$:    movb    @#errbyt,r0        ; map the .rename error
  137.     asl    r0            ; times 2 as always
  138.     mov    renerr(r0),r0        ; simple
  139.  
  140. 100$:    mov    r4    ,r1        ; return rename count
  141.     beq    120$            ; never got any files, exit
  142.     cmp    r0    ,#er$nmf    ; no more files error?
  143.     beq    110$            ; yes, say no errors
  144.     cmp    r0    ,#er$fnf    ; same goes for file not found
  145.     bne    120$            ; exit
  146. 110$:    clr    r0            ; no errors
  147. 120$:    unsave    <r4,r3,r2>        ; pop these and exit
  148.     return
  149.  
  150.  
  151. 200$:    tst    2(r5)            ; print a log of this out
  152.     bmi    210$            ; nothing to do
  153.     print    @r5            ; no wildcarding simplifies things
  154.     print    #290$            ; more
  155. 210$:    return
  156.  
  157.  
  158. 290$:    .asciz    / deleted/<cr><lf>
  159.     .even
  160.  
  161.  
  162.  
  163.  
  164.     .sbttl    parse device and filename
  165.  
  166.  
  167. ;    parse the filename(s)
  168. ;
  169. ;    input:    r0    address of filename
  170. ;        r3    pointer to result of parse
  171.  
  172. docsi:    save    <r1,r2>
  173.     sub    #40.*2    ,sp        ; allocate a local filename buffer
  174.     mov    sp    ,r1        ; and a pointer to it please
  175.     mov    r0    ,r2        ; check for a ':' in the string
  176.     scan    #':    ,r2        ; if there is no colon then insert
  177.     tst    r0            ; the defdir please
  178.     bne    310$            ; we found a colon in the string
  179.     mov    #defdir    ,r0        ; no device was in the string so put
  180. 305$:    movb    (r0)+    ,(r1)+        ; in
  181.     bne    305$            ; next please
  182.     dec    r1            ; backup to the null we just copied
  183.     
  184. 310$:    movb    (r2)+    ,(r1)+        ; copy it to the csi buffer
  185.     bne    310$            ; until a null byte is found.
  186.     movb    #'=    ,-1(r1)        ; fake an output filespec here
  187.     clrb    @r1            ; and .asciz
  188.     mov    sp    ,r1        ; reset pointer (also saving sp)
  189.     .csispc    r1,#defext,r1        ; and try to parse the name
  190.     mov    r1    ,sp        ; restore from any switches
  191.     bcs    320$            ; it's ok
  192.     mov    (r1)+    ,(r3)+        ; copy the device and filename
  193.     mov    (r1)+    ,(r3)+        ; copy the device and filename
  194.     mov    (r1)+    ,(r3)+        ; copy the device and filename
  195.     mov    (r1)+    ,(r3)+        ; copy the device and filename
  196.     add    #40.*2    ,sp        ; restore the stack
  197.     clc                ; no errors
  198.     br    330$
  199.  
  200. 320$:    movb    @#errbyt,r0        ; get the error mapping for .csispc
  201.     asl    r0            ; index to word offsets
  202.     mov    csierr(r0),r0        ; simple
  203.     add    #40.*2    ,sp        ; restore the stack
  204.     sec                ; flag the error and exit
  205. 330$:    unsave    <r2,r1>
  206.     return
  207.  
  208.  
  209.  
  210.     .sbttl    get device driver loaded if need be
  211.  
  212. ;    DEVLOAD
  213. ;
  214. ;    input:    r0    device name
  215. ;    output:    r0    error code if carry is set
  216.  
  217.  
  218. devload:calls    fetch    ,<r0>
  219.     tst    r0            ; did it work ?
  220.     bne    90$            ; no
  221.     clc                ; yes
  222.     return
  223. 90$:    sec                ; no
  224.     return                ; exit
  225.  
  226.  
  227.  
  228.     .sbttl    copy command
  229.  
  230. copy::    save    <r2,r3>            ; save temp registers please
  231.     clr    r2            ; number of blocks = 0
  232.     mov    #1000    ,r3        ;
  233.     calls    open    ,<@r5,#lun.in,#binary> ; get the input file
  234.     tst    r0            ; did it work?
  235.     bne    110$            ; no, simple exit then
  236.     calls    create    ,<2(r5),#lun.out,#binary> ; create the destination
  237.     tst    r0            ; did it work ?
  238.     bne    100$            ; no, close the input file now
  239.  
  240. 10$:    calls    getc    ,<#lun.in>    ; get the next ch from the file
  241.     tst    r0            ; did it work ?
  242.     bne    20$            ; no, check for eof condition
  243.     calls    putc    ,<r1,#lun.ou>    ; yes, copy to output file
  244.     tst    r0            ; did that work ?
  245.     bne    20$            ; no
  246.     sob    r3    ,10$        ; next ch please
  247.     inc    r2            ; blocks := succ( blocks )
  248.     mov    #1000    ,r3        ; copy the next block now
  249.     br    10$            ; back for more now please
  250.  
  251. 20$:    cmp    r0    ,#er$eof    ; normal exit should be eof
  252.     bne    30$            ; it's not
  253.     clr    r0            ; clear error codes
  254. 30$:    save    <r0>            ; save error code
  255.     calls    close    ,<#lun.in>    ; close input file
  256.     calls    close    ,<#lun.ou>    ; close output file
  257.     unsave    <r0>            ; restore error code and exit
  258.     br    120$            ; and exit
  259.  
  260. 100$:    calls    close    ,<#lun.in>    ; close input if output create failed
  261. 110$:                    ;
  262. 120$:    mov    r2    ,r1        ; return number of blocks and exit
  263.     unsave    <r3,r2>
  264.     return
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.     .sbttl    ascdat    convert to ascii date for RT11
  272.     .mcall    .date
  273.  
  274.  
  275. ;    input:    @r5    output buffer address
  276. ;        2(r5)    value of date, zero implies current
  277. ;
  278. ;    I certainly could use my ASH and DIV macros, but may as
  279. ;    well do it this way for future possibilities.
  280.  
  281.  
  282.  
  283. ascdat::save    <r0,r1,r2,r3>        ; save these please
  284.     mov    @r5    ,r1        ; the result address
  285.     cmp    2(r5)    ,#-1        ; if -1, then return 00-XXX-00
  286.     bne    5$            ; no
  287.     copyz    #310$    ,r1        ; yes, then exit
  288.     br    100$            ; bye
  289. 5$:    mov    2(r5)    ,r0        ; get the date desired please
  290.     bne    10$            ; it's ok
  291.     .date                ; zero, assume todays date then
  292. 10$:    bic    #100000    ,r0        ; undefined
  293.     mov    r0    ,r3        ; copy the date
  294.     asr    r3            ; /2
  295.     asr    r3            ; /2 again
  296.     asr    r3            ; ditto
  297.     asr    r3            ; sigh
  298.     asr    r3            ; at last
  299.     bic    #^C37    ,r3        ; the date, at last
  300.     call    200$            ; convert it
  301.     mov    r0    ,r3        ; get the date once again please
  302.     swab    r3            ; get the month to bits 2..7
  303.     asr    r3            ; /2
  304.     asr    r3            ; /2 again
  305.     bic    #^C17    ,r3        ; get rid of the unwanted bits now
  306.     dec    r3            ; convert to 0..11
  307.     asl    r3            ; convert to word offset
  308.     asl    r3            ; quad offset
  309.     add    #300$    ,r3        ; the address of the text
  310.     movb    #'-    ,(r1)+        ; copy it over please
  311.     movb    (r3)+    ,(r1)+        ; three characters please
  312.     movb    (r3)+    ,(r1)+        ; three characters please
  313.     movb    (r3)+    ,(r1)+        ; three characters please
  314.     movb    #'-    ,(r1)+        ; copy it over please
  315.     mov    r0    ,r3        ; copy the date
  316.     bic    #^C37    ,r3        ; the year, at last
  317.     add    #110    ,r3        ; plus the bias please
  318.     call    200$            ; convert
  319.     clrb    @r1            ; .asciz and exit
  320. 100$:    unsave    <r3,r2,r1,r0>
  321.     return
  322.  
  323. 200$:    clr    r2            ; subtract 10 a few times
  324. 210$:    inc    r2            ; high digit number
  325.     sub    #12    ,r3        ; until we get a negative number
  326.     tst    r3            ; done yet ?
  327.     bge    210$            ; no
  328.     dec    r2            ; yes
  329.     add    #12    ,r3        ; correct it please
  330.     add    #'0    ,r2        ; and copy the day number please
  331.     add    #'0    ,r3        ; simple
  332.     movb    r2    ,(r1)+        ; copy it
  333.     movb    r3    ,(r1)+        ; copy it
  334.     return
  335.  
  336. 300$:    .ascii    /Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec /
  337. 310$:    .asciz    /00-XXX-00/
  338.     .even
  339.  
  340.  
  341.  
  342.     .sbttl    get the ascii time 
  343.     .mcall    .gtim
  344.  
  345. ;    input:    @r5    buffer address for .asciz string
  346.  
  347.  
  348. asctim::save    <r0,r1,r2,r3>        ; save all registers that we use
  349.     cmp    -(sp)    ,-(sp)        ; allocate two word buffer
  350.     mov    sp    ,r3        ; and point to the small buffer
  351.     .gtim    #rtwork    ,r3        ; and get the time, ticks past midnite
  352.     mov    (r3)+    ,r1        ; get set to divide to get seconds
  353.     mov    (r3)+    ,r2        ; setup for $ddiv
  354.     mov    #60.*60.,r0        ; at last
  355.     call    ddiv            ; double precision divide
  356.     mov    r0    ,-(sp)        ; save ticks since last minute
  357.     mov    #60.    ,r0        ; and get hours in r2, minutes in r0
  358.     call    ddiv            ; simple to do
  359.     mov    @r5    ,r1        ; buffer address please
  360.     mov    r2    ,r3        ; convert hours to ascii
  361.     call    200$            ; simple
  362.     movb    #':    ,(r1)+        ; a delimiter
  363.     mov    r0    ,r3        ; the minutes next please
  364.     call    200$            ; simple
  365.     movb    #':    ,(r1)+        ; and a delimiter please
  366.     mov    (sp)+    ,r2        ; now get the seconds extracted please
  367.     mov    r1    ,-(sp)        ; save buffer pointer please
  368.     clr    r1            ; may as well use $ddiv
  369.     mov    #60.    ,r0        ; simple
  370.     call    ddiv            ; simple to do
  371.     mov    (sp)+    ,r1        ; restore buffer pointer
  372.     mov    r2    ,r3        ; and convert to ascii
  373.     call    200$            ; do it
  374.     clrb    @r1            ; all done, make it .asciz and exit
  375.     cmp    (sp)+    ,(sp)+        ; pop the two word buffer
  376.     unsave    <r3,r2,r1,r0>        ; pop registers we used and exit
  377.     return
  378.  
  379.  
  380. 200$:    clr    r2            ; subtract 10 a few times
  381. 210$:    inc    r2            ; high digit number
  382.     sub    #12    ,r3        ; until we get a negative number
  383.     tst    r3            ; done yet ?
  384.     bge    210$            ; no
  385.     dec    r2            ; yes
  386.     add    #12    ,r3        ; correct it please
  387.     add    #'0    ,r2        ; and copy the day number please
  388.     add    #'0    ,r3        ; simple
  389.     movb    r2    ,(r1)+        ; copy it
  390.     movb    r3    ,(r1)+        ; copy it
  391.     return
  392.  
  393.  
  394.  
  395.  
  396.  
  397.     .sbttl    double precision divide
  398.  
  399. ;    Double precision divide (from RSX syslib)
  400. ;
  401. ;    input:    r2    =    low  order of dividend
  402. ;        r1    =    high order of dividend
  403. ;        r0    =    divisor
  404. ;
  405. ;    output:    r2    =    low  order of quotient
  406. ;        r1    =    high order of quotient
  407. ;        r0    =    remainder
  408.  
  409.  
  410. ddiv:    mov    r3,-(sp)        ; save r3
  411.     mov    #40,r3            ; set iteration count in r3
  412.     mov    r0,-(sp)        ; put divisor on the stack
  413.     clr    r0            ; set the remainder to zero
  414. 10$:    asl    r2            ; shift the entire divedend
  415.     rol    r1            ; ...
  416.     rol    r0            ; ... to left and into remainder
  417.     cmp    r0,(sp)            ; is remainder greater than divisor
  418.     blo    20$            ; no, skip to iteration control
  419.     sub    (sp),r0            ; yes, subtract divisor out please
  420.     inc    r2            ; increment the quotient
  421. 20$:    dec    r3            ; repeat please
  422.     bgt    10$            ; not done
  423.     tst    (sp)+            ; pop divisor
  424.     mov    (sp)+,r3        ; restore r3 and exit
  425.     return                ; bye
  426.  
  427.  
  428.  
  429.  
  430.     .sbttl    read a record from a sequential file
  431.  
  432.  
  433. ;    G E T R E C
  434. ;
  435. ;    getrec( %loc buffer, %val channel_number )
  436. ;
  437. ;    input:    @r5    address of user buffer, at least 80 bytes
  438. ;        2(r5)    channel number
  439. ;
  440. ;    output:    r0    rms sts
  441. ;        r1    record size
  442. ;
  443. ;    Read the next record from a disk file.  Assumes that the
  444. ;    user  has supplied a buffer of 132 characters to  return
  445. ;    the record to.
  446. ;
  447. ;    We really don't need GETREC for RT11 Kermit. It was used
  448. ;    in the RMS11 version (for RSXM/M+ and RSTS) only in con-
  449. ;    junction with GETC to fake RMS single character i/o. The
  450. ;    only  two places it  is called from is for  the TYPE and
  451. ;    HELP commands (C$TYPE and C$HELP).
  452. ;    GETREC assumes text (stream ascii) file only.
  453.  
  454.  
  455.     .iif ndf, FF , FF = 14
  456.     .iif ndf, CR , CR = 15
  457.     .iif ndf, LF , LF = 12
  458.  
  459. getrec::save    <r2,r3,r4>        ; save registers we may need
  460.     clr    r4            ; recordsize := 0
  461.     mov    @r5    ,r3        ; the recordbuffer address
  462.     mov    #132.    ,r2        ; max size of a record to read
  463.     clr    r1            ; nothing read as of yet
  464.  
  465. 10$:    cmpb    r1    ,#ff        ; exit if ch = form_feed
  466.     beq    30$            ;
  467.     mov    2(r5)    ,r0        ; the channel number to use
  468.     call    getcr0            ; read the next character now
  469.     tst    r0            ; did it work ?
  470.     bne    100$            ; no
  471.     cmpb    r1    ,#cr        ; exit if ch = carriage_return
  472.     beq    30$            ;
  473.     cmpb    r1    ,#'z&37        ; exit if ch = control_z
  474.     beq    30$            ;
  475.     cmpb    r1    ,#lf        ; ignore line feeds
  476.     beq    10$            ;
  477.     inc    r4            ; length := succ(length)
  478.     movb    r1    ,(r3)+        ; yes, stuff the character in
  479.     sob    r2    ,10$        ; up until maxrec size
  480.     mov    #er$rtb    ,r0        ; too much data, return maxsize
  481.     br    100$            ; error
  482.  
  483.  
  484. 30$:    cmpb    r1    ,#'z&37        ; we get here on reading a record
  485.     bne    40$            ; terminator
  486.     mov    #er$eof    ,r0        ; control z means end of file
  487.     clr    r1            ; no data is there at all
  488.     br    100$
  489. 40$:    mov    r4    ,r1        ; return the record length
  490.     br    100$            ; all done if ff or lf    
  491.  
  492. 100$:    unsave    <r4,r3,r2>        ; pop registers we saved
  493.     return                ; bye
  494.  
  495.     .end
  496.