flat assembler
Message board for the users of flat assembler.

Index > Heap > Tiny compression program 4.0 in BASIC.

Author
Thread Post new topic Reply to topic
mbr_tsr



Joined: 03 Apr 2011
Posts: 4903
mbr_tsr
Code:

rem ============================================
rem Tiny compression program by MBR_TSR 
rem Version 4.0, Supports Huge Binary Files.
rem Squishes repeating characters. Nice!
rem Compile using: asicc squeeze.asi e
rem ============================================

KMD$ = COMMAND$
KMD$ = LTRIM$(KMD$)
KMD$ = RTRIM$(KMD$)
KMD$ = LCASE$(KMD$)

if KMD$ = "" then
ErrorJob:
color 15,0
print "=================================================="
color 14,0
print "Squeeze Version 4.0 Simple Compression"
print "squeeze large binary files into a tiny dot"
print "usage: squeeze filename.ext /c (compress)"
print "usage: squeeze filename.dot /d (decompress)"
color 15,0
print "=================================================="
color 7,0
beep
END
endif
color 14,0
FileName$ = ""
for J = 1 to 80
CH$ = mid$(KMD$,J,1)
if CH$ = "." then 
OutFile$ = FileName$
Ext = 1
endif
if CH$ = " " then DoneGettingFileName:
FileName$ = FileName$ + CH$
if Ext = 1 then
if CH$ = "." then Dot:
EXT0$ = EXT0$ + CH$
Dot:
endif
next J
DoneGettingFileName:
if OutFile$ = "" then
print "error: Invalid FileName."
END
endif
OutFile2$ = OutFile$ + ".DOT"

Test1 = instr(KMD$,"/c")
Test2 = instr(KMD$,"/d")
if Test1 > 0 then Compress:
if Test2 > 0 then DeCompress:
goto ErrorJob:

Compress:
print "COMPRESING..."
Repeat& = 0&
OPEN "I",1,FileName$
OPEN "O",2,OutFile2$
print #2, EXT0$ NONULL

HugeFile1:
FOR Scan& = 0& to 64000&
if UsedByte1 = 1 then
Byte1$ = Byte2$
UsedByte1 = 0
goto FindAnother:
endif
input #1, Byte1$ BYTE
if ERROR > 0 then EOF1:
FindAnother:
input #1, Byte2$ BYTE
if ERROR > 0 then 
ExtraByte = 1
goto EOF1:
endif
if Byte1$ = Byte2$ then
Repeat& = Repeat& + 1&
if Repeat& = 64000& then TooManyRepeats:
goto FindAnother:
endif
TooManyRepeats:

if Repeat& > 0& then
if Repeat& < 8& then
For OnlyAfewSoSkip& = 0& to Repeat&
gosub Print1Byte:
next OnlyAfewSoSkip&
if Byte2$ = "" then
print #2, Byte2$
else
print #2, Byte2$ NONULL
endif
UsedByte1 = 0
goto SkipWave:
endif
endif

if Repeat& > 7& then
print #2, "/$" NONULL
print #2, Repeat&
gosub Print1Byte:
goto SkipWave:
endif

gosub Print1Byte:
SkipWave:
Repeat& = 0&

NEXT Scan&
goto HugeFile1:

EOF1:
if ExtraByte = 1 then
gosub Print1Byte:
endif

print "Created file ";
print OutFile2$

CLOSE 1
CLOSE 2
print "Done!"
END

DeCompress:
print "DECOMPRESING..."
Test = instr(FileName$, ".dot")
if Test = 0 then
print "error: FileName must be a .DOT file"
END
endif

OPEN "I",1,FileName$
INPUT #1, EXT1$ BYTE
INPUT #1, EXT2$ BYTE
INPUT #1, EXT3$ BYTE
EXT$ = "." + EXT1$
EXT$ = EXT$ + EXT2$
EXT$ = EXT$ + EXT3$
OutFile2$ = OutFile$ + EXT$
OPEN "O",2,OutFile2$

HugeFile2:
FOR Scan& = 0& to 64000&
input #1, Byte1$ BYTE
if ERROR > 0 then EOF2:

if Byte1$ = "/" then
input #1, Byte2$ BYTE

if Byte2$ = "$" then
 input #1, Times&
 input #1, RepByte$ BYTE
 FOR Rep& = 0 to Times&
 if RepByte$ = "" then
  print #2, RepByte$
  else
  print #2, RepByte$ NONULL
 endif
 next Rep&
goto AfterRepeat:
endif
gosub PrintBytes:
goto AfterRepeat:
endif

gosub Print1Byte:

AfterRepeat:
next Scan&
goto HugeFile2:

EOF2:
print "Created File ";
print OutFile2$
CLOSE 1
CLOSE 2
print "Done!"
END

PrintBytes:
if Byte1$ = "" then
print #2, Byte1$
else
print #2, Byte1$ NONULL
endif
if Byte2$ = "" then
print #2, Byte2$
else
print #2, Byte2$ NONULL
endif
return

Print1Byte:
if Byte1$ = "" then
print #2, Byte1$
else
print #2, Byte1$ NONULL
endif
UsedByte1 = 1
return

    
Post 27 May 2013, 17:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.