home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / TERMS / QT43SRC.LBR / CATCH.ZY / CATCH.ZY
Text File  |  2000-06-30  |  3KB  |  178 lines

  1. ; catch.z - open & close catch files, also put them on hold
  2.  
  3. .incl    "c:vars"
  4.  
  5. .extern    catch
  6. catch:
  7.     ld    a,(cflg)
  8.     or    a
  9.     jr    z,tfileo
  10.     ld    a,2
  11.     ld    (cflg),a
  12.  
  13. .extern    hold
  14. hold:
  15.     ld    hl,cflg
  16.     ld    a,(hl)
  17.     or    a        ; file open?
  18.     ret    z        ; no - so do nothing
  19.     xor    3
  20.     ld    (hl),a        ; toggle hold mode
  21.     push    af
  22.     call    ilprt
  23.     db    '\r\nCatch file \0'
  24.     pop    af
  25.     dec    a
  26.     jr    z,reac
  27.     call    ilprt
  28.     db    'on hold\r\n\0'
  29.     ret
  30. reac:    call    ilprt
  31.     db    'reactivated\r\n\0'
  32.     ret
  33.  
  34. .extern    cclose
  35. cclose:
  36.     ld    a,(cflg)
  37.     or    a
  38.     ret    z
  39.     call    doclos
  40.     call    ilprt
  41.     db    '\r\nFile closed\r\n\0'
  42.     ret
  43.  
  44. tfileo:    call    getfcb
  45.     ret    c
  46.     jp    z,nowc
  47.     ld    a,(fcb + 2)
  48.     cp    ' '
  49.     scf
  50.     ret    z
  51.     call    reset
  52.     ld    hl,fcb
  53.     ld    de,cfcb
  54.     push    de
  55.     ld    bc,34
  56.     ldir
  57.     pop    de
  58.     push    de
  59.     ld    c,open
  60.     call    usrbds
  61.     inc    a
  62.     pop    de
  63.     jr    z,isok
  64. appndq:    ld    hl,10
  65.     add    hl,de
  66.     bit    7,(hl)
  67.     jr    z,appok
  68.     call    ilprt
  69.     db    'Can\'t append file\r\n\0'
  70.     ret
  71. appok:    ld    c,cfsize
  72.     push    de
  73.     call    usrbds
  74.     pop    de
  75.     ld    hl,36
  76.     add    hl,de
  77.     ld    a,(hl)
  78.     dec    hl
  79.     or    (hl)
  80.     dec    hl
  81.     or    (hl)
  82.     jr    z,creok
  83. declp:    ld    a,(hl)
  84.     dec    (hl)
  85.     inc    hl
  86.     or    a
  87.     jr    z,declp
  88.     push    de
  89.     ld    de,(cbuff)
  90.     ld    c,setdma
  91.     call    bdos
  92.     call    fill1a
  93.     pop    de
  94.     ld    c,redrnd
  95.     call    usrbds
  96.     ld    hl,(cbuff)
  97.     dec    hl
  98. eofl:    inc    hl
  99.     ld    a,(hl)
  100.     cp    0x1a
  101.     jr    nz,eofl
  102.     ld    (cptr),hl
  103.     jr    setcfo
  104. isok:    ld    c,create
  105.     call    usrbds
  106.     inc    a
  107.     jr    nz,creok
  108.     call    ilprt
  109.     db    'Can\'t create file\r\n\0'
  110.     ret
  111. creok:    call    fill1a
  112. setcfo:    call    ilprt
  113.     db    'File opened\r\n\0'
  114.     xor    a
  115.     inc    a
  116. setcfl:    ld    (cflg),a
  117.     ret
  118.  
  119. doclos:    call    flushc
  120.     ld    de,cfcb
  121.     ld    c,close
  122.     call    usrbds
  123.     call    ctlq
  124.     xor    a
  125.     jr    setcfl
  126.  
  127. .extern    flushc            ; enter here to flush any pending write of
  128. flushc:                ; catch buffer
  129.     ld    hl,(cptr)
  130.     ld    de,(cbuff)    ; point at buffer
  131.     or    a
  132.     sbc    hl,de        ; how many chars in buffer
  133.     dec    hl
  134.     add    hl,hl
  135.     inc    h
  136.     ld    b,h        ; converted to sector count
  137.     ret    z        ; nothing to write - exit now
  138.     push    bc
  139.     push    de
  140.     call    ctls        ; hold up the other end
  141.     pop    de
  142.     pop    bc
  143. wrtlp:    push    bc
  144.     push    de        ; save registers
  145.     ld    c,setdma
  146.     call    bdos        ; set dma for next 128 bytes
  147.     ld    de,cfcb
  148.     ld    c,write
  149.     call    usrbds        ; out they go
  150.     pop    de
  151.     ld    hl,128
  152.     add    hl,de        ; move dma
  153.     ex    de,hl
  154.     pop    bc
  155.     djnz    wrtlp        ; loop till all done
  156.  
  157. fill1a:                ; enter here to fill catch buffer with 0x1a's
  158.                 ; and reset catch pointer
  159.     ld    hl,(cbuff)
  160.     ld    (cptr),hl    ; adjust catch pointer as well
  161.     ld    d,h
  162.     ld    e,l
  163.     inc    de        ; copy to de & add 1
  164.     ld    bc,(cbfsiz)    ; get buffer size
  165.     ld    (hl),0x1a    ; first one
  166.     ldir            ; and the rest
  167.     ret
  168.  
  169. .dseg
  170. .extern    cflg
  171. cflg:    db    0
  172.  
  173. .useg
  174. .extern    cptr
  175. cptr:    ds    2        ; pointer to next save address
  176. .extern    cfcb
  177. cfcb:    ds    37        ; fcb for catching
  178.