mirror of
https://github.com/rzzzwilson/pymlac.git
synced 2025-06-10 09:32:41 +00:00
Finished TTYIN testing
This commit is contained in:
@@ -18,4 +18,4 @@ lst: $(TESTS)
|
||||
../iasm/iasm -l $*.lst $<
|
||||
|
||||
clean:
|
||||
rm -Rf *.pyc *~ *.out test_*.ptp *.lst test_*.trace _#ASM#_.* _#PTR#_.* _#PTP#_.*
|
||||
rm -Rf *.pyc *~ *.out test_*.ptp *.lst test_*.trace _#*#_.ptp
|
||||
|
||||
@@ -90,14 +90,13 @@ class TtyIn(object):
|
||||
"""Advance the device state by 'cycles' number of CPU cycles."""
|
||||
|
||||
if not self.atEOF:
|
||||
log("TTYIN: Doing 'tick' with %d cycles, .atEOF is %s, .cycle_count=%d"
|
||||
log("TTYIN: Doing 'tick' cycle=%d, .atEOF=%s, .cycle_count=%d"
|
||||
% (cycles, str(self.atEOF), self.cycle_count))
|
||||
self.cycle_count -= cycles
|
||||
if self.cycle_count <= 0:
|
||||
log('TTYIN: .cycle_count expired, read new character')
|
||||
self.cycle_count += self.DEVICE_READY_CYCLES
|
||||
self.value = self.open_file.read(1)
|
||||
self.status = self.DEVICE_READY
|
||||
self.value = self.open_file.read(1)
|
||||
if len(self.value) < 1:
|
||||
# EOF on input file
|
||||
self.atEOF = True
|
||||
@@ -105,4 +104,7 @@ class TtyIn(object):
|
||||
self.cycle_count = 0
|
||||
self.status = self.DEVICE_NOT_READY
|
||||
log('TTYIN: EOF set on device (file %s)' % self.filename)
|
||||
else:
|
||||
log('TTYIN: .cycle_count expired, new character is %s (%03o)'
|
||||
% (self.value, ord(self.value[0])))
|
||||
self.value = ord(self.value)
|
||||
|
||||
@@ -31,21 +31,15 @@ def error(msg):
|
||||
def create_tty_file(filename):
|
||||
"""Create a TTY file."""
|
||||
|
||||
print('create_tty_file(%s)' % filename)
|
||||
|
||||
# create a test file
|
||||
with open(filename, 'wb') as fd:
|
||||
# leader
|
||||
for _ in range(16):
|
||||
fd.write(chr(0))
|
||||
|
||||
for v in range(1, 256):
|
||||
for v in range(1, 33):
|
||||
fd.write(chr(v))
|
||||
|
||||
# trailer
|
||||
for _ in range(16):
|
||||
fd.write(chr(0))
|
||||
|
||||
def no_mounted_file():
|
||||
ttyin = TtyIn.TtyIn()
|
||||
|
||||
@@ -68,21 +62,17 @@ def mount_dismount(filename):
|
||||
def read_tty(filename):
|
||||
"""Mount a file and read from it."""
|
||||
|
||||
print('read_tty(%s)' % filename)
|
||||
|
||||
ttyin = TtyIn.TtyIn()
|
||||
ttyin.mount(filename)
|
||||
|
||||
# read leader
|
||||
byte = None
|
||||
count = 0
|
||||
count = 1
|
||||
while True:
|
||||
while not ttyin.ready():
|
||||
ttyin.tick(1)
|
||||
byte = ttyin.read()
|
||||
print('byte=%s' % str(byte))
|
||||
while ttyin.ready():
|
||||
ttyin.tick(1)
|
||||
ttyin.clear()
|
||||
if byte != 0:
|
||||
break
|
||||
count += 1
|
||||
@@ -90,36 +80,16 @@ def read_tty(filename):
|
||||
print('%d bytes of leader' % count)
|
||||
|
||||
# read body, already read first byte
|
||||
byte = None
|
||||
count = 1
|
||||
while True:
|
||||
while count < 32:
|
||||
while not ttyin.ready():
|
||||
ttyin.tick(1)
|
||||
byte = ttyin.read()
|
||||
while ttyin.ready():
|
||||
ttyin.tick(1)
|
||||
if byte == 0:
|
||||
break
|
||||
ttyin.clear()
|
||||
count += 1
|
||||
print('count=%d' % count)
|
||||
|
||||
print('%d bytes of body' % count)
|
||||
|
||||
# read trailer, already read first byte
|
||||
byte = None
|
||||
count = 1
|
||||
while True:
|
||||
while not ttyin.ready():
|
||||
ttyin.tick(1)
|
||||
byte = ttyin.read()
|
||||
while ttyin.ready():
|
||||
ttyin.tick(1)
|
||||
if byte != 0:
|
||||
break
|
||||
count += 1
|
||||
|
||||
print('%d bytes of trailer' % count)
|
||||
|
||||
# now dismount the file
|
||||
ttyin.dismount()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user