home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol238 / files.aqm / FILES.ASM
Encoding:
Assembly Source File  |  1986-02-10  |  14.8 KB  |  619 lines

  1. title 'FILES.ASM'
  2. ;************************************************
  3. ;*                        *
  4. ;*        FILES.ASM            *
  5. ;*                        *
  6. ;*  CP/M (r) disk file interface module for     *
  7. ;*  X.25 protocol packet interface         *
  8. ;*  (uses CP/M seqio serial I/O macro library)    *
  9. ;*                        *
  10. ;*  rev 0.14    07/18/84    E. Elizondo    *
  11. ;*                        *
  12. ;*  (c) 1984 E. Elizondo - all rights reserved. *
  13. ;*                        *
  14. ;*    This program may be used freely for non-  *
  15. ;*  commercial applications. It may not be sold *
  16. ;*  or used for commercial applications without *
  17. ;*  written permission of the author.           *
  18. ;*                         *
  19. ;************************************************
  20. ;    
  21.     
  22.     maclib    seqio        ;DR sequential I/O library
  23.     maclib    Z80        ;DR Z80 macro library
  24.  
  25. false    equ    0
  26. true    equ    not false
  27.  
  28. ;    CP/M system equates
  29.  
  30. fname1:    equ    005ch        ;ccp default file name #1
  31. fname2:    equ    006ch        ;ccp default file name #2
  32.  
  33. ;    hooks for other programs
  34.  
  35. ;    subroutines
  36.     public    otxfil        ;open transmit file
  37.     public    orxfil        ;open receive file
  38.     public    olgfil        ;open log file
  39.     public    gfdata        ;get a byte from transmit file
  40.     public    pfdata        ;put a byte to receive file
  41.     public    logdat        ;put a byte to log file
  42.     public    crxfil        ;close rx file
  43.     public    ctxfil        ;close tx file
  44.     public    clgfil        ;close log file
  45.     public    iparms        ;initialize system parameters
  46.     public    wparms        ;write system parameters on disk
  47.  
  48. ;    addresses
  49.     public    fstat        ;file status flags
  50.  
  51. ;    definition of fstat status bits
  52. ;    bit    set condition
  53. ;    0    receive file open
  54. ;    1    transmit file open
  55. ;    2    undefined
  56. ;    3    undefined
  57. ;    4    undefined
  58. ;    5    undefined
  59. ;    6    undefined
  60. ;    7    log file open
  61.  
  62. ;    layout of default parameters in file X25.PAR:
  63. ;    byte    name    description
  64. ;    1    dtemod    dte/dce mode flag
  65. ;    2    baudop    baud rate option
  66. ;    3    pvcmod    pvc/vc mode flag
  67. ;    4    laddrl    local DTE address length
  68. ;    5    raddrl    remote DTE address length
  69. ;    6-20    laddr    local DTE address
  70. ;    21-35    raddr    remote DTE address
  71.  
  72.  
  73. ;    external subroutines
  74.     extrn    ilprt        ;in line print routine
  75.     extrn    move        ;move block of data
  76.     extrn    instr        ;input string from console
  77.     
  78. ;    external addresses
  79.  
  80. ;    buffers 
  81.     extrn    inbuf        ;console string input buffer
  82.  
  83. ;    level 1 parameters
  84.     extrn    baudop        ;default baud rate option
  85.  
  86. ;    level 2 parameters
  87.     extrn    dtemod        ;dte/dce mode flag
  88.     extrn    lkstat        ;level 2 status flags
  89.  
  90. ;    level 3 parameters
  91.     extrn    pvcmod        ;pvc/vc mode flag
  92.     extrn    laddrl        ;local DTE address length
  93.     extrn    raddrl        ;remote DTE address length
  94.     extrn    laddr        ;local DTE address
  95.     extrn    raddr        ;remote DTE address
  96.     extrn    chstat        ;level 3 channel status flags
  97.     extrn    l3stat        ;level 3 flow status
  98.  
  99.  
  100. ;    *****************
  101. ;    *  subroutines    *
  102. ;    *****************
  103.  
  104.     cseg            ;code section
  105.  
  106.  
  107. ;    initialize system parameters
  108. ;    (externally called)
  109. ;    on entry:    no parameters
  110. ;    on exit:    all regs, flags clobbered
  111.  
  112. iparms:
  113. ;    check if parameter file exists
  114.     file    setfile,pcheck,,X25,PAR,,parbuf
  115. ;
  116.     direct    pcheck    ;is file there?
  117.     rz        ;no, return
  118. ;
  119. ;    open file for access
  120.     file    infile,oldpar,,X25,PAR,128,parbuf
  121. ;
  122. ;    update system parameters
  123.     get    oldpar        ;get 1st parameter
  124.     sta    dtemod        ;update default DTE/DCE mode flag
  125.     get    oldpar        ;get 2nd parameter
  126.     sta    baudop        ;update default baud rate option
  127.     get    oldpar        ;get 3rd parameter
  128.     sta    pvcmod        ;update default PVC/VC mode flag
  129.     get    oldpar        ;get 4th parameter
  130.     sta    laddrl        ;update default local DTE address length
  131.     get    oldpar        ;get 5th parameter
  132.     sta    raddrl        ;update default remote DTE address length
  133. ;
  134. ;    update local DTE address
  135.     mvi    b,16        ;max address length+1 (in hex chars)
  136.     lxi    h,laddr        ;point to local DTE address
  137. iparm1:    dcr    b        ;last char?
  138.     jz    iparm2        ;yes, exit loop
  139. ;
  140.     push    b        ;save <bc>
  141.     push    h        ;save <hl>
  142.     get    oldpar        ;get address char
  143.     pop    h        ;restore <hl>
  144.     pop    b        ;restore <bc>
  145.     mov    m,a        ;update address char
  146.     inx    h        ;bump pointer
  147.     jmp    iparm1        ;and go for more
  148. ;
  149. ;    update remote DTE address
  150. iparm2:    mvi    b,16        ;max address length+1 (in hex chars)
  151.     lxi    h,raddr        ;point to local DTE address
  152. iparm3:    dcr    b        ;last char?
  153.     jz    iparm4        ;yes, exit loop
  154. ;
  155.     push    b        ;save <bc>
  156.     push    h        ;save <hl>
  157.     get    oldpar        ;get address char
  158.     pop    h        ;restore <hl>
  159.     pop    b        ;restore <bc>
  160.     mov    m,a        ;update address char
  161.     inx    h        ;bump pointer
  162.     jmp    iparm3        ;and go for more
  163. ;
  164. iparm4:    finis    oldpar        ;close file
  165.     ret
  166.  
  167.  
  168.  
  169. ;    write system parameters to disk
  170. ;    (externally called)
  171. ;    on entry:    no parameters
  172. ;    on exit:    all regs, flags clobbered
  173.  
  174. wparms:    
  175. ;    open file for access
  176.     file    outfile,newpar,,X25,PAR,128,parbuf
  177. ;
  178. ;    update file with current system parameters
  179.     lda    dtemod        ;get new DTE/DCE mode flag
  180.     put    newpar        ;update 1st parameter
  181.     lda    baudop        ;get new baud rate option
  182.     put    newpar        ;update 2nd parameter
  183.     lda    pvcmod        ;get pvc/vc mode flag
  184.     put    newpar        ;update 3rd parameter
  185.     lda    laddrl        ;get local DTe address length
  186.     put    newpar        ;update 4th parameter
  187.     lda    raddrl        ;get remote DTE address length
  188.     put    newpar        ;update 5th parameter
  189. ;
  190. ;    update local DTE address in file
  191.     mvi    b,16        ;max address length+1 (in hex chars)
  192.     lxi    h,laddr        ;point to local DTE address
  193. wparm1:    dcr    b        ;last char?
  194.     jz    wparm2        ;yes, exit loop
  195. ;
  196.     push    b        ;save <bc>
  197.     push    h        ;save <hl>
  198.     mov    a,m        ;get address char
  199.     put    newpar        ;update char in file
  200.     pop    h        ;restore <hl>
  201.     pop    b        ;restore <bc>
  202.     inx    h        ;bump pointer
  203.     jmp    wparm1        ;and go for more
  204. ;
  205. ;    update remote DTE address in file
  206. wparm2:    mvi    b,16        ;max address length+1 (in hex chars)
  207.     lxi    h,raddr        ;point to local DTE address
  208. wparm3:    dcr    b        ;last char?
  209.     jz    wparm4        ;yes, exit loop
  210. ;
  211.     push    b        ;save <bc>
  212.     push    h        ;save <hl>
  213.     mov    a,m        ;get address char
  214.     put    newpar        ;update char in file
  215.     pop    h        ;restore <hl>
  216.     pop    b        ;restore <bc>
  217.     inx    h        ;bump pointer
  218.     jmp    wparm3        ;and go for more
  219. ;
  220. wparm4:    finis    newpar        ;close file
  221.     ret
  222.  
  223.  
  224. ;    open transmit file for access:
  225. ;    (externally called)
  226. ;    on entry:    no parameters
  227. ;    on exit:    all regs, flags clobbered
  228.  
  229. otxfil:
  230.     lxi    h,fstat        ;point to status flags
  231.     bit    1,m        ;transmit file open?
  232.     jz    otxf1        ;no, keep going
  233. ;
  234.     call    ilprt        ;else tell operator
  235.     db    'L4: transmit file is already open',cr,lf,0
  236.     ret            ;and return with no action
  237. ;
  238. otxf1:    call    ilprt
  239.     db    'transmit file name: ',0
  240.     call    gfn        ;get file name
  241.     rc            ;abort function if no input
  242. ;
  243.     lxi    h,tfname    ;now move parsed name to default..
  244.     lxi    d,fname1    ;fcb at first name location
  245.     lxi    b,12        ;      /
  246.     call    move        ;     /
  247. ;
  248. ;    set up file to check directory
  249.     file    setfile,txcheck,,1,,
  250. ;
  251.     direct    txcheck        ;see if file is there
  252. ;
  253.     jnz    otxf2        ;jump if we found it
  254.     call    ilprt
  255.     db    'L4: file not found',cr,lf,0
  256.     ret
  257. ;
  258. ;    open file for read
  259. otxf2:    file    infile,source,,1,,1024,txfbuf
  260.     lxi    h,fstat        ;point to file status flags
  261.     setb    1,m        ;set file open flag
  262.     lxi    h,chstat    ;point to level 3 channel status
  263.     bit    0,m        ;flow control ready state?
  264.     jz    otxf3        ;no, keep going
  265. ;
  266.     lxi    h,l3stat    ;point to level 3 status
  267.     setb    7,m        ;signal message waiting
  268.     call    ilprt        ;yes, signal transmission start
  269.     db    'L4: file transmission in process',cr,lf,0
  270.     ret
  271. ;
  272. otxf3:    call    ilprt
  273.     db    'L4: ready to transmit file',cr,lf,0
  274.     ret
  275.  
  276.  
  277. ;    get a byte from transmit file
  278. ;    (externally called)
  279. ;    on entry:    no parameters
  280. ;    on exit:    <a>= byte if available
  281. ;            zero flag set if end of file
  282. ;            all other regs unchanged
  283.  
  284. gfdata:    di            ;disable interrupts
  285.     push    h        ;save regs
  286.     push    d        ;    /
  287.     push    b        ;      /
  288.     get    source        ;get byte from file
  289.     pop    b        ;restore regs
  290.     pop    d        ;    /
  291.     pop    h        ;      /
  292.     ei            ;enable interrupts
  293.     ret            ;and return
  294.  
  295. ;
  296. ;    close transmit file
  297. ;    (externally and internally called)
  298. ;    on entry:    no parameters
  299. ;    on exit:    <a>, flags clobbered
  300. ;            all other regs unchanged
  301.  
  302. ctxfil:
  303.     push    h        ;save regs
  304.     push    d        ;    /
  305.     push    b        ;      /
  306.     lxi    h,fstat        ;reset tx file open flag
  307.     bit    1,m        ;transmit file open?
  308.     jz    ctx1        ;no, exit
  309. ;
  310.     res    1,m        ;else reset flag
  311.     finis    source        ;close file
  312.     call    ilprt        ;and tell operator
  313.     db    'L4: transmit file closed',cr,lf,0
  314. ctx1:    pop    b        ;restore regs
  315.     pop    d        ;    /
  316.     pop    h        ;      /
  317.     ret
  318.  
  319.  
  320.  
  321. ;    open receive file for access
  322. ;    (externally called)
  323. ;    on entry:    no parameters
  324. ;    on exit:    all flags, regs clobbered
  325.  
  326. orxfil:
  327.     lxi    h,fstat        ;point to status flags
  328.     bit    0,m        ;receive file open?
  329.     jz    orxf1        ;no, keep going
  330. ;
  331.     call    ilprt        ;else tell operator
  332.     db    'L4: receive file is already open',cr,lf,0
  333.     ret            ;and return with no action
  334. ;
  335. orxf1:    call    ilprt
  336.     db    'receive file name: ',0
  337.     call    gfn        ;get file name into tfname
  338.     rc            ;abort function if no input
  339. ;
  340. ;
  341.     lxi    h,tfname    ;now move parsed name to default..
  342.     lxi    d,fname2    ;fcb at second name location
  343.     lxi    b,12        ;      /
  344.     call    move        ;     /
  345. ;
  346.  
  347. ;    set up file to check directory
  348.     file    setfile,rxcheck,,2,,
  349. ;
  350.     direct    rxcheck        ;see if file is there
  351. ;
  352.     jz    orxf2        ;jump if new file
  353. ;
  354. ;    file exists by same name
  355.     call    ilprt
  356.     db    'file already exists, delete it (y/n)? ',cr,lf,0
  357.     get    key        ;get reply
  358.     cpi    'y'        ;is it yes?
  359.     jz    orxf2        ;yes, keep going
  360. ;
  361.     cpi    'Y'        ;upper case also
  362.     jz    orxf2        ;    /
  363. ;
  364.     call    ilprt        ;else terminate line
  365.     db    cr,lf,0        ;    /
  366.     ret            ;and return
  367. ;
  368. ;    open file for read
  369. orxf2:    call    ilprt        ;terminate line
  370.     db    cr,lf,0
  371.     file    outfile,dest,,2,,1024,rxfbuf
  372. ;
  373.     call    ilprt
  374.     db    'L4: receive file open - awaiting data',cr,lf,0
  375.     lxi    h,fstat        ;point to file status flags
  376.     setb    0,m        ;set rx file open flag
  377.     ret
  378.  
  379.  
  380.  
  381. ;    write a byte to receive file
  382. ;    (externally called)
  383. ;    on entry:    <a>= byte to be written
  384. ;    on exit:    all regs unchanged
  385.  
  386. pfdata:    push    h        ;save regs
  387.     push    d        ;    /
  388.     push    b        ;      /
  389.     put    dest        ;write byte to file
  390.     pop    b        ;restore regs
  391.     pop    d        ;    /
  392.     pop    h        ;      /
  393.     ret            
  394.  
  395.  
  396.  
  397. ;    close receive file
  398. ;    (externally called)
  399. ;    on entry:    no parameters
  400. ;    on exit:    <a>,flags clobbered
  401. ;            all other regs unchanged
  402.  
  403. crxfil:
  404.     push    h        ;save regs
  405.     push    d        ;    /
  406.     push    b        ;      /
  407.     lxi    h,fstat        ;point to file status flags
  408.     bit    0,m        ;receive file open?
  409.     jz    crx1        ;no, exit
  410. ;
  411.     res    0,m        ;else clear rx file open flag
  412.     finis    dest        ;close file
  413.      call    ilprt        ;and tell operator
  414.     db    'L4: receive file closed',cr,lf,0
  415. crx1:    pop    b        ;restore regs
  416.     pop    d        ;    /
  417.     pop    h        ;      /
  418.     ret
  419.  
  420.  
  421.  
  422. ;    get and parse file name into temp file name buffer
  423. ;    (internally called)
  424. ;    on entry:    no parameters
  425. ;    on exit:    carry set if file name error
  426. ;            parsed file name in tfname buffer
  427. ;            (so it can be copied to fcb)
  428. ;            all other flags, regs clobbered
  429.  
  430. gfn:
  431.     call    instr        ;read console string
  432.     call    ilprt        ;output a line feed
  433.     db    lf,0        ;    /
  434.     lda    inbuf+1        ;<a>=input string size
  435.     mov    b,a        ;save it in <b> also
  436.     ora    a        ;no input?
  437.     stc            ;set carry for abort
  438.     rz            ;and return
  439. ;
  440.     lxi    h,tfname    ;<hl>=A(tfname)
  441.     xra    a        ;clear drive specifier
  442.     mov    m,a        ;    /
  443.     inx    h        ;now clear file name & type
  444.     mvi    a,' '        ;to spaces
  445.     mvi    c,11        ;all 11 bytes
  446. gfn0:    mov    m,a        ;clear a byte
  447.     inx    h        ;bump pointers
  448.     dcr    c        ;    /
  449.     jnz    gfn0        ;until end of file type
  450. ;
  451. ;    get drive specifier, if any
  452.     lxi    d,tfname    ;<de>=A(tfname)
  453.     lxi    h,inbuf+2    ;<hl>=A(input string)
  454.     call    getchr        ;get first non-space character
  455.     jz    gfnerr        ;error if none available
  456. ;
  457.     inx    h        ;point to second byte
  458.     mov    a,m        ;get second byte
  459.     dcx    h        ;point back to first byte
  460.     cpi    ':'        ;drive separator?
  461.     jnz    gfn2        ;no, process normally
  462. ;
  463. ;    transfer drive code to tfname
  464.     mov    a,m        ;get drive code
  465.     inx    h        ;and move past it
  466.     inx    h
  467.     dcr    b        ;and bump pointer
  468.     dcr    b
  469.     call    valchr        ;valid ASCII?
  470.     jc    gfnerr        ;exit with error if not
  471.     sui    40h        ;else remove ASCII bias
  472.     stax    d        ;and store at tfname+0
  473. ;
  474. ;    transfer file name to tfname
  475. gfn2:    inx    d        ;skip over drive code field
  476.     mvi    c,8        ;max file name length
  477.     call    getchr        ;get a real char
  478.     jz    gfnerr        ;error if no character available
  479. ;
  480. gfn3:    call    getchr        ;get char
  481.     rz            ;exit if end of input
  482.     cpi    '.'        ;file type delimiter
  483.     jz    gfn4        ;yes, go process it
  484.     call    valchr        ;valid ASCII?
  485.     jc    gfnerr        ;no, signal error
  486.     stax    d        ;else store in tfname
  487.     inx    h        ;bump pointers
  488.     inx    d        ;    /
  489.     dcr    b        ;    /
  490.     rz            ;exit if end of input
  491.     dcr    c        ;loop until end of name
  492.     jnz    gfn3        ;    /
  493. ;
  494.     call    getchr        ;get next char
  495.     rz            ;done if out of input
  496.     cpi    '.'        ;file type delimiter?
  497.     jnz    gfnerr        ;no, name is too long
  498. ;
  499. gfn4:    inx    h        ;skip over '.'
  500.     dcr    b        ;    /
  501.     rz            ;exit if done
  502.     lxi    d,tfname+9    ;<de>=A(file type)
  503.     mvi    c,3        ;max length of file type
  504. gfn5:    call    getchr        ;get char
  505.     rz            ;exit if done
  506.     call    valchr        ;valid ASCII?
  507.     jc    gfnerr        ;no, exit with error
  508.     stax    d        ;else store in tfname
  509.     inx    h        ;bump pointers
  510.     inx    d        ;    /
  511.     dcr    b        ;    /
  512.     rz            ;return if out of input
  513.     dcr    c        ;loop until end of file type
  514.     jnz    gfn5        ;or drop thru if file type too long
  515. ;
  516. gfnerr:    call    ilprt
  517.     db    'L4: file name error',cr,lf,0
  518.     stc            ;set carry for abort
  519.     ret
  520.  
  521. ;    get char from input buffer, deleting spaces
  522. ;    (internally called)
  523. ;    on entry: <hl>= current pointer location
  524. ;           <c> = remaining character count
  525. ;    on exit:  <a> = character
  526. ;          zero set if last character
  527. ;
  528. getchr:    mov    a,m        ;get char
  529.     cpi    ' '        ;space?
  530.     rnz            ;no, return with char in hand
  531.     inx    h        ;else bump pointers
  532.     dcr    b        ;    /
  533.     rz            ;return with zero if last char
  534.     jmp    getchr        ;or loop till out of spaces
  535.  
  536.  
  537. ;    check for valid file name character
  538. ;    (internally called)
  539. ;    on entry: <a>= character (converted to upper case)
  540. ;    on exit:  carry set if error
  541.  
  542. valchr:    cpi    '0'        ;control or punctuation?
  543.     rc            ;yes, return with error
  544.     cpi    61h        ;lower case?
  545.     jc    valch1        ;no don't process it
  546.     sui    20h        ;make it upper case
  547. ;
  548. valch1:    cpi    'Z'+1        ;punctuation?
  549.     cmc            ;yes, return with error
  550.     rc            ;    /
  551.     cpi    'A'        ;possible special character?
  552.     rnc            ;no, char is ok
  553.     cpi    '9'+1        ;special character?
  554.     cmc            ;yes, set carry for error
  555.     ret            ;and return in any case
  556.  
  557.  
  558. ;    open log file
  559. ;    (externally called)
  560. ;    on entry:    no paramters
  561. ;    on exit:    all regs, flags clobbered
  562.  
  563. olgfil:    file    outfile,lgfil,,X25,LOG,1024,logbuf
  564.     lxi    h,fstat        ;point to file status flags
  565.     setb    7,m        ;signal log file open
  566.     call    ilprt        ;and tell operator
  567.     db    'L4: frame logging enabled',cr,lf,0
  568.     ret
  569.  
  570.  
  571. ;    write byte to log file
  572. ;    (externally called)
  573. ;    on entry:    <a>=byte
  574. ;    on exit:    all regs unchanged
  575.  
  576. logdat:    push    h        ;save regs
  577.     push    d        ;    /
  578.     push    b        ;      /
  579.     put    lgfil        ;write byte to file
  580.     pop    b        ;restore regs
  581.     pop    d        ;    /
  582.     pop    h        ;      /
  583.     ret
  584.  
  585.  
  586. ;    close log file
  587. ;    (externally called)
  588. ;    on entry:    no parameters
  589. ;    on exit:    all flags, regs clobberd
  590.  
  591.  
  592. clgfil:    lxi    h,fstat        ;point to file status flags
  593.     bit    7,m        ;log file open?
  594.     rz            ;no, exit
  595. ;
  596.     res    7,m        ;else signal log file closed
  597.     finis    lgfil        ;close file
  598.     call    ilprt        ;and tell operator
  599.     db    'L4: frame logging disabled',cr,lf,0
  600.     ret
  601.  
  602.  
  603.  
  604. ;    *****************
  605. ;    * data area    *
  606. ;    *****************
  607.  
  608. ;    leave in cseg
  609.  
  610. ;    status flags
  611. fstat:    dw    0    ;file status flags
  612.  
  613. ;    disk data buffers
  614. tfname:    ds    12    ;temp buffer for file name
  615. parbuf:    ds    128    ;disk buffer for parameters
  616. rxfbuf:    ds    1024    ;rx disk file buffer area
  617. txfbuf:    ds    1024    ;tx disk file buffer area
  618. logbuf:    ds    1024    ;log disk file buffer area
  619.