1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-10-15 10:24:03 +00:00

Generate regexps to make addressing easier to read

This commit is contained in:
Mike Naberezny 2014-12-14 18:05:25 -08:00
parent a996cbceec
commit 02e7953373

View File

@ -8,38 +8,22 @@ class Assembler:
r'[,xXyY\s]*)$') r'[,xXyY\s]*)$')
Addressing = ( Addressing = (
('zpi', # "($0012)" ('zpi', "($00FF)"),
r'^\(\$0{BYTE}([0-9A-F]{BYTE})\)$'), ('zpx', "$00FF,X"),
('zpx', # "$0012,X" ('zpy', "$00FF,Y"),
r'^\$0{BYTE}([0-9A-F]{BYTE}),X$'), ('zpg', "$00FF"),
('zpy', # "$0012,Y" ('inx', "($00FF,X)"),
r'^\$0{BYTE}([0-9A-F]{BYTE}),Y$'), ('iax', "($FFFF,X)"),
('zpg', # "$0012" ('iny', "($00FF),Y"),
r'^\$0{BYTE}([0-9A-F]{BYTE})$'), ('ind', "($FFFF)"),
('inx', # "($0012,X) ('abx', "$FFFF,X"),
r'^\(\$0{BYTE}([0-9A-F]{BYTE}),X\)$'), ('aby', "$FFFF,Y"),
('iax', # "($1234,X) ('abs', "$FFFF"),
r'^\(\$([0-9A-F]{BYTE})([0-9A-F]{BYTE}),X\)$'), ('rel', "$FFFF"),
('iny', # "($0012),Y" ('imp', ""),
r'^\(\$0{BYTE}([0-9A-F]{BYTE})\),Y$'), ('acc', ""),
('ind', # "($1234)" ('acc', "A"),
r'^\(\$([0-9A-F]{BYTE})([0-9A-F]{BYTE})\)$'), ('imm', "#$FF")
('abx', # "$1234,X"
r'^\$([0-9A-F]{BYTE})([0-9A-F]{BYTE}),X$'),
('aby', # "$1234,Y"
r'^\$([0-9A-F]{BYTE})([0-9A-F]{BYTE}),Y$'),
('abs', # "$1234"
r'^\$([0-9A-F]{BYTE})([0-9A-F]{BYTE})$'),
('rel', # "$1234"
r'^\$([0-9A-F]{BYTE})([0-9A-F]{BYTE})$'),
('imp', # ""
r'^$'),
('acc', # ""
r'^$'),
('acc', # "A"
r'^A$'),
('imm', # "#$12"
r'^#\$([0-9A-F]{BYTE})$')
) )
def __init__(self, mpu, address_parser=None): def __init__(self, mpu, address_parser=None):
@ -54,9 +38,11 @@ class Assembler:
self._addressing = [] self._addressing = []
numchars = mpu.BYTE_WIDTH / 4 # 1 byte = 2 chars in hex numchars = mpu.BYTE_WIDTH / 4 # 1 byte = 2 chars in hex
for mode, pattern in self.Addressing: for mode, format in self.Addressing:
pattern = pattern.replace('BYTE', '%d' % numchars) pat = "^" + re.escape(format) + "$"
self._addressing.append([mode, re.compile(pattern)]) pat = pat.replace('00', '0{%d}' % numchars)
pat = pat.replace('FF', '([0-9A-F]{%d})' % numchars)
self._addressing.append([mode, re.compile(pat)])
def assemble(self, statement, pc=0000): def assemble(self, statement, pc=0000):
""" Assemble the given assembly language statement. If the statement """ Assemble the given assembly language statement. If the statement