Пример #1
0
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()
Пример #2
0
def ldx(comp: Computer):
    ptr = getat_pages(comp)
    data = comp.getat(ptr)
    comp.regx = data
Пример #3
0
def end(comp: Computer):
    comp.running = False
Пример #4
0
def sub2(comp: Computer):
    ptr = getat_pages(comp, True)
    data = comp.getat(ptr)
    comp.accum -= data
    comp.overflow = comp.accum < 0
    comp.accum %= 256
Пример #5
0
def sta2(comp: Computer):
    ptr = getat_pages(comp, True)
    comp.setat(ptr, comp.accum)
Пример #6
0
def sty2(comp: Computer):
    ptr = getat_pages(comp, True)
    comp.setat(ptr, comp.regy)
Пример #7
0
def lda2(comp: Computer):
    ptr = getat_pages(comp, True)
    data = comp.getat(ptr)
    comp.accum = data
Пример #8
0
def ldy2(comp: Computer):
    ptr = getat_pages(comp, True)
    data = comp.getat(ptr)
    comp.regy = data
Пример #9
0
def add2(comp: Computer):
    ptr = getat_pages(comp, True)
    data = comp.getat(ptr)
    comp.accum += data
    comp.overflow = comp.accum > 255
    comp.accum %= 256
Пример #10
0
def jmp(comp: Computer):
    comp.pc = getat_pages(comp) - 1
Пример #11
0
def adi(comp: Computer):
    comp.pc += 1
    data = comp.getat(comp.pc)
    comp.accum += data
    comp.overflow = comp.accum > 255
    comp.accum %= 256
Пример #12
0
def ada(comp: Computer):
    comp.accum += comp.accum
    comp.overflow = comp.accum > 255
    comp.accum %= 256
Пример #13
0
def ady(comp: Computer):
    comp.accum += comp.regy
    comp.overflow = comp.accum > 255
    comp.accum %= 256
Пример #14
0
def sti2(comp: Computer):
    ptr = getat_pages(comp, True)
    comp.pc += 1
    data = comp.getat(comp.pc)
    comp.setat(ptr, data)
Пример #15
0
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)
Пример #16
0
def ldy_imm(comp: Computer):
    comp.pc += 1
    data = comp.getat(comp.pc)
    comp.regy = data
Пример #17
0
def sby(comp: Computer):
    comp.accum -= comp.regy
    comp.overflow = comp.accum < 0
    comp.accum %= 256
Пример #18
0
def lda_imm(comp: Computer):
    comp.pc += 1
    data = comp.getat(comp.pc)
    comp.accum = data
Пример #19
0
def sba(comp: Computer):
    comp.accum -= comp.accum
    comp.overflow = comp.accum < 0
    comp.accum %= 256
Пример #20
0
def sty(comp: Computer):
    ptr = getat_pages(comp)
    comp.setat(ptr, comp.regy)
Пример #21
0
def sbi(comp: Computer):
    comp.pc += 1
    data = comp.getat(comp.pc)
    comp.accum -= data
    comp.overflow = comp.accum < 0
    comp.accum %= 256
Пример #22
0
def jmp2(comp: Computer):
    comp.pc = getat_pages(comp, True) - 1
Пример #23
0
def sta(comp: Computer):
    ptr = getat_pages(comp)
    comp.setat(ptr, comp.accum)