-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.1
1588 lines (1513 loc) · 38.3 KB
/
io.1
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
.NOLIST
;================= macros ==============
; purge GLOBAL; íåíóæíûé ìàêðîñ â macros.inc
;---------------------------------------
??SaveReg macro F:=<>
push eax
push ecx
push edx
ifnb <F>
pushfd
endif
endm
;---------------------------------------
??RestoreReg macro F:=<>
ifnb <F>
popfd
endif
pop edx
pop ecx
pop eax
endm
;*************************************************
; ??CheckStrToBuf macro x:VARARG
; Ïîìåùàåò òåêñò â áóôåð, ïåðåêîäèðóåò
; è âîçâðàùàåò àäðåñ íà÷àëà òåêñòà â eax
;*************************************************
??CheckStrToBuf macro x:VARARG
Local buf,c,n,L1,L2
c SubStr <x>,1,1
ifidn c,<'>
c textequ <">
endif
.data
n db 0
ifidn c,<">
buf db x,0
else ; x=offset text
buf db 300 dup (0)
.code
mov n,0; íàäî ïåðåêîäèðîâàòü
mov eax,x
xor ecx,ecx
L1: mov dl,[eax]
mov buf[ecx],dl
inc eax
inc ecx
cmp dl,0
jne L1
endif
.code
mov eax,offset buf
cmp ??ConsoleMode,0
jne L2; ïåðåêîäèðîâàíèå âûêëþ÷åíî
cmp n,0
jne L2
push eax
call WinToDos; Windows to DOS
; invoke CharToOem,eax,eax; Windows to DOS
mov n,1; Íå íàäî ïåðåêîäèðîâàòü âòîðîé ðàç!
pop eax
L2:
endm
;***************************************
; ??FindESP macro X:Req,pESP
; pESP:=2222 ESP in X
; pESP:=2222 [ESP] in X
;***************************************
??FindESP macro X:Req,pESP
local k,p1,p2,n
k=1
p1=0; Ïîçèöèÿ [
p2=0; Ïîçèöèÿ ]
p1=@InStr(1,<X>,<[>)
p2=@InStr(1,<X>,<]>)
n=@SizeStr(X)-2
while k LE n
ifidni @SubStr(X,k,3),<esp>; Ïîèñê esp
if k GT p1 and k LT p2; [...esp...]
pESP=3333
else
pESP=2222
endif
exitm
endif
k=k+1
endm
endm
;***********************************************************************
; SetTextAttr macro x=16*ôîí+áóêâû
;***********************************************************************
settextattr equ SetTextAttr
;***********************************************************************
SetTextAttr macro colors:=<LightGray>; Lightgray ñâåòëî-ñåðûé (ñòàíäàðò)
??SaveReg Flags
invoke GetStdHandle,STD_OUTPUT_HANDLE; =-11; eax:=OUTPUT_HANDLE
invoke SetConsoleTextAttribute,eax,colors
??RestoreReg Flags
endm
;************************************************************
; OutNum macro x:REQ,Wide,tip:=<d>,txt:=<>
; x=r8,r16,r32,m8,m16,m32,i32
; Wide=i8 - øèðèíà ïîëÿ âûâîäà, (<0, - ëåâîå âûðàâíèâàíèå)
; tip=d - çíàêîâîå, u-áåççíàêîâîå,
; x,X - øåñòíàäöàòåðè÷íîå, b - äâîè÷íîå
;************************************************************
OutNum equ outnum
;************************************************************
OutNum macro x:REQ,Wide,tip:=<d>,txt:=<>
local n,k,len,fmt,L1,L2,L3,L4,M1,M2,M3,tp,Met
ifnb <txt>
outstr txt
endif
??SaveReg Flags
;------- Ïðîâåðêà type, esp è [esp]
len=0
if @SizeStr(x) GT 3
ifidni @SubStr(x,1,4),<type> ; x=type Y
len=1111
goto Met
endif
endif
n=@SizeStr(&x)-2
k=1
while k LE n
ifidni @SubStr(x,k,3),<esp>; Ïîèñê "esp"
k=(.type &x) and 1000000b
if k; Îïåðàíä â ñòåêå
len=3333
endif
if @SizeStr(&x) EQ 3; x=esp
len=2222
endif
exitm
endif
k=k+1
endm
;----------------------------
:Met
;----------- byte<>sbyte !!!
tp = type (&x)
if len EQ 1111; Áûë outnum type ...;
mov eax,(&x)
elseif tp EQ 1 or tp EQ 2
; Çíàêîâîå è áåççíàêîâîå ðàñøèðåíèå äî 4 áàéò
ifidni <tip>,<d>
movsx eax,(&x)
else
movzx eax,(&x)
endif
elseif tp NE 8; ==> type x EQ 0 or type x EQ 4
mov eax,x
endif
if len EQ 2222; x=esp
add eax,16; êîððåêöèÿ 4*push
endif
if len EQ 3333; x=[...esp...]
lea eax,(&x); àäðåñ îïåðàíäà-16
; Çíàêîâîå è áåççíàêîâîå ðàñøèðåíèå äî 4 áàéò
if tp EQ 1
ifidni <tip>,<d>
movsx eax,byte ptr [eax+16]
else
movzx eax,byte ptr [eax+16]
endif
elseif tp EQ 2
ifidni <tip>,<d>
movsx eax,word ptr [eax+16]
else
movzx eax,word ptr [eax+16]
endif
elseif tp NE 8; ==> type x EQ 0 or type x EQ 4
mov eax,[eax+16]; êîððåêöèÿ 4*push
endif
endif
ifidni <tip>,<b>
xor ebx,ebx; íåò åäèíèö
if tp EQ 8
mov ecx,32
mov eax,dword ptr x
mov edx,dword ptr x+4
M1: shl edx,1
jc M2
cmp ebx,0
je M3; íåçíà÷àùèõ ïðîïóñê íóëåé
outchar '0'
jmp M3
M2: outchar '1'
inc ebx; áûëà åäèíèöà
M3: dec ecx
jne M1
endif
mov ecx,32
L1: shl eax,1
jc L2
cmp ebx,0
je L3; íåçíà÷àùèõ ïðîïóñê íóëåé
outchar '0'
jmp L3
L2: outchar '1'
inc ebx; áûëà åäèíèöà
L3: dec ecx
jne L1
test ebx,ebx
jne L4
outchar '0'
L4: outchar 'b'
??RestoreReg
exitm
endif
if tp EQ 8
.data
fmt db "%&Wide&I64&tip&",0
.code
invoke crt_printf,offset fmt,x
else
.data
fmt db "%&Wide&tip&",0
.code
invoke crt_printf,offset fmt,eax
endif
ifidni <tip>,<X>
outchar "h"
endif
??RestoreReg Flags
endm
;-----------------------------------------------------------------
OutNumLn equ outnumln
OutNumln equ outnumln
;-----------------------------------------------------------------
outnumln macro x:REQ,Wide,tip:=<d>,txt:=<>
OutNum x,Wide,tip,txt
newline
endm
;***************************************************
; Çàäàíèå (óìåíüøåíèå) ðàçìåðà áóôåðà îêíà êîíñîëè
;***************************************************
SetScreenSize macro x:=<80>,y:=<25>
local LnSize,ColSize
.data
LnSize dw ?
ColSize dw ?
.code
mov LnSize,x
mov ColSize,y
invoke GetStdHandle,STD_OUTPUT_HANDLE; eax:=OUTPUT_HANDLE
invoke SetConsoleScreenBufferSize,eax,dword ptr LnSize
endm
;*****************************
; Î÷èñòêà ýêðàíà êîíñîëè
;*****************************
Cls equ ClrScr
clrscr equ ClrScr
CLRSCR equ ClrScr
;*************************
ClrScr macro
??SaveReg Flags
call ClearScreen
??RestoreReg Flags
endm
;**************************************
; Ïåðåõîä íîâóþ ñòðîêó <n> ðàç
;**************************************
NewLine equ newline
Newline equ newline
NEWLINE equ newline
;*********************************
newline macro n:=<1>
; local fmt
??SaveReg Flags
.data
;fmt db "\n",0
.code
repeat n
; invoke crt_printf,offset fmt; C Library
; outchar 13
outchar 10
endm
??RestoreReg Flags
endm
;**************************
; Âûõîä èç ïðîãðàììû
;**************************
Exit equ exit
EXIT equ exit
;**********************
exit macro x:=<0>
cld; 针֌ AVOST
invoke ExitProcess,x; Windows Lib
; invoke crt__exit,x; C Lib
endm
;**********************************************
; outstr macro x:VARARG
; Âûâîä òåêñòà x="..." èëè offset x db "..."
;**********************************************
OutStr equ outstr
OUTSTR equ outstr
;**********************************************
outstr macro x:VARARG
local fmt
??SaveReg Flags
??CheckStrToBuf x
.data
fmt db "%s",0
.code
invoke crt_printf,offset fmt,eax; C Library
; invoke StdOut,eax; Win Library
??RestoreReg Flags
endm
;***********************************************
; OutStrLn macro x="..." èëè offset x db "..."
;***********************************************
OutStrLn equ outstrln
OutstrLn equ outstrln
OUTSTRLN equ outstrln
outstrln macro x:VARARG
ifnb <x>
outstr x
endif
newline
endm
;***************************************************************************
; MessageBox Cap,Msg = "..." èëè offset x db "...",buttons
; Ñ÷èòàåò, ÷òî òåêñò â êîäèðîâêå Windows
; style=MB_OK (0h),MB_OKCANCEL (1h),MB_ABORTRETRYIGNORE (2h)
; MB_YESNOCANCEL (3h),MB_YESNO (4h),MB_RETRYCANCEL (5h)
; MB_CANCELTRYCONTINUE (6h),
; MB_TOPMOST (40000h - ïîâåðõ âñåõ îêîí)
; MB_SYSTEMMODAL (1000h - ïîâåðõ âñåõ îêîí+ôîêóñ ââîäà)
;
; MB_ICONSTOP (10h - êðåñò-ñòîï), MB_ICONQUESTION (20h - ?)
; MB_ICONEXCLAMATION (30h - !), MB_ICONASTERISK (40h - i â êðóãå)
; MB_USERICON (80h - áåç ïèêòîãðàììû, ìîæíî èç ôàéëà ðåñóðñîâ)
; MB_DEFBUTTON1,2,3,4 (0h,100h,200h,300h)
; MB_HELP (4000h êíîïêà ñïðàâêè áåç êîäà)
; MB_RIGHT (80000h ïðàâîå âûðàâíèâàíèå òåêñòà)
; Êîä êíîïêè=IDOK (1),IDCANCEL èëè ESC èëè êðåñòèê çàêðûòèÿ îêíà (2),
; IDABORT (3),IDRETRY (4),IDIGNORE (5),IDYES (6),IDNO (7)
; IDTRYAGAIN (10),IDCONTINUE (11)
;******************************************************************************
msgbox equ MsgBox
MSGBOX equ MsgBox
MsgBox macro Cap:=<" ">,Msg:REQ,style:=<MB_OK+MB_ICONASTERISK+MB_SYSTEMMODAL>
local t1,t2,L,Par1,Par2,c
??SaveReg Flags
ConsoleMode; âûêëþ÷èòü ïåðåêîäèðîâêó
??CheckStrToBuf Cap
push eax
??CheckStrToBuf Msg
pop edx; Cap
invoke MessageBox,NULL,eax,edx,style+MB_SYSTEMMODAL
ConsoleMode; âêëþ÷èòü ïåðåêîäèðîâêó
mov [esp+12],eax; êîä âîçâðàòå â EAX !
??RestoreReg Flags
endm
;*************************************
; Çàãîëîâîê îêíà êîíñîëè
;*************************************
ConsoleTitle macro Title:VARARG
??SaveReg Flags
??CheckStrToBuf Title
invoke SetConsoleTitle,eax
??RestoreReg Flags
endm
;--------------------------------------------------------------
GetConsoleTitle macro buf:REQ,Len:=<127>
??SaveReg
invoke GetConsoleTitleA,buf,Len
??RestoreReg
endm
;*****************************************
; gotoXY macro x,y=i8,r8,r16,m8,m16
;*****************************************
GotoXY equ gotoXY
gotoxy equ gotoXY
GOTOXY equ gotoXY
;*****************************************
gotoXY macro x:REQ,y:REQ
local s;
.data
s dw 0; x ïîçèöèÿ
dw 0; y ïîçèöèÿ
.code
??SaveReg Flags
if type (&x) EQ 1 or type (&x) EQ 2; or len EQ 1
movzx eax,x
mov s,ax
elseif type (&x) EQ 0
mov ax,x
mov s,ax
elseif
echo ------------------------------------------------
echo ***** Macros GotoXY: Bad operand **** &x& ****
echo ------------------------------------------------
.err
exitm
endif
dec s
and s,1111111b
.code
if type (&y) EQ 1 or type (&y) EQ 2; or len EQ 1
movzx eax,y
mov s+2,ax
elseif type (&y) EQ 0
mov ax,y
mov s+2,ax
elseif
echo ------------------------------------------------
echo ***** Macros GotoXY: Bad operand **** &y& ****
echo ------------------------------------------------
.err
exitm
endif
dec s+2
and s+2,111111b
invoke GetStdHandle,STD_OUTPUT_HANDLE; eax:=OUTPUT_HANDLE
invoke SetConsoleCursorPosition,eax,dword ptr s
??RestoreReg Flags
endm
;*************************************
; WhereX, WhereY al:=1..80, 1..50
;*************************************
wherex equ WhereX
whereX equ WhereX
WhereX macro
local pos
.data
pos CONSOLE_SCREEN_BUFFER_INFO <>
.code
invoke GetStdHandle,STD_OUTPUT_HANDLE
invoke GetConsoleScreenBufferInfo,eax,offset pos
mov al,byte ptr pos.dwCursorPosition.x; al=WhereX
inc al
endm
;---------------------------------------------------------------------------
wherey equ WhereY
whereY equ WhereY
WhereY macro
local pos
.data
pos CONSOLE_SCREEN_BUFFER_INFO <>
.code
invoke GetStdHandle,STD_OUTPUT_HANDLE
invoke GetConsoleScreenBufferInfo,eax,offset pos
mov al,byte ptr pos.dwCursorPosition.y; al=WhereY
inc al
endm
;**********************************************************
; InputStr - ââîä ñòðîêè äî ENTER, íå äëèííåå Len<=128
; èëè äî êîíöà ñòðîêè
;**********************************************************
inputstr equ InputStr
INPUTSTR equ InputStr
InputStr macro Buf:REQ,Len:=<128>,prompt:VARARG
Local fmt,sym,L,L1
ifnb <prompt>
outstr prompt
endif
.data
fmt db "%c",0
sym db ?
.code
push ebx
push ecx
push edx
xor eax,eax; ×èñëî ïðî÷èòàííûõ
mov ecx,Len
mov edx,Buf; Àäðåñ íà÷àëà áóôåðà
@@: cmp ecx,0
jz @F
??SaveReg
invoke crt_scanf,offset fmt,offset sym; 1 ñèìâîë - C Library
??RestoreReg
mov bl,sym
cmp bl,10; LF
je @F
mov [edx+eax],bl
inc eax
dec ecx
jmp @B
@@: mov byte ptr [edx+eax],0
outintln eax,,"eax="
pop edx
pop ecx
pop ebx
Comment #
push ecx
push edx
invoke StdIn,Buf,Len; eax:=×èñëî ïðî÷èòàííûõ; Win Library
pop edx
pop ecx
push ebx
mov ebx,Buf
cmp eax,0
je @F
cmp byte ptr [ebx+eax-1],10; LF,CR â áóôåðå
jne @F
sub eax,2
@@: mov byte ptr [ebx+eax],0
pop ebx
#
endm
;**************************************
; pause ["Òåêñò äëÿ âûâîäà..."]
;**************************************
Pause equ pause
PAUSE equ pause
pause macro txt
ifnb <txt>
outstr txt
endif
??SaveReg Flags
call wait_key
??RestoreReg Flags
newline
endm
;********************************************
; inchar macro x=m8,r8,prompt:VARARG
;********************************************
InChar equ inchar
Inchar equ inchar
INCHAR equ inchar
;********************************************
inchar macro x:REQ,prompt:VARARG
local len,buf,fmt,L
ifnb <prompt>
outstr prompt
endif
Comment #
ifidni <x>,<sp>
echo ---------------------------
echo ** BAD Macros: inchar SP **
echo ---------------------------
exitm
endif
ifidni <x>,<esp>
echo ----------------------------
echo ** BAD Macros: inchar ESP **
echo ----------------------------
exitm
endif
#
len=0
for i,<al,ah,bl,bh,cl,ch,dl,dh>
ifidni <i>,<x>
len=1; x=r8
exitm
endif
endm
if len NE 1 and type (&x) NE 1
echo ------------------------------------------------
echo ***** Macros inchar: Bad operand **** &x& ****
echo ------------------------------------------------
.err
exitm
endif
.data
fmt db "%c",0
buf db ?
.code
??SaveReg Flags
mov buf+1,0
; invoke GetStdHandle,STD_INPUT_HANDLE; -10; eax:=INPUT_HANDLE
;L: invoke StdIn,offset buf,1; îäèí ñèìâîë - Win Library
L: invoke crt_scanf,offset fmt,offset buf; îäèí ñèìâîë - C Library
??RestoreReg Flags
if len EQ 1; x=r8
mov x,buf
else; x=m8, ðàáîòàåò è äëÿ inchar X[eax]
push dword ptr (&x)
push eax
mov al,buf
mov byte ptr [esp+4],al
pop eax
pop dword ptr (&x)
endif
endm
;********************************************
; @inchar macro prompt:VARARG
;********************************************
@InChar equ @inchar
@Inchar equ @inchar
@INCHAR equ @inchar
;********************************************
@inchar macro prompt:VARARG
inchar al,prompt
exitm <al>
endm
;********************************
; flush ñáðîñ áóôåðà ââîäà
;********************************
Flush equ flush
FLUSH equ flush
flush macro
local fmt,buf,L
.data
fmt db "%c",0
buf db ?
.code
??SaveReg Flags
cmp ??buf,10
je @F; Óæå ñ÷èòàí LF â ñòðîêå
;L: invoke StdIn,offset buf,1; îäèí ñèìâîë - Win Library
L: invoke crt_scanf,offset fmt,offset buf; îäèí ñèìâîë - C Library
cmp buf,10; \n
jne L
??RestoreReg Flags
@@:
endm
;**********************************
; outchar[ln] x=m8,r8,i8
;**********************************
OutChar equ outchar
OUTCHAR equ outchar
OUTCH equ outchar
outch equ outchar
;**********************************
outchar macro x:REQ,prompt:VarArg
local len,buf,L
ifnb <prompt>
outstr prompt
endif
len=0
for i,<al,ah,bl,bh,cl,ch,dl,dh>
ifidni <i>,<x>
len=1
exitm
endif
endm
if len NE 1 and type (&x) EQ 0; ýòî îïåðàíä i8
if (&x) GT 255 OR (&x) LT 0
echo -----------------------------------------------
echo ***** Macros outchar: Big operand **** &x& ****
echo -----------------------------------------------
.err
exitm
endif
endif
if len NE 1 and type (&x) NE 1 and type (&x) NE 0
echo -----------------------------------------------
echo ***** Macros outchar: Bad operand **** &x& ****
echo -----------------------------------------------
.err
exitm
endif
.data
buf db 0,0
.code
push eax
mov al,x
mov buf,al
pop eax
outstr offset buf
endm
;********************************************
OutCharln equ outcharln
OutCharLn equ outcharln
OUTCHARLN equ outcharln
OUTCLN equ outcharln
;********************************************
outcharln macro x:REQ,prompt:VARARG
outchar x,prompt
newline
endm
;****************************************
; DOS x=m8,r8,i8; char Win to DOS
;****************************************
dos equ DOS
@dos equ DOS
@DOS equ DOS
;****************************************
DOS macro x:REQ
local len,buf
len=0
for i,<al,ah,bl,bh,cl,ch,dl,dh>
ifidni <i>,<x>
len=1
exitm <>
endif
endm
if len NE 1 and type (&x) EQ 0; ýòî îïåðàíä i8
if (&x) GT 255 OR (&x) LT 0
echo -------------------------------------------------
echo ***** Macros DOS: Big operand **** &x& ****
echo -------------------------------------------------
.err
exitm <>
endif
endif
if len NE 1 and type (&x) NE 1 and type (&x) NE 0
echo -------------------------------------------------
echo ***** Macros DOS: Bad operand **** &x& ****
echo -------------------------------------------------
.err
exitm <>
endif
.data
buf db 0,0
.code
??SaveReg Flags
mov al,x
mov buf,al
push eax
mov eax,offset buf
call WinToDos; Windows to DOS
pop eax
; invoke CharToOem,offset buf,offset buf; Windows to DOS
??RestoreReg Flags
mov al,buf
exitm <al>
endm
;***********************************
; ReadKey txt=:<>; al:=ord(char)
;***********************************
ReadKey equ readkey
READKEY equ readkey
;***********************************
readkey macro txt:=<>
ifnb <txt>
outstr txt
endif
??SaveReg Flags
call wait_key; al:=ord(char)
mov [esp+12],al; eax[al]:=al
??RestoreReg Flags
endm
;************************************
; @ReadKey txt=:<>; al:=ord(char)
;************************************
@ReadKey equ @readkey
@READKEY equ @readkey
;************************************
@readkey macro txt:=<>
readkey txt
exitm <al>
endm
;********************************************
; outint[ln] macro x:REQ,Wide,txt:=<>
; x=i32,m8,m16,m32,r8,r16,r32[,Wide=i8]
;********************************************
Outint equ outint
OutInt equ outint
OUTINT equ outint
OutI equ outint
OUTI equ outint
outi equ outint
;********************************************
outint macro x:REQ,Wide,txt:=<>
OutNum x,Wide,d,txt
endm
; ---------------------------------
Outintln equ outintln
OutintLn equ outintln
OutIntLn equ outintln
outintLn equ outintln
OUTINTLN equ outintln
OutILn equ outintln
OutIln equ outintln
; ---------------------------------
outintln macro x:REQ,Wide,txt:=<>
outint x,Wide,txt
newline
endm
;****************************************************
; outword macro x=i32,m8,m16,m32,r8,r16,r32[,Wide=i8]
;****************************************************
OutWord equ outword
Outword equ outword
OUTWORD equ outword
OutUnsigned equ outword
OutU equ outword
OUTU equ outword
outu equ outword
outword macro x:REQ,Wide,txt:=<>
OutNum x,Wide,u,txt
endm
;******************************************************
; outwordln macro x=i32,m8,m16,m32,r8,r16,r32[,Wide=i8]
;******************************************************
OutWordLn equ outwordln
OutwordLn equ outwordln
outwordLn equ outwordln
OUTWORDLN equ outwordln
OutUnsignedLn equ outwordln
OutUnsignedln equ outwordln
OutULn equ outwordln
OutUln equ outwordln
outwordln macro x:REQ,Wide,txt:=<>
outword x,Wide,txt
newline
endm
;**************************************************
; inint[ln] macro x,txt:=<>
; x=m8,m16,m32,r8,r16,r32
; Ñíà÷àëà ïðîïóñê âñåõ ïðîáåëîâ, LF, CR è TAB,
; çàòåì ââîä ëåêñåìû öåëîãî ÷èñëà äî
; ïåðâîãî ñèìâîëà (âêëþ÷èòåëüíî), íå âõîäÿùåãî
; â ýòó ëåêñåìó, èëè äî LF, CR è TAB
;**************************************************
Inint equ inint
InInt equ inint
ININT equ inint
;**************************************************
inint macro x:REQ,txt:=<>
local len,buf
.data
buf dd ?
.code
ifidni <x>,<sp>
echo --------------------------
echo ** BAD Macros: inint SP **
echo --------------------------
exitm
endif
ifidni <x>,<esp>
echo ---------------------------
echo ** BAD Macros: inint ESP **
echo ---------------------------
exitm
endif
ifnb <txt>
outstr txt
endif
push eax
call inint_proc; îòâåò=eax,EFLAGS(CF,ZF,SF)
; Äàëåå ôëàãè íå ìåíÿþòñÿ !
mov buf,eax
ifidni <x>,<ah>
pop eax
mov ah,byte ptr buf; inint ah
exitm
endif
ifidni <x>,<al>
pop eax
mov al,byte ptr buf; inint al
exitm
endif
ifidni <x>,<ax>
pop eax
mov ax,word ptr buf; inint ax
exitm
endif
ifidni <i>,<eax>
mov [esp],eax
pop eax
exitm
endif
len=0
for i,<bl,bh,cl,ch,dl,dh>
ifidni <i>,<x>
len=1
exitm
endif
endm
for i,<bx,cx,dx,di,si,bp>
ifidni <i>,<x>
len=2
exitm
endif
endm
for i,<ebx,ecx,edx,edi,esi,ebp>
ifidni <i>,<x>
len=4
exitm
endif
endm
if len EQ 1; r8
mov x,al
pop eax
elseif len EQ 2; r16
mov x,ax
pop eax
elseif len EQ 4; r32
mov x,eax
pop eax
elseif type (&x) EQ 1; m8
pop eax ; ñòàðîå eax
push dword ptr (&x)
push eax
mov eax,buf
mov byte ptr [esp+4],al
pop eax
pop dword ptr (&x); inint m8[eax] ðàáîòàåò !
elseif type (&x) EQ 2; m16
pop eax; ñòàðîå eax
push dword ptr (&x)
push eax
mov eax,buf
mov word ptr [esp+4],ax
pop eax
pop dword ptr (&x); inint m16[eax] ðàáîòàåò !
else ; m32
pop eax ; ñòàðîå eax
push buf
pop x ; inint m32[eax] ðàáîòàåò !
endif
endm
;***************************
; @inint[ln] macro txt:=<>
;***************************
@Inint equ @inint
@InInt equ @inint
@ININT equ @inint
;***************************
@inint macro txt:=<>
inint eax,txt
exitm <eax>
endm
;*******************************
; inintln macro x:REQ,txt:=<>
; Ñíà÷àëà inint çàòåì flush
;*******************************
InintLn equ inintln
Inintln equ inintln
ININTLN equ inintln
;*******************************
inintln macro x:REQ,txt:=<>
inint x,txt
pushfd
flush
popfd
endm
;**************************
; @inintln macro txt:=<>
;**************************
@InintLn equ @inintln
@Inintln equ @inintln
@ININTLN equ @inintln
;**************************
@inintln macro txt:=<>
inintln eax,txt
exitm <eax>
endm
;****************************************************
; new macro size=i32 ; min size=16
;*****************************************************
.data
??TotalHeapAllocated dd 0
??CommonHeapElemSize dd 0
New equ new
NEW equ new
;****************************************************
new macro size:=<16>
pushfd
invoke GlobalAlloc,GMEM_FIXED+GMEM_ZEROINIT,size
add ??TotalHeapAllocated,size
mov ??CommonHeapElemSize,size
popfd
endm
;****************************************************
; dispose macro ref:req
;****************************************************
Dispose equ dispose
DISPOSE equ dispose
;****************************************************
dispose macro ref:req