forked from NEO-SPECTRUMAN/SpecEmu
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathZ80Macros.inc
362 lines (327 loc) · 12.3 KB
/
Z80Macros.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
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
; Z80 core support macros
; ------------------
; GETINDEXEDOPCODE
; ================
; reads the byte following the signed offset in indexed opcodes
; adds the 5 Tstates (internal operation) + contended cycles
; returns byte in al
; increments PC register
GETINDEXEDOPCODE MACRO
push ebx
movzx ebx, Reg_PC
GETOPCODEBYTE ; read the opcode to al
SETTS 3 ; 3 Ts for opcode read
ADDMULTICONTENTIONPC 2 ; 2 contended cycles at address of opcode read
add Reg_PC, 1 ; advance PC
add Reg_InsLength, 1 ; required for disassembler
pop ebx
ENDM
Setf5_3 MACRO arg1
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
and Reg_F, NOT @FLAGS (53)
and al, @FLAGS (53)
or Reg_F, al
ENDM
; bx = base addr, al = offset
ADDOFFSET MACRO
cbw ; extend al to ax
add bx, ax ; bx = effective addr
mov Reg_MemPtr, bx
ENDM
INCBYTE MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
inc al
lahf
seto cl
mov dl, al
shl cl, 2
and ah, NOT @FLAGS (53VN)
or ah, cl
and dl, @FLAGS (53)
or ah, dl
mov Reg_F, ah
ENDM
DECBYTE MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
dec al
lahf
seto cl
mov dl, al
shl cl, 2
and ah, NOT @FLAGS (53V)
or ah, cl
and dl, @FLAGS (53)
or ah, dl
or ah, FLAG_N
mov Reg_F, ah
ENDM
ADDBYTE MACRO arg1,arg2
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
add al, arg2
lahf
seto cl
mov dl, al
shl cl, 2
and ah, NOT @FLAGS (53VN)
or ah, cl
and dl, @FLAGS (53)
or ah, dl
mov Reg_F, ah
ENDM
ADCBYTE MACRO arg1,arg2
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
adc al, arg2
lahf
seto cl
mov dl, al
shl cl, 2
and ah, NOT @FLAGS (53VN)
or ah, cl
and dl, @FLAGS (53)
or ah, dl
mov Reg_F, ah
ENDM
SUBBYTE MACRO arg1,arg2
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
sub al, arg2
lahf
seto cl
mov dl, al
shl cl, 2
and ah, NOT @FLAGS (53V)
or ah, cl
and dl, @FLAGS (53)
or ah, dl
or ah, FLAG_N
mov Reg_F, ah
ENDM
SBCBYTE MACRO arg1,arg2
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
sbb al, arg2
lahf
seto cl
mov dl, al
shl cl, 2
and ah, NOT @FLAGS (53V)
or ah, cl
and dl, @FLAGS (53)
or ah, dl
or ah, FLAG_N
mov Reg_F, ah
ENDM
ANDBYTE MACRO arg1,arg2
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
and al, arg2
lahf
mov dl, al
or ah, FLAG_H
and ah, NOT @FLAGS (53N)
and dl, @FLAGS (53)
or ah, dl
mov Reg_F,ah
test byte ptr arg2, NOT (64+32)
.if ZERO?
.if (byte ptr arg2 == 32) || (byte ptr arg2 == 64)
mov SL_AND_32_64, TRUE ; set the potential tape loader flag
.endif
.endif
ENDM
ORBYTE MACRO arg1,arg2
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
or al, arg2
lahf
mov dl, al
and ah, NOT @FLAGS (5H3N)
and dl, @FLAGS (53)
or ah, dl
mov Reg_F, ah
ENDM
XORBYTE MACRO arg1,arg2
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <al>
mov al, arg1
ENDIF
mov ah, Reg_F
sahf
xor al, arg2
lahf
mov dl, al
and ah, NOT @FLAGS (5H3N)
and dl, @FLAGS (53)
or ah, dl
mov Reg_F, ah
ENDM
CMPBYTE MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <dl>
mov dl, arg1
ENDIF
mov al, Reg_A
mov ah, Reg_F
sahf
cmp al, dl
lahf
seto cl
shl cl, 2
and ah, NOT @FLAGS (53V)
or ah, cl
and dl, @FLAGS (53)
or ah, dl
or ah, FLAG_N
mov Reg_F, ah
ENDM
ADDHL MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <cx>
mov cx, arg1
ENDIF
movzx ebx, Reg_HL
mov dl, Reg_F
lea eax, [ebx+1]
add bl, cl
mov Reg_MemPtr, ax
adc bh, ch
lahf
mov Reg_HL, bx
and dl, @FLAGS (SZV)
and ah, @FLAGS (HC)
and bh, @FLAGS (53)
or ah, dl
or ah, bh
mov Reg_F, ah
ENDM
ADDIX MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <cx>
mov cx, arg1
ENDIF
movzx ebx, Reg_IX
mov dl, Reg_F
lea eax, [ebx+1]
add bl, cl
mov Reg_MemPtr, ax
adc bh, ch
lahf
mov Reg_IX, bx
and dl, @FLAGS (SZV)
and ah, @FLAGS (HC)
and bh, @FLAGS (53)
or ah, dl
or ah, bh
mov Reg_F, ah
ENDM
ADDIY MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <cx>
mov cx, arg1
ENDIF
movzx ebx, Reg_IY
mov dl, Reg_F
lea eax, [ebx+1]
add bl, cl
mov Reg_MemPtr, ax
adc bh, ch
lahf
mov Reg_IY, bx
and dl, @FLAGS (SZV)
and ah, @FLAGS (HC)
and bh, @FLAGS (53)
or ah, dl
or ah, bh
mov Reg_F, ah
ENDM
ADCHL MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <cx>
mov cx, arg1
ENDIF
movzx ebx, Reg_HL
mov ah, Reg_F
lea edx, [ebx+1]
sahf
adc bl, cl
mov Reg_MemPtr, dx
adc bh, ch
lahf
seto cl
mov Reg_HL, bx
shl cl, 2
and ah, NOT @FLAGS (Z53VN)
or bx, bx
.if ZERO?
or ah, FLAG_Z
.endif
and bh, @FLAGS (53)
or ah, cl
or ah, bh
mov Reg_F, ah
ENDM
SBCHL MACRO arg1
FLAGS_MODIFIED TRUE
IFDIF <arg1>, <cx>
mov cx, arg1
ENDIF
movzx ebx, Reg_HL
mov ah, Reg_F
lea edx, [ebx+1]
sahf
sbb bl, cl
mov Reg_MemPtr, dx
sbb bh, ch
lahf
seto cl
mov Reg_HL, bx
shl cl, 2
and ah, NOT @FLAGS (Z53V)
or bx, bx
.if ZERO?
or ah, FLAG_Z
.endif
and bh, @FLAGS (53)
or ah, cl
or ah, bh
or ah, FLAG_N
mov Reg_F, ah
ENDM