# # Florian SAVOURÉ # 02/06/2020 # # This little code can translate ascii opcodes # like D8 58 A0 7F 8C 12 D0 A9 into a binary file # that can be used in the Apple I. # You can use it for whatever you want idc, # I made it in 10 minutes so if I can save someone's 10 minutes, # copy this code and execute it. # # You can translate your asm into ascii opcodes on https://www.masswerk.at/6502/assembler.html # I do not own this website but this is dope so go check it out # # Enjoy import binascii input_file = "/wozmon.txt" output_file = "/export.rom" rom_size = 256 # bytes def start_convert(input_data: str): print("Converting '{}'".format(input_file)) if len(input_data) <= rom_size * 2: # Complete with 0 until rom size while len(input_data) < rom_size * 2: input_data += "00" # Convert string into hex output_data = binascii.unhexlify(input_data) try: # Convert the string into a bin file with open(output_file, 'wb') as f: f.write(output_data) print("Done !\nOutput file path : '{}' ".format(output_file)) except PermissionError: print("Failed to write output file at '{}' : Permission denied...".format(output_file)) else: print("File is to big !\nFile size: {} bytes\nRom size: {} bytes".format(len(input_data) // 2, rom_size)) # Read input file and make it a string try: with open(input_file, 'r') as f: input_data = f.read().replace('\n', '').replace(' ', '') start_convert(input_data) except FileNotFoundError: print("File '{}' not found".format(input_file)) # if you want to test it with a real program, here is the Woz monitor dump from the Apple I's rom # sha256 e5af0d1c4057bd8e0ef5cb069c208ff7cc0984a7dff53b12c5cf119de8cb5c25 # D8 58 A0 7F 8C 12 D0 A9 # A7 8D 11 D0 8D 13 D0 C9 # DF F0 13 C9 9B F0 03 C8 # 10 0F A9 DC 20 EF FF A9 # 8D 20 EF FF A0 01 88 30 # F6 AD 11 D0 10 FB AD 10 # D0 99 00 02 20 EF FF C9 # 8D D0 D4 A0 FF A9 00 AA # 0A 85 2B C8 B9 00 02 C9 # 8D F0 D4 C9 AE 90 F4 F0 # F0 C9 BA F0 EB C9 D2 F0 # 3B 86 28 86 29 84 2A B9 # 00 02 49 B0 C9 0A 90 06 # 69 88 C9 FA 90 11 0A 0A # 0A 0A A2 04 0A 26 28 26 # 29 CA D0 F8 C8 D0 E0 C4 # 2A F0 97 24 2B 50 10 A5 # 28 81 26 E6 26 D0 B5 E6 # 27 4C 44 FF 6C 24 00 30 # 2B A2 02 B5 27 95 25 95 # 23 CA D0 F7 D0 14 A9 8D # 20 EF FF A5 25 20 DC FF # A5 24 20 DC FF A9 BA 20 # EF FF A9 A0 20 EF FF A1 # 24 20 DC FF 86 2B A5 24 # C5 28 A5 25 E5 29 B0 C1 # E6 24 D0 02 E6 25 A5 24 # 29 07 10 C8 48 4A 4A 4A # 4A 20 E5 FF 68 29 0F 09 # B0 C9 BA 90 02 69 06 2C # 12 D0 30 FB 8D 12 D0 60 # 00 00 00 0F 00 FF 00 00