From 357c9a2fe44e6e3de463fb5815f530e6549926d8 Mon Sep 17 00:00:00 2001 From: Ross Wilson Date: Thu, 21 Apr 2016 15:50:44 +0700 Subject: [PATCH] First fudged display attempt --- pymlac/Display.py | 9 ++++---- pymlac/DisplayCPU.py | 49 ++++++++++++++++++++++++++++---------------- pymlac/Trace.py | 3 ++- pymlac/pymlac | 13 ++++++++---- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/pymlac/Display.py b/pymlac/Display.py index 4a68e14..ff3db8b 100644 --- a/pymlac/Display.py +++ b/pymlac/Display.py @@ -44,7 +44,7 @@ class Display(object): ScaleMaxY = 1024 - def __init__(self, parent, **kwargs): + def __init__(self): # create and initialise the image array # reference .array[y*ScaleMaxX + x] self.array = [0] * self.ScaleMaxY * self.ScaleMaxX @@ -56,7 +56,7 @@ class Display(object): self.next_file_num = 0 # 'dirty' flag set after writing - self.dirty = False + self.dirty = False def write(self): """Write display array to PPM file.""" @@ -143,11 +143,10 @@ class Display(object): dx = x2 - x1 dy = y2 - y1 j = y1 - sigma = dy = dx + sigma = dy - dx for i in range(x1, x2): - #illuminate(i, j) - self.array[j*self.ScaleMaxX + i] + self.array[j*self.ScaleMaxX + i] = 1 if sigma >= 0: j += 1 sigma -= dx diff --git a/pymlac/DisplayCPU.py b/pymlac/DisplayCPU.py index f52e70c..65fc7e2 100644 --- a/pymlac/DisplayCPU.py +++ b/pymlac/DisplayCPU.py @@ -11,6 +11,9 @@ from Globals import * import Trace +trace = Trace.Trace(TRACE_FILENAME) + + class DisplayCPU(object): # display CPU constants @@ -40,6 +43,8 @@ class DisplayCPU(object): self.display = display self.memory = memory + self.dot = self.DPC + def DEIMdecode(self, byte): """Decode a DEIM byte""" @@ -59,7 +64,16 @@ class DisplayCPU(object): else: result += 'A%3.3o' % byte return result - def doDEIMByte(self, byte): + def doDEIMByte(self, byte, last=False): + """Execute a DEIM instruction byte. + + byte is the byte to execute in DEIM mode + last True if the last byte in a word + """ + + trace = DEIMdecode(byte) + print('doDEIMByte: trace=%s' % str(trace)) + if byte & 0x80: # increment? prevDX = self.DX prevDY = self.DY @@ -78,7 +92,7 @@ class DisplayCPU(object): self.Mode = self.MODE_NORMAL if byte & 0x20: # DRJM if self.DRSindex <= 0: - Trace.comment('\nDRS stack underflow at display address %6.6o' + trace.comment('\nDRS stack underflow at display address %6.6o' % (self.DPC - 1)) self.illegal() self.DRSindex -= 1 @@ -92,23 +106,21 @@ class DisplayCPU(object): if byte & 0x01: self.DY &= 0xfff0 + return trace + def execute_one_instruction(self): if not self.Running: - Trace.dtrace('') - return 0 + return (0, None) + self.dot = self.DPC instruction = self.memory.fetch(self.DPC, False) self.DPC = MASK_MEM(self.DPC + 1) if self.Mode == self.MODE_DEIM: - Trace.trace(self.DEIMdecode(instruction >> 8) + '\t') - self.doDEIMByte(instruction >> 8) + tracestr = self.doDEIMByte(instruction >> 8) if self.Mode == self.MODE_DEIM: - Trace.trace(self.DEIMdecode(instruction & 0xff) + '\t') - self.doDEIMByte(instruction & 0xff) - else: - Trace.trace('\t') - return 1 + tracestr += ', ' + self.doDEIMByte(instruction & 0xff, True) + return (1, tracestr) opcode = instruction >> 12 address = instruction & 007777 @@ -125,10 +137,10 @@ class DisplayCPU(object): def illegal(self, instruction=None): if instruction: - Trace.comment('Illegal display instruction (%6.6o) at address %6.6o' + trace.comment('Illegal display instruction (%6.6o) at address %6.6o' % (instruction, (self.DPC - 1))) else: - Trace.comment('Illegal display instruction at address %6.6o' + trace.comment('Illegal display instruction at address %6.6o' % (self.DPC - 1)) sys.exit(0) @@ -137,17 +149,18 @@ class DisplayCPU(object): def i_DDXM(self): self.DX -= 040 - Trace.dtrace('DDXM') + tracestr = trace.dtrace(self.dot, 'DDXM', None) + return (1, tracestr) def i_DDYM(self): self.DY -= 040 - Trace.dtrace('DDYM') + tracestr = trace.dtrace(self.dot, 'DDYM', None) + return (1, tracestr) def i_DEIM(self, address): self.Mode = self.MODE_DEIM - Trace.deimtrace('DEIM', self.DEIMdecode(address & 0377)) - self.doDEIMByte(address & 0377) - return 1 + tracestr += 'DEIM\t' + self.doDEIMByte(address & 0377, last=True) + return (1, tracestr) def i_DHLT(self): self.Running = False diff --git a/pymlac/Trace.py b/pymlac/Trace.py index 13a7aed..e518e9b 100644 --- a/pymlac/Trace.py +++ b/pymlac/Trace.py @@ -57,7 +57,7 @@ class Trace(object): self.cpu = maincpu - def add_dispcpu(self, dispcpu): + def add_displaycpu(self, dispcpu): """Add the display CPU object.""" self.dcpu = dispcpu @@ -112,6 +112,7 @@ class Trace(object): """ result = None + if self.tracing and self.trace_map[dot]: char = '*' if indirect else '' if address is None: diff --git a/pymlac/pymlac b/pymlac/pymlac index 59842dc..b23351c 100755 --- a/pymlac/pymlac +++ b/pymlac/pymlac @@ -40,6 +40,8 @@ import collections from Globals import * import MainCPU +import DisplayCPU +import Display import Memory import PtrPtp import TtyIn @@ -80,7 +82,7 @@ def usage(msg=None): print(__doc__) -def start_running(cpu, memory, ptrptp, ttyin): +def start_running(cpu, dcpu, memory, ptrptp, ttyin): """Run the Imlac machine until it stops.""" cpu.running = True @@ -88,7 +90,7 @@ def start_running(cpu, memory, ptrptp, ttyin): (cycles, tracestr) = cpu.execute_one_instruction() if tracestr: endstr = trace.itraceend(False) - log('%s\t%s' % (tracestr, endstr)) + dcpu.execute_one_instruction() ptrptp.ptr_tick(cycles) ptrptp.ptp_tick(cycles) ttyin.tick(cycles) @@ -101,13 +103,16 @@ def main(): imlac_ptrptp = PtrPtp.PtrPtp() imlac_ttyin = TtyIn.TtyIn() imlac_ttyout = TtyOut.TtyOut() - imlac_cpu = MainCPU.MainCPU(imlac_memory, None, None, + imlac_display = Display.Display() + imlac_dcpu = DisplayCPU.DisplayCPU(imlac_display, imlac_memory) + imlac_cpu = MainCPU.MainCPU(imlac_memory, imlac_dcpu, None, None, imlac_ttyin, imlac_ttyout, imlac_ptrptp) imlac_cpu.running = True imlac_display_state = False # prepare the trace trace.add_maincpu(imlac_cpu) + trace.add_displaycpu(imlac_dcpu) # trace_map defines addresses we are tracing at # initially, no tracing @@ -188,7 +193,7 @@ def main(): else: log('Running from current PC %06o' % imlac_cpu.PC) trace.set_trace_map(trace_map) - start_running(imlac_cpu, imlac_memory, imlac_ptrptp, imlac_ttyin) + start_running(imlac_cpu, imlac_dcpu, imlac_memory, imlac_ptrptp, imlac_ttyin) elif opt == '-s': if ndx >= len_sys_argv: usage("'-s' option needs a following data filename")