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 / CPM / TURBODSG / RS16.MQC / RS16.MAC
Text File  |  2000-06-30  |  4KB  |  295 lines

  1. ;RS-16
  2. ;
  3. cr    equ    0dh
  4. lf    equ    0ah
  5. ;
  6. dfcb    equ    5ch
  7. dbuf    equ    80h
  8. ;
  9.     extrn    f$open,f$close,f$read,f$write
  10.     extrn    scanner,codend,cout
  11.     extrn    bbline,print,phl4hc,eval16,phlfdc
  12.     extrn    initfcb,pfn2,crlf
  13.     extrn    wildex
  14. ;
  15. .z80
  16. ;
  17. start:    ld    sp,stack
  18.     call    print
  19.     cr,lf
  20.     ' --------------------------------------------------',cr,lf
  21.     '|      RS-16 reserializer for 16-bit TurboDOS      |',cr,lf
  22.     '| WARNING: (c) infringement is YOUR responsibility |',cr,lf
  23.     ' --------------------------------------------------',cr,lf,lf,0
  24.     ld    a,(dfcb+1)
  25.     cp    ' '
  26.     jr    nz,..ct1
  27.     call    print
  28.     'No file specified',cr,lf,0
  29.     rst    0
  30. ;
  31. ..ct1:    ld    a,(dfcb+9)
  32.     cp    'O'
  33.     jr    nz,..noo
  34.     ld    hl,(dfcb+10)
  35.     ld    de,'  '
  36.     xor    a
  37.     sbc    hl,de
  38.     jr    nz,..noo
  39.     call    codend
  40.     ld    de,dfcb
  41.     call    wildex
  42.     jr    nz,..ct2
  43.     call    print
  44.     'File(s) not found',cr,lf,0
  45.     rst    0
  46. ;
  47. ..noo:    call    print
  48.     'File(s) must be type .O',cr,lf,0
  49.     rst    0
  50. ;
  51. ..ct2:    call    phlfdc
  52.     call    print
  53.     ' files matched.',cr,lf,lf
  54.     'Enter: New Origin (hex) : ',0
  55.     push    hl
  56.     ld    a,1
  57.     call    bbline
  58.     call    eval16
  59.     ld    (neworg),de
  60.     call    print
  61.     cr,lf
  62.     '       New Unit (hex)   : ',0
  63.     ld    a,1
  64.     call    bbline
  65.     call    eval16
  66.     ld    (newuni),de
  67.     pop    hl
  68.     inc    hl
  69.     ld    (count),hl        ;save # of files
  70.     ex    de,hl
  71.     ld    hl,0
  72.     ld    bc,16            ;find file buffer start
  73. ..mlp:    add    hl,bc
  74.     dec    de
  75.     ld    a,d
  76.     or    e
  77.     jr    nz,..mlp
  78.     ex    de,hl
  79.     call    codend
  80.     ld    (fcbs),hl
  81.     add    hl,de
  82.     inc    h
  83.     ld    l,0
  84.     ld    (buffer),hl
  85. ;
  86. ; come here for each file
  87. ;
  88. loop:    ld    hl,(count)
  89.     dec    hl
  90.     ld    (count),hl
  91.     ld    a,h
  92.     or    l
  93.     jp    z,done
  94.     ld    hl,(fcbs)
  95.     ld    bc,16
  96.     ld    de,dfcb
  97.     ldir
  98.     ld    (fcbs),hl
  99.     ld    de,dfcb
  100.     call    initfcb
  101.     call    print
  102.     cr,lf,lf
  103.     'Now processing ',0
  104.     inc    de
  105.     call    pfn2
  106.     call    crlf
  107.     ld    de,dfcb
  108.     call    f$open
  109.     ld    hl,(buffer)
  110.     ld    (bufptr),hl
  111.     xor    a
  112.     ld    (chgd),a
  113. rdlp:    call    f$read
  114.     jr    nz,allrd
  115.     ld    hl,(bufptr)
  116.     ld    bc,dbuf
  117. ..mvl:    ld    a,(bc)
  118.     ld    (hl),a
  119.     inc    hl
  120.     inc    c
  121.     jr    nz,..mvl
  122.     ld    (bufptr),hl
  123.     jr    rdlp
  124. ;
  125. allrd:    call    f$close
  126.     ld    hl,(bufptr)
  127.     ld    (bufend),hl
  128.     ld    hl,(buffer)
  129.     ld    (bufptr),hl
  130. ..fol:    call    findo
  131.     jr    nz,lku            ;exhausted, look for unit
  132.     push    hl            ;save pointer
  133.     call    getbd            ;get seg=BC, val=DE
  134.     ld    a,b
  135.     or    c
  136.     jr    nz,..no1
  137.     push    hl            ;(HL=.val)
  138.     call    print
  139.     cr,lf
  140.     '"Origin" value ',0
  141.     push    bc
  142.     pop    hl
  143.     call    phl4hc
  144.     ld    a,':'
  145.     call    cout
  146.     ex    de,hl
  147.     call    phl4hc
  148.     ld    de,(neworg)
  149.     pop    hl
  150.     ld    (hl),e
  151.     inc    hl
  152.     ld    (hl),d
  153. ..no1:    pop    hl
  154.     jr    ..fol
  155. ;
  156. lku:    ld    hl,(buffer)
  157. ..ful:    call    findu
  158.     jr    nz,endsb        ;end of substitutions
  159.     push    hl            ;save pointer
  160.     call    getbd            ;get seg=BC, val=DE
  161.     ld    a,b
  162.     or    c
  163.     jr    nz,..nu1
  164.     push    hl            ;(HL=.val)
  165.     call    print
  166.     cr,lf
  167.     '"Unit"   value ',0
  168.     push    bc
  169.     pop    hl
  170.     call    phl4hc
  171.     ld    a,':'
  172.     call    cout
  173.     ex    de,hl
  174.     call    phl4hc
  175.     ld    de,(newuni)
  176.     xor    a
  177.     sbc    hl,de
  178.     jr    z,ch
  179.     ld    a,1
  180.     ld    (chgd),a
  181. ch:    pop    hl
  182.     ld    (hl),e
  183.     inc    hl
  184.     ld    (hl),d
  185. ..nu1:    pop    hl
  186.     jr    ..ful
  187. ;
  188. endsb:    ld    a,(chgd)
  189.     or    a
  190.     jp    z,loop
  191. ;
  192. ; write back to disk
  193. ;
  194.     ld    de,dfcb
  195.     call    initfcb
  196.     call    f$open        ;open for write
  197.     ld    hl,(buffer)
  198.     ld    (bufptr),hl
  199. wrlp:    ld    hl,(bufptr)
  200.     ld    bc,(bufend)
  201.     ld    a,b
  202.     cp    h
  203.     jr    nz,..ne
  204.     ld    a,c
  205.     cp    l
  206.     jr    z,wrend
  207. ..ne:    ld    bc,80h
  208. ..ss:    ld    a,(hl)
  209.     ld    (bc),a
  210.     inc    hl
  211.     inc    c
  212.     jr    nz,..ss
  213.     ld    (bufptr),hl
  214.     call    f$write
  215.     jr    wrlp
  216. ;
  217. wrend:    call    f$close
  218.     JP LOOP
  219. ;
  220. getbd:    dec    hl
  221.     ld    a,(hl)
  222.     cp    ' '+1
  223.     jr    nc,getbd
  224.     ld    b,(hl)
  225.     dec    hl
  226.     ld    c,(hl)
  227.     dec    hl
  228.     ld    d,(hl)
  229.     dec    hl
  230.     ld    e,(hl)
  231.     ret
  232. ;
  233. findu:    ld    de,unit
  234.     jr    ..fnd
  235. ;
  236. findo:    ld    de,orgin
  237. ..fnd:    push    de
  238. ..flop:    ld    a,(de)
  239.     or    a
  240.     jr    z,..fxt
  241.     cp    (hl)
  242.     inc    hl
  243.     call    ..ckb
  244.     jr    nz,..nfd
  245.     inc    de
  246.     jr    ..flop
  247. ;
  248. ..nfd:    pop    de
  249.     jr    ..fnd
  250. ;
  251. ..fxt:    pop    de
  252.     xor    a
  253.     ret
  254. ;
  255. ..ckb:    ld    bc,(bufend)
  256.     push    af    
  257.     ld    a,b
  258.     cp    h
  259.     jr    nz,..nbd
  260.     ld    a,c
  261.     cp    l
  262.     jr    nz,..nbd
  263.     pop    af
  264.     pop    de        ;dummy
  265.     pop    de
  266.     xor    a
  267.     inc    a
  268.     ret
  269. ;
  270. ..nbd:    pop    af
  271.     ret
  272. ;
  273. done:    call    print
  274.     cr,lf,lf
  275.     '*** END OF EXECUTION ***',cr,lf,lf,0
  276.     rst    0
  277. ;
  278. neworg:    dw    24
  279. newuni:    dw    227
  280. orgin:    db    'Origin',0
  281. unit:    db    'Unit',0
  282. chgd:    db    0        ;0=no change, NZ=must write
  283. fcbs:    dw    0        ;pointer to next file name
  284. buffer:    dw    0        ;buffer start
  285. bufptr:    dw    0
  286. bufend:    dw    0
  287. count:    dw    0        ;file count
  288.     ds    80
  289. stack    equ    $
  290.     end
  291. (hl)
  292.     ld    (bc),a
  293.     inc    hl
  294.     inc    c
  295.     jr    nz,..ss