def main(args): """ Runs the assembler with the specified arguments. :param args: the command-line arguments """ program = Program() program.process(args.filename) name = program.name or args.name if args.symbols: program.print_symbol_table() if args.print: program.print_statements() if args.bin_file: binary_file = BinaryFile() binary_file.open_host_file(args.bin_file) binary_file.save_file(None, program.get_binary_array()) binary_file.close_host_file() if args.cas_file: if not name: print("No name for the program specified, not creating cassette file") return try: binary_file = CassetteFile(program.origin, program.origin) binary_file.open_host_file(args.cas_file, append=args.append) binary_file.save_file(name, program.get_binary_array()) binary_file.close_host_file() except ValueError as error: print("Unable to save cassette file:") print(error)
def test_binary_string_regression(self, print_mock): statements = [ Statement(" NAM LITERAL"), Statement(" ORG $0600"), Statement("START LDA #%10101010"), Statement(" END START"), ] program = Program() program.statements = statements program.translate_statements() program.print_statements() self.assertEqual([ call("-- Assembled Statements --"), call( "$0000 NAM LITERAL ; " ), call( "$0600 ORG $0600 ; " ), call( "$0600 86AA START LDA #%10101010 ; " ), call( "$0602 END START ; " ), ], print_mock.mock_calls)
def test_character_literal_regression(self, print_mock): statements = [ Statement(" NAM LITERAL"), Statement(" ORG $0600"), Statement("START LDA #'C"), Statement(" END START"), ] program = Program() program.statements = statements program.translate_statements() program.print_statements() self.assertEqual([ call("-- Assembled Statements --"), call( "$0000 NAM LITERAL ; " ), call( "$0600 ORG $0600 ; " ), call( "$0600 8643 START LDA #'C ; " ), call( "$0602 END START ; " ), ], print_mock.mock_calls)
def test_print_statements_correct(self, print_mock): statement = Statement("LABEL JMP $FFFF ; comment") program = Program() program.statements = [statement] program.print_statements() self.assertEqual([ call("-- Assembled Statements --"), call( "$ LABEL JMP $FFFF ; comment " ), ], print_mock.mock_calls)
def main(args): """ Runs the assembler with the specified arguments. :param args: the command-line arguments """ program = Program(width=args.width) program.process(args.filename) coco_file = CoCoFile(name=program.name or args.name, load_addr=program.origin, exec_addr=program.origin, data=program.get_binary_array()) if args.symbols: program.print_symbol_table() if args.print: program.print_statements() if args.bin_file: try: binary_file = BinaryFile() binary_file.open_host_file_for_write(args.bin_file, append=args.append) binary_file.save_to_host_file(coco_file) binary_file.close_host_file() except ValueError as error: print("Unable to save binary file:") print(error) if args.cas_file: if not coco_file.name: print( "No name for the program specified, not creating cassette file" ) return try: cas_file = CassetteFile() cas_file.open_host_file_for_write(args.cas_file, append=args.append) cas_file.save_to_host_file(coco_file) cas_file.close_host_file() except ValueError as error: print("Unable to save cassette file:") print(error)
def test_print_statements_empty_statements_correct(self, print_mock): program = Program() program.print_statements() self.assertEqual([call("-- Assembled Statements --")], print_mock.mock_calls)