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 / UTILS / S / SPLIT14.LBR / SPLIT14.ZZ0 / SPLIT14.Z8°
Text File  |  2000-06-30  |  12KB  |  611 lines

  1. ;        File Splitter
  2. ;
  3. ;By  Guy Cousineau  1988-02-02
  4. ;
  5. ;This utility has no copyright and is
  6. ;being released to the public domain.  It
  7. ;has been thouroughly tested and should
  8. ;behave as advertized.  The author,
  9. ;however, will assume no responsibility
  10. ;for loss or damage resulting from the
  11. ;use of the program.  The source code
  12. ;only is being released; it should
  13. ;assemble easily with any Z80 assembler.
  14. ;
  15. ;comments or suggestions?
  16. ;
  17. ;    Guy Cousineau
  18. ;    1059 Hindley Street
  19. ;    Ottawa Ontario
  20. ;    K2B 5L9
  21. ;    613-829-6354
  22. ;        Ottawa RCPM (613) 829-2530
  23. ;
  24. ;Syntax SPLIT [d:]ufn [d:]nn [/n]
  25. ;
  26. ;Drive spec optional.
  27. ;If source and destination are the same,
  28. ;swap prompts will be given unless the
  29. ;'/n' option is used to create the split
  30. ;files on the same media.
  31. ;
  32. ;files are split in 16k segments unless
  33. ;overriden by 'nn'
  34. ;
  35. ;e.g. SPLIT long.doc 20 /n
  36. ;will split long.doc in 20k segments
  37. ;on the default drive with no disk swaps
  38. ;
  39. ;    Warning I
  40. ;The output files will have the same name
  41. ;except that the last 2 characters of the
  42. ;file type will have the section number
  43. ;starting at 01.  For example, splitting
  44. ;LONG.DOC would yield files LONG.D01
  45. ;LONG.D02, etc.  Be Sure Your Input File
  46. ;Does Not Have A Number In The Last Two
  47. ;Position.
  48. ;
  49. ;    Warning Ii
  50. ;
  51. ;The utility will not work with Wordstar
  52. ;type files with high bit set on <LF>.
  53. ;
  54. ;
  55. ;Revision History:
  56. ;
  57. ;    1.0    ??-??    first release
  58. ;    1.1    ??-??    introduced the noswap option
  59. ;    1.2    92-06    fixed split bug on files over 144k
  60. ;            added variable output file size
  61. ;    1.3    92-07    fixed write bug for generic CP/M
  62. ;    1.4    93-04    increased output file size to max of 48K
  63. ;            made 32K the default
  64. ;
  65. ;System Equates
  66. ;
  67. GETKEY    EQU    1    ;Read keyboard
  68. PRINTC    EQU    2    ;Print character
  69. PRINT    EQU    9    ;Print string
  70. RESET    EQU    13    ;Log in drive for R/W
  71. OPEN    EQU    15    ;Open file
  72. CLOSE    EQU    16    ;Close file
  73. DELETE    EQU    19    ;Delete file
  74. READ    EQU    20    ;Read sequential
  75. WRITE    EQU    21    ;Write sequential
  76. MAKE    EQU    22    ;Make file
  77. GETDSK    EQU    25    ;Get current disk
  78. SETDMA    EQU    26    ;Set memory address for R/W
  79. ;
  80. FCB    EQU    5CH
  81. FCB2    EQU    6CH
  82. BDOS    EQU    5
  83. DMA    EQU    80H
  84. ;
  85.     ORG    100H
  86.     LD    (OLDSP),SP
  87.     LD    SP,STACK
  88. ;
  89.     LD    HL,FCB+1
  90.     LD    A,(HL)
  91.     LD    DE,SYNTAX
  92.     CP    ' '
  93.     JP    Z,QUIT        ;No file given, show syntax
  94. ;
  95. ;Check For Wild Cards
  96. ;
  97.     LD    BC,11
  98.     LD    A,'?'
  99.     CPIR
  100.     LD    DE,WILD
  101.     JP    Z,QUIT
  102. ;
  103. ;Check For Invalid Type
  104. ;
  105.     LD    DE,NUMERR
  106.     LD    A,(FCB+11)
  107.     CP    '1'        ;'0' is Ok
  108.     JR    C,NONUM
  109.     CP    '9'+1
  110.     JP    C,QUIT        ;if last digit between 1 and 9
  111. ;
  112. NONUM
  113.     XOR    A
  114.     LD    (FCB+12),A    ;extent
  115.     LD    (FCB+14),A    ;S2
  116.     LD    (FCB+32),A    ;record count
  117. ;
  118.     LD    HL,FCB        ;input file
  119.     LD    DE,WFCB        ;store it here for write
  120.     LD    BC,12
  121.     LDIR
  122. ;
  123.     LD    A,(FCB2)
  124.     OR    A        ;if none specified then same
  125.     JR    Z,SAMEDISK
  126.     LD    HL,FCB
  127.     CP    (HL)        ;if same as source drive
  128.     JR    Z,SAMEDISK
  129.     LD    (WFCB),A
  130.     LD    (SAMEDSK),A
  131.     XOR    A
  132.     LD    (SWAPFLG),A    ;if different clear swap flag
  133.     JR    SETDISK
  134. ;
  135. ;Check For Noswap
  136. ;
  137. SAMEDISK
  138.     LD    HL,DMA
  139.     LD    C,(HL)
  140.     LD    B,0
  141.     LD    A,'/'        ;option delimiter
  142.     CPIR
  143.     JR    NZ,SETDISK
  144.     LD    A,(HL)
  145.     AND    5FH
  146.     SUB    'N'
  147.     LD    (SWAPFLG),A    ;Will be zero only if 'n' or 'N'
  148. ;
  149. ;Set Default Drive To Actual
  150. ;Since Disk Reset Will Interfere
  151. ;
  152. SETDISK
  153.     LD    C,GETDSK
  154.     CALL    BDOS
  155.     LD    B,A
  156.     INC    B        ;adjust to drive code
  157.     LD    HL,FCB
  158.     LD    A,(HL)
  159.     OR    A
  160.     JR    NZ,SETD1
  161.     LD    (HL),B
  162. SETD1
  163.     LD    HL,WFCB
  164.     LD    A,(HL)
  165.     OR    A
  166.     JR    NZ,CHECKSIZE
  167.     LD    (HL),B
  168. ;
  169. ;check for override of default split size
  170. ;
  171. CHECKSIZE:
  172.     LD    HL,FCB+17    ;byte 1 of FCB 2
  173.     LD    A,(HL)        ;check to see
  174.     CP    ' '        ;if it is empty
  175.     JR    Z,SETLAST    ;then use default 16k
  176.     CP    '/'        ;or option character
  177.     JR    Z,SETLAST    ;
  178.     SUB    '0'        ;is it a number
  179.     JP    C,BADNUM    ;abort program
  180.     CP    10        ;make sure less than 10
  181.     JP    NC,BADNUM
  182.     LD    B,A        ;save a times 1
  183.     RLCA            ;2*a
  184.     RLCA            ;4*a
  185.     ADD    A,B        ;5*a
  186.     RLCA            ;10*a
  187.     LD    B,A        ;save in B temporarily
  188.     INC    HL        ;next byte
  189.     LD    A,(HL)        ;get it and check vailidity
  190.     SUB    '0'
  191.     JP    C,BADNUM
  192.     CP    10
  193.     JP    NC,BADNUM
  194.     ADD    A,B        ;add Tens to units just retrieved
  195.     CP    49
  196.     JP    NC,BADNUM    ;set max to 32k
  197. ;
  198. ;now turn it into records
  199. ;
  200.     LD    H,0
  201.     LD    L,A
  202.     ADD    HL,HL
  203.     ADD    HL,HL
  204.     ADD    HL,HL        ;*8
  205.     LD    (PATCH1),HL
  206.     LD    (PATCH2),HL
  207.     LD    (PATCH3),HL
  208.     ADD    HL,HL        ;*16
  209.     ADD    HL,HL        ;*32
  210.     ADD    HL,HL        ;*64
  211.     ADD    HL,HL        ;*128
  212.     ADD    HL,HL        ;*256
  213.     ADD    HL,HL        ;*512
  214.     ADD    HL,HL        ;*1024
  215.     LD    DE,BUFFER
  216.     ADD    HL,DE        ;get offset to end of buffer
  217.     LD    (PATCH4),HL
  218.     DEC    HL
  219.     DEC    HL
  220.     LD    (PATCH5),HL
  221. ;
  222. ;Set Last Character Of File Type To '0'
  223. ;
  224. SETLAST
  225.     LD    HL,WFCB+11    ;Last Digit Of File Type
  226.     LD    B,'0'
  227.     LD    (HL),B        ;Set Count To 0
  228.     DEC    HL
  229.     LD    (HL),B
  230.     DEC    HL
  231.     LD    A,(HL)        ;set first of fle type to '0' if blank
  232.     CP    ' '
  233.     JR    NZ,GO
  234.     LD    (HL),B    
  235. ;
  236. GO
  237.     LD    DE,START
  238.     CALL    PROMPT        ;in case we need a swap to start
  239. ;
  240. ;Find File And Open It
  241. ;
  242.     LD    DE,FCB
  243.     LD    C,OPEN
  244.     CALL    BDOS
  245.     LD    DE,NOFL        ;error message just in case
  246.     INC    A        ;255+1=0 on error
  247.     JP    Z,QUIT        ;show error and exit
  248. ;
  249. ;Zero Record Count
  250. ;
  251. READAGAIN
  252.     XOR    A
  253.     SBC    HL,HL
  254.     LD    (IRCNUM),HL
  255. ;
  256.     LD    DE,FCB
  257.     PUSH    DE
  258. ;
  259. ;Set Up DMA For Read
  260. ;
  261.     LD    HL,BUFFER
  262.     LD    DE,(OBUFF)    ;Get read-in offset
  263.     ADD    HL,DE        ;write in file here
  264.     CALL    INCB1        ;set DMA and buffer
  265. ;
  266. ;Read Next Record Of File
  267. ;
  268.     LD    BC,32*8        ;read 32k at a time
  269. PATCH1    EQU    $-2
  270. READF
  271.     POP    DE        ;FCB
  272.     PUSH    DE
  273.     PUSH    BC
  274.     LD    C,READ
  275.     CALL    BDOS
  276.     OR    A        ;=0 if good read and not EOF
  277.     JR    NZ,XDISK    ;get ready to write
  278.     CALL    INCBUF        ;increment DMA for next record
  279.     LD    HL,(IRCNUM)
  280.     INC    HL        ;In record count
  281.     LD    (IRCNUM),HL
  282.     CALL    DUMPIT        ;print value in HL
  283.     POP    BC
  284.     DEC    BC
  285.     LD    A,B
  286.     OR    C
  287.     JR    NZ,READF
  288. ;
  289. ;Prompt For Disk Change
  290. ;
  291. XDISK
  292.     POP    DE        ;Clean up stack
  293.     LD    A,(SWAPFLG)
  294.     OR    A
  295.     JR    Z,NOSWAP
  296.     LD    DE,DDISK    ;Swap disk message
  297.     CALL    PROMPT
  298.     LD    C,RESET
  299.     CALL    BDOS
  300. ;
  301. ;Increment File Type
  302. ;
  303. NOSWAP
  304.     LD    HL,WFCB+11    ;Last digit of file type
  305.     LD    A,(HL)
  306.     INC    A
  307.     CP    '9'+1
  308.     JR    NZ,GOODNUMBER    ;just increment last digit
  309.     DEC    HL        ;move to previous
  310.     INC    (HL)        ;bump it up
  311.     INC    HL        ;back to last
  312.     LD    A,'0'        ;make it Zero
  313. GOODNUMBER:
  314.     LD    (HL),A
  315.     XOR    A
  316.     SBC    HL,HL
  317.     LD    (ORCNUM),HL    ;output record count
  318.     LD    (WFCB+12),A    ;extent
  319.     LD    (WFCB+14),A    ;S2
  320.     LD    (WFCB+32),A    ;record number
  321. ;
  322. ;Delete File Name From Destination Disk
  323. ;
  324.     LD    DE,WFCB
  325.     PUSH    DE
  326.     LD    C,DELETE
  327.     CALL    BDOS
  328. ;
  329. ;Create New File
  330. ;    
  331.     POP    DE
  332.     PUSH    DE
  333.     LD    C,MAKE
  334.     CALL    BDOS
  335.     LD    DE,BADIR    ;error message
  336.     INC    A        ;255+1=0 on error
  337.     JR    Z,QUIT
  338. ;
  339. ;Find Last <LF> In File
  340. ;
  341.     LD    HL,(IRCNUM)
  342.     LD    BC,32*8        ;Read a full PARTITION?
  343. PATCH2    EQU    $-2
  344.     OR    A
  345.     SBC    HL,BC
  346.     JP    NZ,LASTWRITE
  347.     LD    HL,SAFEREC    ;safety buffer to read all of last extent
  348.     INC    (HL)        ;write one more record for each split
  349. ;
  350. ;Start At The End Of The Buffer -2 Characters
  351. ;If Either Of The Last 2 Characters Are <LF>
  352. ;We Will Get A Negative Offset Later.
  353. ;
  354.     LD    HL,BUFFER+32*1024-2
  355. PATCH5    EQU    $-2
  356.     LD    A,10        ;<LF>
  357.     LD    BC,-1        ;Make sure we find one
  358.     CPDR
  359. ;Presume One Is Found
  360.     INC    HL        ;Move back to last <LF>
  361.     INC    HL        ;Use next character after <LF>
  362.     LD    (LASTLF),HL    ;Save the address
  363.     LD    A,(HL)
  364.     LD    (LASTC),A    ;Save character
  365.     LD    (HL),26        ;Write EOF
  366. ;
  367. ;Set Up DMA For Write
  368. ;
  369. WRITE1
  370.     LD    HL,BUFFER    ;Write file from start of buffer
  371.     CALL    INCB1        ;set DMA
  372. ;
  373. ;Start To Write File
  374. ;    
  375. WRITEF
  376.     POP    DE        ;FCB
  377.     PUSH    DE
  378.     LD    C,WRITE
  379.     CALL    BDOS
  380.     LD    DE,BADFL    ;Write error message
  381.     OR    A
  382.     JP    NZ,QUIT
  383.     CALL    INCBUF        ;Get next DMA
  384.     LD    HL,(ORCNUM)    ;Records written
  385.     INC    HL
  386.     LD    (ORCNUM),HL
  387.     PUSH    HL
  388.     CALL    DUMPIT
  389.     LD    HL,(IRCNUM)    ;Amount to copy
  390.     POP    DE
  391.     OR    A
  392.     SBC    HL,DE        ;Write as many as we read?
  393.     JR    NZ,WRITEF    ;Not done yet
  394. ;
  395. ;Close File
  396. ;
  397.     POP    DE        ;FCB
  398.     LD    C,CLOSE
  399.     CALL    BDOS
  400.     LD    DE,BDCLOSE    ;Error message
  401.     INC    A        ;255+1=0 on error
  402.     JR    Z,QUIT
  403. ;
  404. ;Write Output File Name To Screen
  405. ;
  406.     LD    A,32        ;Start with a space
  407.     CALL    PRCHR
  408.     LD    HL,WFCB+1    ;Name starts here
  409.     LD    B,11        ;Length of name
  410. FNAME1
  411.     LD    A,(HL)
  412.     CALL    PRCHR
  413.     INC    HL
  414.     DJNZ    FNAME1
  415. ;
  416. ;Check If Last Read
  417. ;
  418.     LD    HL,(ORCNUM)
  419.     LD    BC,32*8        ;Did we write 32k?
  420. PATCH3    EQU    $-2
  421.     OR    A
  422.     SBC    HL,BC
  423.     JR    Z,NOTYET
  424.     LD    DE,DONE
  425. QUIT
  426.     LD    C,PRINT
  427.     CALL    BDOS
  428. QUIT1
  429.     LD    SP,(OLDSP)
  430.     RET
  431. ;
  432. ;bad number specification in output file size
  433. ;
  434. BADNUM:
  435.     LD    DE,BADSIZE
  436.     JR    QUIT
  437. ;
  438. ;***    End Of Program    ***
  439. ;
  440. ;Not Done Yet
  441. ;
  442. NOTYET
  443.     LD    DE,SDISK    ;Swap disk message
  444.     LD    A,(SWAPFLG)
  445.     OR    A
  446.     CALL    NZ,PROMPT
  447. ;
  448. ;Restore Old Character
  449. ;
  450.     LD    HL,(LASTLF)
  451.     LD    A,(LASTC)
  452.     LD    (HL),A
  453. ;
  454. ;Move From This Byte To End Of Read Buffer
  455. ;To Beginning Of Read Buffer
  456. ;And Calculate New Offset
  457. ;    
  458.     EX    DE,HL        ;DE=last character
  459.     LD    HL,BUFFER+1024*32 ;Normal buffer end
  460. PATCH4    EQU    $-2
  461.     LD    BC,(OBUFF)    ;Get read offset
  462.     ADD    HL,BC        ;Current end of data
  463.     XOR    A
  464.     SBC    HL,DE        ;New offset and bytes to relocate
  465.     LD    (OBUFF),HL
  466.     PUSH    HL
  467.     POP    BC        ;Bytes to move
  468.     EX    DE,HL        ;Start at last character
  469.     LD    DE,BUFFER    ;Move to here
  470.     LDIR
  471.     JP    READAGAIN
  472. ;
  473. ;Get Extra Record Count For Last Write
  474. ;
  475. LASTWRITE
  476.     LD    A,(SAFEREC)    ;Extra records to write
  477.     LD    B,A
  478.     LD    HL,(ORCNUM)    ;Output record number=0
  479. SAFE
  480.     DEC    HL        ;Set to -1, -2, Etc
  481.     DJNZ    SAFE
  482.     LD    (ORCNUM),HL
  483.     JP    WRITE1        ;Write out last segment
  484. ;
  485. ;
  486. ;***    Subroutines    ***
  487. ;
  488. ;Print Message In DE
  489. ;Get Keypress And Abort On ^c
  490. ;
  491. PROMPT    LD    C,PRINT
  492.     CALL    BDOS
  493.     LD    C,GETKEY
  494.     CALL    BDOS        ;Wait for keypress
  495.     CP    3        ;^c
  496.     JR    Z,QUIT1        ;if aborted
  497.     RET
  498. ;
  499. ;Advance DMA By 1 Record
  500. ;
  501. INCBUF    LD    HL,(TDMA)    ;Where it was
  502.     LD    DE,80H        ;Add 1 record
  503.     ADD    HL,DE
  504. INCB1    LD    (TDMA),HL
  505.     EX    DE,HL
  506.     LD    C,SETDMA
  507.     CALL    BDOS
  508.     RET
  509. ;
  510. ;Display HL In DECIMAL
  511. ;
  512. DUMPIT:
  513.     LD    A,13    ;<CR>
  514.     CALL    PRCHR
  515. ;
  516.     PUSH    HL
  517.     PUSH    DE
  518.     PUSH    BC
  519.     LD    BC,2                  ;leading zeroes and BDOS print
  520.     LD    DE,10000
  521.     CALL    SUBDIV
  522.     LD    DE,1000
  523.     CALL    SUBDIV
  524.     LD    DE,100
  525.     CALL    SUBDIV
  526.     LD    E,10
  527.     CALL    SUBDIV
  528.     LD    A,L
  529.     JR    SUBDV4
  530. SUBDIV
  531.     XOR    A
  532. SUBDV1
  533.     SBC    HL,DE
  534.     INC    A
  535.     JR    NC,SUBDV1
  536.     ADD    HL,DE
  537.     DEC    A
  538.     JR    Z,SUBDV2
  539.     LD    B,A
  540.     JR    SUBDV3
  541. SUBDV2
  542.     CP    B
  543.     JR    NZ,SUBDV3
  544.     LD    A,32-'0'
  545. SUBDV3
  546.     PUSH    HL
  547.     PUSH    DE
  548.     PUSH    BC
  549. SUBDV4
  550.     ADD    A,'0'
  551.     LD    E,A
  552.     CALL    5
  553.     POP    BC
  554.     POP    DE
  555.     POP    HL
  556.     RET
  557. ;
  558. ;Falls Through To Print Routine
  559. ;
  560. PRCHR
  561.     PUSH    BC
  562.     PUSH    DE
  563.     PUSH    HL
  564.     LD    E,A        ;Character To Print
  565.     LD    C,PRINTC    ;Function
  566.     CALL    BDOS
  567.     POP    HL
  568.     POP    DE
  569.     POP    BC
  570.     RET
  571. ;
  572. ;Messages
  573. ;Note Wild Message Links To Syntax
  574. ;
  575. WILD    DB    7,'No Wild Cards Allowed',13,10
  576. SYNTAX    DB    'SYNTAX: SPLIT [d:]ufn [d:]nn [/N]'
  577.     DB    13,10,'Where /N means no disk swap'
  578.     DB    13,10,'and nn is the split size (default 32K)$'
  579. NUMERR    DB    7,'No numbers allowed in last character$'
  580. START    DB    12,9,'FILE SPLITTER V1.3',13,10
  581.     DB    9,'BY  Guy Cousineau',13,10,10
  582.     DB    7,'Insert source  (^C ABORTS)',13,10,10,'$'
  583. NOFL    DB    13,10,'Can''t find source$'
  584. DDISK    DB    7,' Records read--insert dest',10,'$'
  585. SDISK    DB    7,'  written',13,10,9,'  Insert source',10,'$'
  586. BADIR    DB    13,10,'No directory space$'
  587. BADFL    DB    13,10,'Bad write$'
  588. DONE    DB    13,10,7,9,'--ALL DONE--',13,10,'$'
  589. BDCLOSE    DB    13,10,'Can''t close file$'
  590. BADSIZE    DB    13,10,'Bad split size specification'
  591.     DB    13,10,'Must be between 10 and 48$'
  592. ;
  593. ;Data Storage Area
  594. ;
  595. SAMEDSK    DB    0        ;Source and destination same
  596. SWAPFLG    DB    1        ;Print Swap message
  597. SAFEREC    DB    0        ;Number of extra records to write at end
  598. IRCNUM    DW    0        ;Input record number count
  599. ORCNUM    DW    0        ;Output record number count
  600. OBUFF    DW    0        ;Offset between read and write buffers
  601. TDMA    DS    2        ;Save DMA address here
  602. OLDSP    DS    2
  603. LASTLF    DS    2        ;Save address of last found <LF>
  604. LASTC    DS    1        ;Save last charcater at EOF
  605. WFCB    DS    33
  606.     DS    20H        ;Generous stack space
  607. STACK
  608. BUFFER    EQU    $        ;Copy buffer starts here
  609.     END
  610. ;
  611.