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;

public class PlTurboROMSegmentedBinaryConvertor implements BinaryConvertor {

    private final Plugin plugin;
    private final String description;


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

    public boolean acceptsBinary(DOS2Binary bf) {
        if (bf.coversMemory(0x0800, 0x0987)) return false;
        return true;
    }

    public boolean acceptsRecorderModification(int recorderModification) {
        if (recorderModification==BinaryConvertor.REC_MOD_PL_TURBO_ROM) {
            return true;
        }
        return false;
    }

    public boolean exhaustsRecorderModification(int recorderModification) {
        return acceptsRecorderModification(recorderModification);
    }

    public int getPilotToneCount(DOS2Binary bf) {
        return 2+(bf.getTotalSegmentCount()*2);
    }

    public String getDescription() {
        return description;
    }

    public boolean hasLoader() {
        return true;
    }

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

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

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

        PlTurboROMPlaylistItem ri = new PlTurboROMPlaylistItem(inFile,outFile,speed,sName.toUpperCase(),PlTurboROMPlaylistItem.CV_BINARY,new int[0]);
        ri.pluginClass=ri.pluginClass=Turgen.pluginManager.getPluginClassName(plugin);
        return ri;

    }

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

    public boolean requiresPulses() {
        return true;
    }


}
