ZX Review #7-8-9-10
08 ноября 1997

Studies - The procedure for making optimal symbol table.

<b>Studies</b> - The procedure for making optimal symbol table.
(C) M. Tatarinov, Solikamsk


   I want to offer the procedure,
which will be useful to the creators of compressors using
Huffman (bit compression).

   As is known, this method
requires a reference table of characters. The smaller the 
number of characters in the table, the require less bits to 
encode the symbol. This procedure is for each File optimal 
table. 

   The program works as follows:
as follows: first of all calculated coefficients of the 
recurrence each character in the file, then the coefficients 
are sorted and IDs of these coefficients are packed into a 
table. 

   Program to work requires
buffer, the maximum size is equal to 3 * 256 = 768 bytes (ie,
If there are 256 different characters. 3 - is the size of one 
record in the buffer). The table will be written in the 
beginning of the buffer. 140.

; Program to compile
; Table
; (C) Mat Software'96

MKTREE LD A, # FF

          LD (TSIZE), A

          LD D, 0
; Start symbol - 0

          LD IX, (TREE)
; Buffer address
AG LD HL, (RAW)
; Address of the file

          LD BC, (LEN)
The length of the file

          CALL ONE

          LD A, D

          CP # FF
And all the characters tested?

          JR NC, SORT
Yea - go to the sorting.

          INC D
; Otherwise - repeat for all 256

          JR AG
ONE XOR A

          LD (PEP), A

          LD (PEP +1), A
SEEK LD A, (HL)

          CP D

          JR NZ, NXT

          PUSH HL

          LD HL, (PEP)

          INC HL

          LD (PEP), HL

          POP HL
NXT LD A, B

          OR C

          JR Z, EOF

          DEC BC

          INC HL

          JR SEEK
EOF LD HL, (PEP)

          LD A, H

          OR L

          RET Z

          LD (IX +0), D

          LD (IX +1), L

          LD (IX +2), H

          LD BC, 3

          ADD IX, BC

          LD HL, TSIZE

          INC (HL)

          RET

; Procedure for collation

SORT LD A, (TSIZE)

          LD B, A
PS2 LD IX, (TREE)

          LD A, (TSIZE)

          LD C, A
PS1 LD D, (IX +2)

          LD E, (IX +1)

          LD H, (IX +5)

          LD L, (IX +4)

          AND A

          SBC HL, DE

          JR C, NOPF

          PUSH BC

          LD A, (IX +3)

          LD B, (IX +0)

          LD (IX +0), A

          LD (IX +3), B

          LD A, (IX +4)

          LD B, (IX +1)

          LD (IX +1), A

          LD (IX +4), B

          LD A, (IX +5)

          LD B, (IX +2)

          LD (IX +2), A

          LD (IX +5), B

          POP BC
NOPF LD DE, 3

          ADD IX, DE

          DEC C

          JR NZ, PS1

          DJNZ PS2

, Forming a table

FORM LD A, (TSIZE)

          LD IX, (TREE)

          LD HL, (TREE)

          LD B, A
ALL LD A, (IX +3)

          INC HL

          LD (HL), A

          LD DE, 3

          ADD IX, DE

          LD A, B
And instead DJNZ!

          AND A

          RET Z

          DEC B

          JR ALL

; Variables:

RAW DW 0; address of the file
TREE DW 0; buffer address
LEN DW 0; length of the file
PEP DW 0; operating variables
                ; Mennaya
TSIZE DB 0; size table
, And if TSIZE = 0, then
; Size - 1 bytes.
2

   Now a bit of a strange initial value TSIZE - # FF
(-1). Logical, seemingly setting TSIZE to 0. However, if
the file will contain the maximum - 256 different characters,
TSIZE, set to 0, the output will also 0, so you have to dodge 
so. 

   And more: the procedure compressor
converts the character code in its
number in the table, too, may work incorrectly when TSIZE = max,
so you'll need it DJNZ replaced by:


          LD A, B

          AND A

          JR NZ, XXXX


   This, of course, if you do not find in your procedure, the 
best method. Generally speaking, you can do no tricks: it is 
necessary size TSIZE not be determined in bytes, and in word.

Then, however, have to sacrifice an extra register
pair and, therefore, inevitable, and all sorts of PUSH'y POP'y 
slowing down already a slow program.

Speaking of speed. In my procedure, most of the compression
time consuming preparation
table. A lot of time
spent on sorting, so
The method proposed above, it is desirable to replace a more 
rapid (Such as algorithms, Shell and the "bubble." Advise you 
to read in the ZX REVIEW N5, 1994 article on the methods

sorting).


   Ca. Ed.: One of the fastest
ways of sorting is the method of "quicksort Hoare.


          *







Other articles:

TR-DOS for beginners - The end.

Computer novella - Prince of Persia.

Computer novella - Laser team (the game Laser Squad).

Crossing Dragon - Game Rapscallion.

Crossing Dragon - Playing The Runes of Zendos.

Crossing Dragon - Playing The Saga.

Crossing Dragon - Game Witch's Cauldron.

Crossing Dragon - Create Adventyuru. Review of the editors.

Crossing Dragon - Create a dictionary to Adventyurnoy game.

Program, which we choose - The possible consequences of using undocumented commands.

Program, which we choose - About noticed irregularities in some programs and suggestions for future versions.

Program, which we choose - A proposal to all the authors of software, printers, memory dump. Programmers protect discs from being copied.

Program, which we choose - A few suggestions to improve the assembly.

Program, which we choose - Suggestions for refining ZX Word v2.5.

Program, which we choose - The "Spectrum emulator" v1.2.

Program, which we choose - What could want in a perfect assembly.

Retro - 40 best procedures: Copying data in memory.

Retro - 40 best procedures: Exchange token.

Retro - 40 best procedures: Determination addresses BASIC string.

Retro - 40 best procedures: Determination of the length of BASIC programs.

Retro - 40 best procedures: Determination of the amount of free memory.

Retro - 40 best procedures for: Search and replace strings.

Retro - 40 best procedure: Find the string.

Retro - 40 best procedures: Search for the string.

Retro - 40 best procedures: the list of variables.

Retro - 40 best procedures: an increase and up the screen.

Retro - 40 best treatments: Removal of REM-strings.

Retro - 40 best procedures: Remove the block of the program.

Expert Tips - Game Fredloader.

Expert Tips - Game Robin of Sherwood: The Touchstones of Rhianon.

Expert Tips - Game Scorpions: Die Machines.

Expert Tips - Game Terropods.

page iS-DOS - Description of system restarts IS DOS.

Forum - An algorithm for recognizing characters.

Forum - Time undocumented command processor Z80.

Forum - The concept of a high-color screen resolution.

Forum - A few Pokes to a game. Program Hacman96.

Forum - As for the new DOS and BIOS settings for the Spectrum.

Forum - Multicolor program on any computer model. Using the 2 nd screen Multicolor'a. Demonstration of the text. Electronic journals.

Forum - Project ZX Config.

Forum - Improve Art Studio. Ideas on file compression.

Forum - ZX Spectrum emulator for IBM. About the hexadecimal system. Program ZX-Stars. Oddities in the Elita

Forum - The effects on the curb and Multicolor.

reader-reader - ZX Spectrum 128 - new opportunities, new challenges.

reader-reader - With 'Light'. Spectrum and expert system.

reader-reader - The printer driver for the Scorpion.

reader-reader - Print numbers in different number systems.

reader-reader - Programming arcade game with scrolling screen.

reader-reader - The procedure for printing labels assembler XAS to monitor debugger STS 4.3.

Studies - attribute scrolling text. "Gasilka" screen. A simplified version of the procedure, "Curtain". Procedure is enriched with pictures. Procedure display images on the points.

Studies - Graphic effect "color bars".

Studies - Driver screen printing 64 characters per line.

Studies - Set of protective boot.

Studies - Address to the drive mode IM 2. Working with non-standard disc format.

Studies - Print the character, magnified by 8 times. The program "pouring" screen. The procedure for screen-saver on the points. Clear screen in Terminator'e. Search strings in memory. System character set conversion.

Studies - Program - cataloger of disks.

Studies - Program the output values of the amplitude channel music. coprocessor on the curb.

Studies - Program the output image.

Studies - The program plugs sprite.

Studies - Cleanup of the specified window screen.

Studies - The program sort the array in ascending order. The procedure for filling the screen specified attribute. Procedure display pictures. The effect of moving towards the stars. "Shower", coming from the upper left corner of the screen. The procedure of "shedding" pictures on the pixel lines. The program of "pulling" the picture at an angle of 45 degrees. Three procedures "Scroll".

Studies - The printing of numbers.

Studies - The procedure for drawing a character with attributes.

Studies - The procedure for display pictures. Fade-OUT effect (picture goes beyond the edge of the screen). Visual effect "Fountain." Fade-OUT effect, mimicking the TV off. Procedure "Ignition" pictures. The program continuously drawing a picture.

Studies - The procedure for drawing a line.

Studies - The procedure for making optimal symbol table.

Studies - scrolling lines of text in the specified window. Attribute scroller. Diagonal scrolling.

Studies - sprite scroller. Procedure display screen.

Studies - Short procedure indicating the amplitude channel music. coprocessor. Way to subtract a constant from a register pair HL.

Studies - The formula for calculating the day of the week.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Mail BUZZ'a - On the software market (Letter from BLAZ'a).
Mosaic - Opinions about ZXNet & BBS.

В этот день...   30 April