home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / 22rsx / rxmd.ark.2 / RXMD04.MAC < prev    next >
Encoding:
Text File  |  1985-12-07  |  8.5 KB  |  362 lines

  1. ;
  2. ;
  3. ; ============================================
  4. ;
  5. ;        BATCH MODE ROUTINES
  6. ;
  7. ; ============================================
  8. ;
  9. ;
  10. ; If in batch receive, gets a file name from the buffer
  11. ; and then asks for a description.
  12. ;
  13. bchd1:    lhld    nbsave;        Get address of next batch filename
  14.     lxi    d,fcb;        Where to put it
  15.     call    move12
  16.     shld    nbsave;        Store address for next filename
  17.     ret
  18. ;
  19. ; If receiving batch, increment the file count, store the filename
  20. ; so we can later ask for a description.
  21. ;
  22. bchinr:    lhld    nbsave;        Where to put the name
  23.     lxi    d,fcb;        Where to get the name
  24.     xchg
  25.     call    move12;        Move the current file name into buffer
  26.     xchg
  27.     shld    nbsave;        Store address for next filename
  28.     lda    filcnt;        Increment the file count
  29.     inr    a
  30.     sta    filcnt
  31.     ret
  32. ;
  33. ; Show batch files remaining after this one is sent
  34. ;
  35. cumsts:    call    ilprt
  36.  db    'When done: ',0
  37.     lda    shocnt;        Get cumulative files
  38.     dcr    a
  39.     sta    shocnt;        Less one
  40.     call    decouta
  41.     call    ilprt
  42.  db    ' left with ',0
  43.     lhld    rcnt;        Get this file's record count again
  44.     xchg
  45.     lhld    totrec;        Total records remaining
  46.     mov    a,l
  47.     sub    e
  48.     mov    l,a
  49.     mov    a,h
  50.     sbb    d
  51.     mov    h,a
  52.     jnc    cmst1
  53.     lxi    h,0;        In case of a slightly negative number
  54. cmst1:    shld    totrec
  55.     push    h
  56.     call    decout;        Show remote remaining records
  57.     call    ilprt
  58.  db    ' records (',0
  59.     pop    h
  60.     call    decoutk
  61.     call    ilprt
  62.  db    'k)',cr,lf,0
  63.     ret
  64. ;
  65. ; ------------------------------------------------
  66. ;
  67. ;         RXMD receive batch mode
  68. ;
  69. rcvfn:    lxi    h,fcb
  70.     call    initfcb;    Does not initialize drive
  71.     mvi    a,1;        Insure printing only to local CRT
  72.     sta    remoff
  73.     xra    a
  74.     sta    rcvtry
  75. rkmd1:    call    ckabort;    Check for user abort
  76.     mvi    b,3;        Wait up to 3 sec. for SOH from remote
  77.     call    recv
  78.     jc    rkmd2;        No char, decrement counter
  79.     cpi    cancel;        Was it a CTL-X for cancel?
  80.     jz    abortx;        Abort if yes
  81.     cpi    soh
  82.     jz    rkmd4;        Got SOH
  83.     jmp    rkmd1;        None of these, wait some more
  84. ;
  85. rkmd2:    mvi    a,crc;        Send a 'C'
  86.     call    send
  87. rkmd3:    lda    rcvtry
  88.     inr    a
  89.     sta    rcvtry
  90.     cpi    33
  91.     jc    rkmd1
  92.     jmp    abort;        Quit and try to force him to quit also
  93. ;
  94. rkmd4:    mvi    b,5;        5 seconds to get sector number
  95.     call    recv
  96.     jc    kmdtot
  97.     mov    d,a;        Save sector number in D
  98.     ora    a;        Must be a 0 if sending batch
  99.     jnz    kmdhdr
  100.     mvi    b,5;        5 seconds to get reciprocal
  101.     call    recv
  102.     jc    kmdtot
  103.     cma;            Invert it and compare to sector #
  104.     cmp    d
  105.     jnz    kmdcrc;        Bad match
  106.     lxi    h,0
  107.     shld    crcval;        Clear CRC counter
  108.     mvi    e,128;        Expecting a 128 byte block
  109.     lhld    recptr;        Point to the buffer address
  110. rkmd5:    mvi    b,5;        5 seconds to get 128 byte header block
  111.     call    recv;        Get the byte
  112.     jc    kmdtot;        Exit if no byte
  113.     mov    m,a;        Store the byte
  114.     inx    h;        Point to next buffer location
  115.     dcr    e;        One less to go
  116.     jnz    rkmd5
  117.     mvi    e,2;        Number of CRC bytes to get
  118. rkmd6:    mvi    b,5
  119.     call    recv;        Get CRC bytes
  120.     jc    kmdtot
  121.     dcr    e
  122.     jnz    rkmd6;        Not done
  123.     call    crcchk;        Compare CRC received against ours
  124.     ora    a
  125.     jnz    kmdcrc;        Not ok
  126.     call    sndack;        Yes, acknowledge to remote
  127. ;    "    "
  128. ; Decode pathname into CPM format
  129. ;
  130.     lxi    d,fcb+1;    Where to put it
  131.     lhld    recptr;        Where to get it
  132.     mvi    b,8;        Filename length
  133. rkmd7:    mov    a,m;        Get the char from the buffer
  134.     ora    a;        Was it a zero?
  135.     jz    rkmd12;        If yes, all done
  136.     cpi    '.';        Was it a delimiter?
  137.     jz    rkmd9
  138.     cpi    '_';        Unix can't handle this properly
  139.     jnz    rkmd8
  140.     mvi    a,'/';        Change it to a slash
  141. rkmd8:    call    ucase;        Insure name is in upper case
  142.     stax    d;        Store filename char in FCB
  143.     inx    d;        Increment pointers
  144.     inx    h
  145.     dcr    b;        One less to go
  146.     jnz    rkmd7;        If not 8, keep going
  147.     mov    a,m;        Get the char back
  148.     ora    a;        We had 8, was there a type?
  149.     jz    rkmd11;        If zero, was all done
  150.     jmp    rkmd10;        Else must be a '.'
  151. ;
  152. rkmd9:    mvi    a,' ';        Spaces to make up 8 spaces for name
  153.     stax    d;        Store space char in FCB
  154.     inx    d;        Increment pointers
  155.     dcr    b;        One less to go
  156.     jnz    rkmd9;        Keep going until in type field
  157. rkmd10:    inx    h;        Skip the '.' position
  158.     mvi    b,3;        type field length
  159. rkmd11:    mov    a,m;        Get char from buffer
  160.     ora    a;        Was it a zero?
  161.     jz    rkmd12;        If yes, all done
  162.     call    ucase;        Insure type is in upper case
  163.     stax    d;        Store type char
  164.     inx    d;        Increment pointers
  165.     inx    h
  166.     dcr    b;        One less to go
  167.     jnz    rkmd11;        Keep going until finished
  168. rkmd12:    lda    fcb+1;        See if there was any filename at all
  169.     cpi    ' '
  170.     stc;            If not set the carry flag
  171.     rz;            No, all done, no more files
  172.     call    ilprt
  173.  db    cr,lf,'File name: ',0
  174.     lhld    recptr;        Print filename
  175. rkmd13:    mov    a,m
  176.     ora    a
  177.     jz    rkmd14
  178.     call    ucase
  179.     call    ctype
  180.     inx    h
  181.     jmp    rkmd13
  182. ;
  183. rkmd14:    lhld    bufstr;        Get the file length, if provided
  184.     mov    a,h
  185.     ora    l
  186.     jz    rkmd15;        If both zero, length not provided
  187.     shld    rcnt;        Store the file length
  188.     call    fisopen
  189.     call    ilprt
  190.  db    'k)',cr,lf,'Recv time: ',0
  191.     call    ktim
  192.     call    showtime
  193. rkmd15:    call    crlf;        Finish the filename line
  194.     xra    a;        Reset carry
  195.     sta    rcvtry;        and the error counter
  196.     ret
  197. ;
  198. kmdcrc:    call    ilprt
  199.  db    '++ CRC error ++',cr,lf,0
  200.     jmp    kmdxfr
  201. ;
  202. kmdhdr:    call    ilprt
  203.  db    '++ Wrong header type ++',cr,lf,0
  204.     jmp    kmdxfr
  205. ;
  206. kmdtot:    call    ilprt
  207.  db    ' ++ Time out receiving filename ++',cr,lf,0
  208. ;    "    "
  209. kmdxfr:    call    wait1;        For sender to stop
  210.     mvi    a,nak;        Tell sender it was not successful
  211.     call    send
  212.     lda    rcvtry;        Increment error counter
  213.     inr    a
  214.     sta    rcvtry
  215.     cpi    33
  216.     jc    rkmd3;        Send a NAK and tell him to try again
  217.     jmp    abort;        Else abort
  218. ;
  219. ;
  220. ;          end of RXMD/KMD get batch file name
  221. ; -------------------------------------------------------------------
  222. ;               RXMD/KMD send batch mode
  223. ;
  224. sndfn:    lxi    h,fcb
  225.     call    initfcb;    Does not initialize drive
  226.     xra    a
  227.     sta    errct;        Reset the error count
  228.     call    catch;        Clear the decks for action
  229.     mvi    e,61;        Wait up to 60 seconds to abort
  230. sndfn1:    dcr    e;        One less to go
  231.     jz    ackmsg;        Abort if timed out and no char
  232. sndfn2:    call    ckabort;    Manually requesting an abort?
  233.     mvi    b,1;        Wait up to 1 sec for a char
  234.     call    recv
  235.     jc    sndfn1;        No char, decrement counter
  236.     cpi    cancel;        If they sent a CTL-X, abort now
  237.     jz    abort
  238.     cpi    crc;        If they sent a CRC, go to work
  239.     jnz    sndfn2;        None of these, wait some more
  240.     mvi    a,1
  241.     sta    crcflg;        Make sure in CRC mode
  242.     lda    filcnt;        Get the file count
  243.     dcr    a;        Decrement it for this one
  244.     sta    filcnt
  245.     jm    kmdend;        If no more files, abort
  246.     call    bchd1;        Get the name into FCB
  247.     lhld    recptr;        Where to load the 0 block
  248.     xchg;            Put into DE
  249.     lxi    h,fcb+1;    Get the start of the filename in HL
  250.     mvi    b,8
  251. skmd1:    mov    a,m
  252.     ani    7fh;        Strip any high bit set
  253.     ora    a
  254.     jz    skmd6;        Null pathname
  255.     cpi    ' '
  256.     jz    skmd3
  257.     cpi    '/';        Change / to underline
  258.     jnz    skmd2
  259.     mvi    a,'_'
  260. skmd2:    call    lcase;        lower case file name for UNIX
  261.     stax    d
  262.     inx    h
  263.     inx    d
  264.     dcr    b
  265.     jnz    skmd1
  266.     jmp    skmd4
  267. skmd3:    inx    h;        Skip over spaces if short name
  268.     dcr    b
  269.     jnz    skmd3
  270. skmd4:    mov    a,m
  271.     cpi    ' '
  272.     jz    skmd6;        Missing file type field
  273.     mvi    a,'.';        Send name-type separator
  274.     stax    d
  275.     inx    d
  276.     mvi    b,3
  277. skmd5:    mov    a,m
  278.     ani    7fh;        Strip any high bit set
  279.     cpi    ' '
  280.     jz    skmd6
  281.     call    lcase;        lower case for UNIX
  282.     stax    d
  283.     inx    h
  284.     inx    d
  285.     dcr    b
  286.     jnz    skmd5
  287. skmd6:    xchg;            Get the address back to HL
  288. skmd7:    mvi    m,0;        Fill rest of block with zeroes
  289.     inr    l
  290.     jnz    skmd7
  291.     call    cnrec;        Get num records in this file
  292.     lhld    rcnt
  293.     shld    bufstr;        Store the file length at end of block
  294.     xra    a;        Make sure the header starts with Zero
  295.     sta    rcdcnt
  296. ;    "    "
  297. ; Now send the 128-byte file name record
  298. skmd8:    xra    a
  299.     sta    kflg
  300.     mvi    a,soh;        Send SOH
  301.     call    send
  302.     call    sndhnm;        Send header (record number, inverse)
  303.     call    sndrec;        Send a 128 byte record
  304.     call    sndcrc;        Send a two byte CRC
  305.     mvi    b,5
  306.     call    recv;        Get acknowledgement of good send
  307.     cpi    ack
  308.     jnz    kmdbad;        Bad name send
  309.     mvi    a,1
  310.     sta    kflg;        Now change to 1k for normal file xfer
  311.     xra    a;        Clear carry
  312.     sta    errct;        Start fresh for the main file
  313.     ret
  314. ;
  315. ;
  316. kmdbad:    cpi    cancel;        Was it a CTL-X for cancel?
  317.     jz    abort;        Abort if yes
  318.     call    ilprt;        Bad name block
  319.  db    '++ CRC error ++',cr,lf,0
  320.     lda    errct;        Increment error counter
  321.     inr    a
  322.     sta    errct
  323.     cpi    10
  324.     jc    skmd8;        If not timed out, try again
  325.     jmp    ackmsg;        Else abort
  326. ;
  327. ;
  328. kmdend:    xra    a;        Reset the pointers
  329.     lhld    recptr
  330.     mov    m,a
  331.     sta    rcdcnt;        Reset record counter
  332.     sta    kflg;        Show in 128 size now
  333.     mvi    a,soh;        Send a start of header
  334.     call    send
  335.     call    sndhnm;        This header is a zero count
  336.     call    sndrec;        Send an empty record
  337.     call    sndcrc;        Send the CRC for the empty record
  338.     stc;            Set carry flag to show all done
  339.     ret
  340. ;
  341. ;        end of send RXMD/KMD batch name
  342. ; --------------------------------------------------
  343. ;
  344. ; Downshift (a)
  345. ; a,f
  346. lcase:    cpi    'A'
  347.     rc
  348.     cpi    'Z'+1
  349.     rnc
  350.     ori    20h;        downshift
  351.     ret
  352. ;
  353. ; Upshift (a)
  354. ; a,f
  355. ucase:    cpi    'a'
  356.     rc
  357.     cpi    'z'+1
  358.     rnc
  359.     ani    5fh;        upshift
  360.     ret
  361. ;
  362. W╔