package turgen.plugin.plturbo;

import java.io.File;
import turgen.Turgen;
import turgen.dtb.DOS2Binary;
import turgen.generator.PulseCrate;
import turgen.playlist.AbstractPlayListItem;
import turgen.plugin.BinaryConvertor;
import turgen.plugin.Plugin;
import turgen.plugin.SimplePlaylistItem;

/**
 *
 * @author michael
 */
public class PlKSOTurbo2000BinaryConvertor implements BinaryConvertor {


    private Plugin plugin;
    private String description;


    public PlKSOTurbo2000BinaryConvertor(Plugin p,String description) {
        this.description=description;
        this.plugin=p;
    }



    public boolean acceptsBinary(DOS2Binary bf) {
        return true;
    }

    public boolean acceptsRecorderModification(int recorderModification) {
        if (recorderModification==BinaryConvertor.REC_MOD_PL_KSOT2000 || recorderModification==BinaryConvertor.REC_MOD_PL_T2000F ) {
            return true;
        }
        else return false;
    }

    public boolean exhaustsRecorderModification(int recorderModification) {
        if (recorderModification==BinaryConvertor.REC_MOD_PL_KSOT2000 || recorderModification==BinaryConvertor.REC_MOD_PL_T2000F ) {
            return true;
        }
        return false;
    }

    public int getPilotToneCount(DOS2Binary bf) {

        /*One pilot tone per kilobyte*/
        int ln = bf.getFileStatistics()[0];
        int blocks = ln/3072;
        if ((ln%3072)!=0) blocks++;

        /*One pilot tone for header*/
        return blocks+1;
    }

    public String getDescription() {
        return description;
    }

    public boolean hasLoader() {
        return true;
    }

    public AbstractPlayListItem getPlaylistItem(DOS2Binary bf, String inFile, String outFile, PulseCrate speed) {

        int hole[] = {0};

        /*Extract name*/
        File f = new File(inFile);
        String sName = f.getName();

        if (sName.length()>16) sName=sName.substring(0,16);

        SimplePlaylistItem ri = new SimplePlaylistItem(inFile,outFile,speed,sName,hole);
        ri.pluginClass=Turgen.pluginManager.getPluginClassName(plugin);

        return ri;

    }

    public PulseCrate[] getSpeeds(int recorderModification) {
        return Turgen.pulseCache.getPulsesForPlugin(plugin);
    }

    public boolean requiresPulses() {
        return true;
    }


}
