[net.micro.cpm] Basic unsqueezer

NBaheti.ES@XEROX.ARPA (04/23/85)

----------------------------------------------------------------
Received: from Flora.ms by ArpaGateway.ms ; 09 APR 85 16:21:16 PST
From: NBaheti.es @ PARC-MAXC
Date:  9-Apr-85 16:22:00 PST
Subject: Basic unsqueezer
To: Keith Peterson <KPETERSON@SIMTEL20.ARPA>
cc: NBaheti.es@Xerox

Keith--

I picked this up on a local BBS with NO DOCUMENTATION, but I still
think it may be of use to the users of SIMTEL20's repository.

--Arun [NBaheti.es@Xerox]

-------------------------

10	'***************************************************************
20	' PCUSQNEW.BAS - Version 1.0 - 3/17/85
30	'    by Kim Levitt - 213-653-6398 (MBBS, 300/1200 baud)
40	'    Update of original 11/25/84 version of USQ.BAS by
50	'    Dave (it can't be done) Rand - 805-493-1987 (voice)
60	'
65	'	This WILL run on an IBM-PC under interpreter BASICA,
66	'	but VERY SLOWLY.. When I compiled it under BASCOM
67	'	and LINKed it with BASCOM.LIB on the PC-AT, it ran
68	'	fast enough to be useable..
69	' 
70	'**************************************************************
80	' INITIALIZATION
90	'
100	DEFINT A-Z : GETC$=" " : GETW$="  " ' for speed!
110	DIM USQ.TABLE%(1,257), BUF$(128), OUTF$(127)
120	FILE$="" : SF%=0 : FO%=-1 : CSL%=0 : CSH%=0 : OD$=""
340	'***************************************************************
350	' COMMON CODE
360	'
370	' Common code, accessed with blank command line or begining of
380	' non-CP/M versions.. (Interactive version)
390	'
400	SF%=-1
410	PRINT : PRINT "PCUSQNEW.BAS -- A SLOW But Sure BASIC Unsqueezer"
420	PRINT
430	PRINT "(Enter name of file to 'unsqueeze'. Use upper case ONLY.)"
440	INPUT "Name of squeezed file";FILE$ : ID$=""
450	PRINT : PRINT "(Enter 'O' for console output only)"
460	INPUT "Console output? (Y/N/O)";CO$
470	IF CO$="O" OR CO$="o" THEN FO%=0 : GOTO 520
480	IF CO$="N" OR CO$="n" THEN SF%=0
490	PRINT : PRINT "(Enter return only for current disk)"
500	INPUT "Output drive";OD$
510	IF LEN(OD$)=1 THEN OD$=OD$+":"
520	PRINT : PRINT "Unsqueezing ";ID$;FILE$;" --> ";
530	OPEN "R", 1, ID$+FILE$, 128
540	GET #1, 1
550	IF EOF(1) THEN PRINT "[File not found]" : CLOSE #1 :
	   KILL ID$+FILE$ : SYSTEM
560	FOR X=0 TO 127 : FIELD 1, X AS D$, 1 AS BUF$(X) : NEXT X
570	GOSUB 900
580	IF USQ.ERR%<>0 THEN 
	   PRINT "[Error in header, or not squeezed]" : SYSTEM
590	PRINT "(";OD$;OLD.NAME$;")";
600	IF FO%=0 THEN PRINT " (console output only)" ELSE PRINT
610	PRINT
620	IF FO%=0 THEN 650
630	OPEN "R", 2, OD$+OLD.NAME$, 128 : OUTR%=1 : OUTS%=0
640	FOR X=0 TO 127 : FIELD #2, X AS D$, 1 AS OUTF$(X) : NEXT X
650	USQ.EOF%=0
660	GOSUB 1170
670	WHILE NOT(USQ.EOF%)
680	   IF INKEY$=CHR$(3) THEN 800
690	   IF SF% AND USQ$=CHR$(26) THEN SF%=0
700	   IF (SF% AND USQ$<>CHR$(10)) THEN PRINT USQ$;
710	   IF FO% THEN GOSUB 840
720	   CSL%=CSL%+ASC(USQ$) : CAR%=INT(CSL%/256) : CSL%=CSL%-(256*CAR%)
730	   CSH%=CSH%+CAR% : CSH%=(CSH% AND 255)
740	   GOSUB 1170
750	WEND
760	NCS%=CVI(CHR$(CSL%)+CHR$(CSH%))
770	IF NCS%<>OLD.CHECK% THEN PRINT : PRINT "[USQ checksum error"; :
	   IF FO% THEN PRINT ", check output file]" ELSE PRINT "]"
780	CLOSE 1 : IF FO% THEN IF OUTS% THEN PUT #2, OUTR% : CLOSE 2 ELSE CLOSE 2
790	SYSTEM
800	CLOSE : IF SF% THEN PRINT : PRINT
810	PRINT "[USQ aborted]"
820	IF FO% THEN KILL OD$+OLD.NAME$ : PRINT "[";OD$;OLD.NAME$;" killed]"
830	SYSTEM
840	'***************************************************************
850	' TRANSPARENT FILE OUTPUT ROUTINE
860	'
870	LSET OUTF$(OUTS%)=USQ$ : OUTS%=OUTS%+1
880	IF OUTS%=128 THEN PUT #2, OUTR% : OUTR%=OUTR%+1 : OUTS%=0
890	RETURN
900	'***************************************************************
910	' OPEN SQUEEZED FILE AND EXTRACT NAME, CHECKSUM AND TABLE
920	'
930	CUR.PNT%=128 : CUR.REC%=-1 : USQ.ERR%=0 : GOSUB 1120
940	IF GETW%<>-138 THEN USQ.ERR%=1 : GOTO 1040
950	GOSUB 1120 : OLD.CHECK%=GETW%
960	GOSUB 1050 : OLD.NAME$=""
970	WHILE GETC$<>CHR$(0) : OLD.NAME$=OLD.NAME$+GETC$ : GOSUB 1050 : WEND
980	GOSUB 1120 : COUNT%=GETW%
990	FOR X=0 TO COUNT%-1
1000	   GOSUB 1120 : USQ.TABLE%(0,X)=GETW%
1010	   GOSUB 1120 : USQ.TABLE%(1,X)=GETW%
1020	NEXT X
1030	REP.CNT%=0 : USQ.LFT%=0
1040	RETURN
1050	'****************************************************************
1060	' GET CHARACTER FROM SQUEEZED FILE
1070	'
1080	IF CUR.REC%<0 THEN CUR.REC%=0
1090	IF CUR.PNT%>127 THEN CUR.PNT%=0 : CUR.REC%=CUR.REC%+1 : GET 1,CUR.REC%
1100	LSET GETC$=BUF$(CUR.PNT%)
1110	CUR.PNT%=CUR.PNT%+1 : RETURN
1120	'***************************************************************
1130	' GET WORD FROM SQUEEZED FILE
1140	'
1150	GOSUB 1050 : MID$(GETW$,1,1)=GETC$ : GOSUB 1050 : MID$(GETW$,2,1)=GETC$
1160	GETW%=CVI(GETW$) : RETURN
1170	'***************************************************************
1180	' GET UNSQUEEZED CHARACTER
1190	'
1200	IF REP.CNT%<>0 THEN USQ$=USQ.LAST$ : REP.CNT%=REP.CNT%-1 : GOTO 1250
1210	GOSUB 1260 : IF USQ$<>CHR$(144) THEN USQ.LAST$=USQ$ : GOTO 1250
1220	GOSUB 1260 : REP.CNT%=ASC(USQ$)-2
1230	IF REP.CNT%=-2 THEN
	   REP.CNT%=0 : USQ$=CHR$(144) : USQ.LAST$=USQ$ : GOTO 1250
1240	USQ$=USQ.LAST$
1250	RETURN
1260	'***************************************************************
1270	' TABLE LOOKUP ROUTINE
1280	'
1290	CUR.USQ%=0
1300	IF USQ.LFT%=0 THEN GOSUB 1050 : USQ.BYTE%=ASC(GETC$) : USQ.LFT%=8
1310	BIT%=USQ.BYTE% AND 1 : USQ.BYTE%=INT(USQ.BYTE%/2) : USQ.LFT%=USQ.LFT%-1
1320	CUR.USQ%=USQ.TABLE%(BIT%,CUR.USQ%)
1330	IF CUR.USQ%>=0 THEN GOTO 1300
1340	IF CUR.USQ%<-255 THEN USQ.EOF%=-1 : GOTO 1360
1350	USQ$=CHR$(-CUR.USQ%-1)
1360	RETURN
1370	END

-------------------------

----------------------------------------------------------------

rbt@sftig.UUCP (R.Thomas) (04/26/85)

> 
> I picked this up on a local BBS with NO DOCUMENTATION, but I still
> think it may be of use to the users of SIMTEL20's repository.
> 
> --Arun [NBaheti.es@Xerox]
> 

Does anybody on this net have the specs for the algorithm used to squeeze
(or more importantly, unsqueeze) things on SIMTEL20?
Better yet, if there is a C program to do the unsqueezing, could somebody
post it, or mail it to me.  PLEASE!

If somebody will mail me the English description of the algorithm, I will
write a C program to do it and post it to net.sources.

Rick Thomas
{ihnp4,akgua,bellcore,ucbvax,just about anywhere}!attunix!rbt
(201)-522-6062

bill@persci.UUCP (04/27/85)

> Does anybody on this net have the specs for the algorithm used to squeeze
> (or more importantly, unsqueeze) things on SIMTEL20?
> Better yet, if there is a C program to do the unsqueezing, could somebody
> post it, or mail it to me.  PLEASE!
> [...]
> Rick Thomas  {ihnp4,akgua,bellcore,ucbvax,just about anywhere}!attunix!rbt

I have a copy of both sq.c and usq.c which I find to be compatible with the
CP/M utilities I use. I got them off a BBS somewhere, and fixed them. I use
them a good deal for squeezing files to be transferred between our VAX at 
work and my CP/M machine at home. At 300 baud, I need all the help I can get!

These utilities appear to have come from the net originally. I haven't been on
long, so I wouldn't really know. If there is interest, I will post them to
net.sources.

A Word of Warning: I sent these utilities to several other CP/M users in the
area (on the net). One (and only one) reported that he was unable to unsqueeze
files that he squeezed on his system at home! Something caused usq to crash
with a core dump. We have not found the problem, but it only occurs with files
squeezed by his particular squeeze program! The rest of us have never had a 
problem with the utilities.

-- 
Bill Swan	{ihnp4|decvax|...}!uw-beaver!tikal!persci!bill
...and some days the dragon wins!

ABN.ISCAMS@USC-ISID.ARPA (05/01/85)

Bill (et al),

Can't find my listing of the SIGM volumes at SIMTEL20 ANYWHERE!  But anyway...

Our friends at Universidad de Pueblo in Mexico City disassembled the 8080
version of SQ and USQ from its binary .COM file (as a student exercise, I
understand), and rewrote it like humans would in Assembler.

Carved a whole BUNCH of waste out of it, reduced its compiled form signifi-
cantly, and also increased its speed.

The kid went through THEIR source code, stuck in a bunch of Z80 stuff (and
tightened up the code a little more), and it still works!

However, for a nice, documented (yep, in English) source code for SQ and
USQ squeeze programs, to include a nice library where you can use the SQ
and USQ algorithms as part of a byte stream in about ANYTHING...

It's in one of the volumes (above 170, as I recollect) in the SIGM archives
at SIMTEL20, identified (as several volumes are) by the Univ. de
Pueblo name and a bunch of SQ/USQ files.  Have fun!  I sure did!

Regards,
David Kirschbaum
Toad Hall
ABN.ISCAMS@USC-ISID

ABN.ISCAMS@USC-ISID.ARPA (05/01/85)

Oh, yeah,

Almost forgot, re the algorithm for SQ/USQ.

Forget where I found it (on this net?), but some persevering soul did an USQ
in BASIC for the PC that nicely shows the algorithm if you can read BASIC.
(They are the first to admit it runs slowly uncompiled, and barely tolerably
compiled.)

If no one else remembers where this came from, I can upload to the requesting
party or put it available via Anonymous FTP in my directory.  Just yell.

Donno if the rascal actually works (didn't bother to try), but the code looks
sound as I recollect from my work with the .ASM and .ZSM versions I played with.

Regards,
David Kirschbaum
Toad Hall
ABN.ISCAMS@USC-ISID