1 ; 6502 assembler Sierpinsky Triangle ver.2
2 ; by Magnus Wedmark 2007-05-02
3 ; This program is especially written for
4 ; the 6502asm.com competition and
5 ; uses the 32*32 pixel display used in that
6 ; virtual platform. The sierpinsky
7 ; fractal is one of the simplest to
8 ; implement. Here is a walk-through:
9 ; 1) Specify 3 points that form a triangle
10 ; 2) Choose one of them as a starting point
11 ; 3) Choose one of them as targetpoint randomly
12 ; 4) Set the new current position half-way
13 ; between the current point and the target
20 LDA $FE ; random 0-255
21 AND #3 ; only 0-3 left
28 ; transform X and Y values according to:
29 ; X=X/2+(P*8) and Y=Y/2+(P*16)
40 STA $F4 ; (P AND 1)*16
49 JSR set_point ; use and restore regs
52 set_point: ; uses both X,Y,A and restores them
53 PHA ; backup all reg-value (X,Y,A)
59 PHA ; triple Y push, two for int. use
60 STX $F2 ; transfer X to Y using $F2
65 STA $F1 ; set base vector to $200
67 PLA ; transfer the pushed Y-coord to A
68 AND #$07 ; the value %0000'0111
81 PLA ; transfer the pushed Y-coord to A
94 LDA #1 ;1 = white for trouble-shooting
95 JSR set_toning_point ; use for shading
96 STA ($F0),Y ; set pixel
97 PLA ; restore all reg-value (X,Y,A)
104 ; sub routine to shade the current pixel ($F0),Y
105 ; lighter on a scale: $0, $B, $C, $F, $1
106 ; Black, DarkGrey, Grey, LightGrey, White