mirror of
https://github.com/ksherlock/65816.tmbundle.git
synced 2024-12-27 11:29:40 +00:00
unify macgens a bit
This commit is contained in:
parent
1a1b36e98b
commit
9c62183f3c
223
mac-gen.py
223
mac-gen.py
@ -37,36 +37,36 @@ def macro_files(dirs, filter):
|
|||||||
|
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
re_pmc = re.compile('^[^.,/\\- ]*')
|
re_pmc = re.compile('^[^.,/\\- ]*')
|
||||||
re_dot_s = re.compile('\\.S$', re.IGNORECASE)
|
re_dot_s = re.compile('\\.S$', re.IGNORECASE)
|
||||||
re_ws = re.compile('[\t ]+')
|
re_ws = re.compile('[\t ]+')
|
||||||
re_comment = re.compile('^[\t ]*[;*]')
|
re_comment = re.compile('^[\t ]*[;*]')
|
||||||
|
|
||||||
|
class CommonMacGen(sublime_plugin.TextCommand):
|
||||||
|
|
||||||
class MerlinMacGen(sublime_plugin.TextCommand):
|
|
||||||
|
|
||||||
opcodes = {
|
def run(self, edit):
|
||||||
'BRL', 'COP', 'JML', 'JMPL', 'JSL', 'MVN', 'MVP', 'MX', 'PEA',
|
|
||||||
'PEI', 'PER', 'REP', 'SEP', 'WDM', 'XCE', 'ADR', 'ADRL', 'ASC',
|
view = self.view
|
||||||
'AST', 'BRK', 'CHK', 'CYC', 'DA', 'DAT', 'DB', 'DCI', 'DDB', 'DEND',
|
|
||||||
'DFB', 'DL', 'DS', 'DSK', 'DUM', 'DW', 'END', 'ENT', 'EQU', 'ERR', 'EXP',
|
missing = set()
|
||||||
'EXT', 'FLS', 'HEX', 'INV', 'KBD', 'LST', 'LSTL', 'LUP', 'OBJ',
|
known = set()
|
||||||
'ORG', 'PAG', 'PAU', 'PMC', 'PUT', 'REL', 'REV', 'SAV', 'SKP',
|
self.build_missing(known, missing)
|
||||||
'STR', 'TR', 'TTL', 'TYP', 'USE', 'USR', 'VAR', 'XC', 'XREF','=',
|
|
||||||
'>>>', 'DO', 'ELS', 'EOM', 'FIN', 'IF', 'MAC', '--^', '<<<',
|
if len(missing) == 0: return
|
||||||
'CLC', 'CLD', 'CLI', 'CLV', 'DEX', 'DEY', 'INX', 'INY', 'NOP',
|
|
||||||
'PHA', 'PHB', 'PHD', 'PHK', 'PHX', 'PHY', 'PLA', 'PLB', 'PLD',
|
buffer = ""
|
||||||
'PLP', 'PLX', 'PLY', 'RTI', 'RTL', 'RTS', 'SEC', 'SED', 'SEI',
|
files = self.build_file_list()
|
||||||
'STP', 'SWA', 'TAD', 'TAS', 'TAX', 'TAY', 'TCD', 'TCS', 'TDA',
|
|
||||||
'TDC', 'TSA', 'TSC', 'TSX', 'TXA', 'TXS', 'TXY', 'TYA', 'TYX',
|
for f in files:
|
||||||
'WAI', 'XBA', 'BCC', 'BCS', 'BEQ', 'BGE', 'BLT', 'BMI', 'BNE',
|
buffer += self.one_macro_file(f, known, missing)
|
||||||
'BPL', 'BRA', 'BVC', 'BVS', 'ADCL', 'ANDL', 'CMPL', 'EORL',
|
if len(missing) == 0: break;
|
||||||
'LDAL', 'ORAL', 'SBCL', 'STAL', 'ADC', 'AND', 'ASL', 'BIT',
|
|
||||||
'CMP', 'CPX', 'CPY', 'DEC', 'EOR', 'INC', 'JMP', 'JSR', 'LDA',
|
buffer = self.front_matter() + self.missing_matter(missing) + buffer
|
||||||
'LDX', 'LDY', 'LSR', 'ORA', 'ROL', 'ROR', 'SBC', 'STA', 'STX',
|
|
||||||
'STY', 'STZ', 'TRB', 'TSB', 'PHP', 'STRL', 'FLO', 'EXD', 'CAS',
|
self.create_macro_file(buffer)
|
||||||
''
|
|
||||||
}
|
|
||||||
|
|
||||||
def front_matter(self):
|
def front_matter(self):
|
||||||
buffer = ""
|
buffer = ""
|
||||||
@ -93,32 +93,54 @@ class MerlinMacGen(sublime_plugin.TextCommand):
|
|||||||
buffer += "\n"
|
buffer += "\n"
|
||||||
return buffer
|
return buffer
|
||||||
|
|
||||||
|
def create_macro_file(self, buffer):
|
||||||
def run(self, edit):
|
|
||||||
|
|
||||||
view = self.view
|
view = self.view
|
||||||
|
mv = view.window().new_file()
|
||||||
|
mv.settings().set("auto_indent", False)
|
||||||
|
mv.run_command('insert', {'characters': buffer})
|
||||||
|
|
||||||
missing = set()
|
|
||||||
known = set()
|
|
||||||
self.build_missing(known, missing)
|
|
||||||
|
|
||||||
if len(missing) == 0: return
|
# override these:
|
||||||
|
def build_missing(self, known, missing):
|
||||||
|
pass
|
||||||
|
|
||||||
buffer = ""
|
def build_file_list(self):
|
||||||
dirlist = view.settings().get('merlin_macro_directories', [])
|
return []
|
||||||
|
|
||||||
|
def one_macro_file(self, file, known, missing):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
class MerlinMacGen(CommonMacGen):
|
||||||
|
|
||||||
|
opcodes = {
|
||||||
|
'BRL', 'COP', 'JML', 'JMPL', 'JSL', 'MVN', 'MVP', 'MX', 'PEA',
|
||||||
|
'PEI', 'PER', 'REP', 'SEP', 'WDM', 'XCE', 'ADR', 'ADRL', 'ASC',
|
||||||
|
'AST', 'BRK', 'CHK', 'CYC', 'DA', 'DAT', 'DB', 'DCI', 'DDB', 'DEND',
|
||||||
|
'DFB', 'DL', 'DS', 'DSK', 'DUM', 'DW', 'END', 'ENT', 'EQU', 'ERR', 'EXP',
|
||||||
|
'EXT', 'FLS', 'HEX', 'INV', 'KBD', 'LST', 'LSTL', 'LUP', 'OBJ',
|
||||||
|
'ORG', 'PAG', 'PAU', 'PMC', 'PUT', 'REL', 'REV', 'SAV', 'SKP',
|
||||||
|
'STR', 'TR', 'TTL', 'TYP', 'USE', 'USR', 'VAR', 'XC', 'XREF','=',
|
||||||
|
'>>>', 'DO', 'ELS', 'EOM', 'FIN', 'IF', 'MAC', '--^', '<<<',
|
||||||
|
'CLC', 'CLD', 'CLI', 'CLV', 'DEX', 'DEY', 'INX', 'INY', 'NOP',
|
||||||
|
'PHA', 'PHB', 'PHD', 'PHK', 'PHX', 'PHY', 'PLA', 'PLB', 'PLD',
|
||||||
|
'PLP', 'PLX', 'PLY', 'RTI', 'RTL', 'RTS', 'SEC', 'SED', 'SEI',
|
||||||
|
'STP', 'SWA', 'TAD', 'TAS', 'TAX', 'TAY', 'TCD', 'TCS', 'TDA',
|
||||||
|
'TDC', 'TSA', 'TSC', 'TSX', 'TXA', 'TXS', 'TXY', 'TYA', 'TYX',
|
||||||
|
'WAI', 'XBA', 'BCC', 'BCS', 'BEQ', 'BGE', 'BLT', 'BMI', 'BNE',
|
||||||
|
'BPL', 'BRA', 'BVC', 'BVS', 'ADCL', 'ANDL', 'CMPL', 'EORL',
|
||||||
|
'LDAL', 'ORAL', 'SBCL', 'STAL', 'ADC', 'AND', 'ASL', 'BIT',
|
||||||
|
'CMP', 'CPX', 'CPY', 'DEC', 'EOR', 'INC', 'JMP', 'JSR', 'LDA',
|
||||||
|
'LDX', 'LDY', 'LSR', 'ORA', 'ROL', 'ROR', 'SBC', 'STA', 'STX',
|
||||||
|
'STY', 'STZ', 'TRB', 'TSB', 'PHP', 'STRL', 'FLO', 'EXD', 'CAS',
|
||||||
|
''
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def build_file_list(self):
|
||||||
|
dirlist = self.view.settings().get('merlin_macro_directories', [])
|
||||||
files = macro_files(dirlist, lambda x: x[-2:].upper() == ".S")
|
files = macro_files(dirlist, lambda x: x[-2:].upper() == ".S")
|
||||||
print(files)
|
return files
|
||||||
|
|
||||||
|
|
||||||
for f in files:
|
|
||||||
buffer += self.one_macro_file(f, known, missing)
|
|
||||||
if len(missing) == 0: break;
|
|
||||||
|
|
||||||
|
|
||||||
buffer = self.front_matter() + self.missing_matter(missing) + buffer
|
|
||||||
|
|
||||||
view = view.window().new_file()
|
|
||||||
view.insert(edit, 0, buffer)
|
|
||||||
|
|
||||||
def build_missing(self, known, missing):
|
def build_missing(self, known, missing):
|
||||||
|
|
||||||
@ -135,7 +157,7 @@ class MerlinMacGen(sublime_plugin.TextCommand):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# _macro args
|
# _macro args
|
||||||
# PMC _macro,args << . / , - ( Space are separtors.
|
# PMC _macro,args << . / , - ( Space are separators.
|
||||||
# >>> _macro
|
# >>> _macro
|
||||||
|
|
||||||
label = tokens[0].upper()
|
label = tokens[0].upper()
|
||||||
@ -163,9 +185,6 @@ class MerlinMacGen(sublime_plugin.TextCommand):
|
|||||||
continue
|
continue
|
||||||
missing.add(opcode)
|
missing.add(opcode)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def one_macro_file(self, file, known, missing):
|
def one_macro_file(self, file, known, missing):
|
||||||
inmac = False
|
inmac = False
|
||||||
buffer = ""
|
buffer = ""
|
||||||
@ -223,7 +242,7 @@ class MerlinMacGen(sublime_plugin.TextCommand):
|
|||||||
return buffer
|
return buffer
|
||||||
|
|
||||||
|
|
||||||
class OrcaMacGen(sublime_plugin.TextCommand):
|
class OrcaMacGen(CommonMacGen):
|
||||||
|
|
||||||
|
|
||||||
opcodes = {
|
opcodes = {
|
||||||
@ -251,29 +270,10 @@ class OrcaMacGen(sublime_plugin.TextCommand):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def run(self, edit):
|
def build_file_list(self):
|
||||||
|
dirlist = self.view.settings().get('orca_macro_directories', [])
|
||||||
view = self.view
|
|
||||||
|
|
||||||
known = set()
|
|
||||||
missing = set()
|
|
||||||
self.build_missing(known, missing)
|
|
||||||
|
|
||||||
if len(missing) == 0: return
|
|
||||||
|
|
||||||
buffer = ""
|
|
||||||
dirlist = view.settings().get('orca_macro_directories', [])
|
|
||||||
files = macro_files(dirlist, lambda x: x[:4].upper() == "M16.")
|
files = macro_files(dirlist, lambda x: x[:4].upper() == "M16.")
|
||||||
#print(files)
|
return files
|
||||||
for f in files:
|
|
||||||
buffer += self.one_macro_file(f, known, missing)
|
|
||||||
if len(missing) == 0: break;
|
|
||||||
|
|
||||||
buffer = self.front_matter() + self.missing_matter(missing) + buffer
|
|
||||||
|
|
||||||
view = view.window().new_file()
|
|
||||||
view.insert(edit, 0, buffer)
|
|
||||||
|
|
||||||
|
|
||||||
def build_missing(self, known, missing):
|
def build_missing(self, known, missing):
|
||||||
|
|
||||||
@ -314,7 +314,6 @@ class OrcaMacGen(sublime_plugin.TextCommand):
|
|||||||
label = tokens[0].upper()
|
label = tokens[0].upper()
|
||||||
opcode = tokens[1].upper()
|
opcode = tokens[1].upper()
|
||||||
|
|
||||||
|
|
||||||
if state == 0:
|
if state == 0:
|
||||||
if opcode == 'MACRO': state = 1
|
if opcode == 'MACRO': state = 1
|
||||||
elif state == 1:
|
elif state == 1:
|
||||||
@ -335,34 +334,8 @@ class OrcaMacGen(sublime_plugin.TextCommand):
|
|||||||
|
|
||||||
return buffer
|
return buffer
|
||||||
|
|
||||||
def front_matter(self):
|
|
||||||
buffer = ""
|
|
||||||
name = self.view.file_name()
|
|
||||||
if name:
|
|
||||||
buffer += "* Generated from " + os.path.basename(name) + " on " + time.asctime() + "\n"
|
|
||||||
else:
|
|
||||||
buffer += "* Generated on " + time.asctime() + "\n"
|
|
||||||
buffer += "\n"
|
|
||||||
return buffer
|
|
||||||
|
|
||||||
def missing_matter(self, missing):
|
class MpwMacGen(CommonMacGen):
|
||||||
buffer = ""
|
|
||||||
if len(missing) == 0:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
buffer = "* Missing Macros\n"
|
|
||||||
|
|
||||||
missing = list(missing)
|
|
||||||
missing.sort
|
|
||||||
for macro in missing:
|
|
||||||
buffer += "* " + macro + "\n"
|
|
||||||
|
|
||||||
buffer += "\n"
|
|
||||||
return buffer
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MpwMacGen(sublime_plugin.TextCommand):
|
|
||||||
|
|
||||||
|
|
||||||
opcodes = {
|
opcodes = {
|
||||||
@ -397,29 +370,10 @@ class MpwMacGen(sublime_plugin.TextCommand):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def run(self, edit):
|
def build_file_list(self):
|
||||||
|
dirlist = self.view.settings().get('mpw_macro_directories', [])
|
||||||
view = self.view
|
|
||||||
|
|
||||||
known = set()
|
|
||||||
missing = set()
|
|
||||||
self.build_missing(known, missing)
|
|
||||||
|
|
||||||
if len(missing) == 0: return
|
|
||||||
|
|
||||||
buffer = ""
|
|
||||||
dirlist = view.settings().get('mpw_macro_directories', [])
|
|
||||||
files = macro_files(dirlist, lambda x: x[:4].upper() == "M16.")
|
files = macro_files(dirlist, lambda x: x[:4].upper() == "M16.")
|
||||||
#print(files)
|
return files
|
||||||
for f in files:
|
|
||||||
buffer += self.one_macro_file(f, known, missing)
|
|
||||||
if len(missing) == 0: break;
|
|
||||||
|
|
||||||
buffer = self.front_matter() + self.missing_matter(missing) + buffer
|
|
||||||
|
|
||||||
view = view.window().new_file()
|
|
||||||
view.insert(edit, 0, buffer)
|
|
||||||
|
|
||||||
|
|
||||||
def build_missing(self, known, missing):
|
def build_missing(self, known, missing):
|
||||||
|
|
||||||
@ -451,8 +405,6 @@ class MpwMacGen(sublime_plugin.TextCommand):
|
|||||||
state = 0
|
state = 0
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if opcode in self.opcodes: continue
|
if opcode in self.opcodes: continue
|
||||||
if opcode in known: continue
|
if opcode in known: continue
|
||||||
missing.add(opcode)
|
missing.add(opcode)
|
||||||
@ -497,28 +449,3 @@ class MpwMacGen(sublime_plugin.TextCommand):
|
|||||||
|
|
||||||
|
|
||||||
return buffer
|
return buffer
|
||||||
|
|
||||||
def front_matter(self):
|
|
||||||
buffer = ""
|
|
||||||
name = self.view.file_name()
|
|
||||||
if name:
|
|
||||||
buffer += "* Generated from " + os.path.basename(name) + " on " + time.asctime() + "\n"
|
|
||||||
else:
|
|
||||||
buffer += "* Generated on " + time.asctime() + "\n"
|
|
||||||
buffer += "\n"
|
|
||||||
return buffer
|
|
||||||
|
|
||||||
def missing_matter(self, missing):
|
|
||||||
buffer = ""
|
|
||||||
if len(missing) == 0:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
buffer = "* Missing Macros\n"
|
|
||||||
|
|
||||||
missing = list(missing)
|
|
||||||
missing.sort
|
|
||||||
for macro in missing:
|
|
||||||
buffer += "* " + macro + "\n"
|
|
||||||
|
|
||||||
buffer += "\n"
|
|
||||||
return buffer
|
|
Loading…
Reference in New Issue
Block a user