include non-interrupt mode emulation

This commit is contained in:
Neil Webber 2023-10-23 10:09:04 -05:00
parent 9239792d6d
commit 7237ed2020

37
kw11.py
View file

@ -26,40 +26,39 @@ import time
import threading import threading
# The real clock runs at 50 or 60 cycles per second. However, the
# overhead of emulated interrupts is high - as a compromise set HZ
# to something slower than 50-60...
HZ = 25
class KW11: class KW11:
KW11_OFFS = 0o17546 KW11_OFFS = 0o17546
def __init__(self, ub): def __init__(self, ub):
self._t = threading.Thread( self._t = threading.Thread(
target=self._cloop, args=(0.05, ub.intmgr), daemon=True) target=self._cloop, args=(1/HZ, ub.intmgr), daemon=True)
self.running = False self.interrupts_enabled = False
self.monbit = 0 self.monbit = 1 # the manual says this starts as 1
ub.mmio.register_simpleattr(self, 'LKS', self.KW11_OFFS, reset=True) ub.mmio.register_simpleattr(self, 'LKS', self.KW11_OFFS, reset=True)
self._t.start()
# clock loop # clock loop
def _cloop(self, interval, imgr): def _cloop(self, interval, imgr):
while self.running: while True:
time.sleep(interval) time.sleep(interval)
# there are inherent races here (in the hardware too) but self.monbit = 1
# seek to make the hazard smaller than the full interval # The loop runs forever (as does the real device) but only
# by testing self.running again here. # generates interrupts if interrupts are enabled
if self.running: if self.interrupts_enabled:
imgr.simple_irq(pri=6, vector=0o100) imgr.simple_irq(pri=6, vector=0o100)
@property @property
def LKS(self): def LKS(self):
return (int(self.monbit) << 7) | (int(self.running) << 6) return (int(self.monbit) << 7) | (int(self.interrupts_enabled) << 6)
@LKS.setter @LKS.setter
def LKS(self, value): def LKS(self, value):
if not self.running: self.interrupts_enabled = bool(value & 0o100)
if value & 0o100: self.monbit = bool(value & 0o200)
self.running = True
self._t.start()
self.monbit = (value & 0o200)
if self.running and not (value & 0o100):
# this never happens in unix but ...
self.running = False
self._t.join()