mirror of
https://github.com/jtauber/applepy.git
synced 2024-12-29 15:29:16 +00:00
got tests working again after memory refactor
This commit is contained in:
parent
02714dff55
commit
2e34927e7c
10
applepy.py
10
applepy.py
@ -18,6 +18,10 @@ class RAM:
|
|||||||
self.end = start + size - 1
|
self.end = start + size - 1
|
||||||
self.__mem = [0x00] * size
|
self.__mem = [0x00] * size
|
||||||
|
|
||||||
|
def load(self, address, data):
|
||||||
|
for offset, datum in enumerate(data):
|
||||||
|
self.__mem[address - self.start + offset] = datum
|
||||||
|
|
||||||
def read_byte(self, address):
|
def read_byte(self, address):
|
||||||
assert self.start <= address <= self.end
|
assert self.start <= address <= self.end
|
||||||
return self.__mem[address - self.start]
|
return self.__mem[address - self.start]
|
||||||
@ -71,7 +75,11 @@ class Memory:
|
|||||||
|
|
||||||
self.ram = RAM(0x0000, 0xC000)
|
self.ram = RAM(0x0000, 0xC000)
|
||||||
self.softswitches = SoftSwitches()
|
self.softswitches = SoftSwitches()
|
||||||
|
|
||||||
|
def load(self, address, data):
|
||||||
|
if address < 0xC000:
|
||||||
|
self.ram.load(address, data)
|
||||||
|
|
||||||
def read_byte(self, address):
|
def read_byte(self, address):
|
||||||
if address < 0xC000:
|
if address < 0xC000:
|
||||||
return self.ram.read_byte(address)
|
return self.ram.read_byte(address)
|
||||||
|
29
tests.py
29
tests.py
@ -5,7 +5,7 @@ from applepy import Memory, CPU
|
|||||||
class TestMemory(unittest.TestCase):
|
class TestMemory(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
|
|
||||||
def test_load(self):
|
def test_load(self):
|
||||||
self.memory.load(0x1000, [0x01, 0x02, 0x03])
|
self.memory.load(0x1000, [0x01, 0x02, 0x03])
|
||||||
@ -25,7 +25,7 @@ class TestMemory(unittest.TestCase):
|
|||||||
class TestLoadStoreOperations(unittest.TestCase):
|
class TestLoadStoreOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
self.memory.load(0x1000, [0x00, 0x01, 0x7F, 0x80, 0xFF])
|
self.memory.load(0x1000, [0x00, 0x01, 0x7F, 0x80, 0xFF])
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class TestLoadStoreOperations(unittest.TestCase):
|
|||||||
class TestRegisterTransferOperations(unittest.TestCase):
|
class TestRegisterTransferOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_TAX(self):
|
def test_TAX(self):
|
||||||
@ -189,7 +189,7 @@ class TestRegisterTransferOperations(unittest.TestCase):
|
|||||||
class TestStackOperations(unittest.TestCase):
|
class TestStackOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_TSX(self):
|
def test_TSX(self):
|
||||||
@ -237,7 +237,7 @@ class TestStackOperations(unittest.TestCase):
|
|||||||
class TestLogicalOperations(unittest.TestCase):
|
class TestLogicalOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_AND(self):
|
def test_AND(self):
|
||||||
@ -325,7 +325,7 @@ class TestLogicalOperations(unittest.TestCase):
|
|||||||
class TestArithmeticOperations(unittest.TestCase):
|
class TestArithmeticOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_ADC_without_BCD(self):
|
def test_ADC_without_BCD(self):
|
||||||
@ -544,7 +544,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
|||||||
class TestIncrementDecrementOperations(unittest.TestCase):
|
class TestIncrementDecrementOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_INC(self):
|
def test_INC(self):
|
||||||
@ -653,7 +653,7 @@ class TestIncrementDecrementOperations(unittest.TestCase):
|
|||||||
class TestShiftOperations(unittest.TestCase):
|
class TestShiftOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_ASL(self):
|
def test_ASL(self):
|
||||||
@ -760,7 +760,7 @@ class TestShiftOperations(unittest.TestCase):
|
|||||||
class TestJumpCallOperations(unittest.TestCase):
|
class TestJumpCallOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_JMP(self):
|
def test_JMP(self):
|
||||||
@ -792,7 +792,7 @@ class TestJumpCallOperations(unittest.TestCase):
|
|||||||
class TestBranchOperations(unittest.TestCase):
|
class TestBranchOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_BCC(self):
|
def test_BCC(self):
|
||||||
@ -879,7 +879,7 @@ class TestBranchOperations(unittest.TestCase):
|
|||||||
class TestStatusFlagOperations(unittest.TestCase):
|
class TestStatusFlagOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_CLC(self):
|
def test_CLC(self):
|
||||||
@ -921,13 +921,12 @@ class TestStatusFlagOperations(unittest.TestCase):
|
|||||||
class TestSystemFunctionOperations(unittest.TestCase):
|
class TestSystemFunctionOperations(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_BRK(self):
|
def test_BRK(self):
|
||||||
self.cpu.program_counter = 0x1000
|
self.cpu.program_counter = 0x1000
|
||||||
self.memory.write_byte(0xFFFE, 0x00)
|
self.memory.rom.load(0xFFFE, [0x00, 0x20])
|
||||||
self.memory.write_byte(0xFFFF, 0x20)
|
|
||||||
status = self.cpu.status_as_byte()
|
status = self.cpu.status_as_byte()
|
||||||
self.cpu.BRK()
|
self.cpu.BRK()
|
||||||
self.assertEqual(self.cpu.program_counter, 0x2000)
|
self.assertEqual(self.cpu.program_counter, 0x2000)
|
||||||
@ -952,7 +951,7 @@ class TestSystemFunctionOperations(unittest.TestCase):
|
|||||||
class Test6502Bugs(unittest.TestCase):
|
class Test6502Bugs(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.memory = Memory(0x10000)
|
self.memory = Memory()
|
||||||
self.cpu = CPU(self.memory)
|
self.cpu = CPU(self.memory)
|
||||||
|
|
||||||
def test_zero_page_x(self):
|
def test_zero_page_x(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user