-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.S
237 lines (212 loc) · 4.63 KB
/
draw.S
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
.global draw
.global edgem
.global trim
.global spherem
.global name
.global parsefd
.global half
.global data
.global minval
.data
.align 32
x: .quad 0
half: .double .5
.align 32
name: .asciz "./image.ppm"
.align 32
parsefile: .asciz "./script"
.align 32
minval: .double -inf
bnlen: .quad 0
convert: .asciz "convert"
.align 32
delay: .asciz "-delay"
.align 32
delaytime: .asciz "3"
.align 32
execpath: .quad 0,0,0
animationlp: .zero 4096
basefactor: .double 1, 1, 1, 0
.bss
.align 32
data: .zero 1048576
.align 32
edgem: .quad 0
drawm: .quad 0
trim: .quad 0
spherem: .quad 0
parsefd: .quad 0
.text
draw:
call initheap
mov $10, %rdi
mov $4, %rsi
call makematrix
mov %rax, edgem(%rip)//make tiny dummy edge matrix
mov $8192, %rdi
mov $4, %rsi
call makematrix
mov %rax, trim(%rip)//make tiny dummy trimatrix
mov $8192, %rdi
mov $4, %rsi
call makematrix
mov %rax, spherem(%rip)//make tiny dummy spherematrix
mov $4, %rdi
mov $4, %rsi
call makematrix
push %rax
mov 32(%rax), %rcx
vmovupd basefactor(%rip), %ymm0
vmovupd %ymm0, (%rcx)
mov %rax, %rdi
call identitymatrix//make identity coordinate stack matrix
mov $16, %rdi
call alloc@PLT
mov %rax, cstop(%rip)
pop %rdi
mov %rdi, (%rax)
call init_temps//initialize temporary values
xor %rax, %rax
nextop:
push %rax
mov $0, %rdx//0th pass
call handleop
pop %rax
inc %rax
cmp lastop(%rip), %rax
jl nextop
xor %rax, %rax
nextop1:
push %rax
mov $1, %rdx//1st pass
call handleop
pop %rax
inc %rax
cmp lastop(%rip), %rax
jl nextop1
mov num_frames(%rip), %rcx
test %rcx, %rcx
jz nofrills
lea basename(%rip), %rdi
call mstrlen
mov %rax, bnlen(%rip)
movl $0x702E3030, (%rdi, %rax)
movw $0x6D70, 4(%rdi, %rax)
xor %rcx, %rcx
frameloop:
push %rcx
call setknobs
xor %rax, %rax
nextop2:
push %rax
mov $2, %rdx//2nd pass
call handleop
pop %rax
inc %rax
cmp lastop(%rip), %rax
jl nextop2
lea basename(%rip), %rdi
mov (%rsp), %rcx //get first 2 letters from A (0) to P (15), for a pseudo hex format
mov %rcx, %rdx
and $0b1111, %rcx
and $0b11110000, %rdx
shr $4, %rdx
addb $0x41, %cl
addb $0x41, %dl //dl is first digit from 0 to 15, cl is second digit
mov bnlen(%rip), %rax
mov %dl, (%rdi, %rax)
mov %cl, 1(%rdi, %rax)
call saveit
lea data(%rip), %rdi
xor %rax, %rax
mov $131072, %rcx
rep stosq
mov trim(%rip), %rdi
mov edgem(%rip), %rsi
movq $0, 24(%rdi)
movq $0, 24(%rsi)
mov spherem(%rip), %rdi
movq $0, 24(%rdi)
call cspop
pop %rcx
inc %rcx
cmp num_frames(%rip), %rcx
jl frameloop
mov edgem(%rip), %rdi
call freematrix//free edge matrix
mov trim(%rip), %rdi
call freematrix//free trimatrix
csstackstillanim:
call cspop//free last item on coordinate stack
cmpq $0, cstop(%rip)
jne csstackstillanim
call free_temps
lea basename(%rip), %rdi
mov bnlen(%rip), %rax
movw $0x02a, (%rdi, %rax)
sub $32, %rsp
xor %rsi, %rsi
xor %rdx, %rdx
mov %rsp, %rcx
call glob@PLT
lea basename(%rip), %rdi
mov bnlen(%rip), %rax
movl $0x6669672E, 0(%rdi, %rax)
movb $0x00, 4(%rdi, %rax)
mov (%rsp),%rcx
mov %rcx, execpath(%rip)
lea animationlp(%rip), %rdi
mov 8(%rsp), %rsi
rep movsq
mov execpath(%rip), %rcx
lea convert(%rip), %rdi
lea execpath(%rip), %rsi
mov %rdi, (%rsi)
lea delay(%rip), %rdi
mov %rdi, 8(%rsi)
lea delaytime(%rip), %rdi
mov %rdi, 16(%rsi)
lea basename(%rip), %rdi
mov %rdi, 24(%rsi, %rcx,8)
mov $57, %rax
syscall
test %rax, %rax
jnz animover
lea convert(%rip), %rdi
lea execpath(%rip), %rsi
call execvp@PLT
mov %rsp, %rdi
call globfree@PLT
animover:
mov $61, %rax
mov $-1, %rdi
xor %rsi, %rsi
xor %rdx, %rdx
xor %rcx, %rcx
syscall
add $32, %rsp
jmp endfrills
nofrills:
xor %rax, %rax
nextop2n:
push %rax
mov $2, %rdx//0th pass
call handleop
pop %rax
inc %rax
cmp lastop(%rip), %rax
jl nextop2n
mov edgem(%rip), %rdi
call freematrix//free edge matrix
mov trim(%rip), %rdi
call freematrix//free trimatrix
mov spherem(%rip), %rdi
call freematrix
csstackstill:
call cspop//free last item on coordinate stack
cmpq $0, cstop(%rip)
jne csstackstill
call free_temps
endfrills:
call deinitheap
ret