1
0
mirror of https://github.com/rzzzwilson/pymlac.git synced 2025-06-10 09:32:41 +00:00

Added UTF tag, extending display

This commit is contained in:
Ross Wilson
2016-01-31 15:53:49 +07:00
parent cffd27640a
commit f836002b40
9 changed files with 112 additions and 57 deletions

View File

@@ -1 +1,8 @@
This program is a smart, interactive disassembler for IMLAC binary files.
This program is a smart, interactive disassembler for IMLAC binary files,
papertape or TTY.
It is designed to allow the user to read in a *.ptp or *.tty file, which
may then be interacted with:
. change MAIN to DISPLAY instruction set and vice versa
. add labels where appropriate
. change DATA to ASCII pseudo-ops and vice versa

View File

@@ -1,7 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Import an imlac binary file
Import an imlac binary file.
"""
import sys
@@ -11,89 +12,125 @@ import mem
import disasmdata
offset = 0
# address where next word will be loaded into memory
Dot = 0
def doblockloader(f, word):
ldaddr = 0177700
numwords = 0100 - 1 # have already read one word in
# dictionary of memory 'chunks'
# {<base_address>: [word1, word2, ...], ...}
Memory = {}
# size of memory configured
MemSize = 04000
# size of block loader
LoaderSize = 0100
def doblockloader(f, word, mymem):
"""Read block loader into high memory.
f file handle to read from
word the word we have already read
mymem Mem() object to store loader in
"""
ldaddr = MemSize - LoaderSize
numwords = LoaderSize - 1 # have already read one word in
mymem.add(ldaddr, word)
while numwords > 0:
word = readword(f)
print('doblockloader: top of loop, numwords=%d, word=%06o' % (numwords, word))
mymem.add(ldaddr, word)
ldaddr += 1
numwords = numwords - 1
ldaddr = ldaddr + 1
def dobody(f, count):
mymem = mem.Mem()
print('doblockloader: mymem.memory=%s' % str(mymem.memory))
numwords = count
def dobody(f, mymem):
"""Read all of file after block loader.
f input file handle
mymem the mem.Mem() dict to store data in
Returns an updated mem.Mem() object containing the input code.
"""
numwords = skipzeros(f)
while True:
# negative load address is end-of-file
ldaddr = readword(f)
if ldaddr & 0x8000:
break
# read data block, calculating checksum
csum = 0
#csum = ldaddr
while numwords > 0:
word = readword(f)
csum += word
# if csum > 0xffff:
# csum += 1
# csum = csum & 0xffff
csum &= 0xffff
mymem.add(ldaddr, word)
(op, fld) = disasmdata.disasmdata(word)
mymem.putOp(ldaddr, op)
mymem.putFld(ldaddr, fld)
ldaddr += 1
numwords -= 1
csum &= 0xffff
#csum &= 0xffff
checksum = readword(f)
if csum != checksum:
print "Checksum error"
#sys.exit(20)
# if csum != checksum:
# print "Checksum error"
# return None
numwords = skipzeros(f)
return mymem
def ptpimport(file):
global offset
global Dot
try:
f = open(file, "rb")
except IOError, e:
except IOError as e:
print e
return 3
offset = 0
# create Mem() object to store data
mymem = mem.Mem()
print('str(dir(mymem))=%s' % str(dir(mymem)))
Dot = 0
# find and read the block loader
byte = skipzeros(f)
word = (byte << 8) + readbyte(f)
doblockloader(f, word)
doblockloader(f, word, mymem)
count = skipzeros(f)
mymem = dobody(f, count)
# now read all the data blocks
mymem = dobody(f, mymem)
return mymem
def readbyte(f):
global offset
global Dot
try:
byte = f.read(1)
except IOError, e:
except IOError as e:
print e
sys.exit(10)
except EOFError, e:
except EOFError as e:
print e
sys.exit(11)
offset += 1
Dot += 1
if len(byte) > 0:
val = struct.unpack("B", byte)
return val[0]
else:
return 0
def readword(f):
return (readbyte(f) << 8) + readbyte(f)
def skipzeros(f):
while True:
val = readbyte(f)
@@ -102,7 +139,11 @@ def skipzeros(f):
if __name__ == "__main__":
themem = ptpimport("keybrd.ptp")
themem = ptpimport('40tp_simpleDisplay.ptp')
if themem is None:
print('Error reading input file.')
sys.exit(10)
print('str(dir(themem))=%s' % str(dir(themem)))
addrlist = themem.keys()
addrlist.sort()

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module disassembles one imlac machine word into a display processor

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module disassembles one imlac machine word into a data instruction

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module disassembles one imlac machine word into a main processor

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module implements the 'mem' object and access routines.
@@ -31,10 +32,10 @@ class Mem(object):
def add(self, address, code):
self.putMem(address, (code, "", "", 0, False, None, 0))
def len(self):
return len(self.memory)
def getMem(self, address):
addrstr = "%05o" % address
result = self.memory.get(addrstr, None)
@@ -42,96 +43,96 @@ class Mem(object):
result = (0, "", "", 0, False, None, 0)
self.putMem(address, result)
return result
def getCode(self, address):
(code, _, _, _, _, _, _) = self.getMem(address)
return code
def getOp(self, address):
(_, op, _, _, _, _, _) = self.getMem(address)
return op
def getFld(self, address):
(_, _, fld, _, _, _, _) = self.getMem(address)
return fld
def getLabcount(self, address):
(_, _, _, labcount, _, _, _) = self.getMem(address)
return labcount
def getRef(self, address):
(_, _, _, _, ref, _, _) = self.getMem(address)
return ref
def getType(self, address):
(_, _, _, _, _, type, _) = self.getMem(address)
return type
def getCycle(self, address):
(_, _, _, _, _, _, cycle) = self.getMem(address)
return cycle
def putMem(self, address, entry):
addrstr = "%05o" % address
self.memory[addrstr] = entry
def putCode(self, address, code):
(_, op, fld, labcount, ref, type, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def putOp(self, address, op):
(code, _, fld, labcount, ref, type, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def putFld(self, address, fld):
(code, op, _, labcount, ref, type, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def putLabcount(self, address, labcount):
(code, op, fld, _, ref, type, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def putRef(self, address, ref):
(code, op, fld, labcount, _, type, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def putType(self, address, type):
(code, op, fld, labcount, ref, _, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def putCycle(self, address, cycle):
(code, op, fld, labcount, ref, type, _) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def decLab(self, address):
(code, op, fld, labcount, ref, type, cycle) = self.getMem(address)
labcount -= 1
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def incLab(self, address):
(code, op, fld, labcount, ref, type, cycle) = self.getMem(address)
labcount += 1
self.putMem(address, (code, op, fld, labcount, ref, type, cycle))
def clearRef(self, address):
(code, op, fld, labcount, _, type, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, False, type, cycle))
def setRef(self, address):
(code, op, fld, labcount, _, type, cycle) = self.getMem(address)
self.putMem(address, (code, op, fld, labcount, True, type, cycle))
def keys(self):
return self.memory.keys()
def clearUndo(self):
self.undo = None
def setUndo(self):
self.undo = self.memory.copy()
def undoX(self):
tmp = self.memory
self.memory = self.undo
self.undo = tmp

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module takes one word value and processes it as a DATA word.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module takes a memory dictionary of the form:

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Process main instructions from a start address.