def main(argv: Optional[list[str]] = None): args = argument_parser.parse_args(argv) library_list = [] if not args.simple: library_list.append('eight_bit.builtin_modules') library_list.extend(args.libraries) module_list: list[type[Module]] = args.modules for (i, module_name) in enumerate(module_list): module_list[i] = colonimport(module_name) for library_name in library_list: library = import_module(library_name) for subname in get_obj_listing(library): libobj = getattr(library, subname) if issubclass(libobj, Module): module_list.append(libobj) modules: dict[str, type[Module]] = {} for module in module_list: modules[module.module_name] = module config = configparser.ConfigParser() config.read(args.ini) pc_config = config.pop('pc', {}) pc_modules = {} for mod_config_name in config: if mod_config_name == 'DEFAULT': continue mod_config = config[mod_config_name] mod_type_name = mod_config.pop('type') mod_type = modules[mod_type_name] start = int(mod_config.pop('start'), 0) length = int(mod_config.pop('length'), 0) pc_modules[mod_config_name] = mod_type(start=start, length=length, **mod_config) computer = Computer(list(pc_modules.values()), debug=args.verbose) computer.run()
def ldx(comp: Computer): ptr = getat_pages(comp) data = comp.getat(ptr) comp.regx = data
def end(comp: Computer): comp.running = False
def sub2(comp: Computer): ptr = getat_pages(comp, True) data = comp.getat(ptr) comp.accum -= data comp.overflow = comp.accum < 0 comp.accum %= 256
def sta2(comp: Computer): ptr = getat_pages(comp, True) comp.setat(ptr, comp.accum)
def sty2(comp: Computer): ptr = getat_pages(comp, True) comp.setat(ptr, comp.regy)
def lda2(comp: Computer): ptr = getat_pages(comp, True) data = comp.getat(ptr) comp.accum = data
def ldy2(comp: Computer): ptr = getat_pages(comp, True) data = comp.getat(ptr) comp.regy = data
def add2(comp: Computer): ptr = getat_pages(comp, True) data = comp.getat(ptr) comp.accum += data comp.overflow = comp.accum > 255 comp.accum %= 256
def jmp(comp: Computer): comp.pc = getat_pages(comp) - 1
def adi(comp: Computer): comp.pc += 1 data = comp.getat(comp.pc) comp.accum += data comp.overflow = comp.accum > 255 comp.accum %= 256
def ada(comp: Computer): comp.accum += comp.accum comp.overflow = comp.accum > 255 comp.accum %= 256
def ady(comp: Computer): comp.accum += comp.regy comp.overflow = comp.accum > 255 comp.accum %= 256
def sti2(comp: Computer): ptr = getat_pages(comp, True) comp.pc += 1 data = comp.getat(comp.pc) comp.setat(ptr, data)
def getat_pages(comp: Computer, pageswitch: bool = False): if pageswitch: comp.pc += 2 return comp.getat(comp.pc - 1) * 256 + comp.getat(comp.pc) comp.pc += 1 return comp.getat(comp.pc)
def ldy_imm(comp: Computer): comp.pc += 1 data = comp.getat(comp.pc) comp.regy = data
def sby(comp: Computer): comp.accum -= comp.regy comp.overflow = comp.accum < 0 comp.accum %= 256
def lda_imm(comp: Computer): comp.pc += 1 data = comp.getat(comp.pc) comp.accum = data
def sba(comp: Computer): comp.accum -= comp.accum comp.overflow = comp.accum < 0 comp.accum %= 256
def sty(comp: Computer): ptr = getat_pages(comp) comp.setat(ptr, comp.regy)
def sbi(comp: Computer): comp.pc += 1 data = comp.getat(comp.pc) comp.accum -= data comp.overflow = comp.accum < 0 comp.accum %= 256
def jmp2(comp: Computer): comp.pc = getat_pages(comp, True) - 1
def sta(comp: Computer): ptr = getat_pages(comp) comp.setat(ptr, comp.accum)