mirror of
https://github.com/jtauber/applepy.git
synced 2024-12-26 12:29:18 +00:00
rename --ui switch to --bus
This commit is contained in:
parent
dcc8e9d8ce
commit
15e174c02a
@ -365,7 +365,7 @@ class Apple2:
|
||||
args = [
|
||||
sys.executable,
|
||||
"cpu6502.py",
|
||||
"--ui", str(listener.getsockname()[1]),
|
||||
"--bus", str(listener.getsockname()[1]),
|
||||
"--rom", options.rom,
|
||||
]
|
||||
if options.ram:
|
||||
|
@ -64,7 +64,7 @@ def run(win):
|
||||
args = [
|
||||
sys.executable,
|
||||
"cpu6502.py",
|
||||
"--ui", str(listener.getsockname()[1]),
|
||||
"--bus", str(listener.getsockname()[1]),
|
||||
"--rom", options.rom,
|
||||
]
|
||||
|
||||
|
40
cpu6502.py
40
cpu6502.py
@ -8,7 +8,7 @@ import struct
|
||||
import sys
|
||||
|
||||
|
||||
ui = None
|
||||
bus = None # socket for bus I/O
|
||||
|
||||
|
||||
def signed(x):
|
||||
@ -46,8 +46,8 @@ class RAM(ROM):
|
||||
|
||||
class Memory:
|
||||
|
||||
def __init__(self, options=None, use_stdio=True):
|
||||
self.use_stdio = use_stdio
|
||||
def __init__(self, options=None, use_bus=True):
|
||||
self.use_bus = use_bus
|
||||
self.rom = ROM(0xD000, 0x3000)
|
||||
|
||||
if options:
|
||||
@ -86,12 +86,12 @@ class Memory:
|
||||
self.bus_write(cycle, address, value)
|
||||
|
||||
def bus_read(self, cycle, address):
|
||||
if not self.use_stdio:
|
||||
if not self.use_bus:
|
||||
return 0
|
||||
op = struct.pack("<IBHB", cycle, 0, address, 0)
|
||||
try:
|
||||
ui.send(op)
|
||||
b = ui.recv(1)
|
||||
bus.send(op)
|
||||
b = bus.recv(1)
|
||||
if len(b) == 0:
|
||||
sys.exit(0)
|
||||
return ord(b)
|
||||
@ -99,11 +99,11 @@ class Memory:
|
||||
sys.exit(0)
|
||||
|
||||
def bus_write(self, cycle, address, value):
|
||||
if not self.use_stdio:
|
||||
if not self.use_bus:
|
||||
return
|
||||
op = struct.pack("<IBHB", cycle, 1, address, value)
|
||||
try:
|
||||
ui.send(op)
|
||||
bus.send(op)
|
||||
except IOError:
|
||||
sys.exit(0)
|
||||
|
||||
@ -511,10 +511,10 @@ class CPU:
|
||||
def reset(self):
|
||||
self.program_counter = self.read_word(self.RESET_VECTOR)
|
||||
|
||||
def run(self, uisocket):
|
||||
global ui
|
||||
ui = socket.socket()
|
||||
ui.connect(("127.0.0.1", uisocket))
|
||||
def run(self, bus_port):
|
||||
global bus
|
||||
bus = socket.socket()
|
||||
bus.connect(("127.0.0.1", bus_port))
|
||||
while True:
|
||||
self.cycles += 2 # all instructions take this as a minimum
|
||||
op = self.read_pc_byte()
|
||||
@ -978,9 +978,9 @@ def usage():
|
||||
print >>sys.stderr
|
||||
print >>sys.stderr, "Usage: cpu6502.py [options]"
|
||||
print >>sys.stderr
|
||||
print >>sys.stderr, " -b, --bus Bus port number"
|
||||
print >>sys.stderr, " -R, --rom ROM file to use (default A2ROM.BIN)"
|
||||
print >>sys.stderr, " -r, --ram RAM file to load (default none)"
|
||||
print >>sys.stderr, " -u, --ui UI socket"
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@ -989,21 +989,21 @@ def get_options():
|
||||
def __init__(self):
|
||||
self.rom = "A2ROM.BIN"
|
||||
self.ram = None
|
||||
self.ui = None
|
||||
self.bus = None
|
||||
|
||||
options = Options()
|
||||
a = 1
|
||||
while a < len(sys.argv):
|
||||
if sys.argv[a].startswith("-"):
|
||||
if sys.argv[a] in ("-R", "--rom"):
|
||||
if sys.argv[a] in ("-b", "--bus"):
|
||||
a += 1
|
||||
options.bus = int(sys.argv[a])
|
||||
elif sys.argv[a] in ("-R", "--rom"):
|
||||
a += 1
|
||||
options.rom = sys.argv[a]
|
||||
elif sys.argv[a] in ("-r", "--ram"):
|
||||
a += 1
|
||||
options.ram = sys.argv[a]
|
||||
elif sys.argv[a] in ("-u", "--ui"):
|
||||
a += 1
|
||||
options.ui = int(sys.argv[a])
|
||||
else:
|
||||
usage()
|
||||
else:
|
||||
@ -1015,7 +1015,7 @@ def get_options():
|
||||
|
||||
if __name__ == "__main__":
|
||||
options = get_options()
|
||||
if options.ui is None:
|
||||
if options.bus is None:
|
||||
print "ApplePy cpu core"
|
||||
print "Run applepy.py instead"
|
||||
sys.exit(0)
|
||||
@ -1023,4 +1023,4 @@ if __name__ == "__main__":
|
||||
mem = Memory(options)
|
||||
|
||||
cpu = CPU(mem)
|
||||
cpu.run(options.ui)
|
||||
cpu.run(options.bus)
|
||||
|
26
tests.py
26
tests.py
@ -5,7 +5,7 @@ from cpu6502 import Memory, CPU
|
||||
class TestMemory(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
|
||||
def test_load(self):
|
||||
self.memory.load(0x1000, [0x01, 0x02, 0x03])
|
||||
@ -25,7 +25,7 @@ class TestMemory(unittest.TestCase):
|
||||
class TestLoadStoreOperations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=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(use_stdio=False)
|
||||
self.memory = Memory(use_bus=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(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_TSX(self):
|
||||
@ -237,7 +237,7 @@ class TestStackOperations(unittest.TestCase):
|
||||
class TestLogicalOperations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_AND(self):
|
||||
@ -325,7 +325,7 @@ class TestLogicalOperations(unittest.TestCase):
|
||||
class TestArithmeticOperations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_ADC_without_BCD(self):
|
||||
@ -544,7 +544,7 @@ class TestArithmeticOperations(unittest.TestCase):
|
||||
class TestIncrementDecrementOperations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_INC(self):
|
||||
@ -653,7 +653,7 @@ class TestIncrementDecrementOperations(unittest.TestCase):
|
||||
class TestShiftOperations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_ASL(self):
|
||||
@ -760,7 +760,7 @@ class TestShiftOperations(unittest.TestCase):
|
||||
class TestJumpCallOperations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_JMP(self):
|
||||
@ -792,7 +792,7 @@ class TestJumpCallOperations(unittest.TestCase):
|
||||
class TestBranchOperations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=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(use_stdio=False)
|
||||
self.memory = Memory(use_bus=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(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_BRK(self):
|
||||
@ -951,7 +951,7 @@ class TestSystemFunctionOperations(unittest.TestCase):
|
||||
class Test6502Bugs(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.memory = Memory(use_stdio=False)
|
||||
self.memory = Memory(use_bus=False)
|
||||
self.cpu = CPU(self.memory)
|
||||
|
||||
def test_zero_page_x(self):
|
||||
|
Loading…
Reference in New Issue
Block a user