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

  1. ;
  2. ; ===============================================
  3. ;
  4. ;        PROGRAM STARTS HERE
  5. ;
  6. ; ===============================================
  7. ;
  8. ;
  9. ; Save CP/M stack, initialize new one for this program
  10. ;
  11. begin:    lxi    h,0
  12.     dad    sp
  13.     lxi    sp,stack+2;    Reset the stack
  14.     push    h;        Save return to ccp
  15. ;    "    "
  16. ; initialize
  17.     lxi    h,firstoclear
  18.     mvi    b,lastoclear-firstoclear;    ng if > 256
  19.     call    fillz;        zero storage area
  20.     lxi    h,dbuf
  21.     shld    recptr;        set i/o pointer
  22.     call    ilprt
  23.  db    cr,lf,'RXMD v',vers+'0','.',modlev+'0','.',fixlvl+'0',' ',0
  24.     call    chkrsx
  25.     jnz    begin1;        BYERSX is present
  26.     call    ilprt
  27.  db    cr,lf,'BYERSX is not running...aborting...',0
  28. exeunt:    lhld    stack
  29.     sphl
  30.     ret
  31. ;
  32. begin1:    lhld    bdos+1
  33.     lxi    d,lastmem
  34.     mov    a,l
  35.     sub    e
  36.     mov    a,h
  37.     sbb    d
  38.     jnc    begin2
  39.     call    ilprt
  40.  db    cr,lf,'Not enough memory...aborting...',0
  41.     jmp    exeunt
  42. ;
  43. begin2:    mvi    a,setusr
  44.     call    sysquery
  45.     sta    oldusr;        Save current drive/user
  46.     sta    actusr
  47.     mvi    a,curdrv
  48.     call    dos
  49.     sta    olddrv
  50.     sta    actdrv;        and init actual drv/usr
  51.     mvi    e,gwrtprt
  52.     mvi    c,rsxmast
  53.     call    bdos;        need 16 bit return value here
  54.     shld    wpmask;        get incoming wrt protect mask
  55.     call    qwheel
  56.     jnz    begin3;        wheel, no secureit mode
  57.     mvi    a,setsecure
  58.     call    dorsx;        set secure mode for general user
  59.     lxi    d,0
  60.     mvi    a,swrtprt;    remove write protection
  61.     call    dos
  62. begin3:    mvi    e,0;        Set parity off for file xfrs
  63.     mvi    a,sgbaud
  64.     call    dos;        get existing parity.
  65.     sta    oldbd
  66.     ani    0cfh;        mask parity field
  67.     ori    010h;        set no parity (can set stops here)
  68.     mov    e,a
  69.     mvi    a,sgbaud
  70.     call    dos;        and set it up
  71.     call    catch;        Flush the line prior to rcv/send
  72. ;    "    "
  73. ; Check primary option
  74.     lxi    h,fcb+1
  75.     mov    a,m
  76.     sta    optsav;        Save option for later use
  77.     sta    crcflg;        Insure in CRC mode now
  78.     cpi    'L';        Send a file from a library?
  79.     jz    begin5
  80.     cpi    'S';        Send a normal file?
  81.     jz    begin5
  82.     cpi    'R';        Receive a file?
  83.     jnz    opterr;        None of these, show help guide
  84.     call    mspeed;        check i/o baud rate
  85.     sui    5
  86.     sbb    a;        0 for nc, ffh for cy
  87.     cma;            0 for < 5, i.e. <1200 baud
  88.     sta    kflg;        Set the 1k flag for now
  89. ;    "    "
  90. ; Check for additional receive options
  91.     inx    h
  92.     mov    a,m;        Get the receive option, if any
  93.     cpi    ' ';        Next column a space character?
  94.     jz    rckbch;        If yes, see if requesting batch
  95.     cpi    'P'
  96.     jnz    begin4
  97.     sta    prvtfl;        set the private flag
  98.     inx    h
  99.     mov    a,m
  100. begin4:    cpi    ' '
  101.     jz    rckbch;        see if requesting batch
  102.     cpi    'B';        For batch mode
  103.     jz    rckbch
  104.     cpi    'C'
  105.     jz    rcksm
  106.     cpi    'X'
  107.     jnz    opterr;        None of these, show help guide
  108.     xra    a;        Orig. XMODEM protocol,
  109.     sta    kflg;        reset the 1k flag
  110.     jmp    rcrc
  111. ;
  112. ; select send mode
  113. begin5:    inx    h
  114.     mov    a,m;        Get next char on command line
  115.     cpi    'B';        Requesting batch mode?
  116.     jz    sbch
  117.     cpi    'X';        'X' for XMODEM protocol?
  118.     jz    sndfl;        If yes go send the file
  119.     cpi    'K'
  120.     jnz    sndfl;        'K' to force 1k transmissions
  121.     sta    kflg;        Else set the 1k flag
  122.     call    ilprt
  123.  db    '1k protocol enabled',0
  124.     jmp    sndfl
  125. ;
  126. ; ==============================================
  127. ;
  128. ; ---> SNDFL    sends a CP/M file
  129. ;
  130. ; ===============================================
  131. ;
  132. bchmsg:    sta    bchflg;        Set the batch flag
  133.     call    ilprt
  134.  db    '- (Batch is enabled)',cr,lf,0
  135.     ret
  136. ;
  137. ; Displays the Batch enabled message for send
  138. ;
  139. sbch:    call    bchmsg
  140. ;    "    "
  141. ; The CP/M file specified in the RXMD command is transferred over the
  142. ; phone to another computer with modem using the "R" (receive)
  143. ; option.  The data is sent one record at a time with headers and
  144. ; checksums, and retransmission on errors.
  145. ;
  146. sndfl:    xra    a
  147.     sta    sndflg;        Show in send mode
  148.     lda    bchflg
  149.     ora    a
  150.     jnz    sbtch;        Batch mode requested
  151.     call    logdu
  152. sndfl1:    lda    optsav
  153.     cpi    'L'
  154.     cnz    cnrec;        Ignore if in library mode
  155.     call    opnfil;        Open the file
  156.     call    rdblk1;        Put up to 16k from file into buffer
  157.     call    catch;        Flush input
  158.     mvi    e,60;        Wait up to 1 minute for initial 'NAK'
  159.     call    waitnak
  160.     call    setflg;        Can't use 1k if not 8 records in file
  161. ;    "    "
  162. ; Loops back to this point after a successful transmission for next one
  163. sndlp:    call    gtratio;    Check the ACK ratio if using 1k blocks
  164.     call    rdrecd;        Read a record
  165.     jc    sndeof;        Send 'EOF' if done
  166.     call    incrno;        Bump record number if sent ok
  167.     xra    a;        Initialize error count to zero
  168.     sta    errct
  169. ;    "    "
  170. ; Comes back here to repeat previous transmission if no ACK was received
  171. sndrpt:    call    ckabort;    Want to stop sending for some reason?
  172.     call    funchk;        Check the function keys
  173.     call    sndhdr;        Send a header
  174.     call    sndrec;        Send data record
  175.     call    sndchk;        Send CRC or checksum value
  176.     call    gtack;        Get the 'ACK'
  177.     jc    sndrpt;        No 'ACK', repeat transmission
  178.     call    setptr;        Successful record so increase pointers
  179.     lda    optsav;        Get the command option again
  180.     cpi    'L'
  181.     jnz    sndlp;        If not library option, exit
  182.     call    setlbr;        Set library pointers and size left
  183.     lhld    rcnt
  184.     mov    a,h
  185.     ora    l
  186.     jnz    sndlp;        not finished, send more
  187. ;    "    "
  188. ; File sent, send EOT but do local log-keeping first
  189. sndeof:    call    eofsnd
  190.     call    alldon
  191.     jmp    done
  192. ;
  193. ; Sends batch mode
  194. sbtch:    lda    fstflg;        If first time through
  195.     ora    a
  196.     jnz    sbtch1;        If not first time, exit
  197.     call    ilprt
  198.  db    'wait while calculating.....',0
  199.     call    logdu;        Check disk, user
  200.     call    tnmbuf;        Put all requested files into NAMBUF
  201. ;    "    "
  202. ; Total number of files, total records and total length is shown,
  203. ; user then gets up to 5 seconds to abort.
  204.     xra    a
  205.     sta    remoff;        Show following to remote on 1st time
  206.     call    ilprt
  207.  db    cr,'Ready to send in batch mode'
  208.  db    cr,lf,'Total files   : ',0
  209.     lda    filcnt;        Get total files
  210.     sta    shocnt
  211.     push    psw
  212.     call    decouta;    Show remote # of files
  213.     pop    psw
  214.     ora    a;        Abort if no files to send
  215.     jz    nofile
  216.     call    ilprt
  217.  db    cr,lf,'Total records : ',0
  218.     lhld    totrec;        Get total records - all files
  219.     push    h
  220.     call    decout;        Show remote
  221.     call    ilprt
  222.  db    ' (',0
  223.     pop    h
  224.     call    decoutk;    Show # of k
  225.     call    ilprt
  226.  db    'k)'
  227.  db    cr,lf,'Disk space    : ',0
  228.     lhld    blokk;        Get k required on remote disk for 2k
  229.     dad    h;        Double the size for 2k blocks
  230.     call    decout;        Print it
  231.     call    ilprt
  232.  db    'k with 2k blocks',0
  233. ;    "    "
  234. sbtch1:    lda    filcnt
  235.     ora    a
  236.     jz    sbtch2
  237.     lda    fstflg
  238.     sta    remoff
  239.     call    ilprt
  240.  db    cr,lf,'Time for files: ',0
  241.     lxi    d,ktable;    using k mode
  242.     lhld    totrec;        Get number of records
  243.     call    filtim
  244.     call    showtime
  245.     call    crlf
  246.     lda    fstflg
  247.     ora    a
  248.     jnz    sbtch2
  249.     inr    a;        Now show we have been this way
  250.     sta    fstflg
  251.     call    ilprt
  252.  db    'CTL-X to cancel',cr,lf,cr,lf,0
  253. ;    "    "
  254. sbtch2:    call    ckabort
  255.     call    sndfn;        Sends file name to receive
  256.     jc    sbtch4;        No more files, exit
  257.     call    showfil;    Show the batch filename
  258.     jmp    sndfl1;        Send the file
  259. ;
  260. sbtch4:    lda    gotone;        Did we actually send at least one?
  261.     ora    a
  262.     jz    abort;        If not, don't act like we did
  263.     call    eofsnd;        No more files so send EOT to finish
  264.     call    xfrdon
  265.     jmp    exit
  266. ;
  267. nofile:    call    erxit
  268.  db    cr,lf,'++ Ask again, no files found ++','$'
  269. ;
  270. eofsnd:    mvi    a,eot;        Send an 'EOT'
  271.     call    send
  272.     lda    chkeot;        Did not get an ACK, try again
  273.     inr    a
  274.     sta    chkeot;        Limit number of retries to 4
  275.     cpi    4;           (to prevent possible 'lock-up')
  276.     rnc;            Quit if already sent 4 or more
  277.     call    gtack;        Get the ACK
  278.     jc    eofsnd;        Resend if carry is set
  279.     ret
  280. ;
  281. alldon:    lda    bchflg
  282.     ora    a
  283.     rnz;            In batch mode, ignore message
  284.     call    crlf;        (Want to keep this a separate message)
  285. ;    "    "
  286. xfrdon:    call    ilprt
  287.  db    cr,lf,'[Transfer completed]',cr,lf,0
  288.     ret
  289. ;
  290. ; ==============================================
  291. ;
  292. ; ---> RCVFL    Receive a CP/M file
  293. ;
  294. ; ==============================================
  295. ;
  296. ; Can be invoked by "RXMD R FILENAME.TYPE" or "RXMD RC FILENAME.TYP"
  297. ; if checksum is to be used.
  298. ;
  299. ; Allows batch mode to private area if R, RB or RPB is typed
  300. rckbch:    lda    fcb1+1;        Was a file requested
  301.     cpi    ' '
  302.     jnz    rcrc;        Can't use batch if file requested
  303.     call    bchmsg;        Show batch enabled message
  304.     jmp    rcvfl
  305. ;
  306. rcrc:    mvi    a,1
  307.     sta    crcflg;        Show in CRC mode
  308.     call    ilprt
  309.  db    ' -  (CRC is enabled)',cr,lf,0
  310.     jmp    rcvfl;        All set to receive a file
  311. ;
  312. rcksm:    xra    a
  313.     sta    crcflg
  314.     sta    kflg;        Can't use 1k blocks with checksum
  315.     call    ilprt
  316.  db    ' -  Checksum enabled',cr,lf,0
  317. ;    "    "
  318. rcvfl:    lda    bchflg
  319.     ora    a
  320.     jnz    rcvbch;        If batch mode requested exit
  321.     call    ducheck;    Find drive/user/filetype permitted
  322.     call    cktyp;        Check for restricted file types
  323.     call    chekfil;    Set d/u access
  324.     call    display;    Display drive/user area
  325.     call    makefil;    Open the file, ready to receive
  326. ;    "    "
  327. rcvlp:    call    rcvrecd;    Get a record
  328.     jc    rcveot;        Exit if 'EOT' for end of current file
  329.     call    incrno;        Bump record number, if received ok
  330.     call    wrrecd;        Write the record
  331.     call    sndack;        Ack the record
  332.     jmp    rcvlp;        Loop until 'EOF'
  333. ;
  334. ; Got EOT on record so flush buffers then done
  335. rcveot:    lhld    recdno
  336.     mov    a,h
  337.     ora    l
  338.     jz    rcvsabt;    Abort and erase a zero length file
  339.     call    sndack;        Ack the record
  340.     call    wrblock;    Write the last block
  341.     call    closfil;    Close the file
  342.     call    alldon
  343.     jmp    done
  344. ;
  345. ; ------------------------------------------------
  346. ;
  347. ; Using batch so reset flags
  348. ;
  349. rcvbch:    xra    a
  350.     sta    frstim;        Needs to be reset for each new file
  351.     mvi    a,1
  352.     sta    sndflg;        Shows we are in receive batch mode
  353.     lda    fstflg
  354.     ora    a
  355.     jnz    rcvbc1;        Following for first batch file only
  356.     call    ducheck;    Find drive/user/filetype permitted
  357.     call    chekfil;    Set d/u access
  358.     call    display;    Display drive/user area
  359.     lxi    h,nambuf
  360.     shld    nbsave
  361.     mvi    a,1
  362.     sta    fstflg
  363. ;    "    "
  364. rcvbc1:    call    rcvfn;        Get and display batch file name
  365.     jc    rcvbc2;        If all done, exit
  366.     call    cktyp;        Change file type if needed
  367.     call    chekfil;    Already have a file with that name?
  368.     call    makefil
  369.     call    bchinr
  370.     call    ilprt
  371.  db    'Waiting.....',0
  372.     mvi    a,crc
  373.     call    send
  374.     mvi    a,ksnd;        Request 1k blocks
  375.     call    send
  376.     jmp    rcvlp;        Go receive the file
  377. ;
  378. rcvbc2:    xra    a;        Zero the batch mode flag
  379.     sta    bchflg
  380.     lda    gotone;        Were there any files received?
  381.     ora    a
  382.     jz    abort
  383.     call    xfrdon;        Show transmission is finished
  384.     call    wait1;        Delay to let remote get into ter. md.
  385. ;    "    "
  386. ; Finished with the file transfer
  387. done:    lda    bchflg
  388.     ora    a
  389.     jz    exit;        not batch, all done so go finish up
  390.     lda    olddrv;        Restore original drive
  391.     call    dskset
  392.     lda    oldusr;        Restore original user
  393.     call    usrset
  394.     lxi    d,tbuf;        Reset to default DMA address
  395.     mvi    a,stdma
  396.     call    dos
  397.     mvi    b,12;        Zero out fntbuf
  398.     lxi    h,fntbuf
  399.     call    fillz
  400. ;    "    "
  401. ; Now fill in the batch file name
  402.     mvi    b,12;        Put file name in fntbuf
  403.     lxi    h,fcb+1
  404.     lxi    d,fntbuf
  405. done2:    mvi    a,4;        Start of file type?
  406.     cmp    b
  407.     jz    done4;        Put in period if so
  408.     mov    a,m
  409.     cpi    ' ';        Don't put in space
  410.     jz    done3
  411.     stax    d;        Store in fntbuf
  412.     inx    d
  413. done3:    inx    h
  414.     dcr    b
  415.     mov    a,b
  416.     ora    a;        End of file name?
  417.     jz    done5;        Display file name
  418.     jmp    done2;        Loop for another character
  419. ;
  420. done4:    mov    a,m
  421.     cpi    ' ';        Is file type empty?
  422.     jz    done5;        Go if so
  423.     mvi    a,'.';        Else put period in message
  424.     stax    d
  425.     inx    d
  426.     dcr    b
  427.     jmp    done2
  428. ;
  429. done5:    mvi    a,1;        Display filename locally only
  430.     sta    remoff
  431.     sta    gotone;        Indicates there was a file handled
  432.     call    crlf
  433.     lxi    h,fntbuf
  434.     call    tstr;        Display the file name
  435.     call    ilprt
  436.  db    ' Transferred',cr,lf,0
  437. ;    "    "
  438. ; Now reset some flags for another possible batch file
  439.     xra    a
  440.     sta    eoflg;        Clear end of file flag
  441.     sta    chkeot;        Clear the "resend EOT" flag
  442.     lxi    h,0
  443.     shld    accerr;        Reset accumulated error count
  444.     shld    recnbf;        Zero num of rcds in the buffer
  445.     shld    recdno;        Zero current rcd number
  446.     shld    rcdcnt;        Zero transmit rcd counter
  447.     lxi    h,dbuf;        Reset buffer pointers
  448.     shld    recptr
  449.     lda    sndflg;        Goes to either send or
  450.     ora    a;        Receive file, depending
  451.     jz    sndfl;        Upon which routine set
  452.     lda    filcnt
  453.     cpi    50;
  454.     jc    rcvfl;        not 50 files yet, get next
  455.     call    ilprt
  456.  db    cr,lf,'++ 50 batch uploads is the limit ++',cr,lf,0
  457.     xra    a
  458.     sta    bchflg;        Reset the batch mode flag
  459.     jmp    exit
  460. ;
  461. ; -------------------------------------
  462. ;        help guide
  463. ;
  464. ; Invalid option
  465. opterr:    call    crlf
  466.     call    ilprt
  467.  db    cr,lf,'   Uploads files to ',0
  468.     call    setgrv;        set general receive area
  469.     jz    optx1;        not jammed
  470.     call    showsz
  471.     jmp    optx3
  472. optx1:    call    ilprt
  473.  db    'specified or current disk/user',0
  474. optx3:    call    setpvt;        set private rcv area
  475.     jz    optx4;        private not enabled
  476.     call    ilprt
  477.  db    cr,lf,'   Private files to ',0
  478.     call    showsz
  479. optx4:    call    crlf
  480.     lda    optsav;        Check 'option'
  481.     cpi    'A';        If 'A' (avail upload space option)
  482.     jz    exit;        Skip error message
  483. ;    "    "
  484.     call    erxit;        Exit with error
  485.  db    '++ Examples of valid options: ++',cr,lf,cr,lf
  486.  db    '   RXMD A                   to show areas'
  487.  db            '/available space for uploads',cr,lf
  488.  db    '   RXMD L CAT.LBR CAT.COM   to send a file '
  489.  db            'from a library',cr,lf
  490.  db    '   RXMD L CAT CAT.COM       (.LBR extent may '
  491.  db            'be omitted)',cr,lf
  492.  db    '   RXMD LK PATCH PATCH.AQM  to send library file with '
  493.  db            '1k protocol',cr,lf
  494.  db    '   RXMD RB   (or just R)    to receive RX/KMD-type 1k '
  495.  db            'batch mode',cr,lf
  496.  db    '   RXMD R HELLO.DOC         to receive a file '
  497.  db            'from you',cr,lf
  498.  db    '   RXMD RC HELLO.DOC        to receive a file via '
  499.  db            'checksum',cr,lf
  500.  db    '   RXMD RP HELLO.DOC        to receive in a private '
  501.  db            'area',cr,lf
  502.  db    '   RXMD RPC HELLO.DOC       to receive a private file '
  503.  db            'via checksum',cr,lf
  504.  db    '   RXMD RX HELLO.DOC        to force CRC protocol',cr,lf
  505.  db    '   RXMD SB HELLO.*          to send RX/KMD-type 1k batch '
  506.  db            'mode',cr,lf
  507.  db    '   RXMD S HELLO.DOC         to send a file',cr,lf
  508.  db    '   RXMD S B1:HELLO.DOC      to send from a '
  509.  db            'named drive/area',cr,lf
  510.  db    '   RXMD SK RXMD.DOC         to manually select 1k '
  511.  db            'protocol',cr,lf,cr,lf
  512.  db    '(Using just R tells sender you have CRC, 1k and '
  513.  db            'checksum modes)'
  514.  db    '$'
  515. ;
  516. ; Show drive/user and size available
  517. showsz:    call    showdu
  518.     call    ilprt
  519.  db    ' - ',0
  520.     lda    actdrv
  521.     adi    'A'
  522.     jmp    kshow
  523. ;
  524. ; Show actually selected dsk/user
  525. showdu:    lda    actdrv
  526.     adi    'A'
  527.     call    ctype
  528.     lda    actusr
  529.     call    decouta
  530.     mvi    a,':'
  531.     jmp    ctype
  532. Lα