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 / ZCPR33 / A-R / EASE20.LBR / VARPACK.ZZ0 / VARPACK.Z80
Text File  |  2000-06-30  |  8KB  |  634 lines

  1. ; PROGRAM:    EASE history file packer
  2. ; AUTHOR:    Paul Pomerleau
  3. ; DATE:        Jan 22, 1987
  4. ; VERSION:    1.1
  5.  
  6. ;=============================================================================
  7. ;
  8. ;        D E F I N I T I O N S    S E C T I O N
  9. ;
  10. ;=============================================================================
  11.  
  12.  
  13. MEMLOC        equ    80h + 21h
  14. STARTREG    equ    80h + 23h
  15. USEMEM        equ    80h + 20h
  16. vers    equ    12
  17. bdos    equ    5
  18.  
  19.     ext    z3init,pfn3,print,pstr,crlf,cout
  20.     ext    f$open,f$read,f$write,f$close,f$delete,f$make
  21.     ext    z3log,qprint,getquiet
  22.     ext    eval10,skpun,putreg,getreg,phlfdc
  23.  
  24.  
  25. ;=============================================================================
  26. ;
  27. ;        S T A N D A R D    P R O G R A M    H E A D E R
  28. ;
  29. ;=============================================================================
  30.  
  31. ENTRY:
  32.     jp    START
  33.     defb    'Z3ENV'
  34.     defb    3        ; Type-3 environment
  35. ENVADDR:
  36.     dw    0f300h
  37.     dw    ENTRY
  38.     defb    vers
  39.  
  40. ;=============================================================================
  41. ;
  42. ;        C O N F I G U R A T I O N    A R E A
  43. ;
  44. ;=============================================================================
  45.  
  46. FCB:    db    0,'EASE    VAR'
  47.     ds    24,0
  48.  
  49. ;=============================================================================
  50. ;
  51. ;        M A I N    C O D E    S E C T I O N
  52. ;
  53. ;=============================================================================
  54.  
  55. START:
  56.  
  57.     ld    hl,(ENVADDR)    ; Get environment address
  58.     call    z3init        ; Initialize library routines
  59.     call    HEADER
  60.  
  61.     ld    hl,(6)
  62.     ld    de,900h
  63.     sbc    hl,de
  64.     ld    (ENDPOS),hl
  65.     xor    a
  66.     ld    (SECTORS),a
  67.     ld    a,(5dh)
  68.     cp    '/'
  69.     jp    z,HELP
  70.     cp    ' '
  71.     jr    z,DEFAULTS
  72.     ld    hl,5dh
  73.     call    eval10
  74.     or    a
  75.     jr    z,NAMFIRST
  76.     ld    a,(hl)
  77.     cp    ' '
  78.     jr    nz,NAMFIRST
  79.     ld    a,e
  80.     ld    (SECTORS),a
  81.     ld    de,6dh
  82.     jr    NAMSECOND
  83. NAMFIRST:
  84.     ld    de,5dh
  85. NAMSECOND:
  86.     ld    a,(de)
  87.     dec    de
  88.     cp    ' '
  89.     jr    nz,GOT_NAME
  90. DEFAULTS:
  91.     ld    de,FCB
  92. GOT_NAME:
  93.     call    nz,Z3LOG
  94.     call    f$open
  95.     jp    nz,FILE_NOT_FOUND
  96.     ld    (FILE),de
  97.     ld    hl,BUFFER
  98. READ_FILE:
  99.     call    SET_DMA_HL
  100.     jp    z,NO_ROOM
  101.     call    f$read
  102.     jr    z,READ_FILE
  103.     ex    de,hl
  104.     ld    hl,82h
  105.     ld    b,7eh
  106. FIND_COMMA:
  107.     dec    b
  108.     jp    z,JUST_WRITE
  109.     ld    a,(hl)
  110.     inc    hl
  111.     or    a
  112.     jp    z,JUST_WRITE
  113.     cp    ','
  114.     jr    nz,FIND_COMMA
  115.     call    skpun
  116.     ld    a,(hl)
  117.     cp    'P'
  118.     jp    nz,BAD_OPTION
  119.     call    MAKE_INDEX
  120.     call    PACK
  121.     ret
  122.  
  123. MAKE_INDEX:
  124.     ld    hl,INDEX
  125.     ld    de,BUFFER + 1
  126. M_I_LOOP:
  127.     call    GET_NEXT_STRING
  128.     push    af
  129.     ld    (hl),e
  130.     inc    hl
  131.     ld    (hl),d
  132.     inc    hl
  133.     pop    af
  134.     jr    nz,M_I_LOOP
  135.     inc    hl
  136.     ld    (hl),1
  137.     ret
  138.  
  139. PACK:
  140.         call    qprint
  141.         db    13,10,'Packing line #',13,10,0
  142.         ld    hl,0
  143.         ld    (LINE),hl
  144.     call    IHLSKIP
  145.     call    WIDE_PACK_LOOP
  146.     ld    a,13
  147.     call    cout
  148.     ld    hl,(LINE)
  149.     call    QPHLFDC
  150.     call    REPORT_DELS
  151.     call    THINK
  152.     call    WRITE
  153.     ret
  154.  
  155. WIDE_PACK_LOOP:
  156. STATUS:        ld    hl,(LINE)
  157.         inc    hl
  158.         ld    (LINE),hl
  159.         ld    a,l
  160.         and    1111b
  161.         push    af
  162.         ld    a,13
  163.         call    z,cout
  164.         pop    af
  165. ENDSTAT:    call    z,QPHLFDC
  166.     call    HLSKIP
  167.     ret    z
  168.     call    IDESKIP
  169.     call    DESKIP
  170.     call    PACK_LOOP
  171.     jp    WIDE_PACK_LOOP
  172.  
  173. PACK_LOOP:
  174.     call    DESKIP
  175.     ret    z
  176.     call    COMPARE_STRINGS
  177.     jp    nz,PACK_LOOP
  178.     call    DEL_CURRENT
  179.     jp    PACK_LOOP
  180.  
  181. THINK:
  182.     ld    de,BUFFER+2
  183.     call    DEL_PACK
  184. THINK2:    call    FIND_END
  185.     inc    hl
  186.     ld    (ENDPOS),hl
  187.     push    hl
  188.     push    de
  189.     ld    e,l
  190.     ld    d,h
  191.     inc    de
  192.     ld    (hl),0
  193.     ld    bc,7fh
  194.     ldir
  195.     pop    de
  196.     pop    hl
  197.     call    FIND_START
  198.     ret
  199.  
  200. FIND_START:
  201.     ld    a,(SECTORS)
  202.     or    a
  203.     jr    z,CALC_FINI
  204.     ld    b,a
  205. CALC_START:
  206.     push    bc
  207.     ld    bc,128
  208.     sbc    hl,bc
  209.     pop    bc
  210.     djnz    CALC_START
  211.     ex    de,hl
  212.     push    de
  213.     ld    hl,BUFFER
  214.     or    a
  215.     sbc    hl,de
  216.     pop    de
  217.     jr    c,CALC_OK
  218. CALC_FINI:
  219.     ld    hl,BUFFER
  220.     ret
  221. CALC_OK:
  222.     call    GET_NEXT_STRING
  223.     ex    de,hl
  224.     dec    hl
  225.     ld    (hl),0
  226.     dec    hl
  227.     ld    (hl),0
  228.     ret
  229.  
  230. WRITE:
  231.     ld    de,(FILE)
  232.     call    CLEAR_FILE
  233.     call    f$delete
  234.     call    CLEAR_FILE
  235.     call    f$make
  236.     ld    a,(SECTORS)
  237.     or    a
  238.     jr    z,WRITE_ALL
  239.     ld    b,a
  240. WRITE_LOOP:
  241.     push    bc
  242.     call    SET_DMA_HL
  243.     jr    z,WRITE_DONE
  244.     call    f$write
  245.     pop    bc
  246.     djnz    WRITE_LOOP
  247.     push    bc
  248. WRITE_DONE:
  249.     pop    bc
  250. WRITE_FINI:
  251.     call    f$close
  252.     push    de
  253.     call    CLEAR_FILE
  254.     pop    de
  255.     push    de
  256.     ex    de,hl
  257.     ld    de,9
  258.     add    hl,de
  259.     ld    de,COM
  260.     ex    de,hl
  261.     ld    bc,3
  262.     ldir
  263.     call    qprint
  264.     db    13,10,'Informing Ease of change...',0
  265.     pop    de
  266.     call    f$open
  267.     jp    nz,FILE_NOT_FOUND
  268.     push    de
  269.     ld    c,26
  270.     ld    de,80h
  271.     call    bdos
  272.     pop    de
  273.     call    f$read
  274.     ld    b,0
  275.     call    get
  276.     cp    'E'
  277.     ret    nz
  278.     xor    a
  279.     call    put
  280.     inc    b
  281.     call    put
  282.     inc    b
  283.     jp    put
  284.  
  285. FIND_END:
  286.     call    GET_NEXT_STRING
  287.     jr    nz,FIND_END
  288.     ex    de,hl
  289.     ret
  290.  
  291. WRITE_ALL:
  292.     call    SET_DMA_HL
  293.     jr    z,WRITE_FINI
  294.     call    f$write
  295.     jr    WRITE_ALL
  296.  
  297. REPORT_DELS:
  298.     call    getquiet
  299.     ret    nz
  300.     call    IHLSKIP
  301.     exx
  302.     ld    bc,0
  303.     call    REP_DEL_LOOP
  304.     push    bc
  305.     exx
  306.     call    qprint
  307.     db    13,10,'Comand lines deleted: ',0
  308.     pop    hl
  309.     jp    QPHLFDC
  310.  
  311. REP_DEL_LOOP:
  312.     inc    hl
  313.     ld    a,(hl)
  314.     inc    hl
  315.     cp    1
  316.     ret    z
  317.     or    a
  318.     jr    nz,REP_DEL_LOOP
  319.     inc    bc
  320.     jr    REP_DEL_LOOP
  321.  
  322. IDESKIP:
  323.     exx
  324.     ld    d,h
  325.     ld    e,l
  326.     exx
  327.     ret
  328.  
  329. IHLSKIP:
  330.     exx
  331.     ld    hl,INDEX
  332.     ld    (SAVEDHL),hl
  333.     exx
  334.     ret
  335.  
  336. DESKIP:    exx
  337.     ex    de,hl
  338.     ld    c,(hl)
  339.     inc    hl
  340.     ld    b,(hl)
  341.     inc    hl
  342.     push    bc
  343.     ex    de,hl
  344.     exx
  345.     pop    de
  346.     ld    a,d
  347.     or    a
  348.     jr    z,DESKIP
  349.     ld    a,(de)
  350.     or    a
  351.     ret
  352.  
  353. HLSKIP:    exx
  354.     ld    hl,(SAVEDHL)
  355.     ld    c,(hl)
  356.     inc    hl
  357.     ld    b,(hl)
  358.     inc    hl
  359.     ld    (SAVEDHL),hl
  360.     push    bc
  361.     exx
  362.     pop    hl
  363.     ld    a,h
  364.     or    a
  365.     jr    z,HLSKIP
  366.     ld    a,(hl)
  367.     or    a
  368.     ret
  369.  
  370. DEL_CURRENT:
  371.     ld    (hl),';'
  372.     exx
  373.     dec    hl
  374.     ld    (hl),0
  375.     inc    hl
  376.     ld    h,d
  377.     ld    l,d
  378.     exx
  379.     ret
  380.     
  381. GET_NEXT_STRING:
  382.     inc    de
  383.     ld    a,(de)
  384.     or    a
  385.     jp    nz,GET_NEXT_STRING
  386.     inc    de
  387.     ld    a,(de)
  388.     or    a
  389.     ret
  390.  
  391. NO_ROOM:
  392.     call    print
  393.     db    13,10,'File too large: ',0
  394.     ld    de,(FILE)
  395.     inc    de
  396.     call    pfn3
  397.     ret
  398.  
  399. FILE_NOT_FOUND:
  400.     call    print
  401.     db    13,10,'Cannot find file: ',0
  402.     inc    de
  403.     call    pfn3
  404.     ret
  405.  
  406. SET_DMA_HL:
  407.     push    de
  408.     ex    de,hl
  409.     ld    hl,(ENDPOS)
  410.     sbc    hl,de
  411.     ex    de,hl
  412.     jr    nc,SET_DMA_OK
  413.     xor    a
  414.     jr    SET_DMA_DONE
  415. SET_DMA_OK:
  416.     xor    a
  417.     inc    a
  418. SET_DMA_DONE:
  419.     push    af
  420.     push    bc
  421.     push    hl
  422.     ld    d,h
  423.     ld    e,l
  424.     ld    c,26
  425.     call    bdos
  426.     pop    hl
  427.     ld    bc,128
  428.     add    hl,bc
  429.     pop    bc
  430.     pop    af
  431.     pop    de
  432.     ret
  433.  
  434. CLEAR_FILE:
  435.     push    af
  436.     push    bc
  437.     push    de
  438.     push    hl
  439.     ex    de,hl
  440.     ld    bc,12
  441.     add    hl,bc
  442.     ld    (hl),0
  443.     inc    hl
  444.     inc    hl
  445.     ld    (hl),0
  446.     ld    d,h
  447.     ld    e,l
  448.     inc    de
  449.     ld    bc,22
  450.     ldir
  451.     pop    hl
  452.     pop    de
  453.     pop    bc
  454.     pop    af
  455.     ret
  456.  
  457. COMPARE_STRINGS:
  458.     push    hl
  459.     ld    c,e
  460.     ld    b,d
  461. CS_LOOP:
  462.     push    bc
  463.     ld    a,(hl)
  464.  
  465. UPCASE:    cp    'z'+1
  466.     jr    nc,U2
  467.     cp    'a'
  468.     jr    nc,U2
  469.     sub    a,'z'-'Z'
  470. U2:    ld    b,a
  471.     ld    a,(de)
  472.     cp    'z'+1
  473.     jr    nc,U3
  474.     cp    'a'
  475.     jr    nc,U3
  476.     sub    a,'z'-'Z'
  477. U3:
  478.     cp    b
  479.     pop    bc
  480.     jp    nz,CS_NO
  481.     or    a
  482.     jp    z,CS_DONE
  483.     inc    hl
  484.     inc    de
  485.     jp    CS_LOOP
  486. CS_DONE:
  487.     ld    d,b
  488.     ld    e,c
  489. CS_NO:    pop    hl
  490.     ret
  491.  
  492. GET:    ld    a,(USEMEM)    ; B = Location 0..2
  493.     or    a
  494.     jr    z,GREGS
  495.     push    hl
  496.     push    de
  497.     ld    d,0
  498.     ld    e,b
  499.     ld    hl,(MEMLOC)
  500.     add    hl,de
  501.     ld    a,(hl)
  502.     pop    de
  503.     pop    hl
  504.     ret
  505. GREGS:    ld    a,(STARTREG)
  506.     push    bc
  507.     add    b
  508.     ld    b,a
  509.     call    getreg
  510.     pop    bc
  511.     ret
  512.  
  513. PUT:    ld    c,a        ; A = Data, B = location 0..2
  514.     ld    a,(USEMEM)
  515.     or    a
  516.     jr    z,PREGS
  517.     push    hl
  518.     push    de
  519.     ld    d,0
  520.     ld    e,b
  521.     ld    hl,(MEMLOC)
  522.     add    hl,de
  523.     ld    (hl),c
  524.     pop    de
  525.     pop    hl
  526.     ret
  527. PREGS:    ld    a,(STARTREG)
  528.     push    bc
  529.     add    b
  530.     ld    b,a
  531.     ld    a,c
  532.     call    putreg
  533.     pop    bc
  534.     ret
  535.  
  536. DEL_PACK:
  537.     push    af
  538.     push    de
  539.     push    hl
  540. ;    ld    a,'D'
  541. ;    call    cout
  542.     ld    de,BUFFER+2
  543.     ld    h,d
  544.     ld    l,e
  545. DEL_PACK2:
  546.     ld    a,(hl)
  547.     or    a
  548.     jr    z,DEL_PACK23
  549.     cp    ';'
  550.     jp    nz,DEL_PACK21
  551. ;    push    af
  552. ;    push    hl
  553. ;    push    de
  554. ;    ld    a,'*'
  555. ;    call    cout
  556. ;    pop    de
  557. ;    pop    hl
  558. ;    pop    af
  559. DEL_PACK22:
  560.     ld    a,(hl)
  561.     inc    hl
  562.     or    a
  563.     jp    nz,DEL_PACK22
  564.     jp    DEL_PACK2
  565. DEL_PACK23:
  566.     xor    a
  567.     ld    (de),a
  568.     pop    hl
  569.     pop    de
  570.     pop    af
  571.     ret
  572. DEL_PACK21:
  573.     ld    a,(hl)
  574.     ld    (de),a
  575.     inc    hl
  576.     inc    de
  577.     or    a
  578.     jp    nz,DEL_PACK21
  579.     jp    DEL_PACK2
  580.  
  581. JUST_WRITE:
  582.     ld    de,BUFFER+2
  583.     call    THINK2
  584.     jp    WRITE
  585.  
  586. BAD_OPTION:
  587.     push    af
  588.     call    print
  589.     db    13,10,'Bad Option: ',0
  590.     pop    af
  591.     call    cout
  592.     jr    LAST_HELP
  593.  
  594. QPHLFDC:
  595.     call    getquiet
  596.     ret    nz
  597.     call    phlfdc
  598.     ret
  599.  
  600. HELP:    call    print
  601.     db    13,10,9,'Packs EASE history files.',0
  602. LAST_HELP:
  603.     call    print
  604.     db    13,10
  605.     db    'SYNTAX:',13,10
  606.     db    9,'VARPACK [nn] [FILENAME.TYP] [,P]',13,10,10
  607.     db    'Where nn = number of sectors to save.',13,10
  608.     db    'FILENAME.TYP = EASE history file you wish to shorten.',13,10
  609.     db    ',P option specifies removal of duplicate command lines.',0
  610.     ret
  611.  
  612. HEADER:    call    qprint
  613.     db    'VARPACK v. ',vers / 10 + '0','.',vers mod 10 + '0',0
  614.     ret
  615.  
  616. COM:    db    'COM'
  617.  
  618. ENDPOS:    dw    0
  619. SECTORS:
  620.     db    0
  621. LINE:    dw    0
  622. FILE:    dw    0
  623. SAVEDHL:
  624.     dw    0
  625.  
  626. LAST:
  627. INDEX    equ    LAST + 6000    ; TO hop over the lib code.
  628. BUFFER    equ    INDEX + 4000    ; Space for 2000 command lines.
  629. :
  630.     dw    0
  631.  
  632. LAST:
  633. INDEX    equ    LAST + 6000    ; TO hop over the lib code.
  634. BUFFER    equ    INDEX + 4000    ;