Help:Converters

From C64 Diskmag Wiki
Revision as of 01:41, 24 June 2009 by Vargaviktor (Talk | contribs)

Jump to: navigation, search

Converter main program

Here is the commented version of the conv_hirado_05-11.py converter.

import binascii, os, sys, string
#whic python library is needed

from convert import hirado05
#import the specific converter

from d64 import d64
#import the d64 manager codeblock

for magpostfix in [ "05", "06", "07", "08", "09", "10", "11"] :
    magname = "hirado" + magpostfix
# the d64s whic are convetable with this are hirado05.d64, hirado06.d64...   


    print "Processing", magname
    f = open(magname + ".d64", "rb")
    disk = f.read()
    f.close()
    img = d64.D64image(disk)
    dir = img.get_dir()
    
    #reads the d64 in
    
    for entry in dir :
        filename = entry[0]
        if filename[0] in string.digits and filename[1] in string.digits :
        #the following block is started with that file, if the filename first and second char is a number
        #of-course, if the coding or somethin changed through the evolution of disk mag, maybe the file names, or the
        #char tabel conversions changed by the time, and you need different code blocks
            
            print filename
            
            data = img.get_file_by_name(filename)
            #reads the specific prg file into data
            
            data = data[4:]
            #cuts the first 3 bytes from file, mainly enough 2  "[3:]" because of load address
            
            data = hirado05.unpack(data)
            #calls the specific unpack function
            
            data = hirado05.translate(data)
            #calls the char specific translation function
            
            data = hirado05.webready(data)
            #call the specific transformation function which is changing the special chars to a web displayable format
            
            of = open(magname + "-" + filename[0:2] + ".txt", "wb")
            of.write(data)
            of.close()
            #writes the converted results
 

Some examples for filename checking:
if filename[0:2] in ("T0", "T1", "T2", "T3", "T4", "T5", "T6", "T7", "T8") :
if filename[0] == "H" and filename[1] in string.digits :
if filename[0] in string.letters and filename[1] == "\xdd" :

Skipping files:
this code skips the file if it is on the disk 09 and starts with O

if filename[0] in string.letters and filename[1] == "\xdd" :
            if magpostfix == "09" and filename[0] == "O" :
                continue

Converter blocks in the exteranl converter

You can define here the special conversion, like extracting, char changing, converting to web format.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox