Micro #09
04 октября 1998
  TR-DOS  

Tape and Disk - Adapting programs to the system TR-DOS (Part 3).

<b>Tape and Disk</b> - Adapting programs to the system TR-DOS (Part 3).
  Adapting programs to the system TR-DOS



                 CHAPTER 3

        =========================

          MORE ON BASIC = =


   A programmer who is not familiar with the representation of 
numbers BASIC interpreter Computer ZX Spectrum, a lot of 
surprise, faced with the following program: 


  10 CLEAR 100

  20 PAPER 27: INK 8E-12: BORDER 65536: CLS

  30 PRINT AT -10000,22 E22; "PLEASE WAIT"

  40 LOAD "" CODE 0,0

  50 RANDOMIZE USR 0


   This programmer will be strongly
argue that this nonsense is written in no other way,
as psychiatric patients,
until then, until the program starts and
not see the results of its work. What happens to the 
programmer, after a middle of the screen will display PLEASE

WAIT, then download and run the game
difficult to predict. Most likely, he
run in the PND with a presumptive diagnosis
"Manic-depressive psychosis on the basis of
programming.

   To you it does not, you will discover another mystery. The 
thing is that the processing of numbers BASIC interpreter uses 
two of their submission. first impression is pleasing to

Eye symbolic form in which the number of
16389, for example, is written by five bytes per table ASCII. 
However, such form a relatively long handled

BASIC interpreter, therefore, for their
needs, it uses a different representation
binary numbers. Binary form of numbers,
prefixed with Code 14 (0Eh),
stored in memory immediately after
symbolic forms. Number 16389, for example,
looks in memory as follows:


     symbolic form of pre-binary

      June 1 3 8 9 fixe form

 ... 49 54 51 56 57 14 0 0 5 64 0 ...



   This shows that the binary form of
occupies 5 bytes plus bytes prefix. When
entire record of the constants in the range from 0 to
65535 "meaningful" is the third and 4-byte
after prefiksa.V this case, the binary form of numbers can be 
pervesti to decimal using the operator 


  PRINT PEEK (n +3) +256 * PEEK (n +4)

- Where n is the address to which the stored bytes
prefix.

   Binary and symbolic forms of numbers exist in parallel. When 
you execute the BASIC interpreter is guided only by the binary 
form, character Form does not care, it is saved

for the sake of readability of programs. Therefore,
"Blight" symbolic representation of numbers
resulting in a horrible kind of program listing,
but does not affect its performance.

   Binary form the number is added at the time syntax checking 
line, that is After a set of rows and press Enter.

When you call on-line editing binary form is removed, and after 
I corrected the line is restored in accordance with the new 
edition. 

   From the above it should be clear that
mysterious program given at the beginning
this chapter will not work if it
enter from the keyboard in the usual way, not
using any special techniques
(Maybe you've tried it to recruit and
run, and decided that no one else like me
and I am a patient of the above clinics)

   In order to bring the program to such a perverted mind, 
while leaving its workable, requires external means, for 
example, the monitor debugger STS5.1 or similar. However, we 
still are talking about adapting programs to disk, rather than 
bringing them into a state of alcoholic intoxication, 
therefore, the problem we are back. 

   It would be possible to do a lengthy description of the 
representation of numbers in binary form, but I prefer to give 
practical advice on the calculation of what is hidden under the 
guise of symbolic forms. 

   The simplest and most effective way to
determining the true values ​​of the numbers of
my experience, is a permutation operator instead of the PRINT 
program operators. In this case all the numbers used by the 
program, will be successively displayed on the screen in the 
normal way. 

   If provided in the beginning of the chapter program change 
follows (note Note that not using the numbers operators and 
other "extra" characters are replaced gaps outlined in this case

underscore):


  10 PRINT 100

  20 27 PRINT: PRINT 8E-12: PRINT 65536: ___

  30 PRINT _-10000, 22E22 ;________________

  40 PRINT ___0, 0

  50 PRINT _0

- As a result of its implementation on the screen
appears:


  24999

  0

  4

  0

  October 1910

  25000 40000

  25000


  0 OK, 50:1


  Substituting these values ​​into the program, we get the 
familiar and intuitive text: 


  10 CLEAR 24999

  20 PAPER 0: INK 4: BORDER 0: CLS

  30 PRINT AT 10,10; "PLEASE WAIT"

  40 LOAD "" CODE 25000,40000

  50 RANDOMIZE USR 25000


   If you have already reached out to key Edit,
to quickly arrange the operators
PRINT, I advise you to read all over again.
As already mentioned, the call to edit a binary form of 
permanently is lost, there is only symbolic, and

If you modify INK 8E-12 at PRINT 8E-12
using the BASIC editor, then get
neither more nor less than 8E-12.Chtoby replace the operators 
of the program on PRINT, do not "break" the binary form of 
numbers, we need other ways. You can use all the same debugger 
STS5.1; in extreme cases will come down and the operator of 
POKE. This text is not my aim to educate the work with the 
debugger, so tell better how to defeat the program without 
improvised. 

   POKE operator is very good, but only
if you know what settings need to follow after him. And it 
needs to look into the computer's memory. For example, we use 
the line, which displays the address and the contents of cells

memory and the symbolic representation of the
Content:

 FOR n = 23755 TO 4E10: PRINT n, PEEK n;
 TAB 22; CHR $ (PEEK n * (PEEK n = 32)): NEXT n


  After completing this line on the screen we get:


  23755 0? line number

  23756 10?

  23757 11? string length

  23758 0?

  23759 253 CLEAR keyword

  23760 49 1

  23 761 48 0 sim.forma parameter

  23762 14 0

  23763 14? prefix

  23764 0?

  23765 0?

  23766 167 COS binary form

                       parameter

  23 767 1997 _

  23768 0?

  23769 13? carriage return

  23770 0? line number

  23771 20?

  23772 38 &

  23773 0?

  23774 218 PAPER

  23775 50 2

  23776 55 7



  scroll?


   Now you need to carefully examine the contents of the screen.

   As you may already know, the first two bytes
is the row number, then the keyword
CLEAR, which is actually what we need.
Grab a piece of paper and pencil and write down the address to 
which is CLEAR (2375 9), and continue this highly intelligent

work. After CLEAR following symbolic form
number, then binary, then the symbol
"Carriage return" (end of line), number and
length of the next line and the operator PAPER.
Again, take a pencil and write down the address
operator PAPER.

   After reviewing the program to the end and writing
all addresses that need to be replaced
you can begin to change:


  POKE 23759,245: REM Replace CLEAR

  POKE 23774,245: REM Replace PAPER

  POKE 23884,245: REM Replace INK

  POKE 23997,245: REM Replace BORDER

  POKE 24110,32: REM Replace CLS

  POKE 24117,32: REM Replace AT

etc. The number 245 is the code the keyword PRINT, and 32 code 
probela.V this example, spaces are replaced the following 
operators and symbols: 


  CLS

  AT

  "PLEASE WAIT"

  "" CODE

  USR


   When will you make all necessary changes, review the program 
listing, to make sure that fixes everything

what you need. Then the program can be run
and examine the results.


   Sometimes this operation can be somewhat
simplified. If the binary representation
numbers using integers between 0 constants
65535, then to determine their true values
can be directly while viewing the memory. To do this, it is 
desirable to add to pencil and paper, calculator. 

   Find in the symbolic form of memory that you want to 
"expose", followed by the be a prefix and binary forma.Esli an 
integer between 0 and 65535, the the prefix two zeros, then the 
two numbers in range from 0 to 255 and another zero.

If not, then definitely we can say that number or not an 
integer, or leaves outside the specified range. In this

case it is better to resort to the previous method. If the 
number of "fit", then multiply 4-th byte of the prefix 256 and 
add 3rd. In this example, to get the option of the operator 
CLEAR, we must calculate: 


  PRINT PEEK (23763 +3) +256 * PEEK (23763 +4)

 or


  PRINT 167 256 * 97


   The result (24,999) and there is
that tried to hide from us.

   Uncover the secret of another common focus based on the 
knowledge of the number format BASIC interpreter (although may 
otgadku you already know). 

   You probably have met such
lines:


  10 CLEAR VAL "24999": INK VAL "7": PAPER

     BIN: BORDER BIN


  Thus, programmers save memory. Paradoxically, but
Record VAL "24999" takes up less space
than 24,999. Since the first case
number 24999 zalkyucheno in quotes, it is a character string, 
and not by the number and has, after a six-byte binary

representation. If you select VAL
this line is translated into a number. Thereby saving three 
bytes. As for BIN, the win is even more evident. If, instead of 
BIN substitute 0, then the memory will be occupied by more than 
six bytes, and the same result. 

   This way of saving some memory
slows down the program, but it can and should be used in the 
loader, so as they are usually most sensitive to size and are 
not critical to the speed implementation.




           Continued to be ...

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

  In the next issue of Micro searched Chapter 4


     = LOADER, native =


          For those who do not know

         What is computer code.


        ..........................


     Gloom Demons Inc. & Computer Eye

           special for Micro 9.


                                08.10.98






Other articles:

Championship - 1-st Zaporozhye Championship viruses.

Tape and Disk - Adapting programs to the system TR-DOS (Part 3).

Chaos - description of the game "Chaos - Battle of the wizards."

Useful Information - description of the enemies of the game BARD'S TALE.

Pokes - Poke's for the games.

Jokes - the parade of anecdotes.


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

Similar articles:
Iron - Interview with director of the firm of Peters planned clone Spectrum Sprinter'e.
Novyny - have changed the network address of the editorial board.
Interface - thinking out loud: "SPECCY computer for young people. If we have so many cool coders, why so little steep domestic soft'a?"

В этот день...   21 November