-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToastyCut.asm
1481 lines (1446 loc) · 58.6 KB
/
ToastyCut.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
format PE GUI 4.0 at 400000h
stack 1*1024*1024
include 'API.inc'
BMPSize =406
GMSSize =14866
ICOSize =2686
CuttersCount=184
CutterParams TCutterParams 117,1000,1000,FLAG_FLIP_X+FLAG_SWAP_COORDS+FLAG_XON_XOFF+FLAG_RTS_CTS+FLAG_KNIFE_ROTATE,'IN;PA','PU','PD',',',';','!PG;',0.42,0.1,$C0A80001,901Fh,0
align 16
data resource from 'res\1.res'
end data
include 'LZMADec.asm'
align 16
entry $
mov eax,1
cpuid
test ecx,1
mov eax,ErrCPU
je Init.Error
invoke WSAStartup,0202h,Temp
call [InitCommonControls]
invoke CreateThread,0,4*1024*1024,Init,0,0,0
mov [CurPoint],eax
invoke DialogBoxParamW,400000h,1,0,DlgProc,0
ShowControls:
pushad
mov ebx,[esp+36]
mov esi,hwnds.count-2
@@:invoke ShowWindow,[hwnds+esi*4],ebx
dec esi
jne @b
popad
ret 4
GetCutterParams:
push edi
mov ecx,sizeof.TCutterParams shr 2
mov edi,ActiveParams
xor eax,eax
rep stosd
invoke SendMessageW,[hwnds.Cutters_combo],CB_GETCURSEL,0,0
mov [ActiveParams.ID],ax
invoke SendMessageA,[hwnds.Init_edit],WM_GETTEXT,19,ActiveParams.Init
invoke SendMessageA,[hwnds.Move_edit],WM_GETTEXT,3,ActiveParams.Move
invoke SendMessageA,[hwnds.Cut_edit],WM_GETTEXT,3,ActiveParams.Cut
invoke SendMessageA,[hwnds.Delim_edit],WM_GETTEXT,2,ActiveParams.Delim
invoke SendMessageA,[hwnds.Term_edit],WM_GETTEXT,3,ActiveParams.Term
invoke SendMessageA,[hwnds.End_edit],WM_GETTEXT,9,ActiveParams.End
invoke SendMessageA,[hwnds.HRes_edit],WM_GETTEXT,TSize,Temp
mov eax,Temp
call StrToUInt
mov [ActiveParams.hres],ax
invoke SendMessageA,[hwnds.VRes_edit],WM_GETTEXT,TSize,Temp
mov eax,Temp
call StrToUInt
mov [ActiveParams.vres],ax
invoke SendMessageW,[hwnds.ShowVertices_check],BM_GETCHECK,0,0
mov edi,eax
invoke SendMessageW,[hwnds.KnifeRotate_check],BM_GETCHECK,0,0
lea edi,[edi*2+eax]
invoke SendMessageW,[hwnds.RTS_check],BM_GETCHECK,0,0
lea edi,[edi*2+eax]
invoke SendMessageW,[hwnds.XON_check],BM_GETCHECK,0,0
lea edi,[edi*2+eax]
invoke SendMessageW,[hwnds.DTR_check],BM_GETCHECK,0,0
lea edi,[edi*2+eax]
invoke SendMessageW,[hwnds.Swap_check],BM_GETCHECK,0,0
lea edi,[edi*2+eax]
invoke SendMessageW,[hwnds.Flip_check],BM_GETCHECK,0,0
lea eax,[edi*2+eax]
mov [ActiveParams.Flags],al
invoke SendMessageA,[hwnds.Radius_edit],WM_GETTEXT,TSize,Temp
mov eax,Temp
call StrToFloatU
mulss xmm0,[flt_100]
movss [ActiveParams.Radius],xmm0
invoke SendMessageA,[hwnds.AngleStep_edit],WM_GETTEXT,TSize,Temp
mov eax,Temp
call StrToFloatU
mulss xmm0,[flt_100]
movss [ActiveParams.AngleStep],xmm0
invoke SendMessageW,[hwnds.IP_addr],IPM_GETADDRESS,0,ActiveParams.IP
invoke SendMessageA,[hwnds.IP_port],WM_GETTEXT,TSize,Temp
mov eax,Temp
call StrToUInt
rol ax,8
mov [ActiveParams.TCPPort],ax
invoke SendMessageW,[hwnds.Port_combo],WM_GETTEXT,7,ActiveParams.Port
pop edi
ret
PortOpen:
push ebp
mov [Write],_WriteFile
invoke closesocket,ebx
invoke CloseHandle,ebx
invoke SendMessageW,[hwnds.Port_combo],CB_GETCURSEL,0,0
mov ebp,eax
invoke SendMessageW,[hwnds.Port_combo],CB_GETCOUNT,0,0
sub eax,ebp
dec eax
jne @f
mov word[Temp],0
invoke GetSaveFileNameW,ofn
test eax,eax
je CutterProc.quit
invoke CreateFileW,Temp,GENERIC_READ+GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
mov ebp,[GetLastError]
jmp .errtest
@@:
dec eax
jne @f
invoke socket,AF_INET,SOCK_STREAM,IPPROTO_TCP
mov ebx,eax
sub esp,8
mov ecx,[ActiveParams.IP]
bswap ecx
push ecx
push [ActiveParams.TCPPort]
pushw AF_INET
mov edx,esp
invoke connect,eax,edx,16
add esp,16
mov ebp,[WSAGetLastError]
mov [Write],_Send
jmp .errtest2
@@:
shl ebp,10
add ebp,COMPorts
invoke CreateFileW,ebp,GENERIC_READ+GENERIC_WRITE,0,0,OPEN_EXISTING,0,0
push dword[esp]
mov dword[esp+4],@f
mov ebp,[GetLastError]
jmp .errtest
@@:
invoke GetDefaultCommConfigW,ActiveParams.Port,COMMConfig,COMMConfig.dwSize
movzx eax,[ActiveParams.Flags]
and eax,FLAG_DTR_DSR+FLAG_XON_XOFF+FLAG_RTS_CTS
shr eax,1
movzx eax,[.DCBFlags+eax]
mov [COMMConfig.dcb.Flags],eax
invoke SetCommConfig,ebx,COMMConfig,[COMMConfig.dwSize]
ret
.errtest:
mov ebx,eax
.errtest2:
cmp eax,INVALID_HANDLE_VALUE
jne @f
call ebp
invoke FormatMessageW,FORMAT_MESSAGE_FROM_SYSTEM,0,eax,0,Temp,TSize,0
mov word[Temp+eax*2],0
invoke MessageBoxW,[ofn.hwndOwner],Temp,0,0
jmp CutterProc.quit
@@:
pop ebp
ret
.DCBFlags dw 20497,20521,21265,21289,24597,24621,25365,25389
_WriteFile:
invoke WriteFile,ebx,esi,edi,act_len,0
test eax,eax
mov eax,[act_len]
ret
_Send:
invoke send,ebx,esi,edi,0
cmp eax,SOCKET_ERROR
ret
_SendCommand: ;eax - command, st0,st1 - x,y
pushad
test [ActiveParams.Flags],FLAG_SWAP_COORDS
je @f
fxch st1
@@:
sub esp,28
mov dword[esp],Temp
mov dword[esp+4],fmt_sisis
mov dword[esp+8],eax
fmul st0,st5
fistp dword[esp+12]
mov dword[esp+16],ActiveParams.Delim
fmul st0,st5
fistp dword[esp+20]
mov dword[esp+24],ActiveParams.Term
call [wsprintfA]
add esp,28
mov edi,eax
mov esi,Temp
.send:call [Write]
jne @f
call PortOpen
@@:
add esi,eax
sub edi,eax
jne .send
popad
ret
macro SendCommand Command{
fld st0
fsincos
fxch st1
fmul [ActiveParams.Radius]
fadd dword[ebp+4]
fxch st1
fmul [ActiveParams.Radius]
fadd dword[ebp]
mov eax,Command
call _SendCommand
}
macro cinvoke2 func,[args]{
common
local i
i equ 0
forward
if args eq st0
fistp dword[esp+i]
else
mov dword[esp+i],args
end if
i equ i+4
common
call [func]
}
CutterProc: ;(lParam: dword);stdcall;
sub esp,16
call PortOpen
invoke SetTimer,[hwnds.Preview],1,100,0
finit
fild [ActiveParams.vres]
fmul [.flt_mm2inch]
fild [ActiveParams.hres]
fmul [.flt_mm2inch]
fld [CutHeight]
fmul st0,st2
fld [CutWidth]
fmul st0,st2
test [ActiveParams.Flags],FLAG_SWAP_COORDS
je @f
fxch st1
@@:
cinvoke2 wsprintfA,Temp,ActiveParams.Init,st0,ActiveParams.Delim,st0
cinvoke2 wsprintfA,Temp,fmt_ss,Temp,ActiveParams.Term
invoke WriteFile,ebx,Temp,eax,act_len,0
mov [CurPoint],0
fldz
fldz
fldz
test [ActiveParams.Flags],FLAG_KNIFE_ROTATE
je @f
fldz
fld [ActiveParams.Radius]
fadd st0,st0
fadd [ActiveParams.Radius]
fchs
mov eax,ActiveParams.Move
call _SendCommand
fldz
fldz
mov eax,ActiveParams.Cut
call _SendCommand
@@:
xor esi,esi
mov ebp,[SortedPoints]
.Path:
SendCommand ActiveParams.Move
mov eax,[SortedPathsLen]
mov edi,[eax+esi*4]
dec edi
.Point:
fstp st0
fld dword[ebp+12]
fsub dword[ebp+4]
fld dword[ebp+8]
fsub dword[ebp]
fpatan
fld st0
fsub st0,st2
fstp dword[esp-4]
movss xmm0,[esp-4]
comiss xmm0,[.flt_PI]
jna @f
subss xmm0,[.flt_2PI]
@@:
comiss xmm0,[.flt_minusPI]
ja @f
addss xmm0,[.flt_2PI]
@@:
movss xmm1,xmm0
movss xmm2,[flt_abs]
andps xmm1,xmm2
mulss xmm1,[ActiveParams.Radius]
divss xmm1,[ActiveParams.AngleStep]
cvtss2si edx,xmm1
test edx,edx
je @f
cvtsi2ss xmm1,edx
divss xmm0,xmm1
@@:
movss [esp-4],xmm0
fld dword[esp-4]
fstp st3
fxch st1
@@:SendCommand ActiveParams.Cut
fadd st0,st2
dec edx
jns @b
inc [CurPoint]
add ebp,8
dec edi
jne .Point
SendCommand ActiveParams.Cut
inc [CurPoint]
add ebp,8
inc esi
cmp esi,[NumPaths]
jne .Path
fld dword[ebp-4]
fldz
mov eax,ActiveParams.Move
call _SendCommand
invoke lstrlenA,ActiveParams.End
invoke WriteFile,ebx,ActiveParams.End,eax,act_len,0
invoke SetTimer,[hwnds.Preview],1,50,0
test [CurCoordSpace],FLAG_FLIP_X
mov eax,65-128
jne @f
movss xmm0,[Preview.Width]
cvtss2si eax,xmm0
sub eax,5+128
@@:
mov [ToastyPos],eax
mov [ToastyInc],0
mov esi,esp
invoke waveOutOpen,esi,WAVE_MAPPER,wForm,0,0,0
mov esi,[esi]
invoke waveOutPrepareHeader,esi,hdr,sizeof.WAVEHDR
invoke waveOutWrite,esi,hdr,sizeof.WAVEHDR
invoke Sleep,WavSize/8
mov [ToastyInc],128/(WavSize/800)
invoke Sleep,WavSize/16
mov [ToastyPos],1 shl 31-1
invoke waveOutUnprepareHeader,esi,hdr,sizeof.WAVEHDR
invoke waveOutClose,esi
.quit:
mov [CurPoint],0
mov [CutterThread],0
invoke closesocket,ebx
invoke CloseHandle,ebx
invoke SendMessageW,[hwnds.Start_button],WM_SETTEXT,0,strStart
invoke KillTimer,[hwnds.Preview],1
stdcall ShowControls,SW_SHOW
stdcall DlgProc,0,WM_COMMAND,CBN_SELCHANGE shl 16+(hwnds.Port_combo-hwnds)/4,0
invoke InvalidateRect,[hwnds.Preview],0,0
invoke ExitThread,0
.flt_mm2inch dd 0.000393701,0.000393701
.flt_PI dd 3.1415926535897932384626433832795
.flt_minusPI dd -3.1415926535897932384626433832795
.flt_2PI dd 6.283185307179586476925286766559
EditProc:
cmp dword[esp+8],WM_CHAR
jne .default
mov eax,[esp+12]
bt dword[chars],eax
jnc .quit
cmp al,'.'
jne .default
invoke SendMessageW,dword[esp+16],EM_GETSEL,0,0
test ax,ax
je .quit
push edi
mov edi,Temp
invoke SendMessageA,dword[esp+20],WM_GETTEXT,TSize,edi
mov ecx,eax
mov al,'.'
repne scasb
pop edi
je .quit
.default:
jmp [defEditProc]
.quit:
ret 16
PreviewProc:
mov eax,[esp+8]
cmp eax,WM_TIMER
je .WM_TIMER
cmp eax,WM_PAINT
je .WM_PAINT
cmp eax,WM_MOUSEMOVE
je .WM_MOUSEMOVE
cmp eax,WM_LBUTTONDOWN
je .WM_LBUTTONDOWN
cmp eax,WM_ERASEBKGND
je .quit
jmp [DefWindowProcW]
.WM_TIMER:invoke SendInput,1,input,28
mov eax,[ToastyInc]
add [ToastyPos],eax
.WM_PAINT:invoke glClear,GL_COLOR_BUFFER_BIT
invoke glLoadMatrixf,Preview.MetricMat
invoke glColor3f,0,0,0
pushad
mov ebx,[NumPoints]
mov esi,[SortedPathsLen]
mov edi,[NumPaths]
@@:sub ebx,[esi+edi*4-4]
invoke glDrawArrays,GL_LINE_STRIP,ebx,dword[esi+edi*4-4]
dec edi
jne @b
popad
invoke glColor3f,0,255.0,0
invoke glDrawArrays,GL_LINE_STRIP,0,[CurPoint]
invoke glColor3f,0,0,255.0
invoke glEnable,GL_LINE_STIPPLE
mov eax,[NumPaths]
mov edx,[NumPoints]
add eax,eax
add edx,117
invoke glDrawArrays,GL_LINES,edx,eax
invoke glDisable,GL_LINE_STIPPLE
test [ActiveParams.Flags],FLAG_SHOW_VERTICES
je @f
invoke glDrawArrays,GL_POINTS,0,[NumPoints]
@@:
invoke glLoadMatrixf,Preview.PixelMat
invoke glColor3f,0,0,0
invoke glDrawArrays,GL_TRIANGLES,[NumPoints],117
invoke glRasterPos2i,[ToastyPos],-5
invoke glDrawPixels,128,128,GL_BGRA,GL_UNSIGNED_BYTE,ToastyBMP
invoke SwapBuffers,[Preview.DC]
invoke ValidateRect,dword[esp+8],0
ret 16
.WM_MOUSEMOVE:test dword[esp+12],MK_LBUTTON
je @f
movd xmm0,[esp+16]
pxor xmm1,xmm1
punpcklwd xmm0,xmm1
cvtdq2ps xmm0,xmm0
movsd xmm2,qword[Preview.Width]
movsd xmm3,qword[Preview.MetricMat+48]
movsd xmm1,[MousePos]
movsd [MousePos],xmm0
subps xmm1,xmm0
divps xmm1,xmm2
addps xmm1,xmm1
addsubps xmm3,xmm1
movsd qword[Preview.MetricMat+48],xmm3
invoke InvalidateRect,dword[esp+12],0,0
@@:
invoke SetFocus,dword[esp+4]
ret 16
.WM_LBUTTONDOWN:movd xmm0,[esp+16]
pxor xmm1,xmm1
punpcklwd xmm0,xmm1
cvtdq2ps xmm0,xmm0
movsd [MousePos],xmm0
.quit:ret 16
SyncExit: ;(lParam: dword);stdcall;
invoke WaitForSingleObject,dword[esp+8],-1
invoke ExitProcess,0
DlgProc: ;(wnd,msg,wParam,lParam: dword): dword;stdcall;
mov eax,[esp+8]
cmp eax,WM_MOUSEWHEEL
je .WM_MOUSEWHEEL
cmp eax,WM_SIZE
je .WM_SIZE
cmp eax,WM_COMMAND
je .WM_COMMAND
cmp eax,WM_INITDIALOG
je .WM_INITDIALOG
cmp eax,WM_CLOSE
je .WM_CLOSE
xor eax,eax
ret 16
.WM_INITDIALOG:pushad
stdcall LZMADecode,ToastyWAV,CompressedData
mov ebp,[esp+36]
mov [ofn.hwndOwner],ebp
mov esi,CutterParams
mov edi,ActiveParams
mov ecx,sizeof.TCutterParams
rep movsb
mov ebx,hwnds.count
@@:invoke GetDlgItem,ebp,ebx
mov [hwnds+ebx*4],eax
dec ebx
jns @b
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Ñêàíèðóåì COM-ïîðòû;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sub esp,8
invoke SetupDiGetClassDevsW,GUID_SERENUM_BUS_ENUMERATOR,0,0,DIGCF_DEVICEINTERFACE+DIGCF_PRESENT
mov ebx,eax
xor edi,edi
mov ebp,COMPorts
jmp .StartScan
.EnumDev:
mov [DeviceInterfaceDetailData.cbSize],6
invoke SetupDiGetDeviceInterfaceDetailW,ebx,DeviceInterfaceData,DeviceInterfaceDetailData,sizeof.SP_DEVICE_INTERFACE_DETAIL_DATA_W,0,0
test eax,eax
je .EnumIf
invoke lstrcpyW,ebp,strGlobalRoot
lea eax,[ebp+sizeof.strGlobalRoot-2]
invoke SetupDiGetDeviceRegistryPropertyW,ebx,DeviceInfoData,SPDRP_PHYSICAL_DEVICE_OBJECT_NAME,0,eax,1024-sizeof.strGlobalRoot,0
invoke SetupDiGetDeviceInstanceIdW,ebx,DeviceInfoData,InstanceID,sizeof.InstanceID,0
cinvoke wsprintfW,Temp,fmt_RegDeviceParameters,InstanceID
mov word[Temp+eax*2],0
invoke RegOpenKeyExW,HKEY_LOCAL_MACHINE,Temp,0,KEY_QUERY_VALUE,esp
lea eax,[esp+4]
mov dword[eax],TSize
invoke RegQueryValueExW,dword[esp+20],strPortName,0,0,Temp,eax
invoke RegCloseKey,dword[esp]
invoke SendMessageW,[hwnds.Port_combo],CB_ADDSTRING,0,Temp
add ebp,1024
.EnumIf:
invoke SetupDiEnumDeviceInterfaces,ebx,DeviceInfoData,GUID_SERENUM_BUS_ENUMERATOR,esi,DeviceInterfaceData
inc esi
test eax,eax
jne .EnumDev
.StartScan:
invoke SetupDiEnumDeviceInfo,ebx,edi,DeviceInfoData
inc edi
xor esi,esi
test eax,eax
jne .EnumIf
invoke SetupDiDestroyDeviceInfoList,ebx
invoke SendMessageW,[hwnds.Port_combo],CB_ADDSTRING,0,strTCP
invoke SendMessageW,[hwnds.Port_combo],CB_ADDSTRING,0,strFile
sub ebp,COMPorts
shr ebp,10
invoke SendMessageW,[hwnds.Port_combo],CB_SETCURSEL,ebp,0
invoke SendMessageW,[hwnds.Port_combo],CB_SELECTSTRING,-1,ActiveParams.Port
add esp,8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
invoke SendMessageW,[hwnds.Init_edit],EM_LIMITTEXT,18,0
invoke SendMessageW,[hwnds.Move_edit],EM_LIMITTEXT,2,0
invoke SendMessageW,[hwnds.Cut_edit],EM_LIMITTEXT,2,0
invoke SendMessageW,[hwnds.Delim_edit],EM_LIMITTEXT,1,0
invoke SendMessageW,[hwnds.Term_edit],EM_LIMITTEXT,3,0
invoke SendMessageW,[hwnds.End_edit],EM_LIMITTEXT,8,0
invoke SendMessageW,[hwnds.HRes_edit],EM_LIMITTEXT,4,0
invoke SendMessageW,[hwnds.VRes_edit],EM_LIMITTEXT,4,0
invoke SendMessageW,[hwnds.Radius_edit],EM_LIMITTEXT,4,0
invoke SendMessageW,[hwnds.AngleStep_edit],EM_LIMITTEXT,4,0
invoke SendMessageW,[hwnds.IP_port],EM_LIMITTEXT,5,0
invoke SetWindowLongW,[hwnds.Radius_edit],GWL_WNDPROC,EditProc
invoke SetWindowLongW,[hwnds.AngleStep_edit],GWL_WNDPROC,EditProc
mov [defEditProc],eax
mov ebx,1
@@:movss xmm0,[CutterParams.Radius+ebx*4]
cvttss2si eax,xmm0
cvtsi2ss xmm1,eax
subss xmm0,xmm1
mulss xmm0,[flt_100]
cvtss2si edx,xmm0
cinvoke wsprintfW,Temp,fmt_u.u,eax,edx
invoke SendMessageW,[hwnds.Radius_edit+ebx*8],WM_SETTEXT,0,Temp
dec ebx
jns @b
invoke SendMessageW,[hwnds.IP_addr],IPM_SETADDRESS,0,[CutterParams.IP]
movzx eax,[CutterParams.TCPPort]
rol ax,8
cinvoke wsprintfW,Temp,fmt_u.u+6,eax
invoke SendMessageW,[hwnds.IP_port],WM_SETTEXT,0,Temp
invoke GetDC,[hwnds.Preview]
mov [Preview.DC],eax
invoke ChoosePixelFormat,eax,Preview.pfd
invoke SetPixelFormat,[Preview.DC],eax,Preview.pfd
invoke wglCreateContext,[Preview.DC]
mov [Preview.RC],eax
invoke wglMakeCurrent,[Preview.DC],[Preview.RC]
invoke glEnableClientState,GL_VERTEX_ARRAY
invoke glClearColor,1.0,1.0,1.0,0
invoke glEnable,GL_LINE_SMOOTH
invoke glLineStipple,2,$CCCC
invoke wglGetProcAddress,glGenBuffers
mov dword[glGenBuffers],eax
mov esi,eax
invoke wglGetProcAddress,glBindBuffer
mov dword[glBindBuffer],eax
and esi,eax
invoke wglGetProcAddress,glBufferData
mov dword[glBufferData],eax
test esi,eax
mov eax,ErrVideo
je Init.Error
invoke glGenBuffers,1,vbo
invoke glBindBuffer,GL_ARRAY_BUFFER,[vbo]
invoke glVertexPointer,2,GL_FLOAT,0,0
invoke glEnable,GL_POINT_SMOOTH
invoke glPointSize,6.0
invoke glEnable,GL_ALPHA_TEST
invoke glAlphaFunc,GL_GREATER,0
invoke WaitForSingleObject,[CurPoint],-1
mov [CurPoint],0
mov esi,-CuttersCount*sizeof.TCutter
@@:lea eax,[Cutters+CuttersCount*sizeof.TCutter+esi]
invoke SendMessageA,[hwnds.Cutters_combo],CB_ADDSTRING,0,eax
add esi,sizeof.TCutter
jne @b
movzx eax,[CutterParams.ID]
invoke SendMessageW,[hwnds.Cutters_combo],CB_SETCURSEL,eax,0
invoke SetWindowLongW,[hwnds.Preview],GWL_WNDPROC,PreviewProc
movzx esi,[CutterParams.Flags]
mov eax,esi
and eax,FLAG_KNIFE_ROTATE
invoke SendMessageW,[hwnds.KnifeRotate_check],BM_SETCHECK,eax,0
mov eax,esi
and eax,FLAG_SHOW_VERTICES
invoke SendMessageW,[hwnds.ShowVertices_check],BM_SETCHECK,eax,0
stdcall DlgProc,0,WM_COMMAND,(CBN_SELCHANGE shl 16)+(hwnds.Port_combo-hwnds)/4,0
xor ebx,ebx
cmp [CutterParams.ID],CuttersCount-1
sete bl
test [CutterParams.Flags],FLAG_FLIP_X
jne .Flip
jmp .PathOptimize
.WM_MOUSEWHEEL:movsx eax,word[esp+14]
cvtsi2ss xmm0,eax
movaps xmm2,dqword[Preview.Width]
movaps xmm3,dqword[Preview.MetricMat+48]
movaps xmm4,dqword[flt_1]
movq xmm5,qword[flt_neg-4]
mulss xmm0,[.flt_1_480]
addss xmm0,xmm4
shufps xmm0,xmm0,0
sub esp,16
invoke GetWindowRect,[hwnds.Preview],esp
punpcklwd mm0,[esp+32]
psrld mm0,16
psubd mm0,[esp]
cvtpi2ps xmm1,mm0
subps xmm1,xmm2
addss xmm1,xmm2
xorps xmm1,xmm5
divps xmm1,xmm2
addps xmm1,xmm1
subps xmm1,xmm3
subps xmm1,xmm4
addps xmm3,xmm1
mulps xmm1,xmm0
subps xmm3,xmm1
mulss xmm0,[Preview.Scale]
movq qword[Preview.MetricMat+48],xmm3
movss [Preview.Scale],xmm0
emms
jmp .Rescale
.WM_SIZE:sub esp,16
invoke GetClientRect,dword[esp+24],esp
sub dword[esp+8],230
cvtpi2ps xmm0,[esp+8]
movaps xmm1,dqword[flt_2]
movaps xmm3,dqword[flt_1]
movq qword[Preview.Width],xmm0
divps xmm1,xmm0
movss [Preview.PixelMat],xmm1
movq qword[Preview.PixelMat+16],xmm1
mov [Preview.PixelMat+16],0
mulps xmm1,dqword[flt_5]
subps xmm1,xmm3
movq qword[Preview.PixelMat+48],xmm1
test [CurCoordSpace],FLAG_FLIP_X
je @f
movss xmm1,[.flt_118]
divss xmm1,xmm0
subss xmm3,xmm1
movss [Preview.PixelMat+48],xmm3
@@:
mov esi,[esp+8]
invoke glViewport,0,0,esi,dword[esp+12]
invoke MoveWindow,[hwnds.Preview],0,0,esi,dword[esp+16],1
pushad
add esi,5
invoke MoveWindow,[hwnds.Cutters_combo],esi,5,225,15,1
mov edi,330
mov ebx,104
@@:invoke MoveWindow,[hwnds+ebx+4],esi,edi,110,18,1
lea eax,[esi+115]
invoke MoveWindow,[hwnds+ebx+8],eax,edi,110,18,1
sub edi,25
sub ebx,8
jne @b
invoke MoveWindow,[hwnds.DTR_check],esi,355,70,20,1
invoke MoveWindow,[hwnds.IP_lbl],esi,360,20,20,1
add esi,20
invoke MoveWindow,[hwnds.IP_addr],esi,360,130,20,1
add esi,33
mov eax,[esp+44]
sub eax,25
invoke MoveWindow,[hwnds.Start_button],esi,eax,100,20,1
add esi,5
invoke MoveWindow,[hwnds.PortParams_button],esi,380,90,20,1
add esi,17
invoke MoveWindow,[hwnds.XON_check],esi,355,90,20,1
add esi,80
invoke MoveWindow,[hwnds.IP_delim],esi,360,10,20,1
add esi,5
invoke MoveWindow,[hwnds.RTS_check],esi,355,65,20,1
add esi,5
invoke MoveWindow,[hwnds.IP_port],esi,360,50,20,1
popad
.Rescale:
add esp,16
movss xmm0,[flt_2]
movss xmm1,xmm0
divss xmm0,[Preview.Width]
divss xmm1,[Preview.Height]
mulss xmm0,[Preview.Scale]
mulss xmm1,[Preview.Scale]
mov eax,[CurCoordSpace]
shl eax,31
movd xmm2,eax
xorps xmm0,xmm2
movss [Preview.MetricMat],xmm0
movss [Preview.MetricMat+20],xmm1
invoke InvalidateRect,[hwnds.Preview],0,0
mov eax,1
ret 16
.WM_COMMAND:cmp word[esp+14],1 ;CBN_SELCHANGE, BN_CLICKED, STN_CLICKED, STN_DBLCLK
ja .quit
movzx eax,word[esp+12]
jmp [.commands+eax*4]
.FlipX:
.Rotate:call GetCutterParams
.Cutters:pushad
invoke SendMessageW,[hwnds.Cutters_combo],CB_GETCURSEL,0,0
mov ebx,1
mov [ActiveParams.ID],ax
cmp eax,CuttersCount-1
je @f
xor ebx,ebx
imul eax,eax,sizeof.TCutter
lea esi,[Cutters.hres+eax]
mov edi,ActiveParams.hres
mov ecx,sizeof.TCutter-sizeof.TCutter.Name
rep movsb
@@:
movzx eax,[ActiveParams.Flags]
xor eax,[CurCoordSpace]
test eax,FLAG_FLIP_X
je .noFlip
.Flip:
mov eax,[NumPoints]
mov edx,[Points]
cvtsd2ss xmm0,[CutWidth]
@@:movss xmm1,xmm0
subss xmm1,[edx+eax*8-8]
movss [edx+eax*8-8],xmm1
dec eax
jne @b
.PathOptimize:
divss xmm0,[Preview.Width]
addss xmm0,xmm0
mulss xmm0,[Preview.Scale]
mov eax,[CurCoordSpace]
shl eax,31
movd xmm1,eax
xorps xmm0,xmm1
addss xmm0,[Preview.MetricMat+48]
movss [Preview.MetricMat+48],xmm0
push ebx
mov edx,[NumPaths]
xorps xmm0,xmm0
movq xmm3,qword[flt_exp_3]
movq xmm4,qword[flt_abs]
xorps xmm6,xmm6
mov edi,[SortedPoints]
.loop1:movss xmm5,[flt_inf]
mov ebx,[NumPaths]
mov ebp,[NumPoints]
shl ebp,3
add ebp,[Points]
.loop2:mov eax,[PathsLen]
mov eax,[eax+ebx*4-4]
shl eax,3
add ebp,eax
test eax,eax
js .skip
sub ebp,eax
movsd xmm1,[ebp-8]
sub ebp,eax
comisd xmm1,[ebp]
je .loop3
mov eax,8
.loop3:movq xmm1,[ebp+eax-8]
subps xmm1,xmm0
shufps xmm1,xmm1,1
comiss xmm1,xmm6
jna @f
paddd xmm1,xmm3 ;Ïðîêðóòêà âïåð¸ä â 64 ðàçà äîðîæå
@@:
paddd xmm1,xmm3 ;Ïðîêðóòêà íàçàä â 8 ðàç äîðîæå (ïðèáàâëÿåì ê ýêñïîíåíòå 3)
andps xmm1,xmm4
haddps xmm1,xmm1
comiss xmm1,xmm5
ja @f
movss xmm5,xmm1
mov ecx,ebx
lea esi,[ebp+eax-8]
mov [esp-4],ebp
@@:
sub eax,8
jne .loop3
.skip:
dec ebx
jne .loop2
mov eax,[PathsLen]
mov ebp,[eax+ecx*4-4]
neg dword[eax+ecx*4-4]
mov eax,[SortedPathsLen]
mov [eax],ebp
add [SortedPathsLen],4
mov eax,[esp-4]
lea ecx,[eax+ebp*8]
movsd xmm1,[ecx-8]
sub ecx,esi
shr ecx,2
mov ebp,esi
rep movsd
mov ecx,ebp
sub ecx,eax
comisd xmm1,[eax]
jne @f
mov ebx,8
sub edi,ebx
movsd xmm7,[ebp]
movsd [edi+ecx],xmm7
@@:
mov esi,eax
shr ecx,2
rep movsd
add edi,ebx
movq xmm0,[edi-8]
dec edx
jne .loop1
mov ecx,[NumPaths]
shl ecx,2
sub [SortedPathsLen],ecx
mov ebx,[PathsLen]
mov eax,[NumPoints]
shl eax,3
add eax,[SortedPoints]
mov edx,[InterconnectLines]
mov esi,[SortedPathsLen]
@@:mov edi,[esi+ecx-4]
shl edi,3
sub eax,edi
neg dword[ebx+ecx-4]
movups xmm0,[eax-8]
movups [edx+ecx*4-16],xmm0
sub ecx,4
jne @b
movq [edx],xmm6
pop ebx
.noFlip:
movzx eax,[ActiveParams.Flags]
and eax,FLAG_FLIP_X+FLAG_SWAP_COORDS
mov [CurCoordSpace],eax
mov ecx,234
mul ecx
lea esi,[Axis+eax*4]
mov edi,[AxisArrows]
rep movsd
mov eax,[NumPaths]
add eax,eax
add eax,[NumPoints]
lea eax,[eax*8+234*4]
invoke glBufferData,GL_ARRAY_BUFFER,eax,[SortedPoints],GL_STATIC_DRAW
invoke SendMessageA,[hwnds.Init_edit],WM_SETTEXT,0,ActiveParams.Init
invoke SendMessageA,[hwnds.Move_edit],WM_SETTEXT,0,ActiveParams.Move
invoke SendMessageA,[hwnds.Cut_edit],WM_SETTEXT,0,ActiveParams.Cut
invoke SendMessageA,[hwnds.Delim_edit],WM_SETTEXT,0,ActiveParams.Delim
invoke SendMessageA,[hwnds.Term_edit],WM_SETTEXT,0,ActiveParams.Term
invoke SendMessageA,[hwnds.End_edit],WM_SETTEXT,0,ActiveParams.End
movzx eax,[ActiveParams.hres]
cinvoke wsprintfW,Temp,fmt_u.u+6,eax
invoke defEditProc,[hwnds.HRes_edit],WM_SETTEXT,0,Temp
movzx eax,[ActiveParams.vres]
cinvoke wsprintfW,Temp,fmt_u.u+6,eax
invoke defEditProc,[hwnds.VRes_edit],WM_SETTEXT,0,Temp
movzx edi,[ActiveParams.Flags]
mov eax,edi
and eax,FLAG_FLIP_X
invoke SendMessageW,[hwnds.Flip_check],BM_SETCHECK,eax,0
mov eax,edi
and eax,FLAG_SWAP_COORDS
invoke SendMessageW,[hwnds.Swap_check],BM_SETCHECK,eax,0
mov esi,(hwnds.Swap_check-hwnds.Init_lbl)/4+1
@@:invoke EnableWindow,[hwnds.Init_lbl+esi*4],ebx
dec esi
jns @b
mov eax,edi
and eax,FLAG_DTR_DSR
invoke SendMessageW,[hwnds.DTR_check],BM_SETCHECK,eax,0
mov eax,edi
and eax,FLAG_XON_XOFF
invoke SendMessageW,[hwnds.XON_check],BM_SETCHECK,eax,0
mov eax,edi
and eax,FLAG_RTS_CTS
invoke SendMessageW,[hwnds.RTS_check],BM_SETCHECK,eax,0
test edi,FLAG_DTR_DSR+FLAG_XON_XOFF+FLAG_RTS_CTS
sete al
or bl,al
invoke EnableWindow,[hwnds.DTR_check],ebx
invoke EnableWindow,[hwnds.XON_check],ebx
invoke EnableWindow,[hwnds.RTS_check],ebx
popad
jmp .WM_SIZE
.ShowPoints:call GetCutterParams
invoke InvalidateRect,[hwnds.Preview],0,0
ret 16
.Port:pusha
invoke SendMessageW,[hwnds.Port_combo],CB_GETCOUNT,0,0
lea esi,[eax-2]
invoke SendMessageW,[hwnds.Port_combo],CB_GETCURSEL,0,0
xor ebx,ebx
mov edi,eax
cmp eax,esi
setb bl
invoke ShowWindow,[hwnds.DTR_check],ebx
invoke ShowWindow,[hwnds.XON_check],ebx
invoke ShowWindow,[hwnds.RTS_check],ebx
invoke ShowWindow,[hwnds.PortParams_button],ebx
cmp edi,esi
sete bl
invoke ShowWindow,[hwnds.IP_lbl],ebx
invoke ShowWindow,[hwnds.IP_addr],ebx
invoke ShowWindow,[hwnds.IP_delim],ebx
invoke ShowWindow,[hwnds.IP_port],ebx
popa
ret 16
.PortParams:invoke SendMessageW,[hwnds.Port_combo],WM_GETTEXT,256,Temp
invoke GetDefaultCommConfigW,Temp,COMMConfig,COMMConfig.dwSize
invoke CommConfigDialogW,Temp,[hwnds.Port_combo],COMMConfig
invoke SetDefaultCommConfigW,Temp,COMMConfig,COMMConfig.dwSize
ret 16
.Start:cmp [CutterThread],0
jne @f
call GetCutterParams
stdcall ShowControls,SW_HIDE
invoke SendMessageW,[hwnds.Start_button],WM_SETTEXT,0,strPause
invoke CreateThread,0,0,CutterProc,0,0,0
mov [CutterThread],eax
ret 16
@@:
cmp [ThreadSuspended],0
je @f
invoke SendMessageW,[hwnds.Start_button],WM_SETTEXT,0,strPause
invoke ResumeThread,[CutterThread]
mov [ThreadSuspended],0
ret 16
@@:
invoke SendMessageW,[hwnds.Start_button],WM_SETTEXT,0,strContinue
invoke SuspendThread,[CutterThread]
mov [ThreadSuspended],1
.quit:ret 16
.WM_CLOSE:call GetCutterParams
movq xmm0,qword[ActiveParams.Radius]
mulps xmm0,dqword[flt_001]
movq qword[ActiveParams.Radius],xmm0
mov esi,CutterParams
mov edi,ActiveParams
mov ecx,sizeof.TCutterParams
repe cmpsb
je @f
mov esi,ActiveParams
mov edi,CutterParams
mov ecx,sizeof.TCutterParams
repe movsb
invoke CreateEventW,0,0,0,strToastyCut
invoke CreateThread,0,0,SyncExit,eax,0,Temp
invoke CoInitialize,0
invoke CoCreateInstance,CorelCLSID,0,CLSCTX_LOCAL_SERVER,IID_IVGApplication,CorelApp
cominvk CorelApp,Get_GMSManager,GMSManager
cominvk GMSManager,RunMacro,strToastyCut,strSaveParams,PParams,Temp
@@:
invoke ExitProcess,0
.commands dd .quit,.Cutters,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.quit,.FlipX,.Rotate,.quit,.quit,.quit,.quit,.quit,.ShowPoints,.quit,.Port,.quit,.quit,.quit,.PortParams,.quit,.quit,.quit,.quit,.Start
.flt_1_480 dd 0.00208333333333333333333333333333 ;1/480
.flt_118 dd 118.0
Init: ;(lParam: dword);stdcall;