-
Notifications
You must be signed in to change notification settings - Fork 1
/
rubikscube.asm
1442 lines (1315 loc) · 26.2 KB
/
rubikscube.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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.entry
push %rbp
mov %rsp,%rbp
call @prog_init
sub $112,%rsp
xor %ecx,%ecx
movq $80,32+0(%rsp)
lea @WndProc-@_$NEXT(%rip),%rax
mov %rax,32+8(%rsp)
mov %rcx,32+16(%rsp)
lea @_$IMAGE-@_$NEXT(%rip),%rax
mov %rax,32+24(%rsp)
mov %rcx,32+32(%rsp)
movq $8,32+48(%rsp)
mov %rcx,32+56(%rsp)
lea @WName-@_$NEXT(%rip),%rax
mov %rax,32+64(%rsp)
mov %rcx,32+72(%rsp)
mov $0x7f00,%edx
.dllcall "user32.dll" "LoadCursorA"
mov %rax,32+40(%rsp)
lea 32(%rsp),%rcx
.dllcall "user32.dll" "RegisterClassExA"
test %rax,%rax
je @Err_Exit
xor %ecx,%ecx
mov $0x80000000,%edx
push %rcx
lea @_$IMAGE-@_$NEXT(%rip),%rax
push %rax
push %rcx
push %rcx
pushq $600
pushq $600
push %rdx
push %rdx
mov $0x100,%ecx
lea @WName-@_$NEXT(%rip),%rdx
mov %rdx,%r8
mov $0x10c80000,%r9d
sub $32,%rsp
.dllcall "user32.dll" "CreateWindowExA"
test %rax,%rax
je @Err_Exit
mov %rax,%rcx
mov $1,%edx
mov $12,%r8d
xor %r9d,%r9d
.dllcall "user32.dll" "SetTimer"
@MsgLoop
lea 32(%rsp),%rcx
xor %edx,%edx
mov %edx,%r8d
mov %edx,%r9d
.dllcall "user32.dll" "GetMessageA"
cmp $0,%rax
jle @Err_Exit
lea 32(%rsp),%rcx
.dllcall "user32.dll" "TranslateMessage"
lea 32(%rsp),%rcx
.dllcall "user32.dll" "DispatchMessageA"
jmp @MsgLoop
@Err_Exit
xor %eax,%eax
mov %rbp,%rsp
pop %rbp
ret
@prog_init
sub $40,%rsp
.dllcall "user32.dll" "SetProcessDPIAware"
mov $0x3f800000,%eax
mov %eax,@_$DATA+0-@_$NEXT(%rip)
mov %eax,@_$DATA+20-@_$NEXT(%rip)
mov %eax,@_$DATA+40-@_$NEXT(%rip)
mov $0x0101010101010101,%rcx
mov %rcx,%rax
mov %rax,@_$DATA+256+16-@_$NEXT(%rip)
mov %rax,@_$DATA+256+24-@_$NEXT(%rip)
add %rcx,%rax
mov %rax,@_$DATA+256+32-@_$NEXT(%rip)
mov %rax,@_$DATA+256+40-@_$NEXT(%rip)
add %rcx,%rax
mov %rax,@_$DATA+256+48-@_$NEXT(%rip)
mov %rax,@_$DATA+256+56-@_$NEXT(%rip)
add %rcx,%rax
mov %rax,@_$DATA+256+64-@_$NEXT(%rip)
mov %rax,@_$DATA+256+72-@_$NEXT(%rip)
add %rcx,%rax
mov %rax,@_$DATA+256+80-@_$NEXT(%rip)
mov %rax,@_$DATA+256+88-@_$NEXT(%rip)
add $40,%rsp
ret
@paint_triangle_2d_subproc
mov 32(%rbp),%esi
sub 16(%rbp),%esi
mov 56(%rbp),%edi
sub 40(%rbp),%edi
mov %ecx,%eax
sub 40(%rbp),%eax
imul %esi
idiv %edi
add 16(%rbp),%eax
mov %eax,24(%rsp)
# paint_line
# 16(%rbp) -- y
# 24(%rbp) -- x1
# 32(%rbp) -- x2
# 40(%rbp) -- color
push %rbp
mov %rsp,%rbp
push %rcx
push %rdx
push %rsi
mov 24(%rbp),%eax
mov 32(%rbp),%ecx
cmp %eax,%ecx
jg @paint_line_swap
mov %eax,32(%rbp)
mov %ecx,24(%rbp)
sub %ecx,%eax
je @paint_line_end
@paint_line_swap
mov 16(%rbp),%eax
neg %eax
add $300,%eax
mov $600,%edx
imul %edx
mov 32(%rbp),%ecx
mov 24(%rbp),%edx
sub %edx,%ecx
add %edx,%eax
shl $2,%eax
lea @_$DATA+4096+1200-@_$NEXT(%rip),%rdx
add %rdx,%rax
mov 112-4096-1200(%rdx),%esi
mov 40(%rbp),%edx
@paint_line_loop
mov %edx,(%rax)
mov %esi,1440000(%rax)
add $4,%rax
dec %ecx
jne @paint_line_loop
@paint_line_end
pop %rsi
pop %rdx
pop %rcx
mov %rbp,%rsp
pop %rbp
ret
@swap_points
# %eax -- p1
# %ecx -- p2
mov (%rax),%rdx
xchg %rdx,(%rcx)
mov %rdx,(%rax)
mov -24(%rax),%rdx
xchg %rdx,-24(%rcx)
mov %rdx,-24(%rax)
ret
@paint_triangle_2d
# 16(%rbp) -- x1
# 24(%rbp) -- x2
# 32(%rbp) -- x3
# 40(%rbp) -- y1
# 48(%rbp) -- y2
# 56(%rbp) -- y3
# 88(%rbp) -- color
push %rbp
mov %rsp,%rbp
push %rax
push %rcx
push %rdx
push %rsi
push %rdi
mov 40(%rbp),%eax
lea 48(%rbp),%rcx
cmp (%rcx),%eax
jle @paint_triangle_2d_sort1
lea 40(%rbp),%rax
call @swap_points
@paint_triangle_2d_sort1
mov 40(%rbp),%eax
lea 56(%rbp),%rcx
cmp (%rcx),%eax
jle @paint_triangle_2d_sort2
lea 40(%rbp),%rax
call @swap_points
@paint_triangle_2d_sort2
mov 48(%rbp),%eax
lea 56(%rbp),%rcx
cmp (%rcx),%eax
jle @paint_triangle_2d_sort3
lea 48(%rbp),%rax
call @swap_points
@paint_triangle_2d_sort3
sub $48,%rsp
mov 88(%rbp),%eax
mov %eax,24(%rsp)
mov 40(%rbp),%ecx
@paint_triangle_2d_loop1
cmp 48(%rbp),%ecx
jge @paint_triangle_2d_loop1_end
mov %ecx,(%rsp)
mov 24(%rbp),%esi
sub 16(%rbp),%esi
mov 48(%rbp),%edi
sub 40(%rbp),%edi
mov %ecx,%eax
sub 40(%rbp),%eax
imul %esi
idiv %edi
add 16(%rbp),%eax
mov %eax,8(%rsp)
call @paint_triangle_2d_subproc
inc %ecx
jmp @paint_triangle_2d_loop1
@paint_triangle_2d_loop1_end
@paint_triangle_2d_loop2
cmp 56(%rbp),%ecx
jge @paint_triangle_2d_loop2_end
mov %ecx,(%rsp)
mov 32(%rbp),%esi
sub 24(%rbp),%esi
mov 56(%rbp),%edi
sub 48(%rbp),%edi
mov %ecx,%eax
sub 48(%rbp),%eax
imul %esi
idiv %edi
add 24(%rbp),%eax
mov %eax,8(%rsp)
call @paint_triangle_2d_subproc
inc %ecx
jmp @paint_triangle_2d_loop2
@paint_triangle_2d_loop2_end
add $48,%rsp
pop %rdi
pop %rsi
pop %rdx
pop %rcx
pop %rax
mov %rbp,%rsp
pop %rbp
ret
@vector_transform
# %rax -- ptr
push %rcx
movss 4(%rax),%xmm5
movss 8(%rax),%xmm3
mov $20,%ecx
cvtsi2ss %ecx,%xmm0
addss %xmm0,%xmm5
divss %xmm5,%xmm3
movss %xmm3,4(%rax)
movss (%rax),%xmm0
divss %xmm5,%xmm0
movss %xmm0,(%rax)
pop %rcx
ret
@paint_triangle_3d
# 16(%rbp) -- p1
# 32(%rbp) -- p2
# 48(%rbp) -- p3
# 64(%rbp) -- color
push %rbp
mov %rsp,%rbp
push %rax
push %rcx
push %rdx
sub $80,%rsp
mov 64(%rbp),%eax
mov %eax,72(%rsp)
lea 16(%rsp),%rax
mov $48,%ecx
@paint_triangle_3d_loop
push %rax
lea (%rcx,%rbp,1),%rax
call @vector_transform
pop %rax
mov $1400,%edx
cvtsi2ss %edx,%xmm1
movss (%rcx,%rbp,1),%xmm0
mulss %xmm1,%xmm0
cvtss2si %xmm0,%edx
mov %edx,(%rax)
movss 4(%rcx,%rbp,1),%xmm0
mulss %xmm1,%xmm0
cvtss2si %xmm0,%edx
mov %edx,24(%rax)
sub $8,%rax
sub $16,%ecx
jne @paint_triangle_3d_loop
call @paint_triangle_2d
add $80,%rsp
pop %rdx
pop %rcx
pop %rax
mov %rbp,%rsp
pop %rbp
ret
@paint_square
# 16(%rbp) -- start
# 32(%rbp) -- x_vec
# 48(%rbp) -- y_vec
# 64(%rbp) -- z_vec
# 80(%rbp) -- red
# 84(%rbp) -- green
# 88(%rbp) -- blue
# 92(%rbp) -- width
push %rbp
mov %rsp,%rbp
push %rax
push %rcx
sub $112,%rsp
movups 16(%rbp),%xmm0
mov $0x41a00000,%eax
movq %rax,%xmm1
shufps $0x51,%xmm1,%xmm1
addps %xmm1,%xmm0
mulps 64(%rbp),%xmm0
movups %xmm0,%xmm1
movups %xmm0,%xmm2
shufps $0x1,%xmm1,%xmm1
shufps $0x2,%xmm2,%xmm2
addss %xmm1,%xmm0
addss %xmm2,%xmm0
xor %eax,%eax
movd %eax,%xmm1
comiss %xmm1,%xmm0
ja @paint_square_end
movss 68(%rbp),%xmm2
mov $125,%eax
cvtsi2ss %eax,%xmm1
mulss %xmm1,%xmm2
mov $128,%eax
cvtsi2ss %eax,%xmm1
subss %xmm2,%xmm1
movss 80(%rbp),%xmm0
mulss %xmm1,%xmm0
cvtss2si %xmm0,%eax
mov %ax,50(%rsp)
movss 84(%rbp),%xmm0
mulss %xmm1,%xmm0
cvtss2si %xmm0,%eax
mov %al,49(%rsp)
movss 88(%rbp),%xmm0
mulss %xmm1,%xmm0
cvtss2si %xmm0,%eax
mov %al,48(%rsp)
movss 92(%rbp),%xmm0
shufps $0x00,%xmm0,%xmm0
movups 16(%rbp),%xmm1
movups %xmm1,(%rsp)
movups %xmm1,80(%rsp)
movups 32(%rbp),%xmm2
movups 48(%rbp),%xmm3
mulps %xmm0,%xmm2
mulps %xmm0,%xmm3
addps %xmm2,%xmm1
movups %xmm1,16(%rsp)
addps %xmm3,%xmm1
movups %xmm1,32(%rsp)
movups %xmm1,96(%rsp)
subps %xmm2,%xmm1
movups %xmm1,64(%rsp)
call @paint_triangle_3d
movups 96(%rsp),%xmm1
movups %xmm1,(%rsp)
movups 64(%rsp),%xmm1
movups %xmm1,16(%rsp)
movups 80(%rsp),%xmm1
movups %xmm1,32(%rsp)
call @paint_triangle_3d
@paint_square_end
add $112,%rsp
pop %rcx
pop %rax
pop %rbp
ret
@paint_full_square
# 16(%rbp) -- start
# 32(%rbp) -- x_vec
# 48(%rbp) -- y_vec
# 64(%rbp) -- z_vec
# 80(%rbp) -- red
# 84(%rbp) -- green
# 88(%rbp) -- blue
push %rbp
mov %rsp,%rbp
push %rax
sub $104,%rsp
movups 16(%rbp),%xmm0
movups %xmm0,(%rsp)
movups 32(%rbp),%xmm0
movups %xmm0,16(%rsp)
movups 48(%rbp),%xmm0
movups %xmm0,32(%rsp)
movups 64(%rbp),%xmm0
movups %xmm0,48(%rsp)
movl $0x3f000000,64(%rsp)
movl $0x3f000000,68(%rsp)
movl $0x3f000000,72(%rsp)
movl $0x3f800000,76(%rsp)
call @paint_square
movups (%rsp),%xmm0
movups 16(%rsp),%xmm1
movups 32(%rsp),%xmm2
mov $0x3e000000,%eax
movd %eax,%xmm3
shufps $0x00,%xmm3,%xmm3
mulps %xmm3,%xmm1
mulps %xmm3,%xmm2
addps %xmm1,%xmm0
addps %xmm2,%xmm0
movups %xmm0,(%rsp)
movups 80(%rbp),%xmm0
movups %xmm0,64(%rsp)
movl $0x3f400000,76(%rsp)
call @paint_square
add $104,%rsp
pop %rax
pop %rbp
ret
@get_xyz
# %rax -- ptr
# %rcx -- num
push %rdx
cmp $2,%cl
jae @get_xyz_X1
movups @_$DATA+0-@_$NEXT(%rip),%xmm0
movups %xmm0,(%rax)
movups @_$DATA+16-@_$NEXT(%rip),%xmm0
movups %xmm0,16(%rax)
movups @_$DATA+32-@_$NEXT(%rip),%xmm0
movups %xmm0,32(%rax)
jmp @get_xyz_end
@get_xyz_X1
cmp $4,%cl
jae @get_xyz_X2
movups @_$DATA+16-@_$NEXT(%rip),%xmm0
movups %xmm0,0(%rax)
movups @_$DATA+32-@_$NEXT(%rip),%xmm0
movups %xmm0,16(%rax)
movups @_$DATA+0-@_$NEXT(%rip),%xmm0
movups %xmm0,32(%rax)
jmp @get_xyz_end
@get_xyz_X2
movups @_$DATA+32-@_$NEXT(%rip),%xmm0
movups %xmm0,0(%rax)
movups @_$DATA+0-@_$NEXT(%rip),%xmm0
movups %xmm0,16(%rax)
movups @_$DATA+16-@_$NEXT(%rip),%xmm0
movups %xmm0,32(%rax)
@get_xyz_end
test $1,%cl
je @get_xyz_noneg
movups (%rax),%xmm0
movups 16(%rax),%xmm1
movups %xmm1,(%rax)
movups %xmm0,16(%rax)
movups 32(%rax),%xmm0
mov $0xbf800000,%edx
movd %edx,%xmm1
shufps $0x00,%xmm1,%xmm1
mulps %xmm1,%xmm0
movups %xmm0,32(%rax)
@get_xyz_noneg
pop %rdx
ret
@get_xyz_r
# %rax -- ptr
# %rcx -- num
push %rdx
cmp $2,%cl
jae @get_xyz_r_X1
movups @_$DATA+48-@_$NEXT(%rip),%xmm0
movups %xmm0,(%rax)
movups @_$DATA+64-@_$NEXT(%rip),%xmm0
movups %xmm0,16(%rax)
movups @_$DATA+80-@_$NEXT(%rip),%xmm0
movups %xmm0,32(%rax)
jmp @get_xyz_r_end
@get_xyz_r_X1
cmp $4,%cl
jae @get_xyz_r_X2
movups @_$DATA+64-@_$NEXT(%rip),%xmm0
movups %xmm0,0(%rax)
movups @_$DATA+80-@_$NEXT(%rip),%xmm0
movups %xmm0,16(%rax)
movups @_$DATA+48-@_$NEXT(%rip),%xmm0
movups %xmm0,32(%rax)
jmp @get_xyz_r_end
@get_xyz_r_X2
movups @_$DATA+80-@_$NEXT(%rip),%xmm0
movups %xmm0,0(%rax)
movups @_$DATA+48-@_$NEXT(%rip),%xmm0
movups %xmm0,16(%rax)
movups @_$DATA+64-@_$NEXT(%rip),%xmm0
movups %xmm0,32(%rax)
@get_xyz_r_end
test $1,%cl
je @get_xyz_r_noneg
movups (%rax),%xmm0
movups 16(%rax),%xmm1
movups %xmm1,(%rax)
movups %xmm0,16(%rax)
movups 32(%rax),%xmm0
mov $0xbf800000,%edx
movd %edx,%xmm1
shufps $0x00,%xmm1,%xmm1
mulps %xmm1,%xmm0
movups %xmm0,32(%rax)
@get_xyz_r_noneg
pop %rdx
ret
@is_square_rotating
# %rcx -- num
# return -- 0: no, 1: yes, 2: invalid
push %rcx
push %rdx
lea @_$DATA-@_$NEXT(%rip),%rdx
cmp $96,%cl
jae @is_square_rotating_invalid
mov %cl,%al
and $15,%al
cmp $11,%al
jae @is_square_rotating_invalid
and $3,%al
cmp $3,%al
je @is_square_rotating_invalid
mov 96(%rdx),%al
cmp $0,%al
je @is_square_rotating_no
dec %al
lea (%rax,%rax,2),%eax
shl $1,%al
mov %cl,%ch
shr $4,%ch
add %ch,%al
movzbl %al,%eax
shl $1,%eax
mov @rotating_list-@_$DATA(%rdx,%rax,1),%ax
and $0xf,%cl
shr %cl,%ax
test $1,%al
jne @is_square_rotating_yes
@is_square_rotating_no
xor %eax,%eax
pop %rdx
pop %rcx
ret
@is_square_rotating_invalid
mov $2,%eax
pop %rdx
pop %rcx
ret
@is_square_rotating_yes
mov $1,%eax
pop %rdx
pop %rcx
ret
@paint_squares_not_rotating
push %rax
push %rcx
push %rdx
push %rbx
sub $136,%rsp
lea @_$DATA-@_$NEXT(%rip),%rbx
movl $96,112(%rsp)
@paint_squares_not_rotating_loop
mov 112(%rsp),%ecx
dec %ecx
call @is_square_rotating
test %eax,%eax
jne @paint_squares_not_rotating_loop_continue
lea 16(%rsp),%rax
shr $4,%ecx
call @get_xyz
mov $0x3fc00000,%edx
movd %edx,%xmm0
mov 112(%rsp),%ecx
dec %ecx
and $0x3,%ecx
cvtsi2ss %ecx,%xmm1
mov 112(%rsp),%ecx
dec %ecx
shr $2,%ecx
and $0x3,%ecx
cvtsi2ss %ecx,%xmm2
shufps $0x00,%xmm0,%xmm0
shufps $0x00,%xmm1,%xmm1
shufps $0x00,%xmm2,%xmm2
subps %xmm0,%xmm1
subps %xmm0,%xmm2
movups 48(%rsp),%xmm3
mulps %xmm0,%xmm3
movups 16(%rsp),%xmm4
mulps %xmm1,%xmm4
addps %xmm4,%xmm3
movups 32(%rsp),%xmm4
mulps %xmm2,%xmm4
addps %xmm4,%xmm3
movups %xmm3,(%rsp)
mov 112(%rsp),%ecx
dec %ecx
mov %ecx,112(%rbx)
movzbl 256(%rbx,%rcx,1),%ecx
shl $4,%ecx
movups @square_colors-@_$DATA(%rbx,%rcx,1),%xmm0
movups %xmm0,64(%rsp)
call @paint_full_square
@paint_squares_not_rotating_loop_continue
decl 112(%rsp)
jne @paint_squares_not_rotating_loop
cmpb $0,@_$DATA+96-@_$NEXT(%rip)
je @paint_squares_not_rotating_end
mov @_$DATA+96-@_$NEXT(%rip),%cl
dec %cl
lea 16(%rsp),%rax
call @get_xyz
mov $0x3f000000,%eax
movd %eax,%xmm0
mov $0x3fc00000,%eax
movd %eax,%xmm1
shufps $0x00,%xmm0,%xmm0
shufps $0x00,%xmm1,%xmm1
movups 48(%rsp),%xmm2
mulps %xmm0,%xmm2
movups 16(%rsp),%xmm3
mulps %xmm1,%xmm3
subps %xmm3,%xmm2
movups 32(%rsp),%xmm3
mulps %xmm1,%xmm3
subps %xmm3,%xmm2
movups %xmm2,(%rsp)
mov $0x3f000000,%eax
mov %eax,64(%rsp)
mov %eax,68(%rsp)
mov %eax,72(%rsp)
movl $0x40400000,76(%rsp)
call @paint_square
@paint_squares_not_rotating_end
add $136,%rsp
pop %rbx
pop %rdx
pop %rcx
pop %rax
ret
@paint_squares_rotating
push %rax
push %rcx
push %rdx
push %rbx
sub $136,%rsp
lea @_$DATA-@_$NEXT(%rip),%rbx
movl $96,112(%rsp)
@paint_squares_rotating_loop
mov 112(%rsp),%ecx
dec %ecx
call @is_square_rotating
cmp $1,%eax
jne @paint_squares_rotating_loop_continue
lea 16(%rsp),%rax
shr $4,%ecx
call @get_xyz_r
mov $0x3fc00000,%edx
movd %edx,%xmm0
mov 112(%rsp),%ecx
dec %ecx
and $0x3,%ecx
cvtsi2ss %ecx,%xmm1
mov 112(%rsp),%ecx
dec %ecx
shr $2,%ecx
and $0x3,%ecx
cvtsi2ss %ecx,%xmm2
shufps $0x00,%xmm0,%xmm0
shufps $0x00,%xmm1,%xmm1
shufps $0x00,%xmm2,%xmm2
subps %xmm0,%xmm1
subps %xmm0,%xmm2
movups 48(%rsp),%xmm3
mulps %xmm0,%xmm3
movups 16(%rsp),%xmm4
mulps %xmm1,%xmm4
addps %xmm4,%xmm3
movups 32(%rsp),%xmm4
mulps %xmm2,%xmm4
addps %xmm4,%xmm3
movups %xmm3,(%rsp)
mov 112(%rsp),%ecx
dec %ecx
movzbl 256(%rbx,%rcx,1),%ecx
shl $4,%ecx
movups @square_colors-@_$DATA(%rbx,%rcx,1),%xmm0
movups %xmm0,64(%rsp)
call @paint_full_square
@paint_squares_rotating_loop_continue
decl 112(%rsp)
jne @paint_squares_rotating_loop
cmpb $0,@_$DATA+96-@_$NEXT(%rip)
je @paint_squares_rotating_end
mov @_$DATA+96-@_$NEXT(%rip),%cl
dec %cl
xor $1,%cl
lea 16(%rsp),%rax
call @get_xyz_r
mov $0xbf000000,%eax
movd %eax,%xmm0
mov $0x3fc00000,%eax
movd %eax,%xmm1
shufps $0x00,%xmm0,%xmm0
shufps $0x00,%xmm1,%xmm1
movups 48(%rsp),%xmm2
mulps %xmm0,%xmm2
movups 16(%rsp),%xmm3
mulps %xmm1,%xmm3
subps %xmm3,%xmm2
movups 32(%rsp),%xmm3
mulps %xmm1,%xmm3
subps %xmm3,%xmm2
movups %xmm2,(%rsp)
mov $0x3f000000,%eax
mov %eax,64(%rsp)
mov %eax,68(%rsp)
mov %eax,72(%rsp)
movl $0x40400000,76(%rsp)
call @paint_square
@paint_squares_rotating_end
add $136,%rsp
pop %rbx
pop %rdx
pop %rcx
pop %rax
ret
@rotate_around
# 16(%rbp) -- pointer to axis
# 24(%rbp) -- pointer to vector
# 32(%rbp) -- angle
push %rbp
mov %rsp,%rbp
push %rax
push %rcx
sub $96,%rsp
mov 16(%rbp),%rax
mov 24(%rbp),%rcx
mov %rcx,56(%rsp)
movups (%rax),%xmm0
movups (%rcx),%xmm1
movups %xmm0,%xmm2
mulps %xmm1,%xmm2
movups %xmm2,%xmm3
movups %xmm2,%xmm4
shufps $0x01,%xmm3,%xmm3
shufps $0x02,%xmm4,%xmm4
addss %xmm3,%xmm2
addss %xmm4,%xmm2
shufps $0x00,%xmm2,%xmm2
movups %xmm0,%xmm3
mulps %xmm3,%xmm2
movups %xmm1,%xmm3
subps %xmm2,%xmm3
movups %xmm2,64(%rsp)
movups %xmm3,80(%rsp)
movups %xmm0,%xmm2
movups %xmm3,%xmm1
shufps $0x09,%xmm0,%xmm0
shufps $0x12,%xmm1,%xmm1
shufps $0x12,%xmm2,%xmm2
shufps $0x09,%xmm3,%xmm3
mulps %xmm1,%xmm0
mulps %xmm3,%xmm2
subps %xmm2,%xmm0
movups %xmm0,32(%rsp)
movss 32(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
.dllcall "msvcrt.dll" "sin"
cvtsd2ss %xmm0,%xmm0
movss %xmm0,48(%rsp)
movss 32(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
.dllcall "msvcrt.dll" "cos"
cvtsd2ss %xmm0,%xmm0
shufps $0x00,%xmm0,%xmm0
movss 48(%rsp),%xmm1
shufps $0x00,%xmm1,%xmm1
movups 80(%rsp),%xmm2
movups 32(%rsp),%xmm3
mulps %xmm0,%xmm2
mulps %xmm1,%xmm3
addps %xmm3,%xmm2
addps 64(%rsp),%xmm2
mov 56(%rsp),%rcx
movups %xmm2,(%rcx)
add $96,%rsp
pop %rcx
pop %rax
pop %rbp
ret
@paint_all
push %rdx
push %rbx
sub $136,%rsp
lea @_$DATA-@_$NEXT(%rip),%rbx
lea 4096(%rbx),%rdx
add $1444096,%rbx
@paint_all_clear_loop
movq $0,(%rdx)
movq $-1,1440000(%rdx)
add $8,%rdx
cmp %rbx,%rdx
jne @paint_all_clear_loop
mov @_$DATA+96-@_$NEXT(%rip),%cl
cmp $0,%cl
je @paint_all_norotate
dec %cl
lea 32(%rsp),%rax
call @get_xyz
mov @_$DATA+116-@_$NEXT(%rip),%eax
mov %eax,16(%rsp)
movups @_$DATA+0-@_$NEXT(%rip),%xmm0
movups %xmm0,@_$DATA+48-@_$NEXT(%rip)
movups @_$DATA+16-@_$NEXT(%rip),%xmm0
movups %xmm0,@_$DATA+64-@_$NEXT(%rip)
movups @_$DATA+32-@_$NEXT(%rip),%xmm0
movups %xmm0,@_$DATA+80-@_$NEXT(%rip)
lea 64(%rsp),%rax
mov %rax,(%rsp)
lea @_$DATA+48-@_$NEXT(%rip),%rax
mov %rax,8(%rsp)
call @rotate_around
addq $16,8(%rsp)
call @rotate_around
addq $16,8(%rsp)
call @rotate_around
mov %rsp,%rax
call @get_xyz
mov $0x3f000000,%eax
movd %eax,%xmm0
shufps $0x00,%xmm0,%xmm0
movups 32(%rsp),%xmm1
movups %xmm1,%xmm2
mulss %xmm0,%xmm1
mov $0x41a00000,%eax
movq %rax,%xmm0
shufps $0x51,%xmm0,%xmm0
addps %xmm0,%xmm1
mulps %xmm1,%xmm2
movups %xmm2,%xmm0
movups %xmm2,%xmm1
shufps $0x01,%xmm1,%xmm1
shufps $0x02,%xmm2,%xmm2
addss %xmm1,%xmm0
addss %xmm2,%xmm0
movss %xmm0,(%rsp)
testl $0x80000000,(%rsp)
jne @paint_all_X1
call @paint_squares_rotating
@paint_all_X1
call @paint_squares_not_rotating
testl $0x80000000,(%rsp)
je @paint_all_X2
call @paint_squares_rotating
@paint_all_X2
jmp @paint_all_end
@paint_all_norotate
call @paint_squares_not_rotating
@paint_all_end
add $136,%rsp
pop %rbx
pop %rdx
ret
@transform_cw
# %al -- surface
push %rax
push %rcx
push %rdx
push %rbx
push %rsi
sub $136,%rsp
movzbl %al,%eax
shl $4,%eax
xor %ecx,%ecx
lea @_$DATA+256-@_$NEXT(%rip),%rsi
@transform_cw_X11
mov (%rax,%rsi,1),%bl
mov %bl,(%rsp,%rcx,1)
inc %ecx
inc %rsi
cmp $11,%ecx
jne @transform_cw_X11
sub $11,%rsi
xor %ecx,%ecx
@transform_cw_X12
movzbl @cube_transform2-@_$DATA-256(%rsi,%rcx,1),%edx
cmp $10,%edx
ja @transform_cw_X13
mov (%rsp,%rcx,1),%bl
add %rax,%rsi
mov %bl,(%rsi,%rdx,1)
sub %rax,%rsi
@transform_cw_X13
inc %ecx
cmp $11,%ecx
jne @transform_cw_X12
shr $2,%eax
lea (%rax,%rax,2),%eax
xor %ecx,%ecx
lea @cube_transform3-@_$NEXT(%rip),%rsi
@transform_cw_X2
movzbl (%rax,%rsi,1),%edx
sub %rcx,%rdx