Echo #03
31 марта 1997 |
|
Book - Secrets ZX-Spectrum: memory usage.
Chapter 5. And the S P O R L O W B A H & E N A M I T I After turning on the computer in the network launches automatically placed in the ROM at 0. It checks the amount of allowable memory divides it into different blocks and assigns a system variable initial values. The diagram below describes section of memory. Volume from 0 to 16383 is located in ROM, the rest in the RAM. Only some units have a permanent position, while others may move in memory and their current addresses are stored in the relevant system variables. The numbers at the end Some areas represent pointers the end of the field and are always present there. ______________ _________________________ | | | | | ADDRESS | AREA | END | |______________|______________|__________| | | | | | # 0000 (0) | System | | | | Procedure | | | # 3000 (15616) | Prototypes | | | | Characters | | | | Codes 32-127 | | | # 4000 (16384) | Screen | | | # 5800 (22528) | Properties | | | # 5B00 (23296) | buffer principle-| | | | Tera | | | # 5C00 (23552) | System | | | | Variables | | | # 5C86 (23734) | Map micro-| | | | Drive | | | CHANS | Information | # 80 (128) | | | Channel | | |--------------|--------------|----------| | PROG | B E J P & K | | |--------------|--------------|----------| | VARS | Variables | # 80 (128) | | | ZX-BASIC | | |--------------|--------------|----------| | E_LINE | buffer | # 80 (128) | | | Editor | | |--------------|--------------|----------| | WORKSP | Buffer inst-| # 0D (13) | | | Struction INPUT | | |--------------|--------------|----------| | | Working | | | | Region | | | | ZX-BASIC | | |--------------|--------------|----------| | STKBOT | Stack tracing-| | | STKEND | oscillator | | |--------------|--------------|----------| | SP | Free | | | | Region | | | | Memory | | | | BASIC | | |--------------|--------------|----------| | ERR_SP | Machine | | | | Stack | | |--------------|--------------|----------| | RAMTOP | Stack Address | # 3E (62) | | | Return | | | | GOSUB | | |--------------|--------------|----------| | | Free | | | | Region | | | | Memory | | |--------------|--------------|----------| | UDG | Prototypes | | | | Characters, | | | | Certain | | | | Users-| | | | Field | | | P_RAMT | | | |______________|______________|__________| 5. 1 images of characters Form of printed characters with codes from 32 127 (8 bytes for each character) fill 768 recent cell ROM. They are coded in the same form as the characters are defined by the user. Signs of a mosaic graphics (Codes from 128 to 143) are constructed each times. Start address this area 256 is stored in the system variable CHARS. 5. 2 Screen This area is intended for storage information about each point of the screen, or rather about whether she should be in color ink or background. 6144 bytes in this block allow address 49152 different points (1 byte describes 8 points). They are arranged in table of 192 rows and 256 columns. For graphic designs BASIC available Only the top 176 rows. Each graphic symbol is displayed in the field of 8x8 pixels. This allows you to display text in the format 24 rows of 32 positions. The bottom two text rows are reserved for system messages and workspace editor. Interesting way in which this region transferred to the screen. Unfortunately, successive 32-byte do not describe the sequence of image line on the screen, 256 consecutive bytes do not describe operator of the text. Placing graphics line (line) is absolutely the opposite, and in terms of ZX-BASIC similar to the invention a madman. This may best be seen when reading the screen with tape. Here we confine ourselves to examples that allow to count text and image coordinates on the screen address. Byte containing a graphical point of coordinates (K, M) (point (0, 0) lies in the top left corner of the screen above the two lowest text operators) on the screen has Address: 16 384 +32 * (INT ((175-M) / 8-INT ((175-M/64 * 8 +8 * (176 * M-INT ((175-M) / 8) * 8 +64 * INT ((175-M) / 64) + INT (K / 8). The position of bits in a byte is calculated as 8-K + INT (K / 8) * 8. In turn, the addresses of text characters count on the model: 16384 +2048 * INT (K / 8) +32 * (K-8 * INT (K / 8)) +256 * M + N, where K denotes the number operator (0 to 23), N is the number of columns (0 ... 31), in turn, M is the number graphic lines (lines), forming long symbol (0 ... 7). The zero is taken, lying on top of the block mark the line. Origin for instructions, writing signs placed in the top left corner of the screen. 5. 3 Attributes (22,528 ... 23,295) In this area, information is stored placing flowers on the screen. Lowest unit surface, the color of which can be modify, a field unit mark the size of 8x8 pixels. For such a field You can define a background color, ink, blinking. A choice of 8 colors available: 0 - black 1 - Purple 2 - red 3 - blue 4 - green 5 - Blue 6 - Yellow 7 - white Each color can act in two colors: regular and intense (BRIGHT 0 1). All information concerning the identity sign field with encrypted in a single byte: _______________________________ | | | | Bits | Value | |________|______________________| | | | | 7 | Blink | |--------|----------------------| | 6 | background intensity | |--------|----------------------| | 5 | | | 4 | Background color | | 3 | | |--------|----------------------| | 2 | | | 1 | Color Ink | | 0 | | |________|______________________| To set the desired attributes of a field and determine what value should be placed in the corresponding byte is better to use an example: 128 * F +64 * B +32 * P + I, where F - determines flicker (FLASH 0, 1) B - specifies the background color (BRIGHT 0 1) P - is the number of background colors I - is the color of ink Specify the address byte, described attributes of the sign field with coordinates K, M, is calculated as follows: 22 528 +32 * K + M. 5. 4 Buffer printer In this area, to collect data that will be sent to the printer. Print, in fact, follows the completion of this Buffer (256 bytes or 32 characters), or after the symbol "end of line" (CHR $ 13). If printer is not connected, then the region will not used by the system and can be used for other purposes. 5. 5 Card mikrodrayva This area is used only when connected to SPECTRUM ZX-INTERFACE-1. The "naked" computer, this card is not there physically and CHANS = 23734. 5. 6 The ZX-BASIC (PROG to VARS-1) After system initialization, without external devices, this unit starts at address # 5CC8 (23,755). It BASIC program text is stored. Private strings in computer memory have the following form: ___________________________________ | | | | | | 2 bytes | 2 bytes | Length | 1 byte | | | | Text | | |-------|--------|------|-----------| | Number | Length | | # 0D (13) | | String | text +1 | TEXT | Code <ENTER> | |_______|________|______|___________| In the case of a line number deviation from the rules and the first here is a byte, and then junior. All the keywords that appear in the text are encoded by single characters. It is an interesting way to store numbers in the program. The sequence of characters representing the sequence of digits, always placed a control character CHR $ 14, followed by 5 bytes containing the binary representation of the numbers. During the program output on the screen, These 6 additional bytes are omitted. This explains why some programmers prefer to write VAL "17" instead of just 17. The first of them actually zanimaet 5 bytes, and the second 8. We are talking about saving memory. During the execution of the program, turn, passed the characters that recorded the number and uses 5 byte binary representation. This allows you to hide the correct value of certain numbers (such as starting address procedures in machine code) from the "curious". In this case, you must determine the address internal representation of the number and POKE instructions specify its desired value. In the derivation of the text on the screen and will continue to appear old representation of the number is no longer associated with the written him a binary number! Applying this technique must be remembered that each extract a row at the bottom of the screen and return it to the place, even without any modifications, changes the internal representation of each number in the text, assigning them the values visible on the screen. Among other interesting tricks give two more. If the first line of the program, cells containing the number, put number 0, then an operator can not be copied to the bottom of the screen editor area, and then modify it. At the other end of the program possibly other Gizmo. There's update line 9999 REM and after establishing its address in both bytes containing the number, place value 255. The first result of this will be borne by program output to the screen. We modified the string does not appear. The second effect is much more valuable, there will be at try reading the program from a tape instruction MERGE. SPECTRUM offended user-friendly and does not respond to any keys. 5. 7 variables ZX-BASIC (VARS to E_LINE-2) In this area, the system stores all the variables that are initialized as a program or via the keyboard. An alternating sequence appended at the end of this area (all subsequent blocks will automatically shift) and remain there until the area is not cleared. Exceptions are simple text variables: when some of them are modified, and removed the previous version (which is accompanied by the necessary movement of other blocks of memory), and the new appended at the end of this area. Then the same happens in the new array declaration. Storage method depends on variables types. In the ZX-BASIC there are 6 different types of variables, denoted by numbers from 2 to 7: 2 (010) - simple text variables; 3 (011) - a simple numeric variable odnoliternymi with names; 4 (100) - numeric arrays; 5 (101) - a simple numeric variable mnogoliternymi with names; 6 (110) - landmark arrays; 7 (111) - variables that control the cycles FOR ... NEXT. In all cases the first byte description variable contains the type and number first characters name. Method of placement this information is in one word, as follows: ____________________________________ | | | | | | Type | Number of characters | |----------|--------|----------------| | Bit | 7 6 5 | 4 3 2 1 0 | |__________|________|________________| Note that bits 4 ... 0 contain the serial number of the letters in the alphabet, but not its code. Own code, we obtain adding to the number # 60 (96). Keeping the names of SPECTRUM automatically replaces the variables big letters small, and ignores all gaps. The contents of the following bytes depends on the type of variable. A simple text variable length description of N + 3 bytes: ___________________________________ | | | | | Type and | N = length of the text | text | | Literature | (2 bytes) | | |________|__________________|_______| Simple numeric variable with odnoliternym name, description length 6 bytes: ____________________________________ | | | | Type and literature | Contents (5 bytes) | |______________|_____________________| Numeric array description length N + 3 bytes: ______________________________________ | | | | | | | Type | N = length | K = number | 1-th ... K-th | E-you | | And | description-| index-| index | of | | Literature | of 3 | owls | (for 2 b.) | 5 b. | | | (2 b.) | | | | |______|_______|_______|_________|_____| Simple numeric variable with mnogoliternym name, description length K + 5 bytes ________________________________________ | | | | | Type and literature | 2nd sign ... K-th symbol | The values-| | | Name name | chenie | | | | 5 b. | |____________|_____________________|_____| Second and subsequent name characters are stored as codes of the characters. The last byte is the name of the eldest bits are always set to 1, which allows you to always recognize it. Landmark array, the length of the description of N + 3 bytes: ________________________________________ | | | | | | | Type and | N = length | K = number | 1-th ... K-th | E-you | | Literature | description-| index-| index | of | | | Of 3 | owls | | | | | (2 b.) | | (At 2 b.) | (1 b.) | |______|_______|________|_________|______| Driven cycles of variable length descriptions of 19 bytes: ________________________________________ | | | | | | | | Type and | The value-| The value-| Step = Z | K = | Number | | Literature-| of | of | | Number | FOR in | | Pa | current-| finite-| | line | row-| | | Schee = X | Noe = Y | | | Ke +1 | | | (5 b.) | (5 b.) | (5 b.) | (2 b.) | (1 b.) | |_____|______|______|______|______|______| The last byte of the field variables as pointer always contains the value # 80 (128). 5. 8 buffer editor (E_LINE to WORKSP-1) In this region, hosted a program line or sequence of directives to direct performance during their keyboard input. Input characters are copied to the bottom of the screen. After clicking <ENTER> computer checks the fidelity Text and take appropriate action. 5. 9 Buffer instructions INPUT (WORKSP to STKBOT-1) In this buffer is initially introduced data read command INPUT and only after pressing <ENTER> should convert them. In this area, as SPECTRUM performs some operations that require working memory (eg, coupling of symbolic variables). 5. 10 Stack Calculator (STKBOT to STKEND-1) Workspace system routines perform most arithmetic operations. 5. 11 Free Region of BASIC (STKEND +1 to SP) This memory block is free, but is designed for the needs of BASIC. Working areas at both ends of the block replenished at its expense. The data posted here may be subject to destruction without warning. Before the onset of action, requiring increased some of the working units, SPECTRUM checks whether there will be in this unit at least 80 free bytes on the possible needs of the machine stack. A negative test result signaled by the message 4. Address of the end this field is stored in the register of the processor Z80, called the stack pointer (SP) and available from the BASIC system. 5. 12 Stack Machine (SP before ERR_SP) The stack is used for processor Z80 current storage of various data, address, etc. This area is absolutely useless for programming in BASIC. 5. 13 GOSUB stack return addresses (ERR_SP +1 to RAMTOP) Another stack, this time for storing the line number and position in her statement GOSUB. These data needed for the team RETURN when non-emergency exit from the subroutine. Reusable performance or GOSUB RETURN causes shift the machine stack, addressable through ERR_SP to 3 bytes up or down. Therefore, modifications recommended by a special unit caution. 5. 14 areas of free memory (RAMTOP +1 to P_RAMT) The block is really free memory and secure in the sense that its contents are not available for BASIC system and can be modified only upon request user by using POKE. Even directive NEW does not violate this area. In principle, it is used to store programs in machine code or country-specific data for which BASIC variables are not suitable. 5. 15 Images of characters user (UDG to UDG +167) After system initialization, the block begins with a cell having an address RAMTOP +1 = # FF58 = 65,368, and ends in P_RAMT = # FFFF = 65535. The address of this block Memory can be obtained by performing manual USR "A". This area is used for storage outlines of graphics, user-defined. Determination of the unit symbol consists of eight bytes, describing the state of each point in the sign field size 8 * 8. For example, define a graphic symbol and place it in the UDG so that he displayed after pressing the mode <O> G. The first step is design form a new label in the box 8 * 8. In the field, intended to paint, placed 1, and let 0. Each filled so the operator is treated as 8-digit binary number. The resulting set of 8 numbers describes the shape of the projected symbol: 0 0 0 0 0 1 0 0 4 0 0 0 0 1 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 60 0 1 0 0 0 0 1 0 66 0 1 0 0 0 0 1 0 66 0 0 1 1 1 1 0 0 60 0 0 0 0 0 0 0 0 0 Now we introduce it into the computer. Simply just do it with the help of the program: 1910 DATA 4, 8, 0, 60, 66, 66, 60, 0 20 FOR I = USR "0" TO USR "0" + 7 30 READ A: POKE T, A 40 NEXT I After her performance in key <O> G mode displays a coded symbol. In a chain of characters it will have code 158. The data in row 10, you can apply also in binary instead of decimal, using the BIN. This requires more writings, but it is much easier all the modifications that we determined the sample. 168 bytes of UDG allow you to store up to 21 different new character. Their codes placed in the range from 144 (A) to 164 (U). After system initialization, this block contains sample forms large letters Latin alphabet.
Other articles:
Similar articles:
В этот день... 21 November