include "tios.h" include "flib.h" include "complib.h" include textview.h xdef _main xdef _comment xdef _tibasic ;--------------------------------------------------------------------- ; virere type si possible pb de taille = 7 ! virer filelib _main: ; FORMAT D'UN TXT COMPRESSE : ;$ SI ZE TYPE 00 ?? ?? $?? ?? ?? ?? ?? DD ; Trigger an "Internal error" if we can't find ; the "x" parameter in our local folder pea param_name(pc) move.w tios::DefTempHandle,-(a7) jsr tios::FindSymEntry add.l #6,a7 move.l a0,d0 bne no_error move.w #1020,-(a7) jsr tios::ERD_dialog lea 2(a7),a7 rts no_error: move.w 10(a0),d0 ; Trigger a "Data type" error if the "x" ; parameter is not a string tios::DEREF d0,a0 move.w (a0),d0 lea 1(a0,d0.w),a0 cmp.b #$2D,(a0) beq good_data_type move.w #130,-(a7) jsr tios::ERD_dialog lea 2(a7),a7 rts good_data_type: sub.l #1,a0 find_string_loop: tst.b -(a0) bne find_string_loop add.l #1,a0 move.w #7,d0 lea filename(PC),a1 lea folder(PC),a2 \Clr_name: clr.b (a2)+ clr.b (a1)+ dbra d0,\Clr_name lea folder(PC),a1 move.w #7,d0 Fold_Loop: move.b (a0)+,(a1)+ cmp.b #$5C,(a0) beq got_fold dbra d0,Fold_Loop bra Invalid_pathname got_fold: add.l #1,a0 lea filename(PC),a1 move.w #7,d0 Name_Loop: move.b (a0)+,(a1)+ cmp.b #$00,(a0) beq got_name dbra d0,Name_Loop bra Invalid_pathname got_name: pea folder(PC) move.w FOLDER_LIST_HANDLE,-(a7) jsr tios::FindSymEntry ;search for folder entry lea 6(a7),a7 cmp.l #0,a0 ;if d0=0000 no var found beq Invalid_pathname move.w 10(a0),d0 move.w d0,folder_h pea filename(PC) move.w d0,-(a7) ;d0:folder handle jsr tios::FindSymEntry ;search for textname entry lea 6(a7),a7 cmp.l #0,a0 ;if d0=0000 no var found beq Invalid_pathname move.l a0,file_a move.w 10(a0),d0 move.w d0,file_h tios::DEREF d0,a4 move.w (a4),d0 move.w d0,Lenght subq.w #1,Lenght move.b 1(a4,d0.w),type cmp.w #15,d0 bls too_small cmp.b #$DD,1(a4,d0.w) bne compress tst.b 3(a4) bne compress move.l a4,a0 adda.l #4,a0 jsr complib::eval_emem add.l #3,d0 move.w d0,d7 move.l d0,-(a7) jsr tios::HeapAlloc lea 4(a7),a7 tst.l d0 beq mem move.w d0,arch_h tios::DEREF d0,a1 move.l a1,arch_a jsr complib::check_emem tst.l d0 bne Enough_mem_for_extraction move.w arch_h,-(a7) jsr tios::HeapFree lea 2(a7),a7 bra mem Enough_mem_for_extraction: movem.l a0-a6/d0-d7,-(a7) bsr Disp_menu WriteStr #64,#32,#4,Title_e SetFont #1 WriteStr #75,#51,#4,name WriteStr #75,#61,#4,fold movem.l (a7)+,a0-a6/d0-d7 subq.w #2,d7 move.b 2(a4),1(a1,d7.w) move.w d7,(a1)+ move.l a4,a0 adda.l #4,a0 jsr complib::extract move.l file_a,a0 move.w arch_h,10(a0) move.w file_h,-(a7) jsr tios::HeapFree lea 2(a7),a7 jsr flib::idle_loop rts compress: move.l a4,a0 adda.l #2,a0 move.w Lenght,d0 jsr complib::check_cmem tst.l d0 beq mem move.w Lenght,d0 move.l a4,a0 adda.l #2,a0 jsr complib::eval_cmem add.w #5,d0 move.l d0,d7 cmp.w Lenght,d7 bls Good_compressed too_small: bsr Disp_menu WriteStr #52,#32,#4,Title_nc SetFont #1 WriteStr #52,#51,#4,Sorry WriteStr #52,#61,#4,Sorry2 jsr flib::idle_loop rts Good_compressed: move.l d0,-(a7) jsr tios::HeapAlloc lea 4(a7),a7 tst.l d0 beq mem move.w d0,arch_h tios::DEREF d0,a1 move.l a1,arch_a jsr complib::check_cmem tst.l d0 bne Enough_mem_for_compression move.w arch_h,-(a7) jsr tios::HeapFree lea 2(a7),a7 bra mem Enough_mem_for_compression: subq.w #2,d7 movem.l a0-a6/d0-d7,-(a7) clr.l d0 move.w Lenght,d6 addq.w #3,d6 move.w d6,d0 lea C_size(PC),a0 move.l #5,d1 bsr ConvStr adda.l #5,a0 move.b #$20,(a0)+ move.b #26,(a0)+ move.b #$20,(a0)+ move.w d7,d0 addq.w #2,d0 move.l #5,d1 bsr ConvStr clr.l d5 move.w d7,d5 mulu #100,d5 divu d6,d5 lea Ratio(PC),a0 adda.l #8,a0 move.l #2,d1 move.w d5,d0 bsr ConvStr bsr Disp_menu WriteStr #64,#32,#4,Title_c SetFont #1 WriteStr #79,#51,#4,C_size WriteStr #83,#61,#4,Ratio movem.l (a7)+,a0-a6/d0-d7 move.b #$DD,1(a1,d7.w) move.w d7,(a1)+ move.b type,(a1)+ move.b #$00,(a1)+ adda.l #2,a4 move.l a4,a0 move.w Lenght,d0 jsr complib::compress jsr flib::idle_loop move.l file_a,a0 move.w arch_h,10(a0) move.w file_h,-(a7) jsr tios::HeapFree lea 2(a7),a7 rts mem: move.w #670,-(a7) jsr tios::ERD_dialog lea 2(a7),a7 rts Invalid_pathname: move.w #570,-(a7) jsr tios::ERD_dialog lea 2(a7),a7 rts Disp_menu: move.w #75,-(a7) move.w #190,-(a7) move.w #30,-(a7) move.w #50,-(a7) jsr flib::erase_rect jsr flib::frame_rect add.l #4,a7 move.w #43,-(a7) move.w #50,-(a7) jsr flib::erase_rect jsr flib::frame_rect add.l #8,a7 SetFont #2 rts ; -------------------------------- ; ; Converts a number to a string ; ; IN: d0 - The number ; d1 - Number of digits ; a0 - Pointer to string ; OUT: *a0 - The string (null-terminated) ; ; -------------------------------- ConvStr: adda.l d1,a0 subq.b #1,d1 RepConv: divu #10,d0 move.l d0,d2 lsr.l #8,d2 lsr.l #8,d2 add.b #48,d2 move.b d2,-(a0) and.l #$FFFF,d0 dbra d1,RepConv rts ;SUBROUTINES---------------------------------------------------------- ;DATAS---------------------------------------------------------------- _comment: dc.b "Compressor / Extractor",0 Lenght dc.w 0 arch_h dc.w 0 arch_a dc.l 0 param_name dc.b "x",0 type dc.b 0 name dc.b "Name : " filename ds.b 9 fold dc.b "Folder : " folder ds.b 9 folder_h dc.w 0 file_a dc.l 0 file_h dc.w 0 archname dc.b 64,"file",0,0,0,0 Title_e dc.b "Extracting...",0 Title_c dc.b "Compressing...",0 Title_nc dc.b "Not Compressing!",0 Ratio dc.b "Ratio : %",0 C_size ds.b 14 Sorry dc.b "Compressed file bigger",0 Sorry2 dc.b "than original file.",0 ;***************************************************** section _tibasic dc.b $E9 dc.b $12,$E4 ; EndPrgm dc.b $00,$E8 ; : dc.b $19,$E4 ; Prgm dc.b $E5,$08 ; (x) dc.b $00,$00,$40,$DC _tibasic ;***************************************************** end