COMMITTED AND MODERN METHODS Coding
WAYS OF WORKING WITH GRAPHICS
Year after year, to organize SPECCY
new groups, write programs. This means that somewhere there are
more and The new musicians, artists, and of course the same
programmers who want to make
something interesting, never seen before and
not surpassed. Somewhere in the future sitting
RST # 7'ye, IMP'y, STALKER'y ... Learn assembler, day and
night, armed with STS ' om, dismantle brick by brick program of
his predecessors.
To help them all to save
weeks and months that we had
sit for the listings of programs, and
case fighting off the ever-present bugs, inventing something
that already many have long known doing what until recently was
considered impossible, and prepared the following material. It
contains diverse coding tips, from very basic procedures to
more sophisticated and effective.
An earlier version of this text is
Once published in an electronic journal
"Depth 1" who has not received sufficient
proliferation. Here you can see its enlarged version. I'm going
to continue the topic in the next room, describing
useful procedures and methods of coding.
So, we go strictly to the topic ...
1. Consider the most frequently used
methods of display images on the screen.
a). The easiest way to get the sprite -
to throw it consistently
byte by byte, line by line.
proramma, take such actions,
looks 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 in the screen,
B-width of the sprite in the familiarity,
C-height of the sprite in pixels.
DOWN_HL - go to the line below.
This method, despite its simplicity
and primitive, quite suitable for you water a static (fixed)
graphics. Changing the input parameters in registers
HL, DE, BC, we can derive a picture of any
size at any position on the screen. Unfortunately Niya, such
flexibility is not common to all other ways of graphics output.
b). Display graphics with a fixed
wide.
LOOP1 PUSH DE
LDI; Number of independent
... , The width of the sprite.
POP DE
EX AF, AF '
CALL DOWN_DE
EX AF, AF '
DEC A
JR NZ, LOOP1
RET
HL-mail sprite in memory,
DE-e in the screen,
A-height of the sprite in pixels.
This method is somewhat faster than of the previous, but
because of binding to a specific width of the sprite, however
raspostranen.
cent.) Output graphics using the stack.
This and the following methods of inference graph
graphs are more efficient and faster
Compared with the previous ones, but together
order and more complicated.
So, sending glass screen:
The program creates when you first start
operating unit, which actually
will be engaged in redeployment schedules.
Address entered in the register graphic SP,
then the value from the stack sequence
Indeed extracted and entered into the equivalent
wounds. Approximately it will vygldet this:
...
POP HL
LD (# 4000), HL
POP HL
LD (# 4002), HL
POP HL
LD (# 4004), HL
...
Naturally, the address to which
would throw the schedule in advance
fixed, and once fiksirvany
measures sprite. Length of the obtained procedure
dures in the memory depends on the size
sprite, and will be twice as large
than he. That is, if you perebrasy
is called a sprite on the screen (6144b.)
size of the program will be - 12288b.
Such a waste of perfectly
justified, since the rate of work
you this program is much higher than
earlier. One byte throws
Camping for 13 cycles. Moreover, that before
installation program will take
only some 100 bytes.
g). The next method is similar to prdyduschy,
but more suitable for scrolling
up and down, than to display graphics.
As to specific addresses here
binds both the source and receiver.
...
LD HL, (# 4100)
LD (# 4000), HL
LD HL, (# 4102)
LD (# 4002), HL
LD HL, (# 4104)
LD (# 4004), HL
...
Absolutely do not use the stack and not
modifies the registers, except for HL.
Uses for each of thrown
B charts three bytes of memory.
One byte is thrown for 16 so
Comrade.
e). The fastest way Scrolling
screen vertically and quite Sauveur
shennym by the graphics output of the PA
myati is the following:
...
LD SP, e-source
POP HL
POP DE
POP BC
POP AF
POP IX
POP IY
EXX
POP HL
POP DE
POP BC
LD SP, e-Objective
PUSH BC
PUSH DE
PUSH HL
EXX
PUSH IY
PUSH IX
PUSH AF
PUSH BC
PUSH DE
PUSH HL
...
This method is very effective, but
still can not bring the whole screen
per interrupt.
e). Now consider the most perfect and
under-utilized method of deriving the graph
Key:
These are mixed with the program,
and obtained design types:
...
LD SP, the address in the screen
LD HL, two bytes of graphics
PUSH HL
LD HL, next two bytes
PUSH HL
LD HL, next two bytes
PUSH HL
...
Now let's take a count ...
LD HL, number - 10 cycles
PUSH HL - 11 clock cycles.
To display full-screen images are not
necessary to repeat this snippet
3072 times = 21 * 3072 = 64512 cycles.
LD SP, the number of - 10 bars.
The stack will have to change (although not
required) before the conclusion of each
line that is 192 times = 10 * 192 =
= 1920 cycles.
And, all as a whole will take
64,512 1920 = 66,432 cycles!
As you see, is quite realistic to deduce
image without repetition of the whole screen
per interrupt.
This method of graphics output is not
new and coined not by me. Anyway
they used a lot of my friends from the RUSH,
and told me about it some more IMP
years ago ...
When using this method also
consumes two bytes of memory on each dy of bytes of graphics.
Conclusion noekrannoy sex pictures absolutely free types
toryayuschihsya fragments elementary UCLA embedded not only in
the Pentagon on closing the limit, but also in an interrupt on
any normal car, for example, SCORPION, PROFI etc. True to the
original car will appear lyayutsya problems related to the fact
that there are separate fields of memory, that is equivalent
to rannaya memory operates much slower but we have to put the
stack into the screen ... But if the brand was re SPECCY
exponentially 70,000 cycles per interrupt all of the personally
managed to work, even it remains a place for music.
To make the image move camping, will have to change the
address entered in SP, but it's real.
And a few more tips for
coders, who were drawn from many years of experience in
assembly language as my personal as well as many other coders:
When images of the mask
sprite, it's best to keep stirred
with a mask. Bytes of graphics, then the byte mask
etc. Displayed a sprite will be as follows:
...
POP DE; two bytes grfiki
LD A, D
AND (HL)
OR E
LD (HL), A
INC L
...
Stack when it should point to the schedule,
and HL on the screen.
The quickest way to clear the screen:
LD SP, # 5800
LD BC, 0
PUSH BC - repeat 3072 times.
You can also clean up any area in memory, etc. Of course not
necessarily make such a procedure is absolutely no cycles. For
example, we make only 256 PUSH'ey, and loop the block desired
Number of times. Specific loss in speed will not.
Now a very important thing
should be aware of all those who decided to write a quality
program SPECCY. In the derivation of a large number of graphs,
the probability that the television beam intersects the
inferred currently block graphics are great. This will lead to
the fact that at the intersection with the ray, dynamic image
will diskrirovat. For example, when scrolling a large movie
screen the upper part of his will be shifted, then a ray of
"catch up" the place of withdrawal, and further half a picture
will be output with a lag of one frame. Even more terrible
picture is obtained if the image on the screen vremmenno erased
scan can get it at such a moment, and then may appear
disappearing sprites promigivayuschie cursors
and other leymerstvo.
How to deal with it:
You can try to sweep does not overlap with the conclusion
throughout interrupts. So, you can first take
graphics in the middle and lower third of the screen,
but in the end, when luch has held the top half of the screen,
one can derive the upper third. This method is often used, but
because of huge differences in design of computers scan for
different types of SPECCY may differ, that will cause
diskrirovaniya image. Worth seeing how it works "SHOCK" at the
Pentagon, and it all becomes clear.
The most effective and practical method in this case is to
use additional screen machines 128k RAM and more. The presence
of two screens which can be switched instantly when
using a single OUT'a very
greatly simplifies the programmer lives.
Working with two screens is
as follows: for termination (optional) hangs a small program
which in turn connects then 7 page and normal screen, then 5
pages and shadow screen. It may look like this:
SCREEN_CHANGER:
SCR LD A, # 55,% 01010101
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 procedures, working with the screen,
should be written with the expectation that
screen is now not address # 4000
(16384 dec), and from the address # C000 (49152 dec).
Procedure DOWN_HL not need to change it and
so it will work correctly.
The essence of this method is
that change (erase, move, etc.) you
will not the screen, which displays
currently on display, but one that resides in memory and not
visible to the viewer. No, diskrirovaniya not be absolute, even
if you change the whole entire screen. Thus, for example made
in the Slovak demo "ECHOLOGY", and it is great works on all
machines INCL. Pentagon MULTICOLOR'ov except, of course.
By the way, MULTICOLOR - this is diskrirovanie ...
Of course to write programs using
One screen - is steeper, but in practice it
not appropriate. I advise you not to torture
users to write and soft under the two screens.
And now the council has no direct
attitude to work with dynamic graphics, but it may be useful to
you in If you do not have enough CPU time to play music, and
free memory is a lot. In this the case can proceed as follows:
Music decomposed into components and then played passing
player. Simple data output ports will take some some 300 bars,
if you compare that player to "ASM"
requires over 8000 cycles - the difference is palpable.
It is advisable not to load is spread out on the data
from CD music, but to create it yourself before you start
program, so as the size of the resulting data block can reach
tens of killobayt. You can also try to compress the repeating
fragments.
This method has been used in many demonstrations -
"ECSTASY", "SHOCK", "SATISFACTION", "INSULT" etc.
But the most beautiful and compact way to mute the sound
on AY, which I saw (he wrote it not me):
SHUT_UP:
LD HL, # 000D
SHUT1 LD BC, # FFFD
OUT (C), L
LD B, # BF
OUT (C), H
DEC L
JR NZ, SHUT1
RET
In the case where you need to identify pressing any key,
including Caps Shift and Simbol Shift is very convenient
use of "classical" procedure of
ROM, which is located at decimal address 654. The procedure
returns the register E code 255 (# FF), if you do not press any
key.
Example of use:
WAIT:
CALL 654
INC E
JR Z, WAIT
RET
If someone does not understand what I am
meant by procedure or DOWN_HL
DOWN_DE, I quote below the text:
DOWN_HL:
INC H
LD A, H
AND 7
RET NZ
LD A, L
ADD A, # 20
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, # 20
LD E, A
RET C
LD A, D
SUB 8
LD D, A
RET
If you need to fall down on the whole
familiarity, follow these steps (the address in HL), and not to
call eight times in a cycle DOWN_HL, as some
naive guys ... :
LOWER_HL:
LD A, L
ADD A, # 20
LD L, A
RET NC
LD A, H
ADD A, 8
LD H, A
RET
Sometimes it is necessary to recalculate the address in
screen at the address corresponding to this
familiarity of the attributes. Make
This can be as follows:
SCR_ATR:
LD A, H
RRCA
RRCA
RRCA
AND 3
OR # 58
LD H, A
RET
Enough for today ... Sure ways to improve programs
may be infinite. For
each case has its own techniques and tricks. They need to know
not only to write Killer
effects ...
Not being able to enjoy the benefits of
advanced encoders, you can not write
dynamic quality toys, and
good system can not write a program, using the methods of a
decade Period.
Therefore, go for it! May soon
You can write full-screen multicolor or even some miracle
coding!
Good luck!!!