1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-07 12:29:27 +00:00

Fix assembling opcodes where the mnemonic has a digit

This commit is contained in:
Mike Naberezny 2012-11-18 22:17:38 -08:00
parent ad31ed40a7
commit 0c51e9f337
4 changed files with 270 additions and 248 deletions

View File

@ -3,6 +3,9 @@
- Assembling now detects syntax errors, overflows, and bad labels
separately and shows specific error messages.
- Fixed assembling 65C02 opcodes whose mnemonics have a digit
such as "RMB3".
0.13 (2012-11-15)
- Fixed a bug where negative numbers could be entered

View File

@ -3,7 +3,7 @@ from py65.devices.mpu6502 import MPU
from py65.utils.addressing import AddressParser
class Assembler:
Statement = re.compile(r'^([A-z]{3}\s+'
Statement = re.compile(r'^([A-z]{3}[0-7]?\s+'
r'\(?\s*)([^,\s\)]+)(\s*[,xXyY\s]*\)?'
r'[,xXyY\s]*)$')
@ -70,10 +70,10 @@ class Assembler:
uses relative addressing, the program counter (pc) must also be given.
The result is a list of bytes. Raises when assembly fails.
"""
opcode, operands = self.normalize_and_split(statement)
opcode, operand = self.normalize_and_split(statement)
for mode, pattern in self.Addressing:
match = pattern.match(operands)
match = pattern.match(operand)
if match:
try:
@ -105,9 +105,8 @@ class Assembler:
""" Given an assembly language statement like "lda $c12,x", normalize
the statement by uppercasing it, removing unnecessary whitespace,
and parsing the address part using AddressParser. The result of
the normalization is a tuple of two strings (opcode, operands).
the normalization is a tuple of two strings (opcode, operand).
"""
# normalize target in operand
match = self.Statement.match(statement)
if match:
@ -129,7 +128,11 @@ class Assembler:
address = self._address_parser.number(target)
statement = before + '$' + self.addrFmt % address + after
# strip unnecessary whitespace
opcode = statement[:3].upper()
operand = ''.join(statement[3:].split()).upper().strip()
# separate opcode and operand
splitted = statement.split(" ", 2)
opcode = splitted[0].strip().upper()
if len(splitted) > 1:
operand = splitted[1].strip().upper()
else:
operand = ''
return (opcode, operand)

View File

@ -1,6 +1,7 @@
import unittest
import sys
from py65.devices.mpu6502 import MPU
from py65.devices.mpu65c02 import MPU as MPU65C02
from py65.assembler import Assembler
from py65.utils.addressing import AddressParser
@ -42,8 +43,14 @@ class AssemblerTests(unittest.TestCase):
self.assertEqual([0x06, 0x44],
self.assemble('ASL $44'))
def dont_test_assembles_07(self):
pass
def test_assembles_07_6502(self):
self.assertRaises(SyntaxError,
self.assemble, "RMB0 $42")
def test_assembles_07_65c02(self):
mpu = MPU65C02()
self.assertEqual([0x07, 0x42],
self.assemble('RMB0 $42', 0x0000, mpu))
def test_assembles_08(self):
self.assertEqual([0x08],
@ -941,8 +948,9 @@ class AssemblerTests(unittest.TestCase):
# Test Helpers
def assemble(self, statement, pc=0000):
mpu = MPU()
def assemble(self, statement, pc=0000, mpu=None):
if mpu is None:
mpu = MPU()
address_parser = AddressParser()
assembler = Assembler(mpu, address_parser)
return assembler.assemble(statement, pc)

File diff suppressed because it is too large Load Diff