added the TI-74 BASIC port and the mu808asm'MU74 export support
This commit is contained in:
+31
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# a simple assembler/disassembler for the mu808 VM
|
||||
# supports both text and binary program formats
|
||||
# usage: mu808asm [at|ab|dt|db|t2b|b2t] file outfile
|
||||
# usage: mu808asm [at|ab|dt|db|t2b|b2t|t74] file outfile
|
||||
# modes:
|
||||
# at: assemble to plaintext (MU8) machine code
|
||||
# ab: assemble to binary (MU8B) machine code
|
||||
@@ -9,6 +9,7 @@
|
||||
# db: disassemble binary (MU8B) machine code
|
||||
# t2b: convert from plaintext MU8 to binary MU8B
|
||||
# b2t: convert from binary MU8B to plaintext MU8
|
||||
# t74: convert from plaintext MU8 to the TI-74 representation
|
||||
|
||||
import sys, re, struct
|
||||
|
||||
@@ -132,6 +133,33 @@ def totext(binrep):
|
||||
out += ' '.join([str(lno), str(cmd), str(x), str(y), str(z)]) + '\n'
|
||||
return out
|
||||
|
||||
# converts the MU8 plaintext machine code to the TI-74 DATA statements (MU74)
|
||||
def ti74data(txtrep:str, baseaddr:int=5000):
|
||||
instrs = [] # instruction list to store here
|
||||
vreg = re.compile(r'\s+')
|
||||
iindex = 0
|
||||
instr = []
|
||||
for instrpart in vreg.split(txtrep):
|
||||
if iindex == 5:
|
||||
instrs.append(instr)
|
||||
instr = []
|
||||
iindex = 0
|
||||
if len(instrpart) > 0:
|
||||
instr.append(int(instrpart))
|
||||
iindex += 1
|
||||
# now, instrs contains 5-number groups
|
||||
out = f'{baseaddr} DATA 0,0\n'
|
||||
maxlno = 0
|
||||
for instr in instrs:
|
||||
lno, cmd, x, y, z = instr
|
||||
if lno > maxlno:
|
||||
maxlno = lno
|
||||
a = cmd*10000 + x
|
||||
b = y*10000 + z
|
||||
out += f'{baseaddr + lno} DATA {a},{b}\n'
|
||||
out += f'{baseaddr + maxlno + 1} DATA -1,0\n'
|
||||
return out
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: mu808asm [at|ab|dt|db|t2b|b2t] file outfile")
|
||||
@@ -162,6 +190,8 @@ def main():
|
||||
elif mode == 'db': # disassemble binary
|
||||
srctext = totext(srctext)
|
||||
output = disassemble(srctext)
|
||||
elif mode == 't74': # convert to TI-74 DATA statements
|
||||
output = ti74data(srctext)
|
||||
else: # assemble
|
||||
output = assemble(srctext) # default mode
|
||||
if mode == 'ab':
|
||||
|
||||
Reference in New Issue
Block a user