mirror of
https://github.com/rzzzwilson/pymlac.git
synced 2025-06-10 09:32:41 +00:00
Finished (?) conversion to python3
This commit is contained in:
@@ -2,20 +2,21 @@
|
||||
# Simple make file just to clean this directory.
|
||||
# And run the test files.
|
||||
#
|
||||
PYTHON=python3
|
||||
|
||||
test:
|
||||
rm -f test.ptr test.ptp CPU.test.trace test_CPU.log pymlac.trace
|
||||
python test_CPU.py dumpmem.test
|
||||
$(PYTHON) test_CPU.py dumpmem.test
|
||||
./make_ptr > test.ptr
|
||||
python test_CPU.py CPU.test
|
||||
# #python test_Display.py # interactive!
|
||||
@echo "########## Run 'python test_Display.py' by hand! ##########"
|
||||
# #python test_KBD.py # interactive!
|
||||
@echo "########## Run 'python test_KBD.py' by hand! ##########"
|
||||
python test_Memory.py
|
||||
python test_PTR_PTP.py
|
||||
python test_TTYIN.py
|
||||
python test_TTYOUT.py
|
||||
$(PYTHON) test_CPU.py CPU.test
|
||||
# #$(PYTHON) test_Display.py # interactive!
|
||||
@echo "########## Run '$(PYTHON) test_Display.py' by hand! ##########"
|
||||
# #$(PYTHON) test_KBD.py # interactive!
|
||||
@echo "########## Run '$(PYTHON) test_KBD.py' by hand! ##########"
|
||||
$(PYTHON) test_Memory.py
|
||||
$(PYTHON) test_PTR_PTP.py
|
||||
$(PYTHON) test_TTYIN.py
|
||||
$(PYTHON) test_TTYOUT.py
|
||||
@echo "*********************"
|
||||
@echo "* Tests successful! *"
|
||||
@echo "*********************"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Emulate the imlac Paper Tape Reader/Punch (PTR/PTP).
|
||||
@@ -85,6 +86,7 @@ class PtrPtp(object):
|
||||
self.device_motor_on = False
|
||||
self.device_filename = fname
|
||||
self.device_open_file = open(self.device_filename, 'rb')
|
||||
print('Opening PTR file: %s' % fname)
|
||||
self.device_ready = False
|
||||
self.device_cycle_count = self.PtrNotReadyCycles
|
||||
self.ptr_at_eof = False
|
||||
@@ -184,7 +186,7 @@ class PtrPtp(object):
|
||||
self.device_ready = False
|
||||
self.device_cycle_count = self.PtrNotReadyCycles
|
||||
self.device_filename = fname
|
||||
self.device_open_file = open(self.device_filename, 'wb')
|
||||
self.device_open_file = open(self.device_filename, 'w')
|
||||
self.ptp_at_eof = False
|
||||
self.ptp_value = None
|
||||
|
||||
|
||||
@@ -152,7 +152,8 @@ class Trace(object):
|
||||
def comment(self, msg):
|
||||
"""Write a line to the trace file."""
|
||||
|
||||
self.tracefile.write(msg+'\n')
|
||||
msg = bytes(msg+'\n', 'utf-8')
|
||||
self.tracefile.write(msg)
|
||||
self.tracefile.flush()
|
||||
|
||||
def settrace(self, new_tracing):
|
||||
|
||||
@@ -83,7 +83,7 @@ class TestCPU(object):
|
||||
def show_progress(self):
|
||||
"""Show progress to stdout. A spinning line."""
|
||||
|
||||
print '%s\r' % self.ProgressChar[self.ProgressCount],
|
||||
print('%s\r' % self.ProgressChar[self.ProgressCount], end='')
|
||||
self.ProgressCount += 1
|
||||
if self.ProgressCount >= len(self.ProgressChar):
|
||||
self.ProgressCount = 0
|
||||
@@ -143,7 +143,7 @@ class TestCPU(object):
|
||||
opcodes = opcodes.split('|')
|
||||
|
||||
# create ASM file with instruction
|
||||
with open(self.AsmFilename+'.asm', 'wb') as fd:
|
||||
with open(self.AsmFilename+'.asm', 'w') as fd:
|
||||
fd.write('\torg\t%07o\n' % addr)
|
||||
for line in opcodes:
|
||||
fd.write('\t%s\n' % line)
|
||||
@@ -155,7 +155,7 @@ class TestCPU(object):
|
||||
res = os.system(cmd)
|
||||
|
||||
# read the listing file to get assembled opcode (second line)
|
||||
with open(self.AsmFilename+'.lst', 'rb') as fd:
|
||||
with open(self.AsmFilename+'.lst', 'r') as fd:
|
||||
lines = fd.readlines()
|
||||
|
||||
result = []
|
||||
@@ -493,7 +493,7 @@ class TestCPU(object):
|
||||
return "dumpmem: dump limits are bad: %s" % addresses
|
||||
|
||||
# create octdump-like text file with required memory locations
|
||||
with open(filename, 'wb') as handle:
|
||||
with open(filename, 'w') as handle:
|
||||
addr = begin
|
||||
offset = addr
|
||||
chunk = []
|
||||
@@ -521,7 +521,7 @@ class TestCPU(object):
|
||||
|
||||
# get file contents into memory
|
||||
try:
|
||||
with open(filename, 'rb') as handle:
|
||||
with open(filename, 'r') as handle:
|
||||
lines = handle.readlines()
|
||||
except IOError as e:
|
||||
return "Error opening file '%s': %s" % (filename, e.strerror)
|
||||
@@ -772,7 +772,7 @@ class TestCPU(object):
|
||||
def memdump(self, filename, start, number):
|
||||
"""Dump memory from 'start' into 'filename', 'number' words dumped."""
|
||||
|
||||
with open(filename, 'wb') as fd:
|
||||
with open(filename, 'w') as fd:
|
||||
for addr in range(start, start+number, 8):
|
||||
a = addr
|
||||
llen = min(8, start+number - addr)
|
||||
@@ -786,7 +786,7 @@ class TestCPU(object):
|
||||
"""Execute CPU tests from 'filename'."""
|
||||
|
||||
# get all tests from file
|
||||
with open(filename, 'rb') as fd:
|
||||
with open(filename, 'r') as fd:
|
||||
lines = fd.readlines()
|
||||
|
||||
# read lines, join continued, get complete tests
|
||||
|
||||
@@ -63,8 +63,8 @@ class TestMemory(unittest.TestCase):
|
||||
|
||||
# check various locations
|
||||
last_value = None
|
||||
for address in [0, 040] + range(0100, MEMORY_SIZE, 0100):
|
||||
for value in range(0, WORDMASK, 010):
|
||||
for address in [0, 0o40] + range(0o100, MEMORY_SIZE, 0o100):
|
||||
for value in range(0, WORDMASK, 0o10):
|
||||
memory.put(value=value, address=address, indirect=False)
|
||||
fetch_value = memory.fetch(address=address, indirect=False)
|
||||
msg = 'Fetch from %07o got %07o, expected %07o' % (address, fetch_value, value)
|
||||
@@ -72,7 +72,7 @@ class TestMemory(unittest.TestCase):
|
||||
last_value = fetch_value
|
||||
|
||||
# now check again that last value still in all those locations
|
||||
for address in [0, 040] + range(0100, MEMORY_SIZE, 0100):
|
||||
for address in [0, 0o40] + range(0o100, MEMORY_SIZE, 0o100):
|
||||
fetch_value = memory.fetch(address=address, indirect=False)
|
||||
msg = 'Fetch from %07o got %07o, expected %07o' % (address, fetch_value, last_value)
|
||||
self.assertTrue(last_value == fetch_value, msg)
|
||||
@@ -82,17 +82,17 @@ class TestMemory(unittest.TestCase):
|
||||
|
||||
memory = Memory.Memory(boot_rom=ROM_NONE)
|
||||
|
||||
expected = 0125252
|
||||
expected = 0o125252
|
||||
|
||||
# address 010 is target of all indirect fetches
|
||||
memory.put(value=expected, address=010, indirect=False)
|
||||
memory.put(value=expected, address=0o10, indirect=False)
|
||||
|
||||
# fill all test addresses with pointer to address 010
|
||||
for address in range(0, MEMORY_SIZE, 0100):
|
||||
memory.put(value=010, address=address, indirect=False)
|
||||
for address in range(0, MEMORY_SIZE, 0o100):
|
||||
memory.put(value=0o10, address=address, indirect=False)
|
||||
|
||||
# now check that fetch through all those addresses gets contents of 010
|
||||
for address in range(0, MEMORY_SIZE, 0100):
|
||||
for address in range(0, MEMORY_SIZE, 0o100):
|
||||
fetch_value = memory.fetch(address=address, indirect=True)
|
||||
msg = 'Fetch of 010 through %07o got %07o, expected %07o' % (address, fetch_value, expected)
|
||||
self.assertTrue(expected == fetch_value, msg)
|
||||
@@ -102,14 +102,14 @@ class TestMemory(unittest.TestCase):
|
||||
|
||||
memory = Memory.Memory(boot_rom=ROM_NONE)
|
||||
|
||||
expected = 0052525
|
||||
expected = 0o052525
|
||||
|
||||
# fill all test addresses with expected value - 1
|
||||
for address in range(010, 017):
|
||||
for address in range(0o10, 0o17):
|
||||
memory.put(value=expected-1, address=address, indirect=False)
|
||||
|
||||
# now check that fetch through all those addresses increments the location
|
||||
for address in range(010, 017):
|
||||
for address in range(0o10, 0o17):
|
||||
fetch_value = memory.fetch(address=address, indirect=True)
|
||||
|
||||
# check that autoinc memory has incremented
|
||||
@@ -122,25 +122,25 @@ class TestMemory(unittest.TestCase):
|
||||
|
||||
memory = Memory.Memory(boot_rom=ROM_NONE)
|
||||
|
||||
expected = 0052525
|
||||
expected = 0o052525
|
||||
|
||||
# address 0100 is target of all indirect fetches
|
||||
memory.put(value=expected, address=0100, indirect=False)
|
||||
memory.put(value=expected, address=0o100, indirect=False)
|
||||
|
||||
# fill all test addresses with pointer to address 0077
|
||||
for address in range(010, 017):
|
||||
memory.put(value=0077, address=address, indirect=False)
|
||||
for address in range(0o10, 0o17):
|
||||
memory.put(value=0o077, address=address, indirect=False)
|
||||
|
||||
# now check that fetch through all those addresses gets contents of 0100
|
||||
for address in range(010, 017):
|
||||
for address in range(0o10, 0o17):
|
||||
fetch_value = memory.fetch(address=address, indirect=True)
|
||||
msg = 'Fetch of 0100 through %07o got %07o, expected %07o' % (address, fetch_value, expected)
|
||||
self.assertTrue(expected == fetch_value, msg)
|
||||
|
||||
# check that autoinc memory has incremented
|
||||
fetch_value = memory.fetch(address=address, indirect=False)
|
||||
msg = 'Location %07o should be %07o, actually %07o' % (address, 0100, fetch_value)
|
||||
self.assertTrue(0100 == fetch_value, msg)
|
||||
msg = 'Location %07o should be %07o, actually %07o' % (address, 0o100, fetch_value)
|
||||
self.assertTrue(0o100 == fetch_value, msg)
|
||||
|
||||
def test_fetch_put_all_values(self):
|
||||
"""Check Memory put/fetch for all word values."""
|
||||
@@ -148,7 +148,7 @@ class TestMemory(unittest.TestCase):
|
||||
memory = Memory.Memory(boot_rom=ROM_NONE)
|
||||
|
||||
# now check that put/fetch through all test addresses for all values
|
||||
for address in range(0, 010, 010):
|
||||
for address in range(0, 0o10, 0o10):
|
||||
for value in range(WORDMASK):
|
||||
memory.put(value=value, address=address, indirect=False)
|
||||
fetch_value = memory.fetch(address=address, indirect=False)
|
||||
|
||||
@@ -29,7 +29,7 @@ Logfile = 'test_PTR_PTP.log'
|
||||
|
||||
def logger(*args):
|
||||
msg = ' '.join(args)
|
||||
with open(Logfile, 'ab') as fd:
|
||||
with open(Logfile, 'a') as fd:
|
||||
fd.write(msg + '\n')
|
||||
|
||||
def read_no_tape(ptr):
|
||||
@@ -37,22 +37,22 @@ def read_no_tape(ptr):
|
||||
|
||||
# read before turning on
|
||||
byte = ptr.read()
|
||||
if byte != 0377:
|
||||
if byte != 0o377:
|
||||
print('Error')
|
||||
ptr.ptr_tick(1000000) # wait a long time
|
||||
byte = ptr.read()
|
||||
if byte != 0377:
|
||||
if byte != 0o377:
|
||||
print('Error')
|
||||
|
||||
# turn device on, still no tape
|
||||
ptr.start()
|
||||
ptr.ptr_tick(1000000) # wait a long time
|
||||
byte = ptr.read()
|
||||
if byte != 0377:
|
||||
if byte != 0o377:
|
||||
print('Error')
|
||||
ptr.ptr_tick(1000000) # wait a long time
|
||||
byte = ptr.read()
|
||||
if byte != 0377:
|
||||
if byte != 0o377:
|
||||
print('Error')
|
||||
ptr.stop()
|
||||
ptr.ptr_dismount()
|
||||
@@ -61,7 +61,7 @@ def create_papertape(filename):
|
||||
"""Create a PTP file."""
|
||||
|
||||
# create a test papertape
|
||||
with open(filename, 'wb') as fd:
|
||||
with open(filename, 'w') as fd:
|
||||
# leader
|
||||
for _ in range(128):
|
||||
fd.write(chr(0))
|
||||
|
||||
@@ -32,7 +32,7 @@ def create_tty_file(filename):
|
||||
"""Create a TTY file."""
|
||||
|
||||
# create a test file
|
||||
with open(filename, 'wb') as fd:
|
||||
with open(filename, 'w') as fd:
|
||||
# leader
|
||||
for _ in range(16):
|
||||
fd.write(chr(0))
|
||||
@@ -45,7 +45,7 @@ def no_mounted_file():
|
||||
|
||||
# read without mounting
|
||||
val = ttyin.read()
|
||||
expected = 0377
|
||||
expected = 0o377
|
||||
if val != expected:
|
||||
error('No mounted file: read() returned %d, expected %d' % (val, expected))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user