forked from Terraspace/UASM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.asm
1182 lines (1137 loc) · 26.8 KB
/
macros.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
arginvoke MACRO argNo:REQ, invCnt:REQ, func:REQ, args:VARARG
LOCAL dstSize, stackPos
REGS15STORAGE
IFB <args>
invoke func
ELSE
IF invCnt EQ 2
mov RRCX,rcx
IF @Arch EQ 0
movaps RXMM0,xmm0
ELSE
vmovaps RXMM0,xmm0
ENDIF
ELSEIF invCnt EQ 3
mov RRCX,rcx
mov RRDX,rdx
IF @Arch EQ 0
movaps RXMM0,xmm0
movaps RXMM1,xmm1
ELSE
vmovaps RXMM0,xmm0
vmovaps RXMM1,xmm1
ENDIF
ELSEIF invCnt EQ 4
mov RRCX,rcx
mov RRDX,rdx
mov RR8,r8
IF @Arch EQ 0
movaps RXMM0,xmm0
movaps RXMM1,xmm1
movaps RXMM2,xmm2
ELSE
vmovaps RXMM0,xmm0
vmovaps RXMM1,xmm1
vmovaps RXMM2,xmm2
ENDIF
ELSEIF invCnt GE 5
mov RRCX,rcx
mov RRDX,rdx
mov RR8,r8
mov RR9,r9
IF @Arch EQ 0
movaps RXMM0,xmm0
movaps RXMM1,xmm1
movaps RXMM2,xmm2
movaps RXMM3,xmm3
ELSE
vmovaps RXMM0,xmm0
vmovaps RXMM1,xmm1
vmovaps RXMM2,xmm2
vmovaps RXMM3,xmm3
ENDIF
ENDIF
invoke func, args
IF invCnt EQ 2
mov rcx,RRCX
IF @Arch EQ 0
movaps xmm0,RXMM0
ELSE
vmovaps xmm0,RXMM0
ENDIF
ELSEIF invCnt EQ 3
mov rcx,RRCX
mov rdx,RRDX
IF @Arch EQ 0
movaps xmm0,RXMM0
movaps xmm1,RXMM1
ELSE
vmovaps xmm0,RXMM0
vmovaps xmm1,RXMM1
ENDIF
ELSEIF invCnt EQ 4
mov rcx,RRCX
mov rdx,RRDX
mov r8,RR8
IF @Arch EQ 0
movaps xmm0,RXMM0
movaps xmm1,RXMM1
movaps xmm2,RXMM2
ELSE
vmovaps xmm0,RXMM0
vmovaps xmm1,RXMM1
vmovaps xmm2,RXMM2
ENDIF
ELSEIF invCnt GE 5
mov rcx,RRCX
mov rdx,RRDX
mov r8,RR8
mov r9,RR9
IF @Arch EQ 0
movaps xmm0,RXMM0
movaps xmm1,RXMM1
movaps xmm2,RXMM2
movaps xmm3,RXMM3
ELSE
vmovaps xmm0,RXMM0
vmovaps xmm1,RXMM1
vmovaps xmm2,RXMM2
vmovaps xmm3,RXMM3
ENDIF
ENDIF
ENDIF
IF @LastReturnType EQ 0
dstSize = 1
ELSEIF @LastReturnType EQ 0x40
dstSize = 1
ELSEIF @LastReturnType EQ 1
dstSize = 2
ELSEIF @LastReturnType EQ 0x41
dstSize = 2
ELSEIF @LastReturnType EQ 2
dstSize = 4
ELSEIF @LastReturnType EQ 0x42
dstSize = 4
ELSEIF @LastReturnType EQ 3
dstSize = 8
ELSEIF @LastReturnType EQ 0x43
dstSize = 8
ELSEIF @LastReturnType EQ 0xc3
dstSize = 8
ELSEIF @LastReturnType EQ 6
dstSize = 16
ELSEIF @LastReturnType EQ 7
dstSize = 32
ELSEIF @LastReturnType EQ 8
dstSize = 64
ELSEIF @LastReturnType EQ 0x22
dstSize = 16
ELSEIF @LastReturnType EQ 0x23
dstSize = 16
ELSE
dstSize = 4
ENDIF
IF argNo EQ 1
IF dstSize EQ 1
mov cl,al
EXITM<cl>
ELSEIF dstSize EQ 2
mov cx,ax
EXITM<cx>
ELSEIF dstSize EQ 4
mov ecx,eax
EXITM<ecx>
ELSEIF dstSize EQ 8
mov rcx,rax
EXITM<rcx>
ELSEIF dstSize EQ 16
EXITM<xmm0>
ELSEIF dstSize EQ 32
EXITM<ymm0>
ELSEIF dstSize EQ 64
EXITM<zmm0>
ENDIF
ELSEIF argNo EQ 2
IF dstSize EQ 1
mov dl,al
EXITM<dl>
ELSEIF dstSize EQ 2
mov dx,ax
EXITM<dx>
ELSEIF dstSize EQ 4
mov edx,eax
EXITM<edx>
ELSEIF dstSize EQ 8
mov rdx,rax
EXITM<rdx>
ELSEIF dstSize EQ 16
IF @Arch EQ 0
movdqa xmm1,xmm0
ELSE
vmovdqa xmm1,xmm0
ENDIF
EXITM<xmm1>
ELSEIF dstSize EQ 32
vmovdqa ymm1,ymm0
EXITM<ymm1>
ELSEIF dstSize EQ 64
vmovdqa zmm1,zmm0
EXITM<zmm1>
ENDIF
ELSEIF argNo EQ 3
IF dstSize EQ 1
mov r8b,al
EXITM<r8b>
ELSEIF dstSize EQ 2
mov r8w,ax
EXITM<r8w>
ELSEIF dstSize EQ 4
mov r8d,eax
EXITM<r8d>
ELSEIF dstSize EQ 8
mov r8,rax
EXITM<r8>
ELSEIF dstSize EQ 16
IF @Arch EQ 0
movdqa xmm2,xmm0
ELSE
vmovdqa xmm2,xmm0
ENDIF
EXITM<xmm2>
ELSEIF dstSize EQ 32
vmovdqa ymm2,ymm0
EXITM<ymm2>
ELSEIF dstSize EQ 64
vmovdqa zmm2,zmm0
EXITM<zmm2>
ENDIF
ELSEIF argNo EQ 4
IF dstSize EQ 1
mov r9b,al
EXITM<r9b>
ELSEIF dstSize EQ 2
mov r9w,ax
EXITM<r9w>
ELSEIF dstSize EQ 4
mov r9d,eax
EXITM<r9d>
ELSEIF dstSize EQ 8
mov r9,rax
EXITM<r9>
ELSEIF dstSize EQ 16
IF @Arch EQ 0
movdqa xmm3,xmm0
ELSE
vmovdqa xmm3,xmm0
ENDIF
EXITM<xmm3>
ELSEIF dstSize EQ 32
vmovdqa ymm3,ymm0
EXITM<ymm3>
ELSEIF dstSize EQ 64
vmovdqa zmm3,zmm0
EXITM<zmm3>
ENDIF
ELSE
IF dstSize EQ 1
mov [rsp+0x20+((argNo-5)*8)],al
ELSEIF dstSize EQ 2
mov [rsp+0x20+((argNo-5)*8)],ax
ELSEIF dstSize EQ 4
mov [rsp+0x20+((argNo-5)*8)],eax
ELSEIF dstSize EQ 8
mov [rsp+0x20+((argNo-5)*8)],rax
ELSEIF (dstSize EQ 16) OR (dstSize EQ 32) OR (dstSize EQ 64)
IF @Arch EQ 0
movsd [rsp+0x20+((argNo-5)*8)],xmm0
ELSE
vmovsd [rsp+0x20+((argNo-5)*8)],xmm0
ENDIF
ENDIF
EXITM<[rsp+0x20+((argNo-5)*8)]>
ENDIF
ENDM
_ARRAY MACRO arrType:REQ,sizeArr:REQ
cdef TEXTEQU <__&arrType&_def>
% IFDEF cdef
mov rax,8
ELSE
mov rax,sizeof(arrType)
ENDIF
imul rax,sizeArr
MEMALLOC(rax)
exitm<rax>
ENDM
_DELETEARRAY MACRO arrPtr:REQ
MEMFREE(arrPtr)
ENDM
OINTERFACE MACRO CName:REQ
% __&CName&_def EQU 1
% __&CName&_size = 16
curClass TEXTEQU <CName>
@CatStr(CName, <vtbl CSTRUCT >)
__0 dq 0
__1 dq 0
ENDM
ENDOINTERFACE MACRO
curClass ENDS
ptrDefS TEXTEQU <psr>
ptrDefS CATSTR ptrDefS, <&curClass&>, < TYPEDEF PTR >, <&curClass&>
% ptrDefS
ENDM
CVIRTUAL MACRO method:REQ, retType:REQ, protoDef:VARARG
LOCAL sz1, sz2
pDef CATSTR <TYPEDEF PROTO >,<&retType&>,< thisPtr:PTR>
IFNB <protoDef>
pDef CATSTR pDef, <, >, <&protoDef>
ENDIF
sz2 CATSTR <_>, curClass, <_&method>, <Pto>
% &sz2 &pDef
% sz1 typedef PTR &sz2
% method sz1 0
% __&curClass&_size = __&curClass&_size + 8
fnex TEXTEQU <_>
fnex CATSTR fnex, curClass, <_>, <&method&>, < PROTO >, <&retType&>, < thisPtr:psr>, curClass
IFNB <args>
fnex CATSTR fnex, <, >, <&args&>
ELSE
ENDIF
fnex
ENDM
CLASS MACRO CName:REQ
% __&CName&_def EQU 1
% __&CName&_size = 16
curClass TEXTEQU <CName>
@CatStr(CName, <vtbl CSTRUCT >)
ctorS TEXTEQU <ctor dq offset _&CName&_Init>
dtorS TEXTEQU <dtor dq offset _&CName&_Destroy>
ctorS
dtorS
ENDM
ENDCLASS MACRO
curClass ENDS
.data
align 16
% _stat&curClass&vtbl &curClass&vtbl <>
% _stat&curClass& curClass <>
ptrDefS TEXTEQU <psr>
ptrDefS CATSTR ptrDefS, <&curClass&>, < TYPEDEF PTR >, <&curClass&>
% ptrDefS
ptrDefS2 TEXTEQU <psr>
ptrDefS2 CATSTR ptrDefS2, <&curClass&vtbl>, < TYPEDEF PTR >, <&curClass&vtbl>
% ptrDefS2
.code
ENDM
ENDMETHODS MACRO
LOCAL evtbl
% evtbl CATSTR <&curClass&>,<vtbl>,< ENDS>
evtbl
@CatStr(curClass, < CSTRUCT >)
% pVtbl dq offset _stat&curClass&vtbl
ENDM
CMETHOD MACRO method:REQ
LOCAL sz1, sz2
sz2 CATSTR <_>, curClass, <_&method>, <Pto>
% sz1 typedef PTR &sz2
% method sz1 offset _&curClass&_&method&
% __&curClass&_size = __&curClass&_size + 8
ENDM
CSTATIC MACRO method:REQ
LOCAL sz1, sz2
sz2 CATSTR <_>, curClass, <_&method>, <Pto>
% sz1 typedef PTR &sz2
% method sz1 offset _&curClass&_&method&
% __&curClass&_size = __&curClass&_size + 8
ENDM
METHOD MACRO className:REQ, method:REQ, retType:=<dword>, usesStr:=<USES rbx rsi rdi>, args:VARARG
curClass TEXTEQU <className>
curMethod TEXTEQU <method>
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, < PROTO >, <&retType&> , < thisPtr:psr>, <&className&>
IFNB <args>
fnex CATSTR fnex, <, >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, <Pto TYPEDEF PROTO >,<&retType&>,< thisPtr:psr>, <&className&>
IFNB <args>
fnex CATSTR fnex, <, >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex,< PROC >, <&retType&>, < >, <&usesStr&>, < thisPtr:psr>, <&className&>
IFNB <args>
fnex CATSTR fnex, <, >, <&args&>
ELSE
ENDIF
IF @Platform EQ 1
assume rcx:ptr curClass
ELSE
assume rdi:ptr curClass
ENDIF
align 16
fnex
ENDM
STATICMETHOD MACRO className:REQ, method:REQ, retType:=<dword>, usesStr:=<USES rbx rsi rdi>, args:VARARG
curClass TEXTEQU <className>
curMethod TEXTEQU <method>
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, < PROTO >, <&retType&>
IFNB <args>
fnex CATSTR fnex, < >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, <Pto TYPEDEF PROTO >,<&retType&>
IFNB <args>
fnex CATSTR fnex, < >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex,< PROC >, <&retType&>, < >, <&usesStr&>
IFNB <args>
fnex CATSTR fnex, < >, <&args&>
ELSE
ENDIF
IF @Platform EQ 1
assume rcx:ptr curClass
ELSE
assume rdi:ptr curClass
ENDIF
align 16
fnex
ENDM
VECMETHOD MACRO className:REQ, method:REQ, retType:=<dword>, usesStr:=<USES rbx rsi rdi>, args:VARARG
curClass TEXTEQU <className>
curMethod TEXTEQU <method>
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, < PROTO VECTORCALL >, <&retType&> , < thisPtr:psr>, <&className&>
IFNB <args>
fnex CATSTR fnex, <, >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, <Pto TYPEDEF PROTO VECTORCALL >,<&retType&>,< thisPtr:psr>, <&className&>
IFNB <args>
fnex CATSTR fnex, <, >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex,< PROC VECTORCALL >, <&retType&>, < >, <&usesStr&>, < thisPtr:psr>, <&className&>
IFNB <args>
fnex CATSTR fnex, <, >, <&args&>
ELSE
ENDIF
IF @Platform EQ 1
assume rcx:ptr curClass
ELSE
assume rdi:ptr curClass
ENDIF
align 16
fnex
ENDM
STATICVECMETHOD MACRO className:REQ, method:REQ, retType:=<dword>, usesStr:=<USES rbx rsi rdi>, args:VARARG
curClass TEXTEQU <className>
curMethod TEXTEQU <method>
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, < PROTO VECTORCALL >, <&retType&>
IFNB <args>
fnex CATSTR fnex, < >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex, <Pto TYPEDEF PROTO VECTORCALL >,<&retType&>
IFNB <args>
fnex CATSTR fnex, < >, <&args&>
ELSE
ENDIF
fnex
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex CATSTR fnex,< PROC VECTORCALL >, <&retType&>, < >, <&usesStr&>
IFNB <args>
fnex CATSTR fnex, < >, <&args&>
ELSE
ENDIF
IF @Platform EQ 1
assume rcx:ptr curClass
ELSE
assume rdi:ptr curClass
ENDIF
align 16
fnex
ENDM
ENDMETHOD MACRO
IF @Platform EQ 1
assume rcx:nothing
ELSE
assume rdi:nothing
ENDIF
fnex TEXTEQU <_>
fnex CATSTR fnex, curClass
fnex CATSTR fnex, <_>
fnex CATSTR fnex, curMethod
fnex CATSTR fnex, < ENDP>
fnex
ENDM
_DECLARE MACRO varName:REQ, typeName:VARARG
ldef TEXTEQU <LOCAL &varName&>
ldef CATSTR ldef, < : >
ldef CATSTR ldef, <typeName>
% ldef
ENDM
_STATICREF MACRO reg:REQ
% lea reg,_stat&curClass&
ENDM
_NEW MACRO className:REQ, ctorArgs:VARARG
% mov r8, sizeof(className)
MEMALLOC(r8)
.if (rax != 0)
mov rdi,rax
% lea rsi,_stat&className
% mov rcx, sizeof(className)
rep movsb
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <Init>
IFNB <ctorArgs>
fnex2 TEXTEQU <invoke fnex, rax, ctorArgs>
ELSE
fnex2 TEXTEQU <invoke fnex, rax>
ENDIF
fnex2
.endif
exitm<rax>
ENDM
_RBXNEW MACRO className:REQ, ctorArgs:VARARG
% mov r8, sizeof(className)
MEMALLOC(r8)
.if (rax != 0)
mov rdi,rax
% lea rsi,_stat&className
% mov rcx, sizeof(className)
rep movsb
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <Init>
IFNB <ctorArgs>
fnex2 TEXTEQU <invoke fnex, rax, ctorArgs>
ELSE
fnex2 TEXTEQU <invoke fnex, rax>
ENDIF
fnex2
mov rbx, rax
.endif
exitm<rbx>
ENDM
_ITEM MACRO objPtr:REQ, idx:REQ
exitm<[_V(objPtr, Iterator, Items, idx)]>
ENDM
_ITEMR MACRO objPtr:REQ, idx:REQ
exitm<_V(objPtr, Iterator, Items, idx)>
ENDM
_INVOKE MACRO className:REQ, method:REQ, objPtr:REQ, args:VARARG
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
IFNB <args>
fnex2 TEXTEQU <invoke fnex, &objPtr&, &args&>
ELSE
fnex2 TEXTEQU <invoke fnex, &objPtr&>
ENDIF
fnex2
ENDM
_I MACRO className:REQ, method:REQ, objPtr:REQ, args:VARARG
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex2 TEXTEQU <invoke fnex, &objPtr&, &args&>
fnex2
IF @LastReturnType EQ 0
EXITM <al>
ELSEIF @LastReturnType EQ 0x40
EXITM <al>
ELSEIF @LastReturnType EQ 1
EXITM <ax>
ELSEIF @LastReturnType EQ 0x41
EXITM <ax>
ELSEIF @LastReturnType EQ 2
EXITM <eax>
ELSEIF @LastReturnType EQ 0x42
EXITM <eax>
ELSEIF @LastReturnType EQ 3
EXITM <rax>
ELSEIF @LastReturnType EQ 0x43
EXITM <rax>
ELSEIF @LastReturnType EQ 0xc3
EXITM <rax>
ELSEIF @LastReturnType EQ 6
EXITM <xmm0>
ELSEIF @LastReturnType EQ 7
EXITM <ymm0>
ELSEIF @LastReturnType EQ 8
EXITM <zmm0>
ELSEIF @LastReturnType EQ 0x22
EXITM <xmm0>
ELSEIF @LastReturnType EQ 0x23
EXITM <xmm0>
ELSE
EXITM <eax>
ENDIF
ENDM
_STATIC MACRO className : REQ, method : REQ, args : VARARG
fnex TEXTEQU <_>
fnex CATSTR fnex, <&className&>
fnex CATSTR fnex, <_>
fnex CATSTR fnex, <&method&>
fnex2 TEXTEQU <invoke fnex, &args&>
fnex2
IF @LastReturnType EQ 0
EXITM <al>
ELSEIF @LastReturnType EQ 0x40
EXITM <al>
ELSEIF @LastReturnType EQ 1
EXITM <ax>
ELSEIF @LastReturnType EQ 0x41
EXITM <ax>
ELSEIF @LastReturnType EQ 2
EXITM <eax>
ELSEIF @LastReturnType EQ 0x42
EXITM <eax>
ELSEIF @LastReturnType EQ 3
EXITM <rax>
ELSEIF @LastReturnType EQ 0x43
EXITM <rax>
ELSEIF @LastReturnType EQ 0xc3
EXITM <rax>
ELSEIF @LastReturnType EQ 6
EXITM <xmm0>
ELSEIF @LastReturnType EQ 7
EXITM <ymm0>
ELSEIF @LastReturnType EQ 8
EXITM <zmm0>
ELSEIF @LastReturnType EQ 0x22
EXITM <xmm0>
ELSEIF @LastReturnType EQ 0x23
EXITM <xmm0>
ELSE
EXITM <eax>
ENDIF
ENDM
_DELETE MACRO objPtr:REQ
IF @Platform EQ 1
mov rcx, objPtr
mov rax, [rcx]
call qword ptr[rax + 8]
ELSE
mov rdi, objPtr
mov rax, [rdi]
call qword ptr[rax + 8]
ENDIF
MEMFREE(objPtr)
ENDM
_VINVOKE MACRO pInterface:REQ, Interface:REQ, Function:REQ, args:VARARG
InterfacePtr TEXTEQU <_>
InterfacePtr CATSTR InterfacePtr, <&Interface>, <_>, <&Function>, <Pto>
IF(OPATTR(pInterface)) AND 00010000b
IFNB <args>
IF @Platform EQ 1
mov rcx,&pInterface
mov r15,[rcx]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx, &args
ELSE
mov rdi,&pInterface
mov r15,[rdi]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rdi, &args
ENDIF
ELSE
IF @Platform EQ 1
mov rcx,&pInterface
mov r15,[rcx]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx
ELSE
mov rdi,&pInterface
mov r15,[rdi]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rdi
ENDIF
ENDIF
ELSE
mov rcx,pInterface
mov r15,[rcx]
IFNB <args>
FOR arg, <args>
IFIDNI <&arg>, <rcx>
.ERR <rcx is not allowed as a Method parameter with indirect object label>
ENDIF
ENDM
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx, &args
ELSE
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx
ENDIF
ENDIF
ENDM
_V MACRO pInterface:REQ, Interface:REQ, Function:REQ, args:VARARG
InterfacePtr TEXTEQU <_>
InterfacePtr CATSTR InterfacePtr, <&Interface>, <_>, <&Function>, <Pto>
IF(OPATTR(pInterface)) AND 00010000b
IFNB <args>
IF @Platform EQ 1
mov rcx,&pInterface
mov r15,[rcx]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx, &args
ELSE
mov rdi,&pInterface
mov r15,[rdi]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rdi, &args
ENDIF
ELSE
IF @Platform EQ 1
mov rcx,&pInterface
mov r15,[rcx]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx
ELSE
mov rdi,&pInterface
mov r15,[rdi]
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rdi
ENDIF
ENDIF
ELSE
IF @Platform EQ 1
mov rcx,pInterface
mov r15,[rcx]
IFNB <args>
FOR arg, <args>
IFIDNI <&arg>, <rcx>
.ERR <rcx is not allowed as a Method parameter with indirect object label>
ENDIF
ENDM
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx, &args
ELSE
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rcx
ENDIF
ELSE
mov rdi,pInterface
mov r15,[rdi]
IFNB <args>
FOR arg, <args>
IFIDNI <&arg>, <rdi>
.ERR <rdi is not allowed as a Method parameter with indirect object label>
ENDIF
ENDM
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rdi, &args
ELSE
invoke(InterfacePtr PTR[r15].&Interface&vtbl.&Function), rdi
ENDIF
ENDIF
ENDIF
IF @LastReturnType EQ 0
EXITM <al>
ELSEIF @LastReturnType EQ 0x40
EXITM <al>
ELSEIF @LastReturnType EQ 1
EXITM <ax>
ELSEIF @LastReturnType EQ 0x41
EXITM <ax>
ELSEIF @LastReturnType EQ 2
EXITM <eax>
ELSEIF @LastReturnType EQ 0x42
EXITM <eax>
ELSEIF @LastReturnType EQ 3
EXITM <rax>
ELSEIF @LastReturnType EQ 0x43
EXITM <rax>
ELSEIF @LastReturnType EQ 0xc3
EXITM <rax>
ELSEIF @LastReturnType EQ 6
EXITM <xmm0>
ELSEIF @LastReturnType EQ 7
EXITM <ymm0>
ELSEIF @LastReturnType EQ 8
EXITM <zmm0>
ELSEIF @LastReturnType EQ 0x22
EXITM <xmm0>
ELSEIF @LastReturnType EQ 0x23
EXITM <xmm0>
ELSE
EXITM <eax>
ENDIF
ENDM
;delete release, acquire, _vd, _vb, _vw, _vf
COMINTERFACE MACRO CName:REQ
curClass TEXTEQU <CName>
@CatStr(CName, <vtbl COMSTRUCT >)
CVIRTUAL QueryInterface, <>, :PTR
CVIRTUAL AddRef, <>
CVIRTUAL Release, <>
ENDM
ENDCOMINTERFACE MACRO
ENDMETHODS
curClass ENDS
ENDM
_VCOMINVOKE MACRO pInterface:REQ, Interface:REQ, Function:REQ, args:VARARG
InterfacePtr TEXTEQU <_>
InterfacePtr CATSTR InterfacePtr, <&Interface>, <_>, <&Function>, <Pto>
IF(OPATTR(pInterface)) AND 00010000b
IFNB <args>
invoke(InterfacePtr PTR[&pInterface].&Interface.&Function), pInterface, &args
ELSE
invoke(InterfacePtr PTR[&pInterface].&Interface.&Function), pInterface
ENDIF
ELSE
mov rcx, pInterface
mov r15,[rcx]
IFNB <args>
FOR arg, <args>
IFIDNI <&arg>, <rcx>
.ERR <rcx is not allowed as a Method parameter with indirect object label>
ENDIF
ENDM
invoke(InterfacePtr PTR[r15].&Interface.&Function), rcx, &args
ELSE
invoke(InterfacePtr PTR[r15].&Interface.&Function), rcx
ENDIF
ENDIF
ENDM
_VCOM MACRO pInterface:REQ, Interface:REQ, Function:REQ, args:VARARG
InterfacePtr TEXTEQU <_>
InterfacePtr CATSTR InterfacePtr, <&Interface>, <_>, <&Function>, <Pto>
IF(OPATTR(pInterface)) AND 00010000b
IFNB <args>
invoke(InterfacePtr PTR[&pInterface].&Interface.&Function), pInterface, &args
ELSE
invoke(InterfacePtr PTR[&pInterface].&Interface.&Function), pInterface
ENDIF
ELSE
mov rcx, pInterface
mov r15,[rcx]
IFNB <args>
FOR arg, <args>
IFIDNI <&arg>, <rcx>
.ERR <rcx is not allowed as a Method parameter with indirect object label>
ENDIF
ENDM
invoke(InterfacePtr PTR[r15].&Interface.&Function), rcx, &args
ELSE
invoke(InterfacePtr PTR[r15].&Interface.&Function), rcx
ENDIF
ENDIF
IF @LastReturnType EQ 0
EXITM <al>
ELSEIF @LastReturnType EQ 0x40
EXITM <al>
ELSEIF @LastReturnType EQ 1
EXITM <ax>
ELSEIF @LastReturnType EQ 0x41
EXITM <ax>
ELSEIF @LastReturnType EQ 2
EXITM <eax>
ELSEIF @LastReturnType EQ 0x42
EXITM <eax>
ELSEIF @LastReturnType EQ 3
EXITM <rax>
ELSEIF @LastReturnType EQ 0x43
EXITM <rax>
ELSEIF @LastReturnType EQ 0xc3
EXITM <rax>
ELSEIF @LastReturnType EQ 6
EXITM <xmm0>
ELSEIF @LastReturnType EQ 7
EXITM <ymm0>
ELSEIF @LastReturnType EQ 8
EXITM <zmm0>
ELSEIF @LastReturnType EQ 0x22
EXITM <xmm0>
ELSEIF @LastReturnType EQ 0x23
EXITM <xmm0>
ELSE
EXITM <eax>
ENDIF
ENDM
_DEREF MACRO itype:REQ, proc:REQ, argCount:REQ, argsAndRefs:VARARG
LOCAL i, ptrstr, typestr, argstr
argstr TEXTEQU < >
i = 0
FOR dref, <argsAndRefs>
IF i LT argCount+1
IF i GT 0
argstr CATSTR argstr, <,>, <&dref&>
ENDIF
ELSE
IF (i-argCount) MOD 2 EQ 1
ptrstr TEXTEQU <&dref&>
ELSE
typestr TEXTEQU <&dref&>
IF (i-argCount) EQ 1
% IF(OPATTR(ptrstr)) EQ 0x30
% mov rcx, &ptrstr&
ELSE
% mov rcx, @CatStr(<[>, <&ptrstr&>, <].>, <&typestr&>)
ENDIF
ELSE
% mov rcx, @CatStr(<[>, <&ptrstr&>, <].>, <&typestr&>)
ENDIF
ENDIF
ENDIF
i = i + 1
ENDM
% IF @SizeStr(<%&argstr&>) GT 3
argstr SUBSTR argstr, 3
ENDIF
IF argCount EQ 0
argstr TEXTEQU <>
ENDIF
IF argCount GT 0
InterfacePtr TEXTEQU <_>
InterfacePtr CATSTR InterfacePtr, <&itype>, <_>, <&proc>, <Pto>
IF(OPATTR(rcx)) AND 00010000b
IF argCount GT 0
IF @Platform EQ 1
mov r15,[rcx]
% invoke(InterfacePtr PTR[r15].&itype&vtbl.&proc), rcx, &argstr
ELSE
mov rdi,rcx
mov r15,[rdi]
% invoke(InterfacePtr PTR[r15].&itype&vtbl.&proc), rdi, &argstr
ENDIF
ELSE
IF @Platform EQ 1
mov r15,[rcx]
% invoke(InterfacePtr PTR[r15].&itype&vtbl.&proc), rcx
ELSE
mov rdi,rcx
mov r15,[rdi]
% invoke(InterfacePtr PTR[r15].&itype&vtbl.&proc), rdi
ENDIF
ENDIF
ELSE
mov r15,[rcx]
IF argCount GT 0
FOR arg, <argstr>
IFIDNI <&arg>, <rcx>
.ERR <rcx is not allowed as a Method parameter with indirect object label>
ENDIF
ENDM
% invoke(InterfacePtr PTR[r15].&itype&vtbl.&proc), rcx, &argstr