__________________________________________
Text :VIATOR
Music :COOPER
__________________________________________
(C) VIATOR/AVALON/RUSH/ASM
PERFECT AND MODERN CODING METHODS
WAYS OF WORKING WITH GRAPHICS
Most SPECCY programmers
were forced to study on their own
assembler and come up with quick ways
working with dynamic graphics. K
unfortunately, not a single worthy book on
This topic never appeared.
Literature from publishing houses "Peter" and
"Inforcom" was outdated even before its
appearance. The book I promised to write
StalKer could be an excellent tool
for the encoder, but it is unknown whether it will appear
does she ever...Recently, in electronic
publications began to publish articles
dedicated to professional methods
working with graphics. But how is it not
sad, it often occurs in them
many inaccuracies and errors.
Of course it would be great if
a similar article was written by RST-7, IMP or
ALEX RAIDER, who have extensive experience in
this area, but if they don’t
bothered to write anything for so long
years, it is unlikely that they will write
anything in the future.
As usual, let's start from the end... and
Let's answer a question that has been around for a long time
tormented the minds of coders from all countries: “Is it possible
display a full-screen image (without
attributes) to the screen in one interruption
?" - YES!!! It is quite possible and
quite simple! Unfortunately, many
the programmers didn’t think so and even
devoted articles to this topic in magazines,
which presented a bunch of arguments and facts,
rejecting this possibility. Worth it
remember at least the article in the first issue
magazine "ZX-POWER". The article is quite
professional, but some mistakes
available. Everyone can make mistakes, but ours
coding duty obliges us to make these mistakes
fix that, which is what we will do now...
1. Considermost often
used image output methods
to the screen.
a).The easiest way to display a sprite is
throw it sequentially
byte by byte, line by line.
a program that performs such actions,
looks something like this:
LOOP1 PUSH BC
PUSH HL
LOOP2 LD A,(DE)
INC DE
LD (HL),A
INC L
DJNZ LOOP2
POP HL
CALL DOWN_HL
POP BC
DEC C
JR NZ,LOOP1
RET
DE-address of the sprite in memory,
HL address on screen,
B -width of the sprite in familiar places,
C - sprite height in pixels.
DOWN_HL - move to the line below.
This method, despite its
simplicity and primitiveness, quite suitable
to display static (motionless)
graphics.
By changing the input parameters in the registers
HL,DE,BC, you can display a picture of any
size anywhere on the screen. Unfortunately-
However, such flexibility is not typical for everyone
other methods of graphics output.
b). Display graphics with fixed
width.
LOOP1 PUSH DE
LDI ;колличество зависит
... ;от ширины спрайта.
POP DE
EX AF,AF'
CALL DOWN_DE
EX AF,AF'
DEC A
JR NZ,LOOP1
RET
HL-адрес спрайта в памяти,
DE-адрес в экране,
A -высота спрайта в пикселях.
Этот способ несколько быстрее предыду-
щего, но из-за привязки к определенной
ширине спрайта, менее распостранен.
в.) Вывод графики при помощи стека.
Этот иthe following methods for outputting graphs
fics are more efficient and faster
compared to the previous ones, but together
This is a little more complicated.
So, forwarding the stack screen:
The program creates at the first
starting a working block, which
will actually do it
transfer of graphics.
The graphics address is entered into the register
SP, then values from stack
are sequentially extracted and
are entered into the screen. This is approximately
it will look like this:
...
POP HL
LD (#ХОOO),HL
POP HL
LD (#ЧOO2),HL
POP HL
LD (#ООЧ),HL
... Naturally, the addresses in
which will throw graphics,
fixed in advance, fixed
also the sprite sizes. Length
the received procedure in memory
depends on the size of the sprite, and
will be twice as large as it is. Then
yes if you rethrow the sprite
full screen (6144b.),
The program size will be 12288b.
Such wastefulness is quite
justified, since the operating speed
you are much higher than this program
previous ones. One byte
is thrown in 13 cycles. Them
Moreover, before installing the program
will only take some
1OO bytes.
G). The next method is similar to the previous one
but more suitable for scrolling
up and down than for graphics output
Since to certain addresses
here both the source and
receiver
...
LD HL,(#41OO)
LD (#ЧOOOO),HL
LD HL,(#41O2)
LD (#ЧOO2),HL
LD HL,(#41O4)
LD (#ООЧ),HL
...
Absolutely no stack is used and no
modifies registers except HL
Uses for everyone
tossed graphics bytes in threes
byte of memory. One byte
is thrown in 16 cycles.
e). The fastest way
SCROLLING the screen vertically and
quite a perfect output method
graphics from memory is
next:
...
LD SP, source address
POP HL POP DE
POP ВС
POP AF
POP IX
POP IY
EXX
POP HL
POP DE
POP ВС
LD SP,адрес-цель
PUSH ВС
PUSH DE
PUSH HL
EXX
PUSH IY
PUSH IX
PUSH AF
PUSH BC
PUSH DE
PUSH HL
...
This method is very effective, but everything
still does not allow you to display all
screen in one interruption.
e). Now let's look at the MOST perfect
and a little-used withdrawal method
graphics:
The data is mixed with the program,
and you get a construction like:
...
LD SP, address on screen
LD HL, two bytes of graphics
PUSHHL
LD HL, next two bytes
PUSH HL
LD HL, next two bytes
PUSH HL
...
Now let's do some math.
LD HL, number - 1O cycles,
PUSH HL - 11 bars.
To display a full screen image
this part needs to be repeated
3O72 times = 21*3O72 = 64512 clock cycles.
LD SP, number - 1O cycles.
The stack will have to be changed (although not
mandatory) before the withdrawal of each
lines, that is 192 times = 1O*192=
=192O clock cycles.
And besides, everything as a whole will take
64512+192O=66432 clock cycles!!!
As you can see, everything is quite possible and re
alno. The capabilities of the Spectrum are not used
have been drawing on themselves until now!
SPECCY ALIVE FOREVER !!!
This method of displaying graphics is far
not new and not invented by me. Anyway
many of my friends have used it
from RUSH, and told me about him IMP also
a few years ago...
When using this method also
two bytes of memory are consumed per
every byte of graphics output. Conclusion
full-screen image absolutely without
repeating fragments in an elementary way
fits not only into the Pentagon
interruption, and in interruption for any
normal car, for example SCORPION,
PROFI, etc. True on a branded car
problems arise due to the fact that
it has separate memory fields, that is
screen memory works much better
slower, and we have to place a stack
into the screen...
But if the branded SPECCY had
really 7OOOO clock cycles in the interrupt, that’s all
would do a great job, even
there would be room for music.
To make the image
move, you'll have to change addresses,
entered into SP, but this is also quite realistic.
It remains only to say that in our new
the demo "HALLUCINATIONS OPERA" has one
FX, although it works on the whole screen
only at the Pentagon, but you have to have
conscience, as our Medicine Man says... And some more useful tips for
coders that were drawn from
many years of experience working in assembly language
both my personal and many others
coders:
When displaying an image using a mask,
The sprite is most convenient to store
mixed with mask. Byte graphics,
then the mask byte, etc. Output like this
the sprite will be like this:
...
POP DE ; two bytes of graphics
LD A,D
AND (HL)
OR E
LD (HL),A
INC L
...
The stack should point to
graphics, andHL to the screen.
The fastest way to clean e-
wound:
LD SP,#58OO
LD BC,O
PUSH BC - repeat 3O72 times.
You can also clean any areas in
memory, etc. Of course not at all
it is necessary to do such procedures
absolutely no cycles. You can, for example,
make only 256 PUSHes, and loop
this block the required number of times. Special
there will be no loss in speed.
Now a very important thing that
everyone who decides to write should know
quality programs on SPECCY. When
output of a large number of graphics,
the probability that the television beam
will intersect with the currently output
The graphics block is very large. This
will lead to the fact that at the intersection
with beam, dynamic imagethere will be
discriminate For example, when scrolling
large screen fragment upper part
it will be shifted, then the beam will “catch up”
output location, and the further half
images will be displayed with a lag
for one frame. An even more terrible picture
it turns out if the image on the screen
is temporarily erased, scanning may
get to just such a moment, and then
disappearing sprites may appear,
blinking cursors, etc.
lameness.
How to deal with this:
You can try so that the scan does not
intersected with the output throughout
total interruptions. Yes, you can first
display graphics in the middle and lower thirds
screen, and at the end, when the beam is already
will go through the top half of the screen, you can
remove the top third. This method
used quite often, but due to
huge differences in design
computers scan on different types
SPECCY may vary greatly, which
will cause discrimination
images. It's worth watching how
"SHOCK" is working at the Pentagon, and that's all for you
it will become clear.
The most effective and practical
the method in this case is
use of an additional screen in
machines with O3Y 128k and more. Availability
two screens that can be switched
instantly with one
the only OUT, very much
makes life easier for the programmer.
Working with two screens
is done as follows: on
interrupts (optional) is hung
a small program that alternately
connects then page 7 and normal
screen, then page 5 and shadow screen.
It might look something like this:
SCREEN_CHANGER:
SCR LD A,#55 ; %O1O1O1O1
RRCA
LD (SCR+1),A
LD A,#17 ; 16+7
JR C,PAGER
LD A,#1D ; 24+5
PAGER:
LD BC,#7FFD ; 32765
OUT (C),A
RET
All screen procedures
must be written taking into account that
the screen is now not from the address #COOOO
(16384 dec), and from the address #COOO (49152
dec). There is no need to change the DOWN_HL procedure,
it will work correctly anyway.
The essence of this method is
what to change (wash, move, etc.)
You will not be the screen that
currently displayed on
monitor, and the one that is in
memory and is not visible to the viewer. None
there will be absolutely no discrimination, even
if you change the entire screen
entirely. For example, this is done in
Slovak demo "ECHOLOGY", and she
works great on all machines,
including the Pentagon, with the exception of
MULTICOLOR'ov, of course. By the way,
MULTICOLOR is discrimination...
Of course, write programs using
one screen is cooler, but in practice it's
not advisable. I advise you not to
torment users and write soft under
two screens.
And now advice that does not have direct
attitude towards working with dynamic
graphics,but it may be useful to you
in case you don't have enough
CPU time for playback
music, but free memory remains
a lot. In this case, you can do
as follows:
The music is decomposed into
constituent components and then
is played bypassing player. Simple
data output to the ports will take
some ZOO cycles, if compared with
because the player from "ASM" requires more
8OOO clock cycles - the difference is noticeable.
It is advisable not to load already
decomposed music from the disk into data, and
create it immediately before
launching the program, since the dimensions
the received data block can reach
tens of kilobytes. You can also
try compression
repeating fragments.
This method was used in
many demonstrations - "ECSTASY",
"SHOCK", "SATISFACTION", "INSULT", etc.
But the most beautiful and compact
a simple way to turn off the sound on an audio device,
which I saw (I didn’t write it):
SHUT_UP:
LD HL,#OOOD
SHUT1 LD ВС,#FFFD
OUT (C),L
LD В,#BF
OUT (C),H
DEC L
JR NZ,SHUT1
RET
Если кто-то не понял, что именно я
имел в виду под процедурой DOWN_HL или
DOWN_DE, я привожу ниже их текст:
DOWN_HL:
INC H
LD A,H
AND 7
RET NZ
LD A,L
ADD A,#2O
LD L,A
RET C
LD A,H
SUB 8
LD H,A
RET
DOWN_DE:
INC D
LD A,D
AND 7
RET NZ
LD A,E
ADD A,#2O
LD E,A
RET C
LD A,D
SUB 8
LD D,A
RET
Sometimes you need to recalculate the address
in the screen to the address corresponding to this
familiarity in the attribute area. Make
it can be done like this:
SCR_ATR:
LD A,H
RRCA
RRCA
RRCA
AND 3
OR #58
LD H,A
RET
That's enough for today... Of course
ways to improve efficiency
there can be an infinite number of programs
multitude. For each specific
The case has its own techniques and subtleties. Their
you need to know not only in order to
write stunning effects...
Not knowing how to use achievements
modern coders, you won't be able to
write high-quality dynamic
toys, and a good system
it is impossible to write programs using
methods ten years ago.
So go for it! Perhaps soon
You will be able to write full screen
multicolor or some other miracle
coding! Good lucK !!!
P.S. It would be nice to write
professional book on coding, in
which would describe all the methods
Not knowing how to use achievements
modern coders, you won't be able to
write high-quality dynamic
toys, and a good system
it is impossible to write programs using
methods ten years ago.
So go for it! Perhaps soon
You will be able to write full screen
multicolor or some other miracle
coding!
Good lucK !!!
P.S. It would be nice to write
professional book on coding, in
which would describe all the methods
programming and many useful
procedures. Perhaps if someone
asks, I could try to write,
something like that...
Share your thoughts about the article