Sinclair Club #05
31 декабря 2001

Programming - a very effective way to improve the performance of the interpreter BASIC (48 Basic), integrated into the ZX-Spectrum, the processing of large data sets.

<b>Programming</b> - a very effective way to improve the performance of the interpreter BASIC (48 Basic), integrated into the ZX-Spectrum, the processing of large data sets.
            BASIC-48K



       (C) Alone Coder / Any



   Today I'm going to tell you about one
very effective way to improve the performance of the 
interpreter BASIC (48 Basic), integrated into the ZX-Spectrum, 
the processing of large data sets. 

   It is known that the classic way to move blocks of data in 
memory when programming in machine code (assembler) a team 
LDIR, as well as its own sister - the team LDDR. In BASIC is 
nothing like this is not provided, and therefore, say, 
"ZX-Revue" advises using for such cases loadable or created by 
READ-DATA-POKE machine-code procedures. 

   But I - for the purity of the native BASIC! ;)

   You can tighten the loop that iterates over the address and 
displacing one byte at a pass, but this version will run as a 
at least a hundred times slower than native code - this is very 
slow. 

   But we remember that the language unit
"BASIC" incorporated a feature that runs at speeds 
LDIR.Funktsiya this - copy the string variables and their 
sites! 

   Unfortunately, in BASIC you can not specify a variable, 
passing through the screen area (And that is exactly what we 
needed, so as copying large blocks often requires to handle the 
screen: his shift to the memory, recovery, etc.) 

   Therefore, try to create a dummy variable that crosses the 
screen, within their means. 

   As is known, two-byte starting address
BASIC variables stored in the system
variable VARS (23627-23628). Variables
in this field one after another, pointing at each other along 
the chain. Several format variables differ by three senior bats 
in the first symbol of the variable name. 

   String variables have the format:

% 010aaaaa <ml.bayt length> 
 


   Where aaaaa - lower five bits of the symbol
variable name (for string variables
single-character names), and "length" - length
substantial part of the line, ie, how many
in this line of characters.

   It turns out that it is enough to fill three
first bytes of variable size, and we can
get a string of arbitrary length with copy inside it, ie,
the possibility of fast moving units.

   But the problem is compounded by the fact that the latter
processed string variable is always
sent BASIC interpreter to the top of the field variables (at 
least I thought so), so even address this

of non-fixed - depends on the length
software and computer configuration, and
In addition, creating this variable, we lose
all other variables BASIC, because they
longer, no previous variable
did not mention. (After all, the previous variables
we have only one thing - the more we create
We can not, because I see the beginning of the paragraph:))

   Hence, the only correct way -
move the area of ​​the variables at fixed addresses in memory, 
to create a fictitious identifier string variable, use it to 
produce the required copy operations, and then restore the 
original address field variables. 


 BASIC program Length: # 01A8 = 424



   1 LIST:

     POKE VAL "23627", CODE "CLEAR":

     POKE 23628, NOT PI
1000 LET b $ (39,968 TO 40,223) = b $ (16,129 TO):

     LET b $ (16,129 TO 17,920) = b $ (16,385 TO):

     LET b $ (17,921 TO 18,144) = b $ (4e4 TO)
1010 LET b $ (18,145 TO 18,176) = b $ (18,177 TO)
1020 LET b $ (4e4 TO 40,223) = b $ (18,209 TO):

     LET b $ (18,177 TO 19,968) = b $ (18,433 TO):

     LET b $ (19,969 TO 20,192) = b $ (4e4 TO)
1030 LET b $ (20,193 TO 20,224) = b $ (39,968 TO):

     GO TO 9



   This program (see also the annex to
newspaper) sets the variable b $, starting
to address 253 (CODE "CLEAR" = 253). In this
addresses in all versions of BASIC is
section table of tokens, which defines a variable with that 
name and length about 50 kilobytes.


   Since the variable identifier starts at address 253, then 
the first symbol (B $ (1)), this variable is located at 256, 
the second - at 257, and etc. So that all the numbers in the 
program - is screen address minus 255.


   The program scrolls two thirds of the screen. This is a 
simplified version of the program is intended only to 
illustrate the method. Therefore, the yield from it is not 
provided. If you during the install press the BREAK, then

even not be able to RUN, because Region
variables has been moved and has not returned
back.

   A practical way to save and restore the correct system 
variable VARS in the absence of access to variables is to copy 
the contents of 23627 and 23628 cells for a certain well-known

address in memory and restore the content immediately after the 
"unfair" portion of the program. 

   Of course, we created a variable can
and point to the next, but for this
it should end where they nachinayutsya.Takaya variables get 
very short, we create it in the first half of the memory, but 
if it begins above 25000, it will take to itself and the 
screen, and the upper memory area, and thus can still point to 
other variables. Of course, in this case, the program should 
not use other string variables, or at least should switch VARS 
before using them. 

   By the way, if a variable was created
at 65534, then the numbering of its characters
would coincide with the addresses to which these characters are 
stored. I have a great suspicion so that the function works 
"MEMORY $ ()" in Beta-BASIC, but it is written using native 
code, and we have - pure BASIC! 

      Spectrum Basic rulez!
      'It's not portable:)





Other articles:

From the authors - "Read our publication and your soul will be crystal Spectrum'ovskaya net. "

Demopati - Announcement ASCII'2002.

Programming - a very effective way to improve the performance of the interpreter BASIC (48 Basic), integrated into the ZX-Spectrum, the processing of large data sets.

Iron - Sprinter? Questions and answers!

Contest - The attention of the competition, "Your Game"!

Soft - Strange system programs: STS 5.1, ALASM 4.1.

Chaos Constructions'2001 - Cusick shares his impressions about the next festival of computer art.

Soft - description of a new version of the GFX UTILITY v0.5.

phONOmania - a database of phone numbers active ZX scenery.

Announcement - advertising and announcements.

Authors - The editors of the newspaper.


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

Similar articles:
Introduction - That appeared in Cheboksary computer newspaper for ZX-Spectrum.
911 - reanimate Dizzy ...
Humor - pro Ostankino.
Software for Sale - Buy yourself a little Speccy.
Support us - the newspaper is required care: musicians, artists and authors of articles.

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