Optron #36
16 июня 2000

Likbez - assembler - a view from afar: memory ZX Spectrum.

<b>Likbez</b> - assembler - a view from afar: memory ZX Spectrum.
       Assembler - a view from afar


               Continued.

    Beginning at | | 20, 21, 24, 25, 28-30,

                32, 33, 35


  {} Infarh, 2000


  My friends, I am saddened! All available
Assembler komandy we have studied ...

  But do not be discouraged! From the study of
language, we go directly to programming. In order for this 
process to be successful, need to start

how to learn ...


       Memory Allocation Speccy


  So, memory ... With the address # 0000 and at # 3fff 
inclusive located ROM on your computer. There stitched 
operating system (OS). Naturally, in its composition

there are many useful procedures that
try to seduce you and make use of yourself in your own 
programs. Of course, this is quite acceptable. But not always 
... 

  OS - a program highly reliable, versatile. But beyond these 
advantages, we have pay brakes work and the complexities of 
using the above Rom. Personally, I have this state of affairs 
is not satisfied, and therefore all the necessary tools I

I do, if possible, myself.

  But it's the lyrics, we extend the lesson. After
ROM is an area of ​​memory reserved
under the screen. It starts at address # 4000 and
ends with the address # 5aff. Moreover, to
address # 5900 is a region of graphics and
Further - the attributes.

  Then there are the memory occupied by variables of the OS. 
The sizes of these regions vary depending on various factors, 
however, As a rule, you can racschityvat that

to address # 6000 at # ffff - free
space.

  So, if you choose to work
completely independent of the OS, you can safely use all the 
RAM. However, in order to be able to

sometimes refer to the operating system, preferably below
# 6000 does not go away. Do not forget that
that a certain amount of memory you need
allocate to the stack. I, as a rule, the most suitable 
alternative in which the value The SP register at the beginning 
of the program is set to # 6000. This made it possible to use 
those bytes that have remained between my program and system 
areas. 

  By the way, usually when you're in
shell editor and run the program
out from under him, the stack will be installed so
that problems in the work for you, as a rule,
not arise.

  But enough! It is time to try to write
some kind of program. Upload your editor.
At the same time remember that different editors
have some differences. When I give examples, keep in mind what 
is meant Editor XAS. If you use others to make adjustments 
according to its specificity. 

  Thus, the beginning of the program. Typically, this
operator ORG, which indicates to the editor
from any address you want your code
received after the compilation of your text.
So feel free to put the first line of your
program ORG # 6000.

  Now we shall understand what resources you
have, if you - Spectrum 128.
Of course, it has the same memory area
that the 48th version. But besides them, you can use the 
so-called "Memory pages". To better understand this look at the 
scheme: 



               Page 7


             Page 6


           Page 4


         Page 3


       Page 1



     page 0


                      # C000


     Page 2


                      # 8000


     page 5


                      # 4000


     ROM 128 (16k)


                        # 0000

       ROM 48 (16K)

                        # 0000


  Before you - a model of paging memory.
Figures on the right show the start address of memory areas, 
which we consider to order.


  Early ROM is located.

  Next - the screen area, the system variables and everything 
else that will fit up to address # 8000. This page has been 
vacant memory | 5. 

  Then - Home | 2 (# 8000 - # BFFF).

  The above-mentioned pages are always
in its place, and therefore no problems with
they do not. But that's behind them comes the
interesting ...

  Memory area with a # C000 on # FFFF is designed to display 
pages that are optional. When restarting you see the page | 0, 
instead of which you can connect page | | 1, 3, 4, 6 or 7. 
Specificity is that can be connected to only one page, and while

it is active, all the rest reside in
the shadows. "One can draw an analogy with an alternative set 
of registers (command EXX, remember?). Only there were two sets 
of registers, and here you can see six pages. For their shift 
is port # 7FFD, which sends control byte. 

  Before we give a detailed explanation of each bit of this 
port, some general information about the screen. In the 48th 
version of the area of ​​the display memory is starting at 
address # 4000 (page 5). For 128 Spectrum of the situation is 
similar, but ...


  Area of ​​memory in bytes # 1B00, located in a page | 7 
starting at address # S000, can be used as an additional

screen. His organization will be exactly
correspond to the normal screen, in all
except, of course, the address location.

  And now - we describe the port:


  Bits D0-D2 determine which page
will be displayed from the address # S000.

  Bit D3 charge of the active screen. If
it is set to "0", active standard
screen (at page 5).

  Bit D4 controls the current ROM. He, being
set to "0" connects the ROM-48 and
setting it to "1" - ROM-128.

  Bit D5 is blocking the port. If you send in
it "1", a port is disabled until the next
Reset'a completely unavailable.

  Bits D6, D7 do not cause problems: they
128th version is not involved.


  And finally, something programmopodobnoe:


        ORG # 6000
; Activating ROM-48, Screen | 1
; Include Page 0

        LD BC, # 7ffd

        LD A, # 10

        OUT (C), A
, And read the first byte

        LD HL, # c000

        LD A, (HL)
; Change it and put on
And the same place, but in page 1

        CPL

        LD E, A

        LD A, # 11

        OUT (C), A

        LD (HL), E
; Rebuilding Page 0

        LD A, # 10

        OUT (C), A
; Its first byte of the compare
; With a modified previously

        LD A, (HL)

        CP E
; Analyzing the results

        JR NZ, mode128
; Mode 48

        ...

        ...
mode128


  Thus we get a program that determines whether the computer on 
which it is running, the extended memory. The first byte of 
page 0, we invert and place in page 1. Produce switched back 
and compare proinvertirovanny byte available. If they are 
equal, then switch has not occurred and computer, most likely 
the 48th. Otherwise, proceed to the mode of 128th memory.


  Let us now examine the additional screen. For starters just 
take a screen file and place it on the drive name

say, "screen.C". In order to implement a code block from the 
disk into the code program, use the operator "LCODE".

Write the following:


        ORG # 6000
; Connect page 7

        LD A, # 17

        LD BC, # 7ffd

        OUT (C), A
; Copy of it loaded the screen

        LD HL, scr

        LD DE, # c000

        LD BC, # 1b00

        LDIR
; Rebuilding Page 0
, And activating the second screen

        LD A, # 18

        LD BC, # 7ffd

        OUT (C), A
; Not prevent a slight delay
, For the vision of the result

        LD BC, 0
wait

        DEC BC

        LD A, B

        OR C

        JR NZ, wait

        RET
scr LCODE "screen"


  If all goes well, you get the picture that you put in
second screen. It will last as long on
how much is enough delay loop. After this
control is passed to the editor and it will automatically 
restore the screen | 1. 

  Pay attention to what to display | 2 does not necessarily
have an active page 7. It is enough that mode is selected the 
corresponding bit of port. 


  Well, this one will suffice. See you soon!


          To be continued ...







Other articles:

4 kilobytes - the contents of the issue.

Meet - an interview with Aleksey Ivanov - the coordinator of an international network spektrumistov ZXNet.

Likbez - assembler - a view from afar: memory ZX Spectrum.

Opinion - Speaking of computer festivals ...

Poems - "Blues civil war."

Rekalama - advertisements and announcements in Lviv.


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

Similar articles:
a rest - Nemo tells the story of VirtualETnoy reality in Russia.
Toolkit - Instructions for use software package "ZX-WINWORD", intended for the preparation of illustrated texts.
Miscellaneous - The editor of shipment for ELITE-3.

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