Systems - Programs with HDD support, or "Linux" for Spectrum with a screw (or SD card).

Info Guide #11
Shmatrix
 Programs with HDD support,
   or "Linux" for Spectrum with screw
             (or SD card)
ZET-9 

 Dedicated to all spec coders.

   So, A MIRACLE HAS HAPPENED!!! You have connected
Winchester to your Spectrum and now ho─
you want to make a program (and more than one) that will ─
Let's use it (hard drive).

   We have the following initial data:
 -Spectrum with a connected IDE controller─
rum and hard drive; 
 -free time for coding on ent
Spectrum. 
   We want to receive:
 -minimum - stir up a program for the screw
(well, this is for beginners...); 
 -maximum - create SOMETHING - like an algorithm─
rhythm of software development and use for 
screw and actually according to this algorithm co─ 
create some software that would allow for─ 
use your hard drive with maximum efficiency─ 
stu. 
   How can you effectively use
use a hard drive?

   Some people think that it is effective to use─
you can call a hard driveonly if you have
on the screw of a certain “AXIS”; others as
"stumbling block" is proposed to be created
some filesystem which, being
placed on the hard drive, automatically under─
performance (i.e. almost the same as
that the efficiency) of the hard drive is unprecedented─
low heights.
   Individual comrades, from among those
who were unable to work with the screw on
Spectrum, they don’t consider a hard drive to be anything...
something special (although he, the Winchester, is undoubtedly
this is exactly whatspecial is), perhaps─
is important because they think that the speed
The work of the screw on the Spectrum is approximately equal to
speed of operation with the drive, and if sometimes
and exceeds it, then insignificantly.
   Let's not trust anyone, but try it ourselves
figure out what a hard drive is
Spectrum and what it can give Spectrum in
in terms of ease of use.
   Firstly, it's speed.  Secondly...
This volume is, first of all, freedom.
choice. I'll give just one example. You can
invent different packaging algorithms in the form─
orolikov and then develop a super-pro
procedures for decoding packed cad─
ditch "on the fly" to show video in re─
real time without “jerks”, and at the same time
one video will take, for example
20 MB. Or you can just store it unpacked─
new video (and, unlike the previous
option - together with unpackaged digital
sound) and the simplest procedure to read ka─
shoot from the screw directly onto the screen - and it will be
work even on Spectrum-48K. So what aboutthat such a video will take
hundreds of megabytes? We have these megabytes on Vi─
nte could be 40,000, 80,000 or even 128
thousand - enough for half a thousand videos.

   For our experiments we will use─
take the approach of a “pure Spectrum encoder”
- but we will not limit ourselves to this approach only
coding, but let's try to use others
approaches that have been and are being used
hackers are always and everywhere:
 -no restrictions, except those that
we will limit ourselves (for example, we ourselves 
we create a restriction that our programs will 
work on Spectrum-128 and higher, and on 
Spectrum-48 will not); 
 -no rules except those we
we will come up with for ourselves (for example, the rule is not 
use commands like OUT (C),0 - like this 
how they don't work on the Z84 processor); 
 -nothing is impossible - no matter what
someone said that this is exactlythis
can't be done, it just means that 
exactlythisnobody has done yet. 

   Before we start coding, let's do a quick review─
a quick excursion into the history of the Spectrum Co─
dinga. Let's consider what types of programs were created
coders for the last 10-15 years, and also briefly
let's touch onrelationships between coders and interactors
I see their creations (programs) with various
Spectrum configurations and operating
system (if such configurations and OS
existed at that point in time that bu─
dem consider).
   Programs created by coders can beconditions─
but divided into three types:
 1)Where the axis is but.
Such programs only require from the system 
one thing is to load the program code into memory and 
run it, and then the program will do 
all by herself. About two thirds of such programs 
(66%) of the total. 
 2)Prog + kernel.
Such programs are approximately one third (33%) of 
total number. 
 3)Full OS.
Such programs make up the remaining 1%. 

   All three are expected to be used─
rianta programs. The user can select
guess what mode will be loaded according to your mind─
lchaniyu.And he can change it as often as
he will need it.

   Now let's look at each in more detail
item.

                    1.
                Axis - but 

   These are programs that:
 -are stored on the screw in the form of files;
 -loaded from the screw into memory; -load files from the screw themselves;
 -write processed data to files
on the screw. 
   The first question immediately arises - who
loads programs from the screw? - Who is loading it?
programs from a floppy disk? - Special type program
"Booth." The functions of the boot include showing sleep─
juice of programs located on a floppy disk, and
give the user the opportunity to choose from
this list is some kind of program. So,
I need to make a similar boot, but for a screw.
Such a boot should be able to show a list
programs on the screw, and after pol─
The caller uses the up and down buttons to select
program and pressEnter, the boot should load
program to memory.
   That is, first we need to place
There are two files on the screw - boot and prog.
   Now the question arises - who will download─
zit in memory but? - Who loads it into pa─
crush boot from floppy disk? - Some software located─
new in ROM and launched after start/reset─
sa.
   This means that we need to place the spec in the ROM
cial bootloader, which after reset
will load into memory some code from zag─
handle area of the screw, and this code, being
loaded and running, the prog-boot will load itself,
located on the screw. And now Booth will allow
load our program from the screw (and in the long run─
shem - select and launch one of many
prog).
   To those whothe ROM has Gluk firmware
6.x, you don’t need to do anything, because in this 
The firmware already has the itemHDD BOOT. Owner─
ts KAY-1024, ATM-2 and Scorpios with ProfPZU
can also use ready-made loaders
from ROM. And the rest can be offered about─
sewing that needs to be sewn instead of Basic-
128, it contains Real Commander 1.96 (launched
when you press reset) and the bootloader from the screw
(launched by pressing reset+space).Or
add boot to your favorite ROM yourself─
chick from the screw. For Nemo IDE it takes135
bytes.

   Now two more questions arise: how
put the code, boot and program on the screw, and then what?
this is for the code that will be loaded loading─
chick?
   This code should be able to load from the screw
directory, find our boot there, upload the boot to
memory and transfer control to it. That is, this one
the code must contain the screw driver
and the file system driver that is on Windows─
those
   Where to get screw and file drivers
systems? Theoretically, you can take drivers
from the iS-DOS system, CP/M or from the program
WDC, but to use these drivers 
first you need to get permission from their authorities─
tors.Cool Coders themselves can develop
any drivers, but we are at first
we will use ready-made drivers that
can be taken from the DNA OS system.
   In this way, the previous
blowingquestion - we use the DNA system, and
Let's write our program and boot onto the screw, and in quality─
Containing code with drivers in the boot volume─
Lastly, let's write down the core of the DNA system.
   In the future we will be able to use
another solution. In the meantime, for our experiments─
this will be enough for the cops.

   More details about the programs of the 1st
type:
   After the program is loaded, it is for─
is allowed, and if she does not need to contact
disk devices, then this is the mission
system, the role of which for type 1 prog
playsSHMATRIX (boot program), completed.
 But what to do if the program wants to display
go to disks (for example, HDD) and boot─
download/save one or more files?
This type 1 program requires a driver
screw and file system driver, which
on the screw. Because there are several options─
connection of the screw, it turns out that
the program cannot get by with just one va─
driver version.
   What approaches can be used
to solve this problem?

   Let's look at what coders used to
TR-DOS programs - using the example of programs, ra─ 
working with different memory models. 

   First we used one universal
driver, which itself tried to determine,
which of the upper memory expansion schemes
used.
   As a rule, not everyone was identified, otherwise─
just a few of the most basic schemes. This
explained by the fact thatit was impossible in the case
basically find out how many circuits there are─
no (new schemes were constantly invented
connections), and for existing circuits, according to
which the encoder had the necessary information, not─
It was impossible to check the driver due to─
the presence of this scheme.
   Another drawback was glitches, which─
Some were observed when the driver was running on
"non-standard" schemes, and sometimes even "hundred"
standard."
   A similar approach was also used, with uni─
universal driver, but without automatic─
th definition - in this case use─
lyu was offered in one way or another by choice─
change the memory model manually (for example, via
menu, or using the disc doctor).

   Subsequently, the most uni─
universal method: the author made the drivers himself
for the most common schemes, and
designed each driver as a separate
file with the same structure, and in the document─
tation to the program was provided by the source driver─
faith (of one or all) with comments for
so that owners of "non-standard" schemes
extensions could make their own driver. For
setting up such a program for operating mode
using a specific race scheme─
it was enough to copy the extension onto di─
sketch the program itself and immediately follow it
the required driver.
   When starting the TR-DOS program, first
loads the BASIC part, inside which
the bootloader is located and transfers control to it─
laziness. The bootloader must load the remaining─this whole part of the program. In this case, for─
the loader loads for one (several) seconds─
more torus(s) - depending on length
driver), and transfers control to the loaded─
no program. At the same time, I already find in my memory─
the required driver is installed, and the program immediately starts ─
starts using it.

   If we now try to spread
the last option discussed above
for our case, we get as a result
almost the same. That is, a program with a set
HDD drivers, for which you can configure it yourself
the user will select one time at the beginning─
select the required driver for the connected IDE-
controller and HDD. (For example, by disintegration─
forging a driver from the driver archive, preparing─
made by the author of the program.)
   But here the next problem arises. How
the program loader will be able to load the base─
the main part of the program and the driver itself? For
Everything was clear for TR-DOS programs - loading─
chick accessed the procedures at#3D13
or used the entry point #3D2F. For
programs loaded from the HDD, no pro─
There are no procedures or entry points.
   You can download the main part
assign the program and the required driver to
system, and for programs of the 1st type as a
All systems areSHMATRIX (prog-boot).

   Then the final version will beyou─
look like this (however, no one bothers you every time)
home to come up with your own “graduate─
linen" option):
   Booth(SHMATRIX or whatever the encoder writes)
loads the program executable file from
name (for example) PROGRAM.COD, at address
#6000, and if the file is larger than 40960, then
first part from the file - part length 40960
byte.
   Next, the boot loads files with the names:
PROGRAM.C00 (to page 0),
PROGRAM.C01 (to page 1),
PROGRAM.C03 (to page 3),
PROGRAM.C04 (to page 4),
PROGRAM.C06 (to page 6),
PROGRAM.C07 (to page 7),
 in case one or more of
these files exist in this directory.
There may be more if there are more pages.
memory.
   In one of these files (for example, in
PROGRAM.C00 ) will be the code
block containing HDD, CD or DVD drivers
drive for a specific IDE controller,
connected tocomputer on which
this program starts. These drivers
the program will use to download
files that the program must process
(from HDD, CD/DVD), for recording results
processing into files located on the HDD and
to download additional parts of the program─
frames that do not fit in memory (if this
necessary for the program).
   In other files (PROGRAM.C01-C07 )
pieces of the program (gra─
fika, music, codes, texts, etc.), which
will be immediately loaded into memory by boot, and
the program will not have to do unnecessary
"body movements".
   If the program does not need to perform operations
walkie-talkie with files, then a code block with a driver─
she doesn't need faith - and at the same time the file
PROGRAM.C00 will be missing.

   Where will the filePROGRAM.C00 appear in ka─
log with the program? The author of the program himself
prepares several options for this
file: for IDE controllers Nemo, SMUC,
ATM, and the user himself will rename one 
from these files corresponding to that IDE-
the controller it is using.
   Depending on the type of program the author
can only be added to the code block by a driver─
HDD faith or only CD/DVD drivers, or both
both. Also if in the future there will be
a new driver has been created(for example, for SD card─
dots) - then it will be enough to add it
(with the name PROGRAM.C00) to the directory with prog─
ramma, and the program will work with it.

   This option is also possible. In case
if the program takes up a small amount of space,
the author may not create this file, but just
place all drivers inside the main block─
programPROGRAM.COD. When you start the pre─
offer the user to select an IDE control─
ler from the list of Nemo, SMUC, ATM and further
work with them. But this option is inconvenient
because it will not be possible to add a driver
user without recompiling the program.

   And there may also be a fantastic brew─
ant, when the code block with drivers will be
also contain file system drivers─
we, for example, FAT16/FATЗ2, and then use─
bodies who want to use another
file system, compile the code block
with a driver, such as a file system
NTFS (or iS-DOS), will compile their version
SHMATRIX (with the driver for this file system─
we), and the program will work successfully with
files located on these file shares
systems.

   Now a lyrical digression according to us
topic called "one evening in the life 
speco-coder": 

   The ROM bootloader loads from the hard drive
48 sectors of 512 bytes,starting from the sector
2 from the beginning of the hard drive (if you count sec─
torus from scratch, i.e. the very first sector on
on the hard drive - this is sector 0). In these seconds─
The torah must contain executable code. Let's write it down
core there.
   At startup the kernel loads the sh file and
launches it.
   Load ALASM from a floppy disk, load
filesave2hdd, compile and run - in
As a result, the kernel will be written to the screw.
   So, now after resetting and pressing the button─
pc the following happens: the bootloader will load─
zit the kernel, and the kernel will load sh and run
him. The sh file is not yet on the screw.
   Create sh in Alasma.
   After running sh, the standard files
input(1) and output (0) are already open. Adding─
let's display the invitation on the screen (re─ sign
grids), then reading from file number1
(this is keyboard input) and writing to a file with
number0 (this is output to the screen):

L1 LD A,1
 CALL read
buf LD HL,buf1
CP 13
 JR Z,ENTER_Y
LD (HL),A
INC HL
 LD (buf+1),HL
 LD A,0
 CALL write
INC C
CP 32
 JR NZ,l1
ENTER_Y
 JR l1

   We compile and run the commandR with─
we store it on a screw - the file is now on the screw
SH.RUN. 
   Now we have a shell that can─
can accept characters of pressed keys and
display them on the screen, and after pressing
Enter you can do something, after which
go to next line and print
there is a prompt to enter the command(#).
 Add the command a so that you can
go to ALASM from sh. Exactly the same until─
add the commandd so that you can re─
go to STS from sh.
   Now after resetting and loading sh from vi─
nt you can use the commands a and d to drop into
ALASM and STS. Now we need to teach sh to load─ 
press ALASM and STS.
   Load ALASM from a floppy disk. Let's go to
STS - upload filealasmЧ2.C to#7900, in 
address#7800 add a piece that is 100
vit stack to address#5FCO, includes page
1 and transfers there an alum of length#4000, by─
then save from the address#7800 length
#4100 under the nameal.C.
Next, upload the file sts7.C to the address
#7900, correct the piece so that it includes
page 7 for STS and transferred STS to hell─
res #DBOO length #2500. Save the file
sl.C from address#7800 with length #2600.
 Loading the program sourceSV_HD and in
here we change the name of the saved one toal.C, com─
file and launch. Repeat for the file
sl.C.
 Now there are these files on the screw - but
already with the extensionRUN, and we need to add
in sh the ability to load them into memory from
subsequent launch.
   The SH source is still in pa─
crumpled on page 6. Let's go to it and to─
add after ENTER_Y a piece that
first puts 8 spaces into the buffer, and then
transfers entered characters to the buffer until
until it encounters a space, or until
will carry 8 characters - this is the length of the name fa─
yla. Next it calls the functionload to the address
#7800 file with the name in the buffer. And go to
#7800 if loaded without errors. When oshi─
Then we display the lineload error.
Now if in sh you typeal and press
Enter - then it will be loaded from the screw and started─
ALASM puppy. And if you type sl (and press
Enter ), then it will boot from the screw andwill start
STS."al" and "sl" mean alasm load and sts 
load.
 Now we need to teach sh to save and z─
destroy the source codes of Alasma.
   Add commands s and l. By command s
the contents of the page will be saved to the screw
faces (for example, 4 is the one indicated in
alasme by default), length #4000, name for 
we will take the file from the same page -
first 9 characters of type"SH .H" and up to─
add 2 more letters of extension"SM", in re─
As a result, we get the fileSH.HSM on the screw.
On commandl SH will be loaded from the screw
file with the nameSH.HSM(or with another name,
indicated separated by a space after the command l) and 
place it on the page. But first
check: if there (on this page) already
is there any source file - the first 8
characters must be in capital letters, and
The 9th character is equal"H" - then we display it on the screen
"the file has already been loaded into the page" and its name, and
question,upload a file there with the name uka─
named afterl, and this is the name. By pressing y -
loading.

                  * * *

                Shamatrix
             Type 2 programs

   Throwing out the multitasking project
axes (MATRIX - see below about it), everything unnecessary,
what hampers the “beautiful impulses of the soul” and
we get a program that shows on the screen─
not icons, taskbar and arrow (which
You can move it around the screen using
keys, joysticks and mice).  It will be
Shamatrix. 
   Each icon is assigned a program name,
which starts when you hover the arrow─
key on the icon and clicking the corresponding
buttons on the keyboard/mouse.
   It is also possible to provide immediately (or by
pressing a key) shows a window,
in which to print program names under
Matrix (for example, from the catalog SHMATRIX/ 
PROGRAM - and the path to the displayed ka─
make the directory customizable). And when nave─ 
pointing the arrow at the name of the program in this window and
By pressing the button the program can be launched.
   We get a certain minimum.
   The first program in this catalog can be ra─
lay down (first make) a certain universe─
flax bottle that starts everything - starting
from prog for DNA, Shmatrix and Matrix, and for─
ending with BASIC files (from floppy disks) and Kodo─
vy blocks,located anywhere
(either on a screw or on a ram disk).
   As a “balm for the soul” those who wish
added to Shamatrix (i.e. to this program) in─
the ability to drag icons, windows, call
taskbar when moving the arrow to the edge
screen, install any picture in ka─
as "wallpaper" for your desktop, screenshot
saver, as well as the ability to hang
music for interruptions. Shamatrix can re─
give messages to programs launched (under it)
sentence: they say, if the program doesn’t bother you
and this circumstance will not constrain you, then in
page 4 (for example, can be customized)
lies the so-called BACKGROUND TASK -by─
please, YOUR MAJESTY PROGRAM, call─
run this task every interrupt. And about─
he can ignore at his discretion
(and nothing bad will happen) or you─
call - if she doesn't need this page, and
The performance for this program is not very good
plays roles (like showing pictures).
   However, the changes made may not
influence other programs, or vice versa,
increase the "enslavement" of prog. For example,
you can tell programs not to clear the screen, but
print your window on top of existing ones
windows Save your image on the screw─
th window in a separate file and the entire screen in
friendfile, and window coordinates and sizes
windows in the third file, and during operation
programs when pressed, for exampleCaps Shift+
Symbol Shift save to a special kata─
log (for example,SHMATRIX/PROC) some file -
in which the code and data of this program at the moment
before pressing, after which the program does
resets or will launch the Shmatrix itself.
   And the Shamatrix on the taskbar shows
names of "running" programs (i.e. programs with─
stored in the folderSHMATRIX/PROC). And after 
hovering the arrow over the name of the program on the panel
tasks and pressing the Shamatrix button loads
to the memory of the saved program - like switching─
looks forward to this program.
   But that's not all: here are the files that...
which the program saves - the background under its window and
the entire screen - needed in order to
Driving an arrow to any of the windows visible
on the screen, and by clicking on them, the Shamatrix could
by manipulating these files you get─
Place the desired window on the screen on top of the others
windows and then load the saved
the program to which this window belongs, and the program─
style her, passing her a message at the same time -
impact on the window, impact coordinates
from the upper left corner of the window and the type of air─
actions (left/right mouse button, etc.).* * *

                  MATRIX
             Type 3 programs

   Now we get to multitasking.
   So, the Matrix is complete slavery for
coders... I wanted to say - full-fledged
preemptive multitasking on a screw, with
task scheduler, with the ability to dynamically─
ical distribution of priorities for dis─
kovyh operations and graphics subsystem.
That is, you can choose what will slow down
- drawing windows and graphics/text in them, with
fairly fast reading/writing from/to
Winchester - or vice versa.
   With all that it implies - no prog at all─
what cannot be done without the permission of the Matrix.
The program gives a request and waits until the Matrix
please pay attention to the program. And this
concerns everything - from printing one
letters on the screen, loading a piece of file (a
before that you still need to ask for memory under
this is the case), and ending with the fact that for the program
there are no screens (first, second─
swarm), no guarantee of performance - yes
like any acceleration of the program is languishing
from idleness the coder is reduced to nothing immediately
after the user runs another
one program (or two or three programs).
   If things aren't so bad with memory─
xo - still a relatively small number
prog (of the entire mass) even uses all
128K memory - but, for example, they are content
64K+second screen, then with CPU time─
he has to rely on turbo mode.
   [Of course it's notconcerns programs that
which mainly await user actions. 
Run the compiler in parallel with editor─ 
It’s still possible to modify the text.] 

 See also the memory structure design and on─
selection of system functions:
http://zx-pk.ru/showthread.php?t=10781

Share your thoughts about the article