mirror of
https://github.com/rzzzwilson/pymlac.git
synced 2025-06-10 09:32:41 +00:00
Add logging for debug
This commit is contained in:
@@ -6,8 +6,8 @@ Emulate the Input TTY device (TTYIN).
|
||||
|
||||
from Globals import *
|
||||
|
||||
#import log
|
||||
#log = log.Log('test_TTYIN.log', log.Log.DEBUG)
|
||||
import log
|
||||
log = log.Log('test_TTYIN.log', log.Log.DEBUG)
|
||||
|
||||
|
||||
class TtyIn(object):
|
||||
@@ -22,7 +22,7 @@ class TtyIn(object):
|
||||
def __init__(self):
|
||||
"""Initialize the TTYIN device."""
|
||||
|
||||
# log('TTYIN: Initializing device')
|
||||
log('TTYIN: Initializing device')
|
||||
|
||||
self.filename = None
|
||||
self.open_file = None
|
||||
@@ -31,12 +31,12 @@ class TtyIn(object):
|
||||
self.cycle_count = 0
|
||||
self.status = self.DEVICE_NOT_READY
|
||||
|
||||
# log('TTYIN: DEVICE_READY_CYCLES=%d' % self.DEVICE_READY_CYCLES)
|
||||
log('TTYIN: DEVICE_READY_CYCLES=%d' % self.DEVICE_READY_CYCLES)
|
||||
|
||||
def mount(self, fname):
|
||||
"""Mount a file on the TTYIN device."""
|
||||
|
||||
# log('TTYIN: Mounting file %s on device' % fname)
|
||||
log('TTYIN: Mounting file %s on device' % fname)
|
||||
|
||||
self.filename = fname
|
||||
self.open_file = open(fname, 'r')
|
||||
@@ -49,13 +49,14 @@ class TtyIn(object):
|
||||
self.atEOF = True
|
||||
self.cycle_count = 0
|
||||
self.value = 0
|
||||
# log('TTYIN: EOF set on device (file %s)' % self.fname)
|
||||
log('TTYIN: EOF set on device (file %s)' % self.fname)
|
||||
self.value = ord(self.value)
|
||||
self.offset = -1
|
||||
|
||||
def dismount(self):
|
||||
"""Dismount the file on the TTYIN device."""
|
||||
|
||||
# log('TTYIN: Dismounting file %s' % self.filename)
|
||||
log('TTYIN: Dismounting file %s' % self.filename)
|
||||
|
||||
if self.open_file:
|
||||
self.open_file.close()
|
||||
@@ -64,25 +65,27 @@ class TtyIn(object):
|
||||
self.value = 0
|
||||
self.atEOF = True
|
||||
self.status = self.DEVICE_NOT_READY
|
||||
self.offset = None
|
||||
|
||||
def read(self):
|
||||
"""Return the current device value."""
|
||||
|
||||
# log('TTYIN: Reading device, value is %03o' % self.value)
|
||||
log('TTYIN: Reading device, value is %03o, offset=%04o' % (self.value, self.offset))
|
||||
|
||||
return self.value
|
||||
|
||||
def ready(self):
|
||||
"""Return device status."""
|
||||
|
||||
# log("TTYIN: Device 'ready' status is %s" % str(self.status == self.DEVICE_READY))
|
||||
log("TTYIN: Device 'ready' status is %s, offset=%d"
|
||||
% (str(self.status == self.DEVICE_READY), self.offset))
|
||||
|
||||
return (self.status == self.DEVICE_READY)
|
||||
|
||||
def clear(self):
|
||||
"""Clear the device 'ready' status."""
|
||||
|
||||
# log("TTYIN: Clearing device 'ready' status")
|
||||
log("TTYIN: Clearing device 'ready' status")
|
||||
|
||||
self.status = self.DEVICE_NOT_READY
|
||||
|
||||
@@ -90,8 +93,8 @@ class TtyIn(object):
|
||||
"""Advance the device state by 'cycles' number of CPU cycles."""
|
||||
|
||||
if not self.atEOF:
|
||||
# log("TTYIN: Doing 'tick' cycle=%d, .atEOF=%s, .cycle_count=%d"
|
||||
# % (cycles, str(self.atEOF), self.cycle_count))
|
||||
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:
|
||||
self.cycle_count += self.DEVICE_READY_CYCLES
|
||||
@@ -103,8 +106,9 @@ class TtyIn(object):
|
||||
self.value = chr(0)
|
||||
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])))
|
||||
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)
|
||||
self.offset += 1
|
||||
|
||||
Reference in New Issue
Block a user