__________________________________________
If the encoder to cut the
hands
If the legs cut off, too,
This encoder will die ... of
boredom,
Because kodit can not!
(C) PIXel / BrC
__________________________________________
People, like can you? Just look at what's going on! If the
Esme is something for novice coders, it is necessary
something like: "The registers are 8-and 16-and
bit ... teams are divided into groups .. and
etc ". All this, of course, is good, but after
It usually does not follow. Therefore,
beginner loads, for example, DoD, and sees
is it that immediately loses all hope
write something beautiful. Today I try to explain how light the
fire, I will chew the algorithm for its creation.
Well, here we go:
ORG 25000
ENT
Ah, yes, exactly, should be first come,
how it would work and how to simulate
fire. Well, do this:
1.B buffer create an array whose elements define the
intensity of the glow of the fire element (eg, artibuta, chunk
or pixel).
2.Pechataem the same array.
3.Izmenyaem array elements according to certain rules.
4.pauza if necessary.
5.perehodim to step 2.
The rules change the array in each case their (they may
depend on pechatalki buffer to the screen). Elemental Fire
follow these rules:
Buffer element (x, y) takes the value
equal to half the sum of its (x, y) values and
value of the element below it (x,
y +1). Ie: M [x, y]: = (M [x, y] + M [x, y +1]) / 2
if these two elements are equal, then the first set to zero:
if M [x, y] = M [x, y +1] then M [x, y]: = 0;
M [x, y]: = (M [x, y] + M [x, y +1]) / 2;
The bottom line of the array elements hammered sluchaimymi
numbers within the (max / 2; max), for example:
Source buffer: The received buffer:
0 ----------------> x 0 -----------------> x
|................ |.......... 2 ......
|.......... 5 ..... | .. 13 ...... 2 ......
| .. 27 ...... 5 ..... | .. 13 .. 1 ... 3 ......
|...... 3 ... 2 ..... |..... 443 .........
|..... Xxx ........ |..... XXX .........
y y
Oddly enough, but we get the effect of a burning fire or flame,
that the same thing. If all is clear, then continue, if not,
then read from the start guide
Programming on BASIC'e.
For simplicity, we represent a buffer in
of attributes # 5b00. Buffer zasun
to address allow # c000, but it will take as
you probably guessed, exactly 768 32
Baitik.
Clean buffer, which is:
LD hl, # c000
LD de, # c001
LD (hl), L
LD bc, 768 32
LDIR
Now we over it subverted:
flame LD ix, # c000 +32; [0,1]
LD de, # c000; [0, 0]
LD bc, 768; length
begin LD a, (DE); take
CP (ix); compare
JR nz, loop1; not equal
XOR a; zeroes, if equal
loop1 ADD a, (ix);
SRL a;> M [x, y]: = (M [x, y] + M [x, y +1]) / 2
LD (de), A; /
INC ix; next
INC de; / element
DEC bc;
LD a, B;
OR c;
JR nz, begin; if not all, further
CALL print; print on screen
CALL pr_key; poll button;)
LD de, # c000;
LD a, R;
AND% 00011111;
LD h, A;
LD a, R;
LD l, A;
LD de, # c000 +768; type the last line
LD bc, 32; x'ov We have 32
rnd LD a, R;
OR (hl); Generate a random number
rang AND 31; to not more max
LD (de), A; suem in the last row
INC hl; next item
INC de; / last line
DJNZ rnd; until you run out of only X
JR flame; and all from the beginning.
print LD hl, # c000; just
LD de, # 5800; throw
LD bc, 768; in
LDIR; attributes
RET; and back.
pr_key LD bc, # 7ffe; there lives SPACE
IN a; a IN (C), A
BIT 0, a; most zero bits.
RET nz; type one SP is not pressed.
POP de; if pressed, then
RET; return to XAS.
That is, in principle, and all source code, but many may not
like the fact that in the present flames are blue, green,
purple items. This, of course, we can fix what we, in fact, are
going to do. To begin with we'll decide what atrubuty in the
fire must be present. We consider them growing:
(I will use the abbreviation: pXiY where Xtsvet paper'a,
Y-color ink'a)
# 00 = p0i0 =% 00000000
# 01 = p0i2 =% 00000010
# 02 = p0i6 =% 00000110
# 03 = p0i7 =% 00000111
# 04 = p2i0 = ...
# 05 = ...
...
# 0e = p7i6
# 0f = p7i7
I think you understand the principle: to be present only in
black, red, yellow and white. Hence, from our pechatalki
require prints in the attributes are not themselves values of
the elements, and corresponding to these attribute value. Now
replace the line rang
by: rang AND 15; because values of 15,
Call print and on the Call pr_buff.
pr_buff LD de, buff; beginning of the buffer.
LD hl, # 5800; to print.
LD bc, 768; many items.
pr_b0 PUSH bc; before I forget:).
LD a, (DE); take to discern.
AND # 0f; us a stranger (a> 15) do not.
PUSH hl; see pr_b0.
LD hl, cnv_tab; beginning of the attribute table
LD b, 0, which is written, what
LD c, A; value of any attribute
ADD hl, BC; matches.
LD a, (HL); taken from plates
POP hl; recall HL
LD (hl), A; zafigachim where it is necessary:)
POP bc; hopping Tama uzho elements?
INC hl; more - more!
INC de; bigger and better! :)
DEC bc; remained at less than one.
LD a, B;
OR c;> all or what?
JR nz, pr_b0; / if not all, or how.
RET; all so all I am not guilty.
cnv_tab
; 000102030405060708090a0b0c0d0e0f; plate values for you.
# 000206071012161730323637383a3e3f; relevant attributes.
That's it. Like, nothing complicated - article does not even
require a profound knowledge of mathematics (although they do
not harm the encoder). All source code written in XAS'e, and
therefore may present specific syntax and others, such as:
# 0123456789abcdef
must be understood as:
DB # 01, # 23, # 45, # 67, # 89, # AB, # CD, # EF
In general, for writing small programs and
algorithms, this assembler is better suited
most (though perhaps not better STORM'a). He
is a compromise between STORM'om and
ALASM'om (version 4.2). Do you make 3D-rotator -
due in Georgia STORM, write the operating system -
Welcome to ALASM. Now, if a
ALASM'u attach XAS'ovy or STORM'ovy
editor, you get ASSEMBLER dreams, and
I think not only my own. Well, okay,
Th me something in the wrong direction skidded. Quite
I can not hear any reviews: (probably in vain I
then try and Nonsense ... you can close a chapter. Going to
tell you better how I am a kindergarten (when I was little)
kids burned hand magnifying glass (focusing luch on the skin),
etc. :) Again, do not go there ... Well, looks like today
all I knew about the fire, I told him.
Bye.
P.S. forgot to say one more formula:
M [x, y]: = (M [x-1, y +1] + M [x, y +1] + M [x +1, y +1] + M
[x, y]) / 4
Now everything!
__________________________________________