Skip to content

Commit b23f99a

Browse files
authored
Merge pull request #298 from boriel/feature/zx_next_asm
Feature/zx next asm
2 parents 04eaa46 + d496730 commit b23f99a

19 files changed

+400
-18
lines changed

api/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def init():
6868
OPTIONS.add_option('explicit', bool, False)
6969
OPTIONS.add_option('Sinclair', bool, False)
7070
OPTIONS.add_option('strict', bool, False) # True to force type checking
71+
OPTIONS.add_option('zxnext', bool, False) # True to enable ZX Next ASM opcodes
7172

7273

7374
init()

asmlex.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,31 @@
9393
'xor': 'XOR',
9494
}
9595

96+
zx_next_mnemonics = {
97+
x.lower(): x for x in [
98+
"LDIX",
99+
"LDWS",
100+
"LDIRX",
101+
"LDDX",
102+
"LDDRX",
103+
"LDPIRX",
104+
"OUTINB",
105+
"MUL",
106+
"SWAPNIB",
107+
"MIRROR",
108+
"NEXTREG",
109+
"PIXELDN",
110+
"PIXELAD",
111+
"SETAE",
112+
"TEST",
113+
"BSLA",
114+
"BSRA",
115+
"BSRL",
116+
"BSRF",
117+
"BRLC"
118+
]
119+
}
120+
96121
pseudo = { # pseudo ops
97122
'align': 'ALIGN',
98123
'org': 'ORG',
@@ -154,6 +179,7 @@
154179
tuple(regs8.values()) +
155180
tuple(regs16.values()) +
156181
tuple(flags.values()) +
182+
tuple(zx_next_mnemonics.values()) +
157183
tuple(preprocessor.values())
158184
)
159185

@@ -162,7 +188,8 @@
162188
regs16.keys()).union(
163189
regs8.keys()).union(
164190
pseudo.keys()).union(
165-
reserved_instructions.keys())
191+
reserved_instructions.keys()).union(
192+
zx_next_mnemonics.keys())
166193

167194

168195
def get_uniques(l):
@@ -273,6 +300,11 @@ def t_INITIAL_ID(self, t):
273300
if t.type is not None:
274301
return t
275302

303+
if OPTIONS.zxnext.value:
304+
t.type = zx_next_mnemonics.get(id_)
305+
if t.type is not None:
306+
return t
307+
276308
t.type = regs16.get(id_, 'ID')
277309
if t.type == 'ID':
278310
t.value = tmp # Restores original value

asmparse.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,12 @@ def assemble(input_):
14551455
if MEMORY is None:
14561456
MEMORY = Memory()
14571457

1458-
parser.parse(input_, lexer=LEXER, debug=OPTIONS.Debug.value > 2)
1458+
if OPTIONS.zxnext.value:
1459+
parser_ = zxnext_parser
1460+
else:
1461+
parser_ = parser
1462+
1463+
parser_.parse(input_, lexer=LEXER, debug=OPTIONS.Debug.value > 2)
14591464
if len(MEMORY.scopes):
14601465
error(MEMORY.scopes[-1], 'Missing ENDP to close this scope')
14611466

@@ -1541,4 +1546,13 @@ def main(argv):
15411546
generate_binary(OPTIONS.outputFileName.value, OPTIONS.output_file_type)
15421547

15431548

1544-
parser = api.utils.get_or_create('asmparse', lambda: yacc.yacc(debug=OPTIONS.Debug.value > 2))
1549+
# Z80 only ASM parser
1550+
parser = api.utils.get_or_create('asmparse',
1551+
lambda: yacc.yacc(start="start", debug=OPTIONS.Debug.value > 2))
1552+
1553+
# needed for ply
1554+
from zxnext import * # noqa
1555+
1556+
# ZXNEXT extended OPcodes parser
1557+
zxnext_parser = api.utils.get_or_create('zxnext_asmparse',
1558+
lambda: yacc.yacc(start="start", debug=OPTIONS.Debug.value > 2))

parsetab/tabs.dbm.bak

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
'zxbppparse', (0, 68810)
2-
'zxbparser', (69120, 707013)
3-
'asmparse', (776192, 250068)
2+
'asmparse', (69120, 250081)
3+
'zxnext_asmparse', (319488, 280962)
4+
'zxbparser', (600576, 707013)

parsetab/tabs.dbm.dat

275 KB
Binary file not shown.

parsetab/tabs.dbm.dir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
'zxbppparse', (0, 68810)
2-
'zxbparser', (69120, 707013)
3-
'asmparse', (776192, 250068)
2+
'asmparse', (69120, 250081)
3+
'zxnext_asmparse', (319488, 280962)
4+
'zxbparser', (600576, 707013)

tests/api/test_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ def test_initted_values(self):
7373
'strict',
7474
'strictBool',
7575
'string_base',
76-
'use_loader'])
76+
'use_loader',
77+
'zxnext'])

tests/functional/no_zxnext.asm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
LDIX
2+
LDWS
3+
LDIRX
4+
LDDX
5+
LDDRX
6+
LDPIRX
7+
OUTINB
8+
MUL D,E
9+
ADD HL,A
10+
ADD DE,A
11+
ADD BC,A
12+
ADD HL,0201h
13+
ADD DE,0201h
14+
ADD BC,0201h
15+
SWAPNIB
16+
MIRROR
17+
PUSH 4321h
18+
NEXTREG 37h,38h
19+
NEXTREG 33h,A
20+
PIXELDN
21+
PIXELAD
22+
SETAE
23+
TEST 77h
24+
BSLA DE,B
25+
BSRA DE,B
26+
BSRL DE,B
27+
BSRF DE,B
28+
BRLC DE,B
29+
JP (C)
30+

tests/functional/test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ def testASM(fname, inline=None, cmdline_args=None):
320320
os.unlink(okfile)
321321

322322
options = [fname, '-o', tfname] + prep
323+
if fname.startswith('zxnext_'):
324+
options.append('--zxnext')
323325
options.extend(cmdline_args)
324326

325327
if inline:

tests/functional/test_asm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
@pytest.mark.parametrize('fname', [os.path.join(TEST_PATH, f) for f in os.listdir(TEST_PATH) if f.endswith(".asm")])
1414
def test_asm(fname):
15-
test.main(['-d', '-e', '/dev/null', fname])
15+
options = ['-d', '-e', '/dev/null', fname]
16+
if os.path.basename(fname).startswith('zxnext_'):
17+
options.extend(['-O=-N'])
18+
19+
test.main(options)
1620
if test.COUNTER == 0:
1721
return
1822

0 commit comments

Comments
 (0)