def test_nop(self): # arrange l = lexer.AsmLexer() line = 'NOP' # act result = l.tokenize(line) # assert token = next(result, None) self.assertEqual("OPCODE", token.type)
def test_comment(self): # arrange l = lexer.AsmLexer() line = '; Some comment' # act result = l.tokenize(line) # assert token = next(result, None) self.assertEqual("COMMENT", token.type)
def test_ascii_value(self): # arrange l = lexer.AsmLexer() line = "LDA 'A'" # act result = l.tokenize(line) # assert token = next(result, None) token = next(result, None) self.assertEqual("ASCII", token.type)
def test_absolute_address(self): # arrange l = lexer.AsmLexer() line = 'LDA $7ffa' # act result = l.tokenize(line) # assert token = next(result, None) token = next(result, None) self.assertEqual("ABSOLUTEADDR", token.type)
def test_zeropage_address(self): # arrange l = lexer.AsmLexer() line = 'LDA $1' # act result = l.tokenize(line) # assert token = next(result, None) token = next(result, None) self.assertEqual("ZEROPAGEADDR", token.type)
def test_immediate_address(self): # arrange l = lexer.AsmLexer() line = 'LDA #$1' # act result = l.tokenize(line) # assert token = next(result, None) token = next(result, None) self.assertEqual("IMMEDIATEADDR", token.type)
raise Exception() except: print(f"Address '{args.starting_address}' is not a valid address.") sys.exit(1) print(f"Going to create HEX file for target '{args.target}'") print(f"Using ${args.starting_address} as starting address") with open(args.inputfile, 'r') as ifile: # read the lines of the file into an array, so we can safely edit them lines = [] for line in ifile: lines.append(line) with open(args.outputfile, 'wb') as ofile: mylexer = lexer.AsmLexer() lineno = 1 address = starting_address line = '' labels = {} linenumber = 1 try: first_opcode_address = None # first process labels and string names for line in lines: result = list(mylexer.tokenize(line)) codes = opcodes.Opcodes(result) if len(result) > 0 and (result[0].type == lexer.TOK_LABEL or result[0].type == lexer.TOK_STRINGNAME):