-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJULIASET.ASM
167 lines (150 loc) · 3.24 KB
/
JULIASET.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
; Fractal entry point
; Set some global definitions
MAX_ITERATIONS equ 48
COLOR_PALLETE equ 0x800000
TMP_BUFFER equ 0xC00000
; Create color pallete
xor eax,eax
xor ecx,ecx
mov edi,COLOR_PALLETE
cld
jmp savecolor
nextcolor:
cmp cl,0x10
jae shiftpallete1
mov ah,cl
shl ah,0x03
mov al,ah
shl eax,0x08
mov al,cl
shl al,0x02
add al,0x80
jmp savecolor
shiftpallete1:
cmp cl,0x40
jae shiftpallete2
mov ah,cl
add ah,0x70
mov al,ah
shl eax,0x08
mov al,cl
add al,0xB0
jmp savecolor
shiftpallete2:
push ecx
mov ch,0xFF
sub cl,0x40
sub ch,cl
mov ah,ch
mov al,ch
shr al,0x01
add al,0x80
shl eax,0x08
mov al,ch
pop ecx
savecolor:
stosd
inc ecx
cmp ecx,0x400000
jbe nextcolor
; Start calculation
xorps xmm4,xmm4 ; Global xmm4 is alpha
movapd xmm5,[zoom] ; Global xmm5 is zoom
movapd xmm6,[scale] ; Global xmm6 is constant
xorps xmm7,xmm7 ; Global xmm7 is pixel position
repeat:
; Main loop, xmm0=screen_to_complex_plane(xmm7)
movapd xmm0,xmm7
subpd xmm0,[center]
divpd xmm0,xmm5
mov ecx,0x01
; Iterate
nextiteration:
; Compute xmm0=xmm0^4+xmm6
movapd xmm1,xmm0
mulpd xmm1,xmm1
hsubpd xmm1,xmm1
movapd xmm2,xmm0
shufpd xmm2,xmm2,0x01
mulpd xmm0,xmm2
addpd xmm0,xmm0
movsd xmm0,xmm1
movapd xmm1,xmm0
mulpd xmm1,xmm1
hsubpd xmm1,xmm1
movapd xmm2,xmm0
shufpd xmm2,xmm2,0x01
mulpd xmm0,xmm2
addpd xmm0,xmm0
movsd xmm0,xmm1
addpd xmm0,xmm6
; Diverge to infinity ?
movapd xmm1,xmm0
mulpd xmm1,xmm1
haddpd xmm1,xmm1
ucomisd xmm1,[infinity]
jae draw
; Next iteration
inc ecx
cmp ecx,MAX_ITERATIONS
jb nextiteration
xor ecx,ecx
draw:
; Get color and save it to buffer
mov eax,[COLOR_PALLETE+ecx*0x04]
movapd xmm0,xmm7
mulpd xmm0,[linearizepixels]
haddpd xmm0,xmm0
cvtsd2si edi,xmm0
mov [TMP_BUFFER+edi*0x04],eax
; Increment screen index x in xmm7
addpd xmm7,[incX]
comisd xmm7,[screenX]
jb repeat
movlpd xmm7,[zero]
; Increment screen index y in xmm7
addpd xmm7,[incY]
movapd xmm0,xmm7
shufpd xmm0,xmm0,0x01
ucomisd xmm0,[screenY]
jb repeat
xorps xmm7,xmm7
; Pseudo v-sync
xor edi,edi
mov esi,TMP_BUFFER
mov ecx,1280*1024
push es
mov ax,SELECTOR_LFB
mov es,ax
rep movsd
pop es
; Compute xmm6=scale*e^(i*xmm4)
movsd [esp-0x08],xmm4
fld qword[esp-0x08]
fcos
fstp qword[esp-0x10]
fld qword[esp-0x08]
fsin
fstp qword[esp-0x18]
movupd xmm6,[esp-0x18]
mulpd xmm6,[scale]
; Increment xmm4 (should be in range from 0 to 2*pi)
addsd xmm4,[addconst]
ucomisd xmm4,[addmax]
jb repeat
xorps xmm4,xmm4
jmp repeat
ALIGN 0x10
incX dq 1.0,0.0
incY dq 0.0,1.0
screenX dq 1280.0
screenY dq 1024.0
center dq 640.0,512.0
zoom dq 250.0,250.0
linearizepixels dq 1.0,1280.0
infinity dq 4.0
zero dq 0.0
addconst dq 0.02
addmax dq 6.28318
scale dq 1.0,1.0 ;0.78,0.78