forked from redcode/SpecEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Macros.inc
168 lines (154 loc) · 5.49 KB
/
Macros.inc
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
LOG MACRO msg:req, cr:=<TRUE>
LOCAL @@msg
IFDEF LOGGING
.DATA
IF cr eq TRUE
@@msg db msg, 13, 10
ELSE
@@msg db msg
ENDIF
.CODE
pushad
.if $fnc (CreateFile, SADD ("E:\SpecEmuLog.txt"), GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) != INVALID_HANDLE_VALUE
mov ebx, eax
invoke SetFilePointer, ebx, 0, NULL, FILE_END
invoke WriteFile, ebx, addr @@msg, sizeof @@msg, addr BytesSaved, NULL
invoke CloseHandle, ebx
.endif
popad
ENDIF
ENDM
LOGLPSTR MACRO msgptr:req
LOCAL @@msg
IFDEF LOGGING
.DATA
@@msg db 13, 10
.CODE
pushad
mov ebx, msgptr
.if $fnc (CreateFile, SADD ("E:\SpecEmuLog.txt"), GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) != INVALID_HANDLE_VALUE
push eax
invoke SetFilePointer, eax, 0, NULL, FILE_END
invoke StrLen, ebx
mov edx, eax
pop eax
push eax
invoke WriteFile, eax, ebx, edx, addr BytesSaved, NULL
pop eax
push eax
invoke WriteFile, eax, addr @@msg, sizeof @@msg, addr BytesSaved, NULL
pop eax
invoke CloseHandle, eax
.endif
popad
ENDIF
ENDM
LOGHEX MACRO msg:req, arg:req
LOCAL @@msg, @@buffer1
IFDEF LOGGING
.DATA?
@@buffer1 BYTE 12 dup (?)
.CODE
LOG msg, FALSE
pushad
mov edx, arg
invoke dw2hex, edx, addr @@buffer1
LOGLPSTR offset @@buffer1
popad
ENDIF
ENDM
LOGRECT macro rectname:req, lprect:req
ifdef LOGGING
pushad
mov ebx, lprect
LOG "Rect: ", FALSE
LOG rectname, FALSE
LOG ": ", TRUE
LOGHEX " .left = ", [ebx].RECT.left
LOGHEX " .right = ", [ebx].RECT.right
LOGHEX " .top = ", [ebx].RECT.top
LOGHEX " .bottom = ", [ebx].RECT.bottom
popad
endif
endm
CHECKACTIVESTATE MACRO
cmp EmuThreadState, ThreadStopped
je @F
cmp EmuThreadState, ThreadStopping
@@:
ENDM
STARTBOX MACRO
pushad
invoke MessageBox, hWnd, addr debugstart, addr szDisplayName, MB_OK or MB_ICONEXCLAMATION
popad
ENDM
ENDBOX MACRO
pushad
invoke MessageBox, hWnd, addr debugend, addr szDisplayName, MB_OK or MB_ICONEXCLAMATION
popad
ENDM
STARTTICKCOUNT MACRO
LOCAL @@loop
call GetTickCount
mov Time1, eax
@@loop: call GetTickCount
cmp eax, Time1
je @@loop
mov Time1, eax
ENDM
ENDTICKCOUNT MACRO
call GetTickCount
sub eax, Time1
mov TimeTook, eax
ENDM
;PRINTSTRING MACRO pstring
; LOCAL @@pstring
; .data
; @@pstring db pstring,0
; .code
; lea esi, @@pstring
; call PrtString
; ENDM
;
;PRINTHEX8 MACRO phex8
; mov al, phex8
; call PrtHex8
; ENDM
;
;PRINTHEX16 MACRO phex16
; mov ax, phex16
; call PrtHex16
; ENDM
;
;PRINTHEX32 MACRO phex32
; mov eax, phex32
; call PrtHex32
; ENDM
;
;PRINTDEC16 MACRO pdec16
; mov ax, pdec16
; call PrtDec16
; ENDM
;
;PRINTDEC32 MACRO pdec32
; mov eax, pdec32
; call PrtDec32
; ENDM
;
;SETPAPER MACRO newpapercol
; mov al, newpapercol
; mov PAPERCOL, al
; ENDM
;
;SETINK MACRO newinkcol
; mov al, newinkcol
; mov INKCOL, al
; ENDM
;
;CLS MACRO
; call ClearMyScreen
; ENDM
;
;HOME MACRO
; call Cursor_HOME
; ENDM