Amiga Forever by Cloanto
 
Home Products
 
 
TITLE

Shared System Files on Android Devices

 

TOPIC

This article explains how third-party apps can access the shared system ROM and OS files provided by Amiga Forever Essentials and C64 Forever Essentials for Android.

 

DISCUSSION

Amiga Forever Essentials and C64 Forever Essentials for Android aim to support the development of third-party emulation apps and to make it easier for users to enjoy such apps. In order to achieve this goal, legal and official ROM and OS files licensed for use on Android are made available, with a shared access mechanism for developers.

Like in other versions of the software, ROM files are stored in a directory named "rom", and ADF (Amiga disk image) files are stored in a directory named "adf". On Android devices, this is inside the "files" directory of the "com.cloanto.amigaforever.essentials" namespace for Amiga Forever, and "com.cloanto.c64forever.essentials" for C64 Forever.

When the app is launched, or if a content rescan is initiated, it copies the system files to a shared location on the public "External Storage" (which may be internal or on SD card) and to the private "Internal Storage".

The publicly accessible "external" storage is within the "/sdcard/" path as returned by Environment.getExternalStorageDirectory().

 The same files are also present on internal storage, within the "/data/data/" path as returned byContext.getFilesDir(), but this space is private (not accessible by other apps) without root access rights.

Additional information about ROM files:

  • Amiga Forever Essentials ROM files are 512 KB
  • The ROM file names are designed for long-term support and are not expected to change
  • A ROM file beginning with "AMIROMTYPE1" indicates an XOR encoding against rom.key, as illustrated in memory.c of the original UAE source code (October 1997 and later versions)
  • A rom.key file, if present, is in the same directory as the ROM files
  • Only Amiga ROM files are encoded (8-bit CBM ROM files are not)

Sample code to locate the "files" directory on external storage: 

private String getExternalDir() {
    String dir = "";
    File current_dir;
    current_dir = this.getExternalFilesDir(null);
    if ((current_dir != null) && (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))) {
        dir = current_dir.toString() + "/../../com.cloanto.amigaforever.essentials/files";
    }
    return dir;
}

Sample code to locate the "files" directory on internal storage: 

 private String getInternalDir() {
    String dir = getFilesDir().toString() + "/../../com.cloanto.amigaforever.essentials/files";
    return dir;
}

The app further writes an "index.txt" file at the root of each "files" directory, placing a timestamp in the first line. This makes it possible to use the most recent file set, if both internal and external storage versions are present: 

 public void startApplication() {
    int external_timestamp = getTimestamp(getExternalDir());
    int internal_timestamp = getTimestamp(getInternalDir());
    Log.i("DEBUG", "External timestamp: " + external_timestamp);
    Log.i("DEBUG", "Internal timestamp: " + internal_timestamp);
}

private int getTimestamp(String directory) {
    if (directory.equals("")) { return 0; }
    try {
        File mypath = new File(directory, "index.txt");
        FileInputStream fis = new FileInputStream(mypath);
        BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
        String timestamp = reader.readLine();
        reader.close();
        fis.close();
        return Integer.parseInt(timestamp);
    } catch (Exception e) {
    }
    return 0;
}

Some tips to improve the user experience:

  • Ideally, a default ROM file should be preselected for each system, so that an emulation session can start without errors even if the user has not manually chosen a ROM file
  • If something goes wrong and a ROM cannot be opened for whatever reason (e.g. Amiga Forever Essentials installed after emulation app, or previous user path set to non-existing location, etc.), consider falling back to a suitable Amiga Forever Essentials ROM
  • To determine the best location of the ROM and OS files, check for the presence of one or more files, not just for the directory (the content of which may be empty or not accessible)
  • Encoded ROMs are best supported transparently (there is no need to request the path of the rom.key file, as it is the same as the ROM files)
  • Keeping the "rom" and "adf" paths independent, and starting from the autodetected location for each, helps the user quickly find the correct files in their respective location (rather than manually changing directory) when changing settings

Related Links

 

Article Information
Article ID: 19-116
Platform: Android
Products: Amiga Forever Essentials
Additional Keywords: None
Last Update: 2015-08-07
Your feedback is always appreciated. It is safe to link to this page.