Separate CPU core and UI processes

This is a first step toward separating the CPU core and UI.  The UI program
starts the CPU core as a subprocess and communicates through its standard input
and output. The protocol is deliberately simple at this point. Each bus request
from the core is exactly eight bytes:

    +-------------------------+
    | cpu cycle counter high  |
    +-------------------------+
    | cpu cycle counter       |
    +-------------------------+
    | cpu cycle counter       |
    +-------------------------+
    | cpu cycle counter low   |
    +-------------------------+
    | 0x00=read / 0x01=write  |
    +-------------------------+
    | address high            |
    +-------------------------+
    | address low             |
    +-------------------------+
    | value (unused for read) |
    +-------------------------+

A single-byte response from the UI is required for a read request, and a
response must not be sent for a write request.

The above protocol is expected to change. For example:

    - the UI should tell the CPU core which address ranges are of interest
    - needs ability to send memory images to the core (both ROM and RAM)

The stream communications is currently buggy because it expects that all eight
bytes will be read when requested (that is, partial reads are not handled). In
practice, this seems to work okay for the moment.

To improve portability, it may be better to communicate over TCP sockets
instead of stdin/stdout.
This commit is contained in:
Greg Hewgill 2011-08-14 10:29:42 +12:00
parent 7c657a8dd8
commit c9c609be1d
5 changed files with 1213 additions and 1006 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

File diff suppressed because it is too large Load Diff

91
applepy_curses.py Normal file
View File

@ -0,0 +1,91 @@
# ApplePy - an Apple ][ emulator in Python
# James Tauber / http://jtauber.com/
# originally written 2001, updated 2011
import curses
import struct
import subprocess
import sys
kbd = 0
def write_screen(win, address, value):
base = address - 0x400
hi, lo = divmod(base, 0x80)
row_group, column = divmod(lo, 0x28)
row = hi + 8 * row_group
# skip if writing to row group 3
if row_group == 3:
return
c = chr(0x20 + ((value + 0x20) % 0x40))
if value < 0x40:
attr = curses.A_DIM
elif value < 0x80:
attr = curses.A_REVERSE
elif value < 0xA0:
attr = curses.A_UNDERLINE
else:
attr = curses.A_DIM
try:
win.addch(row, column, c, attr)
except curses.error:
pass
def read(addr, val):
global kbd
if addr == 0xC000:
return kbd
elif addr == 0xC010:
kbd = kbd & 0x7F
return 0x00
def write(win, addr, val):
if 0x400 <= addr <= 0x800:
write_screen(win, addr, val)
def run(win):
global kbd
p = subprocess.Popen(
args=[sys.executable, "cpu6502.py"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
win.clear()
curses.noecho()
win.nodelay(True)
while True:
op = p.stdout.read(8)
cycle, rw, addr, val = struct.unpack("<IBHB", op)
if rw == 0:
p.stdin.write(chr(read(addr, val)))
p.stdin.flush()
elif rw == 1:
write(win, addr, val)
else:
break
try:
key = ord(win.getkey())
if key == 0xA:
key = 0xD
elif key == 0x7F:
key = 0x8
# win.addstr(15, 50, hex(key))
kbd = 0x80 | key
except curses.error:
pass
except TypeError:
pass
if __name__ == "__main__":
curses.wrapper(run)

1016
cpu6502.py Normal file

File diff suppressed because it is too large Load Diff

136
tests.py
View File

@ -1,11 +1,11 @@
import unittest
from applepy import Memory, CPU
from cpu6502 import Memory, CPU
class TestMemory(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
def test_load(self):
self.memory.load(0x1000, [0x01, 0x02, 0x03])
@ -14,9 +14,9 @@ class TestMemory(unittest.TestCase):
self.assertEqual(self.memory.read_byte(None, 0x1002), 0x03)
def test_write(self):
self.memory.write_byte(0x1000, 0x11)
self.memory.write_byte(0x1001, 0x12)
self.memory.write_byte(0x1002, 0x13)
self.memory.write_byte(None, 0x1000, 0x11)
self.memory.write_byte(None, 0x1001, 0x12)
self.memory.write_byte(None, 0x1002, 0x13)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x11)
self.assertEqual(self.memory.read_byte(None, 0x1001), 0x12)
self.assertEqual(self.memory.read_byte(None, 0x1002), 0x13)
@ -25,7 +25,7 @@ class TestMemory(unittest.TestCase):
class TestLoadStoreOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
self.memory.load(0x1000, [0x00, 0x01, 0x7F, 0x80, 0xFF])
@ -114,7 +114,7 @@ class TestLoadStoreOperations(unittest.TestCase):
class TestRegisterTransferOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_TAX(self):
@ -189,7 +189,7 @@ class TestRegisterTransferOperations(unittest.TestCase):
class TestStackOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_TSX(self):
@ -237,11 +237,11 @@ class TestStackOperations(unittest.TestCase):
class TestLogicalOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_AND(self):
self.memory.write_byte(0x1000, 0x37)
self.memory.write_byte(None, 0x1000, 0x37)
self.cpu.accumulator = 0x34
self.cpu.AND(0x1000)
self.assertEqual(self.cpu.accumulator, 0x34)
@ -254,7 +254,7 @@ class TestLogicalOperations(unittest.TestCase):
self.assertEqual(self.cpu.sign_flag, 0)
def test_EOR(self):
self.memory.write_byte(0x1000, 0x37)
self.memory.write_byte(None, 0x1000, 0x37)
self.cpu.accumulator = 0x34
self.cpu.EOR(0x1000)
self.assertEqual(self.cpu.accumulator, 0x03)
@ -272,7 +272,7 @@ class TestLogicalOperations(unittest.TestCase):
self.assertEqual(self.cpu.sign_flag, 0)
def test_ORA(self):
self.memory.write_byte(0x1000, 0x37)
self.memory.write_byte(None, 0x1000, 0x37)
self.cpu.accumulator = 0x34
self.cpu.ORA(0x1000)
self.assertEqual(self.cpu.accumulator, 0x37)
@ -290,31 +290,31 @@ class TestLogicalOperations(unittest.TestCase):
self.assertEqual(self.cpu.sign_flag, 0)
def test_BIT(self):
self.memory.write_byte(0x1000, 0x00)
self.memory.write_byte(None, 0x1000, 0x00)
self.cpu.accumulator = 0x00
self.cpu.BIT(0x1000)
self.assertEqual(self.cpu.overflow_flag, 0)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1)
self.memory.write_byte(0x1000, 0x40)
self.memory.write_byte(None, 0x1000, 0x40)
self.cpu.accumulator = 0x00
self.cpu.BIT(0x1000)
self.assertEqual(self.cpu.overflow_flag, 1)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1)
self.memory.write_byte(0x1000, 0x80)
self.memory.write_byte(None, 0x1000, 0x80)
self.cpu.accumulator = 0x00
self.cpu.BIT(0x1000)
self.assertEqual(self.cpu.overflow_flag, 0)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 1)
self.memory.write_byte(0x1000, 0xC0)
self.memory.write_byte(None, 0x1000, 0xC0)
self.cpu.accumulator = 0x00
self.cpu.BIT(0x1000)
self.assertEqual(self.cpu.overflow_flag, 1)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 1)
self.memory.write_byte(0x1000, 0xC0)
self.memory.write_byte(None, 0x1000, 0xC0)
self.cpu.accumulator = 0xC0
self.cpu.BIT(0x1000)
self.assertEqual(self.cpu.overflow_flag, 1)
@ -325,7 +325,7 @@ class TestLogicalOperations(unittest.TestCase):
class TestArithmeticOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_ADC_without_BCD(self):
@ -335,7 +335,7 @@ class TestArithmeticOperations(unittest.TestCase):
# 1 + 1 = 2 (C = 0; V = 0)
self.cpu.carry_flag = 0
self.cpu.accumulator = 0x01
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.ADC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x02)
self.assertEqual(self.cpu.carry_flag, 0)
@ -344,7 +344,7 @@ class TestArithmeticOperations(unittest.TestCase):
# 1 + -1 = 0 (C = 1; V = 0)
self.cpu.carry_flag = 0
self.cpu.accumulator = 0x01
self.memory.write_byte(0x1000, 0xFF)
self.memory.write_byte(None, 0x1000, 0xFF)
self.cpu.ADC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x00)
self.assertEqual(self.cpu.carry_flag, 1)
@ -353,7 +353,7 @@ class TestArithmeticOperations(unittest.TestCase):
# 127 + 1 = 128 (C = 0; V = 1)
self.cpu.carry_flag = 0
self.cpu.accumulator = 0x7F
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.ADC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x80) # @@@
self.assertEqual(self.cpu.carry_flag, 0)
@ -362,7 +362,7 @@ class TestArithmeticOperations(unittest.TestCase):
# -128 + -1 = -129 (C = 1; V = 1)
self.cpu.carry_flag = 0
self.cpu.accumulator = 0x80
self.memory.write_byte(0x1000, 0xFF)
self.memory.write_byte(None, 0x1000, 0xFF)
self.cpu.ADC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x7F) # @@@
self.assertEqual(self.cpu.carry_flag, 1)
@ -371,7 +371,7 @@ class TestArithmeticOperations(unittest.TestCase):
# 63 + 64 + 1 = 128 (C = 0; V = 1)
self.cpu.carry_flag = 1
self.cpu.accumulator = 0x3F
self.memory.write_byte(0x1000, 0x40)
self.memory.write_byte(None, 0x1000, 0x40)
self.cpu.ADC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x80)
self.assertEqual(self.cpu.carry_flag, 0)
@ -379,14 +379,14 @@ class TestArithmeticOperations(unittest.TestCase):
def test_SBC_without_BCD(self):
self.cpu.accumulator = 0x02
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.SBC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x00)
self.assertEqual(self.cpu.carry_flag, 1)
self.assertEqual(self.cpu.overflow_flag, 0)
self.cpu.accumulator = 0x01
self.memory.write_byte(0x1000, 0x02)
self.memory.write_byte(None, 0x1000, 0x02)
self.cpu.SBC(0x1000)
self.assertEqual(self.cpu.accumulator, 0xFF)
self.assertEqual(self.cpu.carry_flag, 0)
@ -397,7 +397,7 @@ class TestArithmeticOperations(unittest.TestCase):
# 0 - 1 = -1 (V = 0)
self.cpu.carry_flag = 1
self.cpu.accumulator = 0x00
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.SBC(0x1000)
self.assertEqual(self.cpu.accumulator, 0xFF)
self.assertEqual(self.cpu.carry_flag, 0)
@ -406,7 +406,7 @@ class TestArithmeticOperations(unittest.TestCase):
# -128 - 1 = -129 (V = 1)
self.cpu.carry_flag = 1
self.cpu.accumulator = 0x80
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.SBC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x7F)
self.assertEqual(self.cpu.carry_flag, 1)
@ -415,7 +415,7 @@ class TestArithmeticOperations(unittest.TestCase):
# 127 - -1 = 128 (V = 1)
self.cpu.carry_flag = 1
self.cpu.accumulator = 0x7F
self.memory.write_byte(0x1000, 0xFF)
self.memory.write_byte(None, 0x1000, 0xFF)
self.cpu.SBC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x80)
self.assertEqual(self.cpu.carry_flag, 0)
@ -424,7 +424,7 @@ class TestArithmeticOperations(unittest.TestCase):
# -64 -64 -1 = -129 (V = 1)
self.cpu.carry_flag = 0
self.cpu.accumulator = 0xC0
self.memory.write_byte(0x1000, 0x40)
self.memory.write_byte(None, 0x1000, 0x40)
self.cpu.SBC(0x1000)
self.assertEqual(self.cpu.accumulator, 0x7F)
self.assertEqual(self.cpu.carry_flag, 1)
@ -434,35 +434,35 @@ class TestArithmeticOperations(unittest.TestCase):
def test_CMP(self):
self.cpu.accumulator = 0x0A
self.memory.write_byte(0x1000, 0x09)
self.memory.write_byte(None, 0x1000, 0x09)
self.cpu.CMP(0x1000)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.accumulator = 0x0A
self.memory.write_byte(0x1000, 0x0B)
self.memory.write_byte(None, 0x1000, 0x0B)
self.cpu.CMP(0x1000)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 0)
self.cpu.accumulator = 0x0A
self.memory.write_byte(0x1000, 0x0A)
self.memory.write_byte(None, 0x1000, 0x0A)
self.cpu.CMP(0x1000)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.accumulator = 0xA0
self.memory.write_byte(0x1000, 0x0A)
self.memory.write_byte(None, 0x1000, 0x0A)
self.cpu.CMP(0x1000)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.accumulator = 0x0A
self.memory.write_byte(0x1000, 0xA0)
self.memory.write_byte(None, 0x1000, 0xA0)
self.cpu.CMP(0x1000)
self.assertEqual(self.cpu.sign_flag, 0) # @@@
self.assertEqual(self.cpu.zero_flag, 0)
@ -470,35 +470,35 @@ class TestArithmeticOperations(unittest.TestCase):
def test_CPX(self):
self.cpu.x_index = 0x0A
self.memory.write_byte(0x1000, 0x09)
self.memory.write_byte(None, 0x1000, 0x09)
self.cpu.CPX(0x1000)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.x_index = 0x0A
self.memory.write_byte(0x1000, 0x0B)
self.memory.write_byte(None, 0x1000, 0x0B)
self.cpu.CPX(0x1000)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 0)
self.cpu.x_index = 0x0A
self.memory.write_byte(0x1000, 0x0A)
self.memory.write_byte(None, 0x1000, 0x0A)
self.cpu.CPX(0x1000)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.x_index = 0xA0
self.memory.write_byte(0x1000, 0x0A)
self.memory.write_byte(None, 0x1000, 0x0A)
self.cpu.CPX(0x1000)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.x_index = 0x0A
self.memory.write_byte(0x1000, 0xA0)
self.memory.write_byte(None, 0x1000, 0xA0)
self.cpu.CPX(0x1000)
self.assertEqual(self.cpu.sign_flag, 0) # @@@
self.assertEqual(self.cpu.zero_flag, 0)
@ -506,35 +506,35 @@ class TestArithmeticOperations(unittest.TestCase):
def test_CPY(self):
self.cpu.y_index = 0x0A
self.memory.write_byte(0x1000, 0x09)
self.memory.write_byte(None, 0x1000, 0x09)
self.cpu.CPY(0x1000)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.y_index = 0x0A
self.memory.write_byte(0x1000, 0x0B)
self.memory.write_byte(None, 0x1000, 0x0B)
self.cpu.CPY(0x1000)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 0)
self.cpu.y_index = 0x0A
self.memory.write_byte(0x1000, 0x0A)
self.memory.write_byte(None, 0x1000, 0x0A)
self.cpu.CPY(0x1000)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.y_index = 0xA0
self.memory.write_byte(0x1000, 0x0A)
self.memory.write_byte(None, 0x1000, 0x0A)
self.cpu.CPY(0x1000)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.y_index = 0x0A
self.memory.write_byte(0x1000, 0xA0)
self.memory.write_byte(None, 0x1000, 0xA0)
self.cpu.CPY(0x1000)
self.assertEqual(self.cpu.sign_flag, 0) # @@@
self.assertEqual(self.cpu.zero_flag, 0)
@ -544,21 +544,21 @@ class TestArithmeticOperations(unittest.TestCase):
class TestIncrementDecrementOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_INC(self):
self.memory.write_byte(0x1000, 0x00)
self.memory.write_byte(None, 0x1000, 0x00)
self.cpu.INC(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x01)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 0)
self.memory.write_byte(0x1000, 0x7F)
self.memory.write_byte(None, 0x1000, 0x7F)
self.cpu.INC(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x80)
self.assertEqual(self.cpu.sign_flag, 1)
self.assertEqual(self.cpu.zero_flag, 0)
self.memory.write_byte(0x1000, 0xFF)
self.memory.write_byte(None, 0x1000, 0xFF)
self.cpu.INC(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
self.assertEqual(self.cpu.sign_flag, 0)
@ -599,17 +599,17 @@ class TestIncrementDecrementOperations(unittest.TestCase):
self.assertEqual(self.cpu.zero_flag, 1)
def test_DEC(self):
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.DEC(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1)
self.memory.write_byte(0x1000, 0x80)
self.memory.write_byte(None, 0x1000, 0x80)
self.cpu.DEC(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x7F)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 0)
self.memory.write_byte(0x1000, 0x00)
self.memory.write_byte(None, 0x1000, 0x00)
self.cpu.DEC(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0xFF)
self.assertEqual(self.cpu.sign_flag, 1)
@ -653,7 +653,7 @@ class TestIncrementDecrementOperations(unittest.TestCase):
class TestShiftOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_ASL(self):
@ -663,7 +663,7 @@ class TestShiftOperations(unittest.TestCase):
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 0)
self.assertEqual(self.cpu.carry_flag, 0)
self.memory.write_byte(0x1000, 0x02)
self.memory.write_byte(None, 0x1000, 0x02)
self.cpu.ASL(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x04)
self.assertEqual(self.cpu.sign_flag, 0)
@ -683,7 +683,7 @@ class TestShiftOperations(unittest.TestCase):
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1)
self.assertEqual(self.cpu.carry_flag, 1)
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.LSR(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
self.assertEqual(self.cpu.sign_flag, 0)
@ -712,14 +712,14 @@ class TestShiftOperations(unittest.TestCase):
self.assertEqual(self.cpu.zero_flag, 0) # @@@
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.carry_flag = 0
self.memory.write_byte(0x1000, 0x80)
self.memory.write_byte(None, 0x1000, 0x80)
self.cpu.ROL(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1) # @@@
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.carry_flag = 1
self.memory.write_byte(0x1000, 0x80)
self.memory.write_byte(None, 0x1000, 0x80)
self.cpu.ROL(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x01)
self.assertEqual(self.cpu.sign_flag, 0)
@ -742,14 +742,14 @@ class TestShiftOperations(unittest.TestCase):
self.assertEqual(self.cpu.zero_flag, 0) # @@@
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.carry_flag = 0
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.ROR(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
self.assertEqual(self.cpu.sign_flag, 0)
self.assertEqual(self.cpu.zero_flag, 1) # @@@
self.assertEqual(self.cpu.carry_flag, 1)
self.cpu.carry_flag = 1
self.memory.write_byte(0x1000, 0x01)
self.memory.write_byte(None, 0x1000, 0x01)
self.cpu.ROR(0x1000)
self.assertEqual(self.memory.read_byte(None, 0x1000), 0x80)
self.assertEqual(self.cpu.sign_flag, 1) # @@@
@ -760,7 +760,7 @@ class TestShiftOperations(unittest.TestCase):
class TestJumpCallOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_JMP(self):
@ -775,8 +775,8 @@ class TestJumpCallOperations(unittest.TestCase):
self.assertEqual(self.memory.read_byte(None, self.cpu.STACK_PAGE + self.cpu.stack_pointer + 2), 0x0F)
def test_RTS(self):
self.memory.write_byte(self.cpu.STACK_PAGE + 0xFF, 0x12)
self.memory.write_byte(self.cpu.STACK_PAGE + 0xFE, 0x33)
self.memory.write_byte(None, self.cpu.STACK_PAGE + 0xFF, 0x12)
self.memory.write_byte(None, self.cpu.STACK_PAGE + 0xFE, 0x33)
self.cpu.stack_pointer = 0xFD
self.cpu.RTS()
self.assertEqual(self.cpu.program_counter, 0x1234)
@ -792,7 +792,7 @@ class TestJumpCallOperations(unittest.TestCase):
class TestBranchOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_BCC(self):
@ -879,7 +879,7 @@ class TestBranchOperations(unittest.TestCase):
class TestStatusFlagOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_CLC(self):
@ -921,7 +921,7 @@ class TestStatusFlagOperations(unittest.TestCase):
class TestSystemFunctionOperations(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_BRK(self):
@ -936,9 +936,9 @@ class TestSystemFunctionOperations(unittest.TestCase):
self.assertEqual(self.memory.read_byte(None, self.cpu.STACK_PAGE + self.cpu.stack_pointer + 3), 0x10)
def test_RTI(self):
self.memory.write_byte(self.cpu.STACK_PAGE + 0xFF, 0x12)
self.memory.write_byte(self.cpu.STACK_PAGE + 0xFE, 0x33)
self.memory.write_byte(self.cpu.STACK_PAGE + 0xFD, 0x20)
self.memory.write_byte(None, self.cpu.STACK_PAGE + 0xFF, 0x12)
self.memory.write_byte(None, self.cpu.STACK_PAGE + 0xFE, 0x33)
self.memory.write_byte(None, self.cpu.STACK_PAGE + 0xFD, 0x20)
self.cpu.stack_pointer = 0xFC
self.cpu.RTI()
self.assertEqual(self.cpu.program_counter, 0x1233)
@ -951,7 +951,7 @@ class TestSystemFunctionOperations(unittest.TestCase):
class Test6502Bugs(unittest.TestCase):
def setUp(self):
self.memory = Memory()
self.memory = Memory(use_stdio=False)
self.cpu = CPU(self.memory)
def test_zero_page_x(self):