Search in sources :

Example 1 with ROMFormatUnsupportedException

use of org.javatari.atari.cartridge.ROMFormatUnsupportedException in project javatari by ppeccin.

the class Console method cycleCartridgeFormat.

protected void cycleCartridgeFormat() {
    if (cartridge() == null) {
        showOSD("NO CARTRIDGE INSERTED!", true);
        return;
    }
    ArrayList<CartridgeFormatOption> options;
    try {
        options = CartridgeDatabase.getFormatOptions(cartridge().rom());
    } catch (ROMFormatUnsupportedException e) {
        return;
    }
    CartridgeFormatOption currOption = null;
    for (CartridgeFormatOption option : options) if (option.format.equals(cartridge().format()))
        currOption = option;
    // cycle through options
    int pos = options.indexOf(currOption) + 1;
    if (pos >= options.size())
        pos = 0;
    CartridgeFormatOption newOption = options.get(pos);
    Cartridge newCart = newOption.format.createCartridge(cartridge().rom());
    cartridgeSocket().insert(newCart, true);
    showOSD(newOption.format.toString(), true);
}
Also used : Cartridge(org.javatari.atari.cartridge.Cartridge) CartridgeFormatOption(org.javatari.atari.cartridge.CartridgeFormatOption) ROMFormatUnsupportedException(org.javatari.atari.cartridge.ROMFormatUnsupportedException)

Example 2 with ROMFormatUnsupportedException

use of org.javatari.atari.cartridge.ROMFormatUnsupportedException in project javatari by ppeccin.

the class JComboBoxNim method cartridgeAutoDetect.

private void cartridgeAutoDetect() {
    Console console = room.currentConsole();
    Cartridge cart = console.cartridgeSocket().inserted();
    if (cart == null)
        return;
    ArrayList<CartridgeFormatOption> options;
    try {
        options = CartridgeDatabase.getFormatOptions(cart.rom());
    } catch (ROMFormatUnsupportedException e) {
        return;
    }
    Cartridge newCart = options.get(0).format.createCartridge(cart.rom());
    console.cartridgeSocket().insert(newCart, true);
    refreshCartridge();
}
Also used : Cartridge(org.javatari.atari.cartridge.Cartridge) Console(org.javatari.atari.console.Console) CartridgeFormatOption(org.javatari.atari.cartridge.CartridgeFormatOption) ROMFormatUnsupportedException(org.javatari.atari.cartridge.ROMFormatUnsupportedException)

Example 3 with ROMFormatUnsupportedException

use of org.javatari.atari.cartridge.ROMFormatUnsupportedException in project javatari by ppeccin.

the class JComboBoxNim method refreshCartridge.

private void refreshCartridge() {
    if (refreshInProgress)
        return;
    refreshInProgress = true;
    if (room.currentConsole().cartridgeSocket().inserted() == null) {
        romNameTf.setText("<NO CARTRIDGE INSERTED>");
        romFormatLb.setListData(new Object[0]);
        romFormatLb.setEnabled(false);
        defaultsB.setVisible(false);
    } else {
        Cartridge cart = room.currentConsole().cartridgeSocket().inserted();
        romNameTf.setText(cart.rom().info.name);
        romNameTf.setCaretPosition(0);
        ArrayList<CartridgeFormat> formats = new ArrayList<CartridgeFormat>();
        try {
            ArrayList<CartridgeFormatOption> formatOptions;
            formatOptions = CartridgeDatabase.getFormatOptions(cart.rom());
            for (CartridgeFormatOption option : formatOptions) formats.add(option.format);
        } catch (ROMFormatUnsupportedException e) {
        // Leave formats empty
        }
        if (!formats.contains(cart.format()))
            formats.add(0, cart.format());
        romFormatLb.setListData(formats.toArray());
        romFormatLb.setSelectedValue(cart.format(), true);
        romFormatLb.setEnabled(!formats.isEmpty() && !room.isClientMode());
        defaultsB.setText("Auto Detect");
        defaultsB.setVisible(!room.isClientMode());
    }
    refreshInProgress = false;
}
Also used : Cartridge(org.javatari.atari.cartridge.Cartridge) CartridgeFormat(org.javatari.atari.cartridge.CartridgeFormat) ArrayList(java.util.ArrayList) CartridgeFormatOption(org.javatari.atari.cartridge.CartridgeFormatOption) ROMFormatUnsupportedException(org.javatari.atari.cartridge.ROMFormatUnsupportedException)

Example 4 with ROMFormatUnsupportedException

use of org.javatari.atari.cartridge.ROMFormatUnsupportedException in project javatari by ppeccin.

the class ROMLoader method createFromExternalURL.

private static Cartridge createFromExternalURL(InputStream stream, String romURL, boolean provided) {
    System.out.println("Loading Cartridge from: " + romURL);
    BufferedInputStream buffer = bufferedStream(stream);
    try {
        try {
            // First try reading and creating directly
            return createCartridge(buffer, romURL, provided);
        } catch (ROMFormatUnsupportedException ex) {
            // If it fails, try assuming its a compressed stream (zip)
            buffer.reset();
            InputStream romFromZIP = getFirstROMFromZIP(buffer);
            // Probably not zipped either
            if (romFromZIP == null)
                throw ex;
            return createCartridge(romFromZIP, romURL, provided);
        }
    } catch (ROMFormatUnsupportedException ex) {
        romFormatUnsupportedErrorMessage(ex, romURL);
    } catch (IOException ex) {
        generalErrorMessage(ex, romURL);
    } finally {
        try {
            stream.close();
            buffer.close();
        } catch (IOException e) {
        }
    }
    return null;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ROMFormatUnsupportedException(org.javatari.atari.cartridge.ROMFormatUnsupportedException)

Aggregations

ROMFormatUnsupportedException (org.javatari.atari.cartridge.ROMFormatUnsupportedException)4 Cartridge (org.javatari.atari.cartridge.Cartridge)3 CartridgeFormatOption (org.javatari.atari.cartridge.CartridgeFormatOption)3 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ZipInputStream (java.util.zip.ZipInputStream)1 CartridgeFormat (org.javatari.atari.cartridge.CartridgeFormat)1 Console (org.javatari.atari.console.Console)1