All pastes #60067 Raw Edit

Anonymous

public text v1 · immutable
#60067 ·published 2006-05-30 21:56 UTC
rendered paste body
conv_file = open('25_19_conv.dat','r')
conv_file.seek(18)

def convert_to_hex(some_string):
    # converts string to hex value
    charval = ord(some_string)
    hexval = hex(charval)
    hexstrlen = len(hexval)
    startpos = hexstrlen - 2
    if hexval[startpos] == 'x':
	startpos += 1
	hexval = '0'+hexval[startpos]
    else:
	hexval = hexval[startpos:hexstrlen]
    return hexval

def handle_block0000():
    # O_o
    return 'bleh'

def handle_block0040():
    # block 4000 handler
    print "block0040"
    for item in range(0,64):
        z1_1 = conv_file.read(1)
        z1_2 = conv_file.read(1)
        print convert_to_hex(z1_1)+convert_to_hex(z1_2)        
    return 0

def handle_block0041():
    # block 41000 handler
    print "block0041"
    for item in range(0,64):
        layer = 0
        layercounter  = conv_file.read(1)
        print "layercounter:" + str(int(convert_to_hex(layercounter),16))
        for item2 in range(0,int(convert_to_hex(layercounter),16)):
            print "layer:" + str(layer)
            z1_1 = conv_file.read(1)
            z1_2 = conv_file.read(1)
            print "--" + convert_to_hex(z1_1)+convert_to_hex(z1_2)
            layer+=1
        #z1_2 = conv_file.read(1)
        #print convert_to_hex(z1_1)+convert_to_hex(z1_2)        
    return 0

# main function
for loop1 in range(0,128):
    print loop1
    for loop2 in range(0,128):
        print loop2
        block1 = conv_file.read(1)
        block2 = conv_file.read(1)        
        block2_hex = convert_to_hex(block2)
        if block2_hex   == 'ff': print "error"
        elif block2_hex == '00': print "block0000"
        elif block2_hex == '40': handle_block0040()
        else: handle_block0041()

conv_file.close()