Menu

TextToHuff

LunySoft

TextToHuff

TextToHuff is a command line utility to convert a string source into huffman coding, compressing the strings down.

Requires:
dotnet 5.0
MS SDK 5.0
MS runtime Microsoft.AspNetCore.App 5.0.17

To build:

dotnet build

Details

The output is in a Z80 assembler format. The utility understands comments and assembly labels and if used will compile pointer tables holding the address of each string. Strings can also be grouped into different tables using the special '[]' commands.

For example:

; This is a comment
; The following is a string. It starts with a label, so it will be included in the table of pointers.
label1:
This is a simple sentence which will be compress into Huffman coding.
This is another line on the same string.
This line marks the end of the string by using the character ~
label2:
This is a new string.

; The following tells the utility that all the above string belongs to the same table, and it will create a table of labels found in each string.
[table]

The above example will compile into the following output:

; This is a comment
; The following is a string. It starts with a label, so it will be included in the table of pointers.
label1:
    DEFB 43, 116, 222, 155, 191, 106, 62, 26, 14, 193, 100, 46, 35, 155, 186, 199, 124, 218, 68, 250, 143, 141, 207, 135, 16, 205, 233, 102, 252, 193, 4, 178, 206, 235, 241, 189, 170, 91, 52, 57
    DEFB 43, 116, 222, 155, 186, 222, 118, 35, 210, 148, 123, 175, 157, 142, 206, 113, 218, 99, 75, 102, 156, 1
    DEFB 43, 116, 221, 41, 71, 59, 196, 196, 222, 118, 56, 91, 94, 229, 249, 216, 237, 49, 165, 179, 234, 103, 224, 181, 45, 158, 118, 62, 59, 120, 190, 50, 35, 244, 25
label2:
    DEFB 43, 116, 222, 155, 191, 80, 111, 105, 141, 45, 154, 57
    DEFB 25
; The following tells the utility that all the above string belongs to the same table, and it will create a table of labels found in each string.

table:
DEFW label1,label2

To summarise, the rules are:

Any line starting with a semi-colon ';' will be treated as a comment and included in the output.
Any line ending with a colon ':' will be treated as a label and stored to be used in the next table command.
Any line starting with '[' and ending with ']' will generate a table, using the name within as its own label. The table will consist of all the labels found prior.
Anything will be treated as a string to be encoded. this includes any empty lines ending in a return.
Each string must end with the '~' character, in order to allow newlines to be included in the final text.

Z80 Limitations
In order to keep the final tree small, so as not to have the code end up larger than the original text, each node takes 1 byte.
Due to needing a bit for a flag, this means the strings are limited to the first 127 ascii codes, which is not reasonable for 8-bit machines and is plenty for adventure games.
Each string


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.