mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-01 11:29:32 +00:00
Add support for ASCII chars as immediate values
This commit is contained in:
parent
32a998abaf
commit
23bd9b9a39
@ -55,6 +55,7 @@ class Assembler:
|
||||
match = pattern.match(operand)
|
||||
|
||||
if match:
|
||||
# check if opcode supports this addressing mode
|
||||
try:
|
||||
bytes = [self._mpu.disassemble.index((opcode, mode))]
|
||||
except ValueError:
|
||||
@ -98,9 +99,16 @@ class Assembler:
|
||||
if match:
|
||||
before, target, after = match.groups()
|
||||
|
||||
# target is an immediate number
|
||||
# target is an immediate value
|
||||
if target.startswith('#'):
|
||||
number = self._address_parser.number(target[1:])
|
||||
if target[1] in ("'", '"'): # quoted ascii character
|
||||
try:
|
||||
number = ord(target[2])
|
||||
except IndexError:
|
||||
raise SyntaxError(statement)
|
||||
else:
|
||||
number = self._address_parser.number(target[1:])
|
||||
|
||||
if (number < 0x00) or (number > self._mpu.byteMask):
|
||||
raise OverflowError
|
||||
statement = before + '#$' + self._mpu.BYTE_FORMAT % number
|
||||
|
@ -22,6 +22,8 @@ class AssemblerTests(unittest.TestCase):
|
||||
def test_assemble_bad_syntax_raises_syntaxerror(self):
|
||||
self.assertRaises(SyntaxError,
|
||||
self.assemble, 'foo')
|
||||
self.assertRaises(SyntaxError,
|
||||
self.assemble, 'lda #"')
|
||||
|
||||
def test_assemble_bad_label_raises_keyerror(self):
|
||||
self.assertRaises(KeyError,
|
||||
@ -820,6 +822,12 @@ class AssemblerTests(unittest.TestCase):
|
||||
self.assertEqual([0xa9, 0x44],
|
||||
self.assemble('LDA #$44'))
|
||||
|
||||
def test_assembles_a9_ascii(self):
|
||||
self.assertEqual([0xa9, 0x48],
|
||||
self.assemble("LDA #'H"))
|
||||
self.assertEqual([0xa9, 0x49],
|
||||
self.assemble('LDA #"I'))
|
||||
|
||||
def test_assembles_aa(self):
|
||||
self.assertEqual([0xaa],
|
||||
self.assemble('TAX'))
|
||||
|
Loading…
Reference in New Issue
Block a user