Deja Vu #06
30 сентября 1998

CODING - Lessons from the encoder: Fractal paparatnik.

<b>CODING</b> - Lessons from the encoder: Fractal paparatnik.
SoundTrack: FrEsHeR / PHaNtIm FaMiLy 1998
__________________________________________


(C) Max / Cyberax Software / BD
__________________________________________



          Fractal fern

          ---------------------


   The first time I saw him on the pC - got a little program on 
Q. BASIC 'e. Soon I made it to the analog spekovskom

BASIC, and now propose asmovuyu implementation.

   The principle of construction is quite simple.
We have the following recurrence formulas:

 XNEW = XOLD * A + YOLD * B + C
 YNEW = XOLD * D + YOLD * E + F


Here A, B, C, D, E and F - ratios.



   I understand that these formulas encompass transformation of 
rotation scaling and transfer coordinates simultaneously.


   Factors we will have 4 sets and
respectively, 4 variants of the formulas:


    +-----+-----+-----+-----+-----+-----+

    | A | B | C | D | E | F |
+---+-----+-----+-----+-----+-----+-----+
| 1 | 0 | 0 | 0 | 0 | .16 | 0 |
| 2 | .85 | .4 | 0 | -. 04 | .85 | 1.6 |
| 3 | .2 | -. 26 | 0 | .23 | .23 | 1.6 |
| 4 | -. 15 | .28 | 0 | .26 | .24 | .44 |
+---+-----+-----+-----+-----+-----+-----+



   To construct the fractal you want to specify
the initial values ​​of coordinates X and Y.

   Then spins an infinite loop. In
cycle for the next X, Y through
earlier, use one of the 4 formulas
probability:

 1% (1 st), 85% (2 nd), 7% (3rd), 7% (4-I).

(Somewhere I read that these probabilities are proportional to 
the area fern leaves) 

   Choice of formulas is simple: we take
(Gde-nibud. ..) RND-number from 0 to 1, then
Consider, in what range of horrible number.

R = [0.00, 0.01] - 1-st set of coefficients Comrade
R = (0.01, 0.86] - 2-nd
R = (0.86, 0.93] - 3rd
R = (0.93, 1.00] - 4-th


 s M s E above znaZ radiation coefficients

  sP C P and the probabilities are taken
X sU T U of pC-applets.

  About T sT
g s cycle can stop
* SH D H after a sufficient

  E sE A number of iterations.
8 sR I R The result of

  sE E will be approximately the
F s from the picture.

  s! P!
T s F to implement the entire

  A s this nonsense, I isb s J used fixed point
u T s calculations 8.8, with
ps And the sign of (8 bits
¢ s to-point and 8 - Village ~ s l le).
 s l
M s L

  s l

Now, actually, listing:


        ORG # 6000

        ENT
; Written by Max / CBX / BD
; XAS Assembler v7.447, 15.08.98.


DOT EQU # C0; KB plate.
X_SCALE EQU # 1800; coeffi-you stretch for
Y_SCALE EQU # 1200; X and Y.


        DI

        CALL INIT

        LD IX, 0
FRACTAL LD HL, CONST1

        LD DE, 12

        LD A, R

        ADD A, # AA

        RLCA
RN XOR 0

        XOR (IX)

        INC IX

        LD (RN +1), A; A - RND-number.

        CP 3

        JR C, OK

        ADD HL, DE

        CP 220

        JR C, OK

        ADD HL, DE

        CP 238

        JR C, OK

        ADD HL, DE
OK LD A, HX; have chosen to use a set of

        AND # 3F; coefficients.

        LD HX, A

        PUSH HL

        LD DE, (X)

        CALL MUL_NM1

        LD (TMP1 +1), HL

        POP HL

        INC L

        INC L

        PUSH HL

        LD DE, (Y)

        CALL MUL_NM1
TMP1 LD DE, 0

        ADD HL, DE

        EX DE, HL

        POP HL

        INC L

        INC L

        LD C, (HL)

        INC L

        LD B, (HL)

        INC L

        EX DE, HL

        ADD HL, BC

        PUSH HL

        EX DE, HL

        PUSH HL
; XNEW calculated.

        LD DE, (X)

        CALL MUL_NM1

        LD (TMP2 +1), HL

        POP HL

        INC L

        INC L

        PUSH HL

        LD DE, (Y)

        CALL MUL_NM1
TMP2 LD DE, 0

        ADD HL, DE

        EX DE, HL

        POP HL

        INC L

        INC L

        LD C, (HL)

        INC L

        LD B, (HL)

        EX DE, HL

        ADD HL, BC

        LD (Y), HL
; YNEW also calculated.

        EX DE, HL

        LD BC, Y_SCALE

        CALL MUL_NM2; Scale Y.

        EX DE, HL

        LD HL, # C000

        AND A

        SBC HL, DE

        LD A, H

        EX AF, AF

        POP DE

        LD (X), DE

        LD BC, X_SCALE

        CALL MUL_NM2; Scale X.

        LD DE, # 8000

        ADD HL, DE

        LD B, H

        EX AF, AF

        LD H, DOT; to finish.

        LD L, A

        LD A, (HL)

        INC H

        LD D, (HL)

        INC H

        LD L, B

        OR (HL)

        LD E, A

        INC H

        LD A, (DE)

        OR (HL)

        LD (DE), A

        LD A, # 7F

        IN A, (# FE); Poll SPACE.

        RRCA

        JP C, FRACTAL

        EI

        RET


MUL_NM1 LD C, (HL)

        INC L

        LD B, (HL)
; Procedure for multiplication of two symbolic numbers
; Format 8.8 (DE registers and BC):
MUL_NM2 LD A, D

        AND A

        JP P, NONEG1

        CPL

        LD D, A

        LD A, E

        CPL

        LD E, A

        INC DE
; To change the sign of his (number)
; To invert and increase by 1.

        LD A, B

        AND A

        JP P, NONEG2

        CPL

        LD B, A

        LD A, C

        CPL

        LD C, A

        INC BC
NONEG3 XOR A

        JP ML2
NONEG2 LD A, # FF

        JP ML2
NONEG1 LD A, B

        AND A

        JP P, NONEG3

        CPL

        LD B, A

        LD A, C

        CPL

        LD C, A

        INC BC

        LD A, # FF
; At the moment, DE contains a module 1
; Factors, and BC - the second one.
; In the battery - either 0 or FF - a sign that sharp.
ML2 LD HL, 0

        ! ASSM 1916

        RR B

        RR C

        JR NC, $ +3

        ADD HL, DE

        RR H

        RR L

        ! CONT

        RR B

        RR C
; In HLBC now sitting number in the format 16.16
, (The result of multiplying 8.8 * 8.8).
; Further, if the number should be negative; nym - change its 
sign. ; After all this, unceremoniously discarding, eat at a 
byte from the beginning to the end and drive And the result in 
HL. 

        RRCA

        JR NC, NONEG4

        LD A, C

        CPL

        ADD A, 1

        LD A, L

        CPL

        LD H, A

        LD A, B

        CPL

        LD L, A

        RET NC

        INC HL

        RET
NONEG4 LD H, L

        LD L, B

        RET


; Initialization.

INIT XOR A

        OUT (# FE), A

        LD HL, # 4000

        PUSH HL

        LD DE, # 4001

        LD BC, # 1800

        LD (HL), L

        LDIR

        LD BC, # 2FF

        LD (HL), 68

        LDIR

        POP DE

        LD H, DOT

        LD L, E

        LD B, # C0
MK_ADTB LD (HL), E

        INC H

        LD (HL), D

        DEC H

        INC L

        INC D

        LD A, D

        AND 7

        JP NZ, C1

        LD A, E

        ADD A, 32

        LD E, A

        JR C, C1

        LD A, D

        SUB 8

        LD D, A
C1 DJNZ MK_ADTB
CL_LP LD (HL), B

        INC H

        LD (HL), B

        DEC H

        INC L

        JR NZ, CL_LP

        INC H

        INC H

        LD BC, # 801F
MK_B_TB LD A, L

        RRCA

        RRCA

        RRCA

        AND C

        LD (HL), A

        INC H

        LD (HL), B

        DEC H

        RRC B

        INC L

        JR NZ, MK_B_TB

        RET



        ORG $ / 1 256 256


; Table of constants with fixed point.
, Must be on the / 256 addresses.
;
; In 8.8 format constant translated very
; Easy, especially with a calculator CITIZEN.
;
; Example: a number of 0.16.
, Multiply it by 256, we obtain 40.96.
, Rounded to 41.
, Translated in the HEX: # 0029.
;
; If the number is <0, before being transferred to to HEX
; It we add 65536 (# 10000).

CONST1 DW # 0000; A = 0

        DW # 0000; B = 0

        DW # 0000; C = 0

        DW # 0000; D = 0

        DW # 0029; E =. 16

        DW # 0000; F = 0


CONST2 DW # 00DA; A =. 85

        DW # 000A; B =. 04

        DW # 0000; C = 0

        DW # FFF6; D =-. 04

        DW # 00DA; E =. 85

        DW # 019A; F = 1.6


CONST3 DW # 0033; A =. 2

        DW # FFBD; B =-. 26

        DW # 0000; C = 0

        DW # 003B; D =. 23

        DW # 003B; E =. 23

        DW # 019A; F = 1.6


CONST4 DW # FFDA; A =-. 15

        DW # 0048; B =. 28

        DW # 0000; C = 0

        DW # 0043; D =. 26

        DW # 003D; E =. 24

        DW # 0071; F =. 44



   For fun, in a block can CONST2 1-e
number is replaced by # 00B0 - get something
resembling a Christmas tree, or # 0060 - also
like the Christmas tree, but some skinned ...

; Current positions:
X DW # 0000
Y DW # 0000


P.S. At this fractal good test
procedure for obtaining random numbers. If
generated values ​​to them are often repeated
or all of the time fall into a certain interval, which lies 
inside [0, 255], the fractal will not work (you can try to 
remove ksorku with (IX), pointing to the ROM - see what will 
be). 

   Ideally, all numbers should be equally likely, fall into the 
range 0 - 255 and their sequence, one after another is not

should be repeated and any trend (such as there are procedures 
in which the next number is usually greater than the previous 
one). 






Other articles:

Aperativchik - On the control of the shell DEJA VU

Aperativchik - Accuracy - the politeness of kings, the new issue of the journal.

Topic - Fun Top-98 or the obvious and incredible.

Topic - An Interview with Vladimir. Balchukeem before Fun Top-98.

Topic - Results Fun Top-98.

Topic - Photos from Fun Top-98.

drop of solder - ROM, which we vybiraem.Obzor ROM: Penatagon128, Scorpion ZS256, Spectrum128-branded version, Spectrum +2, Spectrum +2, Spectrum +3, ROM from PROFI CLUB.

drop of solder - Additional graphics mode 512x192.

SOFTWARE - New demoscene: FOREVER, ADRENALIZE, BOOM, TYRANY, BLAME, EMERGENCY, KATNARSIS.

SOFTWARE - New game programs: A LAST HERO of the LIGHT FORCE, MONSTR LAND, MIRROR.

CODING - Ultra-fast disk drives SPECCY.

CODING - Lessons from the encoder: Fractal paparatnik.

CODING - Driver read / write.

CODING - Lessons from the encoder: Generilka balls.

CODING - The algorithms of data compression.

CODING - On obechatke Listing of stack (5 rooms).

ANOTHER WORLD - WINDOWS-95 and beyond.

ANOTHER WORLD - News from the INTEL-a ...

ANOTHER WORLD - work PC and software

Hall of Fame - On spektrumskih journals.

Hall of Fame - letters to the editor.

Hall of Fame - On CD-ROM project from the city of Kemerovo.

Seven and 1 / 2 - Features a national ruleza 2 or ordered motion of electrons.

Seven and 1 / 2 - Guide for consumers of beer.

Seven and 1 / 2 - What if your computer does not work (Instructions for Hacker).

Seven and 1 / 2 - Guessing on cockroaches (Advice to a beginning hunter).

Seven and 1 / 2 - Instructions for use with a ballpoint pen.

attempt at writing - Poems Bazhenova: Candles, Confusion, Fall, Bezishodnost.

attempt at writing - Many Adventures of Winnie the Pooh (Part 3).

attempt at writing - Daily Hacker ordinary.

Advertising - Advertisements and announcements ...


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

Similar articles:
Likbez - a full disassembler ROM (part 31).
Demoparty - the truth: the truth about SS'2001 - recognition Random'a.
Your Server - On the bad user BBS.

В этот день...   21 November