SpaceOut 1.0 ---> 2/3

 BBS: Inland Empire Archive
Date: 02-28-93 (21:28)             Number: 68
From: VICTOR YIU                   Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: SpaceOut 1.0 ---> 2/3          Conf: (2) Quik_Bas
'Part 2 of SPACEOUT.BAS - continued from last message...

IF Ok THEN
    LOCATE , 1
    PRINT USING "Time elapsed: ###.## seconds."; TIMER - T!
    PRINT
    PRINT "Results:"
    PRINT "  Compression percentage: ";
    PRINT USING "###.#%"; (InL& - OutL&) * 100 / InL&
    PRINT "  In:"; InL&; " Out:"; OutL&
    PRINT "  Bytes saved: "; InL& - OutL&; "out of"; InL&
    PRINT
    PRINT "Happy compression!"
ELSE
    PRINT "Compression aborted or error occured."
    IF InL& = 0 THEN PRINT "File does not exist."
END IF

END

' This function expands the compressed code generated by vy.Encode.
' It is a little more complicated because it has to create extra
' spaces without using string concentration (A$ + B$ ...) -- that
' would be toooo slow.
'
FUNCTION vy.Decode (Text$)

    Leng = LEN(Text$)
    IF Leng = 0 THEN Decode = True: EXIT FUNCTION

    OrigLen = CVI(LEFT$(Text$, 2))
    IF OrigLen > Leng - 2 THEN      ' doing something if two blocks
    END IF                      ' of code are squished together...
                                ' but try to avoid it...

    Add = OrigLen - LT
    IF Add > 0 THEN Text$ = SPACE$(Add + 1) + MID$(Text$, 3)

    Temp& = SSEG(Text$)     ' QB USERS: REPLACE
                            ' "SSEG" with VARSEG
    Offset = SADD(Text$)
    DEF SEG = Temp& + Offset \ 16

    After = Offset AND 15
    Offset = After + Add
    IF Add THEN Offset = Offset + 1
    Endd = Offset + Leng - 1
    Abort = False
    Ok = True

    FOR Byte = Offset TO Endd
        IF After > Byte THEN
            PRINT "Input is corrupted!"
            Ok = False
            EXIT FOR
        END IF

        Char = PEEK(Byte)

        IF Char > 127 THEN
            POKE After, Char AND 127
            After = After + 1
            POKE After, 32
        ELSE
            POKE After, Char
        END IF

        After = After + 1
    NEXT

    DEF SEG

    Text$ = LEFT$(Text$, OrigLen)
    IF NOT Ok THEN Text$ = RTRIM$(Text$)
    vy.Decode = Ok

END FUNCTION

' My principal is simple.  Since the SPACE (ASCII 32) character is the
' most commonly found character in English text, and the high bit of
' the text is not used, I have decided to compress the space into the
' one bit.  What I mean: If the next character is a space, turn the
' high bit on.  If it is not, leave it off.
'
' So this input:   weiu weoiru weoiu q
'
' would come out 3 characters shorter, since the spaces are represented
' by the high bit of the previous character.  If the input has two
' incoming spaces, however, the 1st space will be encoded w/the last

'Continued on next message...

--- Blue Wave/RA v2.10 [NR]
 * Origin: Hard Disc Cafe / Houston Texas / (713) 589-2690
/ Node -*N (1:106/30.0)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET