Echo #03
31 марта 1997

Book - Secrets ZX-Spectrum: BASIC system variables.

   Chapter 6.


   C & S T E M E N Li

   P E R E M E N N E Li



   System variables are stored at address
# 5C00 (23552) to the region occupied by the BASIC program. 
Program from the ROM use it to store information, describing 
the state of the computer. Below we consider those variables 
that can be modified and used programmer. The rest is better 
not to touch, as this can cause damage to the operating system. 
Describes the variables divide (according to specific functions,

instead of in memory) into 5 groups:


   - Storing important for a system of addresses;

   - Serving the keyboard;

   - Describing the state of the system;

   - The channels and streams;

   - Serving the television screen.



   6. 1 Important for the system address

ERR_SP # 5C3D (23613) STKEND # 5C65 (23653)
VARS # 5C4B (23627) RAMTOP # 5CB2 (23730)
PROG # 5C53 (23635) P_RAMT # 5CB4 (23732)
E_LINE # 5C59 (23641) CHANS # 5C36 (23606)
WORKSP # 5C61 (23649) UDG # 5C7B (23675)
STKBOT # 5C63 (23651)


   Application of these variables is described in
previous chapter. Natural use of these variables can be 
redistributed size of free memory, or busy program, variables, 
etc. Only variable RAMTOP can be easily

modified from BASIC through
CLEAR K. Unfortunately, this team has
well as other side effects that sometimes makes it impossible 
to use. 



   P_RAMT


   Contains the address of the last, physically
present in computer memory. Consequently, it can be used
for the recognition program in a computer model ZX-SPECTRUM it 
is loaded (16K or 48K).




   CHARS


   With this variable you can define your own form of 
withdrawal. After placing them in the RAM at address K is 
sufficient to specify the value of the variable CHARS K-256. 
From this point on, all text, including a program listing will 
be printed in our new signs. This way you can change the shape 
of all the characters with codes from 32 to 127. It should be 
emphasized that both modified only the outlines of characters 
but not their values, which depend on the character codes. You 
can use this variable tricks that make the text of the program 
is absolutely unreadable. Enough to reduce the value of CHARS 
at 8, and then a printout of the program will be difficult to 
find any meaning. But the inscription, the output is running on 
the execution program will remain legible when

will advance shifted by one
code value, ie, in the original text will place "B" instead of 
"A", "O" instead of "N", etc. etc..




   UDG


   The benefit of placing the address in
list for the variables is that
this unit we can move in memory.
Equally valuable is the ability to use multiple sets of atypical
characters simultaneously. In this case, before the conclusion 
of the sign is required to modify the UDG, assigning it a value 
set that is needed in the moment. Modifying the other variables 
this group is very dangerous and can easily crash and the crash 
of the operating system.




   ERR_SP


   This variable specifies the base of the machine stack. 
There, in turn, put the address of procedure in the memory ROM, 
responsible for the maintenance of all error situations that 
require interruption of the program and issue the appropriate 
message. By mistake is here understood as normal and completion 
of the program, signaled message 0 OK. Passionate programmers

Z80 assembler can know, thanks
this, write your own error-handling code, which allows, among 
other things, adding new commands to the language. Modification 
ERR_SP with BASIC level always leads to system crash at the 
time of occurrence of situations that require the withdrawal of 
any message. It is often used to protect software from 
unauthorized viewing and copying. This method in conjunction 
with recording programs using SAVE F LINE ..., and also with 
the exception of the possibility of reading program MERGE 
statement typically can fully protect the program from less 
literate pirates. Unfortunately, the salvation of the many 
programs do not replicate. 



   6. 2 variables serving keyboard


   KSTATE # 5C00 (23552)


   This variable is constructed from 8 bytes
used to read the keyboard and services samopovtoryaemosti keys. 
For programmer only the cell with address # 5C04

(23,556) can make a difference. It contains
255, if no key is pressed, or code of the basic values ​​down
keys in C (large alphabet letter or number). PEEK 23556 gives so
the same effect as the CODE INKEY $ in
Mode C. The advantage is the fact that
value does not depend on the state of the cursor
(L or C). In the case of clicking a few
keys simultaneously will always recognizes the first (INKEY $ 
in such a situation can ignore). Keys  and ,

clickable separately, would not affect
our cell, but pressed together give the code
14. In addition, the combination , ,
,  Give out codes accordingly
15, 4, 5, 6 (these codes also catches CODE
INKEY $).



   LAST_K # 5C08 (23560)


   This variable holds the byte code of the last key pressed, 
regardless of the clicks on it or not. In the case of clicking 
a few - will be remembered the code first. In contrast to the 
previous variable LAST_K monitors the state of the cursor. C

This variable partly related to the following
variable.



   FLAGS # 5C3B (23611)


   How many times a variable takes LAST_K
new value, as many times as the fifth variable FLAGS bits set 
to 1. This important if we wish to recognize repeatedly 
pressing the same key. In turn, the third bit of the variable,

together with the contents of MODE, allows us to identify in 
what situation regarding reading the keyboard should be used 
cursor K. However, this information may be used only with the 
level of assembly. 7 bits FLAGS variable signal system

that came to execute commands with the keyboard or from the 
program. Placed in the program instruction POKE 23611, 0 abort 
her execution of message 0 OK.




   REPDEL # 5C09 (23651) and REPPER # 5C0A
(23652)


   Two of these variables must be considered simultaneously. 
The first of them determines how long you press the button to 
earn auto-repeat, and the second determines the time between 
reading from the keyboard. In both variables, time is given in 
1 / 50 seconds. On top of these variables are initialized to 35 
and 5, which indicates that a keystroke after 0. 7 sec begins 
to replicate at a rate of about 10 characters per second. In 
the process of reading from the keyboard, these values ​​can be 
reduced to 0. Giving them a value of 0, achieve the highest 
stop, continue as same as PAUSE 256. Entering into these

cell value of 1 lead to the fact that the work of SPECTRUM is 
difficult, but possible (enter any directive from the keyboard 
will require the operator excellent response and sensitivity in 
the fingers). 


   RASP # 5C38 (23608) and PIP # 5C39 (23609)


   These variables define the sound that accompanies the data 
entry. RASP sets the duration (in 1 / 50 sec) warning grunt 
when SPECTRUM no longer wishes to read the data. Initial value

RASP = 64 (1. 26 sec). PIP defines the duration of sound, is 
confirmed by pressing keys. The initial value of PIP = 0. Worth

remember that the RASP and PIP, in contrast to
most of the other system variables,
not re-initialized instruction
NEW.



   6. 3 variables of the system


   These variables allow the system to monitor the situation 
and correctly interpret the next program line. 



   NEWPPC # 5C42 (23618) and NSPPC # 5C44
(23620)


   The first of them (2 bytes) contains a number
line and the second (1 byte) makes a transition. The following 
commands cause a direct transition to the M-th instruction in 
the L-rd line, therefore, are much more accurate command GOTO L.



   POKE 23618, L-256 * (INT (L/256)):

   POKE 23619, INT (L/256):

   POKE 23620, M



   PPC # 5C45 (23621) and SUBPPC # 5C47
(23623)


   These variables contain, respectively,
row and the command being executed.
Together with a variable ERR_NR they serve to complete the 
program with the previously given message without provoking an 
actual error. To this end, the program should complete the 
instruction GOTO 9999 and in this line to put the command:



   9999 POKE 23621, L-256 * INT (L/256):

   POKE 23622, INT (L/256):

   POKE 23610, M-1: POKE 23623, K


   In this case, the program will end
message:


   M TEXT L: K.



   ERR_NR # 5C3A (23610)


   In this cell number appears 1 error has occurred and is 
signaled in a message. The contents of this byte can be 
valuable in write their own procedures for processing

errors in assembly, since immediately determine the cause of 
termination of the program. 


   E_PPC # 5C49 (23625)


   This variable (2 bytes) contains a number
current line and available for editing. Its modification will 
cause the same effect that LIST N, but without a withdrawal 
program screen. This makes it possible to select the keyboard 
lines of code for modification, and then copying it to the 
bottom of the screen and adjust without destroying the contents 
of the screen. 



   MODE # 5C41 (23617)


   This variable informs the editor of a cursor must be used in 
this moment. The system uses the following values: 0-L, C or K, 
1-E, 2-G. These numbers then used in various expressions

to assign a character code, which must be displayed as the 
cursor. Programming in BASIC can only induce SPECTRUM,

to the nearest instructions INPUT instead
standard cursor L and C used
cursor to G or E. Where E is the mode
act only for the first input
symbol. E mode turned on POKE 23617, 1.
Interesting effects provides accommodation in this
other variable values ​​(other than 1,
1, 2). POKE 23617, K for K = 3 ,..., 127 causes the cursor to 
G, although the screen does not will be printed letter G, but 
something else. POKE 23617, K for K = 0, 128 ,..., 255 the 
regime of L or C, but with a conclusion on another screen 
blinking cursor. 



   FLAGS # 5C6A (23658)


   This variable determines what is required mode L or C. Is 
responsible for this third bit FLAGS2. POKE 23658, 0 installs

regime L, and POKE 23658, 8 - Mode C. These changes get from 
the keyboard using the CS / 2. 



   DF_SZ # 5C6B (23659)


   This variable contains the number of rows
bottom of the screen reserved for
system messages and data entered from the
using INPUT. Initialized
2. Practically not used, although sometimes it can be used to 
protect programs from the interrupt. Putting it 0

caused a breakdown of the system as soon as
it is necessary to output anything
the bottom of the screen (for example, messages
about pressing BREAK). However, it is not advantageous
weapons, because at the same time makes it impossible to use 
instructions INPUT, CLS, and also can not ask a question

"SCROLL?".



   OLDPPC # 5C6E (23662) and OCPPC # 5C70
(23664)


   They contain the line number and team
line, which will be a transition in the case of issuing the 
command CONTINUE. Modification of these variables in the 
program allows to find an exact alternative to manual GO TO. In 
some situations it is better than the modification NEWPPC and 
NSPPC, etc. since the transition occurs only when meeting

CONTINUE, but not immediately after update
variables. These variables are automatically
corrected by the system whenever
termination of the program comes with a message different from 
0 OK. 



   SEED # 5C76 (23670)


   This framework of pseudo-random generator
numbers. Using SEED considered
when describing the function of RND.



   FRAMES # 5C78 (23672)


   Three bytes are the internal clock
ZX-SPECTRUM. They represent the number of PEEK
23672 +256 * PEEK 23673 +65536 * PEEK 23674 and
determine how many 1 / 50 seconds have elapsed since system 
initialization. Maximum value is 2 ^ 1.24 = 16,777,215, which

meets 3 days 21 hours 12 minutes and 24.
3 seconds. The accuracy of the timer is
about 0. 01% or less than 9 seconds per day. This
Timer is activated at a time when
SPECTRUM serves external devices
(Printer, tape recorder, a speaker), as well as in
run time in machine code, which shut down or bypass control
for masked interrupts.



   DATADD # 5C57 (23639)


   This variable stores the address of an element in
the list of DATA, which will be read by another statement READ 
(this is close to the truth but it is a good approximation of 
the two cells). Memorizing their contents and using it 
afterwards, you can get an accurate alternative command RESTORE 
K. 



   SCR_CT # 5C8C (23692)


   This byte determines the withdrawal
How many rows 1, the screen should appear the question 
"SCROLL?". If you need to output is not interrupted, then at 
least once on 255 lines must be derived in this box Record 255. 
If we need to stop before the conclusion, it is necessary

set this variable to a value less
23.



   6. 4 variables that serve Screen
TV


   This group of variables is responsible for regular 
interaction between the computer with a TV. One of them 
controls the color, others define the place of displaying the 
next sign or graphic symbol.



   BORDCR # 5C48 (23624)


   This variable contains the attributes that describe the 
bottom of the screen, as well as frame color. Under normal 
circumstances, ZX-SPECTRUM can not install the same color

for the background and the ink in the lower rows (you always 
need to see them introduced symbols). Specifiers colors in the 
list INPUT will be effective only for texts

printed at the bottom of the screen, but the color
ink for the input data is always set to 9 (white or black, 
depending on the color of the background). A workaround is to 
(Eg if the computer needs to read keyboard secret password) 
using command POKE 23624, 128 + F +64 * B +8 * P + I and

assigning letters F, B, P, I parameters command FLASH, BRIGHT, 
PAPER and INK, necessary to obtain the desired

effect. Those who are not convinced, we recommend
get this effect in another way:


BORDER 3: POKE 23624, 222: CLS.


   ATTR_P # 5C8D (23693) and ATTR_T # 5C8F
(23695)


   Both single-byte variables and store
attribute values ​​FLASH, BRIGHT, PAPER and
INK. Letter P stands for the value set by constantly relevant 
commands for the entire program, letter T - the current values 
​​set by the same most teams in the Index

appropriate writing and portraying teams.
In the absence of color in the qualifiers
lists of writing instruction, variable
ATTR_P copied ATTR_T. Way of storing information about the 
colors in a single byte is described in the chapter "Using the 
memory." ATTR_P variable can be used in BASIC program for the 
establishment of attributes of a single instruction POKE. 
ATTR_T, in turn, may be important for programming in native 
code, since commonly used procedures for the memory

ROM for setting the desired colors.


   MASK_P # 5C8E (23694) and MASK_T # 5C90
(23696)


   These byte variables are used to implement commands FLASH, 
BRIGHT, PAPER, INK with parameter 8. The value of letters

P and T in the variable names the same thing
for both variables ATTR. Establishing a bit of these variables 
in 1 means that the bit with the same number of corresponding 
attribute byte should remain unchanged. Note that Team INK 8 
establishes a 1 all 3 significant bits of the variable MASK_P. 
Modifying this variable instruction POKE can, For example, set 
to 1 only one least significant bit. Then it will be received 
by the filter effect. Unchanged in the color of ink will remain 
only the main blue component, while while others may be subject 
to change. (Note that Numbering colors quite accidental. Color 
blue - 1 red - 2, green - 3 is the main color of the mixture 
which gives all the others. In the ZX-SPECTRUM role mixing does 
add numbers corresponding colors.



   COORDS # 5C7D (23677)


   Two consecutive bytes of the variable containing the 
coordinates (X, Y) points on the screen, which has completed 
drawing last instruction PLOT, DRAW, CIRCLE.

Modifying this variable has the same
same effect as the PLOT OVER 1, K, N:
PLOT OVER 1, K, N, ie, the offset pointer screen without 
drawing any point or lines.




   SPOSN # 5C88 (23688)


   This variable (2 bytes) contains the value 33-K, 24-M, where 
K, M - coordinates last displayed on screen character.

Direct modification of these variables is difficult, since we 
must simultaneously modify DF_CC. 



   DF_CC # 5C84 (23684)


   This variable contains the byte address to
screen, which to begin displaying the next character 
instruction PRINT. Modified only with Z_POSN. Much easier to 
apply the command PRINT AT K, N.




   SPONSL # 5C8A (23690) and DFCCL # 5C86
(23686)


   Variables, similar S_POSN and DF_CC,
describing the bottom of the screen.



   P_FLAG # 5C91 (23697)


   Variable containing information about the print mode and 
drawing on the screen. Describes the regimes established by 
using the BASIC INVERSE, OVER, INK 9 and PAPER 9. Odd bits 
correspond to the permanent assignment of these regimes, even 
temporarily. 

    __________________________________

   | | Temporary | permanent |

   | | Bits | bits |

   |-----------|----------|-----------|

   | OVER 1 | 0 | 1 |

   | INVERSE 1 | 2 | 3 |

   | INK 9 | 4 | 5 |

   | PAPER 9 | 6 | 7 |

   |___________|__________|___________|


   If you need to install permanent
OVER 1: INVERSE 1: INK 9: PAPER 9,
instead of 4 teams, only one POKE
23 697 2 8 32 128.


   NOTE: The names of system variables
are not recognized by BASIC. They were introduced by the 
authors of the operating system and taken into all the 
literature related to ZX-SPECTRUM.





Other articles:

Introduction - On the control interface of the newspaper.

Assembler - An interesting trick with the assembler.

roof was demolished - DI: HALT is not always caused a breakdown of ... Santa Claus.

fun begin - The main event of 1996. Dictionary programmer.

own opinion - IMP talks about the development of Russia's ZX-demoscene.

What are heard behind the hill - What is now doing all the known Western manufacturers software on Speccy? ..

Hour ottyaga - Notes of a Terminator T-1000.

Small news - What happens to the Speccy in Belarus? ..

Form - The survey goes on ...

Fantasy - A fantastic tale "Ice and Flame" (continued).

Prikolchik - Prikolchik's Navapolatsk?. What letter comes to us in the laboratory.

Description - Description, prohodilka game BLINKY'S SCARRY SCHOOL.

Presentation - REALSOFT is a strategic game Technodrom.

Ottyag - have a good time can be different. Book of problems - "puzzles" math.

Programmers - On additional functions TR-DOS 5.04.

Programmers - On the music format modules Sound Tracker Pro and source player.

HARDWARE - Mode switch Profi / Pentagon.

Tricks-2 - How to throw a screen to one INT.

Tricks-2 - On the correct handling Retry / Abort / Ignore in the TR-DOS.

interesting letter - Letters from readers containing two different things: - If you burn a floppy drive on the buggy;

Presentation-2 - Description of the TEXT PRINT v1.2.

Humor - A story about Stirlitz.

Humor - Stirlitz: Elephants go north.

Book - Secrets ZX-Spectrum: TOC.

Book - Secrets ZX-Spectrum: Keyboard.

Book - Secrets ZX-Spectrum: Editor.

Book - Secrets ZX-Spectrum: ZX-BASIC.

Book - Secrets ZX-Spectrum: Computer Arithmetic.

Book - Secrets ZX-Spectrum: memory usage.

Book - Secrets ZX-Spectrum: BASIC system variables.

Book - Secrets ZX-Spectrum: Channels and Streams.

Book - Secrets ZX-Spectrum: System Procedures.

Book - Secrets ZX-Spectrum: Bugs in the System.

Advertising - Advertisements and announcements ...

Afterword - That was not included in this number.


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

Similar articles:
HARD and SOFT - The problem of the thirteenth drives.
Igroskop - Computer c super great graphics "Midnight Resistance"
From the Editor - A humorous newspaper ...

В этот день...   22 July