IM2 and multitasking
(C) Dr.Gluker 1997
The article, "club im2" electronic newspaper ZX_Club N4
emerged some terminological confusion, which requires, in my
humble opinion, some clarification. Let me remind you, it was
about interrupts and multitasking. In this article I would like
to refer to a purely terminological and
theoretical aspects of these issues.
Firstly: the interruption - just
mechanism that can be used for
his work application (or,
speaking a language other problem) and, by and large, no
relation to multi-tasking is not available; and multitasking -
The ability to run two (or more) independent (!) Applications
at the same time. Another thing that interrupt timer than it
actually is and is im 2, can be used as
mechanism for multi-tasking.
Why did not consider running in interrupt procedures
independent tasks? All the matter in the very mechanism
interrupts. This question can pereinachit: why interrupt is
named interrupts. Actually, the answer is
in the question itself. Preyvaniya interrupt the execution of
the basic (!) Program to perform some kind of short-term
procedure, that can not be inserted into the main loop
program. In this case (by convention) the interrupt handler
must save the environment and the main program after execution
recover as the judges. This makes every programmer, while
maintaining the stack registers team push and restoring their
team pop.
Another thing - the problem, it can be divided into three
main sections: software stack segment isponyaemogo code segment
data. Any full-fledged, working program always (!) Carries
three of these element. Moreover, the Z80 processor can
perform only one task and have only
a stack: refers to the hardware implementation. For example,
Motorolla 68000 is two stacks and the possibility of switching
therefore, to realize multi-tasking on
Z80 can only programmatically by using the interrupt mechanism
timer.
Next: what would finally clarify the issue of preemption,
it is necessary touch on some aspects of the hardware
implementation of the Speccy. The fact that the hardware
interrupts our favorite made very inflexible, I would even say
that - after sleeves, in connection with which we are deprived
of a very many of the features that provide
standard interrupts. That is, on the Speccy
there is only one worthy of mention
type of interrupt - im2, which happens
every 1 / 50 second, and third is not given.
Since we previously known clock
CPU frequency (3.5 MHz), we can uniquely calculate how many
cycles can make a processor for one interrupt, and
namely - 70000. This refers to variant
The Pentagon, on the other machines can be
smaller but no less than 68000. What we said is the "magic"
number? A case in that the more cycles expended
procedure is interrupted, the less they will remain the main
program, and not excluded Alternatively, when the interruption,
"eat" all machine cycles and not one "tick" will not leave the
main program, which will lead to it stops.
Now, returning to the multi-tasking, we explain the
theoretical implementation thereof by the example of
multi-tasking BASIC. So, we need to Speccy at once performed
two independent (!) BASIC program. To implement, we need The
following mechanisms:
-Sohrannenie environment to perform tasks in
extended memory;
-Restoration of the environment problem and satisfied
of thereof;
-Sharing mechanism of computer time
between two tasks.
So, what should be preserved? Yes all
system! Ie - the domain of variables
text of the program, the stack of the program.
With the restoration of the problems seem to be too
should not be. Then you should pay
attention to the mechanism of task switching.
Here it will be useful to us and im2. Organize a counter which
is set a certain number of interruptions, during which the
first program will be executed, and interview him. As soon as
the ripe, we retain all engine parameters, to stop the task,
copy it to not available (!) other programs area
memory, load the following programs and
run it on the execution of the interrupted
moment. As you can see, to realize multi-tasking BASIC is not
so difficult - in theory. But in practice, will encounter Deep
problems: lack of memory very slow switching, slow execution of
every program, the restriction on the amount of occupied
memory, inability to use the procedure im2, and etc., etc.
Thus, I can guarantee you the futility and senselessness of
such an undertaking.
Actually, that's all I
wanted to say about multi-tasking on
"Antiquity" Speccy.
. Oooo
() Oooo.
----- (------() ---
_)) /
(_ /