home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / crmv1.9t / developer / asm_example / crmdata1.s < prev    next >
Text File  |  1980-01-10  |  16KB  |  751 lines

  1. *********************************
  2. ***  CrMData V1.00            ***
  3. ***  (c) 1993 Thomas Schwarz  ***
  4. *********************************
  5.  
  6.     incdir    dh0:ass/Include/
  7.     include    exec/exec_lib.i
  8.     include    dos/dos_lib.i
  9.     include    dos/dosextens.i
  10.     include    utility/tagitem.i
  11.     include    libraries/CrM.i
  12.     include    libraries/CrM_lib.i
  13.  
  14. *************************************************
  15. CALL    MACRO
  16.     jsr    _LVO\1(a6)
  17.     ENDM
  18. CALLEXEC MACRO
  19.     move.l    4.w,a6
  20.     CALL    \1
  21.     ENDM
  22. CALLCRM    MACRO
  23.     move.l    _CrMBase(pc),a6
  24.     CALL    \1
  25.     ENDM
  26. CALLDOS MACRO
  27.     move.l    _DOSBase(pc),a6
  28.     CALL    \1
  29.     ENDM
  30. *************************************************
  31. CrunchOnly    equ    1
  32. DecrunchOnly    equ    2
  33. ExtraMemLen    equ    100
  34. *************************************************
  35. main:
  36.     lea    CommandLine(pc),a1
  37.     movem.l    d0/a0,(a1)        ;save CLI-Parameters
  38.  
  39. ** Open dos.library: **
  40.     lea    DOSName(pc),a1
  41.     CALLEXEC OldOpenLibrary
  42.     lea    _DOSBase(pc),a0
  43.     move.l    d0,(a0)
  44.     beq.s    .End
  45.  
  46. ** Get output handle: **
  47.     move.l    d0,a6
  48.     CALL    Output
  49.     lea    OutHandle(pc),a0
  50.     move.l    d0,(a0)
  51.     beq.s    .CloseDOS
  52.  
  53. ** Open CrM.library: **
  54.     lea    CrMName(pc),a1
  55.     moveq    #4,d0
  56.     CALLEXEC OpenLibrary
  57.     lea    _CrMBase(pc),a0
  58.     move.l    d0,(a0)
  59.     beq.s    .CloseDOS
  60.  
  61. ** Do all actions: **
  62.     bsr.s    mainloop
  63.  
  64. ** Close CrM.library: **
  65.     move.l    _CrMBase(pc),a1
  66.     CALLEXEC CloseLibrary
  67.  
  68. ** Close dos.library: **
  69. .CloseDOS:
  70.     move.l    _DOSBase(pc),a1
  71.     CALLEXEC CloseLibrary
  72.  
  73. ** Return to the CLI: **
  74. .End:    moveq    #0,d0
  75.     rts
  76. *----------
  77. mainloop:
  78.     lea    InitTxt(pc),a0
  79.     bsr.w    PrintText
  80.  
  81. ** Analyse Commandline:**
  82.     movem.l    CommandLine(pc),d1/a1    ;get Paras
  83.     clr.b    -1(a1,d1.w)        ;replace <cr> by Null
  84.     move.b    (a1),d0
  85.     beq.w    .usage            ;no paras
  86.     cmp.b    #"?",d0
  87.     beq.w    .usage            ;question mark -> print usage
  88.     lea    Algorithm(pc),a2
  89.     move.w    (a2),d1            ;default Algorithm
  90.     cmp.b    #"-",d0
  91.     bne.w    .noopts            ;no option specified
  92.     addq.l    #1,a1
  93.  
  94. ** Optionsloop: processes all options, no spaces between options are allowed!
  95. .optsloop:
  96.     move.b    (a1)+,d0        ;get char
  97.     beq.w    .usage
  98.     cmp.b    #" ",d0
  99.     beq.s    .noopts            ;no more options
  100.  
  101.     cmp.b    #"1",d0
  102.     beq.s    .norm
  103.     cmp.b    #"2",d0
  104.     beq.s    .lzh
  105.     cmp.b    #"c",d0
  106.     beq.s    .crunch
  107.     cmp.b    #"d",d0
  108.     beq.s    .decrunch
  109.     cmp.b    #"f",d0
  110.     beq.s    .flash
  111.     cmp.b    #"s",d0
  112.     beq.s    .sample
  113.     cmp.b    #"y",d0
  114.     beq.s    .encrypt
  115.     lea    UnknownOpt(pc),a0
  116.     move.b    d0,(a0)
  117.     lea    UnknownOptTxt(pc),a0
  118.     bsr.w    PrintText
  119.     bra.s    .optsloop
  120. *-----
  121. .norm:    and.w    #$fff0,d1        ;kill old algorithm
  122.     or.w    #cm_Normal,d1        ;new algo
  123.     bra.s    .optsloop
  124. *-----
  125. .lzh:    and.w    #$fff0,d1        ;kill old algorithm
  126.     or.w    #cm_LZH,d1        ;new algo
  127.     bra.s    .optsloop
  128. *-----
  129. .crunch:
  130.     lea    Operation(pc),a0
  131.     move.b    #CrunchOnly,(a0)
  132.     bra.s    .optsloop
  133. *-----
  134. .decrunch:
  135.     lea    Operation(pc),a0
  136.     move.b    #DecrunchOnly,(a0)
  137.     bra.s    .optsloop
  138. *-----
  139. .flash:
  140.     bset    #cmB_LEDFlash,d1
  141.     bra.s    .optsloop
  142. *-----
  143. .sample:
  144.     bset    #cmB_Sample,d1
  145.     bra.s    .optsloop
  146. *-----
  147. .encrypt:
  148.     bset    #cmB_PW,d1
  149.     bra.s    .optsloop
  150. *-----
  151. .noopts:
  152.     move.w    d1,(a2)            ;new algorithm
  153.     lea    SourceName(pc),a0
  154.     move.l    a1,(a0)
  155.     lea    DestName(pc),a0        ;normally Source- and DestName are
  156.     move.l    a1,(a0)            ;the same...
  157. .search:
  158.     move.b    (a1)+,d0
  159.     beq.s    .samedest        ;no second filename
  160.     cmp.b    #" ",d0
  161.     bne.s    .search
  162.     move.l    a1,(a0)            ;new DestName
  163.     clr.b    -1(a1)            ;replace <Space> by Null
  164. .samedest:
  165.  
  166. ** Open Sourcefile: **
  167.     move.l    SourceName(pc),d1
  168.     move.l    #MODE_OLDFILE,d2
  169.     CALLDOS    Open
  170.     move.l    d0,d5
  171.     beq.w    .srcnotopen
  172.  
  173. ** Read DataHeader (first 14 Bytes in the file): **
  174.     move.l    d5,d1
  175.     lea    DataHdr(pc),a0
  176.     move.l    a0,d2
  177.     moveq    #14,d3
  178.     CALL    Read
  179.  
  180.     lea    DataHdr(pc),a0
  181.     CALLCRM    cmCheckCrunched
  182.     lea    Operation(pc),a0
  183.     tst.l    d0
  184.     beq.s    .loadnormal        ;file is not crunched with CrM
  185.     cmp.b    #CrunchOnly,(a0)
  186.     beq.w    .alreadycrunched    ;can't crunch twice!
  187.     move.b    #DecrunchOnly,(a0)
  188.     bsr.w    CrunchedLoad        ;load crunched file
  189.     bra.s    .crloadcont
  190. .loadnormal:
  191.     cmp.b    #DecrunchOnly,(a0)
  192.     beq.w    .notcrunched
  193.     move.b    #CrunchOnly,(a0)
  194.     bsr.w    NormalLoad        ;load original file
  195. .crloadcont:
  196.     move.l    d0,-(sp)        ;save return code
  197.     move.l    d5,d1
  198.     CALLDOS    Close            ;close Sourcefile
  199.     move.l    (sp)+,d0
  200.     beq.s    .done            ;loading failed!
  201.  
  202.     move.b    Operation(pc),d0
  203.     cmp.b    #DecrunchOnly,d0
  204.     bne.s    .nodecr
  205.     bsr.w    DecrunchIt        ;decrunch data
  206.     beq.s    .done
  207. .nodecr:
  208.     move.b    Operation(pc),d0
  209.     cmp.b    #DecrunchOnly,d0
  210.     bne.s    .nodecrsave
  211.     bsr.w    DecrunchedSave        ;save original data
  212. .nodecrsave:
  213.     move.b    Operation(pc),d0
  214.     cmp.b    #CrunchOnly,d0
  215.     bne.s    .nocr
  216.     bsr.w    CrunchIt        ;crunch data
  217.     beq.s    .done
  218. .nocr:
  219.     move.b    Operation(pc),d0
  220.     cmp.b    #CrunchOnly,d0
  221.     bne.s    .nocrsave
  222.     bsr.w    CrunchedSave        ;save crunched data
  223. .nocrsave:
  224.  
  225. .done:
  226. ** Free cmCrunchStruct: **
  227.     move.l    CrStruct(pc),d0
  228.     beq.s    .nocrstruct        ;no cmCrunchStruct allocated
  229.     move.l    d0,a1
  230.     moveq    #cm_FreeStruct,d0
  231.     CALLCRM    cmProcessCrunchStructA
  232. .nocrstruct:
  233. ** Free Buffer: **
  234.     move.l    MemBase(pc),a1
  235.     move.l    MemLen(pc),d0
  236.     beq.s    .End
  237.     CALLEXEC FreeMem
  238. .End:    rts
  239. *-------
  240. ** Sourcefile open failed! **
  241. .srcnotopen:
  242.     move.l    SourceName(pc),a0
  243.     move.l    a0,-(sp)
  244.     lea    NotOpenTxt(pc),a0
  245.     move.l    sp,a1
  246.     bsr.s    RawPrintText
  247.     addq.l    #4,sp
  248.     rts
  249. *-------
  250. ** DecrunchOnly: File is not crunched **
  251. .notcrunched:
  252.     lea    NotCrunchedTxt(pc),a0
  253. .acrcont:
  254.     move.l    SourceName(pc),-(sp)
  255.     move.l    sp,a1
  256.     bsr.s    RawPrintText
  257.     addq.l    #4,sp
  258.     moveq    #0,d0
  259.     bra.w    .crloadcont
  260. *-----
  261. ** CrunchOnly: File is already crunched **
  262. .alreadycrunched:
  263.     lea    AlreadyCrTxt(pc),a0
  264.     bra.s    .acrcont
  265. *-------
  266. ** Print Usage: **
  267. .usage:    lea    UsageTxt(pc),a0
  268. ;    bra.s    PrintText
  269. ********************************
  270. ** Print some text to the CLI **
  271. PrintText:    ** a0:Text
  272.     movem.l    d0-d3/a0-a1/a6,-(sp)
  273.     move.l    a0,d2
  274.     move.l    OutHandle(pc),d1
  275.     moveq    #-1,d3
  276. .count:    addq.l    #1,d3
  277.     tst.b    (a0)+
  278.     bne.s    .count
  279.     CALLDOS    Write
  280.     movem.l    (sp)+,d0-d3/a0-a1/a6
  281.     rts
  282. *----------
  283. ** Print some text to the CLI with formatting using RawDoFmt(): **
  284. RawPrintText:    ** a0:Text a1:Args
  285.     movem.l    d0-d2/a0-a3/a6,-(sp)
  286.     lea    .stuffchar(pc),a2
  287.     lea    InitTxt(pc),a3
  288.     CALLEXEC RawDoFmt
  289.     lea    InitTxt(pc),a0
  290.     bsr.s    PrintText        ;print the converted text
  291.     movem.l    (sp)+,d0-d2/a0-a3/a6
  292.     rts
  293. *-----
  294. .stuffchar:
  295.     move.b    d0,(a3)+        ;put data to output string
  296.     rts
  297. *****************************
  298. ** Load a file to crunch it. A cmCrunchStruct and the Buffer for the file
  299. ** will be allocated.
  300. NormalLoad:
  301. ** Get Lock on the Sourcefile: **
  302.     move.l    SourceName(pc),d1
  303.     moveq    #ACCESS_READ,d2
  304.     CALLDOS    Lock
  305.     move.l    d0,d4
  306.     beq.w    .notopen        ;locking failed!
  307.  
  308. ** Examine Sourcefile: **
  309.     move.l    d4,d1
  310.     lea    InitTxt(pc),a0        ;InitTxt serves as buffer for the fib
  311.     move.l    a0,d2
  312.     CALL    Examine
  313.     move.l    d0,-(sp)        ;save result on the stack
  314.  
  315. ** UnLock Sourcefile: **
  316.     move.l    d4,d1
  317.     CALL    UnLock
  318.     move.l    (sp)+,d0
  319.     beq.w    .notopen        ;examining failed!
  320.     lea    InitTxt(pc),a0
  321.     move.l    fib_Size(a0),d7        ;Size of Sourcefile
  322.  
  323. ** Allocate Buffer (Len=Sourcefilelength+ExtraMemLen): **
  324.     moveq    #ExtraMemLen,d0
  325.     add.l    d7,d0
  326.     lea    MemLen(pc),a0
  327.     move.l    d0,(a0)
  328.     moveq    #0,d1
  329.     CALLEXEC AllocMem
  330.     lea    MemBase(pc),a0
  331.     move.l    d0,(a0)
  332.     beq.w    .nomem            ;not enough memory
  333.  
  334. ** Allocate a cmCrunchStruct: **
  335.     clr.l    -(sp)            ;TAG_DONE
  336.     move.w    Algorithm(pc),-(sp)
  337.     clr.w    -(sp)
  338.     move.l    #CMCS_Algo,-(sp)
  339.     move.l    sp,a0
  340.     moveq    #cm_AllocStruct,d0
  341.     CALLCRM    cmProcessCrunchStructA
  342.     lea    12(sp),sp
  343.     lea    CrStruct(pc),a0
  344.     move.l    d0,(a0)
  345.     beq.s    .nomem            ;allocating failed
  346.  
  347.     move.l    d7,-(sp)
  348.     move.l    SourceName(pc),a0
  349.     move.l    a0,-(sp)
  350.     lea    LoadingTxt(pc),a0
  351.     move.l    sp,a1
  352.     bsr.w    RawPrintText
  353.     addq.l    #8,sp
  354.  
  355. ** Copy DataHeader to Buffer **
  356.     move.l    MemBase(pc),a1
  357.     add.w    #ExtraMemLen,a1
  358.     lea    DataHdr(pc),a0
  359.     move.l    (a0)+,(a1)+
  360.     move.l    (a0)+,(a1)+
  361.     move.l    (a0)+,(a1)+
  362.     move.w    (a0)+,(a1)+
  363.  
  364. ** Load rest of sourcefile **
  365.     move.l    d5,d1
  366.     move.l    a1,d2
  367.     move.l    d7,d3
  368.     subq.l    #8,d3
  369.     subq.l    #6,d3
  370.     CALLDOS    Read
  371.     cmp.l    d0,d3
  372.     bne.s    .readerr        ;readerror
  373.  
  374.     lea    OrigLen(pc),a0
  375.     move.l    d7,(a0)            ;Originallen (Lenght of Sourcefile)
  376.     lea    ReturnTxt(pc),a0
  377.     bsr.w    PrintText
  378.  
  379.     moveq    #1,d0            ;return: TRUE
  380.     rts
  381. *-----
  382. ** Opening failed: **
  383. .notopen:
  384.     move.l    SourceName(pc),a0
  385.     move.l    a0,-(sp)
  386.     lea    NotOpenTxt(pc),a0
  387.     move.l    sp,a1
  388.     bsr.w    RawPrintText
  389.     addq.l    #4,sp
  390. .Exit:    moveq    #0,d0            ;return: FALSE
  391.     rts
  392. *-----
  393. ** not enough memory available: **
  394. .nomem:    lea    MemLen(pc),a0
  395.     clr.l    (a0)
  396.     lea    NoMemTxt(pc),a0
  397. .prtx:    bsr.w    PrintText
  398.     bra.s    .Exit
  399.  
  400. ** readerror: **
  401. .readerr:
  402.     lea    ReadErrTxt(pc),a0
  403.     bra.s    .prtx
  404. *------------
  405. ** Crunch Data: **
  406. CrunchIt:
  407.     lea    CrunchingTxt(pc),a0
  408.     bsr.w    PrintText
  409.  
  410.     move.l    CrStruct(pc),a0
  411.     move.l    MemBase(pc),a1
  412.     move.l    a1,cmcr_Dest(a0)
  413.     moveq    #ExtraMemLen,d0
  414.     add.l    d0,a1
  415.     move.l    a1,cmcr_Src(a0)
  416.     move.l    OrigLen(pc),d1
  417.     move.l    d1,cmcr_SrcLen(a0)
  418.     add.l    d0,d1
  419.     move.l    d1,cmcr_DestLen(a0)
  420.     lea    DataHdr(pc),a1
  421.     move.l    a1,cmcr_DataHdr(a0)
  422.     clr.l    cmcr_DisplayHook(a0)
  423.     move.w    #$7ffe,cmcr_DisplayStep(a0)
  424.     CALLCRM    cmCrunchData
  425.  
  426.     lea    CrLen(pc),a0
  427.     move.l    d0,(a0)
  428.     beq.s    .error            ;error while crunching
  429.  
  430. ** calculate gain in percent: you have to do this complicated rotating
  431. ** because there is no longword division available on a standard 68000
  432. ** this routine is not very cool, it will produce shit when the gain is
  433. ** negative.
  434.     move.l    OrigLen(pc),d1
  435.     move.l    d1,d2
  436.     sub.l    d0,d2            ;gain
  437.     move.l    d1,d3
  438. .rotloop:
  439.     tst.l    d2
  440.     bmi.s    .rotend
  441.     tst.l    d3
  442.     bmi.s    .rotend
  443.     add.l    d2,d2
  444.     add.l    d3,d3
  445.     bra.s    .rotloop
  446. .rotend:
  447.     lsr.l    #1,d2
  448.     lsr.l    #1,d3
  449.     clr.w    d2
  450.     clr.w    d3
  451.     swap    d2
  452.     swap    d3
  453.     mulu    #100,d2
  454.     divu    d3,d2
  455.     move.w    d2,-(sp)
  456.     move.l    d0,-(sp)
  457.     move.l    d1,-(sp)
  458.     move.l    sp,a1
  459.     lea    CrunchedTxt(pc),a0
  460.     bsr.w    RawPrintText
  461.     lea    10(sp),sp
  462.     moveq    #1,d0            ;return: TRUE
  463.     rts
  464.  
  465. ** error while crunchung: **
  466. .error:    move.l    CrStruct(pc),a0
  467.     move.b    cmcr_QuitFlag(a0),d0
  468.     lea    AbortTxt(pc),a0
  469.     cmp.b    #"a",d0
  470.     beq.s    .errend            ;crunching was aborted (not possible yet)
  471.     lea    NotCrTxt(pc),a0
  472.     cmp.b    #"n",d0
  473.     beq.s    .errend            ;data is not crunchable (or already
  474.                     ;crunched with another packer)
  475.     lea    UnknownErrTxt(pc),a0
  476. .errend:
  477.     bsr.w    PrintText
  478.     moveq    #0,d0            ;return: FALSE
  479.     rts
  480. *----------
  481. ** Save crunched data: **
  482. CrunchedSave:
  483. ** Open Destination file: **
  484.     move.l    DestName(pc),d1
  485.     move.l    #MODE_NEWFILE,d2
  486.     CALLDOS    Open
  487.     move.l    d0,d5
  488.     beq.s    .notopen        ;open failed
  489.  
  490.     moveq    #14,d0
  491.     add.l    CrLen(pc),d0
  492.     move.l    d0,-(sp)
  493.     move.l    DestName(pc),-(sp)
  494.     move.l    sp,a1
  495.     lea    SavingTxt(pc),a0
  496.     bsr.w    RawPrintText
  497.     addq.l    #8,sp
  498.  
  499. ** Write DataHeader: **
  500.     move.l    d5,d1
  501.     lea    DataHdr(pc),a0
  502.     move.l    a0,d2
  503.     moveq    #14,d3
  504.     CALL    Write            ;DataHeader
  505.     tst.l    d0
  506.     bmi.s    .error            ;writeerror
  507.  
  508. ** Write crunched Data: **
  509.     move.l    d5,d1
  510.     move.l    MemBase(pc),d2
  511.     move.l    CrLen(pc),d3
  512.     CALL    Write            ;Data
  513.     tst.l    d0
  514.     bmi.s    .error            ;writeerror
  515.  
  516. ** Close Destination file: **
  517.     move.l    d5,d1
  518.     CALL    Close
  519.  
  520. ** Generate Comment: **
  521.     lea    Comment(pc),a0
  522.     move.l    OrigLen(pc),-(sp)
  523.     move.l    sp,a1
  524.     lea    .stuffchar(pc),a2
  525.     lea    InitTxt(pc),a3        ;again InitTxt serves as a temporary
  526.                     ;buffer
  527.     CALLEXEC RawDoFmt
  528.     addq.l    #4,sp
  529.  
  530. ** Set Comment (for RTDD): **
  531.     move.l    DestName(pc),d1
  532.     lea    InitTxt(pc),a0
  533.     move.l    a0,d2
  534.     CALLDOS    SetComment
  535.  
  536.     lea    ReturnTxt(pc),a0
  537.     bra.w    PrintText        ;print text and return (no returncode)
  538. *-----
  539. ** Destfile open failed: **
  540. .notopen:
  541.     move.l    DestName(pc),-(sp)
  542.     move.l    sp,a1
  543.     lea    NotOpenTxt(pc),a0
  544.     bsr.w    RawPrintText
  545.     addq.l    #4,sp
  546.     rts
  547. *-----
  548. ** writeerror: **
  549. .error:    lea    ErrorWriteTxt(pc),a0
  550.     bsr.w    PrintText
  551.  
  552. ** close destfile **
  553.     move.l    d5,d1
  554.     CALL    Close
  555.  
  556. ** delete destfile:
  557.     move.l    DestName(pc),d1
  558.     CALL    DeleteFile
  559.     rts
  560. *-----
  561. .stuffchar:
  562.     move.b    d0,(a3)+        ;put data to output string
  563.     rts
  564. *****************************
  565. ** Load data to decrunch (Buffer will be allocated): **
  566. CrunchedLoad:
  567. ** Copy contents of DataHeader to internal Variables: **
  568.     lea    DataHdr(pc),a0
  569.     lea    OrigLen(pc),a1
  570.     move.l    dh_OriginalLen(a0),(a1)
  571.     lea    CrLen(pc),a1
  572.     move.l    dh_CrunchedLen(a0),(a1)
  573.  
  574. ** Allocate Buffer (len=OrigLen+MinSecDist): **
  575.     moveq    #0,d0
  576.     move.w    dh_MinSecDist(a0),d0
  577.     add.l    dh_OriginalLen(a0),d0
  578.     lea    MemLen(pc),a0
  579.     move.l    d0,(a0)
  580.     moveq    #0,d1
  581.     CALLEXEC AllocMem
  582.     lea    MemBase(pc),a0
  583.     move.l    d0,(a0)
  584.     beq.w    .nomem            ;not enough memory
  585.  
  586.     moveq    #14,d0
  587.     add.l    CrLen(pc),d0
  588.     move.l    d0,-(sp)
  589.     move.l    SourceName(pc),-(sp)
  590.     move.l    sp,a1
  591.     lea    LoadingTxt(pc),a0
  592.     bsr.w    RawPrintText
  593.     addq.l    #8,sp
  594.  
  595. ** Read crunched Data: **
  596.     move.l    d5,d1
  597.     move.l    MemBase(pc),d2
  598.     move.l    CrLen(pc),d3
  599.     CALLDOS    Read
  600.     cmp.l    d0,d3
  601.     bne.s    .readerr        ;readerror
  602.  
  603.     moveq    #1,d0            ;return: TRUE
  604.     lea    ReturnTxt(pc),a0
  605.     bra.s    .prtx
  606. *-----
  607. .readerr:
  608.     moveq    #0,d0            ;return: FALSE
  609.     lea    ReadErrTxt(pc),a0
  610.     bra.s    .prtx
  611. *-----
  612. .nomem:    lea    MemLen(pc),a0
  613.     clr.l    (a0)
  614.     moveq    #0,d0            ;return: FALSE
  615.     lea    NoMemTxt(pc),a0
  616. .prtx:    bra.w    PrintText
  617. *------------
  618. ** Decrunch Data: **
  619. DecrunchIt:
  620.     move.l    OrigLen(pc),-(sp)
  621.     move.l    CrLen(pc),-(sp)
  622.     move.l    sp,a1
  623.     lea    DecrunchingTxt(pc),a0
  624.     bsr.w    RawPrintText
  625.     addq.l    #8,sp
  626.  
  627.     lea    DataHdr(pc),a2
  628.     move.l    MemBase(pc),a0
  629.     move.w    dh_MinSecDist(a2),d0
  630.     lea    0(a0,d0.w),a1
  631.     CALLCRM    cmDecrunch
  632.     tst.l    d0
  633.     beq.s    .error
  634.  
  635.     lea    ReturnTxt(pc),a0
  636.     bsr.w    PrintText
  637.     moveq    #1,d0            ;return: TRUE
  638.     rts
  639. *-----
  640. ** error while decrunching: **
  641. .error:
  642.     lea    DecrErrorTxt(pc),a0
  643.     bsr.w    PrintText
  644.     moveq    #0,d0            ;return: FALSE
  645.     rts
  646. *----------
  647. ** Save original (decrunched) file: **
  648. DecrunchedSave:
  649. ** Open Destination file: **
  650.     move.l    DestName(pc),d1
  651.     move.l    #MODE_NEWFILE,d2
  652.     CALLDOS    Open
  653.     move.l    d0,d5
  654.     beq.s    .notopen        ;openfail
  655.  
  656.     move.l    OrigLen(pc),-(sp)
  657.     move.l    DestName(pc),-(sp)
  658.     move.l    sp,a1
  659.     lea    SavingTxt(pc),a0
  660.     bsr.w    RawPrintText
  661.     addq.l    #8,sp
  662.  
  663. ** Write Data: **
  664.     move.l    d5,d1
  665.     lea    DataHdr(pc),a0
  666.     moveq    #0,d2
  667.     move.w    dh_MinSecDist(a0),d2
  668.     add.l    MemBase(pc),d2
  669.     move.l    OrigLen(pc),d3
  670.     CALL    Write            ;Data
  671.     tst.l    d0
  672.     bmi.s    .error            ;writeerror
  673.  
  674. ** Close File: **
  675.     move.l    d5,d1
  676.     CALL    Close
  677.  
  678.     lea    ReturnTxt(pc),a0
  679.     bra.w    PrintText        ;print text and return (no returncode)
  680. *-----
  681. ** destfile could not be opened: **
  682. .notopen:
  683.     move.l    DestName(pc),-(sp)
  684.     move.l    sp,a1
  685.     lea    NotOpenTxt(pc),a0
  686.     bsr.w    RawPrintText
  687.     addq.l    #4,sp
  688.     rts
  689. *-----
  690. ** writeerror: **
  691. .error:    lea    ErrorWriteTxt(pc),a0
  692.     bsr.w    PrintText
  693.  
  694. ** Close destfile: **
  695.     move.l    d5,d1
  696.     CALL    Close
  697.  
  698. ** Delete destfile: **
  699.     move.l    DestName(pc),d1
  700.     CALL    DeleteFile
  701.     rts
  702. *************************************************
  703. _DOSBase:    dc.l    0
  704. _CrMBase:    dc.l    0
  705. OutHandle:    dc.l    0        ;Handle to print text in the CLI
  706. MemBase:    dc.l    0        ;Start of Buffer
  707. MemLen:        dc.l    0        ;Length of Buffer
  708. OrigLen:    dc.l    0        ;Original Length of Data
  709. CrLen:        dc.l    0        ;Crunched Length of Data
  710. CrStruct:    dc.l    0        ;struct cmCrunchStruct *
  711. CommandLine:    dc.l    0,0        ;CLI-Parameters (text *,len)
  712. SourceName:    dc.l    0        ;Sourcefilename *
  713. DestName:    dc.l    0        ;Destinationfilename *
  714. DataHdr:    ds.b    14        ;struct DataHeader
  715. Algorithm:    dc.w    cm_LZH!cmF_Overlay    ;Algorithm for cmcs_Algo Tag
  716. Operation:    dc.b    0        ;type of Operation (CrunchOnly,
  717.                     ;DecrunchOnly or NULL for auto)
  718. DOSName:    dc.b    "dos.library",0
  719. CrMName:    CRMNAME
  720.         cnop    0,4
  721. InitTxt:    dc.b    27,"[33;1mCrMData ",27,"[0;33mV1.00 ",27,"[0m--- "
  722.         dc.b    27,"[32m(c) 1993 Thomas Schwarz",27,"[0m",10,10,0
  723.         dc.b    "$VER: CrMData 1.00",0
  724. UsageTxt:    dc.b    "Usage: CrMData [-12cdfsy] <sourcefile> [<destfile>]",10
  725.         dc.b    "-1 : use CrM-Normal algorithm",10
  726.         dc.b    "-2 : use LZ-Huffman algorithm",10
  727.         dc.b    "-c : crunch only",10
  728.         dc.b    "-d : decrunch only",10
  729.         dc.b    "-f : enable Power-LED flashing",10
  730.         dc.b    "-s : use Sample-Mode",10
  731.         dc.b    "-y : enable password encryption",10,0
  732. UnknownOptTxt:    dc.b    "Unknown option: -"
  733. UnknownOpt:    dc.b    " !"
  734. ReturnTxt:    dc.b    10,0
  735. NotOpenTxt:    dc.b    "Could not open `%s'!",10,0
  736. LoadingTxt:    dc.b    "Loading `%s' (%ld bytes)...",0
  737. NoMemTxt:    dc.b    "Not enough memory available!",10,0
  738. ReadErrTxt:    dc.b    "Read Error!",10,0
  739. NotCrunchedTxt:    dc.b    "Can't decrunch `%s': File is not crunched!",10,0
  740. AlreadyCrTxt:    dc.b    "Can't crunch `%s': File is already crunched!",10,0
  741. CrunchingTxt:    dc.b    "Crunching...",0
  742. CrunchedTxt:    dc.b    " %ld -> %ld (%d%% gain)",10,0
  743. AbortTxt:    dc.b    "Crunching aborted!",10,0
  744. NotCrTxt:    dc.b    "File not crunchable!",10,0
  745. UnknownErrTxt:    dc.b    "Strange error occurred while crunching!",10,0
  746. SavingTxt:    dc.b    "Saving `%s' (%ld bytes)...",0
  747. ErrorWriteTxt:    dc.b    " Error while writing!",10,0
  748. Comment:    dc.b    "CrM!%08lx",0
  749. DecrunchingTxt:    dc.b    "Decrunching (%ld -> %ld)...",0
  750. DecrErrorTxt:    dc.b    " Error while decrunching!",10,0
  751.