none
Adaptar código de Python 2.x a otro lenguaje RRS feed

  • Pregunta

  • Buenas:

    Quiero adaptar este código de Python a C#, puede ser si quieren el VB .net incluso C++, me da igual.

    import os, sys, tkFileDialog,Tkinter
    
    root = Tkinter.Tk()
    root.withdraw()
    
    formats = [ ('Roms Super Nintendo SMC','.smc'),('Roms Super Nintendo SFC','.sfc'),('Fichier Bin','.bin'),('Roms Super Nintendo','.smc .sfc .bin') ]
    
    input = tkFileDialog.askopenfile(parent=root,mode='rb',filetypes=formats,title='Select file to swap bin HI to LO like A16->A15, A17->A16...A21->A20 and A15->21')
    if not input:
            print "Error: Cannot open file"
            sys.exit()
    
    output = tkFileDialog.asksaveasfile(parent=root,mode='wb',filetypes=formats,title='Create output file name')
    if not output:
            print "Error: cannot create output file"
            sys.exit()
            
    
    # reading input file to a byte array
    data = bytearray(input.read())
    
    # calculating rom size in 2 exponants
    expsize = 0
    bytesize = len(data)
    while bytesize > 1:
            expsize += 1
            bytesize = bytesize // 2
    
    # init a proper size empty bytearray
    buffer = bytearray()
    for i in range(2**expsize): buffer.append(0)
    
    # let's do the swap	
    count = 0	
    for i in range(len(data)):
            addr = (i & 0x7fff) + ((i & 0x008000) << (expsize - 16)) + ((i & 0x010000) >> 1) + ((i & 0x020000) >> 1) + ((i & 0x040000) >> 1) + ((i & 0x080000) >> 1) +	((i & 0x100000) >> 1) + ((i & 0x200000) >> 1)
            if addr != i: count += 1
            buffer[addr] = data[i]
    print "Swapped %s (%s) addresses" % (count, hex(count))
    
    # writing output file
    output.write(buffer)
    
    # close file handles
    input.close()
    output.close()

    Gracias.


    http://electronica-pic.blogspot.com

    miércoles, 17 de junio de 2020 12:34