package turgen.plugin.csturbo;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import turgen.generator.PulseCrate;
import turgen.playlist.AbstractPlayListItem;

/**Playlist item for Czechoslovak Turbo 2000 and Super Turbo*/
public class CsTurboPlaylistItem extends AbstractPlayListItem {
    
    /**Header - File name*/
    String fname;
    
    /**Header - File type*/
    String type;
    
    /**Header - Load address*/
    String load;
    
    /**Header - Length of file*/
    String length;
    
    /**Header - Run address*/
    String run;
    
    /**Type of conversion*/
    public int conversionType;
    
    /*Conversion type constants*/
    public static final int CV_MONOLITHIC=0;
    public static final int CV_SEGMENTED_CHAIN=1;
    public static final int CV_SEGMENTED_BLOCK=2;
    public static final int CV_BASIC=3;
    public static final int CV_DATA=4;
    public static final int CV_BINTURBO=5;
    
    /**Special flags*/
    public int specialFlags;
    
    /**Special flags constants*/
    public static final int SF_NO_BINARY_LOADER=0x01;
    


  public CsTurboPlaylistItem() {
        this.version=1;
  }
    
  public CsTurboPlaylistItem(String inF,String outF,PulseCrate speed,String type,String fname,String load,String run,String length,int conversionType,int[] silenceList,int specialFlags) {
        this();
        this.inFile=inF;
        this.outFile=outF;
        this.pulses=speed;
        this.fname=fname;
        this.load=load;
        this.run=run;
        this.length=length;
        this.type=type;
        this.conversionType=conversionType;
        this.silenceList=silenceList;
        this.specialFlags=specialFlags;
    }
    
    public String toString() {
       
       switch (conversionType) {
           case CV_SEGMENTED_BLOCK: {
               return "BlockLoading: "+fname;
           }
           case CV_SEGMENTED_CHAIN: {
               return "ChainLoading: "+fname;
           }
           case CV_MONOLITHIC: {
               return "Monolithic: "+fname;
           }
           case CV_BASIC: {
               return "BASIC: "+fname;
           }
           case CV_BINTURBO: {
               return "Binary turbo: "+fname;
           }
           case CV_DATA: {
               return "Data: "+fname+","+load+","+run+","+length;
            }
       }
       return "";
    }
    
    public void appendParameter(String param) {
        
    }
    
    public boolean validate() {
        return false;
    }

    
    public AbstractPlayListItem getClonedCopy() {
        int[] silenceListCopy = (int[])this.silenceList.clone();
        PulseCrate pulsesCopy = pulses.getCopy();
        CsTurboPlaylistItem item = new CsTurboPlaylistItem(inFile, outFile, pulsesCopy, type, fname, load, run, length, conversionType, silenceListCopy,specialFlags);
        copyBasics(item);
        return item;
    }

    
    public void saveToStream(DataOutputStream dos) throws Exception {
        saveBasics(dos);
        dos.writeInt(conversionType);
        dos.writeUTF(fname);
        dos.writeUTF(type);
        dos.writeUTF(load);
        dos.writeUTF(length);
        dos.writeUTF(run);
        dos.writeInt(specialFlags);
    }

    
    public void loadFromStream(DataInputStream dis, int version) throws Exception {
        loadBasics(dis);
        conversionType=dis.readInt();
        fname=dis.readUTF();
        type=dis.readUTF();
        load=dis.readUTF();
        length=dis.readUTF();
        run=dis.readUTF();
        if (version>0) {
            specialFlags=dis.readInt();
        }
    }
    
}
