1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-13 22:29:30 +00:00

Raise OverflowError if assembling exceeds the top of memory

This commit is contained in:
Mike Naberezny 2012-11-25 11:07:12 -08:00
parent 5a47382f7d
commit b2148d72c6
3 changed files with 19 additions and 0 deletions

View File

@ -15,6 +15,9 @@
- Added support for 65C02 opcode 0x7C: JMP (abs,x).
- Assembling now shows an Overflow Error if the statement won't
fit at the top of memory.
0.13 (2012-11-15)
- Fixed a bug where negative numbers could be entered

View File

@ -130,6 +130,11 @@ class Assembler:
operands = [int(hex, 16) for hex in operands]
bytes.extend(operands)
# raise if the assembled bytes would exceed top of memory
if (pc + len(bytes)) > (2 ** self._mpu.ADDR_WIDTH):
raise OverflowError
return bytes
# assembly failed

View File

@ -19,6 +19,17 @@ class AssemblerTests(unittest.TestCase):
self.assertRaises(OverflowError,
self.assemble, 'lda #$fff')
def test_assemble_1_byte_at_top_of_mem_should_not_overflow(self):
self.assemble('nop', pc=0xFFFF) # should not raise
def test_assemble_3_bytes_at_top_of_mem_should_not_overflow(self):
self.assemble('jmp $1234', pc=0xFFFD) # should not raise
def test_assemble_should_overflow_if_over_top_of_mem(self):
# jmp $1234 requires 3 bytes but there's only 2 at $FFFE-FFFF
self.assertRaises(OverflowError,
self.assemble, "jmp $1234", pc=0xFFFE)
def test_assembles_00(self):
self.assertEqual([0x00],
self.assemble('BRK'))