Skip to content

Commit f4bc1a3

Browse files
committed
[Python][Z80InstrBuilder] Support the rest of instructions.
1 parent dcd3b0c commit f4bc1a3

File tree

4 files changed

+188
-16
lines changed

4 files changed

+188
-16
lines changed

tests/testsuite.py

+27
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,37 @@ def __str__(self):
1212
def runTest(self):
1313
TESTS = (
1414
(b'\xcb\x30', 'sll b'),
15+
(b'\xdd\x24', 'inc ixh'),
16+
(b'\xdd\x2c', 'inc ixl'),
17+
(b'\xfd\x24', 'inc iyh'),
18+
(b'\xfd\x2c', 'inc iyl'),
1519
(b'\xdd\xe5', 'push ix'),
1620
(b'\xfd\xe1', 'pop iy'),
21+
(b'\xdd\xe8', 'ret pe'),
22+
(b'\xed\x00', 'xnop 0xed00'),
23+
(b'\xed\x45', 'retn'),
24+
(b'\xed\x55', 'xretn 0xed55'),
25+
(b'\xed\x4d', 'reti'),
26+
(b'\xed\x4c', 'xneg 0xed4c'),
27+
(b'\xed\x4e', 'xim 0xed4e, 0x0'),
28+
(b'\xed\x4f', 'ld r, a'),
1729
(b'\xed\x50', 'in d, (c)'),
30+
(b'\xed\x63\x00\x00', 'xld 0xed63, (0x0), hl'),
1831
(b'\xed\xa3', 'outi'),
32+
(b'\xed\xb3', 'otir'),
33+
(b'\xed\xab', 'outd'),
34+
(b'\xed\xbb', 'otdr'),
35+
(b'\xed\x67', 'rrd'),
36+
(b'\xed\xa0', 'ldi'),
37+
(b'\xed\xa1', 'cpi'),
38+
(b'\xed\xb1', 'cpir'),
39+
(b'\xed\xb9', 'cpdr'),
40+
(b'\xed\xa9', 'cpd'),
41+
(b'\xed\xa2', 'ini'),
42+
(b'\xed\xb2', 'inir'),
43+
(b'\xed\xaa', 'ind'),
44+
(b'\xed\xba', 'indr'),
45+
(b'\xed\xa8', 'ldd'),
1946
)
2047

2148
builder = z80.Z80InstrBuilder()

z80/__init__.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99

1010
from ._disasm import _Disasm, Z80InstrBuilder
1111
from ._error import Error
12-
from ._instr import (ADD, ADC, AND, CP, OR, SBC, SUB, XOR, BIT, CALL, CCF, CPL,
13-
DAA, DEC, DI, DJNZ, EI, EX, EXX, HALT, IM, INC, IN, JP,
14-
JR, LD, LDDR, LDIR, NEG, NOP,
12+
from ._instr import (ADD, ADC, AND, CP, CPD, CPDR, CPI, CPIR,
13+
OR, SBC, SUB, XOR, BIT, CALL, CCF, CPL,
14+
DAA, DEC, DI, DJNZ, EI, EX, EXX, HALT, IM, XIM,
15+
INC, IN, IND, INDR, INI, INIR, JP, JR, LD, XLD,
16+
LDD, LDDR, LDI, LDIR, NEG, XNEG, NOP, XNOP,
1517
RLC, RL, RR, RRC, SLA, SLL, SRA,
16-
SRL, OUT, OUTI, POP, PUSH, RES, RET,
17-
RLA, RLCA, RLD, RRA, RRCA,
18-
RST, SCF, SET, A, AF, AF2, CF, M, NC, NZ, PO, P, Z, DE,
19-
BC, HL, IReg, IY, IX, SP, B, C, D, E, H, L, UnknownInstr,
20-
JumpInstr, CallInstr, RetInstr, At, IndexReg, Add)
18+
SRL, OUT, OUTD, OTDR, OUTI, OTIR, POP, PUSH, RES,
19+
RET, RETN, XRETN, RETI,
20+
RLA, RLCA, RLD, RRA, RRD, RRCA,
21+
RST, SCF, SET, A, AF, AF2, CF, M, NC, NZ, PE, PO, P, Z,
22+
DE, BC, HL, IReg, R, IY, IX, SP,
23+
B, C, D, E, H, L, IXH, IXL, IYH, IYL,
24+
UnknownInstr, JumpInstr, CallInstr, RetInstr, At,
25+
IndexReg, Add)
2126
from ._machine import I8080Machine, Z80Machine
2227
from ._main import main
2328
from ._source import _SourceFile

z80/_disasm.py

+40-8
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
import os
1414
import tempfile
1515
from ._error import Error
16-
from ._instr import (ADD, ADC, AND, CP, OR, SBC, SUB, XOR, BIT, CALL, CCF, CPL,
17-
DAA, DEC, DI, DJNZ, EI, EX, EXX, HALT, IM, INC, IN, JP,
18-
JR, LD, LDDR, LDIR, NEG, NOP,
16+
from ._instr import (ADD, ADC, AND, CP, CPD, CPDR, CPI, CPIR,
17+
OR, SBC, SUB, XOR, BIT, CALL, CCF, CPL,
18+
DAA, DEC, DI, DJNZ, EI, EX, EXX, HALT, IM, XIM,
19+
INC, IN, IND, INDR, INI, INIR, JP, JR, LD, XLD,
20+
LDD, LDDR, LDI, LDIR, NEG, XNEG, NOP, XNOP,
1921
RLC, RL, RR, RRC, SLA, SLL, SRA,
20-
SRL, OUT, OUTI, POP, PUSH, RES, RET,
21-
RLA, RLCA, RLD, RRA, RRCA,
22-
RST, SCF, SET, A, AF, AF2, CF, M, NC, NZ, PO, P, Z, DE,
23-
BC, HL, IReg, IY, IX, SP, B, C, D, E, H, L, UnknownInstr,
24-
JumpInstr, CallInstr, RetInstr, At, IndexReg, Add)
22+
SRL, OUT, OUTD, OTDR, OUTI, OTIR, POP, PUSH, RES,
23+
RET, RETN, XRETN, RETI,
24+
RLA, RLCA, RLD, RRA, RRD, RRCA,
25+
RST, SCF, SET, A, AF, AF2, CF, M, NC, NZ, PE, PO, P, Z,
26+
DE, BC, HL, IReg, R, IY, IX, SP,
27+
B, C, D, E, H, L, IXH, IXL, IYH, IYL,
28+
UnknownInstr, JumpInstr, CallInstr, RetInstr, At,
29+
IndexReg, Add)
2530
from ._machine import Z80Machine
2631

2732

@@ -155,15 +160,29 @@ class Z80InstrBuilder(object):
155160
'exx': EXX,
156161
'halt': HALT,
157162
'im': IM,
163+
'xim': XIM,
158164
'inc': INC,
159165
'in': IN,
166+
'Iind': IND,
167+
'Iindr': INDR,
168+
'Iini': INI,
169+
'Iinir': INIR,
160170
'jp': JP,
161171
'jr': JR,
162172
'ld': LD,
173+
'xld': XLD,
174+
'Lldd': LDD,
163175
'Llddr': LDDR,
176+
'Lldi': LDI,
164177
'Lldir': LDIR,
178+
'Mcpd': CPD,
179+
'Mcpdr': CPDR,
180+
'Mcpi': CPI,
181+
'Mcpir': CPIR,
165182
'neg': NEG,
183+
'xneg': XNEG,
166184
'nop': NOP,
185+
'xnop': XNOP,
167186
'Orlc': RLC,
168187
'Orl': RL,
169188
'Orr': RR,
@@ -177,16 +196,23 @@ class Z80InstrBuilder(object):
177196
'push': PUSH,
178197
'res': RES,
179198
'ret': RET,
199+
'retn': RETN,
200+
'xretn': XRETN,
201+
'reti': RETI,
180202
'rla': RLA,
181203
'rlca': RLCA,
182204
'rld': RLD,
183205
'rra': RRA,
206+
'rrd': RRD,
184207
'rrca': RRCA,
185208
'rst': RST,
186209
'sbc': SBC,
187210
'scf': SCF,
188211
'set': SET,
212+
'Toutd': OUTD,
213+
'Totdr': OTDR,
189214
'Touti': OUTI,
215+
'Totir': OTIR,
190216
}
191217

192218
__OPS = {
@@ -198,6 +224,7 @@ class Z80InstrBuilder(object):
198224
'Cm': M,
199225
'Cnc': NC,
200226
'Cnz': NZ,
227+
'Cpe': PE,
201228
'Cpo': PO,
202229
'Cp': P,
203230
'Cz': Z,
@@ -210,6 +237,7 @@ class Z80InstrBuilder(object):
210237
'Giy': IY,
211238
'hl': HL,
212239
'i': IReg,
240+
'r': R,
213241
'ix': IX,
214242
'iy': IY,
215243
'Pbc': BC,
@@ -225,6 +253,10 @@ class Z80InstrBuilder(object):
225253
'Re': E,
226254
'Rh': H,
227255
'Rl': L,
256+
'Rixh': IXH,
257+
'Rixl': IXL,
258+
'Riyh': IYH,
259+
'Riyl': IYL,
228260
'sp': SP,
229261
}
230262

z80/_instr.py

+108
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class P(metaclass=CondFlag):
4242
pass
4343

4444

45+
class PE(metaclass=CondFlag):
46+
pass
47+
48+
4549
class PO(metaclass=CondFlag):
4650
pass
4751

@@ -94,6 +98,10 @@ class IReg(metaclass=Reg):
9498
_str = 'i'
9599

96100

101+
class R(metaclass=Reg):
102+
pass
103+
104+
97105
class AF(metaclass=Reg):
98106
pass
99107

@@ -118,10 +126,26 @@ class IX(metaclass=IndexReg):
118126
pass
119127

120128

129+
class IXH(metaclass=IndexReg):
130+
pass
131+
132+
133+
class IXL(metaclass=IndexReg):
134+
pass
135+
136+
121137
class IY(metaclass=IndexReg):
122138
pass
123139

124140

141+
class IYH(metaclass=IndexReg):
142+
pass
143+
144+
145+
class IYL(metaclass=IndexReg):
146+
pass
147+
148+
125149
class SP(metaclass=Reg):
126150
pass
127151

@@ -244,6 +268,22 @@ class CP(Instr):
244268
pass
245269

246270

271+
class CPD(Instr):
272+
pass
273+
274+
275+
class CPDR(Instr):
276+
pass
277+
278+
279+
class CPI(Instr):
280+
pass
281+
282+
283+
class CPIR(Instr):
284+
pass
285+
286+
247287
class CPL(Instr):
248288
pass
249289

@@ -284,10 +324,30 @@ class IM(Instr):
284324
pass
285325

286326

327+
class XIM(Instr):
328+
pass
329+
330+
287331
class IN(Instr):
288332
pass
289333

290334

335+
class IND(Instr):
336+
pass
337+
338+
339+
class INDR(Instr):
340+
pass
341+
342+
343+
class INI(Instr):
344+
pass
345+
346+
347+
class INIR(Instr):
348+
pass
349+
350+
291351
class INC(Instr):
292352
pass
293353

@@ -304,10 +364,22 @@ class LD(Instr):
304364
pass
305365

306366

367+
class XLD(Instr):
368+
pass
369+
370+
371+
class LDD(Instr):
372+
pass
373+
374+
307375
class LDDR(Instr):
308376
pass
309377

310378

379+
class LDI(Instr):
380+
pass
381+
382+
311383
class LDIR(Instr):
312384
pass
313385

@@ -316,10 +388,18 @@ class NEG(Instr):
316388
pass
317389

318390

391+
class XNEG(Instr):
392+
pass
393+
394+
319395
class NOP(Instr):
320396
pass
321397

322398

399+
class XNOP(Instr):
400+
pass
401+
402+
323403
class OR(Instr):
324404
pass
325405

@@ -328,10 +408,22 @@ class OUT(Instr):
328408
pass
329409

330410

411+
class OUTD(Instr):
412+
pass
413+
414+
415+
class OTDR(Instr):
416+
pass
417+
418+
331419
class OUTI(Instr):
332420
pass
333421

334422

423+
class OTIR(Instr):
424+
pass
425+
426+
335427
class POP(Instr):
336428
pass
337429

@@ -348,6 +440,18 @@ class RET(RetInstr):
348440
pass
349441

350442

443+
class RETN(RetInstr):
444+
pass
445+
446+
447+
class XRETN(RetInstr):
448+
pass
449+
450+
451+
class RETI(RetInstr):
452+
pass
453+
454+
351455
class RL(Instr):
352456
pass
353457

@@ -376,6 +480,10 @@ class RRA(Instr):
376480
pass
377481

378482

483+
class RRD(Instr):
484+
pass
485+
486+
379487
class RRC(Instr):
380488
pass
381489

0 commit comments

Comments
 (0)