mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-04 01:30:18 +00:00
Raise OverflowError if assembling exceeds the top of memory
This commit is contained in:
parent
5a47382f7d
commit
b2148d72c6
@ -15,6 +15,9 @@
|
|||||||
|
|
||||||
- Added support for 65C02 opcode 0x7C: JMP (abs,x).
|
- 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)
|
0.13 (2012-11-15)
|
||||||
|
|
||||||
- Fixed a bug where negative numbers could be entered
|
- Fixed a bug where negative numbers could be entered
|
||||||
|
@ -130,6 +130,11 @@ class Assembler:
|
|||||||
|
|
||||||
operands = [int(hex, 16) for hex in operands]
|
operands = [int(hex, 16) for hex in operands]
|
||||||
bytes.extend(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
|
return bytes
|
||||||
|
|
||||||
# assembly failed
|
# assembly failed
|
||||||
|
@ -19,6 +19,17 @@ class AssemblerTests(unittest.TestCase):
|
|||||||
self.assertRaises(OverflowError,
|
self.assertRaises(OverflowError,
|
||||||
self.assemble, 'lda #$fff')
|
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):
|
def test_assembles_00(self):
|
||||||
self.assertEqual([0x00],
|
self.assertEqual([0x00],
|
||||||
self.assemble('BRK'))
|
self.assemble('BRK'))
|
||||||
|
Loading…
Reference in New Issue
Block a user