X-Files #02
31 марта 1998

Programming - The effect of "Flying sprite.

<b>Programming</b> - The effect of
==============================>
^|||||| PROGRAMMING ||||||`
'\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ @
________________________________
Konstantin Limonov (Smoke / CLV).
________________________________
Hello to all fans of assembly! In this issue, I
(Smoke) I want to offer your
attention to the procedures of a small but
very expressive -
"Flying Sprite!
________________________________
Such an effect you probably have seen
the heap and any INTRO MUSICDEMO.
Assembler these procedures look different, but the principle of 
action they have almost the same. I imagine my 
variant.Konechno, he is not the best and effective, but the 
most simple and intuitive to each nachinayuschimu koderu.Vse 
line program are numbered and you can see a detailed commentary 
on each of them after the text itself

programmy.Itak begin ...
________________________________
FLY LD DE, # 0000 2000

        CALL CL_SP 01
PTX LD HL, POX 02

        LD A, (HL) 03

        CP # FF 2004

        JR NZ, LIP1 05

        LD HL, POX 06

        LD (PTX + # 01), HL 07

        JR PTX 2008
LIP1 LD D, A 09
PTY LD HL, POY 1910

        LD A, (HL) 11

        CP # FF 1912

        JR NZ, LIP2 13

        LD HL, POY 1914

        LD (PTY + # 01), HL 15

        JR PTY 16
LIP2 LD E, A 17

        CALL PLOT 18

        LD (FLY + # 01), HL 19

        PUSH HL 1920

        LD DE, SPSIZE 21

        LD HL, SPRT-SSIZE 22
LIP3 ADD HL, DE 23

        DJNZ LIP3 24

        POP DE 1925

        CALL GET_SP 26

        LD HL, (PTX + # 01) 27

        INC HL 28

        LD (PTX + # 01), HL 29

        LD HL, (PTY + # 01) 30

        INC HL 31

        LD (PTY + # 01), HL 32

        RET 1933
PLOT LD A, # AF 34

        SUB E 35

        AND A 36

        RRA 37

        SCF 38

        RRA 39

        AND A 40

        RRA 41

        XOR E 42

        AND # F8 1943

        XOR E 44

        LD H, A 45

        LD A, D 46

        RLCA 47

        RLCA 48

        RLCA 49

        XOR E 50

        AND # C7 51

        XOR E 52

        RLCA 53

        RLCA 54

        LD L, A 55

        LD A, D 56

        AND # July 1957

        LD B, A 58

        INC B 59

        RET 1960
GET_SP LD B, VIS * # August 1961
LIP4 PUSH DE, BC 62

        LD B, DLINA 63
LIP4_X PUSH BC 1964

        LDI 1965

        POP BC 1966

        DJNZ LIP4_X 67

        POP BC, DE 1968

        CALL DE_LINE 69

        DJNZ LIP4 70

        RET 1971
CL_SP LD BC, VIS * # 800 72
LIP5 PUSH BC, DE 1973

        XOR A 74

        LD B, DLINA 75
LIP6 LD (DE), A 76

        INC DE 1977

        DJNZ LIP6 78

        POP DE, BC 79

        CALL DE_LINE 80

        DJNZ LIP5 81

        RET 1982
;------------------------------ DE_LINE INC D 83

        LD A, D 84

        AND # July 1985

        RET Z 86

        LD A, E 87

        ADD A, # 20 88

        LD E, A 89

        RET C 90

        LD A, D 91

        SUB # August 1992

        LD D, A 93

        RET 1994
;------------------------------ SPRT INCBIN SPRITES 95
POX INCBIN COORD-X 96
POY INCBIN COORD-Y 97
;------------------------------ Now consider this procedure
more podrobno.Itak, starting with the 0-th
stroki.V this line in the register pair DE loading address in
display area, where at a given
moment is sprayt.Zatem in
line 01 is invoked procedure
erase sprayta.Pri this image is under the sprite
teryaetsya.Poetomu would be better if you are not situated on
place where it will "fly" sprite
some graphical information.
On line 02, in the register pair
HL send the address of the
Table coordinate axis 'X'.
(For instructions on how to prepare a table of coordinates, you 
can read below). In the battery load coordinates from a 
spreadsheet and produced check at the end of the table (code

end of the table is the number of
# FF (255 DEC)). If this is the end
table, the row 02 being upgraded so that the register pair HL 
is set top the table of coordinates. If it is one of the 
coordinates, then transition occurs on line 09.

The resulting X-coordinate is
transferred to the register of D. Then
is similar to loading
and checking the coordinates of Y. In the transition to line 
17, we are Register D coordinate X, and coordinate in register 
E Y. Next, at 18 prompt a call to the procedure takes a string 
PLOT.Ona 34 th to the 60 yu.Protsedura PLOT engaged in the 
calculation of addresses in the display area at coordinates 
defined in pikselah.V register pair HL, it returns the address 
in the display area, and in the case B number of the sprite, 
which must this time printed on the screen

monitora.Vnimanie! The program uses the same sprites 8
width and height, but each
sprite is shifted relative
the previous one pixel vpravo.Eto necessary for smooth
move the sprite left and
vpravo.Pochemu sprites eight??
Yes, because a byte is
of eight bits! Prepare
a set of sprites can, in
Basically, in ART-STUDIO, but better
use for this, for example,
program of Digital Reality
- "SpriteLand v1.xx". But keep in mind
that zdvige sprite, its width will increase by one character (!)
Remember this! When the program is also necessary to know the 
length of one sprite in bytes.

After calculating the coordinates of the address, he entered 
into line 00, where he needed to erase sprayta.Posle this same 
address is sent to the stack, and in lines 21 th to 24 th of 
searching desired sprite from the table and then restoring the 
address of the press, line 26, is a challenge

procedures for printing a sprite.
The printing process is a sprite on the screen takes a line 
from 61 th to 71-yu.Ona easy to predela.V

line 61 to the register B is loaded height of your sprite 
familiarity multiplied by eight. After all, familiarity in one 
8-NIL lines, is not it? The next line store registers DE and 
BC, and then organized another round of

Print each line sprayta.V principle, you can uncover
this cycle of erasing the line with the 63rd
on 67-th, instead type
in this place so many teams LDI,
much familiarity in width takes your sprayt.Dalee, in line
68 th, restored registers
BC and DE, but then comes the challenge procedure for 
calculating the addresses of Print next line of the sprite 
under predyduschey.Eta procedure is so well known and simple, 
that describe how it works just bessmyslenno.Luchshe Read the 
book "Inforkom'A: "Elementary graphics", "Applied Graphics" and 
"Dynamic schedule. "And, of course, ZX-REVIEW!

With the line 72 th to 82 th is erasing procedure sprayta.Ona 
works on the same principle as the how to print sprayta.Nu, 
generally, will understand! And then I'll I'll die for klav'oy 
from such mental stress. 

          ____________
Well it's time to tell you how to make a table of coordinates 
which will "fly" your sprite. In the annex of the magazine you 
will find small program in BASIC,

which will help you in the first
porah.Potom, based on it, you can create something called 
svoe.Ona - LISSADGU, and builds, so called the figure 
Lissazhu.Chtoby understand what is at stake, one should at 
least know a little elektrotehniku.Tak here, the objects that 
appear as a result of program on the screen, and there are those

most figures Lissazhu.Programma
has several variables:
________________________________
'K' - multiplicity.
'G' - a phase shift.
'A1' and 'A2' - amplitude.
________________________________
Try to enter, such
parameters: K [5, G [0, A1 [110, A2 [70,
or are: K [2, G [1, A1 [90, A2 [75, and
once everything is clear! Only
Remember the one condition - sprite
will be printed starting from the upper left corner, and in 
those points, which will be shown

on the screen! So watch out for
so that your sprite is not got a
edge of the screen (on the curb! Joke!)!
Make corresponding indentation
for as many pixels as a wide your sprite! Well, after the 
programm will prompt you to save the created table to disk, you 
can safely substitute their names in the assembly code in line 
96 and 97.A in line 95, substitute the name you created on the 
table spraytov.I This, perhaps, could be zakonchit.Good luck, 
young coders! 


                ________________
CUL8R! Written by Smoke

                  18/11/97-00: 07

                ________________
P.S. The name of the assembly file for
CD: (SPRFLY).




Other articles:

From the Editor - Why so long there was a magazine? .. The journal Speccy left on the PC.

Programming - The effect of "Flying sprite.

Music Box - interviews with JAM'a.

Music Box - On the glitch music editors: PT2. Competition for best song.

Authoring - Presentation of a Copy CLV COPIER v1.0, and programs to record digital audio DSRv2.0.

Advertising - Advertising and announcements.

Mailbox - On the national project - PROGRESS MEGADEMO.

UFOlogiya - The contest for the best story (X-FILES. ..)

Postscript - On what would happen in the next issue.


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

Similar articles:
Interviews - Interview with Alexei Astafiev (Alex Raider / Flash Inc.)
Tips - the definition of long-distance call.
Ottyag - observing life.

В этот день...   3 December